[refs #114] polish controller tests

This commit is contained in:
Alexander Machehin 2012-01-20 22:38:45 +06:00
parent 06a977ea21
commit 3a00a66b86
1 changed files with 18 additions and 44 deletions

View File

@ -55,7 +55,6 @@ describe Comment do
@stranger = Factory(:user) @stranger = Factory(:user)
set_comments_data_for_commit set_comments_data_for_commit
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') @project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
end end
@ -78,10 +77,8 @@ describe Comment do
context 'for default enabled settings' do context 'for default enabled settings' do
it 'should send an e-mail by default settings' do it 'should send an e-mail by default settings' do
ActionMailer::Base.deliveries = [] ActionMailer::Base.deliveries = []
comment = Comment.new(:user => @stranger, :body => 'hello!', :project => @project, comment = Comment.create(:user => @stranger, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id) :commentable_type => @commit.class.name, :commentable_id => @commit.id)
comment.helper
comment.save
ActionMailer::Base.deliveries.count.should == 1 ActionMailer::Base.deliveries.count.should == 1
ActionMailer::Base.deliveries.last.to.include?(@user.email).should == true ActionMailer::Base.deliveries.last.to.include?(@user.email).should == true
end end
@ -91,10 +88,8 @@ describe Comment do
it 'should not send an e-mail' do it 'should not send an e-mail' do
ActionMailer::Base.deliveries = [] ActionMailer::Base.deliveries = []
@project.commit_comments_subscribes.where(:user_id => @user).first.destroy # FIXME @project.commit_comments_subscribes.where(:user_id => @user).first.destroy # FIXME
comment = Comment.new(:user => @stranger, :body => 'hello!', :project => @project, comment = Comment.create(:user => @stranger, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id) :commentable_type => @commit.class.name, :commentable_id => @commit.id)
comment.helper
comment.save
ActionMailer::Base.deliveries.count.should == 0 # cache project.commit_comments_subscribes ... ActionMailer::Base.deliveries.count.should == 0 # cache project.commit_comments_subscribes ...
end end
end end
@ -103,10 +98,8 @@ describe Comment do
it 'should not send an e-mail' do it 'should not send an e-mail' do
ActionMailer::Base.deliveries = [] ActionMailer::Base.deliveries = []
@user.notifier.update_attribute :new_comment_commit_repo_owner, false @user.notifier.update_attribute :new_comment_commit_repo_owner, false
comment = Comment.new(:user => @stranger, :body => 'hello!', :project => @project, comment = Comment.create(:user => @stranger, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id) :commentable_type => @commit.class.name, :commentable_id => @commit.id)
comment.helper
comment.save
ActionMailer::Base.deliveries.count.should == 0 ActionMailer::Base.deliveries.count.should == 0
end end
end end
@ -115,10 +108,8 @@ describe Comment do
it 'should not send an e-mail' do it 'should not send an e-mail' do
ActionMailer::Base.deliveries = [] ActionMailer::Base.deliveries = []
@user.notifier.update_attribute :can_notify, false @user.notifier.update_attribute :can_notify, false
comment = Comment.new(:user => @stranger, :body => 'hello!', :project => @project, comment = Comment.create(:user => @stranger, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id) :commentable_type => @commit.class.name, :commentable_id => @commit.id)
comment.helper
comment.save
ActionMailer::Base.deliveries.count.should == 0 ActionMailer::Base.deliveries.count.should == 0
end end
end end
@ -137,7 +128,7 @@ describe Comment do
end end
it 'should create comment' do it 'should create comment' do
@ability.should be_able_to(:create, Comment.new(@create_params)) @ability.should be_able_to(:create, Comment.create(@create_params))
end end
it 'should update comment' do it 'should update comment' do
@ -155,10 +146,8 @@ describe Comment do
context 'for default enabled settings' do context 'for default enabled settings' do
it 'should send an e-mail by default settings' do it 'should send an e-mail by default settings' do
ActionMailer::Base.deliveries = [] ActionMailer::Base.deliveries = []
comment = Comment.new(:user => @stranger, :body => 'hello!', :project => @project, comment = Comment.create(:user => @stranger, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id) :commentable_type => @commit.class.name, :commentable_id => @commit.id)
comment.helper
comment.save
ActionMailer::Base.deliveries.count.should == 1 ActionMailer::Base.deliveries.count.should == 1
ActionMailer::Base.deliveries.last.to.include?(@project.owner.email).should == true ActionMailer::Base.deliveries.last.to.include?(@project.owner.email).should == true
end end
@ -167,11 +156,9 @@ describe Comment do
context 'for disabled notify setting in project' do context 'for disabled notify setting in project' do
it 'should not send an e-mail' do it 'should not send an e-mail' do
ActionMailer::Base.deliveries = [] ActionMailer::Base.deliveries = []
@project.commit_comments_subscribes.where(:user_id => @project.owner).first.destroy # FIXME Subscribe.first.destroy # FIXME
comment = Comment.new(:user => @stranger, :body => 'hello!', :project => @project, comment = Comment.create(:user => @stranger, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id) :commentable_type => @commit.class.name, :commentable_id => @commit.id)
comment.helper
comment.save
ActionMailer::Base.deliveries.count.should == 0 # cache project.commit_comments_subscribes ... ActionMailer::Base.deliveries.count.should == 0 # cache project.commit_comments_subscribes ...
end end
end end
@ -180,10 +167,8 @@ describe Comment do
it 'should not send an e-mail' do it 'should not send an e-mail' do
ActionMailer::Base.deliveries = [] ActionMailer::Base.deliveries = []
@project.owner.notifier.update_attribute :new_comment_commit_repo_owner, false @project.owner.notifier.update_attribute :new_comment_commit_repo_owner, false
comment = Comment.new(:user => @stranger, :body => 'hello!', :project => @project, comment = Comment.create(:user => @stranger, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id) :commentable_type => @commit.class.name, :commentable_id => @commit.id)
comment.helper
comment.save
ActionMailer::Base.deliveries.count.should == 0 ActionMailer::Base.deliveries.count.should == 0
end end
end end
@ -192,10 +177,8 @@ describe Comment do
it 'should not send an e-mail' do it 'should not send an e-mail' do
ActionMailer::Base.deliveries = [] ActionMailer::Base.deliveries = []
@project.owner.notifier.update_attribute :can_notify, false @project.owner.notifier.update_attribute :can_notify, false
comment = Comment.new(:user => @stranger, :body => 'hello!', :project => @project, comment = Comment.create(:user => @stranger, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id) :commentable_type => @commit.class.name, :commentable_id => @commit.id)
comment.helper
comment.save
ActionMailer::Base.deliveries.count.should == 0 ActionMailer::Base.deliveries.count.should == 0
end end
end end
@ -216,7 +199,7 @@ describe Comment do
end end
it 'should create comment' do it 'should create comment' do
@ability.should be_able_to(:create, Comment.new(@create_params)) @ability.should be_able_to(:create, Comment.create(@create_params))
end end
it 'should update comment' do it 'should update comment' do
@ -234,24 +217,19 @@ describe Comment do
context 'for default enabled settings' do context 'for default enabled settings' do
it 'should not send an e-mail' do it 'should not send an e-mail' do
ActionMailer::Base.deliveries = [] ActionMailer::Base.deliveries = []
comment = Comment.new(:user => @stranger, :body => 'hello!', :project => @project, comment = Comment.create(:user => @stranger, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id) :commentable_type => @commit.class.name, :commentable_id => @commit.id)
comment.helper
comment.save
ActionMailer::Base.deliveries.count.should == 1 ActionMailer::Base.deliveries.count.should == 1
ActionMailer::Base.deliveries.last.to.include?(@stranger.email).should == false ActionMailer::Base.deliveries.last.to.include?(@stranger.email).should == false
end end
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 = Comment.new(:user => @simple, :body => 'hello!', :project => @project, comment = Comment.create(:user => @simple, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id) :commentable_type => @commit.class.name, :commentable_id => @commit.id)
comment.helper
comment.save
ActionMailer::Base.deliveries = [] ActionMailer::Base.deliveries = []
comment = Comment.new(:user => @user, :body => 'owner comment', :project => @project, comment = Comment.create(:user => @user, :body => 'owner comment', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id) :commentable_type => @commit.class.name, :commentable_id => @commit.id)
comment.helper
comment.save
ActionMailer::Base.deliveries.count.should == 1 ActionMailer::Base.deliveries.count.should == 1
ActionMailer::Base.deliveries.last.to.include?(@simple.email).should == true ActionMailer::Base.deliveries.last.to.include?(@simple.email).should == true
end end
@ -262,10 +240,8 @@ describe Comment do
ActionMailer::Base.deliveries = [] ActionMailer::Base.deliveries = []
@project.owner.notifier.update_attribute :can_notify, false @project.owner.notifier.update_attribute :can_notify, false
@project.commit_comments_subscribes.create(:user_id => @stranger.id) @project.commit_comments_subscribes.create(:user_id => @stranger.id)
comment = Comment.new(:user => @project.owner, :body => 'hello!', :project => @project, comment = Comment.create(:user => @project.owner, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id) :commentable_type => @commit.class.name, :commentable_id => @commit.id)
comment.helper
comment.save
ActionMailer::Base.deliveries.count.should == 1 ActionMailer::Base.deliveries.count.should == 1
ActionMailer::Base.deliveries.last.to.include?(@stranger.email).should == true ActionMailer::Base.deliveries.last.to.include?(@stranger.email).should == true
end end
@ -274,13 +250,11 @@ describe Comment do
ActionMailer::Base.deliveries = [] ActionMailer::Base.deliveries = []
@project.owner.notifier.update_attribute :can_notify, false @project.owner.notifier.update_attribute :can_notify, false
@project.commit_comments_subscribes.create(:user_id => @stranger.id) @project.commit_comments_subscribes.create(:user_id => @stranger.id)
comment = Comment.new(:user => @owner, :body => 'hello!', :project => @project, comment = Comment.create(:user => @owner, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id) :commentable_type => @commit.class.name, :commentable_id => @commit.id)
comment.helper
comment.save
ActionMailer::Base.deliveries.count.should == 0 ActionMailer::Base.deliveries.count.should == 0
end end
end end
end end
end end