redmine_crm 0.0.8 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class VotableTest < ActiveSupport::TestCase
4
+ def test_not_be_votable
5
+ assert !NotVotable.votable?, false
6
+ end
7
+
8
+ def test_be_votable
9
+ assert Votable.votable?, true
10
+ end
11
+
12
+ def test_behaves_like_votable_model
13
+ assert Voter.create(:name => 'i can vote!')
14
+ assert VotableCache.create(:name => 'voting model with cache')
15
+ assert VotableVoter.create(:name => 'i can vote too!')
16
+ end
17
+ end
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class VoteHelperTest < ActiveSupport::TestCase
4
+ def vote
5
+ RedmineCrm::ActsAsVotable::Vote.new
6
+ end
7
+
8
+ def test_know_that_like_is_a_true_vote
9
+ assert vote.votable_words.that_mean_true.include? "like"
10
+ end
11
+
12
+ def test_know_that_bad_is_a_false_vote
13
+ assert vote.votable_words.that_mean_false.include? "bad"
14
+ end
15
+
16
+ def test_be_a_vote_for_true_when_word_is_good
17
+ assert vote.votable_words.meaning_of('good')
18
+ end
19
+
20
+ def test_be_a_vote_for_false_when_word_is_down
21
+ assert !vote.votable_words.meaning_of('down')
22
+ end
23
+
24
+ def test_be_a_vote_for_true_when_the_word_is_unknown
25
+ assert vote.votable_words.meaning_of('lsdhklkadhfs')
26
+ end
27
+
28
+ end
@@ -0,0 +1,296 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class VoterModelTest < ActiveSupport::TestCase
4
+ def votable
5
+ votables(:votable)
6
+ end
7
+
8
+ def voter
9
+ voters(:voter)
10
+ end
11
+
12
+ def votable_cache
13
+ votable_caches(:votable_cache)
14
+ end
15
+
16
+ def votable_klass
17
+ votable.class
18
+ end
19
+
20
+ def test_be_voted_on_after_a_voter_has_voted
21
+ votable.vote_by :voter => voter
22
+ assert voter.voted_on?(votable)
23
+ assert voter.voted_for?(votable)
24
+ end
25
+
26
+ def test_not_be_voted_on_if_a_voter_has_not_voted
27
+ assert !voter.voted_on?(votable)
28
+ end
29
+
30
+ def test_be_voted_on_after_a_voter_has_voted_under_scope
31
+ votable.vote_by :voter => voter, :vote_scope => 'rank'
32
+ assert voter.voted_on?(votable, :vote_scope => 'rank')
33
+ end
34
+
35
+ def test_not_be_voted_on_other_scope_after_a_voter_has_voted_under_one_scope
36
+ votable.vote_by(:voter => voter, :vote_scope => 'rank')
37
+ assert !voter.voted_on?(votable)
38
+ end
39
+
40
+ def test_be_voted_as_true_when_a_voter_has_voted_true
41
+ votable.vote_by(:voter => voter)
42
+ assert voter.voted_as_when_voted_on(votable)
43
+ assert voter.voted_as_when_voted_for(votable)
44
+ end
45
+
46
+ def test_be_voted_as_true_when_a_voter_has_voted_true_under_scope
47
+ votable.vote_by(:voter => voter, :vote_scope => 'rank')
48
+ assert voter.voted_as_when_voted_for(votable, :vote_scope => 'rank')
49
+ end
50
+
51
+ def test_be_voted_as_false_when_a_voter_has_voted_false
52
+ votable.vote_by(:voter => voter, :vote => false)
53
+ assert !voter.voted_as_when_voted_for(votable)
54
+ end
55
+
56
+ def test_be_voted_as_false_when_a_voter_has_voted_false_under_scope
57
+ votable.vote_by(:voter => voter, :vote => false, :vote_scope => 'rank')
58
+ assert !voter.voted_as_when_voted_for(votable, :vote_scope => 'rank')
59
+ end
60
+
61
+ def test_be_voted_as_nil_when_a_voter_has_never_voted
62
+ assert_equal voter.voted_as_when_voting_on(votable), nil
63
+ end
64
+
65
+ def test_be_voted_as_nil_when_a_voter_has_never_voted_under_the_scope
66
+ votable.vote_by :voter => voter, :vote => false, :vote_scope => 'rank'
67
+ assert_equal voter.voted_as_when_voting_on(votable), nil
68
+ end
69
+
70
+ def test_return_true_if_voter_has_voted_true
71
+ votable.vote_by(:voter => voter)
72
+ assert voter.voted_up_on?(votable)
73
+ end
74
+
75
+ def test_return_false_if_voter_has_not_voted_true
76
+ votable.vote_by(:voter => voter, :vote => false)
77
+ assert !voter.voted_up_on?(votable)
78
+ end
79
+
80
+ def test_return_true_if_the_voter_has_voted_false
81
+ votable.vote_by(:voter => voter, :vote => false)
82
+ assert voter.voted_down_on?(votable)
83
+ end
84
+
85
+ def test_return_false_if_the_voter_has_not_voted_false
86
+ votable.vote_by(:voter => voter, :vote => true)
87
+ assert !voter.voted_down_on?(votable)
88
+ end
89
+
90
+ def test_provide_reserve_functionality_voter_can_vote_on_votable
91
+ voter.vote(:votable => votable, :vote => 'bad')
92
+ assert !voter.voted_as_when_voting_on(votable)
93
+ end
94
+
95
+ def test_allow_the_voter_to_vote_up_a_model
96
+ voter.vote_up_for(votable)
97
+ assert_equal votable.get_up_votes.first.voter, voter
98
+ assert_equal votable.votes_for.up.first.voter, voter
99
+ end
100
+
101
+ def test_allow_the_voter_to_vote_down_a_model
102
+ voter.vote_down_for(votable)
103
+ assert_equal votable.get_down_votes.first.voter, voter
104
+ assert_equal votable.votes_for.down.first.voter, voter
105
+ end
106
+
107
+ def test_allow_the_voter_to_unvote_a_model
108
+ voter.vote_up_for(votable)
109
+ voter.unvote_for(votable)
110
+ assert_equal votable.find_votes_for.size, 0
111
+ assert_equal votable.votes_for.count, 0
112
+ end
113
+
114
+ def test_get_all_of_the_voters_votes
115
+ voter.vote_up_for(votable)
116
+ assert_equal voter.find_votes.size, 1
117
+ assert_equal voter.votes.up.count, 1
118
+ end
119
+
120
+ def test_get_all_of_the_voters_up_votes
121
+ voter.vote_up_for(votable)
122
+ assert_equal voter.find_up_votes.size, 1
123
+ assert_equal voter.votes.up.count, 1
124
+ end
125
+
126
+ def test_get_all_of_the_voters_down_votes
127
+ voter.vote_down_for(votable)
128
+ assert_equal voter.find_down_votes.size, 1
129
+ assert_equal voter.votes.down.count, 1
130
+ end
131
+
132
+ def test_get_all_of_the_votes_otes_for_a_class
133
+ votable.vote_by(:voter => voter)
134
+ votables(:votable2).vote_by(:voter => voter, :vote => false)
135
+ assert_equal voter.find_votes_for_class(votable_klass).size, 2
136
+ assert_equal voter.votes.for_type(votable_klass).count, 2
137
+ end
138
+
139
+ def test_get_all_of_the_voters_up_votes_for_a_class
140
+ votable.vote_by(:voter => voter)
141
+ votables(:votable2).vote_by( :voter => voter, :vote => false)
142
+ assert_equal voter.find_up_votes_for_class(votable_klass).size, 1
143
+ assert_equal voter.votes.up.for_type(votable_klass).count, 1
144
+ end
145
+
146
+ def test_get_all_of_the_voters_down_votes_for_a_class
147
+ votable.vote_by(:voter => voter)
148
+ votables(:votable2).vote_by( :voter => voter, :vote => false)
149
+ assert_equal voter.find_down_votes_for_class(votable_klass).size, 1
150
+ assert_equal voter.votes.down.for_type(votable_klass).count, 1
151
+ end
152
+
153
+ def test_be_contained_to_instances
154
+ voter.vote(:votable => votable, :vote => false)
155
+ voters(:voter2).vote(:votable => votable)
156
+
157
+ assert !voter.voted_as_when_voting_on(votable)
158
+ end
159
+
160
+ # describe '#find_voted_items
161
+
162
+ def test_returns_objects_that_a_user_has_upvoted_for
163
+ votable.vote_by(:voter => voter)
164
+ votables(:votable2).vote_by(:voter => voters(:voter2))
165
+ assert voter.find_voted_items.include? votable
166
+ assert_equal voter.find_voted_items.size, 1
167
+ end
168
+
169
+ def test_returns_objects_that_a_user_has_upvoted_for_using_scope
170
+ votable.vote_by(:voter => voter, :vote_scope => 'rank')
171
+ votables(:votable2).vote_by(:voter => voters(:voter2), :vote_scope => 'rank')
172
+ assert voter.find_voted_items(:vote_scope => 'rank').include? votable
173
+ assert_equal voter.find_voted_items(:vote_scope => 'rank').size, 1
174
+ end
175
+
176
+ def test_returns_objects_that_a_user_has_downvoted_for
177
+ votable.vote_down(voter)
178
+ votables(:votable2).vote_down(voters(:voter2))
179
+ assert voter.find_voted_items.include? votable
180
+ assert_equal voter.find_voted_items.size, 1
181
+ end
182
+
183
+ def test_returns_objects_that_a_user_has_downvoted_for_using_scope
184
+ votable.vote_down voter, :vote_scope => 'rank'
185
+ votables(:votable2).vote_down(voters(:voter2), :vote_scope => 'rank')
186
+ assert voter.find_voted_items(:vote_scope => 'rank').include? votable
187
+ assert_equal voter.find_voted_items(:vote_scope => 'rank').size, 1
188
+ end
189
+
190
+ # describe '#find_up_voted_items
191
+ def test_returns_objects_that_a_user_has_upvoted_for
192
+ votable.vote_by(:voter => voter)
193
+ votables(:votable2).vote_by :voter => voters(:voter2)
194
+ assert voter.find_up_voted_items.include? votable
195
+ assert_equal voter.find_up_voted_items.size, 1
196
+ assert voter.find_liked_items.include? votable
197
+ assert_equal voter.find_liked_items.size, 1
198
+ end
199
+
200
+ def test_returns_objects_that_a_user_has_upvoted_for_using_scope
201
+ votable.vote_by(:voter => voter, :vote_scope => 'rank')
202
+ votables(:votable2).vote_by(:voter => voters(:voter2), :vote_scope => 'rank')
203
+ assert voter.find_up_voted_items(:vote_scope => 'rank').include? votable
204
+ assert_equal voter.find_up_voted_items(:vote_scope => 'rank').size, 1
205
+ end
206
+
207
+ def test_does_not_return_objects_that_a_user_has_downvoted_for
208
+ votable.vote_down voter
209
+ assert_equal voter.find_up_voted_items.size, 0
210
+ end
211
+
212
+ def test_does_not_return_objects_that_a_user_has_downvoted_for_using_scope
213
+ votable.vote_down voter, :vote_scope => 'rank'
214
+ assert_equal voter.find_up_voted_items(:vote_scope => 'rank').size, 0
215
+ end
216
+
217
+ # describe '#find_down_voted_items
218
+
219
+ def test_does_not_return_objects_that_a_user_has_upvoted_for
220
+ votable.vote_by :voter => voter
221
+ assert_equal voter.find_down_voted_items.size, 0
222
+ end
223
+
224
+ def test_does_not_return_objects_that_a_user_has_upvoted_for_using_scope
225
+ votable.vote_by :voter => voter, :vote_scope => 'rank'
226
+ assert_equal voter.find_down_voted_items(:vote_scope => 'rank').size, 0
227
+ end
228
+
229
+ def test_returns_objects_that_a_user_has_downvoted_for
230
+ votable.vote_down voter
231
+ votables(:votable2).vote_down voters(:voter2)
232
+ assert voter.find_down_voted_items.include? votable
233
+ assert_equal voter.find_down_voted_items.size, 1
234
+ assert voter.find_disliked_items.include? votable
235
+ assert_equal voter.find_disliked_items.size, 1
236
+ end
237
+
238
+ def test_returns_objects_that_a_user_has_downvoted_for_using_scope
239
+ votable.vote_down voter, :vote_scope => 'rank'
240
+ votables(:votable2).vote_down voters(:voter2), :vote_scope => 'rank'
241
+ assert voter.find_down_voted_items(:vote_scope => 'rank').include? votable
242
+ assert_equal voter.find_down_voted_items(:vote_scope => 'rank').size, 1
243
+ end
244
+
245
+ # describe '#get_voted
246
+ def get_voted
247
+ voter.get_voted(votable.class)
248
+ end
249
+
250
+ def test_returns_objects_of_a_class_that_a_voter_has_voted_for
251
+ votable.vote_by :voter => voter
252
+ votables(:votable2).vote_down voter
253
+ assert get_voted.include? votable
254
+ assert get_voted.include? votables(:votable2)
255
+ assert_equal get_voted.size, 2
256
+ end
257
+
258
+ def test_does_not_return_objects_of_a_class_that_a_voter_has_voted_for
259
+ votable.vote_by :voter => voters(:voter2)
260
+ votables(:votable2).vote_by :voter => voters(:voter2)
261
+ assert_equal get_voted.size, 0
262
+ end
263
+
264
+ # describe '#get_up_voted
265
+
266
+ def get_up_voted
267
+ voter.get_up_voted(votable.class)
268
+ end
269
+
270
+ def test_returns_up_voted_items_that_a_voter_has_voted_for
271
+ votable.vote_by :voter => voter
272
+ assert get_up_voted.include? votable
273
+ assert_equal get_up_voted.size, 1
274
+ end
275
+
276
+ def test_does_not_return_down_voted_items_a_voter_has_voted_for
277
+ votable.vote_down voter
278
+ assert_equal get_up_voted.size, 0
279
+ end
280
+
281
+ # describe '#get_down_voted
282
+ def get_down_voted
283
+ voter.get_down_voted(votable.class)
284
+ end
285
+
286
+ def test_does_not_return_up_voted_items_that_a_voter_has_voted_for
287
+ votable.vote_by :voter => voter
288
+ assert_equal get_down_voted.size, 0
289
+ end
290
+
291
+ def test_returns_down_voted_items_a_voter_has_voted_for
292
+ votable.vote_down voter
293
+ assert get_down_voted.include? votable
294
+ assert_equal get_down_voted.size, 1
295
+ end
296
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redmine_crm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - RedmineCRM
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-10 00:00:00.000000000 Z
11
+ date: 2015-08-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: plugins for Redmine
14
14
  email:
@@ -30,13 +30,20 @@ files:
30
30
  - lib/redmine_crm/currency/formatting.rb
31
31
  - lib/redmine_crm/currency/heuristics.rb
32
32
  - lib/redmine_crm/currency/loader.rb
33
+ - lib/redmine_crm/helpers/tags_helper.rb
34
+ - lib/redmine_crm/helpers/vote_helper.rb
33
35
  - lib/redmine_crm/money_helper.rb
34
36
  - lib/redmine_crm/rcrm_acts_as_taggable.rb
37
+ - lib/redmine_crm/rcrm_acts_as_viewed.rb
38
+ - lib/redmine_crm/rcrm_acts_as_votable.rb
39
+ - lib/redmine_crm/rcrm_acts_as_voter.rb
35
40
  - lib/redmine_crm/tag.rb
36
41
  - lib/redmine_crm/tag_list.rb
37
42
  - lib/redmine_crm/tagging.rb
38
- - lib/redmine_crm/tags_helper.rb
39
43
  - lib/redmine_crm/version.rb
44
+ - lib/redmine_crm/votable.rb
45
+ - lib/redmine_crm/vote.rb
46
+ - lib/redmine_crm/voter.rb
40
47
  - redmine_crm.gemspec
41
48
  - test/acts_as_taggable_test.rb
42
49
  - test/currency_test.rb
@@ -47,12 +54,21 @@ files:
47
54
  - test/fixtures/tags.yml
48
55
  - test/fixtures/user.rb
49
56
  - test/fixtures/users.yml
57
+ - test/fixtures/votable_caches.yml
58
+ - test/fixtures/votables.yml
59
+ - test/fixtures/vote_classes.rb
60
+ - test/fixtures/voters.yml
50
61
  - test/money_helper_test.rb
51
62
  - test/schema.rb
52
63
  - test/tag_test.rb
53
64
  - test/tagging_test.rb
54
65
  - test/tags_helper_test.rb
55
66
  - test/test_helper.rb
67
+ - test/viewed_test.rb
68
+ - test/votable_model_test.rb
69
+ - test/votable_test.rb
70
+ - test/vote_helper_test.rb
71
+ - test/voter_model_test.rb
56
72
  homepage: ''
57
73
  licenses:
58
74
  - GPL2
@@ -87,10 +103,19 @@ test_files:
87
103
  - test/fixtures/tags.yml
88
104
  - test/fixtures/user.rb
89
105
  - test/fixtures/users.yml
106
+ - test/fixtures/votable_caches.yml
107
+ - test/fixtures/votables.yml
108
+ - test/fixtures/vote_classes.rb
109
+ - test/fixtures/voters.yml
90
110
  - test/money_helper_test.rb
91
111
  - test/schema.rb
92
112
  - test/tag_test.rb
93
113
  - test/tagging_test.rb
94
114
  - test/tags_helper_test.rb
95
115
  - test/test_helper.rb
116
+ - test/viewed_test.rb
117
+ - test/votable_model_test.rb
118
+ - test/votable_test.rb
119
+ - test/vote_helper_test.rb
120
+ - test/voter_model_test.rb
96
121
  has_rdoc: