mongoid_rateable 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -0
- data/Gemfile +8 -1
- data/README.rdoc +57 -6
- data/Rakefile +14 -16
- data/TODO +5 -0
- data/VERSION +1 -1
- data/lib/mongoid_rateable.rb +2 -1
- data/lib/mongoid_rateable/rateable.rb +7 -7
- data/lib/mongoid_rateable/rater.rb +1 -1
- data/lib/mongoid_rateable/rating.rb +2 -1
- data/mongoid_rateable.gemspec +150 -0
- data/spec/models/post.rb +7 -0
- data/spec/models/user.rb +7 -0
- data/spec/mongoid_rateable_spec.rb +98 -0
- data/spec/spec_helper.rb +31 -0
- metadata +317 -14
- data/test/helper.rb +0 -18
- data/test/test_mongoid_rateable.rb +0 -7
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
2
5
|
# Add dependencies required to use your gem here.
|
3
|
-
|
6
|
+
|
7
|
+
gem "mongoid"
|
4
8
|
|
5
9
|
# Add dependencies to develop your gem here.
|
6
10
|
# Include everything needed to run rake, tests, features, etc.
|
@@ -9,4 +13,7 @@ group :development do
|
|
9
13
|
gem "bundler", "~> 1.0.0"
|
10
14
|
gem "jeweler", "~> 1.6.2"
|
11
15
|
gem "rcov", ">= 0"
|
16
|
+
gem "rdoc", ">= 0"
|
17
|
+
gem "rspec", ">= 2.0.0"
|
18
|
+
gem "database_cleaner"
|
12
19
|
end
|
data/README.rdoc
CHANGED
@@ -1,9 +1,61 @@
|
|
1
|
-
=
|
1
|
+
= Mongoid::Rateable
|
2
2
|
|
3
|
-
|
3
|
+
Adding simple rating functionality for Mongoid models
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
Add to Gemfile:
|
8
|
+
|
9
|
+
gem 'mongoid_rateable'
|
10
|
+
|
11
|
+
== Getting Started
|
12
|
+
|
13
|
+
Include the module in models where you want it:
|
14
|
+
|
15
|
+
class Post
|
16
|
+
include Mongoid::Document
|
17
|
+
include Mongoid::Rateable
|
18
|
+
...
|
19
|
+
end
|
20
|
+
|
21
|
+
class User
|
22
|
+
include Mongoid::Document
|
23
|
+
include Mongoid::Rater
|
24
|
+
...
|
25
|
+
end
|
26
|
+
|
27
|
+
== Cast Rates
|
28
|
+
|
29
|
+
You can rate by passing an integer and a rater model to the "rate" method:
|
30
|
+
|
31
|
+
@post = Post.first
|
32
|
+
@user = User.where(:name => 'Bill') # or more likely, current_user
|
33
|
+
|
34
|
+
@post.rate 1, @user # I like this!
|
35
|
+
@post.rate -1, @user # I don't like this!
|
36
|
+
@post.rate 5, @user # I LOVE this!
|
37
|
+
@post.rate -10, @user # Delete it from the Internet!
|
38
|
+
|
39
|
+
You can unrate by using "unrate" method:
|
40
|
+
|
41
|
+
@post.unrate @user
|
42
|
+
|
43
|
+
== Additional Functionality
|
44
|
+
|
45
|
+
You'll often want to know if a user can rate. Simple:
|
46
|
+
|
47
|
+
@post.rated? @user # True if they've rated
|
48
|
+
|
49
|
+
You can also get a tally of the number of votes cast:
|
50
|
+
|
51
|
+
@post.rate_count # Just one so far!
|
52
|
+
|
53
|
+
You can get the average rating:
|
54
|
+
|
55
|
+
@post.rating # rates / raters.count
|
56
|
+
|
57
|
+
== Contributing to Mongoid::Rateable
|
4
58
|
|
5
|
-
== Contributing to mongoid_rateable
|
6
|
-
|
7
59
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
60
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
61
|
* Fork the project
|
@@ -15,5 +67,4 @@ Description goes here.
|
|
15
67
|
== Copyright
|
16
68
|
|
17
69
|
Copyright (c) 2011 Peter Savichev (proton). See LICENSE.txt for
|
18
|
-
further details.
|
19
|
-
|
70
|
+
further details.
|
data/Rakefile
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
|
+
require 'rake'
|
4
5
|
require 'bundler'
|
6
|
+
|
5
7
|
begin
|
6
8
|
Bundler.setup(:default, :development)
|
7
9
|
rescue Bundler::BundlerError => e
|
@@ -9,7 +11,6 @@ rescue Bundler::BundlerError => e
|
|
9
11
|
$stderr.puts "Run `bundle install` to install missing gems"
|
10
12
|
exit e.status_code
|
11
13
|
end
|
12
|
-
require 'rake'
|
13
14
|
|
14
15
|
require 'jeweler'
|
15
16
|
Jeweler::Tasks.new do |gem|
|
@@ -25,29 +26,26 @@ Jeweler::Tasks.new do |gem|
|
|
25
26
|
end
|
26
27
|
Jeweler::RubygemsDotOrgTasks.new
|
27
28
|
|
28
|
-
require '
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
test.verbose = true
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
|
31
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
32
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
33
33
|
end
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
test.verbose = true
|
40
|
-
test.rcov_opts << '--exclude "gems/*"'
|
35
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
36
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
37
|
+
spec.rcov = true
|
38
|
+
spec.rcov_opts = %q[--exclude "spec"]
|
41
39
|
end
|
42
40
|
|
43
|
-
task :default => :
|
41
|
+
task :default => :spec
|
44
42
|
|
45
|
-
require '
|
46
|
-
|
43
|
+
require 'rdoc/task'
|
44
|
+
RDoc::Task.new do |rdoc|
|
47
45
|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
46
|
|
49
47
|
rdoc.rdoc_dir = 'rdoc'
|
50
48
|
rdoc.title = "mongoid_rateable #{version}"
|
51
49
|
rdoc.rdoc_files.include('README*')
|
52
50
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
-
end
|
51
|
+
end
|
data/TODO
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
add method/scope most_voted(count), rated_between(,) to Rateable
|
2
|
+
add min/max rating
|
3
|
+
add methods rate(rateable) and unrate(rateable) to Rater
|
4
|
+
add indexes to fields (http://www.mongodb.org/display/DOCS/Indexes#Indexes-EmbeddedKeys)
|
5
|
+
improve speed (http://cookbook.mongodb.org/patterns/votes/)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/lib/mongoid_rateable.rb
CHANGED
@@ -3,7 +3,7 @@ module Mongoid
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do
|
6
|
-
field :
|
6
|
+
field :rates, :type => Integer, :default => 0
|
7
7
|
embeds_many :rating_marks, as: :rateable
|
8
8
|
end
|
9
9
|
|
@@ -11,32 +11,32 @@ module Mongoid
|
|
11
11
|
|
12
12
|
def rate(mark, rater)
|
13
13
|
unrate(rater)
|
14
|
-
self.
|
15
|
-
self.rating_marks.new(:rater_id => rater.id, :mark => mark)
|
14
|
+
self.rates += mark.to_i
|
15
|
+
self.rating_marks.new(:rater_id => rater.id, :mark => mark, :rater_class => rater.class.to_s)
|
16
16
|
end
|
17
17
|
|
18
18
|
def unrate(rater)
|
19
19
|
mark = self.rating_marks.where(:rater_id => rater.id).first
|
20
20
|
if mark
|
21
|
-
self.
|
21
|
+
self.rates -= mark.mark.to_i
|
22
22
|
mark.delete
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
def rated?(rater)
|
27
|
-
self.rating_marks.where(:rater_id => rater.id).count == 1
|
27
|
+
self.rating_marks.where(:rater_id => rater.id, :rater_class => rater.class.to_s).count == 1
|
28
28
|
end
|
29
29
|
|
30
30
|
def rating
|
31
31
|
if self.rating_marks.blank?
|
32
32
|
nil
|
33
33
|
else
|
34
|
-
self.
|
34
|
+
self.rates.to_f / self.rating_marks.size
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
def rate_count
|
39
|
-
self.rating_marks.
|
39
|
+
self.rating_marks.size
|
40
40
|
end
|
41
41
|
|
42
42
|
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{mongoid_rateable}
|
8
|
+
s.version = "0.0.3"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Peter Savichev (proton)"]
|
12
|
+
s.date = %q{2011-06-17}
|
13
|
+
s.description = %q{Provides fields and methods for the manipulation of rates on Mongoid documents.}
|
14
|
+
s.email = %q{psavichev@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc",
|
18
|
+
"TODO"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".rspec",
|
22
|
+
".rvmrc",
|
23
|
+
"Gemfile",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"TODO",
|
28
|
+
"VERSION",
|
29
|
+
"lib/mongoid_rateable.rb",
|
30
|
+
"lib/mongoid_rateable/rateable.rb",
|
31
|
+
"lib/mongoid_rateable/rater.rb",
|
32
|
+
"lib/mongoid_rateable/rating.rb",
|
33
|
+
"mongoid_rateable.gemspec",
|
34
|
+
"spec/models/post.rb",
|
35
|
+
"spec/models/user.rb",
|
36
|
+
"spec/mongoid_rateable_spec.rb",
|
37
|
+
"spec/spec_helper.rb"
|
38
|
+
]
|
39
|
+
s.homepage = %q{http://github.com/proton/mongoid_rateable}
|
40
|
+
s.licenses = ["MIT"]
|
41
|
+
s.require_paths = ["lib"]
|
42
|
+
s.rubygems_version = %q{1.6.2}
|
43
|
+
s.summary = %q{Rating functionality for Mongoid documents}
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
s.specification_version = 3
|
47
|
+
|
48
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
+
s.add_runtime_dependency(%q<mongoid_rateable>, [">= 0"])
|
50
|
+
s.add_runtime_dependency(%q<mongoid>, [">= 0"])
|
51
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
52
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
53
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
|
54
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
55
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
56
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
57
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
|
58
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
59
|
+
s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
|
60
|
+
s.add_development_dependency(%q<database_cleaner>, [">= 0"])
|
61
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
62
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
63
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
|
64
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
65
|
+
s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
|
66
|
+
s.add_development_dependency(%q<database_cleaner>, [">= 0"])
|
67
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
68
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
69
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
|
70
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
71
|
+
s.add_development_dependency(%q<rdoc>, [">= 0"])
|
72
|
+
s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
|
73
|
+
s.add_development_dependency(%q<database_cleaner>, [">= 0"])
|
74
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
75
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
76
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
|
77
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
78
|
+
s.add_development_dependency(%q<rdoc>, [">= 0"])
|
79
|
+
s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
|
80
|
+
s.add_development_dependency(%q<database_cleaner>, [">= 0"])
|
81
|
+
else
|
82
|
+
s.add_dependency(%q<mongoid_rateable>, [">= 0"])
|
83
|
+
s.add_dependency(%q<mongoid>, [">= 0"])
|
84
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
85
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
86
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
87
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
88
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
89
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
90
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
91
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
92
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
93
|
+
s.add_dependency(%q<database_cleaner>, [">= 0"])
|
94
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
95
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
96
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
97
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
98
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
99
|
+
s.add_dependency(%q<database_cleaner>, [">= 0"])
|
100
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
101
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
102
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
103
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
104
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
105
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
106
|
+
s.add_dependency(%q<database_cleaner>, [">= 0"])
|
107
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
108
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
109
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
110
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
111
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
112
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
113
|
+
s.add_dependency(%q<database_cleaner>, [">= 0"])
|
114
|
+
end
|
115
|
+
else
|
116
|
+
s.add_dependency(%q<mongoid_rateable>, [">= 0"])
|
117
|
+
s.add_dependency(%q<mongoid>, [">= 0"])
|
118
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
119
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
120
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
121
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
122
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
123
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
124
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
125
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
126
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
127
|
+
s.add_dependency(%q<database_cleaner>, [">= 0"])
|
128
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
129
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
130
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
131
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
132
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
133
|
+
s.add_dependency(%q<database_cleaner>, [">= 0"])
|
134
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
135
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
136
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
137
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
138
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
139
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
140
|
+
s.add_dependency(%q<database_cleaner>, [">= 0"])
|
141
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
142
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
143
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
144
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
145
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
146
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
147
|
+
s.add_dependency(%q<database_cleaner>, [">= 0"])
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
data/spec/models/post.rb
ADDED
data/spec/models/user.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Mongoid::Rateable do
|
4
|
+
|
5
|
+
describe ".included" do
|
6
|
+
|
7
|
+
it "adds fields to the rateable document" do
|
8
|
+
fields = Post.fields
|
9
|
+
fields['rates'].should_not == nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it "defines methods in rateable document" do
|
13
|
+
@post = Post.new
|
14
|
+
@post.respond_to?("rate").should == true
|
15
|
+
@post.respond_to?("rated?").should == true
|
16
|
+
@post.respond_to?("rate_count").should == true
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "rate" do
|
22
|
+
|
23
|
+
before(:each) do
|
24
|
+
@bob = User.create :name => "Bob"
|
25
|
+
@alisa = User.create :name => "Alise"
|
26
|
+
@sally = User.create :name => "Sally"
|
27
|
+
@post = Post.create :name => "Announcement"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "tracks rates" do
|
31
|
+
@post.rate 1, @bob
|
32
|
+
@post.rate 1, @sally
|
33
|
+
@post.rates.should == 2
|
34
|
+
end
|
35
|
+
|
36
|
+
it "limits rates by user" do
|
37
|
+
@post.rate 1, @bob
|
38
|
+
@post.rate 5, @bob
|
39
|
+
@post.rates.should == 5
|
40
|
+
end
|
41
|
+
|
42
|
+
it "can be unrated" do
|
43
|
+
@post.rate 1, @bob
|
44
|
+
@post.unrate @bob
|
45
|
+
@post.rate_count.should == 0
|
46
|
+
@post.rates.should == 0
|
47
|
+
end
|
48
|
+
|
49
|
+
it "works with both positive and negative rates" do
|
50
|
+
@post.rate 5, @bob
|
51
|
+
@post.rate -3, @sally
|
52
|
+
@post.rates.should == 2
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should know if someone has rated" do
|
56
|
+
@post.rate 5, @bob
|
57
|
+
@post.rated?(@bob).should == true
|
58
|
+
@post.rated?(@sally).should == false
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should know how many rates have been cast" do
|
62
|
+
@post.rate 5, @bob
|
63
|
+
@post.rate -5, @sally
|
64
|
+
@post.rate_count.should == 2
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should calculate the average rate" do
|
68
|
+
@post.rate 10, @bob
|
69
|
+
@post.rate 5, @sally
|
70
|
+
@post.rating.should == 7.5
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should average if the result is zero" do
|
74
|
+
@post.rate 1, @bob
|
75
|
+
@post.rate -1, @sally
|
76
|
+
@post.rating.should == 0
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should not average if we have no rates" do
|
80
|
+
@post.rating.nil?.should == true
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should properly update the collection" do
|
84
|
+
@post.rate 8, @bob
|
85
|
+
@post.rate -10, @sally
|
86
|
+
@post.save
|
87
|
+
post = Post.where(:name => "Announcement").first
|
88
|
+
post.rates.should == -2
|
89
|
+
post.rated?(@bob).should == true
|
90
|
+
post.rated?(@sally).should == true
|
91
|
+
post.rate_count.should == 2
|
92
|
+
post.rating.should == -1
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
3
|
+
|
4
|
+
MODELS = File.join(File.dirname(__FILE__), "models")
|
5
|
+
|
6
|
+
require "rubygems"
|
7
|
+
require "mongoid"
|
8
|
+
require "mongoid_rateable"
|
9
|
+
require "rspec"
|
10
|
+
require "database_cleaner"
|
11
|
+
|
12
|
+
Dir["#{File.dirname(__FILE__)}/models/*.rb"].each { |f| require f }
|
13
|
+
|
14
|
+
Mongoid.config.master = Mongo::Connection.new.db("mongoid_rateable_test")
|
15
|
+
Mongoid.logger = Logger.new($stdout)
|
16
|
+
|
17
|
+
DatabaseCleaner.orm = "mongoid"
|
18
|
+
|
19
|
+
RSpec.configure do |config|
|
20
|
+
config.before(:all) do
|
21
|
+
DatabaseCleaner.strategy = :truncation
|
22
|
+
end
|
23
|
+
|
24
|
+
config.before(:each) do
|
25
|
+
DatabaseCleaner.start
|
26
|
+
end
|
27
|
+
|
28
|
+
config.after(:each) do
|
29
|
+
DatabaseCleaner.clean
|
30
|
+
end
|
31
|
+
end
|
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.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,9 +12,20 @@ cert_chain: []
|
|
12
12
|
date: 2011-06-17 00:00:00.000000000 +04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: mongoid_rateable
|
17
|
+
requirement: &87198950 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *87198950
|
15
26
|
- !ruby/object:Gem::Dependency
|
16
27
|
name: mongoid
|
17
|
-
requirement: &
|
28
|
+
requirement: &87198690 !ruby/object:Gem::Requirement
|
18
29
|
none: false
|
19
30
|
requirements:
|
20
31
|
- - ! '>='
|
@@ -22,10 +33,263 @@ dependencies:
|
|
22
33
|
version: '0'
|
23
34
|
type: :runtime
|
24
35
|
prerelease: false
|
25
|
-
version_requirements: *
|
36
|
+
version_requirements: *87198690
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: shoulda
|
39
|
+
requirement: &87198450 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *87198450
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: bundler
|
50
|
+
requirement: &87198210 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.0.0
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *87198210
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: jeweler
|
61
|
+
requirement: &87197970 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ~>
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 1.6.2
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *87197970
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rcov
|
72
|
+
requirement: &87197700 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *87197700
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: shoulda
|
83
|
+
requirement: &87197460 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: *87197460
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: bundler
|
94
|
+
requirement: &87197220 !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ~>
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: 1.0.0
|
100
|
+
type: :development
|
101
|
+
prerelease: false
|
102
|
+
version_requirements: *87197220
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: jeweler
|
105
|
+
requirement: &87196970 !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.6.2
|
111
|
+
type: :development
|
112
|
+
prerelease: false
|
113
|
+
version_requirements: *87196970
|
114
|
+
- !ruby/object:Gem::Dependency
|
115
|
+
name: rcov
|
116
|
+
requirement: &87196710 !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ! '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
type: :development
|
123
|
+
prerelease: false
|
124
|
+
version_requirements: *87196710
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rspec
|
127
|
+
requirement: &87196450 !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ! '>='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: 2.0.0
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: *87196450
|
136
|
+
- !ruby/object:Gem::Dependency
|
137
|
+
name: database_cleaner
|
138
|
+
requirement: &87196180 !ruby/object:Gem::Requirement
|
139
|
+
none: false
|
140
|
+
requirements:
|
141
|
+
- - ! '>='
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
type: :development
|
145
|
+
prerelease: false
|
146
|
+
version_requirements: *87196180
|
147
|
+
- !ruby/object:Gem::Dependency
|
148
|
+
name: shoulda
|
149
|
+
requirement: &87195930 !ruby/object:Gem::Requirement
|
150
|
+
none: false
|
151
|
+
requirements:
|
152
|
+
- - ! '>='
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
type: :development
|
156
|
+
prerelease: false
|
157
|
+
version_requirements: *87195930
|
158
|
+
- !ruby/object:Gem::Dependency
|
159
|
+
name: bundler
|
160
|
+
requirement: &87195680 !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ~>
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: 1.0.0
|
166
|
+
type: :development
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: *87195680
|
169
|
+
- !ruby/object:Gem::Dependency
|
170
|
+
name: jeweler
|
171
|
+
requirement: &87195440 !ruby/object:Gem::Requirement
|
172
|
+
none: false
|
173
|
+
requirements:
|
174
|
+
- - ~>
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: 1.6.2
|
177
|
+
type: :development
|
178
|
+
prerelease: false
|
179
|
+
version_requirements: *87195440
|
180
|
+
- !ruby/object:Gem::Dependency
|
181
|
+
name: rcov
|
182
|
+
requirement: &87195190 !ruby/object:Gem::Requirement
|
183
|
+
none: false
|
184
|
+
requirements:
|
185
|
+
- - ! '>='
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: *87195190
|
191
|
+
- !ruby/object:Gem::Dependency
|
192
|
+
name: rspec
|
193
|
+
requirement: &87194950 !ruby/object:Gem::Requirement
|
194
|
+
none: false
|
195
|
+
requirements:
|
196
|
+
- - ! '>='
|
197
|
+
- !ruby/object:Gem::Version
|
198
|
+
version: 2.0.0
|
199
|
+
type: :development
|
200
|
+
prerelease: false
|
201
|
+
version_requirements: *87194950
|
202
|
+
- !ruby/object:Gem::Dependency
|
203
|
+
name: database_cleaner
|
204
|
+
requirement: &87194710 !ruby/object:Gem::Requirement
|
205
|
+
none: false
|
206
|
+
requirements:
|
207
|
+
- - ! '>='
|
208
|
+
- !ruby/object:Gem::Version
|
209
|
+
version: '0'
|
210
|
+
type: :development
|
211
|
+
prerelease: false
|
212
|
+
version_requirements: *87194710
|
213
|
+
- !ruby/object:Gem::Dependency
|
214
|
+
name: shoulda
|
215
|
+
requirement: &87169040 !ruby/object:Gem::Requirement
|
216
|
+
none: false
|
217
|
+
requirements:
|
218
|
+
- - ! '>='
|
219
|
+
- !ruby/object:Gem::Version
|
220
|
+
version: '0'
|
221
|
+
type: :development
|
222
|
+
prerelease: false
|
223
|
+
version_requirements: *87169040
|
224
|
+
- !ruby/object:Gem::Dependency
|
225
|
+
name: bundler
|
226
|
+
requirement: &87168680 !ruby/object:Gem::Requirement
|
227
|
+
none: false
|
228
|
+
requirements:
|
229
|
+
- - ~>
|
230
|
+
- !ruby/object:Gem::Version
|
231
|
+
version: 1.0.0
|
232
|
+
type: :development
|
233
|
+
prerelease: false
|
234
|
+
version_requirements: *87168680
|
235
|
+
- !ruby/object:Gem::Dependency
|
236
|
+
name: jeweler
|
237
|
+
requirement: &87168380 !ruby/object:Gem::Requirement
|
238
|
+
none: false
|
239
|
+
requirements:
|
240
|
+
- - ~>
|
241
|
+
- !ruby/object:Gem::Version
|
242
|
+
version: 1.6.2
|
243
|
+
type: :development
|
244
|
+
prerelease: false
|
245
|
+
version_requirements: *87168380
|
246
|
+
- !ruby/object:Gem::Dependency
|
247
|
+
name: rcov
|
248
|
+
requirement: &87168080 !ruby/object:Gem::Requirement
|
249
|
+
none: false
|
250
|
+
requirements:
|
251
|
+
- - ! '>='
|
252
|
+
- !ruby/object:Gem::Version
|
253
|
+
version: '0'
|
254
|
+
type: :development
|
255
|
+
prerelease: false
|
256
|
+
version_requirements: *87168080
|
257
|
+
- !ruby/object:Gem::Dependency
|
258
|
+
name: rdoc
|
259
|
+
requirement: &87167780 !ruby/object:Gem::Requirement
|
260
|
+
none: false
|
261
|
+
requirements:
|
262
|
+
- - ! '>='
|
263
|
+
- !ruby/object:Gem::Version
|
264
|
+
version: '0'
|
265
|
+
type: :development
|
266
|
+
prerelease: false
|
267
|
+
version_requirements: *87167780
|
268
|
+
- !ruby/object:Gem::Dependency
|
269
|
+
name: rspec
|
270
|
+
requirement: &87167490 !ruby/object:Gem::Requirement
|
271
|
+
none: false
|
272
|
+
requirements:
|
273
|
+
- - ! '>='
|
274
|
+
- !ruby/object:Gem::Version
|
275
|
+
version: 2.0.0
|
276
|
+
type: :development
|
277
|
+
prerelease: false
|
278
|
+
version_requirements: *87167490
|
279
|
+
- !ruby/object:Gem::Dependency
|
280
|
+
name: database_cleaner
|
281
|
+
requirement: &87167200 !ruby/object:Gem::Requirement
|
282
|
+
none: false
|
283
|
+
requirements:
|
284
|
+
- - ! '>='
|
285
|
+
- !ruby/object:Gem::Version
|
286
|
+
version: '0'
|
287
|
+
type: :development
|
288
|
+
prerelease: false
|
289
|
+
version_requirements: *87167200
|
26
290
|
- !ruby/object:Gem::Dependency
|
27
291
|
name: shoulda
|
28
|
-
requirement: &
|
292
|
+
requirement: &87166900 !ruby/object:Gem::Requirement
|
29
293
|
none: false
|
30
294
|
requirements:
|
31
295
|
- - ! '>='
|
@@ -33,10 +297,10 @@ dependencies:
|
|
33
297
|
version: '0'
|
34
298
|
type: :development
|
35
299
|
prerelease: false
|
36
|
-
version_requirements: *
|
300
|
+
version_requirements: *87166900
|
37
301
|
- !ruby/object:Gem::Dependency
|
38
302
|
name: bundler
|
39
|
-
requirement: &
|
303
|
+
requirement: &87166610 !ruby/object:Gem::Requirement
|
40
304
|
none: false
|
41
305
|
requirements:
|
42
306
|
- - ~>
|
@@ -44,10 +308,10 @@ dependencies:
|
|
44
308
|
version: 1.0.0
|
45
309
|
type: :development
|
46
310
|
prerelease: false
|
47
|
-
version_requirements: *
|
311
|
+
version_requirements: *87166610
|
48
312
|
- !ruby/object:Gem::Dependency
|
49
313
|
name: jeweler
|
50
|
-
requirement: &
|
314
|
+
requirement: &87166310 !ruby/object:Gem::Requirement
|
51
315
|
none: false
|
52
316
|
requirements:
|
53
317
|
- - ~>
|
@@ -55,10 +319,43 @@ dependencies:
|
|
55
319
|
version: 1.6.2
|
56
320
|
type: :development
|
57
321
|
prerelease: false
|
58
|
-
version_requirements: *
|
322
|
+
version_requirements: *87166310
|
59
323
|
- !ruby/object:Gem::Dependency
|
60
324
|
name: rcov
|
61
|
-
requirement: &
|
325
|
+
requirement: &87166010 !ruby/object:Gem::Requirement
|
326
|
+
none: false
|
327
|
+
requirements:
|
328
|
+
- - ! '>='
|
329
|
+
- !ruby/object:Gem::Version
|
330
|
+
version: '0'
|
331
|
+
type: :development
|
332
|
+
prerelease: false
|
333
|
+
version_requirements: *87166010
|
334
|
+
- !ruby/object:Gem::Dependency
|
335
|
+
name: rdoc
|
336
|
+
requirement: &87165690 !ruby/object:Gem::Requirement
|
337
|
+
none: false
|
338
|
+
requirements:
|
339
|
+
- - ! '>='
|
340
|
+
- !ruby/object:Gem::Version
|
341
|
+
version: '0'
|
342
|
+
type: :development
|
343
|
+
prerelease: false
|
344
|
+
version_requirements: *87165690
|
345
|
+
- !ruby/object:Gem::Dependency
|
346
|
+
name: rspec
|
347
|
+
requirement: &87165420 !ruby/object:Gem::Requirement
|
348
|
+
none: false
|
349
|
+
requirements:
|
350
|
+
- - ! '>='
|
351
|
+
- !ruby/object:Gem::Version
|
352
|
+
version: 2.0.0
|
353
|
+
type: :development
|
354
|
+
prerelease: false
|
355
|
+
version_requirements: *87165420
|
356
|
+
- !ruby/object:Gem::Dependency
|
357
|
+
name: database_cleaner
|
358
|
+
requirement: &87165080 !ruby/object:Gem::Requirement
|
62
359
|
none: false
|
63
360
|
requirements:
|
64
361
|
- - ! '>='
|
@@ -66,7 +363,7 @@ dependencies:
|
|
66
363
|
version: '0'
|
67
364
|
type: :development
|
68
365
|
prerelease: false
|
69
|
-
version_requirements: *
|
366
|
+
version_requirements: *87165080
|
70
367
|
description: Provides fields and methods for the manipulation of rates on Mongoid
|
71
368
|
documents.
|
72
369
|
email: psavichev@gmail.com
|
@@ -75,19 +372,25 @@ extensions: []
|
|
75
372
|
extra_rdoc_files:
|
76
373
|
- LICENSE.txt
|
77
374
|
- README.rdoc
|
375
|
+
- TODO
|
78
376
|
files:
|
377
|
+
- .rspec
|
79
378
|
- .rvmrc
|
80
379
|
- Gemfile
|
81
380
|
- LICENSE.txt
|
82
381
|
- README.rdoc
|
83
382
|
- Rakefile
|
383
|
+
- TODO
|
84
384
|
- VERSION
|
85
385
|
- lib/mongoid_rateable.rb
|
86
386
|
- lib/mongoid_rateable/rateable.rb
|
87
387
|
- lib/mongoid_rateable/rater.rb
|
88
388
|
- lib/mongoid_rateable/rating.rb
|
89
|
-
-
|
90
|
-
-
|
389
|
+
- mongoid_rateable.gemspec
|
390
|
+
- spec/models/post.rb
|
391
|
+
- spec/models/user.rb
|
392
|
+
- spec/mongoid_rateable_spec.rb
|
393
|
+
- spec/spec_helper.rb
|
91
394
|
has_rdoc: true
|
92
395
|
homepage: http://github.com/proton/mongoid_rateable
|
93
396
|
licenses:
|
@@ -104,7 +407,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
104
407
|
version: '0'
|
105
408
|
segments:
|
106
409
|
- 0
|
107
|
-
hash:
|
410
|
+
hash: 800869569
|
108
411
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
412
|
none: false
|
110
413
|
requirements:
|
data/test/helper.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
begin
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
10
|
-
require 'test/unit'
|
11
|
-
require 'shoulda'
|
12
|
-
|
13
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
-
require 'mongoid_rateable'
|
16
|
-
|
17
|
-
class Test::Unit::TestCase
|
18
|
-
end
|