@@ -81,6 +81,13 class WatcherTest < ActiveSupport::TestCase | |||||
81 | assert issue.watched_by?(User.find(1)) |
|
81 | assert issue.watched_by?(User.find(1)) | |
82 | end |
|
82 | end | |
83 |
|
83 | |||
|
84 | def test_watcher_user_ids_should_make_ids_uniq | |||
|
85 | issue = Issue.new(:project => Project.find(1), :tracker_id => 1, :subject => "test", :author => User.find(2)) | |||
|
86 | issue.watcher_user_ids = ['1', '3', '1'] | |||
|
87 | issue.save! | |||
|
88 | assert_equal 2, issue.watchers.count | |||
|
89 | end | |||
|
90 | ||||
84 | def test_addable_watcher_users |
|
91 | def test_addable_watcher_users | |
85 | addable_watcher_users = @issue.addable_watcher_users |
|
92 | addable_watcher_users = @issue.addable_watcher_users | |
86 | assert_kind_of Array, addable_watcher_users |
|
93 | assert_kind_of Array, addable_watcher_users |
@@ -9,8 +9,6 module Redmine | |||||
9 | module ClassMethods |
|
9 | module ClassMethods | |
10 | def acts_as_watchable(options = {}) |
|
10 | def acts_as_watchable(options = {}) | |
11 | return if self.included_modules.include?(Redmine::Acts::Watchable::InstanceMethods) |
|
11 | return if self.included_modules.include?(Redmine::Acts::Watchable::InstanceMethods) | |
12 | send :include, Redmine::Acts::Watchable::InstanceMethods |
|
|||
13 |
|
||||
14 | class_eval do |
|
12 | class_eval do | |
15 | has_many :watchers, :as => :watchable, :dependent => :delete_all |
|
13 | has_many :watchers, :as => :watchable, :dependent => :delete_all | |
16 | has_many :watcher_users, :through => :watchers, :source => :user, :validate => false |
|
14 | has_many :watcher_users, :through => :watchers, :source => :user, :validate => false | |
@@ -21,6 +19,8 module Redmine | |||||
21 | } |
|
19 | } | |
22 | attr_protected :watcher_ids, :watcher_user_ids |
|
20 | attr_protected :watcher_ids, :watcher_user_ids | |
23 | end |
|
21 | end | |
|
22 | send :include, Redmine::Acts::Watchable::InstanceMethods | |||
|
23 | alias_method_chain :watcher_user_ids=, :uniq_ids | |||
24 | end |
|
24 | end | |
25 | end |
|
25 | end | |
26 |
|
26 | |||
@@ -54,6 +54,14 module Redmine | |||||
54 | watching ? add_watcher(user) : remove_watcher(user) |
|
54 | watching ? add_watcher(user) : remove_watcher(user) | |
55 | end |
|
55 | end | |
56 |
|
56 | |||
|
57 | # Overrides watcher_user_ids= to make user_ids uniq | |||
|
58 | def watcher_user_ids_with_uniq_ids=(user_ids) | |||
|
59 | if user_ids.is_a?(Array) | |||
|
60 | user_ids = user_ids.uniq | |||
|
61 | end | |||
|
62 | send :watcher_user_ids_without_uniq_ids=, user_ids | |||
|
63 | end | |||
|
64 | ||||
57 | # Returns true if object is watched by +user+ |
|
65 | # Returns true if object is watched by +user+ | |
58 | def watched_by?(user) |
|
66 | def watched_by?(user) | |
59 | !!(user && self.watcher_user_ids.detect {|uid| uid == user.id }) |
|
67 | !!(user && self.watcher_user_ids.detect {|uid| uid == user.id }) |
General Comments 0
You need to be logged in to leave comments.
Login now