thumbs_up 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/acts_as_voteable.rb +1 -1
- data/lib/thumbs_up/version.rb +1 -1
- data/test/test_helper.rb +11 -0
- data/test/thumbs_up_test.rb +13 -0
- metadata +5 -5
data/lib/acts_as_voteable.rb
CHANGED
@@ -24,7 +24,7 @@ module ThumbsUp
|
|
24
24
|
# You can also have the upvotes and downvotes returned separately in the same query:
|
25
25
|
# Post.plusminus_tally(:separate_updown => true)
|
26
26
|
def plusminus_tally(params = {})
|
27
|
-
t = self.joins("LEFT OUTER JOIN #{Vote.table_name} ON #{self.table_name}.id = #{Vote.table_name}.voteable_id")
|
27
|
+
t = self.joins("LEFT OUTER JOIN #{Vote.table_name} ON #{self.table_name}.id = #{Vote.table_name}.voteable_id AND #{Vote.table_name}.voteable_type = '#{self.name}'")
|
28
28
|
t = t.order("plusminus_tally DESC")
|
29
29
|
t = t.group("#{self.table_name}.id")
|
30
30
|
t = t.select("#{self.table_name}.*")
|
data/lib/thumbs_up/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -75,6 +75,12 @@ ActiveRecord::Schema.define do
|
|
75
75
|
t.string :name
|
76
76
|
t.string :description
|
77
77
|
end
|
78
|
+
|
79
|
+
create_table :other_items, :force => true do |t|
|
80
|
+
t.integer :user_id
|
81
|
+
t.string :name
|
82
|
+
t.string :description
|
83
|
+
end
|
78
84
|
end
|
79
85
|
|
80
86
|
require 'thumbs_up'
|
@@ -100,6 +106,11 @@ class Item < ActiveRecord::Base
|
|
100
106
|
belongs_to :user
|
101
107
|
end
|
102
108
|
|
109
|
+
class OtherItem < ActiveRecord::Base
|
110
|
+
acts_as_voteable
|
111
|
+
belongs_to :user
|
112
|
+
end
|
113
|
+
|
103
114
|
class User < ActiveRecord::Base
|
104
115
|
acts_as_voter
|
105
116
|
has_many :items
|
data/test/thumbs_up_test.rb
CHANGED
@@ -354,4 +354,17 @@ class TestThumbsUp < Test::Unit::TestCase
|
|
354
354
|
assert_equal 4, users[0].karma
|
355
355
|
assert_equal 0, users[1].karma
|
356
356
|
end
|
357
|
+
|
358
|
+
def test_plusminus_tally_scopes_by_voteable_type
|
359
|
+
user = User.create(:name => 'david')
|
360
|
+
item = Item.create(:name => 'XBOX', :description => 'XBOX console')
|
361
|
+
another_item = OtherItem.create(:name => 'Playstation', :description => 'Playstation console')
|
362
|
+
|
363
|
+
user.vote_for(item)
|
364
|
+
user.vote_for(another_item)
|
365
|
+
|
366
|
+
assert_equal 1, Item.plusminus_tally.sum(&:plusminus_tally).to_i
|
367
|
+
assert_equal 1, OtherItem.plusminus_tally.sum(&:plusminus_tally).to_i
|
368
|
+
end
|
369
|
+
|
357
370
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thumbs_up
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ authors:
|
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
|
-
date: 2012-
|
17
|
+
date: 2012-09-19 00:00:00.000000000 Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: activerecord
|
@@ -166,7 +166,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
166
166
|
version: '0'
|
167
167
|
segments:
|
168
168
|
- 0
|
169
|
-
hash:
|
169
|
+
hash: 173536367113367291
|
170
170
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
171
|
none: false
|
172
172
|
requirements:
|
@@ -175,10 +175,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
175
|
version: '0'
|
176
176
|
segments:
|
177
177
|
- 0
|
178
|
-
hash:
|
178
|
+
hash: 173536367113367291
|
179
179
|
requirements: []
|
180
180
|
rubyforge_project:
|
181
|
-
rubygems_version: 1.8.
|
181
|
+
rubygems_version: 1.8.23
|
182
182
|
signing_key:
|
183
183
|
specification_version: 3
|
184
184
|
summary: Voting for ActiveRecord with multiple vote sources and karma calculation.
|