acts_as_votable 0.6.0 → 0.7.0

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: 1e79bb042c22d96216fdabab6c6b449bbec1efd7
4
- data.tar.gz: 6b5ba884d93efc2a8abc8009b48c008c8d3f3356
3
+ metadata.gz: 761f4de1f6cb69440c40761f9a73bf33ebd0d626
4
+ data.tar.gz: 531c9e70b810c33a8855021f05e1cbf6a2fe6053
5
5
  SHA512:
6
- metadata.gz: 880aac591a52bb25a20359c0b94ac95f9fd5ed207933a1cbf176ae6941fc75621da8d2862f2f092aedde47bef43efbeb8385387a633ef9a76d576e9ec2fba25f
7
- data.tar.gz: 53a7ed9b541dda5b70d96e8237b4d4100b3b4b0d0af3993bca622c7883f6a63d2d2c11780aedcc44f4c8454ac6907329a91e87bf5725ff4de865c03605c94d33
6
+ metadata.gz: bf5fc76011445515ae9ad68617af57c24ba660e1c8341fb360ee2874b4966ca644c3c9d337d0726b6fb29c59a8a6bb1f68b591975417245f10a2e683df05ff91
7
+ data.tar.gz: 2113bdcec62e87a3fb88bc97bd3b7b3bd1cf67d098b0502b26c41590cdf8ea1f2e1780cd5c63d14c75084422d2039f947cc09761ff4e405e423d035f57054c79
data/README.markdown CHANGED
@@ -1,6 +1,6 @@
1
1
  # Acts As Votable (aka Acts As Likeable)
2
2
 
3
- ![Build Status](https://travis-ci.org/ryanto/acts_as_votable.png?branch=master)
3
+ [![Build Status](https://travis-ci.org/ryanto/acts_as_votable.png)](https://travis-ci.org/ryanto/acts_as_votable)
4
4
 
5
5
  Acts As Votable is a Ruby Gem specifically written for Rails/ActiveRecord models.
6
6
  The main goals of this gem are:
@@ -13,12 +13,12 @@ The main goals of this gem are:
13
13
 
14
14
  ## Installation
15
15
 
16
- ### Rails 3 or 4
16
+ ### Rails 3.0, 3.1, 3.2, and 4.0+
17
17
 
18
18
  Just add the following to your Gemfile.
19
19
 
20
20
  ```ruby
21
- gem 'acts_as_votable', '~> 0.6.0'
21
+ gem 'acts_as_votable', '~> 0.7.0'
22
22
  ```
23
23
 
24
24
  And follow that up with a ``bundle install``.
@@ -297,7 +297,17 @@ end
297
297
 
298
298
  ## Testing
299
299
 
300
- All tests follow the RSpec format and are located in the spec directory
300
+ All tests follow the RSpec format and are located in the spec directory.
301
+ They can be run with:
302
+
303
+ ```
304
+ rake spec
305
+ ```
306
+
307
+ ## License
308
+
309
+ Acts as votable is released under the [MIT
310
+ License](http://www.opensource.org/licenses/MIT).
301
311
 
302
312
  ## TODO
303
313
 
@@ -19,10 +19,6 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
-
23
-
24
22
  s.add_development_dependency "rspec"
25
23
  s.add_development_dependency "sqlite3", '1.3.7'
26
-
27
- s.add_dependency "rails", '>=3.2.11'
28
24
  end
@@ -1,3 +1,3 @@
1
1
  module ActsAsVotable
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -27,8 +27,8 @@ module ActsAsVotable
27
27
  :down_votes => [
28
28
  :false_votes, :downs, :downvotes, :dislikes, :negatives
29
29
  ],
30
- :unvote => [
31
- :unliked_by, :undisliked_by
30
+ :unvote_for => [
31
+ :unvote_up, :unvote_down, :unliked_by, :undisliked_by
32
32
  ]
33
33
  }
34
34
 
@@ -130,6 +130,10 @@ module ActsAsVotable
130
130
  self.vote :voter => voter, :vote => false, :vote_scope => options[:vote_scope]
131
131
  end
132
132
 
133
+ def unvote_for voter, options = {}
134
+ self.unvote :voter => voter, :vote_scope => options[:vote_scope]
135
+ end
136
+
133
137
  # caching
134
138
  def update_cached_votes
135
139
 
@@ -5,11 +5,15 @@ module ActsAsVotable
5
5
 
6
6
  # allow user to define these
7
7
  aliases = {
8
- :vote_up_for => [:likes, :upvotes, :up_votes],
9
- :vote_down_for => [:dislikes, :downvotes, :down_votes],
10
- :unvote_for => [:unlike, :undislike],
8
+ :vote_up_for => [:likes, :upvotes, :up_votes],
9
+ :vote_down_for => [:dislikes, :downvotes, :down_votes],
10
+ :unvote_for => [:unlike, :undislike],
11
+ :voted_on? => [:voted_for?],
11
12
  :voted_up_on? => [:voted_up_for?, :liked?],
12
- :voted_down_on? => [:voted_down_for?, :disliked?]
13
+ :voted_down_on? => [:voted_down_for?, :disliked?],
14
+ :voted_as_when_voting_on => [:voted_as_when_voted_on, :voted_as_when_voting_for, :voted_as_when_voted_for],
15
+ :find_up_voted_items => [:find_liked_items],
16
+ :find_down_voted_items => [:find_disliked_items]
13
17
  }
14
18
 
15
19
  base.class_eval do
@@ -66,7 +70,6 @@ module ActsAsVotable
66
70
  :vote_scope => args[:vote_scope], :vote_flag => false)
67
71
  votes.size > 0
68
72
  end
69
- alias :voted_down_for? :voted_down_on?
70
73
 
71
74
  def voted_as_when_voting_on votable, args={}
72
75
  votes = find_votes(:votable_id => votable.id, :votable_type => votable.class.name,
@@ -74,7 +77,6 @@ module ActsAsVotable
74
77
  return nil if votes.size == 0
75
78
  return votes.first.vote_flag
76
79
  end
77
- alias :voted_as_when_voted_for :voted_as_when_voting_on
78
80
 
79
81
  def find_votes extra_conditions = {}
80
82
  votes.where(extra_conditions)
@@ -113,12 +115,10 @@ module ActsAsVotable
113
115
  def find_up_voted_items extra_conditions = {}
114
116
  find_voted_items extra_conditions.merge(:vote_flag => true)
115
117
  end
116
- alias_method :find_liked_items, :find_up_voted_items
117
118
 
118
119
  def find_down_voted_items extra_conditions = {}
119
120
  find_voted_items extra_conditions.merge(:vote_flag => false)
120
121
  end
121
- alias_method :find_disliked_items, :find_down_voted_items
122
122
 
123
123
  def get_voted klass, extra_conditions = {}
124
124
  klass.joins(:votes).merge find_votes(extra_conditions)
data/spec/votable_spec.rb CHANGED
@@ -116,6 +116,12 @@ describe ActsAsVotable::Votable do
116
116
  @votable.voted_on_by?(@voter).should be true
117
117
  end
118
118
 
119
+ it "should be able to unvote a voter" do
120
+ @votable.liked_by(@voter)
121
+ @votable.unliked_by(@voter)
122
+ @votable.voted_on_by?(@voter).should be false
123
+ end
124
+
119
125
  it "should unvote a positive vote" do
120
126
  @votable.vote :voter => @voter
121
127
  @votable.unvote :voter => @voter
data/spec/voter_spec.rb CHANGED
@@ -35,6 +35,7 @@ describe ActsAsVotable::Voter do
35
35
  it "should be voted on after a voter has voted" do
36
36
  @votable.vote :voter => @voter
37
37
  @voter.voted_on?(@votable).should be true
38
+ @voter.voted_for?(@votable).should be true
38
39
  end
39
40
 
40
41
  it "should not be voted on if a voter has not voted" do
@@ -53,6 +54,7 @@ describe ActsAsVotable::Voter do
53
54
 
54
55
  it "should be voted as true when a voter has voted true" do
55
56
  @votable.vote :voter => @voter
57
+ @voter.voted_as_when_voted_on(@votable).should be true
56
58
  @voter.voted_as_when_voted_for(@votable).should be true
57
59
  end
58
60
 
@@ -206,6 +208,8 @@ describe ActsAsVotable::Voter do
206
208
  @votable2.vote :voter => @voter2
207
209
  @voter.find_up_voted_items.should include @votable
208
210
  @voter.find_up_voted_items.size.should == 1
211
+ @voter.find_liked_items.should include @votable
212
+ @voter.find_liked_items.size.should == 1
209
213
  end
210
214
 
211
215
  it 'returns objects that a user has upvoted for, using scope' do
@@ -242,6 +246,8 @@ describe ActsAsVotable::Voter do
242
246
  @votable2.vote_down @voter2
243
247
  @voter.find_down_voted_items.should include @votable
244
248
  @voter.find_down_voted_items.size.should == 1
249
+ @voter.find_disliked_items.should include @votable
250
+ @voter.find_disliked_items.size.should == 1
245
251
  end
246
252
 
247
253
  it 'returns objects that a user has downvoted for, using scope' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_votable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-08 00:00:00.000000000 Z
11
+ date: 2013-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.3.7
41
- - !ruby/object:Gem::Dependency
42
- name: rails
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '>='
46
- - !ruby/object:Gem::Version
47
- version: 3.2.11
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '>='
53
- - !ruby/object:Gem::Version
54
- version: 3.2.11
55
41
  description: Rails gem to allowing records to be votable
56
42
  email:
57
43
  - ryanto