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
|
2012-04-04 22:43:06 +01:00
|
|
|
FactoryGirl.create(:comment, :user => user, :commentable => @commit, :project => @project)
|
2012-03-27 16:09:04 +01:00
|
|
|
end
|
|
|
|
|
2013-03-27 17:27:02 +00:00
|
|
|
def create_comment_in_commit commit, project, body
|
|
|
|
FactoryGirl.create(:comment, :user => @user, :commentable => commit, :project => project, :body => body)
|
|
|
|
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-12-18 17:53:00 +00:00
|
|
|
@project = FactoryGirl.create(:project_with_commit, :owner => @user)
|
2012-07-17 09:02:56 +01:00
|
|
|
@commit = @project.repo.commits.first
|
2012-01-14 12:36:00 +00:00
|
|
|
|
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
|
|
|
|
|
2012-12-13 11:30:49 +00:00
|
|
|
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
|
|
|
|
|
2012-01-14 12:36:00 +00:00
|
|
|
describe Comment do
|
2012-05-16 16:29:28 +01:00
|
|
|
before { stub_symlink_methods }
|
2012-01-14 12:36:00 +00:00
|
|
|
context 'for global admin user' do
|
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@user = FactoryGirl.create(:admin)
|
|
|
|
@stranger = FactoryGirl.create(:user)
|
2012-01-14 12:36:00 +00:00
|
|
|
|
2012-01-16 13:43:23 +00:00
|
|
|
set_comments_data_for_commit
|
2012-01-14 12:36:00 +00:00
|
|
|
end
|
|
|
|
|
2012-12-13 11:30:49 +00:00
|
|
|
it_should_behave_like 'user with create comment ability (for model)'
|
|
|
|
it_should_behave_like 'user with update own comment ability (for model)'
|
|
|
|
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)'
|
2012-01-14 12:36:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for project admin user' do
|
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@user = FactoryGirl.create(:user)
|
|
|
|
@stranger = FactoryGirl.create(:user)
|
2012-01-14 12:36:00 +00:00
|
|
|
|
2012-01-16 13:43:23 +00:00
|
|
|
set_comments_data_for_commit
|
2012-03-29 21:34:22 +01:00
|
|
|
@admin = FactoryGirl.create(:user)
|
2012-03-27 16:09:04 +01:00
|
|
|
@ability = Ability.new(@admin)
|
2012-04-26 02:38:33 +01:00
|
|
|
@project.relations.create!(:actor_type => 'User', :actor_id => @admin.id, :role => 'admin')
|
2012-03-27 16:09:04 +01:00
|
|
|
ActionMailer::Base.deliveries = []
|
2012-01-14 12:36:00 +00:00
|
|
|
end
|
|
|
|
|
2012-12-13 11:30:49 +00:00
|
|
|
it_should_behave_like 'user with create comment ability (for model)'
|
|
|
|
it_should_behave_like 'user with update own comment ability (for model)'
|
|
|
|
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)'
|
2012-01-14 12:36:00 +00:00
|
|
|
|
2012-12-13 11:30:49 +00:00
|
|
|
it 'should send an e-mail by default settings' do
|
|
|
|
should_send_email(commentor: @stranger, receiver: @user)
|
2012-01-19 18:20:03 +00:00
|
|
|
end
|
|
|
|
|
2012-01-21 19:13:33 +00:00
|
|
|
context 'for disabled notify setting new_comment_commit_repo_owner' do
|
2012-12-13 11:30:49 +00:00
|
|
|
it 'should send an e-mail' do
|
2012-08-15 14:52:32 +01:00
|
|
|
@user.notifier.update_column :new_comment_commit_repo_owner, false
|
2012-12-13 11:30:49 +00:00
|
|
|
should_send_email(commentor: @stranger, receiver: @user)
|
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
|
2012-08-15 14:52:32 +01:00
|
|
|
@user.notifier.update_column :new_comment_commit_owner, false
|
2012-12-13 11:30:49 +00:00
|
|
|
should_send_email(commentor: @stranger, receiver: @user)
|
2012-01-21 19:13:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for disabled notify setting new_comment_commit_commentor' do
|
|
|
|
it 'should send an e-mail' do
|
2012-08-15 14:52:32 +01:00
|
|
|
@user.notifier.update_column :new_comment_commit_commentor, false
|
2012-12-13 11:30:49 +00:00
|
|
|
should_send_email(commentor: @stranger, receiver: @user)
|
2012-01-21 19:13:33 +00:00
|
|
|
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-08-15 14:52:32 +01:00
|
|
|
@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_commentor, false
|
2012-12-13 11:30:49 +00:00
|
|
|
should_not_send_email(commentor: @stranger)
|
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)
|
2012-12-13 11:30:49 +00:00
|
|
|
should_not_send_email(commentor: @stranger)
|
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-08-15 14:52:32 +01:00
|
|
|
@user.notifier.update_column :can_notify, false
|
2012-12-13 11:30:49 +00:00
|
|
|
should_not_send_email(commentor: @stranger)
|
2012-01-19 18:20:03 +00:00
|
|
|
end
|
|
|
|
end
|
2012-01-14 12:36:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for project owner user' do
|
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@user = FactoryGirl.create(:user)
|
|
|
|
@stranger = FactoryGirl.create(:user)
|
2012-01-16 13:43:23 +00:00
|
|
|
set_comments_data_for_commit
|
2012-09-25 12:55:30 +01:00
|
|
|
|
2012-09-06 11:53:03 +01:00
|
|
|
@project.owner = @user
|
|
|
|
@project.save
|
2012-09-25 12:55:30 +01:00
|
|
|
|
2012-03-27 16:09:04 +01:00
|
|
|
ActionMailer::Base.deliveries = []
|
2012-01-14 12:36:00 +00:00
|
|
|
end
|
|
|
|
|
2012-12-13 11:30:49 +00:00
|
|
|
it_should_behave_like 'user with create comment ability (for model)'
|
|
|
|
it_should_behave_like 'user with update own comment ability (for model)'
|
|
|
|
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)'
|
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-12-13 11:30:49 +00:00
|
|
|
should_send_email(commentor: @stranger, receiver: @project.owner)
|
2012-01-19 18:20:03 +00:00
|
|
|
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-08-15 14:52:32 +01:00
|
|
|
@user.notifier.update_column :new_comment_commit_repo_owner, false
|
2012-03-27 16:09:04 +01:00
|
|
|
Comment.destroy_all
|
2012-12-13 11:30:49 +00:00
|
|
|
should_not_send_email(commentor: @stranger)
|
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
|
2012-08-15 14:52:32 +01:00
|
|
|
@user.notifier.update_column :new_comment_commit_owner, false
|
2012-12-13 11:30:49 +00:00
|
|
|
should_send_email(commentor: @stranger, receiver: @user)
|
2012-01-21 19:13:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for disabled notify setting new_comment_commit_commentor' do
|
|
|
|
it 'should send an e-mail' do
|
2012-08-15 14:52:32 +01:00
|
|
|
@user.notifier.update_column :new_comment_commit_commentor, false
|
2012-12-13 11:30:49 +00:00
|
|
|
should_send_email(commentor: @stranger, receiver: @user)
|
2012-01-21 19:13:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for disabled all notify setting expect global' do
|
|
|
|
it 'should not send an e-mail' do
|
2012-08-15 14:52:32 +01:00
|
|
|
@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_commentor, false
|
2012-12-13 11:30:49 +00:00
|
|
|
should_not_send_email(commentor: @stranger)
|
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)
|
2012-12-13 11:30:49 +00:00
|
|
|
should_not_send_email(commentor: @stranger)
|
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-08-15 14:52:32 +01:00
|
|
|
@user.notifier.update_column :can_notify, false
|
2012-12-13 11:30:49 +00:00
|
|
|
should_not_send_email(commentor: @stranger)
|
2012-01-19 18:20:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-20 18:22:25 +00:00
|
|
|
context 'for own commit' do
|
|
|
|
it 'should send a one e-mail' do
|
2012-08-15 14:52:32 +01:00
|
|
|
@project.owner.update_column :email, 'code@tpope.net'
|
2012-12-13 11:30:49 +00:00
|
|
|
should_send_email(commentor: @stranger, receiver: @project.owner)
|
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
|
2012-03-29 21:34:22 +01:00
|
|
|
@user = FactoryGirl.create(:user)
|
|
|
|
@simple = FactoryGirl.create(:user)
|
|
|
|
@stranger = FactoryGirl.create(: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
|
|
|
|
|
2012-12-13 11:30:49 +00:00
|
|
|
it_should_behave_like 'user with create comment ability (for model)'
|
|
|
|
it_should_behave_like 'user with update own comment ability (for model)'
|
|
|
|
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_behave_like 'user without destroy stranger comment ability (for model)'
|
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
|
2012-12-13 11:30:49 +00:00
|
|
|
should_send_email(commentor: @stranger, receiver: @simple)
|
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-12-13 11:30:49 +00:00
|
|
|
should_send_email(commentor: @stranger, receiver: @simple)
|
2012-01-20 15:17:05 +00:00
|
|
|
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)
|
2012-12-13 11:30:49 +00:00
|
|
|
should_send_email(commentor: @project.owner, receiver: @simple)
|
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-12-13 11:30:49 +00:00
|
|
|
should_not_send_email(commentor: @simple)
|
2012-01-19 18:20:03 +00:00
|
|
|
end
|
|
|
|
end
|
2012-01-24 12:15:56 +00:00
|
|
|
|
|
|
|
context 'for committer' do
|
|
|
|
it 'should send an e-mail' do
|
2012-09-25 12:55:30 +01:00
|
|
|
@simple.update_column :email, 'test@test.test'
|
2012-12-13 11:30:49 +00:00
|
|
|
should_send_email commentor: @stranger, receiver: @simple
|
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)
|
2012-09-25 12:55:30 +01:00
|
|
|
@simple.update_column :email, 'test@test.test'
|
2012-12-13 11:30:49 +00:00
|
|
|
should_send_email(commentor: @stranger, receiver: @simple)
|
2012-01-24 12:15:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not send an e-mail for own comment' do
|
2012-09-25 12:55:30 +01:00
|
|
|
@simple.update_column :email, 'test@test.test'
|
2012-12-13 11:30:49 +00:00
|
|
|
should_not_send_email(commentor: @simple)
|
2012-01-24 12:15:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not send an e-mail if global notify off' do
|
2012-08-15 14:52:32 +01:00
|
|
|
@project.owner.notifier.update_column :can_notify, false
|
2012-09-25 12:55:30 +01:00
|
|
|
@simple.update_column :email, 'test@test.test'
|
2012-08-15 14:52:32 +01:00
|
|
|
@simple.notifier.update_column :can_notify, false
|
2012-12-13 11:30:49 +00:00
|
|
|
should_not_send_email(commentor: @user)
|
2012-01-24 12:15:56 +00:00
|
|
|
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
|
2012-08-15 14:52:32 +01:00
|
|
|
@simple.notifier.update_column :new_comment_commit_owner, false
|
2012-09-25 12:55:30 +01:00
|
|
|
@simple.update_column :email, 'test@test.test'
|
2012-12-13 11:30:49 +00:00
|
|
|
should_not_send_email(commentor: @user)
|
2012-01-24 12:15:56 +00:00
|
|
|
end
|
|
|
|
end
|
2013-03-27 17:27:02 +00:00
|
|
|
|
|
|
|
context 'automatic issue linking' do
|
|
|
|
before(:each) do
|
|
|
|
@same_name_project = FactoryGirl.create(:project, :name => @project.name)
|
|
|
|
@issue_in_same_name_project = FactoryGirl.create(:issue, :project => @same_name_project, :user => @same_name_project.owner)
|
|
|
|
@another_project = FactoryGirl.create(:project, :owner => @user)
|
|
|
|
@other_user_project = FactoryGirl.create(:project)
|
|
|
|
@issue = FactoryGirl.create(:issue, :project => @project, :user => @user)
|
|
|
|
@second_issue = FactoryGirl.create(:issue, :project => @project, :user => @user)
|
|
|
|
@issue_in_another_project = FactoryGirl.create(:issue, :project => @another_project, :user => @user)
|
|
|
|
@issue_in_other_user_project = FactoryGirl.create(:issue, :project => @other_user_project, :user => @other_user_project.owner)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should create automatic comment' do
|
|
|
|
create_comment_in_commit(@commit, @project, "test link to ##{@issue.serial_id}; [##{@second_issue.serial_id}]")
|
|
|
|
Comment.where(:automatic => true, :commentable_type => 'Issue',
|
2013-04-02 09:35:25 +01:00
|
|
|
:commentable_id => @second_issue.id,
|
|
|
|
:created_from_commit_hash => @commit.id.hex).count.should == 1
|
2013-03-27 17:27:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should create automatic comment in the another project issue' do
|
|
|
|
body = "[#{@another_project.name_with_owner}##{@issue_in_another_project.serial_id}]"
|
|
|
|
create_comment_in_commit(@commit, @project, body)
|
|
|
|
Comment.where(:automatic => true, :commentable_type => 'Issue',
|
2013-04-02 09:35:25 +01:00
|
|
|
:commentable_id => @issue_in_another_project.id,
|
|
|
|
:created_from_commit_hash => @commit.id.hex).count.should == 1
|
2013-03-27 17:27:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should create automatic comment in the same name project issue' do
|
|
|
|
body = "[#{@same_name_project.owner.uname}##{@issue_in_same_name_project.serial_id}]"
|
|
|
|
create_comment_in_commit(@commit, @project, body)
|
|
|
|
Comment.where(:automatic => true, :commentable_type => 'Issue',
|
2013-04-02 09:35:25 +01:00
|
|
|
:commentable_id => @issue_in_same_name_project.id,
|
|
|
|
:created_from_commit_hash => @commit.id.hex).count.should == 1
|
2013-03-27 17:27:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not create duplicate automatic comment' do
|
|
|
|
create_comment_in_commit(@commit, @project, "test link to [##{@second_issue.serial_id}]")
|
|
|
|
create_comment_in_commit(@commit, @project, "test duplicate link to [##{@second_issue.serial_id}]")
|
|
|
|
Comment.where(:automatic => true, :commentable_type => 'Issue',
|
2013-04-02 09:35:25 +01:00
|
|
|
:commentable_id => @second_issue.id,
|
|
|
|
:created_from_commit_hash => @commit.id.hex).count.should == 1
|
2013-03-27 17:27:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not create duplicate automatic comment from one' do
|
|
|
|
create_comment_in_commit(@commit, @project, "test link to [##{@second_issue.serial_id}]; ##{@second_issue.serial_id}")
|
|
|
|
Comment.where(:automatic => true, :commentable_type => 'Issue',
|
2013-04-02 09:35:25 +01:00
|
|
|
:commentable_id => @second_issue.id,
|
|
|
|
:created_from_commit_hash => @commit.id.hex).count.should == 1
|
2013-03-27 17:27:02 +00:00
|
|
|
end
|
|
|
|
it 'should create two automatic comment' do
|
|
|
|
body = "test ##{@second_issue.serial_id}" +
|
|
|
|
" && [#{@another_project.name_with_owner}##{@issue_in_another_project.serial_id}]"
|
|
|
|
create_comment_in_commit(@commit, @project, body)
|
2013-04-02 09:35:25 +01:00
|
|
|
Comment.where(:automatic => true,
|
|
|
|
:created_from_commit_hash => @commit.id.hex).count.should == 2
|
2013-03-27 17:27:02 +00:00
|
|
|
end
|
|
|
|
end
|
2012-01-14 12:36:00 +00:00
|
|
|
end
|
|
|
|
end
|