thumbs_up 0.6.7 → 0.6.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 464148d08066dd7089e51825a2024c8048f727de
4
- data.tar.gz: 6d27f12fe8acee4b7fb006549a0d24e820484ccb
3
+ metadata.gz: 9b4c6157fab12e707bdf8d681ccb3033ab05deba
4
+ data.tar.gz: 4c13e8131cb4f9d897ff097b756aad21c9cb2fcd
5
5
  SHA512:
6
- metadata.gz: cec0d3ddfd4102a86b52c116d4f342d8f3c0e5cb323fc761f327744959d6378925ca098a99f1023503c39bef5383e6fd2ed3788b4f82d2cf899ebe362006c5cc
7
- data.tar.gz: 7a01b8de0f56bfa0ad9b76fb018c722dd1f5807548dd6ba323bff20591b1447370b09764a2e751ab3eb4ba4b62303aa03cc475a55306f1170910e70e539affcf
6
+ metadata.gz: e8fd16303bc0b5a878ee487e4872760defb9e83673bae944b75e88ec84773b6adcc9ad428ea75e929cbf0644cf68fe1ad234246be7f0b22e75e38730bd0f1912
7
+ data.tar.gz: f7a186650adf759f1e0ba58f996f43e204bfc677af28446d9ef9c298735f64bd0c29dac18e88be5d1c7280712f11def965020c5b3a98e03462cda6c91f72e82f
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Brady Bouchard (brady@thewellinspired.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -23,28 +23,31 @@ Installation
23
23
  ============
24
24
 
25
25
  ### Require the gem:
26
-
27
- gem 'thumbs_up'
26
+ ```shell
27
+ gem 'thumbs_up'
28
+ ```
28
29
 
29
30
  ### Create and run the ThumbsUp migration:
30
-
31
- rails generate thumbs_up
32
- rake db:migrate
31
+ ```shell
32
+ rails generate thumbs_up
33
+ rake db:migrate
34
+ ```
33
35
 
34
36
  Configuration
35
37
  =============
36
38
 
37
39
  The relationship setup by the acts_as_voteable and acts_as_voter mixins both default to `votes`. This causes one to obscure the other if you have a single class that votes on other instances of the same class. If you have this scenario:
38
-
39
- class User < ActiveRecord::Base
40
- acts_as_voter # relationship :votes will be obscured by the same named relationship from acts_as_voteable :(
41
- acts_as_voteable
42
- end
43
-
40
+ ```ruby
41
+ class User < ActiveRecord::Base
42
+ acts_as_voter # relationship :votes will be obscured by the same named relationship from acts_as_voteable :(
43
+ acts_as_voteable
44
+ end
45
+ ```
44
46
  Configure alternate relationship names in an initializer at `config/initializers/thumbs_up.rb`:
45
-
46
- ThumbsUp.configuration.voteable_relationship_name = :votes_on # defaults to :votes
47
- ThumbsUp.configuration.voter_relationship_name = :votes_by # defaults to :votes
47
+ ```ruby
48
+ ThumbsUp.configuration.voteable_relationship_name = :votes_on # defaults to :votes
49
+ ThumbsUp.configuration.voter_relationship_name = :votes_by # defaults to :votes
50
+ ```
48
51
 
49
52
 
50
53
  Usage
@@ -53,84 +56,94 @@ Usage
53
56
  ## Getting Started
54
57
 
55
58
  ### Turn your AR models into something that can be voted upon.
59
+ ```ruby
60
+ class SomeModel < ActiveRecord::Base
61
+ acts_as_voteable
62
+ end
56
63
 
57
- class SomeModel < ActiveRecord::Base
58
- acts_as_voteable
59
- end
60
-
61
- class Question < ActiveRecord::Base
62
- acts_as_voteable
63
- end
64
+ class Question < ActiveRecord::Base
65
+ acts_as_voteable
66
+ end
67
+ ```
64
68
 
65
69
  ### Turn your Users (or any other model) into voters.
66
-
67
- class User < ActiveRecord::Base
68
- acts_as_voter
69
- # The following line is optional, and tracks karma (up votes) for questions this user has submitted.
70
- # Each question has a submitter_id column that tracks the user who submitted it.
71
- # The option :weight value will be multiplied to any karma from that voteable model (defaults to 1).
72
- # You can track any voteable model.
73
- has_karma :questions, :as => :submitter, :weight => 0.5
74
- # Karma by default is only calculated from upvotes. If you pass an array to the weight option, you can count downvotes as well (below, downvotes count for half as much karma against you):
75
- has_karma :questions, :as => :submitter, :weight => [ 1, 0.5 ]
76
- end
77
-
78
- class Robot < ActiveRecord::Base
79
- acts_as_voter
80
- end
70
+ ```ruby
71
+ class User < ActiveRecord::Base
72
+ acts_as_voter
73
+ # The following line is optional, and tracks karma (up votes) for questions this user has submitted.
74
+ # Each question has a submitter_id column that tracks the user who submitted it.
75
+ # The option :weight value will be multiplied to any karma from that voteable model (defaults to 1).
76
+ # You can track any voteable model.
77
+ has_karma :questions, :as => :submitter, :weight => 0.5
78
+ # Karma by default is only calculated from upvotes. If you pass an array to the weight option, you can count downvotes as well (below, downvotes count for half as much karma against you):
79
+ has_karma :questions, :as => :submitter, :weight => [ 1, 0.5 ]
80
+ end
81
+
82
+ class Robot < ActiveRecord::Base
83
+ acts_as_voter
84
+ end
85
+ ```
81
86
 
82
87
  ### To cast a vote for a Model you can do the following:
83
88
 
84
89
  #### Shorthand syntax
85
- voter.vote_for(voteable) # Adds a +1 vote
86
- voter.vote_against(voteable) # Adds a -1 vote
87
- voter.vote(voteable, vote) # Adds either a +1 or -1 vote: vote => true (+1), vote => false (-1)
90
+ ```ruby
91
+ voter.vote_for(voteable) # Adds a +1 vote
92
+ voter.vote_against(voteable) # Adds a -1 vote
93
+ voter.vote(voteable, vote) # Adds either a +1 or -1 vote: vote => true (+1), vote => false (-1)
88
94
 
89
- voter.vote_exclusively_for(voteable) # Removes any previous votes by that particular voter, and votes for.
90
- voter.vote_exclusively_against(voteable) # Removes any previous votes by that particular voter, and votes against.
95
+ voter.vote_exclusively_for(voteable) # Removes any previous votes by that particular voter, and votes for.
96
+ voter.vote_exclusively_against(voteable) # Removes any previous votes by that particular voter, and votes against.
91
97
 
92
- voter.unvote_for(voteable) # Clears all votes for that user
98
+ voter.unvote_for(voteable) # Clears all votes for that user
99
+ ```
93
100
 
94
101
  ### Querying votes
95
102
 
96
103
  Did the first user vote for the Car with id = 2 already?
97
-
98
- u = User.first
99
- u.vote_for(Car.find(2))
100
- u.voted_on?(Car.find(2)) #=> true
104
+ ```ruby
105
+ u = User.first
106
+ u.vote_for(Car.find(2))
107
+ u.voted_on?(Car.find(2)) #=> true
108
+ ```
101
109
 
102
110
  Did the first user vote for or against the Car with id = 2?
103
-
104
- u = User.first
105
- u.vote_for(Car.find(2))
106
- u.voted_for?(Car.find(2)) #=> true
107
- u.voted_against?(Car.find(2)) #=> false
111
+ ```ruby
112
+ u = User.first
113
+ u.vote_for(Car.find(2))
114
+ u.voted_for?(Car.find(2)) #=> true
115
+ u.voted_against?(Car.find(2)) #=> false
116
+ ```
108
117
 
109
118
  Or check directly!
119
+ ```ruby
120
+ u = User.first
121
+ u.vote_for(Car.find(2))
122
+ u.voted_how?(Car.find(2)) #=> true, if voted_for
110
123
 
111
- u = User.first
112
- u.vote_for(Car.find(2))
113
- u.voted_how?(Car.find(2)) #=> true, if voted_for
114
-
115
- u.vote_against(Car.find(3))
116
- u.voted_how?(Car.find(3)) #=> false, if voted_against
124
+ u.vote_against(Car.find(3))
125
+ u.voted_how?(Car.find(3)) #=> false, if voted_against
117
126
 
118
- u.vote_for(Car.find(4))
119
- u.voted_how?(Car.find(4)) #=> nil, if didn't vote for it
127
+ u.vote_for(Car.find(4))
128
+ u.voted_how?(Car.find(4)) #=> nil, if didn't vote for it
129
+ ```
120
130
 
121
131
  in case you use `--unique-voting false` (documented below):
122
-
123
- u.voted_how?(Car.find(2)) #=> [false, true, true, false]
132
+ ```ruby
133
+ u.voted_how?(Car.find(2)) #=> [false, true, true, false]
134
+ ```
124
135
 
125
136
  #### Tallying Votes
126
137
 
127
138
  You can easily retrieve voteable object collections based on the properties of their votes:
128
-
129
- @items = Item.tally.limit(10).where('created_at > ?', 2.days.ago).having('COUNT(votes.id) < 10')
139
+ ```ruby
140
+ @items = Item.tally.limit(10).where('created_at > ?', 2.days.ago).having('COUNT(votes.id) < 10')
141
+ ```
130
142
 
131
143
  Or for MySQL:
132
-
133
- @items = Item.tally.limit(10).where('created_at > ?', 2.days.ago).having('vote_count < 10')
144
+ ```ruby
145
+ @items = Item.tally.limit(10).where('created_at > ?', 2.days.ago).having('vote_count < 10')
146
+ ```
134
147
 
135
148
  This will select the Items with less than 10 votes, the votes having been cast within the last two days, with a limit of 10 items. *This tallies all votes, regardless of whether they are +1 (up) or -1 (down).* The #tally method returns an ActiveRecord Relation, so you can chain the normal method calls on to it.
136
149
 
@@ -139,21 +152,23 @@ This will select the Items with less than 10 votes, the votes having been cast w
139
152
  **You most likely want to use this over the normal tally**
140
153
 
141
154
  This is similar to tallying votes, but this will return voteable object collections based on the sum of the differences between up and down votes (ups are +1, downs are -1). For Instance, a voteable with 3 upvotes and 2 downvotes will have a plusminus_tally of 1.
142
-
143
- @items = Item.plusminus_tally.limit(10).where('created_at > ?', 2.days.ago).having('plusminus_tally > 10')
155
+ ```ruby
156
+ @items = Item.plusminus_tally.limit(10).where('created_at > ?', 2.days.ago).having('plusminus_tally > 10')
157
+ ```
144
158
 
145
159
  #### Lower level queries
160
+ ```ruby
161
+ positiveVoteCount = voteable.votes_for
162
+ negativeVoteCount = voteable.votes_against
163
+ # Votes for minus votes against. If you want more than a few model instances' worth, use `plusminus_tally` instead.
164
+ plusminus = voteable.plusminus
146
165
 
147
- positiveVoteCount = voteable.votes_for
148
- negativeVoteCount = voteable.votes_against
149
- # Votes for minus votes against. If you want more than a few model instances' worth, use `plusminus_tally` instead.
150
- plusminus = voteable.plusminus
151
-
152
- voter.voted_for?(voteable) # True if the voter voted for this object.
153
- voter.vote_count(:up | :down | :all) # returns the count of +1, -1, or all votes
166
+ voter.voted_for?(voteable) # True if the voter voted for this object.
167
+ voter.vote_count(:up | :down | :all) # returns the count of +1, -1, or all votes
154
168
 
155
- voteable.voted_by?(voter) # True if the voter voted for this object.
156
- @voters = voteable.voters_who_voted
169
+ voteable.voted_by?(voter) # True if the voter voted for this object.
170
+ @voters = voteable.voters_who_voted
171
+ ```
157
172
 
158
173
 
159
174
  ### One vote per user!
@@ -161,16 +176,18 @@ This is similar to tallying votes, but this will return voteable object collecti
161
176
  ThumbsUp by default only allows one vote per user. This can be changed by removing:
162
177
 
163
178
  #### In vote.rb:
164
-
165
- validates_uniqueness_of :voteable_id, :scope => [:voteable_type, :voter_type, :voter_id]
179
+ ```ruby
180
+ validates_uniqueness_of :voteable_id, :scope => [:voteable_type, :voter_type, :voter_id]
181
+ ```
166
182
 
167
183
  #### In the migration, the unique index:
168
-
169
- add_index :votes, ["voter_id", "voter_type", "voteable_id", "voteable_type"], :unique => true, :name => "uniq_one_vote_only"
170
-
184
+ ```ruby
185
+ add_index :votes, ["voter_id", "voter_type", "voteable_id", "voteable_type"], :unique => true, :name => "uniq_one_vote_only"
186
+ ```
171
187
  You can also use `--unique-voting false` when running the generator command:
172
-
173
- rails generate thumbs_up --unique-voting false
188
+ ```shell
189
+ rails generate thumbs_up --unique-voting false
190
+ ```
174
191
 
175
192
  #### Testing ThumbsUp
176
193
 
@@ -178,30 +195,30 @@ Testing is a bit more than trivial now as our #tally and #plusminus_tally querie
178
195
 
179
196
  * mysql
180
197
 
181
- ```
182
- $ mysql -uroot # You may have set a password locally. Change as needed.
183
- > CREATE USER 'test'@'localhost' IDENTIFIED BY 'test';
184
- > CREATE DATABASE thumbs_up_test;
185
- > USE thumbs_up_test;
186
- > GRANT ALL PRIVILEGES ON thumbs_up_test TO 'test'@'localhost' IDENTIFIED BY 'test';
187
- > exit;
188
- ```
198
+ ```sql
199
+ $ mysql -uroot # You may have set a password locally. Change as needed.
200
+ > CREATE USER 'test'@'localhost' IDENTIFIED BY 'test';
201
+ > CREATE DATABASE thumbs_up_test;
202
+ > USE thumbs_up_test;
203
+ > GRANT ALL PRIVILEGES ON thumbs_up_test TO 'test'@'localhost' IDENTIFIED BY 'test';
204
+ > exit;
205
+ ```
189
206
  * Postgres
190
207
 
191
- ```
192
- $ psql # You may have set a password locally. Change as needed.
193
- > CREATE ROLE test;
194
- > ALTER ROLE test WITH SUPERUSER;
195
- > ALTER ROLE test WITH LOGIN;
196
- > CREATE DATABASE thumbs_up_test;
197
- > GRANT ALL PRIVILEGES ON DATABASE thumbs_up_test to test;
198
- > \q
199
- ```
208
+ ```PLpgSQL
209
+ $ psql # You may have set a password locally. Change as needed.
210
+ > CREATE ROLE test;
211
+ > ALTER ROLE test WITH SUPERUSER;
212
+ > ALTER ROLE test WITH LOGIN;
213
+ > CREATE DATABASE thumbs_up_test;
214
+ > GRANT ALL PRIVILEGES ON DATABASE thumbs_up_test to test;
215
+ > \q
216
+ ```
200
217
  * Run tests
201
218
 
202
- ```
203
- $ rake # Runs the test suite against all adapters.
204
- ```
219
+ ```shell
220
+ $ rake # Runs the test suite against all adapters.
221
+ ```
205
222
 
206
223
  Credits
207
224
  =======
data/Rakefile CHANGED
@@ -33,10 +33,13 @@ end
33
33
  task :test_all_databases do
34
34
  # Test MySQL, Postgres and SQLite3
35
35
  ENV['DB'] = 'mysql'
36
+ puts "Testing MySQL..."
36
37
  Rake::Task['test'].execute
37
38
  ENV['DB'] = 'postgres'
39
+ puts "Testing Postgres..."
38
40
  Rake::Task['test'].execute
39
41
  ENV['DB'] = 'sqlite3'
42
+ puts "Testing SQLite3..."
40
43
  Rake::Task['test'].execute
41
44
  end
42
45
 
@@ -5,7 +5,7 @@ class ThumbsUpGenerator < Rails::Generators::Base
5
5
  include Rails::Generators::Migration
6
6
 
7
7
  source_root File.expand_path('../templates', __FILE__)
8
-
8
+
9
9
  class_option :unique_voting, :type => :boolean, :default => true, :desc => 'Do you want only one vote allowed per voter? (default: true)'
10
10
 
11
11
  # Implement the required interface for Rails::Generators::Migration.
@@ -18,7 +18,7 @@ class ThumbsUpGenerator < Rails::Generators::Base
18
18
  end
19
19
  end
20
20
 
21
- def create_migration
21
+ def create_thumbs_up_migration
22
22
  migration_template 'migration.rb', File.join('db', 'migrate', 'thumbs_up_migration.rb')
23
23
  end
24
24
 
@@ -26,4 +26,4 @@ class ThumbsUpGenerator < Rails::Generators::Base
26
26
  template 'vote.rb', File.join('app', 'models', 'vote.rb')
27
27
  end
28
28
 
29
- end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module ThumbsUp
2
- VERSION = '0.6.7'
2
+ VERSION = '0.6.8'
3
3
  end
@@ -1,6 +1,6 @@
1
1
  require 'simplecov'
2
+ require 'minitest/autorun'
2
3
  SimpleCov.start
3
- require 'test/unit'
4
4
 
5
5
  $LOAD_PATH.unshift(File.dirname(__FILE__))
6
6
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
@@ -64,7 +64,7 @@ ActiveRecord::Schema.define do
64
64
  t.boolean :vote, :default => false
65
65
  t.references :voteable, :polymorphic => true, :null => false
66
66
  t.references :voter, :polymorphic => true
67
- t.timestamps
67
+ t.timestamps :null => false
68
68
  end
69
69
 
70
70
  add_index :votes, [:voter_id, :voter_type]
@@ -75,7 +75,7 @@ ActiveRecord::Schema.define do
75
75
 
76
76
  create_table :users, :force => true do |t|
77
77
  t.string :name
78
- t.timestamps
78
+ t.timestamps :null => false
79
79
  end
80
80
 
81
81
  create_table :items, :force => true do |t|
@@ -92,7 +92,7 @@ ActiveRecord::Schema.define do
92
92
 
93
93
  create_table :user_customs, :force => true do |t|
94
94
  t.string :name
95
- t.timestamps
95
+ t.timestamps :null => false
96
96
  end
97
97
 
98
98
  create_table :item_customs, :force => true do |t|
@@ -149,7 +149,12 @@ class User < ActiveRecord::Base
149
149
  ThumbsUp.configuration.voter_relationship_name = :votes
150
150
  acts_as_voter
151
151
  has_many :items
152
- has_karma(:items)
152
+ has_karma :items
153
+
154
+ def self.default_karma
155
+ self.karmic_objects = nil
156
+ has_karma :items, :weight => 1
157
+ end
153
158
 
154
159
  def self.weighted_has_karma
155
160
  self.karmic_objects = nil
@@ -183,6 +188,3 @@ class UserCustom < ActiveRecord::Base
183
188
  has_many :items
184
189
  has_karma :items
185
190
  end
186
-
187
- class Test::Unit::TestCase
188
- end
@@ -1,6 +1,6 @@
1
1
  require File.join(File.expand_path(File.dirname(__FILE__)), 'test_helper')
2
2
 
3
- class TestThumbsUp < Test::Unit::TestCase
3
+ class TestThumbsUp < Minitest::Test
4
4
  def setup
5
5
  Vote.delete_all
6
6
  User.delete_all
@@ -17,7 +17,7 @@ class TestThumbsUp < Test::Unit::TestCase
17
17
  item = Item.create(:name => 'XBOX', :description => 'XBOX console')
18
18
  item2= Item.create(:name => 'PS3', :description => 'Playstation 3')
19
19
 
20
- assert_not_nil user_for.vote_for(item)
20
+ refute_nil user_for.vote_for(item)
21
21
  assert_raises(ActiveRecord::RecordInvalid) do
22
22
  user_for.vote_for(item)
23
23
  end
@@ -36,7 +36,7 @@ class TestThumbsUp < Test::Unit::TestCase
36
36
  user_for.voted_which_way?(item, :foo)
37
37
  end
38
38
 
39
- assert_not_nil user_against.vote_against(item)
39
+ refute_nil user_against.vote_against(item)
40
40
  assert_raises(ActiveRecord::RecordInvalid) do
41
41
  user_against.vote_against(item)
42
42
  end
@@ -53,10 +53,10 @@ class TestThumbsUp < Test::Unit::TestCase
53
53
  user_against.voted_which_way?(item, :foo)
54
54
  end
55
55
 
56
- assert_not_nil user_against.vote_exclusively_for(item)
56
+ refute_nil user_against.vote_exclusively_for(item)
57
57
  assert_equal true, user_against.voted_for?(item)
58
58
 
59
- assert_not_nil user_for.vote_exclusively_against(item)
59
+ refute_nil user_for.vote_exclusively_against(item)
60
60
  assert_equal true, user_for.voted_against?(item)
61
61
 
62
62
  user_for.unvote_for(item)
@@ -159,7 +159,7 @@ class TestThumbsUp < Test::Unit::TestCase
159
159
  user_for.votes
160
160
  end
161
161
 
162
- assert_not_nil user_for.vote_for(item)
162
+ refute_nil user_for.vote_for(item)
163
163
  assert_raises(ActiveRecord::RecordInvalid) do
164
164
  user_for.vote_for(item)
165
165
  end
@@ -177,7 +177,7 @@ class TestThumbsUp < Test::Unit::TestCase
177
177
  user_for.voted_which_way?(item, :foo)
178
178
  end
179
179
 
180
- assert_not_nil user_against.vote_against(item)
180
+ refute_nil user_against.vote_against(item)
181
181
  assert_raises(ActiveRecord::RecordInvalid) do
182
182
  user_against.vote_against(item)
183
183
  end
@@ -193,10 +193,10 @@ class TestThumbsUp < Test::Unit::TestCase
193
193
  user_against.voted_which_way?(item, :foo)
194
194
  end
195
195
 
196
- assert_not_nil user_against.vote_exclusively_for(item)
196
+ refute_nil user_against.vote_exclusively_for(item)
197
197
  assert_equal true, user_against.voted_for?(item)
198
198
 
199
- assert_not_nil user_for.vote_exclusively_against(item)
199
+ refute_nil user_for.vote_exclusively_against(item)
200
200
  assert_equal true, user_for.voted_against?(item)
201
201
 
202
202
  user_for.unvote_for(item)
@@ -293,7 +293,7 @@ class TestThumbsUp < Test::Unit::TestCase
293
293
 
294
294
  user.vote_for(item2)
295
295
 
296
- assert_not_nil Item.tally.first.id
296
+ refute_nil Item.tally.first.id
297
297
  end
298
298
 
299
299
  def test_tally_starts_at
@@ -338,7 +338,7 @@ class TestThumbsUp < Test::Unit::TestCase
338
338
  end
339
339
 
340
340
  def test_tally_count
341
- Item.tally.except(:order).count
341
+ Item.tally.except(:order).to_a.count
342
342
  end
343
343
 
344
344
  def test_tally_any
@@ -403,7 +403,7 @@ class TestThumbsUp < Test::Unit::TestCase
403
403
  item = Item.create(:name => 'XBOX', :description => 'XBOX console')
404
404
  item_not_included = Item.create(:name => 'Playstation', :description => 'Playstation console')
405
405
 
406
- assert_not_nil user.vote_for(item)
406
+ refute_nil user.vote_for(item)
407
407
 
408
408
  if ActiveRecord::Base.connection.adapter_name == 'MySQL'
409
409
  assert(Item.plusminus_tally.having('vote_count > 0').include?(item))
@@ -420,8 +420,8 @@ class TestThumbsUp < Test::Unit::TestCase
420
420
  item2 = Item.create(:name => 'Playstation', :description => 'Playstation console')
421
421
  item3 = Item.create(:name => 'Wii', :description => 'Wii console')
422
422
 
423
- assert_not_nil user.vote_for(item1)
424
- assert_not_nil user.vote_against(item2)
423
+ refute_nil user.vote_for(item1)
424
+ refute_nil user.vote_against(item2)
425
425
 
426
426
  assert_equal [1, 0, 0], Item.plusminus_tally(:separate_updown => true).map(&:up).map(&:to_i)
427
427
  end
@@ -432,8 +432,8 @@ class TestThumbsUp < Test::Unit::TestCase
432
432
  item2 = Item.create(:name => 'Playstation', :description => 'Playstation console')
433
433
  item3 = Item.create(:name => 'Wii', :description => 'Wii console')
434
434
 
435
- assert_not_nil user.vote_for(item1)
436
- assert_not_nil user.vote_against(item2)
435
+ refute_nil user.vote_for(item1)
436
+ refute_nil user.vote_against(item2)
437
437
 
438
438
  assert_equal [0, 0, 1], Item.plusminus_tally(:separate_updown => true).map(&:down).map(&:to_i)
439
439
  end
@@ -444,8 +444,8 @@ class TestThumbsUp < Test::Unit::TestCase
444
444
  item2 = Item.create(:name => 'Playstation', :description => 'Playstation console')
445
445
  item3 = Item.create(:name => 'Wii', :description => 'Wii console')
446
446
 
447
- assert_not_nil user.vote_for(item1)
448
- assert_not_nil user.vote_against(item2)
447
+ refute_nil user.vote_for(item1)
448
+ refute_nil user.vote_against(item2)
449
449
 
450
450
  assert_equal [1, 0, -1], Item.plusminus_tally.map(&:plusminus_tally).map(&:to_i)
451
451
  end
@@ -454,7 +454,7 @@ class TestThumbsUp < Test::Unit::TestCase
454
454
  user1 = User.create(:name => 'david')
455
455
  item = Item.create(:name => 'Playstation', :description => 'Playstation console')
456
456
 
457
- assert_not_nil user1.vote_for(item)
457
+ refute_nil user1.vote_for(item)
458
458
 
459
459
  # https://github.com/rails/rails/issues/1718
460
460
  assert_equal 1, Item.plusminus_tally[0].vote_count.to_i
@@ -466,8 +466,8 @@ class TestThumbsUp < Test::Unit::TestCase
466
466
  user2 = User.create(:name => 'john')
467
467
  item = Item.create(:name => 'Playstation', :description => 'Playstation console')
468
468
 
469
- assert_not_nil user1.vote_against(item)
470
- assert_not_nil user2.vote_against(item)
469
+ refute_nil user1.vote_against(item)
470
+ refute_nil user2.vote_against(item)
471
471
 
472
472
  # https://github.com/rails/rails/issues/1718
473
473
  assert_equal 2, Item.plusminus_tally[0].vote_count.to_i
@@ -481,10 +481,10 @@ class TestThumbsUp < Test::Unit::TestCase
481
481
  item_for = Item.create(:name => 'XBOX', :description => 'XBOX console')
482
482
  item_against = Item.create(:name => 'Playstation', :description => 'Playstation console')
483
483
 
484
- assert_not_nil user1.vote_for(item_for)
485
- assert_not_nil user1.vote_for(item_twice_for)
486
- assert_not_nil user2.vote_for(item_twice_for)
487
- assert_not_nil user1.vote_against(item_against)
484
+ refute_nil user1.vote_for(item_for)
485
+ refute_nil user1.vote_for(item_twice_for)
486
+ refute_nil user2.vote_for(item_twice_for)
487
+ refute_nil user1.vote_against(item_against)
488
488
 
489
489
  assert_equal item_twice_for, Item.plusminus_tally[0]
490
490
  assert_equal item_for, Item.plusminus_tally[1]
@@ -504,8 +504,8 @@ class TestThumbsUp < Test::Unit::TestCase
504
504
  item_for = Item.create(:name => 'XBOX', :description => 'XBOX console')
505
505
  item_against = Item.create(:name => 'Playstation', :description => 'Playstation console')
506
506
 
507
- assert_not_nil user.vote_for(item_for)
508
- assert_not_nil user.vote_against(item_against)
507
+ refute_nil user.vote_for(item_for)
508
+ refute_nil user.vote_against(item_against)
509
509
 
510
510
  assert_equal item_for, Item.plusminus_tally.reorder('plusminus_tally ASC')[1]
511
511
  assert_equal item_against, Item.plusminus_tally.reorder('plusminus_tally ASC')[0]
@@ -524,7 +524,7 @@ class TestThumbsUp < Test::Unit::TestCase
524
524
  end
525
525
 
526
526
  def test_plusminus_tally_count
527
- Item.plusminus_tally.except(:order).count
527
+ Item.plusminus_tally.except(:order).to_a.count
528
528
  end
529
529
 
530
530
  def test_plusminus_tally_any
@@ -532,6 +532,7 @@ class TestThumbsUp < Test::Unit::TestCase
532
532
  end
533
533
 
534
534
  def test_karma
535
+ User.default_karma
535
536
  users = (0..1).map{ |u| User.create(:name => "User #{u}") }
536
537
  items = (0..1).map{ |u| users[0].items.create(:name => "Item #{u}", :description => "Item #{u}") }
537
538
  users.each{ |u| items.each { |i| u.vote_for(i) } }
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.7
4
+ version: 0.6.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brady Bouchard
@@ -13,118 +13,132 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2013-09-02 00:00:00.000000000 Z
16
+ date: 2015-10-04 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: activerecord
20
20
  requirement: !ruby/object:Gem::Requirement
21
21
  requirements:
22
- - - '>='
22
+ - - "~>"
23
23
  - !ruby/object:Gem::Version
24
- version: '0'
24
+ version: 4.2.x
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
28
28
  requirements:
29
- - - '>='
29
+ - - "~>"
30
30
  - !ruby/object:Gem::Version
31
- version: '0'
31
+ version: 4.2.x
32
32
  - !ruby/object:Gem::Dependency
33
33
  name: statistics2
34
34
  requirement: !ruby/object:Gem::Requirement
35
35
  requirements:
36
- - - '>='
36
+ - - ">="
37
37
  - !ruby/object:Gem::Version
38
38
  version: '0'
39
39
  type: :runtime
40
40
  prerelease: false
41
41
  version_requirements: !ruby/object:Gem::Requirement
42
42
  requirements:
43
- - - '>='
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: minitest
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ type: :development
54
+ prerelease: false
55
+ version_requirements: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
44
58
  - !ruby/object:Gem::Version
45
59
  version: '0'
46
60
  - !ruby/object:Gem::Dependency
47
61
  name: simplecov
48
62
  requirement: !ruby/object:Gem::Requirement
49
63
  requirements:
50
- - - '>='
64
+ - - ">="
51
65
  - !ruby/object:Gem::Version
52
66
  version: '0'
53
67
  type: :development
54
68
  prerelease: false
55
69
  version_requirements: !ruby/object:Gem::Requirement
56
70
  requirements:
57
- - - '>='
71
+ - - ">="
58
72
  - !ruby/object:Gem::Version
59
73
  version: '0'
60
74
  - !ruby/object:Gem::Dependency
61
75
  name: bundler
62
76
  requirement: !ruby/object:Gem::Requirement
63
77
  requirements:
64
- - - '>='
78
+ - - ">="
65
79
  - !ruby/object:Gem::Version
66
80
  version: '0'
67
81
  type: :development
68
82
  prerelease: false
69
83
  version_requirements: !ruby/object:Gem::Requirement
70
84
  requirements:
71
- - - '>='
85
+ - - ">="
72
86
  - !ruby/object:Gem::Version
73
87
  version: '0'
74
88
  - !ruby/object:Gem::Dependency
75
89
  name: mysql2
76
90
  requirement: !ruby/object:Gem::Requirement
77
91
  requirements:
78
- - - '>='
92
+ - - "~>"
79
93
  - !ruby/object:Gem::Version
80
- version: '0'
94
+ version: 0.3.20
81
95
  type: :development
82
96
  prerelease: false
83
97
  version_requirements: !ruby/object:Gem::Requirement
84
98
  requirements:
85
- - - '>='
99
+ - - "~>"
86
100
  - !ruby/object:Gem::Version
87
- version: '0'
101
+ version: 0.3.20
88
102
  - !ruby/object:Gem::Dependency
89
103
  name: pg
90
104
  requirement: !ruby/object:Gem::Requirement
91
105
  requirements:
92
- - - '>='
106
+ - - ">="
93
107
  - !ruby/object:Gem::Version
94
108
  version: '0'
95
109
  type: :development
96
110
  prerelease: false
97
111
  version_requirements: !ruby/object:Gem::Requirement
98
112
  requirements:
99
- - - '>='
113
+ - - ">="
100
114
  - !ruby/object:Gem::Version
101
115
  version: '0'
102
116
  - !ruby/object:Gem::Dependency
103
117
  name: sqlite3
104
118
  requirement: !ruby/object:Gem::Requirement
105
119
  requirements:
106
- - - '>='
120
+ - - ">="
107
121
  - !ruby/object:Gem::Version
108
122
  version: '0'
109
123
  type: :development
110
124
  prerelease: false
111
125
  version_requirements: !ruby/object:Gem::Requirement
112
126
  requirements:
113
- - - '>='
127
+ - - ">="
114
128
  - !ruby/object:Gem::Version
115
129
  version: '0'
116
130
  - !ruby/object:Gem::Dependency
117
131
  name: rake
118
132
  requirement: !ruby/object:Gem::Requirement
119
133
  requirements:
120
- - - '>='
134
+ - - ">="
121
135
  - !ruby/object:Gem::Version
122
136
  version: '0'
123
137
  type: :development
124
138
  prerelease: false
125
139
  version_requirements: !ruby/object:Gem::Requirement
126
140
  requirements:
127
- - - '>='
141
+ - - ">="
128
142
  - !ruby/object:Gem::Version
129
143
  version: '0'
130
144
  description: ThumbsUp provides dead-simple voting capabilities to ActiveRecord models
@@ -135,24 +149,24 @@ executables: []
135
149
  extensions: []
136
150
  extra_rdoc_files: []
137
151
  files:
152
+ - CHANGELOG.md
153
+ - Gemfile
154
+ - LICENSE
155
+ - README.md
156
+ - Rakefile
138
157
  - lib/acts_as_voteable.rb
139
158
  - lib/acts_as_voter.rb
140
159
  - lib/generators/thumbs_up/templates/migration.rb
141
160
  - lib/generators/thumbs_up/templates/vote.rb
142
161
  - lib/generators/thumbs_up/thumbs_up_generator.rb
143
162
  - lib/has_karma.rb
163
+ - lib/thumbs_up.rb
144
164
  - lib/thumbs_up/base.rb
145
165
  - lib/thumbs_up/configuration.rb
146
166
  - lib/thumbs_up/version.rb
147
- - lib/thumbs_up.rb
148
167
  - rails/init.rb
149
168
  - test/test_helper.rb
150
169
  - test/thumbs_up_test.rb
151
- - CHANGELOG.md
152
- - Gemfile
153
- - MIT-LICENSE
154
- - README.md
155
- - Rakefile
156
170
  homepage: http://github.com/bouchard/thumbs_up
157
171
  licenses:
158
172
  - MIT
@@ -163,17 +177,17 @@ require_paths:
163
177
  - lib
164
178
  required_ruby_version: !ruby/object:Gem::Requirement
165
179
  requirements:
166
- - - '>='
180
+ - - ">="
167
181
  - !ruby/object:Gem::Version
168
182
  version: '0'
169
183
  required_rubygems_version: !ruby/object:Gem::Requirement
170
184
  requirements:
171
- - - '>='
185
+ - - ">="
172
186
  - !ruby/object:Gem::Version
173
187
  version: '0'
174
188
  requirements: []
175
189
  rubyforge_project:
176
- rubygems_version: 2.0.2
190
+ rubygems_version: 2.4.5
177
191
  signing_key:
178
192
  specification_version: 4
179
193
  summary: Voting for ActiveRecord with multiple vote sources and karma calculation.
@@ -1,66 +0,0 @@
1
- Copyright (c) 2011 Brady Bouchard (thewellinspired.com)
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
-
22
- Major portions of this package were adapted from VoteFu, which is subject to the same license. Here is the original copyright notice for VoteFu:
23
-
24
- Copyright (c) 2008 Peter Jackson (peteonrails.com)
25
-
26
- Permission is hereby granted, free of charge, to any person obtaining
27
- a copy of this software and associated documentation files (the
28
- "Software"), to deal in the Software without restriction, including
29
- without limitation the rights to use, copy, modify, merge, publish,
30
- distribute, sublicense, and/or sell copies of the Software, and to
31
- permit persons to whom the Software is furnished to do so, subject to
32
- the following conditions:
33
-
34
- The above copyright notice and this permission notice shall be
35
- included in all copies or substantial portions of the Software.
36
-
37
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
38
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
39
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
40
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
41
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
42
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
43
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
44
-
45
- Major portions of this package were adapted from ActsAsVoteable, which is subject to the same license. Here is the original copyright notice for ActsAsVoteable:
46
-
47
- Copyright (c) 2006 Cosmin Radoi
48
-
49
- Permission is hereby granted, free of charge, to any person obtaining
50
- a copy of this software and associated documentation files (the
51
- "Software"), to deal in the Software without restriction, including
52
- without limitation the rights to use, copy, modify, merge, publish,
53
- distribute, sublicense, and/or sell copies of the Software, and to
54
- permit persons to whom the Software is furnished to do so, subject to
55
- the following conditions:
56
-
57
- The above copyright notice and this permission notice shall be
58
- included in all copies or substantial portions of the Software.
59
-
60
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
61
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
62
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
63
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
64
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
65
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
66
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.