solidus_reviews 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +322 -0
- data/.travis.yml +27 -14
- data/Gemfile +23 -8
- data/LICENSE.md +2 -2
- data/README.md +9 -11
- data/Rakefile +2 -0
- data/app/controllers/spree/admin/feedback_reviews_controller.rb +3 -1
- data/app/controllers/spree/admin/review_settings_controller.rb +3 -1
- data/app/controllers/spree/admin/reviews_controller.rb +9 -6
- data/app/controllers/spree/feedback_reviews_controller.rb +25 -19
- data/app/controllers/spree/products_controller_decorator.rb +2 -0
- data/app/controllers/spree/reviews_controller.rb +11 -7
- data/app/helpers/spree/api/api_helpers_decorator.rb +12 -0
- data/app/helpers/spree/reviews_helper.rb +15 -5
- data/app/models/spree/feedback_review.rb +5 -4
- data/app/models/spree/product_decorator.rb +5 -4
- data/app/models/spree/review.rb +28 -10
- data/app/models/spree/reviews_ability.rb +17 -3
- data/app/models/spree/reviews_configuration.rb +16 -8
- data/app/models/spree/user_decorator.rb +3 -0
- data/app/overrides/add_reviews_after_product_properties.rb +7 -5
- data/app/overrides/add_reviews_tab_to_admin.rb +12 -4
- data/app/overrides/add_reviews_to_admin_configuration_sidebar.rb +13 -5
- data/app/views/spree/admin/feedback_reviews/index.html.erb +9 -9
- data/app/views/spree/admin/review_settings/edit.html.erb +64 -35
- data/app/views/spree/admin/reviews/_form.html.erb +26 -5
- data/app/views/spree/admin/reviews/edit.html.erb +2 -2
- data/app/views/spree/admin/reviews/index.html.erb +100 -88
- data/app/views/spree/api/reviews/_review.json.jbuilder +8 -0
- data/app/views/spree/api/reviews/index.json.jbuilder +6 -0
- data/app/views/spree/api/reviews/show.json.jbuilder +3 -0
- data/app/views/spree/feedback_reviews/_form.html.erb +5 -5
- data/app/views/spree/feedback_reviews/_summary.html.erb +3 -3
- data/app/views/spree/feedback_reviews/create.js.erb +2 -2
- data/app/views/spree/reviews/_form.html.erb +15 -10
- data/app/views/spree/reviews/new.html.erb +2 -2
- data/app/views/spree/shared/_rating.html.erb +3 -3
- data/app/views/spree/shared/_review.html.erb +29 -19
- data/app/views/spree/shared/_review_summary.html.erb +3 -3
- data/app/views/spree/shared/_reviews.html.erb +6 -6
- data/app/views/spree/shared/_shortrating.html.erb +2 -2
- data/bin/rails +4 -2
- data/config/initializers/constants.rb +2 -0
- data/config/initializers/load_preferences.rb +2 -0
- data/config/locales/de-CH.yml +14 -1
- data/config/locales/de.yml +14 -1
- data/config/locales/en-GB.yml +14 -2
- data/config/locales/en.yml +14 -1
- data/config/locales/es.yml +14 -2
- data/config/locales/fr.yml +14 -2
- data/config/locales/it.yml +79 -0
- data/config/locales/pl.yml +14 -2
- data/config/locales/pt-BR.yml +14 -2
- data/config/locales/pt.yml +14 -2
- data/config/locales/ro.yml +15 -3
- data/config/locales/ru.yml +14 -2
- data/config/locales/sv.yml +14 -1
- data/config/locales/tr.yml +14 -2
- data/config/locales/uk.yml +14 -1
- data/config/locales/zh-CN.yml +14 -1
- data/config/locales/zh-TW.yml +14 -1
- data/config/routes.rb +18 -1
- data/db/migrate/20081020220724_create_reviews.rb +4 -2
- data/db/migrate/20101222083309_create_feedback_reviews.rb +5 -3
- data/db/migrate/20110406083603_add_rating_to_products.rb +7 -5
- data/db/migrate/20110606150524_add_user_to_reviews.rb +4 -2
- data/db/migrate/20110806093221_add_ip_address_to_reviews.rb +3 -1
- data/db/migrate/20120110172331_namespace_tables.rb +3 -1
- data/db/migrate/20120123141326_recalculate_ratings.rb +6 -5
- data/db/migrate/20120712182514_add_locale_to_reviews.rb +4 -2
- data/db/migrate/20120712182627_add_locale_to_feedback_reviews.rb +4 -2
- data/db/migrate/20140703200946_add_show_identifier_to_reviews.rb +3 -1
- data/db/migrate/20190613165528_add_verified_purchaser_to_reviews.rb +5 -0
- data/lib/controllers/spree/api/reviews_controller.rb +111 -0
- data/lib/generators/solidus_reviews/install/install_generator.rb +5 -4
- data/lib/solidus_reviews.rb +3 -1
- data/lib/solidus_reviews/factories.rb +3 -1
- data/lib/solidus_reviews/factories/feedback_review_factory.rb +6 -5
- data/lib/solidus_reviews/factories/review_factory.rb +19 -9
- data/lib/spree_reviews/engine.rb +7 -0
- data/solidus_reviews.gemspec +20 -18
- data/spec/controllers/admin/feedback_reviews_controller_spec.rb +9 -7
- data/spec/controllers/admin/review_settings_controller_spec.rb +18 -16
- data/spec/controllers/admin/reviews_controller_spec.rb +18 -16
- data/spec/controllers/feedback_reviews_controller_spec.rb +29 -25
- data/spec/controllers/products_controller_spec.rb +4 -2
- data/spec/controllers/reviews_controller_spec.rb +67 -40
- data/spec/controllers/spree/api/reviews_controller_spec.rb +233 -0
- data/spec/features/admin_spec.rb +3 -0
- data/spec/features/reviews_spec.rb +27 -11
- data/spec/helpers/review_helper_spec.rb +3 -2
- data/spec/models/feedback_review_spec.rb +19 -17
- data/spec/models/product_spec.rb +41 -19
- data/spec/models/review_spec.rb +100 -42
- data/spec/models/reviews_ability_spec.rb +10 -8
- data/spec/models/reviews_configuration_spec.rb +28 -19
- data/spec/spec_helper.rb +21 -35
- data/vendor/assets/javascripts/jquery.rating.js +389 -376
- metadata +108 -59
@@ -1,8 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SolidusReviews
|
2
4
|
module Generators
|
3
5
|
class InstallGenerator < Rails::Generators::Base
|
4
|
-
|
5
|
-
class_option :auto_run_migrations, :type => :boolean, :default => false
|
6
|
+
class_option :auto_run_migrations, type: :boolean, default: false
|
6
7
|
|
7
8
|
def add_javascripts
|
8
9
|
append_file "vendor/assets/javascripts/spree/frontend/all.js", "//= require spree/frontend/solidus_reviews\n"
|
@@ -10,7 +11,7 @@ module SolidusReviews
|
|
10
11
|
end
|
11
12
|
|
12
13
|
def add_stylesheets
|
13
|
-
inject_into_file "vendor/assets/stylesheets/spree/frontend/all.css", " *= require spree/frontend/solidus_reviews\n", :
|
14
|
+
inject_into_file "vendor/assets/stylesheets/spree/frontend/all.css", " *= require spree/frontend/solidus_reviews\n", before: /\*\//, verbose: true
|
14
15
|
end
|
15
16
|
|
16
17
|
def add_migrations
|
@@ -18,7 +19,7 @@ module SolidusReviews
|
|
18
19
|
end
|
19
20
|
|
20
21
|
def run_migrations
|
21
|
-
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask
|
22
|
+
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))
|
22
23
|
if run_migrations
|
23
24
|
run 'bundle exec rake db:migrate'
|
24
25
|
else
|
data/lib/solidus_reviews.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
FactoryBot.define do
|
4
|
+
factory :feedback_review, class: Spree::FeedbackReview do |_f|
|
3
5
|
user
|
4
6
|
review
|
5
|
-
|
6
|
-
rating { rand(1..5) }
|
7
|
+
rating { rand(1..5) }
|
7
8
|
end
|
8
|
-
end
|
9
|
+
end
|
@@ -1,20 +1,30 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
FactoryBot.define do
|
4
|
+
factory :review, class: Spree::Review do |_f|
|
5
|
+
sequence(:name) { |i| "User #{i}" }
|
6
|
+
title { FFaker::Book.title }
|
7
|
+
review { 'This product is ok!' }
|
6
8
|
rating { rand(1..5) }
|
7
|
-
approved false
|
8
|
-
show_identifier true
|
9
|
+
approved { false }
|
10
|
+
show_identifier { true }
|
9
11
|
user
|
10
12
|
product
|
11
13
|
|
12
14
|
trait :approved do
|
13
|
-
approved true
|
15
|
+
approved { true }
|
14
16
|
end
|
15
17
|
|
16
18
|
trait :hide_identifier do
|
17
|
-
show_identifier false
|
19
|
+
show_identifier { false }
|
20
|
+
end
|
21
|
+
|
22
|
+
trait :with_image do
|
23
|
+
images {
|
24
|
+
[
|
25
|
+
FactoryBot.create(:image)
|
26
|
+
]
|
27
|
+
}
|
18
28
|
end
|
19
29
|
end
|
20
30
|
end
|
data/lib/spree_reviews/engine.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SpreeReviews
|
2
4
|
class Engine < Rails::Engine
|
3
5
|
require 'spree/core'
|
@@ -12,6 +14,11 @@ module SpreeReviews
|
|
12
14
|
end
|
13
15
|
Spree::Ability.register_ability(Spree::ReviewsAbility)
|
14
16
|
end
|
17
|
+
|
18
|
+
if SolidusSupport.api_available?
|
19
|
+
paths["app/controllers"] << "lib/controllers"
|
20
|
+
end
|
21
|
+
|
15
22
|
config.to_prepare &method(:activate).to_proc
|
16
23
|
end
|
17
24
|
end
|
data/solidus_reviews.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
Gem::Specification.new do |s|
|
2
4
|
s.platform = Gem::Platform::RUBY
|
3
5
|
s.name = 'solidus_reviews'
|
4
|
-
s.version = '1.
|
5
|
-
s.summary = 'Basic review and ratings facility for
|
6
|
-
s.authors
|
6
|
+
s.version = '1.1.0'
|
7
|
+
s.summary = 'Basic review and ratings facility for Solidus'
|
8
|
+
s.authors = ['Solidus Contrib']
|
7
9
|
s.description = s.summary
|
8
10
|
s.required_ruby_version = '>= 1.9.3'
|
9
11
|
|
10
|
-
s.
|
11
|
-
s.email = 'paulcc.two@gmail.com'
|
12
|
-
s.homepage = 'https://github.com/solidusio-contrib/solidus-reviews/'
|
12
|
+
s.homepage = 'https://github.com/solidusio-contrib/solidus_reviews/'
|
13
13
|
s.license = 'BSD-3'
|
14
14
|
|
15
15
|
s.files = `git ls-files`.split("\n")
|
@@ -17,19 +17,21 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.require_path = 'lib'
|
18
18
|
s.requirements << 'none'
|
19
19
|
|
20
|
-
s.add_dependency '
|
21
|
-
s.add_dependency '
|
22
|
-
s.add_dependency 'solidus_auth_devise', '
|
20
|
+
s.add_dependency 'deface', '~> 1'
|
21
|
+
s.add_dependency 'solidus', ['>= 1.4', '< 3']
|
22
|
+
s.add_dependency 'solidus_auth_devise', ['>= 1.0', '< 3']
|
23
|
+
s.add_dependency 'solidus_support', '~> 0.1'
|
23
24
|
|
25
|
+
s.add_development_dependency 'capybara'
|
26
|
+
s.add_development_dependency 'capybara-screenshot'
|
27
|
+
s.add_development_dependency 'coffee-rails'
|
28
|
+
s.add_development_dependency 'database_cleaner'
|
24
29
|
s.add_development_dependency 'ffaker'
|
25
|
-
s.add_development_dependency '
|
26
|
-
s.add_development_dependency 'database_cleaner', '1.2.0'
|
27
|
-
s.add_development_dependency 'poltergeist', '~> 1.10.0'
|
28
|
-
s.add_development_dependency 'rspec-rails', '~> 3'
|
29
|
-
s.add_development_dependency 'factory_girl', '~> 4.4'
|
30
|
-
s.add_development_dependency 'sqlite3'
|
31
|
-
s.add_development_dependency 'simplecov', '~> 0.7.1'
|
32
|
-
s.add_development_dependency 'coffee-rails', '~> 4.0.0'
|
33
|
-
s.add_development_dependency 'sass-rails', '~> 5.0'
|
30
|
+
s.add_development_dependency 'poltergeist'
|
34
31
|
s.add_development_dependency 'pry'
|
32
|
+
s.add_development_dependency 'rspec-rails'
|
33
|
+
s.add_development_dependency 'rubocop', '~> 0.53.0'
|
34
|
+
s.add_development_dependency 'sass-rails'
|
35
|
+
s.add_development_dependency 'simplecov'
|
36
|
+
s.add_development_dependency 'sqlite3', '~> 1.3.6'
|
35
37
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Spree::Admin::FeedbackReviewsController do
|
@@ -5,11 +7,11 @@ describe Spree::Admin::FeedbackReviewsController do
|
|
5
7
|
|
6
8
|
before do
|
7
9
|
user = create(:admin_user)
|
8
|
-
controller.
|
10
|
+
allow(controller).to receive(:spree_current_user).and_return(user)
|
9
11
|
end
|
10
12
|
|
11
13
|
context '#index' do
|
12
|
-
let!(:review) { create(:review)}
|
14
|
+
let!(:review) { create(:review) }
|
13
15
|
let!(:other_review) { create(:review) }
|
14
16
|
|
15
17
|
let!(:feedback_review_1) { create(:feedback_review, created_at: 10.days.ago, review: review) }
|
@@ -20,10 +22,10 @@ describe Spree::Admin::FeedbackReviewsController do
|
|
20
22
|
let!(:other_feedback_review_2) { create(:feedback_review, created_at: 2.days.ago, review: other_review) }
|
21
23
|
|
22
24
|
it 'looks up feedback reviews for the specified review and renders the template' do
|
23
|
-
|
24
|
-
response.status.
|
25
|
-
response.
|
26
|
-
assigns(:collection).
|
25
|
+
get :index, params: { review_id: review.id }
|
26
|
+
expect(response.status).to eq(200)
|
27
|
+
expect(response).to render_template(:index)
|
28
|
+
expect(assigns(:collection)).to eq([feedback_review_2, feedback_review_3, feedback_review_1])
|
27
29
|
end
|
28
30
|
end
|
29
|
-
end
|
31
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Spree::Admin::ReviewSettingsController do
|
@@ -5,13 +7,13 @@ describe Spree::Admin::ReviewSettingsController do
|
|
5
7
|
|
6
8
|
before do
|
7
9
|
user = create(:admin_user)
|
8
|
-
controller.
|
10
|
+
allow(controller).to receive(:spree_current_user).and_return(user)
|
9
11
|
end
|
10
12
|
|
11
13
|
context '#update' do
|
12
14
|
it 'redirects to edit-review-settings page' do
|
13
|
-
|
14
|
-
response.
|
15
|
+
put :update, params: { preferences: { preview_size: 4 } }
|
16
|
+
expect(response).to redirect_to spree.edit_admin_review_settings_path
|
15
17
|
end
|
16
18
|
|
17
19
|
context 'For parameters:
|
@@ -22,36 +24,36 @@ describe Spree::Admin::ReviewSettingsController do
|
|
22
24
|
track_locale: true' do
|
23
25
|
|
24
26
|
it 'sets preferred_preview_size to 4' do
|
25
|
-
|
26
|
-
Spree::Reviews::Config.preferred_preview_size.
|
27
|
+
put :update, params: { preferences: { preview_size: 4 } }
|
28
|
+
expect(Spree::Reviews::Config.preferred_preview_size).to eq 4
|
27
29
|
end
|
28
30
|
|
29
31
|
it 'sets preferred_show_email to false' do
|
30
|
-
|
31
|
-
Spree::Reviews::Config.preferred_show_email.
|
32
|
+
put :update, params: { preferences: { show_email: false } }
|
33
|
+
expect(Spree::Reviews::Config.preferred_show_email).to be false
|
32
34
|
end
|
33
35
|
|
34
36
|
it 'sets preferred_feedback_rating to false' do
|
35
|
-
|
36
|
-
Spree::Reviews::Config.preferred_feedback_rating.
|
37
|
+
put :update, params: { preferences: { feedback_rating: false } }
|
38
|
+
expect(Spree::Reviews::Config.preferred_feedback_rating).to be false
|
37
39
|
end
|
38
40
|
|
39
41
|
it 'sets preferred_require_login to true' do
|
40
|
-
|
41
|
-
Spree::Reviews::Config.preferred_require_login.
|
42
|
+
put :update, params: { preferences: { require_login: true } }
|
43
|
+
expect(Spree::Reviews::Config.preferred_require_login).to be true
|
42
44
|
end
|
43
45
|
|
44
46
|
it 'sets preferred_track_locale to true' do
|
45
|
-
|
46
|
-
Spree::Reviews::Config.preferred_track_locale.
|
47
|
+
put :update, params: { preferences: { track_locale: true } }
|
48
|
+
expect(Spree::Reviews::Config.preferred_track_locale).to be true
|
47
49
|
end
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
51
53
|
context '#edit' do
|
52
54
|
it 'should render the edit template' do
|
53
|
-
|
54
|
-
response.
|
55
|
+
get :edit
|
56
|
+
expect(response).to render_template(:edit)
|
55
57
|
end
|
56
58
|
end
|
57
|
-
end
|
59
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Spree::Admin::ReviewsController do
|
@@ -8,7 +10,7 @@ describe Spree::Admin::ReviewsController do
|
|
8
10
|
|
9
11
|
before do
|
10
12
|
user = create(:admin_user)
|
11
|
-
controller.
|
13
|
+
allow(controller).to receive(:spree_current_user).and_return(user)
|
12
14
|
end
|
13
15
|
|
14
16
|
context '#index' do
|
@@ -17,30 +19,30 @@ describe Spree::Admin::ReviewsController do
|
|
17
19
|
create(:review, product: product),
|
18
20
|
create(:review, product: product)
|
19
21
|
]
|
20
|
-
|
21
|
-
assigns[:reviews].
|
22
|
+
get :index, params: { product_id: product.slug }
|
23
|
+
expect(assigns[:reviews]).to match_array reviews
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
25
27
|
context '#approve' do
|
26
28
|
it 'show notice message when approved' do
|
27
29
|
review.update_attribute(:approved, true)
|
28
|
-
|
29
|
-
response.
|
30
|
-
flash[:
|
30
|
+
get :approve, params: { id: review.id }
|
31
|
+
expect(response).to redirect_to spree.admin_reviews_path
|
32
|
+
expect(flash[:success]).to eq I18n.t('spree.info_approve_review')
|
31
33
|
end
|
32
34
|
|
33
35
|
it 'show error message when not approved' do
|
34
|
-
Spree::Review.
|
35
|
-
|
36
|
-
flash[:error].
|
36
|
+
expect_any_instance_of(Spree::Review).to receive(:save).and_return(false)
|
37
|
+
get :approve, params: { id: review.id }
|
38
|
+
expect(flash[:error]).to eq I18n.t('spree.error_approve_review')
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
40
42
|
context '#edit' do
|
41
43
|
specify do
|
42
|
-
|
43
|
-
response.status.
|
44
|
+
get :edit, params: { id: review.id }
|
45
|
+
expect(response.status).to eq(200)
|
44
46
|
end
|
45
47
|
|
46
48
|
context 'when product is nil' do
|
@@ -50,14 +52,14 @@ describe Spree::Admin::ReviewsController do
|
|
50
52
|
end
|
51
53
|
|
52
54
|
it 'flash error' do
|
53
|
-
|
54
|
-
flash[:error].
|
55
|
+
get :edit, params: { id: review.id }
|
56
|
+
expect(flash[:error]).to eq I18n.t('spree.error_no_product')
|
55
57
|
end
|
56
58
|
|
57
59
|
it 'redirect to admin-reviews page' do
|
58
|
-
|
59
|
-
response.
|
60
|
+
get :edit, params: { id: review.id }
|
61
|
+
expect(response).to redirect_to spree.admin_reviews_path
|
60
62
|
end
|
61
63
|
end
|
62
64
|
end
|
63
|
-
end
|
65
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Spree::FeedbackReviewsController do
|
@@ -10,62 +12,64 @@ describe Spree::FeedbackReviewsController do
|
|
10
12
|
feedback_review: {
|
11
13
|
rating: '4 stars',
|
12
14
|
comment: 'some comment'
|
13
|
-
}}
|
15
|
+
} }
|
14
16
|
end
|
15
17
|
|
16
18
|
before do
|
17
|
-
controller.
|
18
|
-
controller.
|
19
|
+
allow(controller).to receive(:spree_current_user).and_return(user)
|
20
|
+
allow(controller).to receive(:spree_user_signed_in?).and_return(true)
|
19
21
|
request.env['HTTP_REFERER'] = '/'
|
20
22
|
end
|
21
23
|
|
22
24
|
describe '#create' do
|
23
25
|
it 'creates a new feedback review' do
|
24
26
|
rating = 4
|
25
|
-
comment =
|
27
|
+
comment = ['Thanks for your review!', 'Cheers'].join("\n")
|
26
28
|
expect {
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
post :create, params: { review_id: review.id,
|
30
|
+
feedback_review: {
|
31
|
+
comment: comment,
|
32
|
+
rating: rating
|
33
|
+
},
|
34
|
+
format: :js }
|
35
|
+
expect(response.status).to eq(200)
|
36
|
+
expect(response).to render_template(:create)
|
33
37
|
}.to change(Spree::Review, :count).by(1)
|
34
38
|
feedback_review = Spree::FeedbackReview.last
|
35
|
-
feedback_review.comment.
|
36
|
-
feedback_review.review.
|
37
|
-
feedback_review.rating.
|
38
|
-
feedback_review.user.
|
39
|
-
|
39
|
+
expect(feedback_review.comment).to eq(comment)
|
40
|
+
expect(feedback_review.review).to eq(review)
|
41
|
+
expect(feedback_review.rating).to eq(rating)
|
42
|
+
expect(feedback_review.user).to eq(user)
|
40
43
|
end
|
41
44
|
|
42
45
|
it 'redirects back to the calling page' do
|
43
|
-
|
44
|
-
response.
|
46
|
+
post :create, params: valid_attributes
|
47
|
+
expect(response).to redirect_to '/'
|
45
48
|
end
|
46
49
|
|
47
50
|
it 'sets locale on feedback-review if required by config' do
|
48
51
|
Spree::Reviews::Config.preferred_track_locale = true
|
49
|
-
|
50
|
-
assigns[:review].locale.
|
52
|
+
post :create, params: valid_attributes
|
53
|
+
expect(assigns[:review].locale).to eq I18n.locale.to_s
|
51
54
|
end
|
52
55
|
|
53
56
|
it 'fails when user is not authorized' do
|
54
|
-
controller.
|
57
|
+
allow(controller).to receive(:authorize!).and_raise(RuntimeError)
|
58
|
+
|
55
59
|
expect {
|
56
|
-
|
60
|
+
post :create, params: valid_attributes
|
57
61
|
}.to raise_error
|
58
62
|
end
|
59
63
|
|
60
64
|
it 'removes all non-numbers from ratings parameter' do
|
61
|
-
|
62
|
-
controller.params[:feedback_review][:rating].
|
65
|
+
post :create, params: valid_attributes
|
66
|
+
expect(controller.params[:feedback_review][:rating]).to eq '4'
|
63
67
|
end
|
64
68
|
|
65
69
|
it 'do not create feedback-review if review doesnt exist' do
|
66
70
|
expect {
|
67
|
-
|
68
|
-
}.to raise_error
|
71
|
+
post :create, params: valid_attributes.merge!({ review_id: nil })
|
72
|
+
}.to raise_error ActionController::UrlGenerationError
|
69
73
|
end
|
70
74
|
end
|
71
75
|
end
|