spree_reviews_rating 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -9,7 +9,7 @@ Basic Installation
9
9
 
10
10
  1. Add the following to your Gemfile
11
11
  <pre>
12
- gem 'spree_reviews_rating', '~> 1.0.4'
12
+ gem 'spree_reviews_rating', '~> 1.1.0'
13
13
  </pre>
14
14
  2. Run `bundle install`
15
15
  3. To copy and apply migrations run:
@@ -1,15 +1,14 @@
1
1
  Spree::Product.class_eval do
2
2
  has_many :reviews
3
3
  attr_accessible :avg_rating, :reviews_count
4
-
4
+
5
5
  def get_stars
6
6
  {:star => ((2.0 * self.avg_rating).round / 2.0), :rcount => reviews_count}
7
7
  end
8
8
 
9
9
  def recalculate_rating
10
10
  reviews_count = reviews.reload.approved.where('rating IS NOT NULL').count
11
- avg_rating = (reviews_count > 0) ? (self.reviews.approved.sum(:rating).to_f / reviews_count) : 0
11
+ self.avg_rating = (reviews_count > 0) ? (self.reviews.approved.sum(:rating).to_f / reviews_count) : 0
12
12
  self.update_attributes(:avg_rating => avg_rating, :reviews_count => reviews_count)
13
- end
14
-
13
+ end
15
14
  end
@@ -4,7 +4,7 @@ module Spree
4
4
  belongs_to :user
5
5
 
6
6
  attr_accessible :rating, :review, :name, :product, :user, :product_id, :user_id, :approved
7
-
7
+
8
8
  validates_presence_of :name, :review
9
9
  validates_numericality_of :rating, :if => Proc.new {|r| !r.rating.blank?}
10
10
 
@@ -15,10 +15,8 @@ module Spree
15
15
  end
16
16
 
17
17
  private
18
-
19
18
  def expire_cache_for(review)
20
19
  review.product.recalculate_rating
21
20
  end
22
-
23
21
  end
24
22
  end
@@ -1,3 +1,2 @@
1
1
  require 'spree_core'
2
- require 'formtastic'
3
2
  require 'spree_reviews_rating/engine'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_reviews_rating
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-22 00:00:00.000000000 Z
12
+ date: 2012-07-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: spree_core