From 99fb4d8757fbf0fdedd6f182ec093dde7c840e62 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Wed, 10 Jul 2013 02:12:27 +0600 Subject: [PATCH] [#200] add some specs --- .../projects/pull_requests_controller_spec.rb | 2 ++ spec/models/pull_request_spec.rb | 1 - spec/support/shared_examples/pull_requests.rb | 35 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 spec/support/shared_examples/pull_requests.rb diff --git a/spec/controllers/projects/pull_requests_controller_spec.rb b/spec/controllers/projects/pull_requests_controller_spec.rb index 37728f9c2..3286ac1de 100644 --- a/spec/controllers/projects/pull_requests_controller_spec.rb +++ b/spec/controllers/projects/pull_requests_controller_spec.rb @@ -282,4 +282,6 @@ describe Projects::PullRequestsController do it_should_behave_like 'user without pull request update rights' end + + it_should_behave_like 'sending messages and activity feed' end diff --git a/spec/models/pull_request_spec.rb b/spec/models/pull_request_spec.rb index fc048b4ec..ab1de8796 100644 --- a/spec/models/pull_request_spec.rb +++ b/spec/models/pull_request_spec.rb @@ -15,7 +15,6 @@ def set_data_for_pull end describe PullRequest do - context 'for owner user' do before do stub_symlink_methods diff --git a/spec/support/shared_examples/pull_requests.rb b/spec/support/shared_examples/pull_requests.rb new file mode 100644 index 000000000..5e2e8cedd --- /dev/null +++ b/spec/support/shared_examples/pull_requests.rb @@ -0,0 +1,35 @@ +# -*- 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