mongoid_rateable 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -50,9 +50,13 @@ Sure, you can rate and save in one fuction:
50
50
 
51
51
  == Additional Functionality
52
52
 
53
- You'll often want to know if a user can rate. Simple:
53
+ You'll often want to know if a user already rated post. Simple:
54
54
 
55
- @post.rated? @user # True if they've rated
55
+ @post.rated? @user # True if it rated by user
56
+
57
+ And if someone rated it:
58
+
59
+ @post.rated? # True if it rated by anyone
56
60
 
57
61
  You can also get a tally of the number of votes cast:
58
62
 
data/TODO CHANGED
@@ -1,4 +1,5 @@
1
1
  add method/scope most_voted(count), rated_between(,) to Rateable
2
2
  add min/max rating
3
3
  store rate_count and average_rate as fields (need migration to migrate from other versions)
4
- improve speed (http://cookbook.mongodb.org/patterns/votes/)
4
+ improve speed (http://cookbook.mongodb.org/patterns/votes/)
5
+ rate embedded (indexes?!)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.8
@@ -40,8 +40,12 @@ module Mongoid
40
40
  save
41
41
  end
42
42
 
43
- def rated?(rater)
44
- self.rating_marks.where(:rater_id => rater.id, :rater_class => rater.class.to_s).count == 1
43
+ def rated?(rater = nil)
44
+ if rater
45
+ self.rating_marks.where(:rater_id => rater.id, :rater_class => rater.class.to_s).count == 1
46
+ else
47
+ !self.rating_marks.empty?
48
+ end
45
49
  end
46
50
 
47
51
  def rating
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid_rateable}
8
- s.version = "0.0.7"
8
+ s.version = "0.0.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Peter Savichev (proton)"]
12
- s.date = %q{2011-06-20}
12
+ s.date = %q{2011-06-30}
13
13
  s.description = %q{Provides fields and methods for the manipulation of rates on Mongoid documents.}
14
14
  s.email = %q{psavichev@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -1,19 +1,19 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Post do
4
-
4
+
5
5
  before(:each) do
6
6
  @bob = User.create :name => "Bob"
7
7
  @alice = User.create :name => "Alice"
8
8
  @sally = User.create :name => "Sally"
9
9
  @post = Post.create :name => "Announcement"
10
10
  end
11
-
11
+
12
12
  it "should have Mongoid::Rateable module" do
13
13
  #TODO: Refactor this
14
14
  @post.class.const_get("Mongoid").const_get("Rateable").should be_true
15
15
  end
16
-
16
+
17
17
  subject { @post }
18
18
  it { should respond_to :rate }
19
19
  it { should respond_to :unrate }
@@ -24,85 +24,93 @@ describe Post do
24
24
  it { should respond_to :rates }
25
25
  it { should respond_to :rating }
26
26
  it { should respond_to :rating_marks }
27
-
27
+
28
28
  describe "#rates" do
29
29
  it "should be proper Mongoid field" do
30
30
  @post.fields['rates'].should be_an_instance_of Mongoid::Field
31
- end
31
+ end
32
32
  end
33
-
33
+
34
34
  describe "#rating_marks" do
35
35
  it "should be proper Mongoid field" do
36
36
  @post.rating_marks.should be_an_instance_of Array
37
- end
37
+ end
38
38
  end
39
-
39
+
40
40
  context "when rated" do
41
41
  before (:each) { @post.rate 1, @bob }
42
-
42
+
43
43
  describe "#rate" do
44
44
  it "should track #rates properly" do
45
45
  @post.rate 1, @sally
46
46
  @post.rates.should eql 2
47
- end
48
-
47
+ end
48
+
49
49
  it "should limit #rates by user properly" do
50
50
  @post.rate 5, @bob
51
51
  @post.rates.should eql 5
52
52
  end
53
-
53
+
54
54
  #TODO: Rewrite for random values
55
55
  describe "when using negative values" do
56
56
  it "should work properly for -1" do
57
57
  @post.rate -1, @sally
58
58
  @post.rates.should eql 0
59
- end
59
+ end
60
60
  it "should work properly for -2" do
61
61
  @post.rate -3, @sally
62
62
  @post.rates.should eql -2
63
63
  end
64
64
  end
65
65
  end
66
-
66
+
67
67
  describe "#rated?" do
68
- describe "for Bob" do
68
+ describe "for anyone" do
69
+ specify { @post.rated?().should be_true }
70
+ end
71
+
72
+ describe "for Bob" do
69
73
  specify { @post.rated?(@bob).should be_true }
70
74
  end
71
-
75
+
72
76
  describe "when rated by someone else" do
73
77
  before { @post.rate 1, @alice }
74
-
78
+
75
79
  describe "for Alice" do
76
80
  specify { @post.rated?(@alice).should be_true }
77
81
  end
78
82
  end
79
-
83
+
80
84
  describe "when not rated by someone else" do
81
85
  describe "for Sally" do
82
86
  specify { @post.rated?(@sally).should be_false }
83
87
  end
84
88
  end
85
89
  end
86
-
90
+
87
91
  describe "#unrate" do
88
- before { @post.unrate @bob }
92
+ before { @post.unrate @bob }
89
93
 
90
94
  it "should have null #rate_count" do
91
95
  @post.rate_count.should eql 0
92
96
  end
93
-
97
+
94
98
  it "should have null #rates" do
95
99
  @post.rates.should eql 0
100
+ end
101
+
102
+ it "should be unrated" do
103
+ @post.rated?.should be_false
96
104
  end
97
105
  end
98
-
106
+
99
107
  describe "#rate_count" do
100
108
  it "should know how many rates have been cast" do
101
109
  @post.rate 1, @sally
102
110
  @post.rate_count.should eql 2
103
111
  end
104
112
  end
105
-
113
+
106
114
  describe "#rating" do
107
115
  it "should calculate the average rate" do
108
116
  @post.rate 4, @sally
@@ -115,12 +123,12 @@ describe Post do
115
123
  end
116
124
  end
117
125
  end
118
-
126
+
119
127
  context "when not rated" do
120
128
  describe "#rates" do
121
129
  specify { @post.rates.should eql 0 }
122
130
  end
123
-
131
+
124
132
  describe "#rating" do
125
133
  specify { @post.rating.should be_nil }
126
134
  end
@@ -137,7 +145,7 @@ describe Post do
137
145
  end
138
146
  end
139
147
  end
140
-
148
+
141
149
  context "when saving the collection" do
142
150
  before (:each) do
143
151
  @post.rate 8, @bob
@@ -145,29 +153,29 @@ describe Post do
145
153
  @post.save
146
154
  @finded_post = Post.where(:name => "Announcement").first
147
155
  end
148
-
156
+
149
157
  describe "#rated?" do
150
158
  describe "for Bob" do
151
159
  specify { @finded_post.rated?(@bob).should be_true }
152
160
  end
153
-
161
+
154
162
  describe "for Sally" do
155
163
  specify { @finded_post.rated?(@sally).should be_true }
156
164
  end
157
-
165
+
158
166
  describe "for Alice" do
159
167
  specify { @finded_post.rated?(@alice).should be_false}
160
168
  end
161
169
  end
162
-
170
+
163
171
  describe "#rates" do
164
172
  specify { @finded_post.rates.should eql -2 }
165
173
  end
166
-
174
+
167
175
  describe "#rate_count" do
168
176
  specify { @finded_post.rate_count.should eql 2 }
169
177
  end
170
-
178
+
171
179
  describe "#rating" do
172
180
  specify { @finded_post.rating.should eql -1.0 }
173
181
  end
@@ -220,6 +228,10 @@ describe Post do
220
228
  it "should be not #rated? by Sally" do
221
229
  @finded_post.rated?(@sally).should be_false
222
230
  end
231
+
232
+ it "should be #rated?" do
233
+ @finded_post.rated?.should be_true
234
+ end
223
235
  end
224
236
 
225
237
  it "should have #rates equal 8" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_rateable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-06-20 00:00:00.000000000 +04:00
12
+ date: 2011-06-30 00:00:00.000000000 +04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bson_ext
17
- requirement: &88207860 !ruby/object:Gem::Requirement
17
+ requirement: &77632090 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *88207860
25
+ version_requirements: *77632090
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: mongoid
28
- requirement: &88207610 !ruby/object:Gem::Requirement
28
+ requirement: &77631840 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *88207610
36
+ version_requirements: *77631840
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: bundler
39
- requirement: &88207360 !ruby/object:Gem::Requirement
39
+ requirement: &77631580 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 1.0.0
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *88207360
47
+ version_requirements: *77631580
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: jeweler
50
- requirement: &88207100 !ruby/object:Gem::Requirement
50
+ requirement: &77631320 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: 1.6.2
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *88207100
58
+ version_requirements: *77631320
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: simplecov
61
- requirement: &88206840 !ruby/object:Gem::Requirement
61
+ requirement: &77631060 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: 0.4.0
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *88206840
69
+ version_requirements: *77631060
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rdoc
72
- requirement: &88206580 !ruby/object:Gem::Requirement
72
+ requirement: &77630810 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *88206580
80
+ version_requirements: *77630810
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: rspec
83
- requirement: &88206340 !ruby/object:Gem::Requirement
83
+ requirement: &77630570 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ! '>='
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: 2.0.0
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *88206340
91
+ version_requirements: *77630570
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: database_cleaner
94
- requirement: &88206100 !ruby/object:Gem::Requirement
94
+ requirement: &77630320 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ! '>='
@@ -99,7 +99,7 @@ dependencies:
99
99
  version: '0'
100
100
  type: :development
101
101
  prerelease: false
102
- version_requirements: *88206100
102
+ version_requirements: *77630320
103
103
  description: Provides fields and methods for the manipulation of rates on Mongoid
104
104
  documents.
105
105
  email: psavichev@gmail.com
@@ -143,7 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
143
  version: '0'
144
144
  segments:
145
145
  - 0
146
- hash: -77765551
146
+ hash: 1019547357
147
147
  required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  none: false
149
149
  requirements: