make_voteable 0.1.0 → 0.1.1
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/lib/make_voteable/version.rb +1 -1
- data/lib/make_voteable/voter.rb +17 -0
- data/make_voteable.gemspec +2 -2
- data/spec/lib/make_voteable_spec.rb +12 -6
- metadata +4 -4
data/lib/make_voteable/voter.rb
CHANGED
@@ -40,6 +40,8 @@ module MakeVoteable
|
|
40
40
|
voteable.save
|
41
41
|
voting.save
|
42
42
|
end
|
43
|
+
|
44
|
+
true
|
43
45
|
end
|
44
46
|
|
45
47
|
# Up votes the +voteable+, but doesn't raise an error if the votelable was already up voted.
|
@@ -47,8 +49,11 @@ module MakeVoteable
|
|
47
49
|
def up_vote!(voteable)
|
48
50
|
begin
|
49
51
|
up_vote(voteable)
|
52
|
+
success = true
|
50
53
|
rescue Exceptions::AlreadyVotedError
|
54
|
+
success = false
|
51
55
|
end
|
56
|
+
success
|
52
57
|
end
|
53
58
|
|
54
59
|
# Down vote a +voteable+.
|
@@ -79,6 +84,8 @@ module MakeVoteable
|
|
79
84
|
voteable.save
|
80
85
|
voting.save
|
81
86
|
end
|
87
|
+
|
88
|
+
true
|
82
89
|
end
|
83
90
|
|
84
91
|
# Down votes the +voteable+, but doesn't raise an error if the votelable was already down voted.
|
@@ -86,8 +93,11 @@ module MakeVoteable
|
|
86
93
|
def down_vote!(voteable)
|
87
94
|
begin
|
88
95
|
down_vote(voteable)
|
96
|
+
success = true
|
89
97
|
rescue Exceptions::AlreadyVotedError
|
98
|
+
success = false
|
90
99
|
end
|
100
|
+
success
|
91
101
|
end
|
92
102
|
|
93
103
|
# Clears an already done vote on a +voteable+.
|
@@ -112,6 +122,8 @@ module MakeVoteable
|
|
112
122
|
voteable.save
|
113
123
|
voting.destroy
|
114
124
|
end
|
125
|
+
|
126
|
+
true
|
115
127
|
end
|
116
128
|
|
117
129
|
# Clears an already done vote on a +voteable+, but doesn't raise an error if
|
@@ -119,8 +131,11 @@ module MakeVoteable
|
|
119
131
|
def unvote!(voteable)
|
120
132
|
begin
|
121
133
|
unvote(voteable)
|
134
|
+
success = true
|
122
135
|
rescue Exceptions::NotVotedError
|
136
|
+
success = false
|
123
137
|
end
|
138
|
+
success
|
124
139
|
end
|
125
140
|
|
126
141
|
# Returns true if the voter voted for the +voteable+.
|
@@ -134,6 +149,7 @@ module MakeVoteable
|
|
134
149
|
def up_voted?(voteable)
|
135
150
|
check_voteable(voteable)
|
136
151
|
voting = fetch_voting(voteable)
|
152
|
+
return false if voting.nil?
|
137
153
|
return true if voting.has_attribute?(:up_vote) && voting.up_vote
|
138
154
|
false
|
139
155
|
end
|
@@ -142,6 +158,7 @@ module MakeVoteable
|
|
142
158
|
def down_voted?(voteable)
|
143
159
|
check_voteable(voteable)
|
144
160
|
voting = fetch_voting(voteable)
|
161
|
+
return false if voting.nil?
|
145
162
|
return true if voting.has_attribute?(:up_vote) && !voting.up_vote
|
146
163
|
false
|
147
164
|
end
|
data/make_voteable.gemspec
CHANGED
@@ -14,10 +14,10 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.required_rubygems_version = ">= 1.3.6"
|
15
15
|
s.rubyforge_project = "make_voteable"
|
16
16
|
|
17
|
-
s.add_dependency "activerecord", "~> 3.0
|
17
|
+
s.add_dependency "activerecord", "~> 3.0"
|
18
18
|
s.add_development_dependency "bundler", "~> 1.0.0"
|
19
19
|
s.add_development_dependency "rspec", "~> 2.5.0"
|
20
|
-
s.add_development_dependency "database_cleaner", "0.6.7
|
20
|
+
s.add_development_dependency "database_cleaner", "0.6.7"
|
21
21
|
s.add_development_dependency "sqlite3-ruby", "~> 1.3.0"
|
22
22
|
s.add_development_dependency "generator_spec", "~> 0.8.2"
|
23
23
|
|
@@ -17,11 +17,11 @@ describe "Make Voteable" do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should get correct vote summary" do
|
20
|
-
@voter.up_vote(@voteable)
|
20
|
+
@voter.up_vote(@voteable).should == true
|
21
21
|
@voteable.votes.should == 1
|
22
|
-
@voter.down_vote(@voteable)
|
22
|
+
@voter.down_vote(@voteable).should == true
|
23
23
|
@voteable.votes.should == -1
|
24
|
-
@voter.unvote(@voteable)
|
24
|
+
@voter.unvote(@voteable).should == true
|
25
25
|
@voteable.votes.should == 0
|
26
26
|
end
|
27
27
|
|
@@ -83,7 +83,9 @@ describe "Make Voteable" do
|
|
83
83
|
|
84
84
|
it "should only allow a voter to up vote a voteable once without raising an error" do
|
85
85
|
@voter.up_vote!(@voteable)
|
86
|
-
lambda {
|
86
|
+
lambda {
|
87
|
+
@voter.up_vote!(@voteable).should == false
|
88
|
+
}.should_not raise_error(MakeVoteable::Exceptions::AlreadyVotedError)
|
87
89
|
MakeVoteable::Voting.count.should == 1
|
88
90
|
end
|
89
91
|
|
@@ -155,7 +157,9 @@ describe "Make Voteable" do
|
|
155
157
|
|
156
158
|
it "should only allow a voter to down vote a voteable once without raising an error" do
|
157
159
|
@voter.down_vote!(@voteable)
|
158
|
-
lambda {
|
160
|
+
lambda {
|
161
|
+
@voter.down_vote!(@voteable).should == false
|
162
|
+
}.should_not raise_error(MakeVoteable::Exceptions::AlreadyVotedError)
|
159
163
|
MakeVoteable::Voting.count.should == 1
|
160
164
|
end
|
161
165
|
|
@@ -219,7 +223,9 @@ describe "Make Voteable" do
|
|
219
223
|
end
|
220
224
|
|
221
225
|
it "should not raise error if voter didn't vote for the voteable and unvote! is called" do
|
222
|
-
lambda {
|
226
|
+
lambda {
|
227
|
+
@voter.unvote!(@voteable).should == false
|
228
|
+
}.should_not raise_error(MakeVoteable::Exceptions::NotVotedError)
|
223
229
|
end
|
224
230
|
|
225
231
|
it "should raise an error for an invalid voteable" do
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: make_voteable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Kai Schlamp
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-07-25 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
requirements:
|
22
22
|
- - ~>
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version: 3.0
|
24
|
+
version: "3.0"
|
25
25
|
type: :runtime
|
26
26
|
version_requirements: *id001
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
requirements:
|
55
55
|
- - "="
|
56
56
|
- !ruby/object:Gem::Version
|
57
|
-
version: 0.6.7
|
57
|
+
version: 0.6.7
|
58
58
|
type: :development
|
59
59
|
version_requirements: *id004
|
60
60
|
- !ruby/object:Gem::Dependency
|