2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2012-01-14 12:36:00 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
require "cancan/matchers"
|
|
|
|
|
2012-03-27 16:09:04 +01:00
|
|
|
def create_comment user
|
|
|
|
comment = user.comments.create(:commentable_id => @commit.id.hex, :commentable_type => @commit.class.name,
|
|
|
|
:body => 'test', :project_id => @project.id)
|
|
|
|
comment
|
|
|
|
end
|
|
|
|
|
2012-01-16 13:43:23 +00:00
|
|
|
def set_comments_data_for_commit
|
2012-01-14 12:36:00 +00:00
|
|
|
@ability = Ability.new(@user)
|
|
|
|
|
2012-01-19 18:20:03 +00:00
|
|
|
@project = Factory(:project, :owner => @user)
|
2012-01-14 12:36:00 +00:00
|
|
|
%x(cp -Rf #{Rails.root}/spec/tests.git/* #{@project.git_repository.path}) # maybe FIXME ?
|
|
|
|
@commit = @project.git_repository.commits.first
|
|
|
|
|
2012-03-27 16:09:04 +01:00
|
|
|
@comment = create_comment(@user)
|
|
|
|
@stranger_comment = create_comment(@stranger)
|
2012-01-14 12:36:00 +00:00
|
|
|
|
2012-03-27 16:09:04 +01:00
|
|
|
@subscribe_params = {:project_id => @project.id, :subscribeable_id => @commit.id.hex, :subscribeable_type => @commit.class.name}
|
|
|
|
Subscribe.destroy_all
|
2012-01-14 12:36:00 +00:00
|
|
|
|
|
|
|
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
|
|
|
|
end
|
|
|
|
|
|
|
|
describe Comment do
|
2012-02-20 23:13:05 +00:00
|
|
|
before { stub_rsync_methods }
|
2012-01-14 12:36:00 +00:00
|
|
|
context 'for global admin user' do
|
|
|
|
before(:each) do
|
|
|
|
@user = Factory(:admin)
|
|
|
|
@stranger = Factory(:user)
|
|
|
|
|
2012-01-16 13:43:23 +00:00
|
|
|
set_comments_data_for_commit
|
2012-01-14 12:36:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should create comment' do
|
2012-03-27 16:09:04 +01:00
|
|
|
@ability.should be_able_to(:create, @comment)
|
2012-01-14 12:36:00 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
context 'for project admin user' do
|
|
|
|
before(:each) do
|
|
|
|
@user = Factory(:user)
|
|
|
|
@stranger = Factory(:user)
|
|
|
|
|
2012-01-16 13:43:23 +00:00
|
|
|
set_comments_data_for_commit
|
2012-03-27 16:09:04 +01:00
|
|
|
@admin = Factory(:user)
|
|
|
|
@ability = Ability.new(@admin)
|
|
|
|
@project.relations.create!(:object_type => 'User', :object_id => @admin.id, :role => 'admin')
|
|
|
|
ActionMailer::Base.deliveries = []
|
2012-01-14 12:36:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should create comment' do
|
2012-03-27 16:09:04 +01:00
|
|
|
@ability.should be_able_to(:create, @comment)
|
2012-01-14 12:36:00 +00:00
|
|
|
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 not destroy comment' do
|
|
|
|
@ability.should_not be_able_to(:destroy, @comment)
|
|
|
|
end
|
2012-01-19 18:20:03 +00:00
|
|
|
|
2012-01-21 19:13:33 +00:00
|
|
|
context 'for default settings' do
|
2012-03-27 16:09:04 +01:00
|
|
|
it 'should not send an e-mail' do
|
|
|
|
comment = create_comment(@stranger)
|
2012-01-19 18:20:03 +00:00
|
|
|
ActionMailer::Base.deliveries.count.should == 1
|
|
|
|
ActionMailer::Base.deliveries.last.to.include?(@user.email).should == true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-21 19:13:33 +00:00
|
|
|
context 'for disabled notify setting new_comment_commit_repo_owner' do
|
2012-01-24 12:15:56 +00:00
|
|
|
it 'should not send an e-mail' do
|
2012-01-21 19:13:33 +00:00
|
|
|
@user.notifier.update_attribute :new_comment_commit_repo_owner, false
|
2012-03-27 16:09:04 +01:00
|
|
|
comment = create_comment(@stranger)
|
|
|
|
ActionMailer::Base.deliveries.count.should == 1
|
2012-01-21 19:13:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for disabled notify setting new_comment_commit_owner' do
|
|
|
|
it 'should send an e-mail' do
|
|
|
|
@user.notifier.update_attribute :new_comment_commit_owner, false
|
2012-03-27 16:09:04 +01:00
|
|
|
comment = create_comment(@stranger)
|
2012-01-24 12:15:56 +00:00
|
|
|
ActionMailer::Base.deliveries.count.should == 1
|
2012-01-21 19:13:33 +00:00
|
|
|
ActionMailer::Base.deliveries.last.to.include?(@user.email).should == true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for disabled notify setting new_comment_commit_commentor' do
|
|
|
|
it 'should send an e-mail' do
|
|
|
|
@user.notifier.update_attribute :new_comment_commit_commentor, false
|
2012-03-27 16:09:04 +01:00
|
|
|
comment = create_comment(@stranger)
|
2012-01-24 12:15:56 +00:00
|
|
|
ActionMailer::Base.deliveries.count.should == 1
|
2012-01-21 19:13:33 +00:00
|
|
|
ActionMailer::Base.deliveries.last.to.include?(@user.email).should == true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for disabled all notify setting expect global' do
|
2012-01-19 18:20:03 +00:00
|
|
|
it 'should not send an e-mail' do
|
2012-01-21 19:13:33 +00:00
|
|
|
@user.notifier.update_attribute :new_comment_commit_repo_owner, false
|
|
|
|
@user.notifier.update_attribute :new_comment_commit_owner, false
|
|
|
|
@user.notifier.update_attribute :new_comment_commit_commentor, false
|
2012-03-27 16:09:04 +01:00
|
|
|
comment = create_comment(@stranger)
|
2012-01-24 12:15:56 +00:00
|
|
|
ActionMailer::Base.deliveries.count.should == 0
|
2012-01-19 18:20:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-24 12:15:56 +00:00
|
|
|
context 'for unsubscribe commit' do
|
2012-01-19 18:20:03 +00:00
|
|
|
it 'should not send an e-mail' do
|
2012-03-27 16:09:04 +01:00
|
|
|
Subscribe.unsubscribe_from_commit @subscribe_params.merge(:user_id => @user.id)
|
|
|
|
comment = create_comment(@stranger)
|
2012-02-14 20:28:01 +00:00
|
|
|
ActionMailer::Base.deliveries.count.should == 0
|
2012-01-19 18:20:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for disabled global notify setting' do
|
|
|
|
it 'should not send an e-mail' do
|
|
|
|
@user.notifier.update_attribute :can_notify, false
|
2012-03-27 16:09:04 +01:00
|
|
|
comment = create_comment(@stranger)
|
2012-01-19 18:20:03 +00:00
|
|
|
ActionMailer::Base.deliveries.count.should == 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-14 12:36:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for project owner user' do
|
|
|
|
before(:each) do
|
|
|
|
@user = Factory(:user)
|
|
|
|
@stranger = Factory(:user)
|
2012-01-16 13:43:23 +00:00
|
|
|
set_comments_data_for_commit
|
2012-01-14 12:36:00 +00:00
|
|
|
@project.update_attribute(:owner, @user)
|
2012-03-27 16:09:04 +01:00
|
|
|
ActionMailer::Base.deliveries = []
|
2012-01-14 12:36:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should create comment' do
|
2012-03-27 16:09:04 +01:00
|
|
|
@ability.should be_able_to(:create, @comment)
|
2012-01-14 12:36:00 +00:00
|
|
|
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 not destroy comment' do
|
|
|
|
@ability.should_not be_able_to(:destroy, @comment)
|
|
|
|
end
|
2012-01-19 18:20:03 +00:00
|
|
|
|
|
|
|
context 'for default enabled settings' do
|
|
|
|
it 'should send an e-mail by default settings' do
|
2012-03-27 16:09:04 +01:00
|
|
|
comment = create_comment(@stranger)
|
2012-01-19 18:20:03 +00:00
|
|
|
ActionMailer::Base.deliveries.count.should == 1
|
|
|
|
ActionMailer::Base.deliveries.last.to.include?(@project.owner.email).should == true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-21 19:13:33 +00:00
|
|
|
context 'for disabled notify setting new_comment_commit_repo_owner' do
|
2012-01-19 18:20:03 +00:00
|
|
|
it 'should not send an e-mail' do
|
2012-01-21 19:13:33 +00:00
|
|
|
@user.notifier.update_attribute :new_comment_commit_repo_owner, false
|
2012-03-27 16:09:04 +01:00
|
|
|
Comment.destroy_all
|
|
|
|
comment = create_comment(@stranger)
|
2012-01-24 12:15:56 +00:00
|
|
|
ActionMailer::Base.deliveries.count.should == 0
|
2012-01-21 19:13:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for disabled notify setting new_comment_commit_owner' do
|
|
|
|
it 'should send an e-mail' do
|
|
|
|
@user.notifier.update_attribute :new_comment_commit_owner, false
|
2012-03-27 16:09:04 +01:00
|
|
|
comment = create_comment(@stranger)
|
2012-01-31 15:43:42 +00:00
|
|
|
ActionMailer::Base.deliveries.count.should == 1
|
2012-01-21 19:13:33 +00:00
|
|
|
ActionMailer::Base.deliveries.last.to.include?(@user.email).should == true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for disabled notify setting new_comment_commit_commentor' do
|
|
|
|
it 'should send an e-mail' do
|
|
|
|
@user.notifier.update_attribute :new_comment_commit_commentor, false
|
2012-03-27 16:09:04 +01:00
|
|
|
comment = create_comment(@stranger)
|
2012-01-31 15:43:42 +00:00
|
|
|
ActionMailer::Base.deliveries.count.should == 1
|
2012-01-21 19:13:33 +00:00
|
|
|
ActionMailer::Base.deliveries.last.to.include?(@user.email).should == true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for disabled all notify setting expect global' do
|
|
|
|
it 'should not send an e-mail' do
|
|
|
|
@user.notifier.update_attribute :new_comment_commit_repo_owner, false
|
|
|
|
@user.notifier.update_attribute :new_comment_commit_owner, false
|
|
|
|
@user.notifier.update_attribute :new_comment_commit_commentor, false
|
2012-03-27 16:09:04 +01:00
|
|
|
comment = create_comment(@stranger)
|
2012-01-24 12:15:56 +00:00
|
|
|
ActionMailer::Base.deliveries.count.should == 0
|
2012-01-19 18:20:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-21 19:13:33 +00:00
|
|
|
context 'for unsubscribe project' do
|
2012-01-19 18:20:03 +00:00
|
|
|
it 'should not send an e-mail' do
|
2012-03-27 16:09:04 +01:00
|
|
|
Subscribe.unsubscribe_from_commit @subscribe_params.merge(:user_id => @user.id)
|
|
|
|
comment = create_comment(@stranger)
|
2012-01-24 12:15:56 +00:00
|
|
|
ActionMailer::Base.deliveries.count.should == 0
|
2012-01-19 18:20:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for disabled global notify setting' do
|
|
|
|
it 'should not send an e-mail' do
|
2012-01-21 19:13:33 +00:00
|
|
|
@user.notifier.update_attribute :can_notify, false
|
2012-03-27 16:09:04 +01:00
|
|
|
comment = create_comment(@stranger)
|
2012-01-19 18:20:03 +00:00
|
|
|
ActionMailer::Base.deliveries.count.should == 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-20 18:22:25 +00:00
|
|
|
context 'for own commit' do
|
|
|
|
it 'should send a one e-mail' do
|
|
|
|
@project.owner.update_attribute :email, 'code@tpope.net'
|
2012-03-27 16:09:04 +01:00
|
|
|
comment = create_comment(@stranger)
|
2012-01-21 19:13:33 +00:00
|
|
|
ActionMailer::Base.deliveries.count.should == 1
|
|
|
|
ActionMailer::Base.deliveries.last.to.include?(@project.owner.email).should == true
|
2012-01-20 18:22:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-14 12:36:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for simple user' do
|
|
|
|
before(:each) do
|
|
|
|
@user = Factory(:user)
|
2012-01-20 06:24:55 +00:00
|
|
|
@simple = Factory(:user)
|
2012-01-14 12:36:00 +00:00
|
|
|
@stranger = Factory(:user)
|
2012-01-16 13:43:23 +00:00
|
|
|
set_comments_data_for_commit
|
2012-03-27 16:09:04 +01:00
|
|
|
@comment = create_comment(@simple)
|
2012-01-20 06:24:55 +00:00
|
|
|
@ability = Ability.new(@simple)
|
2012-03-27 16:09:04 +01:00
|
|
|
ActionMailer::Base.deliveries = []
|
|
|
|
Subscribe.unsubscribe_from_commit @subscribe_params.merge(:user_id => [@stranger.id, @project.owner.id])
|
2012-01-14 12:36:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should create comment' do
|
2012-03-27 16:09:04 +01:00
|
|
|
@ability.should be_able_to(:create, @comment)
|
2012-01-14 12:36:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should update comment' do
|
|
|
|
@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
|
2012-01-19 18:20:03 +00:00
|
|
|
|
|
|
|
context 'for default enabled settings' do
|
2012-03-27 16:09:04 +01:00
|
|
|
it 'should send an e-mail' do
|
|
|
|
comment = create_comment(@stranger)
|
2012-01-19 18:20:03 +00:00
|
|
|
ActionMailer::Base.deliveries.count.should == 1
|
2012-03-27 16:09:04 +01:00
|
|
|
ActionMailer::Base.deliveries.last.to.include?(@simple.email).should == true
|
2012-01-19 18:20:03 +00:00
|
|
|
end
|
2012-01-20 15:17:05 +00:00
|
|
|
|
|
|
|
it 'should send an e-mail for comments after his comment' do
|
2012-03-27 16:09:04 +01:00
|
|
|
comment = create_comment(@simple)
|
2012-01-20 15:17:05 +00:00
|
|
|
ActionMailer::Base.deliveries = []
|
2012-03-27 16:09:04 +01:00
|
|
|
comment = create_comment(@user)
|
2012-01-20 15:17:05 +00:00
|
|
|
ActionMailer::Base.deliveries.count.should == 1
|
|
|
|
ActionMailer::Base.deliveries.last.to.include?(@simple.email).should == true
|
|
|
|
end
|
2012-01-20 18:22:25 +00:00
|
|
|
|
2012-01-22 17:49:41 +00:00
|
|
|
it 'should send an e-mail when subscribed to project' do
|
2012-03-27 16:09:04 +01:00
|
|
|
Subscribe.subscribe_to_commit @subscribe_params.merge(:user_id => @simple.id)
|
|
|
|
comment = create_comment(@project.owner)
|
2012-01-19 18:20:03 +00:00
|
|
|
ActionMailer::Base.deliveries.count.should == 1
|
2012-03-27 16:09:04 +01:00
|
|
|
ActionMailer::Base.deliveries.last.to.include?(@simple.email).should == true
|
2012-01-19 18:20:03 +00:00
|
|
|
end
|
|
|
|
|
2012-01-20 06:24:55 +00:00
|
|
|
it 'should not send an e-mail for own comment' do
|
2012-03-27 16:09:04 +01:00
|
|
|
comment = create_comment(@simple)
|
2012-01-19 18:20:03 +00:00
|
|
|
ActionMailer::Base.deliveries.count.should == 0
|
|
|
|
end
|
|
|
|
end
|
2012-01-24 12:15:56 +00:00
|
|
|
|
|
|
|
context 'for committer' do
|
|
|
|
it 'should send an e-mail' do
|
2012-03-27 16:09:04 +01:00
|
|
|
@simple.update_attribute :email, 'code@tpope.net'
|
|
|
|
comment = create_comment(@user)
|
2012-01-24 12:15:56 +00:00
|
|
|
ActionMailer::Base.deliveries.count.should == 1
|
2012-03-27 16:09:04 +01:00
|
|
|
ActionMailer::Base.deliveries.last.to.include?(@simple.email).should == true
|
2012-01-24 12:15:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should send a one e-mail when subscribed to commit' do
|
2012-03-27 16:09:04 +01:00
|
|
|
Subscribe.subscribe_to_commit @subscribe_params.merge(:user_id => @simple.id)
|
|
|
|
@simple.update_attribute :email, 'code@tpope.net'
|
|
|
|
comment = create_comment(@user)
|
2012-01-24 12:15:56 +00:00
|
|
|
ActionMailer::Base.deliveries.count.should == 1
|
2012-03-27 16:09:04 +01:00
|
|
|
ActionMailer::Base.deliveries.last.to.include?(@simple.email).should == true
|
2012-01-24 12:15:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not send an e-mail for own comment' do
|
2012-03-27 16:09:04 +01:00
|
|
|
@simple.update_attribute :email, 'code@tpope.net'
|
|
|
|
comment = create_comment(@simple)
|
|
|
|
ActionMailer::Base.deliveries.count.should == 0
|
2012-01-24 12:15:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not send an e-mail if global notify off' do
|
|
|
|
@project.owner.notifier.update_attribute :can_notify, false
|
2012-03-27 16:09:04 +01:00
|
|
|
@simple.update_attribute :email, 'code@tpope.net'
|
|
|
|
@simple.notifier.update_attribute :can_notify, false
|
|
|
|
comment = create_comment(@user)
|
2012-01-24 12:15:56 +00:00
|
|
|
ActionMailer::Base.deliveries.count.should == 0
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not send an e-mail if notify for my commits off' do
|
2012-03-27 16:09:04 +01:00
|
|
|
Comment.destroy_all
|
|
|
|
@simple.notifier.update_attribute :new_comment_commit_owner, false
|
|
|
|
@simple.update_attribute :email, 'code@tpope.net'
|
|
|
|
comment = create_comment(@user)
|
2012-01-24 12:15:56 +00:00
|
|
|
ActionMailer::Base.deliveries.count.should == 0
|
|
|
|
end
|
|
|
|
end
|
2012-01-14 12:36:00 +00:00
|
|
|
end
|
|
|
|
end
|