mongoid-letsrate 1.0.13 → 1.0.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 804bab80b25f5fce372efbb580c8548e76d04d01
4
- data.tar.gz: 8aa8578ee5d9d53207d81f79049175b4ff2f02b9
3
+ metadata.gz: 15e0364db64cb2444b376275ef14f1d1c24ac6e2
4
+ data.tar.gz: 240fd5b76501813bd6cde26411bd793e2977ae28
5
5
  SHA512:
6
- metadata.gz: 77ba76f669b3bbc1139fce240a4a5d3fae2f1f6ae7b9cba988c76c01a17297b021cf79929dcfd58c2b8089340c0cf547d4da5031cdcf8e664756667c9cb044c9
7
- data.tar.gz: fcb4d810335911d3806c1ce30ce87db3bc8b659f865bf7b9647e65d89ea793ff19b9b6fc2080c14fb9ddafd4a91581f97f8fafed4f6c464fbdc0539473569d88
6
+ metadata.gz: 0163ff14591f75bf48a72774922a9a0c8489dd5d90b4d3516b57f5c5d67ff69f316196f2a2e30955224ebda9759b667ae604b6e62b19611861091fd328ebe554
7
+ data.tar.gz: 8fde05c198c4a68665881469ece2b84a2b9777cddb8fdc4df93a8e438c1d3e73dca7dfb99fd51b448c7586025dcf1fb555f224526554b2b636e96fc55dd8289a
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  /pkg/*
3
3
  .idea
4
4
  .bundle
5
+ .ruby-version
data/Gemfile CHANGED
@@ -1,8 +1,6 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
3
  gem 'jquery-rails'
4
- gem 'activesupport'
5
- gem 'mongoid', github: 'mongoid/mongoid'
6
4
  gem 'bson'
7
5
 
8
6
  gemspec
data/Gemfile.lock CHANGED
@@ -1,93 +1,92 @@
1
- GIT
2
- remote: git://github.com/mongoid/mongoid.git
3
- revision: c8af8d0836b086cebc4a609037a97747e9f3359b
4
- specs:
5
- mongoid (4.0.0.beta1)
6
- activemodel (>= 4.0.0)
7
- moped (~> 2.0.beta6)
8
- origin (~> 2.1)
9
- tzinfo (>= 0.3.37)
10
-
11
1
  PATH
12
2
  remote: .
13
3
  specs:
14
- mongoid-letsrate (1.0.13)
4
+ mongoid-letsrate (1.0.14)
15
5
 
16
6
  GEM
17
7
  remote: http://rubygems.org/
18
8
  specs:
19
- actionpack (4.0.2)
20
- activesupport (= 4.0.2)
21
- builder (~> 3.1.0)
9
+ actionpack (3.2.17)
10
+ activemodel (= 3.2.17)
11
+ activesupport (= 3.2.17)
12
+ builder (~> 3.0.0)
22
13
  erubis (~> 2.7.0)
23
- rack (~> 1.5.2)
24
- rack-test (~> 0.6.2)
25
- activemodel (4.0.2)
26
- activesupport (= 4.0.2)
27
- builder (~> 3.1.0)
28
- activesupport (4.0.2)
14
+ journey (~> 1.0.4)
15
+ rack (~> 1.4.5)
16
+ rack-cache (~> 1.2)
17
+ rack-test (~> 0.6.1)
18
+ sprockets (~> 2.2.1)
19
+ activemodel (3.2.17)
20
+ activesupport (= 3.2.17)
21
+ builder (~> 3.0.0)
22
+ activesupport (3.2.17)
29
23
  i18n (~> 0.6, >= 0.6.4)
30
- minitest (~> 4.2)
31
- multi_json (~> 1.3)
32
- thread_safe (~> 0.1)
33
- tzinfo (~> 0.3.37)
34
- atomic (1.1.14)
35
- atomic (1.1.14-java)
24
+ multi_json (~> 1.0)
36
25
  bson (2.2.1)
37
- bson (2.2.1-java)
38
- builder (3.1.4)
39
- connection_pool (1.2.0)
26
+ builder (3.0.4)
40
27
  diff-lcs (1.2.5)
41
28
  erubis (2.7.0)
29
+ hike (1.2.3)
42
30
  i18n (0.6.9)
43
- jquery-rails (3.0.4)
31
+ journey (1.0.4)
32
+ jquery-rails (3.1.0)
44
33
  railties (>= 3.0, < 5.0)
45
34
  thor (>= 0.14, < 2.0)
46
- minitest (4.7.5)
47
- mongoid-rspec (1.10.0)
48
- mongoid (>= 3.0.1)
35
+ json (1.8.1)
36
+ mongoid (3.1.6)
37
+ activemodel (~> 3.2)
38
+ moped (~> 1.4)
39
+ origin (~> 1.0)
40
+ tzinfo (~> 0.3.29)
41
+ mongoid-rspec (1.11.0)
42
+ mongoid (~> 3.1.6)
49
43
  rake
50
44
  rspec (>= 2.14)
51
- moped (2.0.0.beta6)
52
- bson (~> 2.2)
53
- connection_pool (~> 1.2)
54
- optionable (~> 0.2.0)
55
- multi_json (1.8.2)
56
- optionable (0.2.0)
57
- origin (2.1.0)
58
- rack (1.5.2)
45
+ moped (1.5.2)
46
+ multi_json (1.9.0)
47
+ origin (1.1.0)
48
+ rack (1.4.5)
49
+ rack-cache (1.2)
50
+ rack (>= 0.4)
51
+ rack-ssl (1.3.3)
52
+ rack
59
53
  rack-test (0.6.2)
60
54
  rack (>= 1.0)
61
- railties (4.0.2)
62
- actionpack (= 4.0.2)
63
- activesupport (= 4.0.2)
55
+ railties (3.2.17)
56
+ actionpack (= 3.2.17)
57
+ activesupport (= 3.2.17)
58
+ rack-ssl (~> 1.3.2)
64
59
  rake (>= 0.8.7)
65
- thor (>= 0.18.1, < 2.0)
60
+ rdoc (~> 3.4)
61
+ thor (>= 0.14.6, < 2.0)
66
62
  rake (10.1.1)
63
+ rdoc (3.12.2)
64
+ json (~> 1.4)
67
65
  rspec (2.14.1)
68
66
  rspec-core (~> 2.14.0)
69
67
  rspec-expectations (~> 2.14.0)
70
68
  rspec-mocks (~> 2.14.0)
71
- rspec-core (2.14.7)
69
+ rspec-core (2.14.8)
72
70
  rspec-expectations (2.14.5)
73
71
  diff-lcs (>= 1.1.3, < 2.0)
74
72
  rspec-mocks (2.14.6)
73
+ sprockets (2.2.2)
74
+ hike (~> 1.2)
75
+ multi_json (~> 1.0)
76
+ rack (~> 1.0)
77
+ tilt (~> 1.1, != 1.3.0)
75
78
  thor (0.18.1)
76
- thread_safe (0.1.3)
77
- atomic
78
- thread_safe (0.1.3-java)
79
- atomic
79
+ tilt (1.4.1)
80
80
  tzinfo (0.3.38)
81
81
 
82
82
  PLATFORMS
83
- java
84
83
  ruby
85
84
 
86
85
  DEPENDENCIES
87
86
  activesupport
88
87
  bson
89
88
  jquery-rails
90
- mongoid!
89
+ mongoid
91
90
  mongoid-letsrate!
92
91
  mongoid-rspec
93
92
  rspec
@@ -17,15 +17,22 @@ module Mongoid
17
17
  end
18
18
  end
19
19
 
20
+ # The average rating
21
+ def rating
22
+ average ? average.avg : 0
23
+ end
24
+
20
25
  def update_rate_average(stars)
21
26
  if average.nil?
22
27
  RatingCache.create! do |avg|
28
+ puts "About to create average"
23
29
  avg.cacheable_id = self.id
24
30
  avg.cacheable_type = self.class.name
25
31
  avg.avg = stars
26
32
  avg.qty = 1
27
33
  end
28
34
  else
35
+ puts "Found average"
29
36
  a = average
30
37
  all_stars = rates.map &:stars
31
38
  a.avg = all_stars.inject { |sum, value| sum + value } / all_stars.size
@@ -1,6 +1,6 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Mongoid
3
3
  module Letsrate
4
- VERSION = '1.0.13'
4
+ VERSION = '1.0.14'
5
5
  end
6
6
  end
@@ -37,7 +37,7 @@ describe Mongoid::Letsrate do
37
37
  end
38
38
  end
39
39
 
40
- describe 'Product gets rated by user' do
40
+ describe 'Product rated by user' do
41
41
  it 'rates should be of type Mongoid::Relations::Targets::Enumerable' do
42
42
  product.rates.class.should eql Mongoid::Relations::Targets::Enumerable
43
43
  end
@@ -56,5 +56,21 @@ describe Mongoid::Letsrate do
56
56
  product.rate 5, second_user
57
57
  product.rates.count.should eql 2
58
58
  end
59
+
60
+ it 'average rating create' do
61
+ rating_cache = product.rate 2, first_user
62
+ rating_cache.should_not be_nil
63
+ end
64
+
65
+ it 'average rating create' do
66
+ rating_cache = product.rate 2, first_user
67
+ rating_cache.avg.should eql 2.0
68
+ end
69
+
70
+ it 'average rating should be 2.5 after rating with 2 and 3 stars' do
71
+ cacheable = product.rate(2, first_user).cacheable
72
+ cacheable.rate 3, second_user
73
+ cacheable.rating.should eql 2.5
74
+ end
59
75
  end
60
76
  end
metadata CHANGED
@@ -1,81 +1,82 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-letsrate
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.13
4
+ version: 1.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Johann
8
8
  - Murat GUZEL
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-05 00:00:00.000000000 Z
12
+ date: 2014-03-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- version_requirements: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - '>='
19
- - !ruby/object:Gem::Version
20
- version: '0'
21
16
  requirement: !ruby/object:Gem::Requirement
22
17
  requirements:
23
- - - '>='
18
+ - - ">="
24
19
  - !ruby/object:Gem::Version
25
20
  version: '0'
26
- prerelease: false
27
21
  type: :development
28
- - !ruby/object:Gem::Dependency
29
- name: mongoid-rspec
22
+ prerelease: false
30
23
  version_requirements: !ruby/object:Gem::Requirement
31
24
  requirements:
32
- - - '>='
25
+ - - ">="
33
26
  - !ruby/object:Gem::Version
34
27
  version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: mongoid-rspec
35
30
  requirement: !ruby/object:Gem::Requirement
36
31
  requirements:
37
- - - '>='
32
+ - - ">="
38
33
  - !ruby/object:Gem::Version
39
34
  version: '0'
40
- prerelease: false
41
35
  type: :development
42
- - !ruby/object:Gem::Dependency
43
- name: mongoid
36
+ prerelease: false
44
37
  version_requirements: !ruby/object:Gem::Requirement
45
38
  requirements:
46
- - - '>='
39
+ - - ">="
47
40
  - !ruby/object:Gem::Version
48
41
  version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: mongoid
49
44
  requirement: !ruby/object:Gem::Requirement
50
45
  requirements:
51
- - - '>='
46
+ - - ">="
52
47
  - !ruby/object:Gem::Version
53
48
  version: '0'
54
- prerelease: false
55
49
  type: :development
56
- - !ruby/object:Gem::Dependency
57
- name: activesupport
50
+ prerelease: false
58
51
  version_requirements: !ruby/object:Gem::Requirement
59
52
  requirements:
60
- - - '>='
53
+ - - ">="
61
54
  - !ruby/object:Gem::Version
62
55
  version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: activesupport
63
58
  requirement: !ruby/object:Gem::Requirement
64
59
  requirements:
65
- - - '>='
60
+ - - ">="
66
61
  - !ruby/object:Gem::Version
67
62
  version: '0'
68
- prerelease: false
69
63
  type: :development
70
- description: Provides the best solution to add rating functionality to your models using mongoid.
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ description: Provides the best solution to add rating functionality to your models
71
+ using mongoid.
71
72
  email:
72
73
  - mjohann@rails-experts.com
73
74
  executables: []
74
75
  extensions: []
75
76
  extra_rdoc_files: []
76
77
  files:
77
- - .gitignore
78
- - .travis.yml
78
+ - ".gitignore"
79
+ - ".travis.yml"
79
80
  - Gemfile
80
81
  - Gemfile.lock
81
82
  - README.md
@@ -104,26 +105,27 @@ files:
104
105
  homepage: http://github.com/malagant/mongoid-letsrate
105
106
  licenses: []
106
107
  metadata: {}
107
- post_install_message:
108
+ post_install_message:
108
109
  rdoc_options: []
109
110
  require_paths:
110
111
  - lib
111
112
  required_ruby_version: !ruby/object:Gem::Requirement
112
113
  requirements:
113
- - - '>='
114
+ - - ">="
114
115
  - !ruby/object:Gem::Version
115
116
  version: '0'
116
117
  required_rubygems_version: !ruby/object:Gem::Requirement
117
118
  requirements:
118
- - - '>='
119
+ - - ">="
119
120
  - !ruby/object:Gem::Version
120
121
  version: '0'
121
122
  requirements: []
122
- rubyforge_project:
123
- rubygems_version: 2.1.9
124
- signing_key:
123
+ rubyforge_project:
124
+ rubygems_version: 2.2.0
125
+ signing_key:
125
126
  specification_version: 4
126
- summary: Provides the best solution to add rating functionality to your models using mongoid.
127
+ summary: Provides the best solution to add rating functionality to your models using
128
+ mongoid.
127
129
  test_files:
128
130
  - spec/letsrate_spec.rb
129
131
  - spec/models/product.rb