From 3372f3ee9c205630a520aac841b88cbe2276c0e7 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Wed, 10 Jul 2013 15:32:59 +0600 Subject: [PATCH] [#200] add specs to pull request api --- .../api/v1/pull_requests_controller.rb | 43 +++++++++++++++++++ .../projects/pull_requests_controller_spec.rb | 43 ++++++++++++++++++- spec/support/shared_examples/pull_requests.rb | 35 --------------- 3 files changed, 85 insertions(+), 36 deletions(-) delete mode 100644 spec/support/shared_examples/pull_requests.rb diff --git a/spec/controllers/api/v1/pull_requests_controller.rb b/spec/controllers/api/v1/pull_requests_controller.rb index f7e1c9ea9..55234af9b 100644 --- a/spec/controllers/api/v1/pull_requests_controller.rb +++ b/spec/controllers/api/v1/pull_requests_controller.rb @@ -262,6 +262,49 @@ describe Api::V1::PullRequestsController do end end + context 'send email messages' do + before(:each) do + @project_reader = FactoryGirl.create :user + @project.relations.create!(:actor_type => 'User', :actor_id => @project_reader.id, :role => 'reader') + @project_admin = FactoryGirl.create :user + @project.relations.create!(:actor_type => 'User', :actor_id => @project_admin.id, :role => 'admin') + @project_writer = FactoryGirl.create :user + @project.relations.create!(:actor_type => 'User', :actor_id => @project_writer.id, :role => 'writer') + + http_login(@project_writer) + ActionMailer::Base.deliveries = [] + end + + it 'should send two email messages to project admins' do + post :create, @create_params + @project.pull_requests.last.issue.send(:new_issue_notifications) + @project.pull_requests.last.issue.send(:send_assign_notifications) + ActionMailer::Base.deliveries.count.should == 2 + end + + it 'should send two email messages to admins and one to assignee' do + post :create, @create_params.deep_merge(:pull_request => {:assignee_id => @project_reader.id}) + @project.pull_requests.last.issue.send(:new_issue_notifications) + @project.pull_requests.last.issue.send(:send_assign_notifications) + ActionMailer::Base.deliveries.count.should == 3 + end + + it 'should send email message to new assignee' do + put :update, @update_params.deep_merge(:pull_request => {:assignee_id => @project_reader.id}) + @project.pull_requests.last.issue.send(:new_issue_notifications) + @project.pull_requests.last.issue.send(:send_assign_notifications) + ActionMailer::Base.deliveries.count.should == 1 + end + + it 'should not duplicate email message' do + post :create, @create_params.deep_merge(:pull_request => {:assignee_id => @project_admin.id}) + @project.pull_requests.last.issue.send(:new_issue_notifications) + @project.pull_requests.last.issue.send(:send_assign_notifications) + ActionMailer::Base.deliveries.count.should == 2 # send only to admins + ActionMailer::Base.deliveries.first.to != ActionMailer::Base.deliveries.last.to + end + end + after(:all) do User.destroy_all Platform.destroy_all diff --git a/spec/controllers/projects/pull_requests_controller_spec.rb b/spec/controllers/projects/pull_requests_controller_spec.rb index 3286ac1de..b4927acba 100644 --- a/spec/controllers/projects/pull_requests_controller_spec.rb +++ b/spec/controllers/projects/pull_requests_controller_spec.rb @@ -283,5 +283,46 @@ describe Projects::PullRequestsController do it_should_behave_like 'user without pull request update rights' end - it_should_behave_like 'sending messages and activity feed' + context 'send email messages' do + before(:each) do + @project_reader = FactoryGirl.create :user + @project.relations.create!(:actor_type => 'User', :actor_id => @project_reader.id, :role => 'reader') + @project_admin = FactoryGirl.create :user + @project.relations.create!(:actor_type => 'User', :actor_id => @project_admin.id, :role => 'admin') + @project_writer = FactoryGirl.create :user + @project.relations.create!(:actor_type => 'User', :actor_id => @project_writer.id, :role => 'writer') + + set_session_for(@project_writer) + ActionMailer::Base.deliveries = [] + end + + it 'should send two email messages to project admins' do + post :create, @create_params + @project.pull_requests.last.issue.send(:new_issue_notifications) + @project.pull_requests.last.issue.send(:send_assign_notifications) + ActionMailer::Base.deliveries.count.should == 2 + end + + it 'should send two email messages to admins and one to assignee' do + post :create, @create_params.deep_merge(:issue => {:assignee_id => @project_reader.id}) + @project.pull_requests.last.issue.send(:new_issue_notifications) + @project.pull_requests.last.issue.send(:send_assign_notifications) + ActionMailer::Base.deliveries.count.should == 3 + end + + it 'should send email message to new assignee' do + put :update, @update_params.deep_merge(:pull_request => {:assignee_id => @project_reader.id}) + @project.pull_requests.last.issue.send(:new_issue_notifications) + @project.pull_requests.last.issue.send(:send_assign_notifications) + ActionMailer::Base.deliveries.count.should == 1 + end + + it 'should not duplicate email message' do + post :create, @create_params.deep_merge(:issue => {:assignee_id => @project_admin.id}) + @project.pull_requests.last.issue.send(:new_issue_notifications) + @project.pull_requests.last.issue.send(:send_assign_notifications) + ActionMailer::Base.deliveries.count.should == 2 # send only to admins + ActionMailer::Base.deliveries.first.to != ActionMailer::Base.deliveries.last.to + end + end end diff --git a/spec/support/shared_examples/pull_requests.rb b/spec/support/shared_examples/pull_requests.rb deleted file mode 100644 index 5e2e8cedd..000000000 --- a/spec/support/shared_examples/pull_requests.rb +++ /dev/null @@ -1,35 +0,0 @@ -# -*- encoding : utf-8 -*- -shared_examples_for 'sending messages and activity feed' do - before(:each) do - @project_reader = FactoryGirl.create :user - @project.relations.create!(:actor_type => 'User', :actor_id => @project_reader.id, :role => 'reader') - @project_admin = FactoryGirl.create :user - @project.relations.create!(:actor_type => 'User', :actor_id => @project_admin.id, :role => 'admin') - @project_writer = FactoryGirl.create :user - @project.relations.create!(:actor_type => 'User', :actor_id => @project_writer.id, :role => 'writer') - - set_session_for(@project_writer) - ActionMailer::Base.deliveries = [] - end - - it 'should send two email messages to project admins' do - post :create, @create_params - @project.pull_requests.last.issue.send(:new_issue_notifications) - @project.pull_requests.last.issue.send(:send_assign_notifications) - ActionMailer::Base.deliveries.count.should == 2 - end - - it 'should send two email messages to admins and one to assignee' do - post :create, @create_params.deep_merge(:issue => {:assignee_id => @project_reader.id}) - @project.pull_requests.last.issue.send(:new_issue_notifications) - @project.pull_requests.last.issue.send(:send_assign_notifications) - ActionMailer::Base.deliveries.count.should == 3 - end - - it 'should send email message to new assignee' do - put :update, @update_params.deep_merge(:pull_request => {:assignee_id => @project_reader.id}) - @project.pull_requests.last.issue.send(:new_issue_notifications) - @project.pull_requests.last.issue.send(:send_assign_notifications) - ActionMailer::Base.deliveries.count.should == 1 - end -end