mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 03:32:17 +08:00
FIX: Couldn't move a topic into the uncategorized category.
This commit is contained in:
@ -1089,127 +1089,6 @@ describe TopicsController do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'update' do
|
||||
it "won't allow us to update a topic when we're not logged in" do
|
||||
put :update, params: { topic_id: 1, slug: 'xyz' }, format: :json
|
||||
expect(response.status).to eq(403)
|
||||
end
|
||||
|
||||
describe 'when logged in' do
|
||||
before do
|
||||
@topic = Fabricate(:topic, user: log_in)
|
||||
Fabricate(:post, topic: @topic)
|
||||
end
|
||||
|
||||
describe 'without permission' do
|
||||
it "raises an exception when the user doesn't have permission to update the topic" do
|
||||
Guardian.any_instance.expects(:can_edit?).with(@topic).returns(false)
|
||||
|
||||
put :update, params: {
|
||||
topic_id: @topic.id, slug: @topic.title
|
||||
}, format: :json
|
||||
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with permission' do
|
||||
before do
|
||||
Guardian.any_instance.expects(:can_edit?).with(@topic).returns(true)
|
||||
end
|
||||
|
||||
it 'succeeds' do
|
||||
put :update, params: {
|
||||
topic_id: @topic.id, slug: @topic.title
|
||||
}, format: :json
|
||||
|
||||
expect(response).to be_success
|
||||
expect(::JSON.parse(response.body)['basic_topic']).to be_present
|
||||
end
|
||||
|
||||
it 'allows a change of title' do
|
||||
put :update, params: {
|
||||
topic_id: @topic.id, slug: @topic.title, title: 'This is a new title for the topic'
|
||||
}, format: :json
|
||||
|
||||
@topic.reload
|
||||
expect(@topic.title).to eq('This is a new title for the topic')
|
||||
end
|
||||
|
||||
it "returns errors with invalid titles" do
|
||||
put :update, params: {
|
||||
topic_id: @topic.id, slug: @topic.title, title: 'asdf'
|
||||
}, format: :json
|
||||
|
||||
expect(response).not_to be_success
|
||||
end
|
||||
|
||||
it "returns errors when the rate limit is exceeded" do
|
||||
EditRateLimiter.any_instance.expects(:performed!).raises(RateLimiter::LimitExceeded.new(60))
|
||||
put :update, params: {
|
||||
topic_id: @topic.id, slug: @topic.title, title: 'This is a new title for the topic'
|
||||
}, format: :json
|
||||
|
||||
expect(response).not_to be_success
|
||||
end
|
||||
|
||||
it "returns errors with invalid categories" do
|
||||
put :update, params: {
|
||||
topic_id: @topic.id, slug: @topic.title, category_id: -1
|
||||
}, format: :json
|
||||
|
||||
expect(response).not_to be_success
|
||||
end
|
||||
|
||||
it "doesn't call the PostRevisor when there is no changes" do
|
||||
PostRevisor.any_instance.expects(:revise!).never
|
||||
put :update, params: {
|
||||
topic_id: @topic.id, slug: @topic.title, title: @topic.title, category_id: @topic.category_id
|
||||
}, format: :json
|
||||
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
context 'when topic is private' do
|
||||
before do
|
||||
@topic.archetype = Archetype.private_message
|
||||
@topic.category = nil
|
||||
@topic.save!
|
||||
end
|
||||
|
||||
context 'when there are no changes' do
|
||||
it 'does not call the PostRevisor' do
|
||||
PostRevisor.any_instance.expects(:revise!).never
|
||||
|
||||
put :update, params: {
|
||||
topic_id: @topic.id, slug: @topic.title, title: @topic.title, category_id: @topic.category_id
|
||||
}, format: :json
|
||||
|
||||
expect(response).to be_success
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "allow_uncategorized_topics is false" do
|
||||
before do
|
||||
SiteSetting.allow_uncategorized_topics = false
|
||||
end
|
||||
|
||||
it "can add a category to an uncategorized topic" do
|
||||
c = Fabricate(:category)
|
||||
|
||||
put :update, params: {
|
||||
topic_id: @topic.id, slug: @topic.title, category_id: c.id
|
||||
}, format: :json
|
||||
|
||||
expect(response).to be_success
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'invite_group' do
|
||||
let :admins do
|
||||
Group[:admins]
|
||||
|
Reference in New Issue
Block a user