acts_as_votable 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- acts_as_votable (0.2.0)
4
+ acts_as_votable (0.3.0)
5
5
  rails (>= 3.0.0)
6
6
 
7
7
  GEM
data/README.markdown CHANGED
@@ -141,6 +141,21 @@ check how the voter voted by using ``voted_as_when_voted_for``.
141
141
  @user.voted_as_when_voted_for @comment2 # => false, he didnt like it
142
142
  @user.voted_as_when_voted_for @comment3 # => nil, he has yet to vote
143
143
 
144
+ You can also check whether the voter has voted up or down.
145
+
146
+ @user.likes @comment1
147
+ @user.dislikes @comment2
148
+ # user has not voted on @comment3
149
+
150
+ @user.voted_up_on? @comment1 # => true
151
+ @user.voted_down_on? @comment1 # => false
152
+
153
+ @user.voted_down_on? @comment2 # => true
154
+ @user.voted_up_on? @comment2 # => false
155
+
156
+ @user.voted_up_on? @comment3 # => false
157
+ @user.voted_down_on? @comment3 # => false
158
+
144
159
  ### Registered Votes
145
160
 
146
161
  Voters can only vote once per model. In this example the 2nd vote does not count
@@ -1,3 +1,3 @@
1
1
  module ActsAsVotable
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -53,6 +53,18 @@ module ActsAsVotable
53
53
  end
54
54
  alias :voted_for? :voted_on?
55
55
 
56
+ def voted_up_on? votable
57
+ votes = find_votes(:votable_id => votable.id, :votable_type => votable.class.name, :vote_flag => true)
58
+ votes.size > 0
59
+ end
60
+ alias :voted_up_for? :voted_up_on?
61
+
62
+ def voted_down_on? votable
63
+ votes = find_votes(:votable_id => votable.id, :votable_type => votable.class.name, :vote_flag => false)
64
+ votes.size > 0
65
+ end
66
+ alias :voted_down_for? :voted_down_on?
67
+
56
68
  def voted_as_when_voting_on votable
57
69
  votes = find_votes(:votable_id => votable.id, :votable_type => votable.class.name)
58
70
  return nil if votes.size == 0
data/spec/voter_spec.rb CHANGED
@@ -55,6 +55,26 @@ describe ActsAsVotable::Voter do
55
55
  @voter.voted_as_when_voting_on(@votable).should be nil
56
56
  end
57
57
 
58
+ it "should return true if voter has voted true" do
59
+ @votable.vote :voter => @voter
60
+ @voter.voted_up_on?(@votable).should be true
61
+ end
62
+
63
+ it "should return false if voter has not voted true" do
64
+ @votable.vote :voter => @voter, :vote => false
65
+ @voter.voted_up_on?(@votable).should be false
66
+ end
67
+
68
+ it "should return true if the voter has voted false" do
69
+ @votable.vote :voter => @voter, :vote => false
70
+ @voter.voted_down_on?(@votable).should be true
71
+ end
72
+
73
+ it "should return false if the voter has not voted false" do
74
+ @votable.vote :voter => @voter, :vote => true
75
+ @voter.voted_down_on?(@votable).should be false
76
+ end
77
+
58
78
  it "should provide reserve functionality, voter can vote on votable" do
59
79
  @voter.vote :votable => @votable, :vote => 'bad'
60
80
  @voter.voted_as_when_voting_on(@votable).should be false
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.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-25 00:00:00.000000000 Z
12
+ date: 2012-04-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -100,7 +100,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
100
100
  version: '0'
101
101
  segments:
102
102
  - 0
103
- hash: 2055289200548922413
103
+ hash: 4111085336176516167
104
104
  required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  version: '0'
110
110
  segments:
111
111
  - 0
112
- hash: 2055289200548922413
112
+ hash: 4111085336176516167
113
113
  requirements: []
114
114
  rubyforge_project: acts_as_votable
115
115
  rubygems_version: 1.8.21