Merge branch '114-comment_notifications' into user-emails-list

Conflicts:
	app/models/subscribe.rb
	config/locales/en.yml
This commit is contained in:
Alexander Machehin 2012-01-26 14:55:16 +06:00
commit e04b2eb59b
21 changed files with 263 additions and 135 deletions

View File

@ -0,0 +1,30 @@
class CommitSubscribesController < ApplicationController
before_filter :authenticate_user!
load_and_authorize_resource :project
before_filter :find_commit
def create
if Subscribe.set_subscribe_to_commit(@project, @commit, current_user.id, Subscribe::ON)
flash[:notice] = I18n.t("flash.subscribe.commit.saved")
# TODO js
redirect_to commit_path(@project, @commit)
else
flash[:error] = I18n.t("flash.subscribe.saved_error")
redirect_to commit_path(@project, @commit)
end
end
def destroy
Subscribe.set_subscribe_to_commit(@project, @commit, current_user.id, Subscribe::OFF)
flash[:notice] = t("flash.subscribe.commit.destroyed")
redirect_to commit_path(@project, @commit)
end
protected
def find_commit
@commit = @project.git_repository.commit(params[:commit_id])
end
end

View File

@ -1,24 +0,0 @@
class ProjectSubscribesController < ApplicationController
before_filter :authenticate_user!
load_and_authorize_resource :project
load_resource :subscribe
#load_and_authorize_resource :subscribe, :find_by => :user_id
def create
@subscribe = @project.commit_comments_subscribes.build(:user_id => current_user.id)
if @subscribe.save
flash[:notice] = I18n.t("flash.subscribe.saved")
redirect_to @project
else
flash[:error] = I18n.t("flash.subscribe.saved_error")
redirect_to @project
end
end
def destroy
@project.commit_comments_subscribes.where(:user_id => current_user.id).first.destroy # FIXME
flash[:notice] = t("flash.subscribe.destroyed")
redirect_to @project
end
end

View File

@ -13,24 +13,41 @@ class UserMailer < ActionMailer::Base
def new_comment_notification(comment, user)
@user = user
@comment = comment
mail(:to => user.email, :subject => I18n.t("notifications.subjects.new_comment_notification")) do |format|
set_locale
mail(:to => user.email, :subject => I18n.t("notifications.subjects.new_#{comment.commentable.class == Grit::Commit ? 'commit_' : ''}comment_notification")) do |format|
format.html
end
ensure reset_locale
end
def new_issue_notification(issue, user)
@user = user
@issue = issue
set_locale
mail(:to => user.email, :subject => I18n.t("notifications.subjects.new_issue_notification")) do |format|
format.html
end
ensure reset_locale
end
def issue_assign_notification(issue, user)
@user = user
@issue = issue
set_locale
mail(:to => user.email, :subject => I18n.t("notifications.subjects.issue_assign_notification")) do |format|
format.html
end
ensure reset_locale
end
protected
def set_locale
@initial_locale, I18n.locale = I18n.locale, @user.language
end
def reset_locale
I18n.locale = @initial_locale
end
end

View File

@ -6,7 +6,7 @@ class Comment < ActiveRecord::Base
validates :body, :user_id, :commentable_id, :commentable_type, :presence => true
after_create :invoke_helper, :if => "commentable_type == 'Grit::Commit'"
after_create :subscribe_on_reply
after_create :subscribe_users
after_create {|comment| Subscribe.new_comment_notification(comment)}
def helper
@ -17,15 +17,20 @@ class Comment < ActiveRecord::Base
user_id == user.id
end
protected
def subscribe_on_reply
self.commentable.subscribes.create(:user_id => self.user_id) if self.commentable_type == 'Issue' && !self.commentable.subscribes.exists?(:user_id => self.user_id)
self.project.commit_comments_subscribes.create(:user_id => self.user_id) if self.commentable_type == 'Grit::Commit' && !self.project.commit_comments_subscribes.exists?(:user_id => self.user_id)
end
def invoke_helper
self.helper
end
def subscribe_users
if self.commentable.class == Issue
self.commentable.subscribes.create(:user_id => self.user_id) if !self.commentable.subscribes.exists?(:user_id => self.user_id)
elsif self.commentable.class == Grit::Commit
recipients = self.project.relations.by_role('admin').where(:object_type => 'User').map &:object # admins
recipients << self.user << User.where(:email => self.commentable.committer.email).first # commentor and committer
recipients << self.project.owner if self.project.owner_type == 'User' # project owner
recipients.compact.uniq.each {|user| Subscribe.subscribe_user_to_commit(self, user.id)}
end
end
end

View File

@ -5,13 +5,9 @@ class Issue < ActiveRecord::Base
belongs_to :user
has_many :comments, :as => :commentable,
:finder_sql => proc { "comments.commentable_id = '#{self.id}' " +
" AND comments.commentable_type = '#{self.class.name}'"}
#'SELECT comments.* FROM comments ' +
#'WHERE comments.commentable_id = \'#{self.id}\' ' +
#' AND comments.commentable_type = \'#{self.class.name}\' ' +
#'ORDER BY comments.created_at'
has_many :subscribes, :as => :subscribeable
:finder_sql => proc { "comments.commentable_id = '#{self.id}' AND comments.commentable_type = '#{self.class.name}'"}
has_many :subscribes, :as => :subscribeable,
:finder_sql => proc { "subscribes.subscribeable_id = '#{self.id}' AND subscribes.subscribeable_type = '#{self.class.name}'"}
validates :title, :body, :project_id, :presence => true

View File

@ -14,7 +14,6 @@ class Project < ActiveRecord::Base
has_many :relations, :as => :target, :dependent => :destroy
has_many :collaborators, :through => :relations, :source => :object, :source_type => 'User'
has_many :groups, :through => :relations, :source => :object, :source_type => 'Group'
has_many :commit_comments_subscribes, :as => :subscribeable, :class_name => 'Subscribe'
validates :name, :uniqueness => {:scope => [:owner_id, :owner_type]}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-\+\.]+$/ }
validates :owner, :presence => true
@ -31,7 +30,6 @@ class Project < ActiveRecord::Base
after_create :attach_to_personal_repository
after_create :create_git_repo
after_create :subscribe_owner
after_destroy :destroy_git_repo
# after_rollback lambda { destroy_git_repo rescue true if new_record? }
@ -143,6 +141,10 @@ class Project < ActiveRecord::Base
end
end
def owner?(user)
owner_id == user.id
end
protected
def build_path(dir)
@ -161,7 +163,4 @@ class Project < ActiveRecord::Base
FileUtils.rm_rf path
end
def subscribe_owner
Subscribe.subscribe_user(self, self.owner.id)
end
end

View File

@ -12,8 +12,6 @@ class Relation < ActiveRecord::Base
scope :by_target, lambda {|tar| {:conditions => ['target_id = ? AND target_type = ?', tar.id, tar.class.to_s]}}
scope :by_role, lambda {|role| {:conditions => ['role = ?', role]}}
after_create :subscribe_project_admin, :if => "role == 'admin' && object_id == 'User' && targer_type == 'Project'"
def self.create_with_role(object, target, role)
r = new
r.object = object
@ -26,8 +24,4 @@ class Relation < ActiveRecord::Base
def add_default_role
self.role = ROLES.first if role.nil? || role.empty?
end
def subscribe_project_admin
Subscribe.subscribe_user(self.target_id, self.object_id)
end
end

View File

@ -1,31 +1,61 @@
class Subscribe < ActiveRecord::Base
ON = 1
OFF = 0
belongs_to :subscribeable, :polymorphic => true
belongs_to :user
belongs_to :project
validates :status, :inclusion => {:in => 0..1}
scope :on, where(:status => ON)
scope :off, where(:status => OFF)
scope :finder_hack, order('') # FIXME .subscribes - error; .subscribes.finder_hack - success Oo
def self.comment_subscribes(comment)
Subscribe.where(:subscribeable_id => comment.commentable.id, :subscribeable_type => comment.commentable.class.name, :project_id => comment.project)
end
def self.new_comment_notification(comment)
commentable_class = comment.commentable.class
subscribes = comment.commentable.subscribes if commentable_class == Issue
if commentable_class == Grit::Commit
subscribes = comment.project.commit_comments_subscribes(true) # FIXME (true) for rspec
committer = User.includes(:user_emails).where("user_emails.email = ?", comment.commentable.committer.email).first
UserMailer.delay.new_comment_notification(comment, committer) if committer && !comment.own_comment?(committer) && committer.notifier.new_comment_commit_owner && !committer.notifier.can_notify && subscribes.where(:user_id => committer).empty?
Subscribe.new_comment_issue_notification(comment) if commentable_class == Issue
Subscribe.new_comment_commit_notification(comment) if commentable_class == Grit::Commit
end
def self.new_comment_issue_notification(comment)
comment.commentable.subscribes.finder_hack.each do |subscribe|
next if comment.own_comment?(subscribe.user) || !subscribe.user.notifier.can_notify
UserMailer.delay.new_comment_notification(comment, subscribe.user) if subscribe.user.notifier.new_comment_reply
end
end
def self.new_comment_commit_notification(comment)
subscribes = Subscribe.comment_subscribes(comment).on#(true) # FIXME (true) for rspec
subscribes.each do |subscribe|
user = subscribe.user
next if comment.own_comment?(user) || !user.notifier.can_notify
UserMailer.delay.new_comment_notification(comment, user) if commentable_class == Issue && user.notifier.new_comment_reply
UserMailer.delay.new_comment_notification(comment, user) if commentable_class == Grit::Commit && Subscribe.send_notification_for_commit_comment?(subscribe.subscribeable, user, comment)
next if comment.own_comment?(subscribe.user) || !subscribe.user.notifier.can_notify
UserMailer.delay.new_comment_notification(comment, subscribe.user)
end
end
def self.subscribe_user(project_id, user_id)
list = Project.find(project_id).commit_comments_subscribes
list.create(:user_id => user_id) unless list.exists?(:user_id => user_id)
def self.subscribe_user_to_commit(comment, user)
Subscribe.set_subscribe_to_commit(comment.project, comment.commentable, user, Subscribe::ON) if Subscribe.subscribed_to_commit?(comment.project, User.find(user), comment.commentable)
end
def self.send_notification_for_commit_comment?(project, user, comment)
is_owner = (project.owner_id == user.id)
is_commentor = (project.commit_comments_subscribes.exists?(:user_id => user.id))
(is_owner && user.notifier.new_comment_commit_repo_owner) or (is_commentor && user.notifier.new_comment_commit_commentor)
def self.subscribed_to_commit?(project, user, commentable)
is_commentor = (Comment.where(:commentable_type => commentable.class.name, :commentable_id => commentable.id).exists?(:user_id => user.id))
is_committer = (user.email == commentable.committer.email)
return false if user.subscribes.where(:subscribeable_id => commentable.id, :subscribeable_type => commentable.class.name,
:project_id => project.id, :status => Subscribe::OFF).first.present?
(project.owner?(user) && user.notifier.new_comment_commit_repo_owner) or
(is_commentor && user.notifier.new_comment_commit_commentor) or
(is_committer && user.notifier.new_comment_commit_owner)
end
def self.set_subscribe_to_commit(project, commit, user, status)
options = {:subscribeable_id => commit.id, :subscribeable_type => commit.class.name, :user_id => user, :project_id => project.id}
if subscribe = Subscribe.where(options).first # FIXME maybe?
subscribe.update_attribute(:status, status)
else
Subscribe.create(options.merge(:status => status))
end
end
end

View File

@ -23,6 +23,7 @@ class User < ActiveRecord::Base
has_many :projects, :through => :targets, :source => :target, :source_type => 'Project', :autosave => true
has_many :platforms, :through => :targets, :source => :target, :source_type => 'Platform', :autosave => true
has_many :repositories, :through => :targets, :source => :target, :source_type => 'Repository', :autosave => true
has_many :subscribes, :foreign_key => :user_id, :dependent => :destroy
has_many :user_emails, :dependent => :destroy, :as => :emails

View File

@ -28,3 +28,12 @@
- content_for :sidebar, render(:partial => 'git/shared/sidebar')
= render :partial => "comments/list", :locals => {:list => Project.commit_comments(@commit, @project), :project => @project, :commentable => @commit}
%p
%b
= t('layout.issues.subscribe')
\:
- subscribe = current_user.subscribes.where(:subscribeable_id => @commit.id, :subscribeable_type => @commit.class.name.to_s, :project_id => @project, :status => Subscribe::OFF).first
- if subscribe.nil? or Subscribe.subscribed_to_commit?(@project, current_user, @commit)
= link_to t('layout.commits.unsubscribe_btn'), unsubscribe_commit_path(@project, @commit), :method => :delete
- else
= link_to t('layout.commits.subscribe_btn'), subscribe_commit_path(@project, @commit), :method => :post

View File

@ -30,14 +30,6 @@
= t("activerecord.attributes.project.repository")
\:
= git_repo_url @project.git_repo_name
%p
%b
= t('layout.issues.subscribe')
\:
- if @project.commit_comments_subscribes.exists? :user_id => current_user.id
= link_to t('layout.issues.unsubscribe_btn'), project_subscribe_path(@project, current_user.id), :method => :delete
- else
= link_to t('layout.issues.subscribe_btn'), project_subscribes_path(@project), :method => :post
.wat-cf
= link_to image_tag("web-app-theme/icons/application_edit.png", :alt => t("layout.edit")) + " " + t("layout.edit"), edit_project_path(@project), :class => "button" if can? :update, @project
= link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), project_path(@project), :method => "delete", :class => "button", :confirm => t("layout.projects.confirm_delete") if can? :destroy, @project

View File

@ -1,14 +1,14 @@
%p== Hello, #{@user.name}.
%p== Здравствуйте, #{@user.name}.
- if @comment.commentable.class == Issue
- link = link_to @comment.commentable.title, [@comment.commentable.project, @comment.commentable]
- object = 'issue'
- object = 'задаче'
- elsif @comment.commentable.class == Grit::Commit
- link = link_to @comment.commentable.message, commit_path(@comment.project, @comment.commentable_id])
- object = 'commit'
%p User #{ link_to @comment.user.uname, user_path(@comment.user)} added new comment to #{object} #{link}.
- link = link_to @comment.commentable.message, commit_path(@comment.project, @comment.commentable_id)
- object = 'коммиту'
%p #{ link_to @comment.user.uname, user_path(@comment.user)} добавил комментарий к #{object} #{link}.
%p "#{ @comment.body }"
%p== Support Team «ROSA Build System»
%p== Команда поддержки «ROSA Build System»

View File

@ -27,6 +27,7 @@ en:
signed_up: 'You have signed up successfully. If enabled, a confirmation was sent to your e-mail.'
updated: 'You updated your account successfully.'
destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
sign_up_header: 'Signup'
unlocks:
send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
unlocked: 'Your account was successfully unlocked. You are now signed in.'

View File

@ -40,6 +40,7 @@ en:
not_access: Access denied!
owner: Owner
confirm: Sure?
back: Back
settings:
notifier: Notifier setting
notifiers:
@ -127,6 +128,10 @@ en:
subscribe_btn: Subscribe
unsubscribe_btn: Unsubscribe
commits:
subscribe_btn: Subscribe to commit
unsubscribe_btn: Unsubscribe from commit
comments:
confirm_delete: Are you sure to delete the comment?
new_header: New comment
@ -366,7 +371,11 @@ en:
subscribe:
saved: Subscription on notifications for this task is created
saved_error: Subscription create error
destroyed: Subscription on notifications for this task is cleaned
commit:
saved: Subscription on notifications for this commit is created
destroyed: Subscription on notifications for this commit is cleaned
exception_message: Access violation to this page!
@ -692,3 +701,4 @@ en:
new_issue_notification: New task added to project
new_user_notification: Registered on project «%{ project_name }»
issue_assign_notification: New task assigned
new_commit_comment_notification: New comment to commit

View File

@ -366,7 +366,11 @@ ru:
subscribe:
saved: Вы подписаны на оповещения для этой задачи
saved_error: При создании подписки произошла ошибка
destroyed: Подписка на оповещения для этой задачи убрана
commit:
saved: Вы подписаны на оповещения для этого коммита
destroyed: Подписка на оповещения для этого коммита убрана
exception_message: У Вас нет доступа к этой странице!
@ -695,3 +699,4 @@ ru:
new_issue_notification: Новая задача добавлена к проекту
new_user_notification: Регистрация на проекте «%{ project_name }»
issue_assign_notification: Вам назначили задачу
new_commit_comment_notification: Новый комментарий к коммиту

View File

@ -92,7 +92,6 @@ Rosa::Application.routes.draw do
end
resource :repo, :controller => "git/repositories", :only => [:show]
resources :build_lists, :only => [:index, :new, :create]
resources :subscribes, :only => [:create, :destroy], :controller => 'project_subscribes'
resources :collaborators, :only => [:index, :edit, :update, :add] do
collection do
@ -160,6 +159,9 @@ Rosa::Application.routes.draw do
match '/projects/:project_id/git/commit/:commit_id/comments/:id(.:format)', :controller => "comments", :action => :update, :as => :project_commit_comment, :via => :put
match '/projects/:project_id/git/commit/:commit_id/comments/:id(.:format)', :controller => "comments", :action => :destroy, :via => :delete
match '/projects/:project_id/git/commit/:commit_id/comments(.:format)', :controller => "comments", :action => :create, :as => :project_commit_comments, :via => :post
# Commits subscribe
match '/projects/:project_id/git/commit/:commit_id/subscribe', :controller => "commit_subscribes", :action => :create, :defaults => { :format => :html }, :as => :subscribe_commit, :via => :post
match '/projects/:project_id/git/commit/:commit_id/unsubscribe', :controller => "commit_subscribes", :action => :destroy, :defaults => { :format => :html }, :as => :unsubscribe_commit, :via => :delete
# Blobs
match '/projects/:project_id/git/blob/:treeish/*path', :controller => "git/blobs", :action => :show, :treeish => /[0-9a-zA-Z_.\-]*/, :defaults => { :treeish => :master }, :as => :blob
match '/projects/:project_id/git/commit/blob/:commit_hash/*path', :controller => "git/blobs", :action => :show, :project_name => /[0-9a-zA-Z_.\-]*/, :as => :blob_commit

View File

@ -0,0 +1,9 @@
class AddStatusToSubscribe < ActiveRecord::Migration
def self.up
add_column :subscribes, :status, :integer, :default => 1
end
def self.down
remove_column :subscribes, :status
end
end

View File

@ -0,0 +1,9 @@
class AddProjectToSubscribe < ActiveRecord::Migration
def self.up
add_column :subscribes, :project_id, :integer
end
def self.down
remove_column :subscribes, :project_id
end
end

View File

@ -0,0 +1,9 @@
class ChangeSubscribeableToString < ActiveRecord::Migration
def self.up
change_column :subscribes, :subscribeable_id, :string
end
def self.down
change_column :subscribes, :subscribeable_id, :integer
end
end

View File

@ -278,6 +278,19 @@ ActiveRecord::Schema.define(:version => 20120123161250) do
t.datetime "updated_at"
end
create_table "role_lines", :force => true do |t|
t.integer "role_id"
t.integer "relation_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "roles", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "rpms", :force => true do |t|
t.string "name", :null => false
t.integer "arch_id", :null => false

View File

@ -55,7 +55,7 @@ describe Comment do
@stranger = Factory(:user)
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
it 'should create comment' do
@ -85,13 +85,12 @@ describe Comment do
end
context 'for disabled notify setting new_comment_commit_repo_owner' do
it 'should send an e-mail' do
it 'should not send an e-mail' do
ActionMailer::Base.deliveries = []
@user.notifier.update_attribute :new_comment_commit_repo_owner, false
comment = Comment.create(:user => @stranger, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id)
ActionMailer::Base.deliveries.count.should == 1 # cache project.commit_comments_subscribes ...
ActionMailer::Base.deliveries.last.to.include?(@user.email).should == true
ActionMailer::Base.deliveries.count.should == 0
end
end
@ -101,7 +100,7 @@ describe Comment do
@user.notifier.update_attribute :new_comment_commit_owner, false
comment = Comment.create(:user => @stranger, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id)
ActionMailer::Base.deliveries.count.should == 1 # cache project.commit_comments_subscribes ...
ActionMailer::Base.deliveries.count.should == 1
ActionMailer::Base.deliveries.last.to.include?(@user.email).should == true
end
end
@ -112,7 +111,7 @@ describe Comment do
@user.notifier.update_attribute :new_comment_commit_commentor, false
comment = Comment.create(:user => @stranger, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id)
ActionMailer::Base.deliveries.count.should == 1 # cache project.commit_comments_subscribes ...
ActionMailer::Base.deliveries.count.should == 1
ActionMailer::Base.deliveries.last.to.include?(@user.email).should == true
end
end
@ -125,14 +124,14 @@ describe Comment do
@user.notifier.update_attribute :new_comment_commit_commentor, false
comment = Comment.create(:user => @stranger, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id)
ActionMailer::Base.deliveries.count.should == 0 # cache project.commit_comments_subscribes ...
ActionMailer::Base.deliveries.count.should == 0
end
end
context 'for unsubscribe project' do
context 'for unsubscribe commit' do
it 'should not send an e-mail' do
ActionMailer::Base.deliveries = []
@project.commit_comments_subscribes.where(:user_id => @user).first.destroy # FIXME
Subscribe.set_subscribe_to_commit(@project, @commit, @user.id, Subscribe::OFF)
comment = Comment.create(:user => @stranger, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id)
ActionMailer::Base.deliveries.count.should == 0 # cache project.commit_comments_subscribes ...
@ -194,8 +193,7 @@ describe Comment do
@user.notifier.update_attribute :new_comment_commit_repo_owner, false
comment = Comment.create(:user => @stranger, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id)
ActionMailer::Base.deliveries.count.should == 1 # cache project.commit_comments_subscribes ...
ActionMailer::Base.deliveries.last.to.include?(@user.email).should == true
ActionMailer::Base.deliveries.count.should == 0
end
end
@ -229,17 +227,17 @@ describe Comment do
@user.notifier.update_attribute :new_comment_commit_commentor, false
comment = Comment.create(:user => @stranger, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id)
ActionMailer::Base.deliveries.count.should == 0 # cache project.commit_comments_subscribes ...
ActionMailer::Base.deliveries.count.should == 0
end
end
context 'for unsubscribe project' do
it 'should not send an e-mail' do
ActionMailer::Base.deliveries = []
@project.commit_comments_subscribes.where(:user_id => @user).first.destroy # FIXME
Subscribe.set_subscribe_to_commit(@project, @commit, @user.id, Subscribe::OFF)
comment = Comment.create(:user => @stranger, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id)
ActionMailer::Base.deliveries.count.should == 0 # cache project.commit_comments_subscribes ...
ActionMailer::Base.deliveries.count.should == 0
end
end
@ -316,44 +314,6 @@ describe Comment do
ActionMailer::Base.deliveries.last.to.include?(@simple.email).should == true
end
context 'for committer' do
it 'should send a one e-mail' do
ActionMailer::Base.deliveries = []
@stranger.update_attribute :email, 'code@tpope.net'
comment = Comment.create(:user => @user, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id)
ActionMailer::Base.deliveries.count.should == 1
ActionMailer::Base.deliveries.last.to.include?(@stranger.email).should == true
end
it 'should not send an e-mail for own comment' do
ActionMailer::Base.deliveries = []
#@project.owner.notifier.update_attribute :can_notify, false
@stranger.update_attribute :email, 'code@tpope.net'
comment = Comment.create(:user => @stranger, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id)
ActionMailer::Base.deliveries.count.should == 0
end
it 'should not send an e-mail if global notify off' do
ActionMailer::Base.deliveries = []
@project.owner.notifier.update_attribute :can_notify, false
@stranger.update_attribute :email, 'code@tpope.net'
comment = Comment.create(:user => @user, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id)
ActionMailer::Base.deliveries.count.should == 0
end
it 'should not send an e-mail if notify for my commits off' do
ActionMailer::Base.deliveries = []
@stranger.notifier.update_attribute :new_comment_commit_owner, false
@stranger.update_attribute :email, 'code@tpope.net'
comment = Comment.create(:user => @user, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id)
ActionMailer::Base.deliveries.count.should == 0
end
end
it 'should send an e-mail when subscribed to project' do
ActionMailer::Base.deliveries = []
@project.owner.notifier.update_attribute :can_notify, false
@ -361,7 +321,7 @@ describe Comment do
@stranger.notifier.update_attribute :new_comment_commit_owner, false
#@stranger.notifier.update_attribute :new_comment_commit_commentor, false
@project.commit_comments_subscribes.create(:user_id => @stranger.id)
Subscribe.set_subscribe_to_commit(@project, @commit, @stranger.id, Subscribe::ON)
comment = Comment.create(:user => @project.owner, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id)
ActionMailer::Base.deliveries.count.should == 1
@ -371,11 +331,72 @@ describe Comment do
it 'should not send an e-mail for own comment' do
ActionMailer::Base.deliveries = []
#@project.owner.notifier.update_attribute :can_notify, false
@project.commit_comments_subscribes.create(:user_id => @stranger.id)
Subscribe.set_subscribe_to_commit(@project, @commit, @stranger.id, Subscribe::ON)
comment = Comment.create(:user => @owner, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id)
ActionMailer::Base.deliveries.count.should == 0
end
end
context 'for committer' do
it 'should send an e-mail' do
ActionMailer::Base.deliveries = []
@stranger.update_attribute :email, 'code@tpope.net'
comment = Comment.create(:user => @user, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id)
ActionMailer::Base.deliveries.count.should == 1
ActionMailer::Base.deliveries.last.to.include?(@stranger.email).should == true
end
it 'should send an e-mail with user locale' do
ActionMailer::Base.deliveries = []
@stranger.update_attribute :email, 'code@tpope.net'
@stranger.update_attribute :language, 'ru'
comment = Comment.create(:user => @user, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id)
ActionMailer::Base.deliveries.count.should == 1
ActionMailer::Base.deliveries.last.to.include?(@stranger.email).should == true
ActionMailer::Base.deliveries.last.subject.include?('Новый комментарий к коммиту').should == true
end
it 'should send a one e-mail when subscribed to commit' do
ActionMailer::Base.deliveries = []
Subscribe.set_subscribe_to_commit(@project, @commit, @stranger.id, Subscribe::ON)
@stranger.update_attribute :email, 'code@tpope.net'
comment = Comment.create(:user => @user, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id)
ActionMailer::Base.deliveries.count.should == 1
ActionMailer::Base.deliveries.last.to.include?(@stranger.email).should == true
end
it 'should not send an e-mail for own comment' do
ActionMailer::Base.deliveries = []
#@project.owner.notifier.update_attribute :can_notify, false
@stranger.update_attribute :email, 'code@tpope.net'
comment = Comment.create(:user => @stranger, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id)
ActionMailer::Base.deliveries.count.should == 1
ActionMailer::Base.deliveries.last.to.include?(@stranger.email).should == false
end
it 'should not send an e-mail if global notify off' do
ActionMailer::Base.deliveries = []
@project.owner.notifier.update_attribute :can_notify, false
@stranger.update_attribute :email, 'code@tpope.net'
@stranger.notifier.update_attribute :can_notify, false
comment = Comment.create(:user => @user, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id)
ActionMailer::Base.deliveries.count.should == 0
end
it 'should not send an e-mail if notify for my commits off' do
ActionMailer::Base.deliveries = []
@stranger.notifier.update_attribute :new_comment_commit_owner, false
@stranger.update_attribute :email, 'code@tpope.net'
comment = Comment.create(:user => @user, :body => 'hello!', :project => @project,
:commentable_type => @commit.class.name, :commentable_id => @commit.id)
ActionMailer::Base.deliveries.count.should == 0
end
end
end
end