acts_as_votable 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +76 -65
- data/README.markdown +28 -1
- data/lib/acts_as_votable/version.rb +1 -1
- data/lib/acts_as_votable/votable.rb +27 -10
- data/lib/acts_as_votable/vote.rb +5 -0
- data/lib/acts_as_votable/voter.rb +14 -13
- data/spec/votable_spec.rb +54 -5
- data/spec/voter_spec.rb +17 -4
- metadata +26 -11
data/Gemfile.lock
CHANGED
@@ -1,87 +1,98 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
acts_as_votable (0.
|
4
|
+
acts_as_votable (0.2.0)
|
5
5
|
rails (>= 3.0.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
rack (~> 1.2
|
21
|
-
rack-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
arel (
|
38
|
-
builder (
|
39
|
-
diff-lcs (1.1.
|
40
|
-
erubis (2.
|
41
|
-
|
42
|
-
i18n (0.
|
43
|
-
|
44
|
-
|
10
|
+
actionmailer (3.2.3)
|
11
|
+
actionpack (= 3.2.3)
|
12
|
+
mail (~> 2.4.4)
|
13
|
+
actionpack (3.2.3)
|
14
|
+
activemodel (= 3.2.3)
|
15
|
+
activesupport (= 3.2.3)
|
16
|
+
builder (~> 3.0.0)
|
17
|
+
erubis (~> 2.7.0)
|
18
|
+
journey (~> 1.0.1)
|
19
|
+
rack (~> 1.4.0)
|
20
|
+
rack-cache (~> 1.2)
|
21
|
+
rack-test (~> 0.6.1)
|
22
|
+
sprockets (~> 2.1.2)
|
23
|
+
activemodel (3.2.3)
|
24
|
+
activesupport (= 3.2.3)
|
25
|
+
builder (~> 3.0.0)
|
26
|
+
activerecord (3.2.3)
|
27
|
+
activemodel (= 3.2.3)
|
28
|
+
activesupport (= 3.2.3)
|
29
|
+
arel (~> 3.0.2)
|
30
|
+
tzinfo (~> 0.3.29)
|
31
|
+
activeresource (3.2.3)
|
32
|
+
activemodel (= 3.2.3)
|
33
|
+
activesupport (= 3.2.3)
|
34
|
+
activesupport (3.2.3)
|
35
|
+
i18n (~> 0.6)
|
36
|
+
multi_json (~> 1.0)
|
37
|
+
arel (3.0.2)
|
38
|
+
builder (3.0.0)
|
39
|
+
diff-lcs (1.1.3)
|
40
|
+
erubis (2.7.0)
|
41
|
+
hike (1.2.1)
|
42
|
+
i18n (0.6.0)
|
43
|
+
journey (1.0.3)
|
44
|
+
json (1.6.6)
|
45
|
+
mail (2.4.4)
|
45
46
|
i18n (>= 0.4.0)
|
46
47
|
mime-types (~> 1.16)
|
47
48
|
treetop (~> 1.4.8)
|
48
|
-
mime-types (1.
|
49
|
-
|
50
|
-
|
51
|
-
rack
|
52
|
-
|
53
|
-
|
49
|
+
mime-types (1.18)
|
50
|
+
multi_json (1.2.0)
|
51
|
+
polyglot (0.3.3)
|
52
|
+
rack (1.4.1)
|
53
|
+
rack-cache (1.2)
|
54
|
+
rack (>= 0.4)
|
55
|
+
rack-ssl (1.3.2)
|
56
|
+
rack
|
57
|
+
rack-test (0.6.1)
|
54
58
|
rack (>= 1.0)
|
55
|
-
rails (3.
|
56
|
-
actionmailer (= 3.
|
57
|
-
actionpack (= 3.
|
58
|
-
activerecord (= 3.
|
59
|
-
activeresource (= 3.
|
60
|
-
activesupport (= 3.
|
59
|
+
rails (3.2.3)
|
60
|
+
actionmailer (= 3.2.3)
|
61
|
+
actionpack (= 3.2.3)
|
62
|
+
activerecord (= 3.2.3)
|
63
|
+
activeresource (= 3.2.3)
|
64
|
+
activesupport (= 3.2.3)
|
61
65
|
bundler (~> 1.0)
|
62
|
-
railties (= 3.
|
63
|
-
railties (3.
|
64
|
-
actionpack (= 3.
|
65
|
-
activesupport (= 3.
|
66
|
+
railties (= 3.2.3)
|
67
|
+
railties (3.2.3)
|
68
|
+
actionpack (= 3.2.3)
|
69
|
+
activesupport (= 3.2.3)
|
70
|
+
rack-ssl (~> 1.3.2)
|
66
71
|
rake (>= 0.8.7)
|
67
72
|
rdoc (~> 3.4)
|
68
|
-
thor (~> 0.14.
|
69
|
-
rake (0.9.2)
|
70
|
-
rdoc (3.
|
71
|
-
|
72
|
-
|
73
|
-
rspec-
|
74
|
-
rspec-
|
75
|
-
|
76
|
-
rspec-
|
77
|
-
|
78
|
-
|
79
|
-
|
73
|
+
thor (~> 0.14.6)
|
74
|
+
rake (0.9.2.2)
|
75
|
+
rdoc (3.12)
|
76
|
+
json (~> 1.4)
|
77
|
+
rspec (2.9.0)
|
78
|
+
rspec-core (~> 2.9.0)
|
79
|
+
rspec-expectations (~> 2.9.0)
|
80
|
+
rspec-mocks (~> 2.9.0)
|
81
|
+
rspec-core (2.9.0)
|
82
|
+
rspec-expectations (2.9.1)
|
83
|
+
diff-lcs (~> 1.1.3)
|
84
|
+
rspec-mocks (2.9.0)
|
85
|
+
sprockets (2.1.2)
|
86
|
+
hike (~> 1.2)
|
87
|
+
rack (~> 1.0)
|
88
|
+
tilt (~> 1.1, != 1.3.0)
|
89
|
+
sqlite3 (1.3.5)
|
80
90
|
thor (0.14.6)
|
91
|
+
tilt (1.3.3)
|
81
92
|
treetop (1.4.10)
|
82
93
|
polyglot
|
83
94
|
polyglot (>= 0.3.1)
|
84
|
-
tzinfo (0.3.
|
95
|
+
tzinfo (0.3.33)
|
85
96
|
|
86
97
|
PLATFORMS
|
87
98
|
ruby
|
data/README.markdown
CHANGED
@@ -77,7 +77,7 @@ Revisiting the previous example of code.
|
|
77
77
|
# negative votes
|
78
78
|
@post.downvote_from @user2
|
79
79
|
@post.vote :voter => @user2, :vote => 'bad'
|
80
|
-
|
80
|
+
|
81
81
|
# tally them up!
|
82
82
|
@post.votes.size # => 5
|
83
83
|
@post.likes.size # => 3
|
@@ -85,6 +85,33 @@ Revisiting the previous example of code.
|
|
85
85
|
@post.dislikes.size # => 2
|
86
86
|
@post.downvotes.size # => 2
|
87
87
|
|
88
|
+
Active Record scopes are provided to make life easier.
|
89
|
+
|
90
|
+
@post.votes.up.by_type(User)
|
91
|
+
@post.votes.down
|
92
|
+
@user1.votes.up
|
93
|
+
@user1.votes.down
|
94
|
+
@user1.votes.up.by_type(Post)
|
95
|
+
|
96
|
+
Once scoping is complete, you can also trigger a get for the
|
97
|
+
voter/votable
|
98
|
+
|
99
|
+
@post.votes.up.by_type(User).voters
|
100
|
+
@post.votes.down.by_type(User).voters
|
101
|
+
|
102
|
+
@user.votes.up.for_type(Post).votables
|
103
|
+
@user.votes.up.votables
|
104
|
+
|
105
|
+
You can also 'unvote' a model to remove a previous vote.
|
106
|
+
|
107
|
+
@post.liked_by @user1
|
108
|
+
@post.unlike_by @user1
|
109
|
+
|
110
|
+
@post.disliked_by @user1
|
111
|
+
@post.undisliked_by @user1
|
112
|
+
|
113
|
+
Unvoting works for both positive and negative votes.
|
114
|
+
|
88
115
|
### The Voter
|
89
116
|
|
90
117
|
You can have your voters ``acts_as_voter`` to provide some reserve functionality.
|
@@ -26,13 +26,20 @@ module ActsAsVotable
|
|
26
26
|
|
27
27
|
:down_votes => [
|
28
28
|
:false_votes, :downs, :downvotes, :dislikes, :negatives
|
29
|
+
],
|
30
|
+
:unvote => [
|
31
|
+
:unliked_by, :undisliked_by
|
29
32
|
]
|
30
|
-
|
31
33
|
}
|
32
34
|
|
33
35
|
base.class_eval do
|
34
36
|
|
35
37
|
belongs_to :votable, :polymorphic => true
|
38
|
+
has_many :votes, :class_name => "ActsAsVotable::Vote", :as => :votable do
|
39
|
+
def voters
|
40
|
+
includes(:voter).map(&:voter)
|
41
|
+
end
|
42
|
+
end
|
36
43
|
|
37
44
|
aliases.each do |method, links|
|
38
45
|
links.each do |new_method|
|
@@ -70,12 +77,12 @@ module ActsAsVotable
|
|
70
77
|
end
|
71
78
|
|
72
79
|
# find the vote
|
73
|
-
|
80
|
+
_votes_ = find_votes({
|
74
81
|
:voter_id => options[:voter].id,
|
75
82
|
:voter_type => options[:voter].class.name
|
76
83
|
})
|
77
84
|
|
78
|
-
if
|
85
|
+
if _votes_.count == 0
|
79
86
|
# this voter has never voted
|
80
87
|
vote = ActsAsVotable::Vote.new(
|
81
88
|
:votable => self,
|
@@ -83,7 +90,7 @@ module ActsAsVotable
|
|
83
90
|
)
|
84
91
|
else
|
85
92
|
# this voter is potentially changing his vote
|
86
|
-
vote =
|
93
|
+
vote = _votes_.first
|
87
94
|
end
|
88
95
|
|
89
96
|
last_update = vote.updated_at
|
@@ -101,6 +108,17 @@ module ActsAsVotable
|
|
101
108
|
|
102
109
|
end
|
103
110
|
|
111
|
+
def unvote args = {}
|
112
|
+
return false if args[:voter].nil?
|
113
|
+
_votes_ = find_votes(:voter_id => args[:voter].id, :voter_type => args[:voter].class.name)
|
114
|
+
|
115
|
+
return true if _votes_.size == 0
|
116
|
+
_votes_.each(&:destroy)
|
117
|
+
update_cached_votes
|
118
|
+
self.vote_registered = false if votes.count == 0
|
119
|
+
return true
|
120
|
+
end
|
121
|
+
|
104
122
|
def vote_up voter
|
105
123
|
self.vote :voter => voter, :vote => true
|
106
124
|
end
|
@@ -133,9 +151,8 @@ module ActsAsVotable
|
|
133
151
|
|
134
152
|
# results
|
135
153
|
def find_votes extra_conditions = {}
|
136
|
-
|
154
|
+
votes.where(extra_conditions)
|
137
155
|
end
|
138
|
-
alias :votes :find_votes
|
139
156
|
|
140
157
|
def up_votes
|
141
158
|
find_votes(:vote_flag => true)
|
@@ -151,27 +168,27 @@ module ActsAsVotable
|
|
151
168
|
if !skip_cache && self.respond_to?(:cached_votes_total)
|
152
169
|
return self.send(:cached_votes_total)
|
153
170
|
end
|
154
|
-
find_votes.
|
171
|
+
find_votes.count
|
155
172
|
end
|
156
173
|
|
157
174
|
def count_votes_up skip_cache = false
|
158
175
|
if !skip_cache && self.respond_to?(:cached_votes_up)
|
159
176
|
return self.send(:cached_votes_up)
|
160
177
|
end
|
161
|
-
up_votes.
|
178
|
+
up_votes.count
|
162
179
|
end
|
163
180
|
|
164
181
|
def count_votes_down skip_cache = false
|
165
182
|
if !skip_cache && self.respond_to?(:cached_votes_down)
|
166
183
|
return self.send(:cached_votes_down)
|
167
184
|
end
|
168
|
-
down_votes.
|
185
|
+
down_votes.count
|
169
186
|
end
|
170
187
|
|
171
188
|
# voters
|
172
189
|
def voted_on_by? voter
|
173
190
|
votes = find_votes :voter_id => voter.id, :voter_type => voter.class.name
|
174
|
-
votes.
|
191
|
+
votes.count > 0
|
175
192
|
end
|
176
193
|
|
177
194
|
end
|
data/lib/acts_as_votable/vote.rb
CHANGED
@@ -13,6 +13,11 @@ module ActsAsVotable
|
|
13
13
|
belongs_to :votable, :polymorphic => true
|
14
14
|
belongs_to :voter, :polymorphic => true
|
15
15
|
|
16
|
+
scope :up, where(:vote_flag => true)
|
17
|
+
scope :down, where(:vote_flag => false)
|
18
|
+
scope :for_type, lambda{ |klass| where(:votable_type => klass) }
|
19
|
+
scope :by_type, lambda{ |klass| where(:voter_type => klass) }
|
20
|
+
|
16
21
|
validates_presence_of :votable_id
|
17
22
|
validates_presence_of :voter_id
|
18
23
|
|
@@ -5,13 +5,19 @@ module ActsAsVotable
|
|
5
5
|
|
6
6
|
# allow user to define these
|
7
7
|
aliases = {
|
8
|
-
:vote_up_for
|
9
|
-
:vote_down_for => [:dislikes, :downvotes, :down_votes]
|
8
|
+
:vote_up_for => [:likes, :upvotes, :up_votes],
|
9
|
+
:vote_down_for => [:dislikes, :downvotes, :down_votes],
|
10
|
+
:unvote_for => [:unlike, :undislike]
|
10
11
|
}
|
11
12
|
|
12
13
|
base.class_eval do
|
13
14
|
|
14
15
|
belongs_to :voter, :polymorphic => true
|
16
|
+
has_many :votes, :class_name => "ActsAsVotable::Vote", :as => :voter do
|
17
|
+
def votables
|
18
|
+
includes(:votable).map(&:votable)
|
19
|
+
end
|
20
|
+
end
|
15
21
|
|
16
22
|
aliases.each do |method, links|
|
17
23
|
links.each do |new_method|
|
@@ -23,19 +29,12 @@ module ActsAsVotable
|
|
23
29
|
|
24
30
|
end
|
25
31
|
|
26
|
-
def default_conditions
|
27
|
-
{
|
28
|
-
:voter_id => self.id,
|
29
|
-
:voter_type => self.class.name
|
30
|
-
}
|
31
|
-
end
|
32
|
-
|
33
32
|
# voting
|
34
33
|
def vote args
|
35
34
|
args[:votable].vote args.merge({:voter => self})
|
36
35
|
end
|
37
36
|
|
38
|
-
def vote_up_for model
|
37
|
+
def vote_up_for model=nil
|
39
38
|
vote :votable => model, :vote => true
|
40
39
|
end
|
41
40
|
|
@@ -43,6 +42,10 @@ module ActsAsVotable
|
|
43
42
|
vote :votable => model, :vote => false
|
44
43
|
end
|
45
44
|
|
45
|
+
def unvote_for model
|
46
|
+
model.unvote :voter => self
|
47
|
+
end
|
48
|
+
|
46
49
|
# results
|
47
50
|
def voted_on? votable
|
48
51
|
votes = find_votes(:votable_id => votable.id, :votable_type => votable.class.name)
|
@@ -58,9 +61,8 @@ module ActsAsVotable
|
|
58
61
|
alias :voted_as_when_voted_for :voted_as_when_voting_on
|
59
62
|
|
60
63
|
def find_votes extra_conditions = {}
|
61
|
-
|
64
|
+
votes.where(extra_conditions)
|
62
65
|
end
|
63
|
-
alias :votes :find_votes
|
64
66
|
|
65
67
|
def find_up_votes
|
66
68
|
find_votes :vote_flag => true
|
@@ -82,6 +84,5 @@ module ActsAsVotable
|
|
82
84
|
find_votes_for_class klass, :vote_flag => false
|
83
85
|
end
|
84
86
|
|
85
|
-
|
86
87
|
end
|
87
88
|
end
|
data/spec/votable_spec.rb
CHANGED
@@ -14,7 +14,7 @@ describe ActsAsVotable::Votable do
|
|
14
14
|
it "should be votable" do
|
15
15
|
Votable.should be_votable
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
describe "voting on a votable object" do
|
19
19
|
|
20
20
|
before(:each) do
|
@@ -24,7 +24,7 @@ describe ActsAsVotable::Votable do
|
|
24
24
|
|
25
25
|
@voter2 = Voter.new(:name => 'a new person')
|
26
26
|
@voter2.save
|
27
|
-
|
27
|
+
|
28
28
|
@votable = Votable.new(:name => 'a voting model')
|
29
29
|
@votable.save
|
30
30
|
end
|
@@ -37,7 +37,7 @@ describe ActsAsVotable::Votable do
|
|
37
37
|
@votable.vote :voter => @voter, :vote => 'yes'
|
38
38
|
@votable.votes.size.should == 1
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
it "should have one vote when voted on twice by the same person" do
|
42
42
|
@votable.vote :voter => @voter, :vote => 'yes'
|
43
43
|
@votable.vote :voter => @voter, :vote => 'no'
|
@@ -87,7 +87,7 @@ describe ActsAsVotable::Votable do
|
|
87
87
|
@votable.vote :voter => @voter, :vote => 'yes'
|
88
88
|
@votable.vote_registered?.should be false
|
89
89
|
end
|
90
|
-
|
90
|
+
|
91
91
|
it "should count the vote as registered if the voter has voted and the vote has changed" do
|
92
92
|
@votable.vote :voter => @voter, :vote => true
|
93
93
|
@votable.vote :voter => @voter, :vote => 'dislike'
|
@@ -99,10 +99,35 @@ describe ActsAsVotable::Votable do
|
|
99
99
|
@votable.voted_on_by?(@voter).should be true
|
100
100
|
end
|
101
101
|
|
102
|
+
it "should unvote a positive vote" do
|
103
|
+
@votable.vote :voter => @voter
|
104
|
+
@votable.unvote :voter => @voter
|
105
|
+
@votable.find_votes.count.should == 0
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should set the votable to unregistered after unvoting" do
|
109
|
+
@votable.vote :voter => @voter
|
110
|
+
@votable.unvote :voter => @voter
|
111
|
+
@votable.vote_registered?.should be false
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should unvote a negative vote" do
|
115
|
+
@votable.vote :voter => @voter, :vote => 'no'
|
116
|
+
@votable.unvote :voter => @voter
|
117
|
+
@votable.find_votes.count.should == 0
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should unvote only the from a single voter" do
|
121
|
+
@votable.vote :voter => @voter
|
122
|
+
@votable.vote :voter => @voter2
|
123
|
+
@votable.unvote :voter => @voter
|
124
|
+
@votable.find_votes.count.should == 1
|
125
|
+
end
|
126
|
+
|
102
127
|
it "should be contained to instances" do
|
103
128
|
votable2 = Votable.new(:name => '2nd votable')
|
104
129
|
votable2.save
|
105
|
-
|
130
|
+
|
106
131
|
@votable.vote :voter => @voter, :vote => false
|
107
132
|
votable2.vote :voter => @voter, :vote => true
|
108
133
|
votable2.vote :voter => @voter, :vote => true
|
@@ -135,6 +160,18 @@ describe ActsAsVotable::Votable do
|
|
135
160
|
@votable_cache.cached_votes_total.should == 1
|
136
161
|
end
|
137
162
|
|
163
|
+
it "should update cached total votes when a vote up is removed" do
|
164
|
+
@votable_cache.vote :voter => @voter, :vote => 'true'
|
165
|
+
@votable_cache.unvote :voter => @voter
|
166
|
+
@votable_cache.cached_votes_total.should == 0
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should update cached total votes when a vote down is removed" do
|
170
|
+
@votable_cache.vote :voter => @voter, :vote => 'false'
|
171
|
+
@votable_cache.unvote :voter => @voter
|
172
|
+
@votable_cache.cached_votes_total.should == 0
|
173
|
+
end
|
174
|
+
|
138
175
|
it "should update cached up votes if there is an up vote column" do
|
139
176
|
@votable_cache.cached_votes_up = 50
|
140
177
|
@votable_cache.vote :voter => @voter
|
@@ -148,6 +185,18 @@ describe ActsAsVotable::Votable do
|
|
148
185
|
@votable_cache.cached_votes_down.should == 1
|
149
186
|
end
|
150
187
|
|
188
|
+
it "should update cached up votes when a vote up is removed" do
|
189
|
+
@votable_cache.vote :voter => @voter, :vote => 'true'
|
190
|
+
@votable_cache.unvote :voter => @voter
|
191
|
+
@votable_cache.cached_votes_up.should == 0
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should update cached down votes when a vote down is removed" do
|
195
|
+
@votable_cache.vote :voter => @voter, :vote => 'false'
|
196
|
+
@votable_cache.unvote :voter => @voter
|
197
|
+
@votable_cache.cached_votes_down.should == 0
|
198
|
+
end
|
199
|
+
|
151
200
|
it "should select from cached total votes if there a total column" do
|
152
201
|
@votable_cache.vote :voter => @voter
|
153
202
|
@votable_cache.cached_votes_total = 50
|
data/spec/voter_spec.rb
CHANGED
@@ -14,7 +14,7 @@ describe ActsAsVotable::Voter do
|
|
14
14
|
it "should be a voter" do
|
15
15
|
Votable.should be_votable
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
describe "voting by a voter" do
|
19
19
|
|
20
20
|
before(:each) do
|
@@ -24,7 +24,7 @@ describe ActsAsVotable::Voter do
|
|
24
24
|
|
25
25
|
@voter2 = Voter.new(:name => 'a new person')
|
26
26
|
@voter2.save
|
27
|
-
|
27
|
+
|
28
28
|
@votable = Votable.new(:name => 'a voting model')
|
29
29
|
@votable.save
|
30
30
|
|
@@ -63,44 +63,59 @@ describe ActsAsVotable::Voter do
|
|
63
63
|
it "should allow the voter to vote up a model" do
|
64
64
|
@voter.vote_up_for @votable
|
65
65
|
@votable.up_votes.first.voter.should == @voter
|
66
|
+
@votable.votes.up.first.voter.should == @voter
|
66
67
|
end
|
67
68
|
|
68
69
|
it "should allow the voter to vote down a model" do
|
69
70
|
@voter.vote_down_for @votable
|
70
71
|
@votable.down_votes.first.voter.should == @voter
|
72
|
+
@votable.votes.down.first.voter.should == @voter
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should allow the voter to unvote a model" do
|
76
|
+
@voter.vote_up_for @votable
|
77
|
+
@voter.unvote_for @votable
|
78
|
+
@votable.find_votes.size.should == 0
|
79
|
+
@votable.votes.count.should == 0
|
71
80
|
end
|
72
81
|
|
73
82
|
it "should get all of the voters votes" do
|
74
83
|
@voter.vote_up_for @votable
|
75
84
|
@voter.find_votes.size.should == 1
|
85
|
+
@voter.votes.up.count.should == 1
|
76
86
|
end
|
77
87
|
|
78
88
|
it "should get all of the voters up votes" do
|
79
89
|
@voter.vote_up_for @votable
|
80
90
|
@voter.find_up_votes.size.should == 1
|
91
|
+
@voter.votes.up.count.should == 1
|
81
92
|
end
|
82
93
|
|
83
94
|
it "should get all of the voters down votes" do
|
84
95
|
@voter.vote_down_for @votable
|
85
96
|
@voter.find_down_votes.size.should == 1
|
97
|
+
@voter.votes.down.count.should == 1
|
86
98
|
end
|
87
99
|
|
88
100
|
it "should get all of the votes votes for a class" do
|
89
101
|
@votable.vote :voter => @voter
|
90
102
|
@votable2.vote :voter => @voter, :vote => false
|
91
103
|
@voter.find_votes_for_class(Votable).size.should == 2
|
104
|
+
@voter.votes.for_type(Votable).count.should == 2
|
92
105
|
end
|
93
106
|
|
94
107
|
it "should get all of the voters up votes for a class" do
|
95
108
|
@votable.vote :voter => @voter
|
96
109
|
@votable2.vote :voter => @voter, :vote => false
|
97
110
|
@voter.find_up_votes_for_class(Votable).size.should == 1
|
111
|
+
@voter.votes.up.for_type(Votable).count.should == 1
|
98
112
|
end
|
99
113
|
|
100
114
|
it "should get all of the voters down votes for a class" do
|
101
115
|
@votable.vote :voter => @voter
|
102
116
|
@votable2.vote :voter => @voter, :vote => false
|
103
117
|
@voter.find_down_votes_for_class(Votable).size.should == 1
|
118
|
+
@voter.votes.down.for_type(Votable).count.should == 1
|
104
119
|
end
|
105
120
|
|
106
121
|
it "should be contained to instances" do
|
@@ -111,6 +126,4 @@ describe ActsAsVotable::Voter do
|
|
111
126
|
end
|
112
127
|
|
113
128
|
end
|
114
|
-
|
115
|
-
|
116
129
|
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.2.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:
|
12
|
+
date: 2012-04-25 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
|
@@ -85,7 +100,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
100
|
version: '0'
|
86
101
|
segments:
|
87
102
|
- 0
|
88
|
-
hash:
|
103
|
+
hash: 2055289200548922413
|
89
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
105
|
none: false
|
91
106
|
requirements:
|
@@ -94,10 +109,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
109
|
version: '0'
|
95
110
|
segments:
|
96
111
|
- 0
|
97
|
-
hash:
|
112
|
+
hash: 2055289200548922413
|
98
113
|
requirements: []
|
99
114
|
rubyforge_project: acts_as_votable
|
100
|
-
rubygems_version: 1.8.
|
115
|
+
rubygems_version: 1.8.21
|
101
116
|
signing_key:
|
102
117
|
specification_version: 3
|
103
118
|
summary: Rails gem to allowing records to be votable
|