fixed comment specs
This commit is contained in:
parent
4aebe1e695
commit
f779ae417b
|
@ -8,7 +8,7 @@ end
|
||||||
shared_examples_for 'user with create comment rights for commits' do
|
shared_examples_for 'user with create comment rights for commits' do
|
||||||
it 'should be able to perform create action' do
|
it 'should be able to perform create action' do
|
||||||
post :create, @create_params
|
post :create, @create_params
|
||||||
response.should redirect_to(commit_path(@project, @commit.id))
|
response.should redirect_to(commit_path(@project, @commit.id)+"#comment#{Comment.last.id}")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should create subscribe object into db' do
|
it 'should create subscribe object into db' do
|
||||||
|
@ -63,16 +63,16 @@ shared_examples_for 'user without destroy comment rights for commits' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#shared_examples_for 'user with destroy rights' do
|
shared_examples_for 'user with destroy comment rights for commits' do
|
||||||
# it 'should be able to perform destroy action' do
|
it 'should be able to perform destroy action' do
|
||||||
# delete :destroy, :id => @stranger_comment.id, :owner_name => @project.owner.uname, :project_name => @project.name
|
delete :destroy, :id => @stranger_comment.id, :commit_id => @commit.id, :owner_name => @project.owner.uname, :project_name => @project.name
|
||||||
# response.should redirect_to(commit_path(@project, @commit.id))
|
response.should redirect_to(commit_path(@project, @commit.id))
|
||||||
# end
|
end
|
||||||
#
|
|
||||||
# it 'should reduce comments count' do
|
it 'should reduce comments count' do
|
||||||
# lambda{ delete :destroy, :id => @stranger_comment.id, :issue_id => @issue.serial_id, :owner_name => @project.owner.uname, :project_name => @project.name }.should change{ Comment.count }.by(-1)
|
lambda{ delete :destroy, :id => @stranger_comment.id, :commit_id => @commit.id, :owner_name => @project.owner.uname, :project_name => @project.name }.should change{ Comment.count }.by(-1)
|
||||||
# end
|
end
|
||||||
#end
|
end
|
||||||
|
|
||||||
describe Projects::CommentsController do
|
describe Projects::CommentsController do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
|
@ -99,7 +99,7 @@ describe Projects::CommentsController do
|
||||||
it_should_behave_like 'user with create comment rights for commits'
|
it_should_behave_like 'user with create comment rights for commits'
|
||||||
it_should_behave_like 'user with update stranger comment rights for commits'
|
it_should_behave_like 'user with update stranger comment rights for commits'
|
||||||
it_should_behave_like 'user with update own comment rights for commits'
|
it_should_behave_like 'user with update own comment rights for commits'
|
||||||
it_should_behave_like 'user without destroy comment rights for commits'
|
it_should_behave_like 'user with destroy comment rights for commits'
|
||||||
#it_should_behave_like 'user with destroy rights'
|
#it_should_behave_like 'user with destroy rights'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ describe Projects::CommentsController do
|
||||||
it_should_behave_like 'user with create comment rights for commits'
|
it_should_behave_like 'user with create comment rights for commits'
|
||||||
it_should_behave_like 'user with update stranger comment rights for commits'
|
it_should_behave_like 'user with update stranger comment rights for commits'
|
||||||
it_should_behave_like 'user with update own comment rights for commits'
|
it_should_behave_like 'user with update own comment rights for commits'
|
||||||
it_should_behave_like 'user without destroy comment rights for commits'
|
it_should_behave_like 'user with destroy comment rights for commits'
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for project reader user' do
|
context 'for project reader user' do
|
||||||
|
|
|
@ -24,7 +24,7 @@ end
|
||||||
shared_examples_for 'user with create comment rights' do
|
shared_examples_for 'user with create comment rights' do
|
||||||
it 'should be able to perform create action' do
|
it 'should be able to perform create action' do
|
||||||
post :create, @create_params
|
post :create, @create_params
|
||||||
response.should redirect_to(project_issue_path(@project, @issue))
|
response.should redirect_to(project_issue_path(@project, @issue)+"#comment#{Comment.last.id}")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should create comment in the database' do
|
it 'should create comment in the database' do
|
||||||
|
@ -113,7 +113,7 @@ describe Projects::CommentsController do
|
||||||
it_should_behave_like 'user with create comment rights'
|
it_should_behave_like 'user with create comment rights'
|
||||||
it_should_behave_like 'user with update stranger comment rights'
|
it_should_behave_like 'user with update stranger comment rights'
|
||||||
it_should_behave_like 'user with update own comment rights'
|
it_should_behave_like 'user with update own comment rights'
|
||||||
it_should_behave_like 'user without destroy comment rights'
|
it_should_behave_like 'user with destroy comment rights'
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for project owner user' do
|
context 'for project owner user' do
|
||||||
|
@ -124,7 +124,7 @@ describe Projects::CommentsController do
|
||||||
it_should_behave_like 'user with create comment rights'
|
it_should_behave_like 'user with create comment rights'
|
||||||
it_should_behave_like 'user with update stranger comment rights'
|
it_should_behave_like 'user with update stranger comment rights'
|
||||||
it_should_behave_like 'user with update own comment rights'
|
it_should_behave_like 'user with update own comment rights'
|
||||||
it_should_behave_like 'user without destroy comment rights'
|
it_should_behave_like 'user with destroy comment rights'
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for project reader user' do
|
context 'for project reader user' do
|
||||||
|
|
|
@ -22,6 +22,17 @@ def set_comments_data_for_commit
|
||||||
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
|
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def should_send_email(args={})
|
||||||
|
create_comment args[:commentor]
|
||||||
|
ActionMailer::Base.deliveries.count.should == 1
|
||||||
|
ActionMailer::Base.deliveries.last.to.include?(args[:receiver].email).should == true
|
||||||
|
end
|
||||||
|
|
||||||
|
def should_not_send_email(args={})
|
||||||
|
create_comment args[:commentor]
|
||||||
|
ActionMailer::Base.deliveries.count.should == 0
|
||||||
|
end
|
||||||
|
|
||||||
describe Comment do
|
describe Comment do
|
||||||
before { stub_symlink_methods }
|
before { stub_symlink_methods }
|
||||||
context 'for global admin user' do
|
context 'for global admin user' do
|
||||||
|
@ -32,25 +43,11 @@ describe Comment do
|
||||||
set_comments_data_for_commit
|
set_comments_data_for_commit
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should create comment' do
|
it_should_behave_like 'user with create comment ability (for model)'
|
||||||
@ability.should be_able_to(:create, @comment)
|
it_should_behave_like 'user with update own comment ability (for model)'
|
||||||
end
|
it_should_behave_like 'user with update stranger comment ability (for model)'
|
||||||
|
it_should_behave_like 'user with destroy comment ability (for model)'
|
||||||
it 'should update comment' do
|
it_should_behave_like 'user with destroy stranger comment ability (for model)'
|
||||||
@ability.should be_able_to(:update, @comment)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should update stranger comment' do
|
|
||||||
@ability.should be_able_to(:update, @stranger_comment)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should destroy own comment' do
|
|
||||||
@ability.should be_able_to(:destroy, @comment)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should destroy stranger comment' do
|
|
||||||
@ability.should be_able_to(:destroy, @stranger_comment)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for project admin user' do
|
context 'for project admin user' do
|
||||||
|
@ -65,53 +62,34 @@ describe Comment do
|
||||||
ActionMailer::Base.deliveries = []
|
ActionMailer::Base.deliveries = []
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should create comment' do
|
it_should_behave_like 'user with create comment ability (for model)'
|
||||||
@ability.should be_able_to(:create, @comment)
|
it_should_behave_like 'user with update own comment ability (for model)'
|
||||||
end
|
it_should_behave_like 'user with update stranger comment ability (for model)'
|
||||||
|
it_should_behave_like 'user with destroy comment ability (for model)'
|
||||||
|
it_should_behave_like 'user with destroy stranger comment ability (for model)'
|
||||||
|
|
||||||
it 'should update comment' do
|
it 'should send an e-mail by default settings' do
|
||||||
@ability.should be_able_to(:update, @comment)
|
should_send_email(commentor: @stranger, receiver: @user)
|
||||||
end
|
|
||||||
|
|
||||||
it 'should update stranger comment' do
|
|
||||||
@ability.should be_able_to(:update, @stranger_comment)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should not destroy comment' do
|
|
||||||
@ability.should_not be_able_to(:destroy, @comment)
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'for default settings' do
|
|
||||||
it 'should not send an e-mail' do
|
|
||||||
comment = create_comment(@stranger)
|
|
||||||
ActionMailer::Base.deliveries.count.should == 1
|
|
||||||
ActionMailer::Base.deliveries.last.to.include?(@user.email).should == true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for disabled notify setting new_comment_commit_repo_owner' do
|
context 'for disabled notify setting new_comment_commit_repo_owner' do
|
||||||
it 'should not send an e-mail' do
|
it 'should send an e-mail' do
|
||||||
@user.notifier.update_column :new_comment_commit_repo_owner, false
|
@user.notifier.update_column :new_comment_commit_repo_owner, false
|
||||||
comment = create_comment(@stranger)
|
should_send_email(commentor: @stranger, receiver: @user)
|
||||||
ActionMailer::Base.deliveries.count.should == 1
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for disabled notify setting new_comment_commit_owner' do
|
context 'for disabled notify setting new_comment_commit_owner' do
|
||||||
it 'should send an e-mail' do
|
it 'should send an e-mail' do
|
||||||
@user.notifier.update_column :new_comment_commit_owner, false
|
@user.notifier.update_column :new_comment_commit_owner, false
|
||||||
comment = create_comment(@stranger)
|
should_send_email(commentor: @stranger, receiver: @user)
|
||||||
ActionMailer::Base.deliveries.count.should == 1
|
|
||||||
ActionMailer::Base.deliveries.last.to.include?(@user.email).should == true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for disabled notify setting new_comment_commit_commentor' do
|
context 'for disabled notify setting new_comment_commit_commentor' do
|
||||||
it 'should send an e-mail' do
|
it 'should send an e-mail' do
|
||||||
@user.notifier.update_column :new_comment_commit_commentor, false
|
@user.notifier.update_column :new_comment_commit_commentor, false
|
||||||
comment = create_comment(@stranger)
|
should_send_email(commentor: @stranger, receiver: @user)
|
||||||
ActionMailer::Base.deliveries.count.should == 1
|
|
||||||
ActionMailer::Base.deliveries.last.to.include?(@user.email).should == true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -120,27 +98,23 @@ describe Comment do
|
||||||
@user.notifier.update_column :new_comment_commit_repo_owner, false
|
@user.notifier.update_column :new_comment_commit_repo_owner, false
|
||||||
@user.notifier.update_column :new_comment_commit_owner, false
|
@user.notifier.update_column :new_comment_commit_owner, false
|
||||||
@user.notifier.update_column :new_comment_commit_commentor, false
|
@user.notifier.update_column :new_comment_commit_commentor, false
|
||||||
comment = create_comment(@stranger)
|
should_not_send_email(commentor: @stranger)
|
||||||
ActionMailer::Base.deliveries.count.should == 0
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for unsubscribe commit' do
|
context 'for unsubscribe commit' do
|
||||||
it 'should not send an e-mail' do
|
it 'should not send an e-mail' do
|
||||||
Subscribe.unsubscribe_from_commit @subscribe_params.merge(:user_id => @user.id)
|
Subscribe.unsubscribe_from_commit @subscribe_params.merge(:user_id => @user.id)
|
||||||
comment = create_comment(@stranger)
|
should_not_send_email(commentor: @stranger)
|
||||||
ActionMailer::Base.deliveries.count.should == 0
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for disabled global notify setting' do
|
context 'for disabled global notify setting' do
|
||||||
it 'should not send an e-mail' do
|
it 'should not send an e-mail' do
|
||||||
@user.notifier.update_column :can_notify, false
|
@user.notifier.update_column :can_notify, false
|
||||||
comment = create_comment(@stranger)
|
should_not_send_email(commentor: @stranger)
|
||||||
ActionMailer::Base.deliveries.count.should == 0
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for project owner user' do
|
context 'for project owner user' do
|
||||||
|
@ -155,27 +129,15 @@ describe Comment do
|
||||||
ActionMailer::Base.deliveries = []
|
ActionMailer::Base.deliveries = []
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should create comment' do
|
it_should_behave_like 'user with create comment ability (for model)'
|
||||||
@ability.should be_able_to(:create, @comment)
|
it_should_behave_like 'user with update own comment ability (for model)'
|
||||||
end
|
it_should_behave_like 'user with update stranger comment ability (for model)'
|
||||||
|
it_should_behave_like 'user with destroy comment ability (for model)'
|
||||||
it 'should update comment' do
|
it_should_behave_like 'user with destroy stranger comment ability (for model)'
|
||||||
@ability.should be_able_to(:update, @comment)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should update stranger comment' do
|
|
||||||
@ability.should be_able_to(:update, @stranger_comment)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should not destroy comment' do
|
|
||||||
@ability.should_not be_able_to(:destroy, @comment)
|
|
||||||
end
|
|
||||||
|
|
||||||
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
|
||||||
comment = create_comment(@stranger)
|
should_send_email(commentor: @stranger, receiver: @project.owner)
|
||||||
ActionMailer::Base.deliveries.count.should == 1
|
|
||||||
ActionMailer::Base.deliveries.last.to.include?(@project.owner.email).should == true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -183,26 +145,21 @@ describe Comment do
|
||||||
it 'should not send an e-mail' do
|
it 'should not send an e-mail' do
|
||||||
@user.notifier.update_column :new_comment_commit_repo_owner, false
|
@user.notifier.update_column :new_comment_commit_repo_owner, false
|
||||||
Comment.destroy_all
|
Comment.destroy_all
|
||||||
comment = create_comment(@stranger)
|
should_not_send_email(commentor: @stranger)
|
||||||
ActionMailer::Base.deliveries.count.should == 0
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for disabled notify setting new_comment_commit_owner' do
|
context 'for disabled notify setting new_comment_commit_owner' do
|
||||||
it 'should send an e-mail' do
|
it 'should send an e-mail' do
|
||||||
@user.notifier.update_column :new_comment_commit_owner, false
|
@user.notifier.update_column :new_comment_commit_owner, false
|
||||||
comment = create_comment(@stranger)
|
should_send_email(commentor: @stranger, receiver: @user)
|
||||||
ActionMailer::Base.deliveries.count.should == 1
|
|
||||||
ActionMailer::Base.deliveries.last.to.include?(@user.email).should == true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for disabled notify setting new_comment_commit_commentor' do
|
context 'for disabled notify setting new_comment_commit_commentor' do
|
||||||
it 'should send an e-mail' do
|
it 'should send an e-mail' do
|
||||||
@user.notifier.update_column :new_comment_commit_commentor, false
|
@user.notifier.update_column :new_comment_commit_commentor, false
|
||||||
comment = create_comment(@stranger)
|
should_send_email(commentor: @stranger, receiver: @user)
|
||||||
ActionMailer::Base.deliveries.count.should == 1
|
|
||||||
ActionMailer::Base.deliveries.last.to.include?(@user.email).should == true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -211,36 +168,30 @@ describe Comment do
|
||||||
@user.notifier.update_column :new_comment_commit_repo_owner, false
|
@user.notifier.update_column :new_comment_commit_repo_owner, false
|
||||||
@user.notifier.update_column :new_comment_commit_owner, false
|
@user.notifier.update_column :new_comment_commit_owner, false
|
||||||
@user.notifier.update_column :new_comment_commit_commentor, false
|
@user.notifier.update_column :new_comment_commit_commentor, false
|
||||||
comment = create_comment(@stranger)
|
should_not_send_email(commentor: @stranger)
|
||||||
ActionMailer::Base.deliveries.count.should == 0
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for unsubscribe project' do
|
context 'for unsubscribe project' do
|
||||||
it 'should not send an e-mail' do
|
it 'should not send an e-mail' do
|
||||||
Subscribe.unsubscribe_from_commit @subscribe_params.merge(:user_id => @user.id)
|
Subscribe.unsubscribe_from_commit @subscribe_params.merge(:user_id => @user.id)
|
||||||
comment = create_comment(@stranger)
|
should_not_send_email(commentor: @stranger)
|
||||||
ActionMailer::Base.deliveries.count.should == 0
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for disabled global notify setting' do
|
context 'for disabled global notify setting' do
|
||||||
it 'should not send an e-mail' do
|
it 'should not send an e-mail' do
|
||||||
@user.notifier.update_column :can_notify, false
|
@user.notifier.update_column :can_notify, false
|
||||||
comment = create_comment(@stranger)
|
should_not_send_email(commentor: @stranger)
|
||||||
ActionMailer::Base.deliveries.count.should == 0
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for own commit' do
|
context 'for own commit' do
|
||||||
it 'should send a one e-mail' do
|
it 'should send a one e-mail' do
|
||||||
@project.owner.update_column :email, 'code@tpope.net'
|
@project.owner.update_column :email, 'code@tpope.net'
|
||||||
comment = create_comment(@stranger)
|
should_send_email(commentor: @stranger, receiver: @project.owner)
|
||||||
ActionMailer::Base.deliveries.count.should == 1
|
|
||||||
ActionMailer::Base.deliveries.last.to.include?(@project.owner.email).should == true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for simple user' do
|
context 'for simple user' do
|
||||||
|
@ -255,86 +206,62 @@ describe Comment do
|
||||||
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
|
||||||
|
|
||||||
it 'should create comment' do
|
it_should_behave_like 'user with create comment ability (for model)'
|
||||||
@ability.should be_able_to(:create, @comment)
|
it_should_behave_like 'user with update own comment ability (for model)'
|
||||||
end
|
it_should_behave_like 'user without update stranger comment ability (for model)'
|
||||||
|
it_should_behave_like 'user with destroy comment ability (for model)'
|
||||||
it 'should update comment' do
|
it_should_behave_like 'user without destroy stranger comment ability (for model)'
|
||||||
@ability.should be_able_to(:update, @comment)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should not update stranger comment' do
|
|
||||||
@ability.should_not be_able_to(:update, @stranger_comment)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should not destroy comment' do
|
|
||||||
@ability.should_not be_able_to(:destroy, @comment)
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'for default enabled settings' do
|
context 'for default enabled settings' do
|
||||||
it 'should send an e-mail' do
|
it 'should send an e-mail' do
|
||||||
comment = create_comment(@stranger)
|
should_send_email(commentor: @stranger, receiver: @simple)
|
||||||
ActionMailer::Base.deliveries.count.should == 1
|
|
||||||
ActionMailer::Base.deliveries.last.to.include?(@simple.email).should == true
|
|
||||||
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 = create_comment(@simple)
|
comment = create_comment(@simple)
|
||||||
ActionMailer::Base.deliveries = []
|
ActionMailer::Base.deliveries = []
|
||||||
comment = create_comment(@user)
|
should_send_email(commentor: @stranger, receiver: @simple)
|
||||||
ActionMailer::Base.deliveries.count.should == 1
|
|
||||||
ActionMailer::Base.deliveries.last.to.include?(@simple.email).should == true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should send an e-mail when subscribed to project' do
|
it 'should send an e-mail when subscribed to project' do
|
||||||
Subscribe.subscribe_to_commit @subscribe_params.merge(:user_id => @simple.id)
|
Subscribe.subscribe_to_commit @subscribe_params.merge(:user_id => @simple.id)
|
||||||
comment = create_comment(@project.owner)
|
should_send_email(commentor: @project.owner, receiver: @simple)
|
||||||
ActionMailer::Base.deliveries.count.should == 1
|
|
||||||
ActionMailer::Base.deliveries.last.to.include?(@simple.email).should == true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not send an e-mail for own comment' do
|
it 'should not send an e-mail for own comment' do
|
||||||
comment = create_comment(@simple)
|
should_not_send_email(commentor: @simple)
|
||||||
ActionMailer::Base.deliveries.count.should == 0
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for committer' do
|
context 'for committer' do
|
||||||
it 'should send an e-mail' do
|
it 'should send an e-mail' do
|
||||||
@simple.update_column :email, 'test@test.test'
|
@simple.update_column :email, 'test@test.test'
|
||||||
comment = create_comment(@user)
|
should_send_email commentor: @stranger, receiver: @simple
|
||||||
ActionMailer::Base.deliveries.count.should == 1
|
|
||||||
ActionMailer::Base.deliveries.last.to.include?(@simple.email).should == true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should send a one e-mail when subscribed to commit' do
|
it 'should send a one e-mail when subscribed to commit' do
|
||||||
Subscribe.subscribe_to_commit @subscribe_params.merge(:user_id => @simple.id)
|
Subscribe.subscribe_to_commit @subscribe_params.merge(:user_id => @simple.id)
|
||||||
@simple.update_column :email, 'test@test.test'
|
@simple.update_column :email, 'test@test.test'
|
||||||
comment = create_comment(@user)
|
should_send_email(commentor: @stranger, receiver: @simple)
|
||||||
ActionMailer::Base.deliveries.count.should == 1
|
|
||||||
ActionMailer::Base.deliveries.last.to.include?(@simple.email).should == true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not send an e-mail for own comment' do
|
it 'should not send an e-mail for own comment' do
|
||||||
@simple.update_column :email, 'test@test.test'
|
@simple.update_column :email, 'test@test.test'
|
||||||
comment = create_comment(@simple)
|
should_not_send_email(commentor: @simple)
|
||||||
ActionMailer::Base.deliveries.count.should == 0
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not send an e-mail if global notify off' do
|
it 'should not send an e-mail if global notify off' do
|
||||||
@project.owner.notifier.update_column :can_notify, false
|
@project.owner.notifier.update_column :can_notify, false
|
||||||
@simple.update_column :email, 'test@test.test'
|
@simple.update_column :email, 'test@test.test'
|
||||||
@simple.notifier.update_column :can_notify, false
|
@simple.notifier.update_column :can_notify, false
|
||||||
comment = create_comment(@user)
|
should_not_send_email(commentor: @user)
|
||||||
ActionMailer::Base.deliveries.count.should == 0
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not send an e-mail if notify for my commits off' do
|
it 'should not send an e-mail if notify for my commits off' do
|
||||||
Comment.destroy_all
|
Comment.destroy_all
|
||||||
@simple.notifier.update_column :new_comment_commit_owner, false
|
@simple.notifier.update_column :new_comment_commit_owner, false
|
||||||
@simple.update_column :email, 'test@test.test'
|
@simple.update_column :email, 'test@test.test'
|
||||||
comment = create_comment(@user)
|
should_not_send_email(commentor: @user)
|
||||||
ActionMailer::Base.deliveries.count.should == 0
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,29 +24,11 @@ describe Comment do
|
||||||
set_commentable_data
|
set_commentable_data
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should create comment' do
|
it_should_behave_like 'user with create comment ability (for model)'
|
||||||
@ability.should be_able_to(:create, @comment)
|
it_should_behave_like 'user with update own comment ability (for model)'
|
||||||
end
|
it_should_behave_like 'user with update stranger comment ability (for model)'
|
||||||
|
it_should_behave_like 'user with destroy comment ability (for model)'
|
||||||
pending "sends an e-mail" do
|
it_should_behave_like 'user with destroy stranger comment ability (for model)'
|
||||||
ActionMailer::Base.deliveries.last.to.include?(@stranger.email).should == true
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should update comment' do
|
|
||||||
@ability.should be_able_to(:update, @comment)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should update stranger comment' do
|
|
||||||
@ability.should be_able_to(:update, @stranger_comment)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should destroy own comment' do
|
|
||||||
@ability.should be_able_to(:destroy, @comment)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should destroy stranger comment' do
|
|
||||||
@ability.should be_able_to(:destroy, @stranger_comment)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for project admin user' do
|
context 'for project admin user' do
|
||||||
|
@ -59,21 +41,14 @@ describe Comment do
|
||||||
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
|
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should create comment' do
|
it_should_behave_like 'user with create comment ability (for model)'
|
||||||
@comment.user = @user
|
it_should_behave_like 'user with update own comment ability (for model)'
|
||||||
@ability.should be_able_to(:create, @comment)
|
it_should_behave_like 'user with update stranger comment ability (for model)'
|
||||||
end
|
it_should_behave_like 'user with destroy comment ability (for model)'
|
||||||
|
it_should_behave_like 'user with destroy stranger comment ability (for model)'
|
||||||
|
|
||||||
it 'should update comment' do
|
pending "sends an e-mail" do
|
||||||
@ability.should be_able_to(:update, @comment)
|
ActionMailer::Base.deliveries.last.to.include?(@stranger.email).should == true
|
||||||
end
|
|
||||||
|
|
||||||
it 'should update stranger comment' do
|
|
||||||
@ability.should be_able_to(:update, @stranger_comment)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should not destroy comment' do
|
|
||||||
@ability.should_not be_able_to(:destroy, @comment)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -89,21 +64,11 @@ describe Comment do
|
||||||
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
|
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should create comment' do
|
it_should_behave_like 'user with create comment ability (for model)'
|
||||||
@ability.should be_able_to(:create, @comment)
|
it_should_behave_like 'user with update own comment ability (for model)'
|
||||||
end
|
it_should_behave_like 'user with update stranger comment ability (for model)'
|
||||||
|
it_should_behave_like 'user with destroy comment ability (for model)'
|
||||||
it 'should update comment' do
|
it_should_behave_like 'user with destroy stranger comment ability (for model)'
|
||||||
@ability.should be_able_to(:update, @comment)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should update stranger comment' do
|
|
||||||
@ability.should be_able_to(:update, @stranger_comment)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should not destroy comment' do
|
|
||||||
@ability.should_not be_able_to(:destroy, @comment)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for simple user' do
|
context 'for simple user' do
|
||||||
|
@ -114,21 +79,11 @@ describe Comment do
|
||||||
set_commentable_data
|
set_commentable_data
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should create comment' do
|
it_should_behave_like 'user with create comment ability (for model)'
|
||||||
@ability.should be_able_to(:create, @comment)
|
it_should_behave_like 'user with update own comment ability (for model)'
|
||||||
end
|
it_should_behave_like 'user without update stranger comment ability (for model)'
|
||||||
|
it_should_behave_like 'user with destroy comment ability (for model)'
|
||||||
it 'should update comment' do
|
it_should_behave_like 'user without destroy stranger comment ability (for model)'
|
||||||
@ability.should be_able_to(:update, @comment)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should not update stranger comment' do
|
|
||||||
@ability.should_not be_able_to(:update, @stranger_comment)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should not destroy comment' do
|
|
||||||
@ability.should_not be_able_to(:destroy, @comment)
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'with mass assignment' do
|
context 'with mass assignment' do
|
||||||
it 'should not be able to update commentable' do
|
it 'should not be able to update commentable' do
|
||||||
|
@ -145,6 +100,5 @@ describe Comment do
|
||||||
@comment.should_not allow_mass_assignment_of :project_id
|
@comment.should_not allow_mass_assignment_of :project_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
# -*- encoding : utf-8 -*-
|
||||||
|
shared_examples_for 'user with create comment ability (for model)' do
|
||||||
|
it 'should create comment' do
|
||||||
|
@ability.should be_able_to(:create, @comment)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
shared_examples_for 'user with update own comment ability (for model)' do
|
||||||
|
it 'should update comment' do
|
||||||
|
@ability.should be_able_to(:update, @comment)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
shared_examples_for 'user with update stranger comment ability (for model)' do
|
||||||
|
it 'should update stranger comment' do
|
||||||
|
@ability.should be_able_to(:update, @stranger_comment)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
shared_examples_for 'user with destroy comment ability (for model)' do
|
||||||
|
it 'should destroy own comment' do
|
||||||
|
@ability.should be_able_to(:destroy, @comment)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
shared_examples_for 'user with destroy stranger comment ability (for model)' do
|
||||||
|
it 'should destroy stranger comment' do
|
||||||
|
@ability.should be_able_to(:destroy, @stranger_comment)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
shared_examples_for 'user without update stranger comment ability (for model)' do
|
||||||
|
it 'should not update stranger comment' do
|
||||||
|
@ability.should_not be_able_to(:update, @stranger_comment)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
shared_examples_for 'user without destroy stranger comment ability (for model)' do
|
||||||
|
it 'should not destroy stranger comment' do
|
||||||
|
@ability.should_not be_able_to(:destroy, @stranger_comment)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
shared_examples_for 'by default settings' do
|
||||||
|
it 'should send an e-mail' do
|
||||||
|
comment = create_comment(@stranger)
|
||||||
|
ActionMailer::Base.deliveries.count.should == 1
|
||||||
|
ActionMailer::Base.deliveries.last.to.include?(@user.email).should == true
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue