acts_as_votable 0.10.0 → 0.13.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.
- checksums.yaml +5 -5
- data/.github/workflows/main.yml +44 -0
- data/.gitignore +10 -6
- data/.rubocop.yml +121 -0
- data/.ruby-version +1 -0
- data/Appraisals +23 -0
- data/Gemfile +3 -14
- data/{README.markdown → README.md} +87 -52
- data/Rakefile +6 -4
- data/acts_as_votable.gemspec +12 -7
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/rails_4.gemfile +7 -0
- data/gemfiles/rails_5.gemfile +7 -0
- data/gemfiles/rails_5_1.gemfile +7 -0
- data/gemfiles/rails_5_2.gemfile +7 -0
- data/gemfiles/rails_6.gemfile +8 -0
- data/gemfiles/rails_6_1.gemfile +8 -0
- data/gemfiles/rails_6_rc1.gemfile +8 -0
- data/lib/acts_as_votable.rb +9 -9
- data/lib/acts_as_votable/cacheable.rb +174 -0
- data/lib/acts_as_votable/extenders/controller.rb +3 -4
- data/lib/acts_as_votable/extenders/votable.rb +17 -6
- data/lib/acts_as_votable/extenders/voter.rb +4 -6
- data/lib/acts_as_votable/helpers/words.rb +7 -10
- data/lib/acts_as_votable/version.rb +3 -1
- data/lib/acts_as_votable/votable.rb +74 -194
- data/lib/acts_as_votable/vote.rb +10 -12
- data/lib/acts_as_votable/voter.rb +55 -56
- data/lib/generators/acts_as_votable/migration/migration_generator.rb +25 -4
- data/lib/generators/acts_as_votable/migration/templates/active_record/{migration.rb → migration.erb} +1 -6
- data/spec/factories/votable.rb +6 -0
- data/spec/factories/votable_cache.rb +6 -0
- data/spec/factories/votable_cache_update_attributes.rb +6 -0
- data/spec/factories/votable_cache_update_columns.rb +6 -0
- data/spec/factories/votable_child_of_sti_not_votable.rb +6 -0
- data/spec/factories/votable_child_of_sti_votable.rb +6 -0
- data/spec/factories/votable_voter.rb +6 -0
- data/spec/factories/vote.rb +6 -0
- data/spec/factories/voter.rb +6 -0
- data/spec/generators/active_record_generator_spec.rb +13 -0
- data/spec/shared_example/votable_model.rb +542 -0
- data/spec/shared_example/voter_model.rb +280 -0
- data/spec/spec_helper.rb +28 -18
- data/spec/support/factory_bot.rb +9 -0
- data/spec/votable_spec.rb +10 -9
- data/spec/votable_voter_spec.rb +12 -12
- data/spec/voter_spec.rb +9 -10
- data/spec/words_spec.rb +9 -12
- metadata +116 -26
- data/.travis.yml +0 -25
- data/spec/shared_example/votable_model_spec.rb +0 -421
- data/spec/shared_example/voter_model_spec.rb +0 -279
data/spec/words_spec.rb
CHANGED
@@ -1,30 +1,27 @@
|
|
1
|
-
|
2
|
-
require 'spec_helper'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
require "spec_helper"
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
end
|
5
|
+
describe ActsAsVotable::Helpers::Words do
|
6
|
+
let(:vote) { build(:vote) }
|
9
7
|
|
10
8
|
it "should know that like is a true vote" do
|
11
|
-
|
9
|
+
expect(vote.votable_words.that_mean_true).to include "like"
|
12
10
|
end
|
13
11
|
|
14
12
|
it "should know that bad is a false vote" do
|
15
|
-
|
13
|
+
expect(vote.votable_words.that_mean_false).to include "bad"
|
16
14
|
end
|
17
15
|
|
18
16
|
it "should be a vote for true when word is good" do
|
19
|
-
|
17
|
+
expect(vote.votable_words.meaning_of("good")).to be true
|
20
18
|
end
|
21
19
|
|
22
20
|
it "should be a vote for false when word is down" do
|
23
|
-
|
21
|
+
expect(vote.votable_words.meaning_of("down")).to be false
|
24
22
|
end
|
25
23
|
|
26
24
|
it "should be a vote for true when the word is unknown" do
|
27
|
-
|
25
|
+
expect(vote.votable_words.meaning_of("lsdhklkadhfs")).to be true
|
28
26
|
end
|
29
|
-
|
30
27
|
end
|
metadata
CHANGED
@@ -1,43 +1,99 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_votable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '3.6'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '3.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sqlite3
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.3.
|
33
|
+
version: 1.3.6
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.3.
|
40
|
+
version: 1.3.6
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.49.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.49.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.15.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.15.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: appraisal
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.2'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: factory_bot
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '4.8'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '4.8'
|
41
97
|
description: Rails gem to allowing records to be votable
|
42
98
|
email:
|
43
99
|
- ryanto
|
@@ -45,13 +101,25 @@ executables: []
|
|
45
101
|
extensions: []
|
46
102
|
extra_rdoc_files: []
|
47
103
|
files:
|
48
|
-
- .
|
49
|
-
- .
|
104
|
+
- ".github/workflows/main.yml"
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rubocop.yml"
|
107
|
+
- ".ruby-version"
|
108
|
+
- Appraisals
|
50
109
|
- Gemfile
|
51
|
-
- README.
|
110
|
+
- README.md
|
52
111
|
- Rakefile
|
53
112
|
- acts_as_votable.gemspec
|
113
|
+
- gemfiles/.bundle/config
|
114
|
+
- gemfiles/rails_4.gemfile
|
115
|
+
- gemfiles/rails_5.gemfile
|
116
|
+
- gemfiles/rails_5_1.gemfile
|
117
|
+
- gemfiles/rails_5_2.gemfile
|
118
|
+
- gemfiles/rails_6.gemfile
|
119
|
+
- gemfiles/rails_6_1.gemfile
|
120
|
+
- gemfiles/rails_6_rc1.gemfile
|
54
121
|
- lib/acts_as_votable.rb
|
122
|
+
- lib/acts_as_votable/cacheable.rb
|
55
123
|
- lib/acts_as_votable/extenders/controller.rb
|
56
124
|
- lib/acts_as_votable/extenders/votable.rb
|
57
125
|
- lib/acts_as_votable/extenders/voter.rb
|
@@ -61,41 +129,63 @@ files:
|
|
61
129
|
- lib/acts_as_votable/vote.rb
|
62
130
|
- lib/acts_as_votable/voter.rb
|
63
131
|
- lib/generators/acts_as_votable/migration/migration_generator.rb
|
64
|
-
- lib/generators/acts_as_votable/migration/templates/active_record/migration.
|
65
|
-
- spec/
|
66
|
-
- spec/
|
132
|
+
- lib/generators/acts_as_votable/migration/templates/active_record/migration.erb
|
133
|
+
- spec/factories/votable.rb
|
134
|
+
- spec/factories/votable_cache.rb
|
135
|
+
- spec/factories/votable_cache_update_attributes.rb
|
136
|
+
- spec/factories/votable_cache_update_columns.rb
|
137
|
+
- spec/factories/votable_child_of_sti_not_votable.rb
|
138
|
+
- spec/factories/votable_child_of_sti_votable.rb
|
139
|
+
- spec/factories/votable_voter.rb
|
140
|
+
- spec/factories/vote.rb
|
141
|
+
- spec/factories/voter.rb
|
142
|
+
- spec/generators/active_record_generator_spec.rb
|
143
|
+
- spec/shared_example/votable_model.rb
|
144
|
+
- spec/shared_example/voter_model.rb
|
67
145
|
- spec/spec_helper.rb
|
146
|
+
- spec/support/factory_bot.rb
|
68
147
|
- spec/votable_spec.rb
|
69
148
|
- spec/votable_voter_spec.rb
|
70
149
|
- spec/voter_spec.rb
|
71
150
|
- spec/words_spec.rb
|
72
151
|
homepage: http://rubygems.org/gems/acts_as_votable
|
73
|
-
licenses:
|
152
|
+
licenses:
|
153
|
+
- MIT
|
74
154
|
metadata: {}
|
75
|
-
post_install_message:
|
155
|
+
post_install_message:
|
76
156
|
rdoc_options: []
|
77
157
|
require_paths:
|
78
158
|
- lib
|
79
159
|
required_ruby_version: !ruby/object:Gem::Requirement
|
80
160
|
requirements:
|
81
|
-
- -
|
161
|
+
- - ">="
|
82
162
|
- !ruby/object:Gem::Version
|
83
163
|
version: '0'
|
84
164
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
165
|
requirements:
|
86
|
-
- -
|
166
|
+
- - ">="
|
87
167
|
- !ruby/object:Gem::Version
|
88
168
|
version: '0'
|
89
169
|
requirements: []
|
90
|
-
|
91
|
-
|
92
|
-
signing_key:
|
170
|
+
rubygems_version: 3.2.2
|
171
|
+
signing_key:
|
93
172
|
specification_version: 4
|
94
173
|
summary: Rails gem to allowing records to be votable
|
95
174
|
test_files:
|
96
|
-
- spec/
|
97
|
-
- spec/
|
175
|
+
- spec/factories/votable.rb
|
176
|
+
- spec/factories/votable_cache.rb
|
177
|
+
- spec/factories/votable_cache_update_attributes.rb
|
178
|
+
- spec/factories/votable_cache_update_columns.rb
|
179
|
+
- spec/factories/votable_child_of_sti_not_votable.rb
|
180
|
+
- spec/factories/votable_child_of_sti_votable.rb
|
181
|
+
- spec/factories/votable_voter.rb
|
182
|
+
- spec/factories/vote.rb
|
183
|
+
- spec/factories/voter.rb
|
184
|
+
- spec/generators/active_record_generator_spec.rb
|
185
|
+
- spec/shared_example/votable_model.rb
|
186
|
+
- spec/shared_example/voter_model.rb
|
98
187
|
- spec/spec_helper.rb
|
188
|
+
- spec/support/factory_bot.rb
|
99
189
|
- spec/votable_spec.rb
|
100
190
|
- spec/votable_voter_spec.rb
|
101
191
|
- spec/voter_spec.rb
|
data/.travis.yml
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- 1.8.7
|
4
|
-
- 1.9.2
|
5
|
-
- 1.9.3
|
6
|
-
- 2.0.0
|
7
|
-
- 2.1.0
|
8
|
-
env:
|
9
|
-
- "RAILS_VERSION=3.0.0"
|
10
|
-
- "RAILS_VERSION=3.1.0"
|
11
|
-
- "RAILS_VERSION=3.2.0"
|
12
|
-
- "RAILS_VERSION=4.0.0"
|
13
|
-
- "RAILS_VERSION=4.1.0"
|
14
|
-
matrix:
|
15
|
-
exclude:
|
16
|
-
- rvm: 1.8.7
|
17
|
-
env: "RAILS_VERSION=4.0.0"
|
18
|
-
- rvm: 1.9.2
|
19
|
-
env: "RAILS_VERSION=4.0.0"
|
20
|
-
- rvm: 1.8.7
|
21
|
-
env: "RAILS_VERSION=4.1.0"
|
22
|
-
- rvm: 1.9.2
|
23
|
-
env: "RAILS_VERSION=4.1.0"
|
24
|
-
- rvm: 1.9.3
|
25
|
-
env: "RAILS_VERSION=4.1.0"
|
@@ -1,421 +0,0 @@
|
|
1
|
-
shared_examples "a votable_model" do
|
2
|
-
it "should return false when a vote with no voter is saved" do
|
3
|
-
votable.vote_by.should be false
|
4
|
-
end
|
5
|
-
|
6
|
-
it "should have one vote when saved" do
|
7
|
-
votable.vote_by :voter => voter, :vote => 'yes'
|
8
|
-
votable.votes_for.size.should == 1
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should have one vote when voted on twice by the same person" do
|
12
|
-
votable.vote_by :voter => voter, :vote => 'yes'
|
13
|
-
votable.vote_by :voter => voter, :vote => 'no'
|
14
|
-
votable.votes_for.size.should == 1
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should have two votes_for when voted on twice by the same person with duplicate paramenter" do
|
18
|
-
votable.vote_by :voter => voter, :vote => 'yes'
|
19
|
-
votable.vote_by :voter => voter, :vote => 'no', :duplicate => true
|
20
|
-
votable.votes_for.size.should == 2
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should have one scoped vote when voting under an scope" do
|
24
|
-
votable.vote_by :voter => voter, :vote => 'yes', :vote_scope => 'rank'
|
25
|
-
votable.find_votes_for(:vote_scope => 'rank').size.should == 1
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should have one vote when voted on twice using scope by the same person" do
|
29
|
-
votable.vote_by :voter => voter, :vote => 'yes', :vote_scope => 'rank'
|
30
|
-
votable.vote_by :voter => voter, :vote => 'no', :vote_scope => 'rank'
|
31
|
-
votable.find_votes_for(:vote_scope => 'rank').size.should == 1
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should have two votes_for when voting on two different scopes by the same person" do
|
35
|
-
votable.vote_by :voter => voter, :vote => 'yes', :vote_scope => 'weekly_rank'
|
36
|
-
votable.vote_by :voter => voter, :vote => 'no', :vote_scope => 'monthly_rank'
|
37
|
-
votable.votes_for.size.should == 2
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should be callable with vote_up" do
|
41
|
-
votable.vote_up voter
|
42
|
-
votable.get_up_votes.first.voter.should == voter
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should be callable with vote_down" do
|
46
|
-
votable.vote_down voter
|
47
|
-
votable.get_down_votes.first.voter.should == voter
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should have 2 votes_for when voted on once by two different people" do
|
51
|
-
votable.vote_by :voter => voter
|
52
|
-
votable.vote_by :voter => voter2
|
53
|
-
votable.votes_for.size.should == 2
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should have one true vote" do
|
57
|
-
votable.vote_by :voter => voter
|
58
|
-
votable.vote_by :voter => voter2, :vote => 'dislike'
|
59
|
-
votable.get_up_votes.size.should == 1
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should have 2 false votes_for" do
|
63
|
-
votable.vote_by :voter => voter, :vote => 'no'
|
64
|
-
votable.vote_by :voter => voter2, :vote => 'dislike'
|
65
|
-
votable.get_down_votes.size.should == 2
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should have been voted on by voter2" do
|
69
|
-
votable.vote_by :voter => voter2, :vote => true
|
70
|
-
votable.find_votes_for.first.voter.id.should be voter2.id
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should count the vote as registered if this is the voters first vote" do
|
74
|
-
votable.vote_by :voter => voter
|
75
|
-
votable.vote_registered?.should be true
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should not count the vote as being registered if that voter has already voted and the vote has not changed" do
|
79
|
-
votable.vote_by :voter => voter, :vote => true
|
80
|
-
votable.vote_by :voter => voter, :vote => 'yes'
|
81
|
-
votable.vote_registered?.should be false
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should count the vote as registered if the voter has voted and the vote flag has changed" do
|
85
|
-
votable.vote_by :voter => voter, :vote => true
|
86
|
-
votable.vote_by :voter => voter, :vote => 'dislike'
|
87
|
-
votable.vote_registered?.should be true
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should count the vote as registered if the voter has voted and the vote weight has changed" do
|
91
|
-
votable.vote_by :voter => voter, :vote => true, :vote_weight => 1
|
92
|
-
votable.vote_by :voter => voter, :vote => true, :vote_weight => 2
|
93
|
-
votable.vote_registered?.should be true
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should be voted on by voter" do
|
97
|
-
votable.vote_by :voter => voter
|
98
|
-
votable.voted_on_by?(voter).should be true
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should be able to unvote a voter" do
|
102
|
-
votable.liked_by(voter)
|
103
|
-
votable.unliked_by(voter)
|
104
|
-
votable.voted_on_by?(voter).should be false
|
105
|
-
end
|
106
|
-
|
107
|
-
it "should unvote a positive vote" do
|
108
|
-
votable.vote_by :voter => voter
|
109
|
-
votable.unvote :voter => voter
|
110
|
-
votable.find_votes_for.count.should == 0
|
111
|
-
end
|
112
|
-
|
113
|
-
it "should set the votable to unregistered after unvoting" do
|
114
|
-
votable.vote_by :voter => voter
|
115
|
-
votable.unvote :voter => voter
|
116
|
-
votable.vote_registered?.should be false
|
117
|
-
end
|
118
|
-
|
119
|
-
it "should unvote a negative vote" do
|
120
|
-
votable.vote_by :voter => voter, :vote => 'no'
|
121
|
-
votable.unvote :voter => voter
|
122
|
-
votable.find_votes_for.count.should == 0
|
123
|
-
end
|
124
|
-
|
125
|
-
it "should unvote only the from a single voter" do
|
126
|
-
votable.vote_by :voter => voter
|
127
|
-
votable.vote_by :voter => voter2
|
128
|
-
votable.unvote :voter => voter
|
129
|
-
votable.find_votes_for.count.should == 1
|
130
|
-
end
|
131
|
-
|
132
|
-
it "should be contained to instances" do
|
133
|
-
votable2 = Votable.new(:name => '2nd votable')
|
134
|
-
votable2.save
|
135
|
-
|
136
|
-
votable.vote_by :voter => voter, :vote => false
|
137
|
-
votable2.vote_by :voter => voter, :vote => true
|
138
|
-
votable2.vote_by :voter => voter, :vote => true
|
139
|
-
|
140
|
-
votable.vote_registered?.should be true
|
141
|
-
votable2.vote_registered?.should be false
|
142
|
-
end
|
143
|
-
|
144
|
-
it "should set default vote weight to 1 if not specified" do
|
145
|
-
votable.upvote_by voter
|
146
|
-
votable.find_votes_for.first.vote_weight.should == 1
|
147
|
-
end
|
148
|
-
|
149
|
-
describe "with cached votes_for" do
|
150
|
-
|
151
|
-
before(:each) do
|
152
|
-
clean_database
|
153
|
-
voter = Voter.new(:name => 'i can vote!')
|
154
|
-
voter.save
|
155
|
-
|
156
|
-
votable = Votable.new(:name => 'a voting model without a cache')
|
157
|
-
votable.save
|
158
|
-
|
159
|
-
votable_cache = VotableCache.new(:name => 'voting model with cache')
|
160
|
-
votable_cache.save
|
161
|
-
end
|
162
|
-
|
163
|
-
it "should not update cached votes_for if there are no columns" do
|
164
|
-
votable.vote_by :voter => voter
|
165
|
-
end
|
166
|
-
|
167
|
-
it "should update cached total votes_for if there is a total column" do
|
168
|
-
votable_cache.cached_votes_total = 50
|
169
|
-
votable_cache.vote_by :voter => voter
|
170
|
-
votable_cache.cached_votes_total.should == 1
|
171
|
-
end
|
172
|
-
|
173
|
-
it "should update cached total votes_for when a vote up is removed" do
|
174
|
-
votable_cache.vote_by :voter => voter, :vote => 'true'
|
175
|
-
votable_cache.unvote :voter => voter
|
176
|
-
votable_cache.cached_votes_total.should == 0
|
177
|
-
end
|
178
|
-
|
179
|
-
it "should update cached total votes_for when a vote down is removed" do
|
180
|
-
votable_cache.vote_by :voter => voter, :vote => 'false'
|
181
|
-
votable_cache.unvote :voter => voter
|
182
|
-
votable_cache.cached_votes_total.should == 0
|
183
|
-
end
|
184
|
-
|
185
|
-
it "should update cached score votes_for if there is a score column" do
|
186
|
-
votable_cache.cached_votes_score = 50
|
187
|
-
votable_cache.vote_by :voter => voter
|
188
|
-
votable_cache.cached_votes_score.should == 1
|
189
|
-
votable_cache.vote_by :voter => voter2, :vote => 'false'
|
190
|
-
votable_cache.cached_votes_score.should == 0
|
191
|
-
votable_cache.vote_by :voter => voter, :vote => 'false'
|
192
|
-
votable_cache.cached_votes_score.should == -2
|
193
|
-
end
|
194
|
-
|
195
|
-
it "should update cached score votes_for when a vote up is removed" do
|
196
|
-
votable_cache.vote_by :voter => voter, :vote => 'true'
|
197
|
-
votable_cache.cached_votes_score.should == 1
|
198
|
-
votable_cache.unvote :voter => voter
|
199
|
-
votable_cache.cached_votes_score.should == 0
|
200
|
-
end
|
201
|
-
|
202
|
-
it "should update cached score votes_for when a vote down is removed" do
|
203
|
-
votable_cache.vote_by :voter => voter, :vote => 'false'
|
204
|
-
votable_cache.cached_votes_score.should == -1
|
205
|
-
votable_cache.unvote :voter => voter
|
206
|
-
votable_cache.cached_votes_score.should == 0
|
207
|
-
end
|
208
|
-
|
209
|
-
it "should update cached weighted total if there is a weighted total column" do
|
210
|
-
votable_cache.cached_weighted_total = 50
|
211
|
-
votable_cache.vote_by :voter => voter
|
212
|
-
votable_cache.cached_weighted_total.should == 1
|
213
|
-
votable_cache.vote_by :voter => voter2, :vote => 'false'
|
214
|
-
votable_cache.cached_weighted_total.should == 2
|
215
|
-
end
|
216
|
-
|
217
|
-
it "should update cached weighted total votes_for when a vote up is removed" do
|
218
|
-
votable_cache.vote_by :voter => voter, :vote => 'true', :vote_weight => 3
|
219
|
-
votable_cache.cached_weighted_total.should == 3
|
220
|
-
votable_cache.unvote :voter => voter
|
221
|
-
votable_cache.cached_weighted_total.should == 0
|
222
|
-
end
|
223
|
-
|
224
|
-
it "should update cached weighted total votes_for when a vote down is removed" do
|
225
|
-
votable_cache.vote_by :voter => voter, :vote => 'false', :vote_weight => 4
|
226
|
-
votable_cache.cached_weighted_total.should == 4
|
227
|
-
votable_cache.unvote :voter => voter
|
228
|
-
votable_cache.cached_weighted_total.should == 0
|
229
|
-
end
|
230
|
-
|
231
|
-
it "should update cached weighted score if there is a weighted score column" do
|
232
|
-
votable_cache.cached_weighted_score = 50
|
233
|
-
votable_cache.vote_by :voter => voter
|
234
|
-
votable_cache.cached_weighted_score.should == 1
|
235
|
-
votable_cache.vote_by :voter => voter2, :vote => 'false'
|
236
|
-
votable_cache.cached_weighted_score.should == 0
|
237
|
-
votable_cache.vote_by :voter => voter, :vote => 'false'
|
238
|
-
votable_cache.cached_weighted_score.should == -2
|
239
|
-
end
|
240
|
-
|
241
|
-
it "should update cached weighted score votes_for when a vote up is removed" do
|
242
|
-
votable_cache.vote_by :voter => voter, :vote => 'true', :vote_weight => 3
|
243
|
-
votable_cache.cached_weighted_score.should == 3
|
244
|
-
votable_cache.unvote :voter => voter
|
245
|
-
votable_cache.cached_weighted_score.should == 0
|
246
|
-
end
|
247
|
-
|
248
|
-
it "should update cached weighted score votes_for when a vote down is removed" do
|
249
|
-
votable_cache.vote_by :voter => voter, :vote => 'false', :vote_weight => 4
|
250
|
-
votable_cache.cached_weighted_score.should == -4
|
251
|
-
votable_cache.unvote :voter => voter
|
252
|
-
votable_cache.cached_weighted_score.should == 0
|
253
|
-
end
|
254
|
-
|
255
|
-
it "should update cached up votes_for if there is an up vote column" do
|
256
|
-
votable_cache.cached_votes_up = 50
|
257
|
-
votable_cache.vote_by :voter => voter
|
258
|
-
votable_cache.vote_by :voter => voter
|
259
|
-
votable_cache.cached_votes_up.should == 1
|
260
|
-
end
|
261
|
-
|
262
|
-
it "should update cached down votes_for if there is a down vote column" do
|
263
|
-
votable_cache.cached_votes_down = 50
|
264
|
-
votable_cache.vote_by :voter => voter, :vote => 'false'
|
265
|
-
votable_cache.cached_votes_down.should == 1
|
266
|
-
end
|
267
|
-
|
268
|
-
it "should update cached up votes_for when a vote up is removed" do
|
269
|
-
votable_cache.vote_by :voter => voter, :vote => 'true'
|
270
|
-
votable_cache.unvote :voter => voter
|
271
|
-
votable_cache.cached_votes_up.should == 0
|
272
|
-
end
|
273
|
-
|
274
|
-
it "should update cached down votes_for when a vote down is removed" do
|
275
|
-
votable_cache.vote_by :voter => voter, :vote => 'false'
|
276
|
-
votable_cache.unvote :voter => voter
|
277
|
-
votable_cache.cached_votes_down.should == 0
|
278
|
-
end
|
279
|
-
|
280
|
-
it "should select from cached total votes_for if there a total column" do
|
281
|
-
votable_cache.vote_by :voter => voter
|
282
|
-
votable_cache.cached_votes_total = 50
|
283
|
-
votable_cache.count_votes_total.should == 50
|
284
|
-
end
|
285
|
-
|
286
|
-
it "should select from cached up votes_for if there is an up vote column" do
|
287
|
-
votable_cache.vote_by :voter => voter
|
288
|
-
votable_cache.cached_votes_up = 50
|
289
|
-
votable_cache.count_votes_up.should == 50
|
290
|
-
end
|
291
|
-
|
292
|
-
it "should select from cached down votes_for if there is a down vote column" do
|
293
|
-
votable_cache.vote_by :voter => voter, :vote => 'false'
|
294
|
-
votable_cache.cached_votes_down = 50
|
295
|
-
votable_cache.count_votes_down.should == 50
|
296
|
-
end
|
297
|
-
|
298
|
-
it "should select from cached weighted total if there is a weighted total column" do
|
299
|
-
votable_cache.vote_by :voter => voter, :vote => 'false'
|
300
|
-
votable_cache.cached_weighted_total = 50
|
301
|
-
votable_cache.weighted_total.should == 50
|
302
|
-
end
|
303
|
-
|
304
|
-
it "should select from cached weighted score if there is a weighted score column" do
|
305
|
-
votable_cache.vote_by :voter => voter, :vote => 'false'
|
306
|
-
votable_cache.cached_weighted_score = 50
|
307
|
-
votable_cache.weighted_score.should == 50
|
308
|
-
end
|
309
|
-
|
310
|
-
end
|
311
|
-
|
312
|
-
describe "with scoped cached votes_for" do
|
313
|
-
|
314
|
-
it "should update cached total votes_for if there is a total column" do
|
315
|
-
votable_cache.cached_scoped_test_votes_total = 50
|
316
|
-
votable_cache.vote_by :voter => voter, :vote_scope => "test"
|
317
|
-
votable_cache.cached_scoped_test_votes_total.should == 1
|
318
|
-
end
|
319
|
-
|
320
|
-
it "should update cached total votes_for when a vote up is removed" do
|
321
|
-
votable_cache.vote_by :voter => voter, :vote => 'true', :vote_scope => "test"
|
322
|
-
votable_cache.unvote :voter => voter, :vote_scope => "test"
|
323
|
-
votable_cache.cached_scoped_test_votes_total.should == 0
|
324
|
-
end
|
325
|
-
|
326
|
-
it "should update cached total votes_for when a vote down is removed" do
|
327
|
-
votable_cache.vote_by :voter => voter, :vote => 'false', :vote_scope => "test"
|
328
|
-
votable_cache.unvote :voter => voter, :vote_scope => "test"
|
329
|
-
votable_cache.cached_scoped_test_votes_total.should == 0
|
330
|
-
end
|
331
|
-
|
332
|
-
it "should update cached score votes_for if there is a score column" do
|
333
|
-
votable_cache.cached_scoped_test_votes_score = 50
|
334
|
-
votable_cache.vote_by :voter => voter, :vote_scope => "test"
|
335
|
-
votable_cache.cached_scoped_test_votes_score.should == 1
|
336
|
-
votable_cache.vote_by :voter => voter2, :vote => 'false', :vote_scope => "test"
|
337
|
-
votable_cache.cached_scoped_test_votes_score.should == 0
|
338
|
-
votable_cache.vote_by :voter => voter, :vote => 'false', :vote_scope => "test"
|
339
|
-
votable_cache.cached_scoped_test_votes_score.should == -2
|
340
|
-
end
|
341
|
-
|
342
|
-
it "should update cached score votes_for when a vote up is removed" do
|
343
|
-
votable_cache.vote_by :voter => voter, :vote => 'true', :vote_scope => "test"
|
344
|
-
votable_cache.cached_scoped_test_votes_score.should == 1
|
345
|
-
votable_cache.unvote :voter => voter, :vote_scope => "test"
|
346
|
-
votable_cache.cached_scoped_test_votes_score.should == 0
|
347
|
-
end
|
348
|
-
|
349
|
-
it "should update cached score votes_for when a vote down is removed" do
|
350
|
-
votable_cache.vote_by :voter => voter, :vote => 'false', :vote_scope => "test"
|
351
|
-
votable_cache.cached_scoped_test_votes_score.should == -1
|
352
|
-
votable_cache.unvote :voter => voter, :vote_scope => "test"
|
353
|
-
votable_cache.cached_scoped_test_votes_score.should == 0
|
354
|
-
end
|
355
|
-
|
356
|
-
it "should update cached up votes_for if there is an up vote column" do
|
357
|
-
votable_cache.cached_scoped_test_votes_up = 50
|
358
|
-
votable_cache.vote_by :voter => voter, :vote_scope => "test"
|
359
|
-
votable_cache.vote_by :voter => voter, :vote_scope => "test"
|
360
|
-
votable_cache.cached_scoped_test_votes_up.should == 1
|
361
|
-
end
|
362
|
-
|
363
|
-
it "should update cached down votes_for if there is a down vote column" do
|
364
|
-
votable_cache.cached_scoped_test_votes_down = 50
|
365
|
-
votable_cache.vote_by :voter => voter, :vote => 'false', :vote_scope => "test"
|
366
|
-
votable_cache.cached_scoped_test_votes_down.should == 1
|
367
|
-
end
|
368
|
-
|
369
|
-
it "should update cached up votes_for when a vote up is removed" do
|
370
|
-
votable_cache.vote_by :voter => voter, :vote => 'true', :vote_scope => "test"
|
371
|
-
votable_cache.unvote :voter => voter, :vote_scope => "test"
|
372
|
-
votable_cache.cached_scoped_test_votes_up.should == 0
|
373
|
-
end
|
374
|
-
|
375
|
-
it "should update cached down votes_for when a vote down is removed" do
|
376
|
-
votable_cache.vote_by :voter => voter, :vote => 'false', :vote_scope => "test"
|
377
|
-
votable_cache.unvote :voter => voter, :vote_scope => "test"
|
378
|
-
votable_cache.cached_scoped_test_votes_down.should == 0
|
379
|
-
end
|
380
|
-
|
381
|
-
it "should select from cached total votes_for if there a total column" do
|
382
|
-
votable_cache.vote_by :voter => voter, :vote_scope => "test"
|
383
|
-
votable_cache.cached_scoped_test_votes_total = 50
|
384
|
-
votable_cache.count_votes_total(false, "test").should == 50
|
385
|
-
end
|
386
|
-
|
387
|
-
it "should select from cached up votes_for if there is an up vote column" do
|
388
|
-
votable_cache.vote_by :voter => voter, :vote_scope => "test"
|
389
|
-
votable_cache.cached_scoped_test_votes_up = 50
|
390
|
-
votable_cache.count_votes_up(false, "test").should == 50
|
391
|
-
end
|
392
|
-
|
393
|
-
it "should select from cached down votes_for if there is a down vote column" do
|
394
|
-
votable_cache.vote_by :voter => voter, :vote => 'false', :vote_scope => "test"
|
395
|
-
votable_cache.cached_scoped_test_votes_down = 50
|
396
|
-
votable_cache.count_votes_down(false, "test").should == 50
|
397
|
-
end
|
398
|
-
|
399
|
-
end
|
400
|
-
|
401
|
-
describe "sti models" do
|
402
|
-
|
403
|
-
it "should be able to vote on a votable child of a non votable sti model" do
|
404
|
-
votable = VotableChildOfStiNotVotable.create(:name => 'sti child')
|
405
|
-
|
406
|
-
votable.vote_by :voter => voter, :vote => 'yes'
|
407
|
-
votable.votes_for.size.should == 1
|
408
|
-
end
|
409
|
-
|
410
|
-
it "should not be able to vote on a parent non votable" do
|
411
|
-
StiNotVotable.should_not be_votable
|
412
|
-
end
|
413
|
-
|
414
|
-
it "should be able to vote on a child when its parent is votable" do
|
415
|
-
votable = ChildOfStiVotable.create(:name => 'sti child')
|
416
|
-
|
417
|
-
votable.vote_by :voter => voter, :vote => 'yes'
|
418
|
-
votable.votes_for.size.should == 1
|
419
|
-
end
|
420
|
-
end
|
421
|
-
end
|