Delegate bulk operations to a TopicsBulkAction object.

This commit is contained in:
Robin Ward
2014-01-30 11:15:49 -05:00
parent 0c73eb8ce1
commit b315a5c28f
3 changed files with 50 additions and 1 deletions

View File

@ -781,4 +781,34 @@ describe TopicsController do
end
describe "bulk" do
it 'needs you to be logged in' do
lambda { xhr :put, :bulk }.should raise_error(Discourse::NotLoggedIn)
end
describe "when logged in" do
let!(:user) { log_in }
let(:operation) { {type: 'change_category', category_id: '1'} }
let(:topic_ids) { [1,2,3] }
it "requires a list of topic_ids" do
lambda { xhr :put, :bulk, operation: operation }.should raise_error(ActionController::ParameterMissing)
end
it "requires an operation param" do
lambda { xhr :put, :bulk, topic_ids: topic_ids}.should raise_error(ActionController::ParameterMissing)
end
it "requires a type field for the operation param" do
lambda { xhr :put, :bulk, topic_ids: topic_ids, operation: {}}.should raise_error(ActionController::ParameterMissing)
end
it "delegates work to `TopicsBulkAction`" do
topics_bulk_action = mock
TopicsBulkAction.expects(:new).with(user, topic_ids, operation).returns(topics_bulk_action)
topics_bulk_action.expects(:perform!)
xhr :put, :bulk, topic_ids: topic_ids, operation: operation
end
end
end
end