mongoid_rateable 0.0.3 → 0.0.4

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.
@@ -1,12 +0,0 @@
1
- module Mongoid
2
- module Rater
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- has_many :rating_marks, as: :rater
7
- end
8
-
9
- module InstanceMethods
10
- end
11
- end
12
- end
@@ -1,98 +0,0 @@
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
-