#345: pdated specs

This commit is contained in:
Vokhmin Alexey V 2014-03-18 01:03:26 +04:00
parent c672aaa0ec
commit 8173bce392
4 changed files with 13 additions and 16 deletions

View File

@ -80,7 +80,7 @@ describe UserMailer do
@issue = FactoryGirl.create(:issue, project: @project, assignee: @issue_user, user: @issue_user) @issue = FactoryGirl.create(:issue, project: @project, assignee: @issue_user, user: @issue_user)
@comment = FactoryGirl.create(:comment, commentable: @issue, user: @user, project: @project) @comment = FactoryGirl.create(:comment, commentable: @issue, user: @user, project: @project)
@email = UserMailer.new_comment_notification(@comment, @issue_user).deliver! @email = UserMailer.new_comment_notification(@comment, @issue_user.id).deliver!
end end
it 'should have correct subject' do it 'should have correct subject' do

View File

@ -25,14 +25,16 @@ def set_comments_data_for_commit
end end
def should_send_email(args={}) def should_send_email(args={})
user_mailer = double(:user_mailer)
expect(UserMailer).to receive(:new_comment_notification).with(kind_of(Comment), args[:receiver].id).and_return(user_mailer)
expect(user_mailer).to receive(:deliver)
create_comment args[:commentor] create_comment args[:commentor]
ActionMailer::Base.deliveries.count.should == 1
ActionMailer::Base.deliveries.last.to.include?(args[:receiver].email).should == true
end end
def should_not_send_email(args={}) def should_not_send_email(args={})
expect(UserMailer).to_not receive(:new_comment_notification)
create_comment args[:commentor] create_comment args[:commentor]
ActionMailer::Base.deliveries.count.should == 0
end end
describe Comment do describe Comment do
@ -53,15 +55,14 @@ describe Comment do
end end
context 'for project admin user' do context 'for project admin user' do
before(:each) do before do
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
@stranger = FactoryGirl.create(:user) @stranger = FactoryGirl.create(:user)
set_comments_data_for_commit set_comments_data_for_commit
@admin = FactoryGirl.create(:user) @admin = FactoryGirl.create(:user)
@ability = Ability.new(@admin) @ability = Ability.new(@admin)
@project.relations.create!(actor_type: 'User', actor_id: @admin.id, role: 'admin') @project.relations.create!({actor_type: 'User', actor_id: @admin.id, role: 'admin'}, without_protection: true)
ActionMailer::Base.deliveries = []
end end
it_should_behave_like 'user with create comment ability (for model)' it_should_behave_like 'user with create comment ability (for model)'
@ -127,8 +128,6 @@ describe Comment do
@project.owner = @user @project.owner = @user
@project.save @project.save
ActionMailer::Base.deliveries = []
end end
it_should_behave_like 'user with create comment ability (for model)' it_should_behave_like 'user with create comment ability (for model)'
@ -204,7 +203,6 @@ describe Comment do
set_comments_data_for_commit set_comments_data_for_commit
@comment = create_comment(@simple) @comment = create_comment(@simple)
@ability = Ability.new(@simple) @ability = Ability.new(@simple)
ActionMailer::Base.deliveries = []
Subscribe.unsubscribe_from_commit @subscribe_params.merge(user_id: [@stranger.id, @project.owner.id]) Subscribe.unsubscribe_from_commit @subscribe_params.merge(user_id: [@stranger.id, @project.owner.id])
end end
@ -221,7 +219,6 @@ describe Comment do
it 'should send an e-mail for comments after his comment' do it 'should send an e-mail for comments after his comment' do
comment = create_comment(@simple) comment = create_comment(@simple)
ActionMailer::Base.deliveries = []
should_send_email(commentor: @stranger, receiver: @simple) should_send_email(commentor: @stranger, receiver: @simple)
end end

View File

@ -172,7 +172,7 @@ describe Comment do
issue = FactoryGirl.create(:issue, project: @project, user: @user, issue = FactoryGirl.create(:issue, project: @project, user: @user,
title: "link to ##{@issue.serial_id}") title: "link to ##{@issue.serial_id}")
Comment.where(automatic: true, Comment.where(automatic: true,
created_from_issue_id: issue.id).count.should == 1 created_from_issue_id: issue.id).should have(1).item
end end
it 'should create automatic comment from issue body' do it 'should create automatic comment from issue body' do

View File

@ -14,8 +14,8 @@ RSpec.configure do |config|
# #
# config.mock_with :mocha # config.mock_with :mocha
# config.mock_with :flexmock # config.mock_with :flexmock
config.mock_with :rr # config.mock_with :rr
#config.mock_with :rspec config.mock_with :rspec
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures" config.fixture_path = "#{::Rails.root}/spec/fixtures"
@ -64,8 +64,8 @@ end
def stub_redis def stub_redis
@redis_instance = MockRedis.new @redis_instance = MockRedis.new
stub(Redis).new { @redis_instance } allow(Redis).to receive(:new).and_return(@redis_instance)
stub(Resque).redis { @redis_instance } allow(Resque).to receive(:redis).and_return(@redis_instance)
end end
def fill_project project def fill_project project