solidus_frontend 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of solidus_frontend might be problematic. Click here for more details.

Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -0
  3. data/Gemfile +6 -0
  4. data/Rakefile +15 -0
  5. data/script/rails +9 -0
  6. data/solidus_frontend.gemspec +28 -0
  7. data/spec/controllers/controller_extension_spec.rb +126 -0
  8. data/spec/controllers/controller_helpers_spec.rb +26 -0
  9. data/spec/controllers/spree/checkout_controller_spec.rb +401 -0
  10. data/spec/controllers/spree/checkout_controller_with_views_spec.rb +36 -0
  11. data/spec/controllers/spree/content_controller_spec.rb +7 -0
  12. data/spec/controllers/spree/current_order_tracking_spec.rb +44 -0
  13. data/spec/controllers/spree/home_controller_spec.rb +27 -0
  14. data/spec/controllers/spree/orders_controller_ability_spec.rb +104 -0
  15. data/spec/controllers/spree/orders_controller_spec.rb +134 -0
  16. data/spec/controllers/spree/orders_controller_transitions_spec.rb +31 -0
  17. data/spec/controllers/spree/products_controller_spec.rb +36 -0
  18. data/spec/controllers/spree/taxons_controller_spec.rb +12 -0
  19. data/spec/features/address_spec.rb +76 -0
  20. data/spec/features/automatic_promotion_adjustments_spec.rb +47 -0
  21. data/spec/features/caching/products_spec.rb +55 -0
  22. data/spec/features/caching/taxons_spec.rb +22 -0
  23. data/spec/features/cart_spec.rb +81 -0
  24. data/spec/features/checkout_spec.rb +477 -0
  25. data/spec/features/checkout_unshippable_spec.rb +35 -0
  26. data/spec/features/coupon_code_spec.rb +227 -0
  27. data/spec/features/currency_spec.rb +18 -0
  28. data/spec/features/free_shipping_promotions_spec.rb +59 -0
  29. data/spec/features/locale_spec.rb +60 -0
  30. data/spec/features/order_spec.rb +73 -0
  31. data/spec/features/products_spec.rb +260 -0
  32. data/spec/features/promotion_code_invalidation_spec.rb +51 -0
  33. data/spec/features/quantity_promotions_spec.rb +128 -0
  34. data/spec/features/taxons_spec.rb +135 -0
  35. data/spec/features/template_rendering_spec.rb +19 -0
  36. data/spec/fixtures/thinking-cat.jpg +0 -0
  37. data/spec/helpers/base_helper_spec.rb +11 -0
  38. data/spec/spec_helper.rb +121 -0
  39. data/spec/support/shared_contexts/checkout_setup.rb +9 -0
  40. data/spec/support/shared_contexts/custom_products.rb +25 -0
  41. data/spec/support/shared_contexts/product_prototypes.rb +30 -0
  42. data/spec/views/spree/checkout/_summary_spec.rb +11 -0
  43. metadata +47 -6
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ # This spec is useful for when we just want to make sure a view is rendering correctly
5
+ # Walking through the entire checkout process is rather tedious, don't you think?
6
+ describe Spree::CheckoutController, type: :controller do
7
+ render_views
8
+ let(:token) { 'some_token' }
9
+ let(:user) { stub_model(Spree::LegacyUser) }
10
+
11
+ before do
12
+ allow(controller).to receive_messages try_spree_current_user: user
13
+ end
14
+
15
+ # Regression test for #3246
16
+ context "when using GBP" do
17
+ before do
18
+ Spree::Config[:currency] = "GBP"
19
+ end
20
+
21
+ context "when order is in delivery" do
22
+ before do
23
+ # Using a let block won't acknowledge the currency setting
24
+ # Therefore we just do it like this...
25
+ order = OrderWalkthrough.up_to(:address)
26
+ allow(controller).to receive_messages current_order: order
27
+ end
28
+
29
+ it "displays rate cost in correct currency" do
30
+ spree_get :edit
31
+ html = Nokogiri::HTML(response.body)
32
+ expect(html.css('.rate-cost').text).to eq "£10.00"
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+ describe Spree::ContentController, :type => :controller do
3
+ it "should display CVV page" do
4
+ spree_get :cvv
5
+ expect(response.response_code).to eq(200)
6
+ end
7
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'current order tracking', :type => :controller do
4
+ let(:user) { create(:user) }
5
+
6
+ controller(Spree::StoreController) do
7
+ def index
8
+ render :nothing => true
9
+ end
10
+ end
11
+
12
+ let(:order) { FactoryGirl.create(:order) }
13
+
14
+ it 'automatically tracks who the order was created by & IP address' do
15
+ allow(controller).to receive_messages(:try_spree_current_user => user)
16
+ get :index
17
+ expect(controller.current_order(create_order_if_necessary: true).created_by).to eq controller.try_spree_current_user
18
+ expect(controller.current_order.last_ip_address).to eq "0.0.0.0"
19
+ end
20
+
21
+ context "current order creation" do
22
+ before { allow(controller).to receive_messages(:try_spree_current_user => user) }
23
+
24
+ it "doesn't create a new order out of the blue" do
25
+ expect {
26
+ spree_get :index
27
+ }.not_to change { Spree::Order.count }
28
+ end
29
+ end
30
+ end
31
+
32
+ describe Spree::OrdersController, :type => :controller do
33
+ let(:user) { create(:user) }
34
+
35
+ before { allow(controller).to receive_messages(:try_spree_current_user => user) }
36
+
37
+ describe Spree::OrdersController do
38
+ it "doesn't create a new order out of the blue" do
39
+ expect {
40
+ spree_get :edit
41
+ }.not_to change { Spree::Order.count }
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::HomeController, :type => :controller do
4
+ it "provides current user to the searcher class" do
5
+ user = mock_model(Spree.user_class, :last_incomplete_spree_order => nil, :spree_api_key => 'fake')
6
+ allow(controller).to receive_messages :try_spree_current_user => user
7
+ expect_any_instance_of(Spree::Config.searcher_class).to receive(:current_user=).with(user)
8
+ spree_get :index
9
+ expect(response.status).to eq(200)
10
+ end
11
+
12
+ context "layout" do
13
+ it "renders default layout" do
14
+ spree_get :index
15
+ expect(response).to render_template(layout: 'spree/layouts/spree_application')
16
+ end
17
+
18
+ context "different layout specified in config" do
19
+ before { Spree::Config.layout = 'layouts/application' }
20
+
21
+ it "renders specified layout" do
22
+ spree_get :index
23
+ expect(response).to render_template(layout: 'layouts/application')
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,104 @@
1
+ require 'spec_helper'
2
+
3
+ module Spree
4
+ describe OrdersController, :type => :controller do
5
+ ORDER_TOKEN = 'ORDER_TOKEN'
6
+
7
+ let(:user) { create(:user) }
8
+ let(:guest_user) { create(:user) }
9
+ let(:order) { Spree::Order.create }
10
+
11
+ it 'should understand order routes with token' do
12
+ expect(spree.token_order_path('R123456', 'ABCDEF')).to eq('/orders/R123456/token/ABCDEF')
13
+ end
14
+
15
+ context 'when an order exists in the cookies.signed' do
16
+ let(:token) { 'some_token' }
17
+ let(:specified_order) { create(:order) }
18
+
19
+ before do
20
+ allow(controller).to receive_messages :current_order => order
21
+ allow(controller).to receive_messages :spree_current_user => user
22
+ end
23
+
24
+ context '#populate' do
25
+ it 'should check if user is authorized for :edit' do
26
+ expect(controller).to receive(:authorize!).with(:edit, order, token)
27
+ spree_post :populate, :token => token
28
+ end
29
+ it "should check against the specified order" do
30
+ expect(controller).to receive(:authorize!).with(:edit, specified_order, token)
31
+ spree_post :populate, :id => specified_order.number, :token => token
32
+ end
33
+ end
34
+
35
+ context '#edit' do
36
+ it 'should check if user is authorized for :edit' do
37
+ expect(controller).to receive(:authorize!).with(:edit, order, token)
38
+ spree_get :edit, :token => token
39
+ end
40
+ it "should check against the specified order" do
41
+ expect(controller).to receive(:authorize!).with(:edit, specified_order, token)
42
+ spree_get :edit, :id => specified_order.number, :token => token
43
+ end
44
+ end
45
+
46
+ context '#update' do
47
+ it 'should check if user is authorized for :edit' do
48
+ allow(order).to receive :update_attributes
49
+ expect(controller).to receive(:authorize!).with(:edit, order, token)
50
+ spree_post :update, :order => { :email => "foo@bar.com" }, :token => token
51
+ end
52
+ it "should check against the specified order" do
53
+ allow(order).to receive :update_attributes
54
+ expect(controller).to receive(:authorize!).with(:edit, specified_order, token)
55
+ spree_post :update, :order => { :email => "foo@bar.com" }, :id => specified_order.number, :token => token
56
+ end
57
+ end
58
+
59
+ context '#empty' do
60
+ it 'should check if user is authorized for :edit' do
61
+ expect(controller).to receive(:authorize!).with(:edit, order, token)
62
+ spree_post :empty, :token => token
63
+ end
64
+ it "should check against the specified order" do
65
+ expect(controller).to receive(:authorize!).with(:edit, specified_order, token)
66
+ spree_post :empty, :id => specified_order.number, :token => token
67
+ end
68
+ end
69
+
70
+ context "#show" do
71
+ it "should check against the specified order" do
72
+ expect(controller).to receive(:authorize!).with(:edit, specified_order, token)
73
+ spree_get :show, :id => specified_order.number, :token => token
74
+ end
75
+ end
76
+ end
77
+
78
+ context 'when no authenticated user' do
79
+ let(:order) { create(:order, :number => 'R123') }
80
+
81
+ context '#show' do
82
+ context 'when token parameter present' do
83
+ it 'always ooverride existing token when passing a new one' do
84
+ cookies.signed[:guest_token] = "soo wrong"
85
+ spree_get :show, { :id => 'R123', :token => order.guest_token }
86
+ expect(cookies.signed[:guest_token]).to eq(order.guest_token)
87
+ end
88
+
89
+ it 'should store as guest_token in session' do
90
+ spree_get :show, {:id => 'R123', :token => order.guest_token }
91
+ expect(cookies.signed[:guest_token]).to eq(order.guest_token)
92
+ end
93
+ end
94
+
95
+ context 'when no token present' do
96
+ it 'should respond with 404' do
97
+ spree_get :show, {:id => 'R123'}
98
+ expect(response.code).to eq('404')
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,134 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::OrdersController, :type => :controller do
4
+ let(:user) { create(:user) }
5
+
6
+ context "Order model mock" do
7
+ let(:order) do
8
+ Spree::Order.create!
9
+ end
10
+ let(:variant) { create(:variant) }
11
+
12
+ before do
13
+ allow(controller).to receive_messages(:try_spree_current_user => user)
14
+ end
15
+
16
+ context "#populate" do
17
+ it "should create a new order when none specified" do
18
+ spree_post :populate, {}, {}
19
+ expect(cookies.signed[:guest_token]).not_to be_blank
20
+ expect(Spree::Order.find_by_guest_token(cookies.signed[:guest_token])).to be_persisted
21
+ end
22
+
23
+ context "with Variant" do
24
+ it "should handle population" do
25
+ expect do
26
+ spree_post :populate, variant_id: variant.id, quantity: 5
27
+ end.to change { user.orders.count }.by(1)
28
+ order = user.orders.last
29
+ expect(response).to redirect_to spree.cart_path
30
+ expect(order.line_items.size).to eq(1)
31
+ line_item = order.line_items.first
32
+ expect(line_item.variant_id).to eq(variant.id)
33
+ expect(line_item.quantity).to eq(5)
34
+ end
35
+
36
+ it "shows an error when population fails" do
37
+ request.env["HTTP_REFERER"] = spree.root_path
38
+ allow_any_instance_of(Spree::LineItem).to(
39
+ receive(:valid?).and_return(false)
40
+ )
41
+ allow_any_instance_of(Spree::LineItem).to(
42
+ receive_message_chain(:errors, :full_messages).
43
+ and_return(["Order population failed"])
44
+ )
45
+
46
+ spree_post :populate, variant_id: variant.id, quantity: 5
47
+
48
+ expect(response).to redirect_to(spree.root_path)
49
+ expect(flash[:error]).to eq("Order population failed")
50
+ end
51
+
52
+ it "shows an error when quantity is invalid" do
53
+ request.env["HTTP_REFERER"] = spree.root_path
54
+
55
+ spree_post(
56
+ :populate,
57
+ variant_id: variant.id, quantity: -1
58
+ )
59
+
60
+ expect(response).to redirect_to(spree.root_path)
61
+ expect(flash[:error]).to eq(
62
+ Spree.t(:please_enter_reasonable_quantity)
63
+ )
64
+ end
65
+ end
66
+ end
67
+
68
+ context "#update" do
69
+ context "with authorization" do
70
+ before do
71
+ allow(controller).to receive :check_authorization
72
+ allow(controller).to receive_messages current_order: order
73
+ end
74
+
75
+ it "should render the edit view (on failure)" do
76
+ # email validation is only after address state
77
+ order.update_column(:state, "delivery")
78
+ spree_put :update, { :order => { :email => "" } }, { :order_id => order.id }
79
+ expect(response).to render_template :edit
80
+ end
81
+
82
+ it "should redirect to cart path (on success)" do
83
+ allow(order).to receive(:update_attributes).and_return true
84
+ spree_put :update, {}, {:order_id => 1}
85
+ expect(response).to redirect_to(spree.cart_path)
86
+ end
87
+ end
88
+ end
89
+
90
+ context "#empty" do
91
+ before do
92
+ allow(controller).to receive :check_authorization
93
+ end
94
+
95
+ it "should destroy line items in the current order" do
96
+ allow(controller).to receive(:current_order).and_return(order)
97
+ expect(order).to receive(:empty!)
98
+ spree_put :empty
99
+ expect(response).to redirect_to(spree.cart_path)
100
+ end
101
+ end
102
+
103
+ # Regression test for #2750
104
+ context "#update" do
105
+ before do
106
+ allow(user).to receive :last_incomplete_spree_order
107
+ allow(controller).to receive :set_current_order
108
+ end
109
+
110
+ it "cannot update a blank order" do
111
+ spree_put :update, :order => { :email => "foo" }
112
+ expect(flash[:error]).to eq(Spree.t(:order_not_found))
113
+ expect(response).to redirect_to(spree.root_path)
114
+ end
115
+ end
116
+ end
117
+
118
+ context "line items quantity is 0" do
119
+ let(:order) { Spree::Order.create }
120
+ let(:variant) { create(:variant) }
121
+ let!(:line_item) { order.contents.add(variant, 1) }
122
+
123
+ before do
124
+ allow(controller).to receive(:check_authorization)
125
+ allow(controller).to receive_messages(:current_order => order)
126
+ end
127
+
128
+ it "removes line items on update" do
129
+ expect(order.line_items.count).to eq 1
130
+ spree_put :update, :order => { line_items_attributes: { "0" => { id: line_item.id, quantity: 0 } } }
131
+ expect(order.reload.line_items.count).to eq 0
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ Spree::Order.class_eval do
4
+ attr_accessor :did_transition
5
+ end
6
+
7
+ module Spree
8
+ describe OrdersController, :type => :controller do
9
+ # Regression test for #2004
10
+ context "with a transition callback on first state" do
11
+ let(:order) { Spree::Order.new }
12
+
13
+ before do
14
+ allow(controller).to receive_messages :current_order => order
15
+ expect(controller).to receive(:authorize!).at_least(:once).and_return(true)
16
+
17
+ first_state, _ = Spree::Order.checkout_steps.first
18
+ Spree::Order.state_machine.after_transition :to => first_state do |order|
19
+ order.did_transition = true
20
+ end
21
+ end
22
+
23
+ it "correctly calls the transition callback" do
24
+ expect(order.did_transition).to be_nil
25
+ order.line_items << FactoryGirl.create(:line_item)
26
+ spree_put :update, { :checkout => "checkout" }, { :order_id => 1}
27
+ expect(order.did_transition).to be true
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::ProductsController, :type => :controller do
4
+ let!(:product) { create(:product, :available_on => 1.year.from_now) }
5
+
6
+ # Regression test for #1390
7
+ it "allows admins to view non-active products" do
8
+ allow(controller).to receive_messages :spree_current_user => mock_model(Spree.user_class, :has_spree_role? => true, :last_incomplete_spree_order => nil, :spree_api_key => 'fake')
9
+ spree_get :show, :id => product.to_param
10
+ expect(response.status).to eq(200)
11
+ end
12
+
13
+ it "cannot view non-active products" do
14
+ spree_get :show, :id => product.to_param
15
+ expect(response.status).to eq(404)
16
+ end
17
+
18
+ it "should provide the current user to the searcher class" do
19
+ user = mock_model(Spree.user_class, :last_incomplete_spree_order => nil, :spree_api_key => 'fake')
20
+ allow(controller).to receive_messages :spree_current_user => user
21
+ expect_any_instance_of(Spree::Config.searcher_class).to receive(:current_user=).with(user)
22
+ spree_get :index
23
+ expect(response.status).to eq(200)
24
+ end
25
+
26
+ # Regression test for #2249
27
+ it "doesn't error when given an invalid referer" do
28
+ current_user = mock_model(Spree.user_class, :has_spree_role? => true, :last_incomplete_spree_order => nil, :generate_spree_api_key! => nil)
29
+ allow(controller).to receive_messages :spree_current_user => current_user
30
+ request.env['HTTP_REFERER'] = "not|a$url"
31
+
32
+ # Previously a URI::InvalidURIError exception was being thrown
33
+ expect { spree_get :show, :id => product.to_param }.not_to raise_error
34
+ end
35
+
36
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::TaxonsController, :type => :controller do
4
+ it "should provide the current user to the searcher class" do
5
+ taxon = create(:taxon, :permalink => "test")
6
+ user = mock_model(Spree.user_class, :last_incomplete_spree_order => nil, :spree_api_key => 'fake')
7
+ allow(controller).to receive_messages :spree_current_user => user
8
+ expect_any_instance_of(Spree::Config.searcher_class).to receive(:current_user=).with(user)
9
+ spree_get :show, :id => taxon.permalink
10
+ expect(response.status).to eq(200)
11
+ end
12
+ end
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Address", type: :feature, inaccessible: true do
4
+ let!(:product) { create(:product, :name => "RoR Mug") }
5
+ let!(:order) { create(:order_with_totals, :state => 'cart') }
6
+
7
+ stub_authorization!
8
+
9
+ before do
10
+ visit spree.root_path
11
+
12
+ click_link "RoR Mug"
13
+ click_button "add-to-cart-button"
14
+
15
+ address = "order_bill_address_attributes"
16
+ @country_css = "#{address}_country_id"
17
+ @state_select_css = "##{address}_state_id"
18
+ @state_name_css = "##{address}_state_name"
19
+ end
20
+
21
+ context "country requires state", :js => true, :focus => true do
22
+ let!(:canada) { create(:country, :name => "Canada", :states_required => true, :iso => "CA") }
23
+ let!(:uk) { create(:country, :name => "United Kingdom", :states_required => true, :iso => "UK") }
24
+
25
+ before { Spree::Config[:default_country_id] = uk.id }
26
+
27
+ context "but has no state" do
28
+ it "shows the state input field" do
29
+ click_button "Checkout"
30
+
31
+ select canada.name, :from => @country_css
32
+ expect(page).to have_no_css(@state_select_css)
33
+ expect(page).to have_css("#{@state_name_css}.required")
34
+ end
35
+ end
36
+
37
+ context "and has state" do
38
+ before { create(:state, :name => "Ontario", :country => canada) }
39
+
40
+ it "shows the state collection selection" do
41
+ click_button "Checkout"
42
+
43
+ select canada.name, :from => @country_css
44
+ expect(page).to have_no_css(@state_name_css)
45
+ expect(page).to have_css("#{@state_select_css}.required")
46
+ end
47
+ end
48
+
49
+ context "user changes to country without states required" do
50
+ let!(:france) { create(:country, :name => "France", :states_required => false, :iso => "FRA") }
51
+
52
+ it "clears the state name" do
53
+ click_button "Checkout"
54
+ select canada.name, :from => @country_css
55
+ page.find(@state_name_css).set("Toscana")
56
+
57
+ select france.name, :from => @country_css
58
+
59
+ expect(page).to have_no_css(@state_name_css)
60
+ expect(page).to have_no_css(@state_select_css)
61
+ end
62
+ end
63
+ end
64
+
65
+ context "country does not require state", :js => true do
66
+ let!(:france) { create(:country, :name => "France", :states_required => false, :iso => "FRA") }
67
+
68
+ it "shows a disabled state input field" do
69
+ click_button "Checkout"
70
+
71
+ select france.name, :from => @country_css
72
+ expect(page).to have_no_css(@state_name_css)
73
+ expect(page).to have_css("#{@state_select_css}[disabled]", visible: false)
74
+ end
75
+ end
76
+ end