solidus_reviews 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +8 -318
  3. data/.rubocop_todo.yml +221 -0
  4. data/CHANGELOG.md +100 -0
  5. data/Gemfile +11 -10
  6. data/README.md +29 -44
  7. data/app/controllers/spree/feedback_reviews_controller.rb +2 -8
  8. data/app/controllers/spree/reviews_controller.rb +1 -1
  9. data/app/decorators/models/solidus_reviews/spree/product_decorator.rb +6 -5
  10. data/app/helpers/spree/reviews_helper.rb +5 -5
  11. data/app/models/spree/feedback_review.rb +1 -1
  12. data/app/models/spree/review.rb +9 -8
  13. data/app/models/spree/reviews_ability.rb +2 -2
  14. data/app/views/spree/api/reviews/_feedback_review.json.jbuilder +1 -1
  15. data/app/views/spree/api/reviews/_review.json.jbuilder +1 -1
  16. data/db/migrate/20120123141326_recalculate_ratings.rb +1 -2
  17. data/db/migrate/20190613165528_add_verified_purchaser_to_reviews.rb +2 -0
  18. data/lib/controllers/spree/api/reviews_controller.rb +16 -14
  19. data/lib/generators/solidus_reviews/install/install_generator.rb +1 -1
  20. data/lib/solidus_reviews.rb +4 -2
  21. data/lib/{spree_reviews → solidus_reviews}/engine.rb +3 -3
  22. data/lib/solidus_reviews/version.rb +5 -0
  23. data/solidus_reviews.gemspec +14 -23
  24. data/spec/controllers/spree/admin/feedback_reviews_controller_spec.rb +1 -1
  25. data/spec/controllers/spree/admin/review_settings_controller_spec.rb +3 -4
  26. data/spec/controllers/spree/admin/reviews_controller_spec.rb +3 -3
  27. data/spec/controllers/spree/api/reviews_controller_spec.rb +27 -25
  28. data/spec/controllers/spree/feedback_reviews_controller_spec.rb +7 -7
  29. data/spec/controllers/spree/products_controller_spec.rb +1 -1
  30. data/spec/controllers/spree/reviews_controller_spec.rb +6 -7
  31. data/spec/features/admin_spec.rb +6 -6
  32. data/spec/features/reviews_spec.rb +32 -31
  33. data/spec/models/feedback_review_spec.rb +13 -13
  34. data/spec/models/product_spec.rb +13 -10
  35. data/spec/models/review_spec.rb +36 -40
  36. data/spec/models/reviews_ability_spec.rb +14 -14
  37. data/spec/models/reviews_configuration_spec.rb +9 -10
  38. data/spec/spec_helper.rb +4 -19
  39. data/spec/support/config.rb +7 -0
  40. data/spec/support/factories.rb +3 -0
  41. metadata +18 -180
  42. data/CONTRIBUTING.md +0 -28
data/CHANGELOG.md ADDED
@@ -0,0 +1,100 @@
1
+ # Changelog
2
+
3
+ ## [v1.3.0](https://github.com/solidusio-contrib/solidus_reviews/tree/v1.3.0) (2019-11-27)
4
+
5
+ [Full Changelog](https://github.com/solidusio-contrib/solidus_reviews/compare/v1.2.0...v1.3.0)
6
+
7
+ **Closed issues:**
8
+
9
+ - sass/rails is deprecated. Please update to `require 'sassc/rails'` [\#48](https://github.com/solidusio-contrib/solidus_reviews/issues/48)
10
+ - Class variable access from toplevel [\#47](https://github.com/solidusio-contrib/solidus_reviews/issues/47)
11
+
12
+ **Merged pull requests:**
13
+
14
+ - Prepare v1.3.0 [\#68](https://github.com/solidusio-contrib/solidus_reviews/pull/68) ([aldesantis](https://github.com/aldesantis))
15
+ - Adopt solidus\_extension\_dev\_tools [\#66](https://github.com/solidusio-contrib/solidus_reviews/pull/66) ([aldesantis](https://github.com/aldesantis))
16
+ - Switch to sassc/rails [\#65](https://github.com/solidusio-contrib/solidus_reviews/pull/65) ([pelargir](https://github.com/pelargir))
17
+ - Fix flaky specs caused by bad preference stubbing [\#54](https://github.com/solidusio-contrib/solidus_reviews/pull/54) ([aldesantis](https://github.com/aldesantis))
18
+
19
+ ## [v1.2.0](https://github.com/solidusio-contrib/solidus_reviews/tree/v1.2.0) (2019-09-17)
20
+
21
+ [Full Changelog](https://github.com/solidusio-contrib/solidus_reviews/compare/v1.1.1...v1.2.0)
22
+
23
+ **Merged pull requests:**
24
+
25
+ - Remove solidus\_auth\_devise as dependency [\#53](https://github.com/solidusio-contrib/solidus_reviews/pull/53) ([kennyadsl](https://github.com/kennyadsl))
26
+ - Adopt CircleCI instead of Travis [\#51](https://github.com/solidusio-contrib/solidus_reviews/pull/51) ([aldesantis](https://github.com/aldesantis))
27
+
28
+ ## [v1.1.1](https://github.com/solidusio-contrib/solidus_reviews/tree/v1.1.1) (2019-08-15)
29
+
30
+ [Full Changelog](https://github.com/solidusio-contrib/solidus_reviews/compare/v1.1.0...v1.1.1)
31
+
32
+ **Closed issues:**
33
+
34
+ - Rubygems release [\#22](https://github.com/solidusio-contrib/solidus_reviews/issues/22)
35
+
36
+ **Merged pull requests:**
37
+
38
+ - Adds missing API features to the index and show endpoints [\#46](https://github.com/solidusio-contrib/solidus_reviews/pull/46) ([ericsaupe](https://github.com/ericsaupe))
39
+
40
+ ## [v1.1.0](https://github.com/solidusio-contrib/solidus_reviews/tree/v1.1.0) (2019-08-14)
41
+
42
+ [Full Changelog](https://github.com/solidusio-contrib/solidus_reviews/compare/v1.0.0...v1.1.0)
43
+
44
+ **Closed issues:**
45
+
46
+ - Support rating only reviews [\#41](https://github.com/solidusio-contrib/solidus_reviews/issues/41)
47
+ - Settings \> Reviews styling is broken [\#35](https://github.com/solidusio-contrib/solidus_reviews/issues/35)
48
+ - Need add key to translate file ru.yml [\#23](https://github.com/solidusio-contrib/solidus_reviews/issues/23)
49
+ - Error in solidus 2.1 due to add\_routes method [\#5](https://github.com/solidusio-contrib/solidus_reviews/issues/5)
50
+
51
+ **Merged pull requests:**
52
+
53
+ - General Typos [\#45](https://github.com/solidusio-contrib/solidus_reviews/pull/45) ([ericsaupe](https://github.com/ericsaupe))
54
+ - Updated API to include new fields [\#44](https://github.com/solidusio-contrib/solidus_reviews/pull/44) ([ericsaupe](https://github.com/ericsaupe))
55
+ - Fix specs [\#43](https://github.com/solidusio-contrib/solidus_reviews/pull/43) ([ericsaupe](https://github.com/ericsaupe))
56
+ - Rating only reviews [\#42](https://github.com/solidusio-contrib/solidus_reviews/pull/42) ([ericsaupe](https://github.com/ericsaupe))
57
+ - Adds verified purchaser [\#40](https://github.com/solidusio-contrib/solidus_reviews/pull/40) ([ericsaupe](https://github.com/ericsaupe))
58
+ - Cleanup [\#39](https://github.com/solidusio-contrib/solidus_reviews/pull/39) ([ericsaupe](https://github.com/ericsaupe))
59
+ - Added Images to Reviews [\#38](https://github.com/solidusio-contrib/solidus_reviews/pull/38) ([ericsaupe](https://github.com/ericsaupe))
60
+ - Add missing admin translation [\#37](https://github.com/solidusio-contrib/solidus_reviews/pull/37) ([jtapia](https://github.com/jtapia))
61
+ - Fix wrong locale id for require login in admin [\#36](https://github.com/solidusio-contrib/solidus_reviews/pull/36) ([kevinnio](https://github.com/kevinnio))
62
+ - Gem maintenance [\#34](https://github.com/solidusio-contrib/solidus_reviews/pull/34) ([spaghetticode](https://github.com/spaghetticode))
63
+ - Remove Solidus v2.3 from Travis config \(EOL\) [\#33](https://github.com/solidusio-contrib/solidus_reviews/pull/33) ([aitbw](https://github.com/aitbw))
64
+ - Add Solidus v2.7 and v2.8 to Travis config [\#32](https://github.com/solidusio-contrib/solidus_reviews/pull/32) ([aitbw](https://github.com/aitbw))
65
+ - Fix deprecation warnings [\#31](https://github.com/solidusio-contrib/solidus_reviews/pull/31) ([aitbw](https://github.com/aitbw))
66
+ - Fix Travis build [\#30](https://github.com/solidusio-contrib/solidus_reviews/pull/30) ([aitbw](https://github.com/aitbw))
67
+ - Fix validation i18n [\#29](https://github.com/solidusio-contrib/solidus_reviews/pull/29) ([mamhoff](https://github.com/mamhoff))
68
+ - Avoid conflicts when same rating HTML is repeated on page [\#28](https://github.com/solidusio-contrib/solidus_reviews/pull/28) ([spaghetticode](https://github.com/spaghetticode))
69
+ - Add missing TH tag [\#27](https://github.com/solidusio-contrib/solidus_reviews/pull/27) ([spaghetticode](https://github.com/spaghetticode))
70
+ - Use default translation key structure for validation message [\#26](https://github.com/solidusio-contrib/solidus_reviews/pull/26) ([aldesantis](https://github.com/aldesantis))
71
+ - Remove redundant rescue\_from from api controller [\#24](https://github.com/solidusio-contrib/solidus_reviews/pull/24) ([dgra](https://github.com/dgra))
72
+ - Improve specs [\#21](https://github.com/solidusio-contrib/solidus_reviews/pull/21) ([kennyadsl](https://github.com/kennyadsl))
73
+ - Refactor spec helper to let specs pass [\#20](https://github.com/solidusio-contrib/solidus_reviews/pull/20) ([kennyadsl](https://github.com/kennyadsl))
74
+ - Fix Trevis CI badge to use master branch status [\#19](https://github.com/solidusio-contrib/solidus_reviews/pull/19) ([kennyadsl](https://github.com/kennyadsl))
75
+ - Fix bundle install issue with solidus\_auth\_devise 2.0 [\#18](https://github.com/solidusio-contrib/solidus_reviews/pull/18) ([kennyadsl](https://github.com/kennyadsl))
76
+ - Fix resetting preferences in specs [\#17](https://github.com/solidusio-contrib/solidus_reviews/pull/17) ([kennyadsl](https://github.com/kennyadsl))
77
+ - Add italian translations [\#16](https://github.com/solidusio-contrib/solidus_reviews/pull/16) ([vassalloandrea](https://github.com/vassalloandrea))
78
+ - Add user email to admin review editing page [\#15](https://github.com/solidusio-contrib/solidus_reviews/pull/15) ([pelargir](https://github.com/pelargir))
79
+ - Api interface [\#14](https://github.com/solidusio-contrib/solidus_reviews/pull/14) ([dgra](https://github.com/dgra))
80
+ - General Solidus 2.3 updates [\#13](https://github.com/solidusio-contrib/solidus_reviews/pull/13) ([dgra](https://github.com/dgra))
81
+ - Prefix named route [\#11](https://github.com/solidusio-contrib/solidus_reviews/pull/11) ([pelargir](https://github.com/pelargir))
82
+ - Add the has\_many association for reviews from a user [\#10](https://github.com/solidusio-contrib/solidus_reviews/pull/10) ([dgra](https://github.com/dgra))
83
+ - Updates to Solidus admin UI [\#9](https://github.com/solidusio-contrib/solidus_reviews/pull/9) ([tvdeyen](https://github.com/tvdeyen))
84
+ - Update for Solidus 2.1 [\#6](https://github.com/solidusio-contrib/solidus_reviews/pull/6) ([kennyadsl](https://github.com/kennyadsl))
85
+
86
+ ## [v1.0.0](https://github.com/solidusio-contrib/solidus_reviews/tree/v1.0.0) (2017-02-03)
87
+
88
+ [Full Changelog](https://github.com/solidusio-contrib/solidus_reviews/compare/8640958dc42f9472cb5cbb85cab981a44f4c45db...v1.0.0)
89
+
90
+ **Merged pull requests:**
91
+
92
+ - Allow solidus\_auth\_devise \< 1.5 [\#8](https://github.com/solidusio-contrib/solidus_reviews/pull/8) ([tvdeyen](https://github.com/tvdeyen))
93
+ - Test against multiple Solidus 1.x versions [\#7](https://github.com/solidusio-contrib/solidus_reviews/pull/7) ([tvdeyen](https://github.com/tvdeyen))
94
+ - Fix install generator [\#3](https://github.com/solidusio-contrib/solidus_reviews/pull/3) ([andrewjwu](https://github.com/andrewjwu))
95
+ - Do not add CRUD product routes to frontend [\#2](https://github.com/solidusio-contrib/solidus_reviews/pull/2) ([mamhoff](https://github.com/mamhoff))
96
+ - Move factories into `lib` [\#1](https://github.com/solidusio-contrib/solidus_reviews/pull/1) ([alexblackie](https://github.com/alexblackie))
97
+
98
+
99
+
100
+ \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
data/Gemfile CHANGED
@@ -6,26 +6,27 @@ branch = ENV.fetch('SOLIDUS_BRANCH', 'master')
6
6
  gem 'solidus', git: 'https://github.com/solidusio/solidus.git', branch: branch
7
7
  gem 'solidus_auth_devise'
8
8
 
9
- # Needed to help Bundler figure out how to resolve dependencies, otherwise it takes forever to
10
- # resolve them
9
+ # Needed to help Bundler figure out how to resolve dependencies,
10
+ # otherwise it takes forever to resolve them
11
11
  if branch == 'master' || Gem::Version.new(branch[1..-1]) >= Gem::Version.new('2.10.0')
12
12
  gem 'rails', '~> 6.0'
13
13
  else
14
14
  gem 'rails', '~> 5.0'
15
15
  end
16
16
 
17
- gem 'puma'
18
- gem 'rails-controller-testing', group: :test
19
-
20
17
  case ENV['DB']
21
18
  when 'mysql'
22
- gem 'mysql2', '~> 0.4.10'
23
- when 'postgres'
24
- gem 'pg', '~> 0.21'
19
+ gem 'mysql2'
20
+ when 'postgresql'
21
+ gem 'pg'
22
+ else
23
+ gem 'sqlite3'
25
24
  end
26
25
 
27
- group :development, :test do
28
- gem 'factory_bot', '> 4.10.0'
26
+ group :test do
27
+ gem 'rails-controller-testing'
29
28
  end
30
29
 
30
+ gem 'solidus_extension_dev_tools', github: 'solidusio-contrib/solidus_extension_dev_tools'
31
+
31
32
  gemspec
data/README.md CHANGED
@@ -1,12 +1,10 @@
1
- # Reviews
1
+ # Solidus Reviews
2
2
 
3
3
  [![CircleCI](https://circleci.com/gh/solidusio-contrib/solidus_reviews.svg?style=svg)](https://circleci.com/gh/solidusio-contrib/solidus_reviews)
4
4
 
5
- Straightforward review/rating functionality, updated for
6
- [Solidus](https://solidus.io). While the Gem name has changed, the module
7
- namespace and commands are still `spree` for now.
5
+ Straightforward review/rating functionality, updated for [Solidus](https://solidus.io).
8
6
 
9
- ---
7
+ While the gem's name has changed, the module namespace and commands are still `spree` for now.
10
8
 
11
9
  ## Installation
12
10
 
@@ -17,75 +15,62 @@ gem 'solidus_reviews', github: 'solidusio-contrib/solidus_reviews'
17
15
  ```
18
16
  Now bundle up with:
19
17
 
20
- bundle
18
+ ```console
19
+ $ bundle
20
+ ```
21
21
 
22
22
  Next, run the rake task that copies the necessary migrations and assets to your project:
23
23
 
24
- rails g solidus_reviews:install
24
+ ```console
25
+ $ rails g solidus_reviews:install
26
+ ```
27
+
25
28
 
26
29
  And finish with a migrate:
27
30
 
28
- rake db:migrate
31
+ ```console
32
+ $ rake db:migrate
33
+ ```
29
34
 
30
35
  Now you should be able to boot up your server with:
31
36
 
32
- rails s
37
+ ```console
38
+ $ rails s
39
+ ```
33
40
 
34
41
  That's all!
35
42
 
36
- ---
37
-
38
43
  ## Usage
39
44
 
40
- Action "submit" in "reviews" controller - goes to review entry form
41
-
42
- Users must be logged in to submit a review
45
+ The `Spree::ReviewsController` controller provides all the CRUD functionality for product reviews.
43
46
 
44
- Three partials:
45
- - `app/views/spree/products/_rating.html.erb` -- display number of stars
46
- - `app/views/spree/products/_shortrating.html.erb` -- shorter version of above
47
- - `app/views/spree/products/_review.html.erb` -- display a single review
47
+ The `Spree::FeedbackReviewsController` allows user to express their feedback on a specific review.
48
+ You can think of these as meta-reviews (e.g. the classic "Was this useful?" modal).
48
49
 
49
- Administrator can edit and/or approve and/or delete reviews.
50
+ You can approve, edit and delete reviews and feedback reviews from the backend.
50
51
 
51
52
  ## Factories
52
53
 
53
- If you want factories for our models available in your application, simply
54
- require our factories in your `spec_helper.rb`:
54
+ If you want factories for our models available in your application, simply require our factories in
55
+ your `spec_helper.rb`:
55
56
 
56
57
  ```ruby
57
- require "solidus_reviews/factories"
58
+ require 'solidus_reviews/factories'
58
59
  ```
59
60
 
60
- ## Implementation
61
-
62
- Reviews table is quite obvious - and note the "approved" flag which is for the
63
- administrator to update.
64
-
65
- Ratings table holds current fractional value - avoids frequent recalc...
66
-
67
- ---
68
-
69
61
  ## Testing
70
62
 
71
- Just run the following to automatically build a dummy app if necessary and
72
- run the tests:
63
+ Just run the following to automatically build a dummy app if necessary and run the tests:
73
64
 
74
65
  ```shell
75
- bundle exec rake
66
+ $ bundle exec rake
76
67
  ```
77
68
 
78
- ---
79
-
80
69
  ## Contributing
81
70
 
82
- See corresponding [contributing guidelines][1].
83
-
84
- ---
71
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/solidusio-contrib/solidus_reviews>.
85
72
 
86
- Copyright (c) 2009-2019 [Solidus][2] and [contributors][3], released under the [New BSD License][4]
73
+ ## License
87
74
 
88
- [1]: ./CONTRIBUTING.md
89
- [2]: https://github.com/solidusio
90
- [3]: https://github.com/solidusio-contrib/solidus_reviews/graphs/contributors
91
- [4]: ./LICENSE.md
75
+ Copyright (c) 2009-2019 [Solidus](https://github.com/solidusio) and [contributors](https://github.com/solidusio-contrib/solidus_reviews/graphs/contributors),
76
+ released under the [New BSD License](https://github.com/solidusio-contrib/solidus_reviews/blob/master/LICENSE.md).
@@ -16,13 +16,7 @@ class Spree::FeedbackReviewsController < Spree::StoreController
16
16
  end
17
17
 
18
18
  respond_to do |format|
19
- format.html {
20
- if SolidusSupport.solidus_gem_version < Gem::Version.new('2.0')
21
- redirect_to(:back)
22
- else
23
- redirect_back(fallback_location: root_path)
24
- end
25
- }
19
+ format.html { redirect_back(fallback_location: root_path) }
26
20
  format.js { render action: :create }
27
21
  end
28
22
  end
@@ -30,7 +24,7 @@ class Spree::FeedbackReviewsController < Spree::StoreController
30
24
  protected
31
25
 
32
26
  def load_review
33
- @review ||= Spree::Review.find_by_id!(params[:review_id])
27
+ @review ||= Spree::Review.find_by!(id: params[:review_id])
34
28
  end
35
29
 
36
30
  def permitted_feedback_review_attributes
@@ -15,7 +15,7 @@ class Spree::ReviewsController < Spree::StoreController
15
15
 
16
16
  # save if all ok
17
17
  def create
18
- params[:review][:rating].sub!(/\s*[^0-9]*\z/, '') unless params[:review][:rating].blank?
18
+ params[:review][:rating].sub!(/\s*[^0-9]*\z/, '') if params[:review][:rating].present?
19
19
 
20
20
  @review = Spree::Review.new(review_params)
21
21
  @review.product = @product
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module SolidusReviews
3
4
  module Spree
4
5
  module ProductDecorator
@@ -16,11 +17,11 @@ module SolidusReviews
16
17
  reviews_count = reviews.reload.default_approval_filter.count
17
18
 
18
19
  self.reviews_count = reviews_count
19
- if reviews_count > 0
20
- self.avg_rating = '%.1f' % (reviews.default_approval_filter.sum(:rating).to_f / reviews_count)
21
- else
22
- self.avg_rating = 0
23
- end
20
+ self.avg_rating = if reviews_count > 0
21
+ '%.1f' % (reviews.default_approval_filter.sum(:rating).to_f / reviews_count)
22
+ else
23
+ 0
24
+ end
24
25
  save
25
26
  end
26
27
 
@@ -18,10 +18,10 @@ module Spree::ReviewsHelper
18
18
  def display_verified_purchaser?(review)
19
19
  Spree::Reviews::Config[:show_verified_purchaser] && review.user &&
20
20
  Spree::LineItem.joins(:order, :variant)
21
- .where.not(spree_orders: { completed_at: nil })
22
- .find_by(
23
- spree_variants: { product_id: review.product_id },
24
- spree_orders: { user_id: review.user_id }
25
- ).present?
21
+ .where.not(spree_orders: { completed_at: nil })
22
+ .find_by(
23
+ spree_variants: { product_id: review.product_id },
24
+ spree_orders: { user_id: review.user_id }
25
+ ).present?
26
26
  end
27
27
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Spree::FeedbackReview < ActiveRecord::Base
3
+ class Spree::FeedbackReview < ApplicationRecord
4
4
  belongs_to :user, class_name: Spree.user_class.to_s, optional: true
5
5
 
6
6
  belongs_to :review, dependent: :destroy
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Spree::Review < ActiveRecord::Base
3
+ class Spree::Review < ApplicationRecord
4
4
  belongs_to :product, touch: true, optional: true
5
5
  belongs_to :user, class_name: Spree.user_class.to_s, optional: true
6
6
  has_many :feedback_reviews
7
7
  has_many :images, -> { order(:position) }, as: :viewable,
8
- dependent: :destroy, class_name: "Spree::Image"
8
+ dependent: :destroy, class_name: "Spree::Image"
9
9
 
10
10
  before_create :verify_purchaser
11
11
  after_save :recalculate_product_rating, if: :approved?
@@ -28,6 +28,7 @@ class Spree::Review < ActiveRecord::Base
28
28
 
29
29
  def feedback_stars
30
30
  return 0 if feedback_reviews.size <= 0
31
+
31
32
  ((feedback_reviews.sum(:rating) / feedback_reviews.size) + 0.5).floor
32
33
  end
33
34
 
@@ -36,18 +37,18 @@ class Spree::Review < ActiveRecord::Base
36
37
  end
37
38
 
38
39
  def email
39
- user.try!(:email)
40
+ user&.email
40
41
  end
41
42
 
42
43
  def verify_purchaser
43
44
  return unless user_id && product_id
44
45
 
45
46
  verified_purchase = Spree::LineItem.joins(:order, :variant)
46
- .where.not(spree_orders: { completed_at: nil })
47
- .find_by(
48
- spree_variants: { product_id: product_id },
49
- spree_orders: { user_id: user_id }
50
- ).present?
47
+ .where.not(spree_orders: { completed_at: nil })
48
+ .find_by(
49
+ spree_variants: { product_id: product_id },
50
+ spree_orders: { user_id: user_id }
51
+ ).present?
51
52
 
52
53
  self.verified_purchaser = verified_purchase
53
54
  end
@@ -7,11 +7,11 @@ class Spree::ReviewsAbility
7
7
  review_ability_class = self.class
8
8
 
9
9
  can :create, Spree::Review do |_review|
10
- review_ability_class.allow_anonymous_reviews? || !user.email.blank?
10
+ review_ability_class.allow_anonymous_reviews? || user.email.present?
11
11
  end
12
12
 
13
13
  can :create, Spree::FeedbackReview do |_review|
14
- review_ability_class.allow_anonymous_reviews? || !user.email.blank?
14
+ review_ability_class.allow_anonymous_reviews? || user.email.present?
15
15
  end
16
16
 
17
17
  # You can read your own reviews, and everyone can read approved ones
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  json.cache! [I18n.locale, feedback_review] do
4
- json.(feedback_review, *feedback_review_attributes)
4
+ json.call(feedback_review, *feedback_review_attributes)
5
5
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  json.cache! [I18n.locale, review] do
4
- json.(review, *review_attributes)
4
+ json.call(review, *review_attributes)
5
5
  json.images(review.images) do |image|
6
6
  json.partial!("spree/api/images/image", image: image)
7
7
  end
@@ -16,6 +16,5 @@ class RecalculateRatings < SolidusSupport::Migration[4.2]
16
16
  end
17
17
  end
18
18
 
19
- def down
20
- end
19
+ def down; end
21
20
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddVerifiedPurchaserToReviews < SolidusSupport::Migration[4.2]
2
4
  def change
3
5
  add_column :spree_reviews, :verified_purchaser, :boolean, default: false
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
4
  module Api
3
5
  class ReviewsController < Spree::Api::BaseController
@@ -9,11 +11,11 @@ module Spree
9
11
  before_action :prevent_multiple_reviews, only: [:create]
10
12
 
11
13
  def index
12
- if @product
13
- @reviews = Spree::Review.default_approval_filter.where(product: @product)
14
- else
15
- @reviews = Spree::Review.where(user: @current_api_user)
16
- end
14
+ @reviews = if @product
15
+ Spree::Review.default_approval_filter.where(product: @product)
16
+ else
17
+ Spree::Review.where(user: @current_api_user)
18
+ end
17
19
 
18
20
  respond_with(@reviews)
19
21
  end
@@ -34,7 +36,7 @@ module Spree
34
36
 
35
37
  authorize! :create, @review
36
38
  if @review.save
37
- render json: @review, include: [:images, :feedback_reviews], status: 201
39
+ render json: @review, include: [:images, :feedback_reviews], status: :created
38
40
  else
39
41
  invalid_resource!(@review)
40
42
  end
@@ -46,7 +48,7 @@ module Spree
46
48
  attributes = review_params.merge(ip_address: request.remote_ip, approved: false)
47
49
 
48
50
  if @review.update(attributes)
49
- render json: @review, include: [:images, :feedback_reviews], status: 200
51
+ render json: @review, include: [:images, :feedback_reviews], status: :ok
50
52
  else
51
53
  invalid_resource!(@review)
52
54
  end
@@ -56,7 +58,7 @@ module Spree
56
58
  authorize! :destroy, @review
57
59
 
58
60
  if @review.destroy
59
- render json: @review, status: 200
61
+ render json: @review, status: :ok
60
62
  else
61
63
  invalid_resource!(@review)
62
64
  end
@@ -74,11 +76,11 @@ module Spree
74
76
 
75
77
  # Loads product from product id.
76
78
  def load_product
77
- if params[:product_id]
78
- @product = Spree::Product.friendly.find(params[:product_id])
79
- else
80
- @product = @review&.product
81
- end
79
+ @product = if params[:product_id]
80
+ Spree::Product.friendly.find(params[:product_id])
81
+ else
82
+ @review&.product
83
+ end
82
84
  end
83
85
 
84
86
  # Finds user based on api_key or by user_id if api_key belongs to an admin.
@@ -104,7 +106,7 @@ module Spree
104
106
  # Converts rating strings like "5 units" to "5"
105
107
  # Operates on params
106
108
  def sanitize_rating
107
- params[:rating].sub!(/\s*[^0-9]*\z/, '') unless params[:rating].blank?
109
+ params[:rating].sub!(/\s*[^0-9]*\z/, '') if params[:rating].present?
108
110
  end
109
111
  end
110
112
  end