redmine_crm 0.0.23 → 0.0.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/doc/CHANGELOG +4 -0
  4. data/lib/redmine_crm.rb +28 -20
  5. data/lib/redmine_crm/{rcrm_acts_as_taggable.rb → acts_as_taggable/rcrm_acts_as_taggable.rb} +93 -87
  6. data/lib/redmine_crm/acts_as_taggable/tag.rb +81 -0
  7. data/lib/redmine_crm/acts_as_taggable/tag_list.rb +111 -0
  8. data/lib/redmine_crm/acts_as_taggable/tagging.rb +16 -0
  9. data/lib/redmine_crm/acts_as_viewed/rcrm_acts_as_viewed.rb +274 -0
  10. data/lib/redmine_crm/{rcrm_acts_as_votable.rb → acts_as_votable/rcrm_acts_as_votable.rb} +8 -11
  11. data/lib/redmine_crm/acts_as_votable/rcrm_acts_as_voter.rb +20 -0
  12. data/lib/redmine_crm/{votable.rb → acts_as_votable/votable.rb} +36 -47
  13. data/lib/redmine_crm/{vote.rb → acts_as_votable/vote.rb} +7 -10
  14. data/lib/redmine_crm/{voter.rb → acts_as_votable/voter.rb} +29 -34
  15. data/lib/redmine_crm/currency/formatting.rb +0 -3
  16. data/lib/redmine_crm/currency/heuristics.rb +1 -1
  17. data/lib/redmine_crm/currency/loader.rb +1 -1
  18. data/lib/redmine_crm/helpers/tags_helper.rb +1 -3
  19. data/lib/redmine_crm/helpers/vote_helper.rb +29 -32
  20. data/lib/redmine_crm/liquid/drops/issues_drop.rb +66 -0
  21. data/lib/redmine_crm/liquid/drops/news_drop.rb +54 -0
  22. data/lib/redmine_crm/liquid/drops/projects_drop.rb +86 -0
  23. data/lib/redmine_crm/liquid/drops/users_drop.rb +72 -0
  24. data/lib/redmine_crm/liquid/filters/arrays.rb +178 -0
  25. data/lib/redmine_crm/liquid/filters/base.rb +208 -0
  26. data/lib/redmine_crm/version.rb +1 -1
  27. data/redmine_crm.gemspec +1 -1
  28. data/test/{acts_as_taggable_test.rb → acts_as_taggable/rcrm_acts_as_taggable_test.rb} +114 -151
  29. data/test/acts_as_taggable/tag_list_test.rb +38 -0
  30. data/test/acts_as_taggable/tag_test.rb +74 -0
  31. data/test/acts_as_taggable/tagging_test.rb +15 -0
  32. data/test/{viewed_test.rb → acts_as_viewed/rcrm_acts_as_viewed_test.rb} +17 -15
  33. data/test/{votable_test.rb → acts_as_votable/rcrm_acts_as_votable_test.rb} +3 -3
  34. data/test/acts_as_votable/rcrm_acts_as_voter_test.rb +12 -0
  35. data/test/{votable_model_test.rb → acts_as_votable/votable_test.rb} +4 -4
  36. data/test/{voter_model_test.rb → acts_as_votable/voter_test.rb} +7 -7
  37. data/test/currency_test.rb +10 -10
  38. data/test/fixtures/issue.rb +6 -2
  39. data/test/fixtures/issues.yml +13 -1
  40. data/test/fixtures/news.rb +3 -0
  41. data/test/fixtures/news.yml +8 -0
  42. data/test/fixtures/project.rb +8 -0
  43. data/test/fixtures/projects.yml +10 -0
  44. data/test/fixtures/user.rb +5 -1
  45. data/test/fixtures/users.yml +3 -2
  46. data/test/fixtures/vote_classes.rb +2 -3
  47. data/test/liquid/drops/issues_drop_test.rb +34 -0
  48. data/test/liquid/drops/liquid_test.rb +52 -0
  49. data/test/liquid/drops/news_drop_test.rb +38 -0
  50. data/test/liquid/drops/projects_drop_test.rb +44 -0
  51. data/test/liquid/drops/uses_drop_test.rb +36 -0
  52. data/test/liquid/filters/arrays_filter_test.rb +24 -0
  53. data/test/liquid/filters/base_filter_test.rb +63 -0
  54. data/test/liquid/liquid_helper.rb +32 -0
  55. data/test/money_helper_test.rb +5 -5
  56. data/test/schema.rb +21 -9
  57. data/test/test_helper.rb +26 -25
  58. metadata +76 -28
  59. data/lib/redmine_crm/rcrm_acts_as_viewed.rb +0 -287
  60. data/lib/redmine_crm/rcrm_acts_as_voter.rb +0 -27
  61. data/lib/redmine_crm/tag.rb +0 -81
  62. data/lib/redmine_crm/tag_list.rb +0 -112
  63. data/lib/redmine_crm/tagging.rb +0 -20
  64. data/test/tag_test.rb +0 -64
  65. data/test/tagging_test.rb +0 -14
@@ -3,32 +3,30 @@ require 'active_record'
3
3
  module RedmineCrm
4
4
  module ActsAsVotable #:nodoc:
5
5
  module Votable #:nodoc:
6
-
7
6
  def votable?
8
7
  false
9
8
  end
10
9
 
11
10
  def rcrm_acts_as_votable
12
- require 'redmine_crm/votable'
13
- include ActsAsVotable::Votable
11
+ require 'redmine_crm/acts_as_votable/votable'
12
+ include RedmineCrm::ActsAsVotable::Votable
14
13
 
15
14
  class_eval do
16
15
  def self.votable?
17
16
  true
18
17
  end
19
18
  end
20
-
21
19
  end
22
20
 
23
21
  def create_index(table_name, column_name)
24
22
  return if self.connection.index_exists?(table_name, column_name)
25
-
23
+
26
24
  self.connection.add_index table_name, column_name
27
25
  end
28
26
 
29
- def create_votable_table options = {}
27
+ def create_votable_table(options = {})
30
28
  votes_name_table = options[:votes] || :votes
31
-
29
+
32
30
  if !self.connection.table_exists?(votes_name_table)
33
31
  self.connection.create_table(votes_name_table) do |t|
34
32
  t.references :votable, :polymorphic => true
@@ -67,13 +65,12 @@ module RedmineCrm
67
65
  create_index votes_name_table, [:votable_id, :votable_type, :vote_scope]
68
66
  end
69
67
 
70
- def drop_votable_table options = {}
71
- votes_name_table = options[:votes] || :votes
68
+ def drop_votable_table(options = {})
69
+ votes_name_table = options[:votes] || :votes
72
70
  if self.connection.table_exists?(votes_name_table)
73
71
  self.connection.drop_table votes_name_table
74
72
  end
75
73
  end
76
-
77
74
  end
78
75
  end
79
- end
76
+ end
@@ -0,0 +1,20 @@
1
+ module RedmineCrm
2
+ module ActsAsVotable
3
+ module Voter
4
+ def voter?
5
+ false
6
+ end
7
+
8
+ def rcrm_acts_as_voter(*args)
9
+ require 'redmine_crm/acts_as_votable/voter'
10
+ include RedmineCrm::ActsAsVotable::Voter
11
+
12
+ class_eval do
13
+ def self.voter?
14
+ true
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -3,11 +3,9 @@ require 'redmine_crm/helpers/vote_helper'
3
3
  module RedmineCrm
4
4
  module ActsAsVotable
5
5
  module Votable
6
-
7
6
  include ActsAsVotable::Helpers::Words
8
7
 
9
- def self.included base
10
-
8
+ def self.included(base)
11
9
  # allow the user to define these himself
12
10
  aliases = {
13
11
 
@@ -45,14 +43,13 @@ module RedmineCrm
45
43
  alias_method(new_method, method)
46
44
  end
47
45
  end
48
-
49
46
  end
50
47
  end
51
48
 
52
49
  attr_accessor :vote_registered
53
50
 
54
51
  def vote_registered?
55
- return self.vote_registered
52
+ self.vote_registered
56
53
  end
57
54
 
58
55
  def default_conditions
@@ -63,8 +60,7 @@ module RedmineCrm
63
60
  end
64
61
 
65
62
  # voting
66
- def vote_by args = {}
67
-
63
+ def vote_by(args = {})
68
64
  options = {
69
65
  :vote => true,
70
66
  :vote_scope => nil
@@ -72,18 +68,14 @@ module RedmineCrm
72
68
 
73
69
  self.vote_registered = false
74
70
 
75
- if options[:voter].nil?
76
- return false
77
- end
71
+ return false if options[:voter].nil?
78
72
 
79
73
  # find the vote
80
- _votes_ = find_votes_for({
81
- :voter_id => options[:voter].id,
82
- :vote_scope => options[:vote_scope],
83
- :voter_type => options[:voter].class.base_class.name
84
- })
74
+ votes_for = find_votes_for(:voter_id => options[:voter].id,
75
+ :vote_scope => options[:vote_scope],
76
+ :voter_type => options[:voter].class.base_class.name)
85
77
 
86
- if _votes_.count == 0 or options[:duplicate]
78
+ if votes_for.count == 0 || options[:duplicate]
87
79
  # this voter has never voted
88
80
  vote = RedmineCrm::ActsAsVotable::Vote.new(
89
81
  :votable => self,
@@ -92,14 +84,14 @@ module RedmineCrm
92
84
  )
93
85
  else
94
86
  # this voter is potentially changing his vote
95
- vote = _votes_.last
87
+ vote = votes_for.last
96
88
  end
97
89
 
98
90
  last_update = vote.updated_at
99
91
 
100
92
  vote.vote_flag = votable_words.meaning_of(options[:vote])
101
93
 
102
- #Allowing for a vote_weight to be associated with every vote. Could change with every voter object
94
+ # Allowing for a vote_weight to be associated with every vote. Could change with every voter object
103
95
  vote.vote_weight = (options[:vote_weight].to_i if options[:vote_weight].present?) || 1
104
96
 
105
97
  if vote.save
@@ -110,33 +102,34 @@ module RedmineCrm
110
102
  self.vote_registered = false
111
103
  return false
112
104
  end
113
-
114
105
  end
115
106
 
116
- def unvote args = {}
107
+ def unvote(args = {})
117
108
  return false if args[:voter].nil?
118
- _votes_ = find_votes_for(:voter_id => args[:voter].id, :vote_scope => args[:vote_scope], :voter_type => args[:voter].class.base_class.name)
109
+ votes_for = find_votes_for(:voter_id => args[:voter].id,
110
+ :vote_scope => args[:vote_scope],
111
+ :voter_type => args[:voter].class.base_class.name)
119
112
 
120
- return true if _votes_.size == 0
121
- _votes_.each(&:destroy)
113
+ return true if votes_for.empty?
114
+ votes_for.each(&:destroy)
122
115
  update_cached_votes args[:vote_scope]
123
116
  self.vote_registered = false if votes_for.count == 0
124
- return true
117
+ true
125
118
  end
126
119
 
127
- def vote_up voter, options={}
120
+ def vote_up(voter, options = {})
128
121
  self.vote_by :voter => voter, :vote => true, :vote_scope => options[:vote_scope], :vote_weight => options[:vote_weight]
129
122
  end
130
123
 
131
- def vote_down voter, options={}
124
+ def vote_down(voter, options = {})
132
125
  self.vote_by :voter => voter, :vote => false, :vote_scope => options[:vote_scope], :vote_weight => options[:vote_weight]
133
126
  end
134
127
 
135
- def unvote_by voter, options = {}
136
- self.unvote :voter => voter, :vote_scope => options[:vote_scope] #Does not need vote_weight since the votes_for are anyway getting destroyed
128
+ def unvote_by(voter, options = {})
129
+ self.unvote :voter => voter, :vote_scope => options[:vote_scope] # Does not need vote_weight since the votes_for are anyway getting destroyed
137
130
  end
138
131
 
139
- def scope_cache_field field, vote_scope
132
+ def scope_cache_field(field, vote_scope)
140
133
  return field if vote_scope.nil?
141
134
 
142
135
  case field
@@ -172,8 +165,7 @@ module RedmineCrm
172
165
  end
173
166
 
174
167
  # caching
175
- def update_cached_votes vote_scope = nil
176
-
168
+ def update_cached_votes(vote_scope = nil)
177
169
  updates = {}
178
170
 
179
171
  if self.respond_to?(:cached_votes_total=)
@@ -241,53 +233,50 @@ module RedmineCrm
241
233
  end
242
234
 
243
235
  if (::ActiveRecord::VERSION::MAJOR == 3) && (::ActiveRecord::VERSION::MINOR != 0)
244
- self.update_attributes(updates, :without_protection => true) if updates.size > 0
236
+ self.update_attributes(updates, :without_protection => true) if !updates.empty?
245
237
  else
246
- self.update_attributes(updates) if updates.size > 0
238
+ self.update_attributes(updates) if !updates.empty?
247
239
  end
248
-
249
240
  end
250
241
 
251
-
252
242
  # results
253
- def find_votes_for extra_conditions = {}
243
+ def find_votes_for(extra_conditions = {})
254
244
  votes_for.where(extra_conditions)
255
245
  end
256
246
 
257
- def get_up_votes options={}
247
+ def get_up_votes(options = {})
258
248
  vote_scope_hash = scope_or_empty_hash(options[:vote_scope])
259
249
  find_votes_for({:vote_flag => true}.merge(vote_scope_hash))
260
250
  end
261
251
 
262
- def get_down_votes options={}
252
+ def get_down_votes(options = {})
263
253
  vote_scope_hash = scope_or_empty_hash(options[:vote_scope])
264
- find_votes_for({:vote_flag => false}.merge(vote_scope_hash))
254
+ find_votes_for({ :vote_flag => false }.merge(vote_scope_hash))
265
255
  end
266
256
 
267
-
268
257
  # counting
269
- def count_votes_total skip_cache = false, vote_scope = nil
258
+ def count_votes_total(skip_cache = false, vote_scope = nil)
270
259
  if !skip_cache && self.respond_to?(scope_cache_field :cached_votes_total, vote_scope)
271
260
  return self.send(scope_cache_field :cached_votes_total, vote_scope)
272
261
  end
273
262
  find_votes_for(scope_or_empty_hash(vote_scope)).count
274
263
  end
275
264
 
276
- def count_votes_up skip_cache = false, vote_scope = nil
265
+ def count_votes_up(skip_cache = false, vote_scope = nil)
277
266
  if !skip_cache && self.respond_to?(scope_cache_field :cached_votes_up, vote_scope)
278
267
  return self.send(scope_cache_field :cached_votes_up, vote_scope)
279
268
  end
280
269
  get_up_votes(:vote_scope => vote_scope).count
281
270
  end
282
271
 
283
- def count_votes_down skip_cache = false, vote_scope = nil
272
+ def count_votes_down(skip_cache = false, vote_scope = nil)
284
273
  if !skip_cache && self.respond_to?(scope_cache_field :cached_votes_down, vote_scope)
285
274
  return self.send(scope_cache_field :cached_votes_down, vote_scope)
286
275
  end
287
276
  get_down_votes(:vote_scope => vote_scope).count
288
277
  end
289
278
 
290
- def weighted_total skip_cache = false, vote_scope = nil
279
+ def weighted_total(skip_cache = false, vote_scope = nil)
291
280
  if !skip_cache && self.respond_to?(scope_cache_field :cached_weighted_total, vote_scope)
292
281
  return self.send(scope_cache_field :cached_weighted_total, vote_scope)
293
282
  end
@@ -296,7 +285,7 @@ module RedmineCrm
296
285
  ups + downs
297
286
  end
298
287
 
299
- def weighted_score skip_cache = false, vote_scope = nil
288
+ def weighted_score(skip_cache = false, vote_scope = nil)
300
289
  if !skip_cache && self.respond_to?(scope_cache_field :cached_weighted_score, vote_scope)
301
290
  return self.send(scope_cache_field :cached_weighted_score, vote_scope)
302
291
  end
@@ -305,7 +294,7 @@ module RedmineCrm
305
294
  ups - downs
306
295
  end
307
296
 
308
- def weighted_average skip_cache = false, vote_scope = nil
297
+ def weighted_average(skip_cache = false, vote_scope = nil)
309
298
  if !skip_cache && self.respond_to?(scope_cache_field :cached_weighted_average, vote_scope)
310
299
  return self.send(scope_cache_field :cached_weighted_average, vote_scope)
311
300
  end
@@ -319,7 +308,7 @@ module RedmineCrm
319
308
  end
320
309
 
321
310
  # voters
322
- def voted_on_by? voter
311
+ def voted_on_by?(voter)
323
312
  votes = find_votes_for :voter_id => voter.id, :voter_type => voter.class.base_class.name
324
313
  votes.count > 0
325
314
  end
@@ -3,28 +3,25 @@ require 'redmine_crm/helpers/vote_helper'
3
3
  module RedmineCrm
4
4
  module ActsAsVotable
5
5
  class Vote < ActiveRecord::Base
6
-
7
6
  include Helpers::Words
8
7
 
9
8
  if defined?(ProtectedAttributes) || ::ActiveRecord::VERSION::MAJOR < 4
10
9
  attr_accessible :votable_id, :votable_type,
11
- :voter_id, :voter_type,
12
- :votable, :voter,
13
- :vote_flag, :vote_scope
10
+ :voter_id, :voter_type,
11
+ :votable, :voter,
12
+ :vote_flag, :vote_scope
14
13
  end
15
14
 
16
15
  belongs_to :votable, :polymorphic => true
17
16
  belongs_to :voter, :polymorphic => true
18
17
 
19
- scope :up, lambda{ where(:vote_flag => true) }
20
- scope :down, lambda{ where(:vote_flag => false) }
21
- scope :for_type, lambda{ |klass| where(:votable_type => klass) }
22
- scope :by_type, lambda{ |klass| where(:voter_type => klass) }
18
+ scope :up, lambda { where(:vote_flag => true) }
19
+ scope :down, lambda { where(:vote_flag => false) }
20
+ scope :for_type, lambda { |klass| where(:votable_type => klass) }
21
+ scope :by_type, lambda { |klass| where(:voter_type => klass) }
23
22
 
24
23
  validates_presence_of :votable_id
25
24
  validates_presence_of :voter_id
26
-
27
25
  end
28
-
29
26
  end
30
27
  end
@@ -1,9 +1,7 @@
1
1
  module RedmineCrm
2
2
  module ActsAsVotable
3
3
  module Voter
4
-
5
4
  def self.included(base)
6
-
7
5
  # allow user to define these
8
6
  aliases = {
9
7
  :vote_up_for => [:likes, :upvotes, :up_votes],
@@ -18,7 +16,6 @@ module RedmineCrm
18
16
  }
19
17
 
20
18
  base.class_eval do
21
-
22
19
  has_many :votes, :class_name => 'RedmineCrm::ActsAsVotable::Vote', :as => :voter, :dependent => :destroy do
23
20
  def votables
24
21
  includes(:votable).map(&:votable)
@@ -30,107 +27,105 @@ module RedmineCrm
30
27
  alias_method(new_method, method)
31
28
  end
32
29
  end
33
-
34
30
  end
35
-
36
31
  end
37
32
 
38
33
  # voting
39
- def vote args
40
- args[:votable].vote_by args.merge({:voter => self})
34
+ def vote(args)
35
+ args[:votable].vote_by args.merge(:voter => self)
41
36
  end
42
37
 
43
- def vote_up_for model=nil, args={}
38
+ def vote_up_for(model = nil, args = {})
44
39
  vote :votable => model, :vote_scope => args[:vote_scope], :vote => true
45
40
  end
46
41
 
47
- def vote_down_for model=nil, args={}
42
+ def vote_down_for(model = nil, args = {})
48
43
  vote :votable => model, :vote_scope => args[:vote_scope], :vote => false
49
44
  end
50
45
 
51
- def unvote_for model, args={}
46
+ def unvote_for(model, args = {})
52
47
  model.unvote :voter => self, :vote_scope => args[:vote_scope]
53
48
  end
54
49
 
55
50
  # results
56
- def voted_on? votable, args={}
51
+ def voted_on?(votable, args = {})
57
52
  votes = find_votes(:votable_id => votable.id, :votable_type => votable.class.base_class.name,
58
53
  :vote_scope => args[:vote_scope])
59
- votes.size > 0
54
+ !votes.empty?
60
55
  end
61
56
 
62
- def voted_up_on? votable, args={}
57
+ def voted_up_on?(votable, args = {})
63
58
  votes = find_votes(:votable_id => votable.id, :votable_type => votable.class.base_class.name,
64
59
  :vote_scope => args[:vote_scope], :vote_flag => true)
65
- votes.size > 0
60
+ !votes.empty?
66
61
  end
67
62
 
68
- def voted_down_on? votable, args={}
63
+ def voted_down_on?(votable, args = {})
69
64
  votes = find_votes(:votable_id => votable.id, :votable_type => votable.class.base_class.name,
70
65
  :vote_scope => args[:vote_scope], :vote_flag => false)
71
- votes.size > 0
66
+ !votes.empty?
72
67
  end
73
68
 
74
- def voted_as_when_voting_on votable, args={}
69
+ def voted_as_when_voting_on(votable, args = {})
75
70
  vote = find_votes(:votable_id => votable.id, :votable_type => votable.class.base_class.name,
76
- :vote_scope => args[:vote_scope]).select(:vote_flag).last
71
+ :vote_scope => args[:vote_scope]).select(:vote_flag).last
77
72
  return nil unless vote
78
- return vote.vote_flag
73
+ vote.vote_flag
79
74
  end
80
75
 
81
- def find_votes extra_conditions = {}
76
+ def find_votes(extra_conditions = {})
82
77
  votes.where(extra_conditions)
83
78
  end
84
79
 
85
- def find_up_votes args={}
80
+ def find_up_votes(args = {})
86
81
  find_votes :vote_flag => true, :vote_scope => args[:vote_scope]
87
82
  end
88
83
 
89
- def find_down_votes args={}
84
+ def find_down_votes(args = {})
90
85
  find_votes :vote_flag => false, :vote_scope => args[:vote_scope]
91
86
  end
92
87
 
93
- def find_votes_for_class klass, extra_conditions = {}
94
- find_votes extra_conditions.merge({:votable_type => klass.name})
88
+ def find_votes_for_class(klass, extra_conditions = {})
89
+ find_votes extra_conditions.merge(:votable_type => klass.name)
95
90
  end
96
91
 
97
- def find_up_votes_for_class klass, args={}
92
+ def find_up_votes_for_class(klass, args = {})
98
93
  find_votes_for_class klass, :vote_flag => true, :vote_scope => args[:vote_scope]
99
94
  end
100
95
 
101
- def find_down_votes_for_class klass, args={}
96
+ def find_down_votes_for_class(klass, args = {})
102
97
  find_votes_for_class klass, :vote_flag => false, :vote_scope => args[:vote_scope]
103
98
  end
104
99
 
105
100
  # Including polymporphic relations for eager loading
106
101
  def include_objects
107
- ActsAsVotable::Vote.includes(:votable)
102
+ RedmineCrm::ActsAsVotable::Vote.includes(:votable)
108
103
  end
109
104
 
110
- def find_voted_items extra_conditions = {}
105
+ def find_voted_items(extra_conditions = {})
111
106
  options = extra_conditions.merge :voter_id => id, :voter_type => self.class.base_class.name
112
107
  include_objects.where(options).collect(&:votable)
113
108
  end
114
109
 
115
- def find_up_voted_items extra_conditions = {}
110
+ def find_up_voted_items(extra_conditions = {})
116
111
  find_voted_items extra_conditions.merge(:vote_flag => true)
117
112
  end
118
113
 
119
- def find_down_voted_items extra_conditions = {}
114
+ def find_down_voted_items(extra_conditions = {})
120
115
  find_voted_items extra_conditions.merge(:vote_flag => false)
121
116
  end
122
117
 
123
- def get_voted klass, extra_conditions = {}
118
+ def get_voted(klass, extra_conditions = {})
124
119
  klass.joins(:votes_for).merge find_votes(extra_conditions)
125
120
  end
126
121
 
127
- def get_up_voted klass
122
+ def get_up_voted(klass)
128
123
  klass.joins(:votes_for).merge find_up_votes
129
124
  end
130
125
 
131
- def get_down_voted klass
126
+ def get_down_voted(klass)
132
127
  klass.joins(:votes_for).merge find_down_votes
133
128
  end
134
129
  end
135
130
  end
136
- end
131
+ end