[#200] fix callbacks & add some specs

This commit is contained in:
Alexander Machehin 2013-07-10 23:44:18 +06:00
parent 3372f3ee9c
commit 939f0dfe05
4 changed files with 21 additions and 7 deletions

View File

@ -5,11 +5,11 @@ module Modules::Observers::ActivityFeed::Issue
included do included do
after_commit :new_issue_notifications, :on => :create after_commit :new_issue_notifications, :on => :create
after_commit :send_assign_notifications, :on => :create after_commit :send_assign_notifications, :on => :create, :if => Proc.new { |i| i.assignee }
after_commit -> { send_assign_notifications(:update) }, :on => :update after_commit -> { send_assign_notifications(:update) }, :on => :update
after_commit :send_hooks, :on => :create after_commit :send_hooks, :on => :create
after_commit -> { send_hooks(:update) }, :on => :update, :if => :status_changed? after_commit -> { send_hooks(:update) }, :on => :update, :if => Proc.new { |i| i.previous_changes['status'].present? }
end end
private private
@ -39,7 +39,7 @@ module Modules::Observers::ActivityFeed::Issue
end end
def send_assign_notifications(action = :create) def send_assign_notifications(action = :create)
if(action == :create && assignee_id) || assignee_id_changed? if(action == :create && assignee_id) || previous_changes['assignee_id'].present?
if assignee.notifier.issue_assign && assignee.notifier.can_notify if assignee.notifier.issue_assign && assignee.notifier.can_notify
UserMailer.issue_assign_notification(self, assignee).deliver UserMailer.issue_assign_notification(self, assignee).deliver
end end
@ -58,11 +58,10 @@ module Modules::Observers::ActivityFeed::Issue
) )
end end
# dont remove outdated issues link # dont remove outdated issues link
Comment.create_link_on_issues_from_item(self) if title_changed? || body_changed? Comment.create_link_on_issues_from_item(self) if previous_changes['title'].present? || previous_changes['body'].present?
end end
def send_hooks(action = :create) def send_hooks(action = :create)
project.hooks.each{ |h| h.receive_issues(self, action) } project.hooks.each{ |h| h.receive_issues(self, action) }
end end
end end

View File

@ -291,7 +291,6 @@ describe Api::V1::PullRequestsController do
it 'should send email message to new assignee' do it 'should send email message to new assignee' do
put :update, @update_params.deep_merge(:pull_request => {:assignee_id => @project_reader.id}) put :update, @update_params.deep_merge(:pull_request => {:assignee_id => @project_reader.id})
@project.pull_requests.last.issue.send(:new_issue_notifications)
@project.pull_requests.last.issue.send(:send_assign_notifications) @project.pull_requests.last.issue.send(:send_assign_notifications)
ActionMailer::Base.deliveries.count.should == 1 ActionMailer::Base.deliveries.count.should == 1
end end

View File

@ -312,7 +312,6 @@ describe Projects::PullRequestsController do
it 'should send email message to new assignee' do it 'should send email message to new assignee' do
put :update, @update_params.deep_merge(:pull_request => {:assignee_id => @project_reader.id}) put :update, @update_params.deep_merge(:pull_request => {:assignee_id => @project_reader.id})
@project.pull_requests.last.issue.send(:new_issue_notifications)
@project.pull_requests.last.issue.send(:send_assign_notifications) @project.pull_requests.last.issue.send(:send_assign_notifications)
ActionMailer::Base.deliveries.count.should == 1 ActionMailer::Base.deliveries.count.should == 1
end end

View File

@ -33,6 +33,23 @@ describe Issue do
create_issue(@user) create_issue(@user)
ActionMailer::Base.deliveries.count.should == 0 ActionMailer::Base.deliveries.count.should == 0
end end
it 'should create automatic comment from another issue' do
create_issue(@user)
another_issue = FactoryGirl.create(:issue, :project => @project, :title => "[##{@issue.serial_id}]")
Comment.where(:automatic => true, :commentable_type => 'Issue',
:created_from_issue_id => another_issue.id).count.should == 1
end
it 'should create automatic comment after updating another issue body' do
create_issue(@user)
another_issue = FactoryGirl.create(:issue, :project => @project)
another_issue.update_attribute(:title, "[##{@issue.serial_id}]")
another_issue.send(:send_assign_notifications)
Comment.where(:automatic => true, :commentable_type => 'Issue',
:created_from_issue_id => another_issue.id).count.should == 1
end
end end
context 'for member-group' do context 'for member-group' do