#345: fixed some specs, etc

This commit is contained in:
Vokhmin Alexey V 2014-03-18 00:18:46 +04:00
parent e6934057b4
commit c672aaa0ec
11 changed files with 73 additions and 55 deletions

View File

@ -112,11 +112,15 @@ group :development do
#gem 'ruby-dbus' if RUBY_PLATFORM =~ /linux/i # Error at deploy #gem 'ruby-dbus' if RUBY_PLATFORM =~ /linux/i # Error at deploy
end end
group :development, :test do
gem 'rspec-rails', '~> 2.14.1'
end
group :test do group :test do
gem 'rspec-rails', '~> 2.14.1', group: 'development'
gem 'factory_girl_rails', '~> 4.4.1' gem 'factory_girl_rails', '~> 4.4.1'
gem 'rr', '~> 1.1.2' gem 'rr', '~> 1.1.2'
gem 'shoulda' gem 'shoulda'
gem 'shoulda-matchers'
gem 'mock_redis', '~> 0.11' gem 'mock_redis', '~> 0.11'
gem 'rake' gem 'rake'
end end

View File

@ -66,7 +66,7 @@ GEM
angular-i18n (0.1.2) angular-i18n (0.1.2)
angularjs-rails (1.2.14) angularjs-rails (1.2.14)
arel (4.0.2) arel (4.0.2)
atomic (1.1.15) atomic (1.1.16)
attr_encrypted (1.3.2) attr_encrypted (1.3.2)
encryptor (>= 1.3.0) encryptor (>= 1.3.0)
bcrypt (3.1.7) bcrypt (3.1.7)
@ -534,6 +534,7 @@ DEPENDENCIES
schema_plus (~> 1.4.0) schema_plus (~> 1.4.0)
shotgun shotgun
shoulda shoulda
shoulda-matchers
skype skype
soundmanager-rails soundmanager-rails
state_machine (~> 1.2) state_machine (~> 1.2)

View File

@ -18,12 +18,12 @@ class UserMailer < ActionMailer::Base
end end
end end
def new_comment_notification(comment, user) def new_comment_notification(comment, user_id)
@user, @comment = user, comment @user, @comment = User.find(user_id), comment
subject = @comment.issue_comment? ? subject_for_issue(@comment.commentable) : subject = @comment.issue_comment? ? subject_for_issue(@comment.commentable) :
I18n.t('notifications.subjects.new_commit_comment_notification') I18n.t('notifications.subjects.new_commit_comment_notification')
mail( mail(
to: email_with_name(user, user.email), to: email_with_name(@user, @user.email),
subject: subject, subject: subject,
from: email_with_name(comment.user) from: email_with_name(comment.user)
) do |format| ) do |format|

View File

@ -144,7 +144,7 @@ class BuildList < ActiveRecord::Base
serialize :extra_build_lists, Array serialize :extra_build_lists, Array
serialize :extra_params, Hash serialize :extra_params, Hash
after_commit :place_build, on: :create after_create :place_build
after_destroy :remove_container after_destroy :remove_container
state_machine :status, initial: :waiting_for_response do state_machine :status, initial: :waiting_for_response do

View File

@ -7,7 +7,7 @@ class Comment < ActiveRecord::Base
# #Num # #Num
ISSUES_REGEX = /(?:[a-zA-Z0-9\-_]*\/)?(?:[a-zA-Z0-9\-_]*)?#[0-9]+/ ISSUES_REGEX = /(?:[a-zA-Z0-9\-_]*\/)?(?:[a-zA-Z0-9\-_]*)?#[0-9]+/
belongs_to :commentable, polymorphic: true, touch: true belongs_to :commentable, polymorphic: true
belongs_to :user belongs_to :user
belongs_to :project belongs_to :project
serialize :data serialize :data
@ -17,6 +17,7 @@ class Comment < ActiveRecord::Base
scope :for_commit, ->(c) { where(commentable_id: c.id.hex, commentable_type: c.class) } scope :for_commit, ->(c) { where(commentable_id: c.id.hex, commentable_type: c.class) }
default_scope { order(:created_at) } default_scope { order(:created_at) }
before_save :touch_commentable
after_create :subscribe_on_reply, unless: ->(c) { c.commit_comment? } after_create :subscribe_on_reply, unless: ->(c) { c.commit_comment? }
after_create :subscribe_users after_create :subscribe_users
@ -186,8 +187,12 @@ class Comment < ActiveRecord::Base
protected protected
def touch_commentable
commentable.touch unless commit_comment?
end
def subscribe_on_reply def subscribe_on_reply
commentable.subscribes.create(user_id: user_id) if !commentable.subscribes.exists?(user_id: user_id) commentable.subscribes.where(user_id: user_id).first_or_create
end end
def subscribe_users def subscribe_users
@ -195,7 +200,7 @@ class Comment < ActiveRecord::Base
commentable.subscribes.create(user: user) if !commentable.subscribes.exists?(user_id: user.id) commentable.subscribes.create(user: user) if !commentable.subscribes.exists?(user_id: user.id)
elsif commit_comment? elsif commit_comment?
recipients = project.admins recipients = project.admins
recipients << user << User.where(email: commentable.try(:committer).try(:email)).first # commentor and committer recipients << user << User.find_by_email(commentable.try(:committer).try(:email)) # commentor and committer
recipients.compact.uniq.each do |user| recipients.compact.uniq.each do |user|
options = {project_id: project.id, subscribeable_id: commentable_id, subscribeable_type: commentable.class.name, user_id: user.id} options = {project_id: project.id, subscribeable_id: commentable_id, subscribeable_type: commentable.class.name, user_id: user.id}
Subscribe.subscribe_to_commit(options) if Subscribe.subscribed_to_commit?(project, user, commentable) Subscribe.subscribe_to_commit(options) if Subscribe.subscribed_to_commit?(project, user, commentable)

View File

@ -2,7 +2,7 @@ module Feed::Comment
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do
after_commit :new_comment_notifications, on: :create after_create :new_comment_notifications
# dont remove outdated issues link # dont remove outdated issues link
after_update -> { Comment.create_link_on_issues_from_item(self) } after_update -> { Comment.create_link_on_issues_from_item(self) }
end end
@ -13,49 +13,54 @@ module Feed::Comment
return if automatic? return if automatic?
if issue_comment? if issue_comment?
commentable.subscribes.each do |subscribe| commentable.subscribes.each do |subscribe|
if user_id != subscribe.user_id if user_id != subscribe.user_id && can_notify_on_new_comment?(subscribe)
UserMailer.new_comment_notification(self, subscribe.user).deliver if can_notify_on_new_comment?(subscribe) UserMailer.new_comment_notification(self, subscribe.user_id).deliver
ActivityFeed.create( ActivityFeed.create(
user: subscribe.user, {
kind: 'new_comment_notification', user_id: subscribe.user_id,
data: { kind: 'new_comment_notification',
user_name: user.name, data: {
user_email: user.email, user_name: user.name,
user_id: user_id, user_email: user.email,
comment_body: body, user_id: user_id,
issue_title: commentable.title, comment_body: body,
issue_serial_id: commentable.serial_id, issue_title: commentable.title,
project_id: commentable.project.id, issue_serial_id: commentable.serial_id,
comment_id: id, project_id: commentable.project.id,
project_name: project.name, comment_id: id,
project_owner: project.owner.uname project_name: project.name,
} project_owner: project.owner.uname
}
}, without_protection: true
) )
end end
end end
elsif commit_comment? elsif commit_comment?
Subscribe.comment_subscribes(self).where(status: true).each do |subscribe| Subscribe.comment_subscribes(self).where(status: true).each do |subscribe|
next if own_comment?(subscribe.user) next if !subscribe.user_id || own_comment?(subscribe.user)
if subscribe.user.notifier.can_notify and if subscribe.user.notifier.can_notify &&
( (subscribe.project.owner?(subscribe.user) && subscribe.user.notifier.new_comment_commit_repo_owner) or ( (subscribe.project.owner?(subscribe.user) && subscribe.user.notifier.new_comment_commit_repo_owner) ||
(subscribe.user.commentor?(self.commentable) && subscribe.user.notifier.new_comment_commit_commentor) or (subscribe.user.commentor?(self.commentable) && subscribe.user.notifier.new_comment_commit_commentor) ||
(subscribe.user.committer?(self.commentable) && subscribe.user.notifier.new_comment_commit_owner) ) (subscribe.user.committer?(self.commentable) && subscribe.user.notifier.new_comment_commit_owner) )
UserMailer.new_comment_notification(self, subscribe.user).deliver UserMailer.new_comment_notification(self, subscribe.user_id).deliver
end end
ActivityFeed.create( ActivityFeed.create(
user: subscribe.user, {
kind: 'new_comment_commit_notification', user_id: subscribe.user_id,
data: { kind: 'new_comment_commit_notification',
user_name: user.name, data: {
user_email: user.email, user_name: user.name,
user_id: user_id, user_email: user.email,
comment_body: body, user_id: user_id,
commit_message: commentable.message, comment_body: body,
commit_id: commentable.id, commit_message: commentable.message,
project_id: project.id, commit_id: commentable.id,
comment_id: id, project_id: project.id,
project_name: project.name, comment_id: id,
project_owner: project.owner.uname} project_name: project.name,
project_owner: project.owner.uname
}
}, without_protection: true
) )
end end
end end
@ -63,6 +68,7 @@ module Feed::Comment
end end
def can_notify_on_new_comment?(subscribe) def can_notify_on_new_comment?(subscribe)
User.find(subscribe.user).notifier.new_comment && User.find(subscribe.user).notifier.can_notify notifier = SettingsNotifier.find_by_user_id(subscribe.user_id)
notifier && notifier.new_comment && notifier.can_notify
end end
end end

View File

@ -2,13 +2,13 @@ module Feed::Issue
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do
after_commit :new_issue_notifications, on: :create after_create :new_issue_notifications
after_commit :send_assign_notifications, on: :create, if: ->(i) { i.assignee } after_create :send_assign_notifications, if: ->(i) { i.assignee }
after_commit -> { send_assign_notifications(:update) }, on: :update after_update -> { send_assign_notifications(:update) }
after_commit :send_hooks, on: :create after_create :send_hooks
after_commit -> { send_hooks(:update) }, on: :update, if: ->(i) { i.previous_changes['status'].present? } after_update -> { send_hooks(:update) }, if: ->(i) { i.previous_changes['status'].present? }
end end
private private

View File

@ -2,7 +2,7 @@ module Feed::User
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do
after_commit :new_user_notification, on: :create after_create :new_user_notification
end end
private private

View File

@ -11,8 +11,8 @@ module Git
validates_attachment_content_type :srpm, content_type: ['application/octet-stream', "application/x-rpm", "application/x-redhat-package-manager"], message: I18n.t('layout.invalid_content_type') validates_attachment_content_type :srpm, content_type: ['application/octet-stream', "application/x-rpm", "application/x-redhat-package-manager"], message: I18n.t('layout.invalid_content_type')
after_create :create_git_repo after_create :create_git_repo
after_commit(on: :create) {|p| p.fork_git_repo unless p.is_root?} # later with resque after_create {|p| p.fork_git_repo unless p.is_root?} # later with resque
after_commit(on: :create) {|p| p.import_attached_srpm if p.srpm?} # later with resque # should be after create_git_repo after_create {|p| p.import_attached_srpm if p.srpm?} # later with resque # should be after create_git_repo
after_destroy :destroy_git_repo after_destroy :destroy_git_repo
# after_rollback -> { destroy_git_repo rescue true if new_record? } # after_rollback -> { destroy_git_repo rescue true if new_record? }

View File

@ -19,7 +19,7 @@ class MassBuild < ActiveRecord::Base
validates :projects_list, length: {maximum: 500_000}, presence: true validates :projects_list, length: {maximum: 500_000}, presence: true
validates_inclusion_of :auto_publish, :increase_release_tag, in: [true, false] validates_inclusion_of :auto_publish, :increase_release_tag, in: [true, false]
after_commit :build_all, on: :create after_create :build_all
before_validation :set_data, on: :create before_validation :set_data, on: :create
COUNT_STATUSES = [ COUNT_STATUSES = [

View File

@ -3,6 +3,8 @@ class Subscribe < ActiveRecord::Base
belongs_to :user belongs_to :user
belongs_to :project belongs_to :project
attr_accessible :status
def commit_subscribe? def commit_subscribe?
subscribeable_type == 'Grit::Commit' subscribeable_type == 'Grit::Commit'
end end
@ -35,7 +37,7 @@ class Subscribe < ActiveRecord::Base
if subscribe = Subscribe.where(options).first if subscribe = Subscribe.where(options).first
subscribe.update_attributes(status: status) subscribe.update_attributes(status: status)
else else
Subscribe.create(options.merge(status: status)) Subscribe.create(options.merge(status: status), without_protection: true)
end end
end end