acts_as_votable 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +39 -39
- data/README.markdown +22 -1
- data/lib/acts_as_votable/version.rb +1 -1
- data/lib/acts_as_votable/voter.rb +31 -0
- data/spec/voter_spec.rb +91 -0
- metadata +30 -9
data/Gemfile.lock
CHANGED
@@ -1,76 +1,76 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
acts_as_votable (0.
|
4
|
+
acts_as_votable (0.4.0)
|
5
5
|
rails (>= 3.0.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
|
-
actionmailer (3.2.
|
11
|
-
actionpack (= 3.2.
|
10
|
+
actionmailer (3.2.8)
|
11
|
+
actionpack (= 3.2.8)
|
12
12
|
mail (~> 2.4.4)
|
13
|
-
actionpack (3.2.
|
14
|
-
activemodel (= 3.2.
|
15
|
-
activesupport (= 3.2.
|
13
|
+
actionpack (3.2.8)
|
14
|
+
activemodel (= 3.2.8)
|
15
|
+
activesupport (= 3.2.8)
|
16
16
|
builder (~> 3.0.0)
|
17
17
|
erubis (~> 2.7.0)
|
18
|
-
journey (~> 1.0.
|
18
|
+
journey (~> 1.0.4)
|
19
19
|
rack (~> 1.4.0)
|
20
20
|
rack-cache (~> 1.2)
|
21
21
|
rack-test (~> 0.6.1)
|
22
|
-
sprockets (~> 2.1.
|
23
|
-
activemodel (3.2.
|
24
|
-
activesupport (= 3.2.
|
22
|
+
sprockets (~> 2.1.3)
|
23
|
+
activemodel (3.2.8)
|
24
|
+
activesupport (= 3.2.8)
|
25
25
|
builder (~> 3.0.0)
|
26
|
-
activerecord (3.2.
|
27
|
-
activemodel (= 3.2.
|
28
|
-
activesupport (= 3.2.
|
26
|
+
activerecord (3.2.8)
|
27
|
+
activemodel (= 3.2.8)
|
28
|
+
activesupport (= 3.2.8)
|
29
29
|
arel (~> 3.0.2)
|
30
30
|
tzinfo (~> 0.3.29)
|
31
|
-
activeresource (3.2.
|
32
|
-
activemodel (= 3.2.
|
33
|
-
activesupport (= 3.2.
|
34
|
-
activesupport (3.2.
|
31
|
+
activeresource (3.2.8)
|
32
|
+
activemodel (= 3.2.8)
|
33
|
+
activesupport (= 3.2.8)
|
34
|
+
activesupport (3.2.8)
|
35
35
|
i18n (~> 0.6)
|
36
36
|
multi_json (~> 1.0)
|
37
37
|
arel (3.0.2)
|
38
|
-
builder (3.0.
|
38
|
+
builder (3.0.4)
|
39
39
|
diff-lcs (1.1.3)
|
40
40
|
erubis (2.7.0)
|
41
41
|
hike (1.2.1)
|
42
|
-
i18n (0.6.
|
43
|
-
journey (1.0.
|
44
|
-
json (1.
|
42
|
+
i18n (0.6.1)
|
43
|
+
journey (1.0.4)
|
44
|
+
json (1.7.5)
|
45
45
|
mail (2.4.4)
|
46
46
|
i18n (>= 0.4.0)
|
47
47
|
mime-types (~> 1.16)
|
48
48
|
treetop (~> 1.4.8)
|
49
|
-
mime-types (1.
|
50
|
-
multi_json (1.
|
49
|
+
mime-types (1.19)
|
50
|
+
multi_json (1.3.7)
|
51
51
|
polyglot (0.3.3)
|
52
52
|
rack (1.4.1)
|
53
53
|
rack-cache (1.2)
|
54
54
|
rack (>= 0.4)
|
55
55
|
rack-ssl (1.3.2)
|
56
56
|
rack
|
57
|
-
rack-test (0.6.
|
57
|
+
rack-test (0.6.2)
|
58
58
|
rack (>= 1.0)
|
59
|
-
rails (3.2.
|
60
|
-
actionmailer (= 3.2.
|
61
|
-
actionpack (= 3.2.
|
62
|
-
activerecord (= 3.2.
|
63
|
-
activeresource (= 3.2.
|
64
|
-
activesupport (= 3.2.
|
59
|
+
rails (3.2.8)
|
60
|
+
actionmailer (= 3.2.8)
|
61
|
+
actionpack (= 3.2.8)
|
62
|
+
activerecord (= 3.2.8)
|
63
|
+
activeresource (= 3.2.8)
|
64
|
+
activesupport (= 3.2.8)
|
65
65
|
bundler (~> 1.0)
|
66
|
-
railties (= 3.2.
|
67
|
-
railties (3.2.
|
68
|
-
actionpack (= 3.2.
|
69
|
-
activesupport (= 3.2.
|
66
|
+
railties (= 3.2.8)
|
67
|
+
railties (3.2.8)
|
68
|
+
actionpack (= 3.2.8)
|
69
|
+
activesupport (= 3.2.8)
|
70
70
|
rack-ssl (~> 1.3.2)
|
71
71
|
rake (>= 0.8.7)
|
72
72
|
rdoc (~> 3.4)
|
73
|
-
thor (
|
73
|
+
thor (>= 0.14.6, < 2.0)
|
74
74
|
rake (0.9.2.2)
|
75
75
|
rdoc (3.12)
|
76
76
|
json (~> 1.4)
|
@@ -82,17 +82,17 @@ GEM
|
|
82
82
|
rspec-expectations (2.9.1)
|
83
83
|
diff-lcs (~> 1.1.3)
|
84
84
|
rspec-mocks (2.9.0)
|
85
|
-
sprockets (2.1.
|
85
|
+
sprockets (2.1.3)
|
86
86
|
hike (~> 1.2)
|
87
87
|
rack (~> 1.0)
|
88
88
|
tilt (~> 1.1, != 1.3.0)
|
89
89
|
sqlite3 (1.3.5)
|
90
|
-
thor (0.
|
90
|
+
thor (0.16.0)
|
91
91
|
tilt (1.3.3)
|
92
|
-
treetop (1.4.
|
92
|
+
treetop (1.4.12)
|
93
93
|
polyglot
|
94
94
|
polyglot (>= 0.3.1)
|
95
|
-
tzinfo (0.3.
|
95
|
+
tzinfo (0.3.34)
|
96
96
|
|
97
97
|
PLATFORMS
|
98
98
|
ruby
|
data/README.markdown
CHANGED
@@ -14,7 +14,7 @@ The main goals of this gem are:
|
|
14
14
|
|
15
15
|
Just add the following to your Gemfile.
|
16
16
|
|
17
|
-
gem 'acts_as_votable'
|
17
|
+
gem 'acts_as_votable', '~> 0.4.0'
|
18
18
|
|
19
19
|
And follow that up with a ``bundle install``.
|
20
20
|
|
@@ -156,6 +156,27 @@ You can also check whether the voter has voted up or down.
|
|
156
156
|
@user.voted_up_on? @comment3 # => false
|
157
157
|
@user.voted_down_on? @comment3 # => false
|
158
158
|
|
159
|
+
Also, you can obtain a list of all the objects a user has voted for.
|
160
|
+
This returns the actual objects instead of instances of the Vote model.
|
161
|
+
All objects are eager loaded
|
162
|
+
|
163
|
+
@user.find_voted_items
|
164
|
+
|
165
|
+
@user.find_up_voted_items
|
166
|
+
@user.find_liked_items
|
167
|
+
|
168
|
+
@user.find_down_voted_items
|
169
|
+
@user.find_disliked_items
|
170
|
+
|
171
|
+
Members of an individual model that a user has voted for can also be
|
172
|
+
displayed. The result is an ActiveRecord Relation.
|
173
|
+
|
174
|
+
@user.get_voted Comment
|
175
|
+
|
176
|
+
@user.get_up_voted Comment
|
177
|
+
|
178
|
+
@user.get_down_voted Comment
|
179
|
+
|
159
180
|
### Registered Votes
|
160
181
|
|
161
182
|
Voters can only vote once per model. In this example the 2nd vote does not count
|
@@ -96,5 +96,36 @@ module ActsAsVotable
|
|
96
96
|
find_votes_for_class klass, :vote_flag => false
|
97
97
|
end
|
98
98
|
|
99
|
+
# Including polymporphic relations for eager loading
|
100
|
+
def include_objects
|
101
|
+
ActsAsVotable::Vote.includes(:votable)
|
102
|
+
end
|
103
|
+
|
104
|
+
def find_voted_items extra_conditions = {}
|
105
|
+
options = extra_conditions.merge :voter_id => id, :voter_type => self.class.name
|
106
|
+
include_objects.where(options).collect(&:votable)
|
107
|
+
end
|
108
|
+
|
109
|
+
def find_up_voted_items extra_conditions = {}
|
110
|
+
find_voted_items extra_conditions.merge(:vote_flag => true)
|
111
|
+
end
|
112
|
+
alias_method :find_liked_items, :find_up_voted_items
|
113
|
+
|
114
|
+
def find_down_voted_items extra_conditions = {}
|
115
|
+
find_voted_items extra_conditions.merge(:vote_flag => false)
|
116
|
+
end
|
117
|
+
alias_method :find_disliked_items, :find_down_voted_items
|
118
|
+
|
119
|
+
def get_voted klass, extra_conditions = {}
|
120
|
+
klass.joins(:votes).merge find_votes(extra_conditions)
|
121
|
+
end
|
122
|
+
|
123
|
+
def get_up_voted klass
|
124
|
+
klass.joins(:votes).merge find_up_votes
|
125
|
+
end
|
126
|
+
|
127
|
+
def get_down_voted klass
|
128
|
+
klass.joins(:votes).merge find_down_votes
|
129
|
+
end
|
99
130
|
end
|
100
131
|
end
|
data/spec/voter_spec.rb
CHANGED
@@ -145,5 +145,96 @@ describe ActsAsVotable::Voter do
|
|
145
145
|
@voter.voted_as_when_voting_on(@votable).should be false
|
146
146
|
end
|
147
147
|
|
148
|
+
describe '#find_voted_items' do
|
149
|
+
it 'returns objects that a user has upvoted for' do
|
150
|
+
@votable.vote :voter => @voter
|
151
|
+
@votable2.vote :voter => @voter2
|
152
|
+
@voter.find_voted_items.should include @votable
|
153
|
+
@voter.find_voted_items.size.should == 1
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'returns objects that a user has downvoted for' do
|
157
|
+
@votable.vote_down @voter
|
158
|
+
@votable2.vote_down @voter2
|
159
|
+
@voter.find_voted_items.should include @votable
|
160
|
+
@voter.find_voted_items.size.should == 1
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe '#find_up_voted_items' do
|
165
|
+
it 'returns objects that a user has upvoted for' do
|
166
|
+
@votable.vote :voter => @voter
|
167
|
+
@votable2.vote :voter => @voter2
|
168
|
+
@voter.find_up_voted_items.should include @votable
|
169
|
+
@voter.find_up_voted_items.size.should == 1
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'does not return objects that a user has downvoted for' do
|
173
|
+
@votable.vote_down @voter
|
174
|
+
@voter.find_up_voted_items.size.should == 0
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
describe '#find_down_voted_items' do
|
179
|
+
it 'does not return objects that a user has upvoted for' do
|
180
|
+
@votable.vote :voter => @voter
|
181
|
+
@voter.find_down_voted_items.size.should == 0
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'returns objects that a user has downvoted for' do
|
185
|
+
@votable.vote_down @voter
|
186
|
+
@votable2.vote_down @voter2
|
187
|
+
@voter.find_down_voted_items.should include @votable
|
188
|
+
@voter.find_down_voted_items.size.should == 1
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
describe '#get_voted' do
|
193
|
+
subject { @voter.get_voted(@votable.class) }
|
194
|
+
|
195
|
+
it 'returns objects of a class that a voter has voted for' do
|
196
|
+
@votable.vote :voter => @voter
|
197
|
+
@votable2.vote_down @voter
|
198
|
+
subject.should include @votable
|
199
|
+
subject.should include @votable2
|
200
|
+
subject.size.should == 2
|
201
|
+
end
|
202
|
+
|
203
|
+
it 'does not return objects of a class that a voter has voted for' do
|
204
|
+
@votable.vote :voter => @voter2
|
205
|
+
@votable2.vote :voter => @voter2
|
206
|
+
subject.size.should == 0
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
describe '#get_up_voted' do
|
211
|
+
subject { @voter.get_up_voted(@votable.class) }
|
212
|
+
|
213
|
+
it 'returns up voted items that a voter has voted for' do
|
214
|
+
@votable.vote :voter => @voter
|
215
|
+
subject.should include @votable
|
216
|
+
subject.size.should == 1
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'does not return down voted items a voter has voted for' do
|
220
|
+
@votable.vote_down @voter
|
221
|
+
subject.size.should == 0
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
describe '#get_down_voted' do
|
226
|
+
subject { @voter.get_down_voted(@votable.class) }
|
227
|
+
|
228
|
+
it 'does not return up voted items that a voter has voted for' do
|
229
|
+
@votable.vote :voter => @voter
|
230
|
+
subject.size.should == 0
|
231
|
+
end
|
232
|
+
|
233
|
+
it 'returns down voted items a voter has voted for' do
|
234
|
+
@votable.vote_down @voter
|
235
|
+
subject.should include @votable
|
236
|
+
subject.size.should == 1
|
237
|
+
end
|
238
|
+
end
|
148
239
|
end
|
149
240
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_votable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: sqlite3
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: rails
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
@@ -43,7 +53,12 @@ dependencies:
|
|
43
53
|
version: 3.0.0
|
44
54
|
type: :runtime
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.0.0
|
47
62
|
description: Rails gem to allowing records to be votable
|
48
63
|
email:
|
49
64
|
- ryanto
|
@@ -83,15 +98,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
98
|
- - ! '>='
|
84
99
|
- !ruby/object:Gem::Version
|
85
100
|
version: '0'
|
101
|
+
segments:
|
102
|
+
- 0
|
103
|
+
hash: -2774267182574358565
|
86
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
105
|
none: false
|
88
106
|
requirements:
|
89
107
|
- - ! '>='
|
90
108
|
- !ruby/object:Gem::Version
|
91
109
|
version: '0'
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
hash: -2774267182574358565
|
92
113
|
requirements: []
|
93
114
|
rubyforge_project: acts_as_votable
|
94
|
-
rubygems_version: 1.8.
|
115
|
+
rubygems_version: 1.8.24
|
95
116
|
signing_key:
|
96
117
|
specification_version: 3
|
97
118
|
summary: Rails gem to allowing records to be votable
|