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,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
feature 'Reviews', js: true do
|
4
6
|
given!(:someone) { create(:user, email: 'ryan@spree.com') }
|
5
7
|
given!(:review) { create(:review, :approved, user: someone) }
|
8
|
+
given!(:unapproved_review) { create(:review, product: review.product) }
|
6
9
|
|
7
10
|
background do
|
8
11
|
Spree::Reviews::Config.include_unapproved_reviews = false
|
@@ -12,13 +15,13 @@ feature 'Reviews', js: true do
|
|
12
15
|
given!(:product_no_reviews) { create(:product) }
|
13
16
|
scenario 'informs that no reviews has been written yet' do
|
14
17
|
visit spree.product_path(product_no_reviews)
|
15
|
-
expect(page).to have_text
|
18
|
+
expect(page).to have_text I18n.t('spree.no_reviews_available')
|
16
19
|
end
|
17
20
|
|
18
21
|
# Regression test for #103
|
19
22
|
context "shows correct number of previews" do
|
20
23
|
background do
|
21
|
-
|
24
|
+
FactoryBot.create_list :review, 3, product: product_no_reviews, approved: true
|
22
25
|
Spree::Reviews::Config[:preview_size] = 2
|
23
26
|
end
|
24
27
|
|
@@ -44,7 +47,7 @@ feature 'Reviews', js: true do
|
|
44
47
|
end
|
45
48
|
|
46
49
|
scenario 'can not create review' do
|
47
|
-
expect(page).not_to have_text
|
50
|
+
expect(page).not_to have_text I18n.t('spree.write_your_own_review')
|
48
51
|
end
|
49
52
|
end
|
50
53
|
end
|
@@ -65,14 +68,27 @@ feature 'Reviews', js: true do
|
|
65
68
|
expect(page).to have_text review.title
|
66
69
|
end
|
67
70
|
|
71
|
+
context 'with unapproved content allowed' do
|
72
|
+
background do
|
73
|
+
Spree::Reviews::Config[:include_unapproved_reviews] = true
|
74
|
+
Spree::Reviews::Config[:display_unapproved_reviews] = true
|
75
|
+
visit spree.product_path(review.product)
|
76
|
+
end
|
77
|
+
|
78
|
+
scenario 'can see unapproved content when allowed' do
|
79
|
+
expect(unapproved_review.approved?).to eq(false)
|
80
|
+
expect(page).to have_text unapproved_review.title
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
68
84
|
scenario 'can see create new review button' do
|
69
|
-
expect(page).to have_text
|
85
|
+
expect(page).to have_text I18n.t('spree.write_your_own_review')
|
70
86
|
end
|
71
87
|
|
72
88
|
scenario 'can create new review' do
|
73
|
-
click_on
|
89
|
+
click_on I18n.t('spree.write_your_own_review')
|
74
90
|
|
75
|
-
expect(page).to have_text
|
91
|
+
expect(page).to have_text I18n.t('spree.leave_us_a_review_for', name: review.product.name)
|
76
92
|
expect(page).not_to have_text 'Show Identifier'
|
77
93
|
|
78
94
|
within '#new_review' do
|
@@ -81,10 +97,11 @@ feature 'Reviews', js: true do
|
|
81
97
|
fill_in 'review_name', with: user.email
|
82
98
|
fill_in 'review_title', with: 'Great product!'
|
83
99
|
fill_in 'review_review', with: 'Some big review text..'
|
100
|
+
attach_file 'review_images', Spree::Core::Engine.root + 'spec/fixtures/thinking-cat.jpg'
|
84
101
|
click_on 'Submit your review'
|
85
102
|
end
|
86
|
-
|
87
|
-
expect(page.find('.flash.notice', text:
|
103
|
+
|
104
|
+
expect(page.find('.flash.notice', text: I18n.t('spree.review_successfully_submitted'))).to be_truthy
|
88
105
|
expect(page).not_to have_text 'Some big review text..'
|
89
106
|
end
|
90
107
|
end
|
@@ -93,16 +110,15 @@ feature 'Reviews', js: true do
|
|
93
110
|
context 'visit product with review where show_identifier is false' do
|
94
111
|
given!(:user) { create(:user) }
|
95
112
|
given!(:review) { create(:review, :approved, :hide_identifier, review: 'review text', user: user) }
|
96
|
-
|
113
|
+
|
97
114
|
background do
|
98
115
|
visit spree.product_path(review.product)
|
99
116
|
end
|
100
117
|
|
101
118
|
scenario 'show anonymous review' do
|
102
|
-
expect(page).to have_text
|
119
|
+
expect(page).to have_text I18n.t('spree.anonymous')
|
103
120
|
expect(page).to have_text 'review text'
|
104
121
|
end
|
105
|
-
|
106
122
|
end
|
107
123
|
|
108
124
|
private
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Spree::ReviewsHelper do
|
@@ -11,7 +13,6 @@ describe Spree::ReviewsHelper do
|
|
11
13
|
specify do
|
12
14
|
matches = mk_stars(2).scan(/unlit/)
|
13
15
|
expect(matches.length).to eq 3
|
14
|
-
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
@@ -25,4 +26,4 @@ describe Spree::ReviewsHelper do
|
|
25
26
|
expect(txt_stars(3, false)).to eq('3')
|
26
27
|
end
|
27
28
|
end
|
28
|
-
end
|
29
|
+
end
|
@@ -1,45 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Spree::FeedbackReview do
|
4
6
|
context 'validations' do
|
5
7
|
it 'validates by default' do
|
6
|
-
build(:feedback_review).
|
8
|
+
expect(build(:feedback_review)).to be_valid
|
7
9
|
end
|
8
10
|
|
9
11
|
it 'validates with a nil user' do
|
10
|
-
build(:feedback_review, user: nil).
|
12
|
+
expect(build(:feedback_review, user: nil)).to be_valid
|
11
13
|
end
|
12
14
|
|
13
15
|
it 'does not validate with a nil review' do
|
14
|
-
build(:feedback_review, review: nil).
|
16
|
+
expect(build(:feedback_review, review: nil)).to_not be_valid
|
15
17
|
end
|
16
18
|
|
17
19
|
context 'rating' do
|
18
20
|
it 'does not validate when no rating is specified' do
|
19
|
-
build(:feedback_review, rating: nil).
|
21
|
+
expect(build(:feedback_review, rating: nil)).to_not be_valid
|
20
22
|
end
|
21
23
|
|
22
24
|
it 'does not validate when the rating is not a number' do
|
23
|
-
build(:feedback_review, rating: 'not_a_number').
|
25
|
+
expect(build(:feedback_review, rating: 'not_a_number')).to_not be_valid
|
24
26
|
end
|
25
27
|
|
26
28
|
it 'does not validate when the rating is a float' do
|
27
|
-
build(:feedback_review, rating: 2.718).
|
29
|
+
expect(build(:feedback_review, rating: 2.718)).to_not be_valid
|
28
30
|
end
|
29
31
|
|
30
32
|
it 'does not validate when the rating is less than 1' do
|
31
|
-
build(:feedback_review, rating: 0).
|
32
|
-
build(:feedback_review, rating: -5).
|
33
|
+
expect(build(:feedback_review, rating: 0)).to_not be_valid
|
34
|
+
expect(build(:feedback_review, rating: -5)).to_not be_valid
|
33
35
|
end
|
34
36
|
|
35
37
|
it 'does not validate when the rating is greater than 5' do
|
36
|
-
build(:feedback_review, rating: 6).
|
37
|
-
build(:feedback_review, rating: 8).
|
38
|
+
expect(build(:feedback_review, rating: 6)).to_not be_valid
|
39
|
+
expect(build(:feedback_review, rating: 8)).to_not be_valid
|
38
40
|
end
|
39
41
|
|
40
42
|
(1..5).each do |i|
|
41
43
|
it "validates when the rating is #{i}" do
|
42
|
-
build(:feedback_review, rating: i).
|
44
|
+
expect(build(:feedback_review, rating: i)).to be_valid
|
43
45
|
end
|
44
46
|
end
|
45
47
|
end
|
@@ -52,11 +54,11 @@ describe Spree::FeedbackReview do
|
|
52
54
|
let!(:feedback_review_3) { create(:feedback_review, created_at: 5.days.ago) }
|
53
55
|
|
54
56
|
it 'properly runs most_recent_first queries' do
|
55
|
-
Spree::FeedbackReview.most_recent_first.to_a.
|
57
|
+
expect(Spree::FeedbackReview.most_recent_first.to_a).to eq([feedback_review_2, feedback_review_3, feedback_review_1])
|
56
58
|
end
|
57
59
|
|
58
60
|
it 'defaults to most_recent_first queries' do
|
59
|
-
Spree::FeedbackReview.all.to_a.
|
61
|
+
expect(Spree::FeedbackReview.all.to_a).to eq([feedback_review_2, feedback_review_3, feedback_review_1])
|
60
62
|
end
|
61
63
|
end
|
62
64
|
|
@@ -69,10 +71,10 @@ describe Spree::FeedbackReview do
|
|
69
71
|
let!(:fr_feedback_review_1) { create(:feedback_review, locale: 'fr', created_at: 10.days.ago) }
|
70
72
|
|
71
73
|
it 'properly runs localized queries' do
|
72
|
-
Spree::FeedbackReview.localized('en').to_a.
|
73
|
-
Spree::FeedbackReview.localized('es').to_a.
|
74
|
-
Spree::FeedbackReview.localized('fr').to_a.
|
74
|
+
expect(Spree::FeedbackReview.localized('en').to_a).to eq([en_feedback_review_2, en_feedback_review_3, en_feedback_review_1])
|
75
|
+
expect(Spree::FeedbackReview.localized('es').to_a).to eq([es_feedback_review_1])
|
76
|
+
expect(Spree::FeedbackReview.localized('fr').to_a).to eq([fr_feedback_review_1])
|
75
77
|
end
|
76
78
|
end
|
77
79
|
end
|
78
|
-
end
|
80
|
+
end
|
data/spec/models/product_spec.rb
CHANGED
@@ -1,24 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Spree::Product do
|
4
|
-
it {
|
5
|
-
it {
|
6
|
-
it {
|
6
|
+
it { is_expected.to respond_to(:avg_rating) }
|
7
|
+
it { is_expected.to respond_to(:reviews) }
|
8
|
+
it { is_expected.to respond_to(:stars) }
|
7
9
|
|
8
10
|
context '#stars' do
|
9
11
|
let(:product) { build(:product) }
|
10
12
|
|
11
13
|
it 'rounds' do
|
12
|
-
product.
|
14
|
+
allow(product).to receive(:avg_rating).and_return(3.7)
|
13
15
|
expect(product.stars).to eq(4)
|
14
16
|
|
15
|
-
product.
|
17
|
+
allow(product).to receive(:avg_rating).and_return(2.3)
|
16
18
|
expect(product.stars).to eq(2)
|
17
19
|
end
|
18
20
|
|
19
|
-
|
20
21
|
it 'handles a nil value' do
|
21
|
-
product.
|
22
|
+
allow(product).to receive(:avg_rating).and_return(nil)
|
23
|
+
|
22
24
|
expect {
|
23
25
|
expect(product.stars).to eq(0)
|
24
26
|
}.not_to raise_error
|
@@ -33,18 +35,39 @@ describe Spree::Product do
|
|
33
35
|
let!(:approved_review_2) { create(:review, product: product, approved: true, rating: 5) }
|
34
36
|
let!(:unapproved_review_1) { create(:review, product: product, approved: false, rating: 4) }
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
38
|
+
context "including unapproved reviews" do
|
39
|
+
before(:all) do
|
40
|
+
Spree::Reviews::Config[:include_unapproved_reviews] = true
|
41
|
+
end
|
42
|
+
after(:all) do
|
43
|
+
Spree::Reviews::Config[:include_unapproved_reviews] = false
|
44
|
+
end
|
40
45
|
|
41
|
-
product
|
42
|
-
|
43
|
-
|
46
|
+
it "updates the product average rating and ignores unapproved reviews" do
|
47
|
+
product.avg_rating = 0
|
48
|
+
product.reviews_count = 0
|
49
|
+
product.save!
|
50
|
+
|
51
|
+
product.recalculate_rating
|
52
|
+
expect(product.avg_rating).to eq(4.3)
|
53
|
+
expect(product.reviews_count).to eq(3)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "only approved reviews" do
|
58
|
+
it "updates the product average rating and ignores unapproved reviews" do
|
59
|
+
product.avg_rating = 0
|
60
|
+
product.reviews_count = 0
|
61
|
+
product.save!
|
62
|
+
|
63
|
+
product.recalculate_rating
|
64
|
+
expect(product.avg_rating).to eq(4.5)
|
65
|
+
expect(product.reviews_count).to eq(2)
|
66
|
+
end
|
44
67
|
end
|
45
68
|
end
|
46
69
|
|
47
|
-
context
|
70
|
+
context "without unapproved reviews" do
|
48
71
|
let!(:unapproved_review_1) { create(:review, product: product, approved: false, rating: 4) }
|
49
72
|
|
50
73
|
it "updates the product average rating and ignores unapproved reviews" do
|
@@ -53,10 +76,9 @@ describe Spree::Product do
|
|
53
76
|
product.save!
|
54
77
|
|
55
78
|
product.recalculate_rating
|
56
|
-
product.avg_rating.
|
57
|
-
product.reviews_count.
|
79
|
+
expect(product.avg_rating).to eq(0)
|
80
|
+
expect(product.reviews_count).to eq(0)
|
58
81
|
end
|
59
82
|
end
|
60
|
-
|
61
83
|
end
|
62
|
-
end
|
84
|
+
end
|
data/spec/models/review_spec.rb
CHANGED
@@ -1,53 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Spree::Review do
|
4
|
-
|
5
6
|
context 'validations' do
|
6
7
|
it 'validates by default' do
|
7
|
-
build(:review).
|
8
|
+
expect(build(:review)).to be_valid
|
8
9
|
end
|
9
10
|
|
10
11
|
it 'validates with a nil user' do
|
11
|
-
build(:review, user: nil).
|
12
|
+
expect(build(:review, user: nil)).to be_valid
|
12
13
|
end
|
13
14
|
|
14
|
-
it '
|
15
|
-
build(:review, review: nil).
|
15
|
+
it 'validates with a nil review' do
|
16
|
+
expect(build(:review, review: nil)).to be_valid
|
16
17
|
end
|
17
18
|
|
18
19
|
context 'rating' do
|
19
20
|
it 'does not validate when no rating is specified' do
|
20
|
-
build(:review, rating: nil).
|
21
|
+
expect(build(:review, rating: nil)).to_not be_valid
|
21
22
|
end
|
22
23
|
|
23
24
|
it 'does not validate when the rating is not a number' do
|
24
|
-
build(:review, rating: 'not_a_number').
|
25
|
+
expect(build(:review, rating: 'not_a_number')).to_not be_valid
|
25
26
|
end
|
26
27
|
|
27
28
|
it 'does not validate when the rating is a float' do
|
28
|
-
build(:review, rating: 2.718).
|
29
|
+
expect(build(:review, rating: 2.718)).to_not be_valid
|
29
30
|
end
|
30
31
|
|
31
32
|
it 'does not validate when the rating is less than 1' do
|
32
|
-
build(:review, rating: 0).
|
33
|
-
build(:review, rating: -5).
|
33
|
+
expect(build(:review, rating: 0)).to_not be_valid
|
34
|
+
expect(build(:review, rating: -5)).to_not be_valid
|
34
35
|
end
|
35
36
|
|
36
37
|
it 'does not validate when the rating is greater than 5' do
|
37
|
-
build(:review, rating: 6).
|
38
|
-
build(:review, rating: 8).
|
38
|
+
expect(build(:review, rating: 6)).to_not be_valid
|
39
|
+
expect(build(:review, rating: 8)).to_not be_valid
|
39
40
|
end
|
40
41
|
|
41
42
|
(1..5).each do |i|
|
42
|
-
it
|
43
|
-
build(:review, rating: i).
|
43
|
+
it 'validates when the rating is #{i}' do
|
44
|
+
expect(build(:review, rating: i)).to be_valid
|
44
45
|
end
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
48
49
|
context 'review body' do
|
49
|
-
it 'should
|
50
|
-
build(:review, review: nil).
|
50
|
+
it 'should be valid without a body' do
|
51
|
+
expect(build(:review, review: nil)).to be_valid
|
51
52
|
end
|
52
53
|
end
|
53
54
|
end
|
@@ -59,11 +60,11 @@ describe Spree::Review do
|
|
59
60
|
let!(:review_3) { create(:review, created_at: 5.days.ago) }
|
60
61
|
|
61
62
|
it 'properly runs most_recent_first queries' do
|
62
|
-
Spree::Review.most_recent_first.to_a.
|
63
|
+
expect(Spree::Review.most_recent_first.to_a).to eq([review_2, review_3, review_1])
|
63
64
|
end
|
64
65
|
|
65
66
|
it 'defaults to most_recent_first queries' do
|
66
|
-
Spree::Review.all.to_a.
|
67
|
+
expect(Spree::Review.all.to_a).to eq([review_2, review_3, review_1])
|
67
68
|
end
|
68
69
|
end
|
69
70
|
|
@@ -75,14 +76,15 @@ describe Spree::Review do
|
|
75
76
|
|
76
77
|
before do
|
77
78
|
reset_spree_preferences
|
79
|
+
Spree::Reviews::Config.preference_store = Spree::Reviews::Config.default_preferences
|
78
80
|
end
|
79
81
|
|
80
82
|
it 'properly runs oldest_first queries' do
|
81
|
-
Spree::Review.oldest_first.to_a.
|
83
|
+
expect(Spree::Review.oldest_first.to_a).to eq([review_1, review_3, review_2, review_4])
|
82
84
|
end
|
83
85
|
|
84
86
|
it 'uses oldest_first for preview' do
|
85
|
-
Spree::Review.preview.to_a.
|
87
|
+
expect(Spree::Review.preview.to_a).to eq([review_1, review_3, review_2])
|
86
88
|
end
|
87
89
|
end
|
88
90
|
|
@@ -95,9 +97,9 @@ describe Spree::Review do
|
|
95
97
|
let!(:fr_review_1) { create(:review, locale: 'fr', created_at: 10.days.ago) }
|
96
98
|
|
97
99
|
it 'properly runs localized queries' do
|
98
|
-
Spree::Review.localized('en').to_a.
|
99
|
-
Spree::Review.localized('es').to_a.
|
100
|
-
Spree::Review.localized('fr').to_a.
|
100
|
+
expect(Spree::Review.localized('en').to_a).to eq([en_review_2, en_review_3, en_review_1])
|
101
|
+
expect(Spree::Review.localized('es').to_a).to eq([es_review_1])
|
102
|
+
expect(Spree::Review.localized('fr').to_a).to eq([fr_review_1])
|
101
103
|
end
|
102
104
|
end
|
103
105
|
|
@@ -110,59 +112,115 @@ describe Spree::Review do
|
|
110
112
|
let!(:unapproved_review_2) { create(:review, approved: false, created_at: 1.days.ago) }
|
111
113
|
|
112
114
|
it 'properly runs approved and unapproved queries' do
|
113
|
-
Spree::Review.approved.to_a.
|
114
|
-
Spree::Review.not_approved.to_a.
|
115
|
+
expect(Spree::Review.approved.to_a).to eq([approved_review_2, approved_review_3, approved_review_1])
|
116
|
+
expect(Spree::Review.not_approved.to_a).to eq([unapproved_review_2, unapproved_review_1])
|
115
117
|
|
116
118
|
Spree::Reviews::Config[:include_unapproved_reviews] = true
|
117
|
-
Spree::Review.default_approval_filter.to_a.
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
119
|
+
expect(Spree::Review.default_approval_filter.to_a).to eq([unapproved_review_2,
|
120
|
+
approved_review_2,
|
121
|
+
approved_review_3,
|
122
|
+
unapproved_review_1,
|
123
|
+
approved_review_1])
|
122
124
|
|
123
125
|
Spree::Reviews::Config[:include_unapproved_reviews] = false
|
124
|
-
Spree::Review.default_approval_filter.to_a.
|
126
|
+
expect(Spree::Review.default_approval_filter.to_a).to eq([approved_review_2, approved_review_3, approved_review_1])
|
125
127
|
end
|
126
128
|
end
|
127
129
|
end
|
128
130
|
|
129
|
-
context
|
131
|
+
context '#recalculate_product_rating' do
|
130
132
|
let(:product) { create(:product) }
|
131
133
|
let!(:review) { create(:review, product: product) }
|
132
134
|
|
133
135
|
before { product.reviews << review }
|
134
136
|
|
135
|
-
it
|
136
|
-
review.
|
137
|
+
it 'if approved' do
|
138
|
+
expect(review).to receive(:recalculate_product_rating)
|
137
139
|
review.approved = true
|
138
140
|
review.save!
|
139
141
|
end
|
140
142
|
|
141
|
-
it
|
142
|
-
review.
|
143
|
+
it 'if not approved' do
|
144
|
+
expect(review).to_not receive(:recalculate_product_rating)
|
143
145
|
review.save!
|
144
146
|
end
|
145
147
|
|
146
|
-
it
|
147
|
-
review.product.
|
148
|
+
it 'updates the product average rating' do
|
149
|
+
expect(review.product).to receive(:recalculate_rating)
|
148
150
|
review.approved = true
|
149
151
|
review.save!
|
150
152
|
end
|
151
153
|
end
|
152
154
|
|
153
|
-
context
|
155
|
+
context '#feedback_stars' do
|
154
156
|
let!(:review) { create(:review) }
|
155
157
|
before do
|
156
158
|
3.times do |i|
|
157
159
|
f = Spree::FeedbackReview.new
|
158
160
|
f.review = review
|
159
|
-
f.rating = (i+1)
|
161
|
+
f.rating = (i + 1)
|
160
162
|
f.save
|
161
163
|
end
|
162
164
|
end
|
163
165
|
|
164
|
-
it
|
165
|
-
review.feedback_stars.
|
166
|
+
it 'should return the average rating from feedback reviews' do
|
167
|
+
expect(review.feedback_stars).to eq 2
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context '#email' do
|
172
|
+
it 'returns email from user' do
|
173
|
+
user = build(:user, email: 'john@smith.com')
|
174
|
+
review = build(:review, user: user)
|
175
|
+
expect(review.email).to eq('john@smith.com')
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context 'images' do
|
180
|
+
it 'supports images' do
|
181
|
+
review = build(:review, images: [build(:image)])
|
182
|
+
expect(review.images).not_to eq(nil)
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'respects order' do
|
186
|
+
image_1 = build(:image, position: 2)
|
187
|
+
image_2 = build(:image, position: 1)
|
188
|
+
review = create(:review, images: [image_1, image_2])
|
189
|
+
review.reload
|
190
|
+
expect(review.images.first).to eq(image_2)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
context "#verify_purchaser" do
|
195
|
+
let(:order) { create(:completed_order_with_totals) }
|
196
|
+
let(:product) { order.products.first }
|
197
|
+
let(:user) { order.user }
|
198
|
+
let(:review) { build(:review, user: user, product: product) }
|
199
|
+
|
200
|
+
it "returns true if the user has purchased the product" do
|
201
|
+
expect(review.verified_purchaser).to eq(false)
|
202
|
+
review.verify_purchaser
|
203
|
+
expect(review.verified_purchaser).to eq(true)
|
204
|
+
end
|
205
|
+
|
206
|
+
it "returns false if the user has not purchased the product" do
|
207
|
+
review.user = create(:user)
|
208
|
+
expect(review.verified_purchaser).to eq(false)
|
209
|
+
review.verify_purchaser
|
210
|
+
expect(review.verified_purchaser).to eq(false)
|
211
|
+
end
|
212
|
+
|
213
|
+
it "returns nothing if there is no user_id or product_id" do
|
214
|
+
review.product_id = nil
|
215
|
+
expect(review.verified_purchaser).to eq(false)
|
216
|
+
review.verify_purchaser
|
217
|
+
expect(review.verified_purchaser).to eq(false)
|
218
|
+
|
219
|
+
review.product_id = product.id
|
220
|
+
review.user_id = nil
|
221
|
+
expect(review.verified_purchaser).to eq(false)
|
222
|
+
review.verify_purchaser
|
223
|
+
expect(review.verified_purchaser).to eq(false)
|
166
224
|
end
|
167
225
|
end
|
168
226
|
end
|