[#200] add specs to pull request api

This commit is contained in:
Alexander Machehin 2013-07-10 15:32:59 +06:00
parent 99fb4d8757
commit 3372f3ee9c
3 changed files with 85 additions and 36 deletions

View File

@ -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

View File

@ -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

View File

@ -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