solidus_frontend 2.6.5 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of solidus_frontend might be problematic. Click here for more details.
- checksums.yaml +4 -4
 - data/README.md +7 -5
 - data/app/assets/images/favicon.ico +0 -0
 - data/app/assets/javascripts/spree/frontend/checkout/coupon-code.js +2 -1
 - data/app/assets/stylesheets/spree/frontend/screen.css.scss +39 -1
 - data/app/controllers/spree/checkout_controller.rb +61 -3
 - data/app/controllers/spree/coupon_codes_controller.rb +35 -0
 - data/app/controllers/spree/locale_controller.rb +1 -1
 - data/app/controllers/spree/orders_controller.rb +27 -12
 - data/app/controllers/spree/store_controller.rb +0 -18
 - data/app/controllers/spree/taxons_controller.rb +6 -3
 - data/app/views/spree/checkout/_coupon_code.html.erb +12 -0
 - data/app/views/spree/checkout/_delivery.html.erb +6 -2
 - data/app/views/spree/checkout/_payment.html.erb +0 -10
 - data/app/views/spree/checkout/_summary.html.erb +4 -0
 - data/app/views/spree/checkout/payment/_gateway.html.erb +6 -5
 - data/app/views/spree/coupon_codes/new.html.erb +6 -0
 - data/app/views/spree/orders/_form.html.erb +1 -1
 - data/app/views/spree/orders/_line_item.html.erb +3 -5
 - data/app/views/spree/orders/edit.html.erb +5 -6
 - data/app/views/spree/products/_image.html.erb +4 -1
 - data/app/views/spree/products/_thumbnails.html.erb +10 -8
 - data/app/views/spree/shared/_image.html.erb +4 -4
 - data/app/views/spree/shared/_locale_selector.html.erb +1 -1
 - data/app/views/spree/shared/_order_details.html.erb +3 -5
 - data/app/views/spree/shared/_products.html.erb +1 -1
 - data/config/routes.rb +1 -0
 - data/lib/spree/frontend.rb +1 -1
 - data/solidus_frontend.gemspec +1 -1
 - data/spec/controllers/spree/checkout_controller_spec.rb +109 -9
 - data/spec/controllers/spree/checkout_controller_with_views_spec.rb +1 -1
 - data/spec/controllers/spree/home_controller_spec.rb +1 -1
 - data/spec/controllers/spree/orders_controller_ability_spec.rb +11 -30
 - data/spec/controllers/spree/orders_controller_spec.rb +54 -3
 - data/spec/controllers/spree/products_controller_spec.rb +3 -3
 - data/spec/controllers/spree/taxons_controller_spec.rb +1 -1
 - data/spec/features/address_spec.rb +1 -1
 - data/spec/features/automatic_promotion_adjustments_spec.rb +2 -2
 - data/spec/features/caching/taxons_spec.rb +1 -1
 - data/spec/features/checkout_confirm_insufficient_stock_spec.rb +71 -0
 - data/spec/features/checkout_spec.rb +34 -25
 - data/spec/features/coupon_code_spec.rb +96 -56
 - data/spec/features/currency_spec.rb +1 -1
 - data/spec/features/first_order_promotion_spec.rb +59 -0
 - data/spec/features/free_shipping_promotions_spec.rb +2 -2
 - data/spec/features/products_spec.rb +8 -8
 - data/spec/features/promotion_code_invalidation_spec.rb +2 -2
 - data/spec/features/quantity_promotions_spec.rb +9 -9
 - data/spec/spec_helper.rb +1 -1
 - metadata +14 -9
 - data/spec/support/features/fill_in_with_force.rb +0 -12
 
| 
         @@ -7,8 +7,6 @@ module Spree 
     | 
|
| 
       7 
7 
     | 
    
         
             
                ORDER_TOKEN = 'ORDER_TOKEN'
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
                let!(:store) { create(:store) }
         
     | 
| 
       10 
     | 
    
         
            -
                let(:user) { create(:user) }
         
     | 
| 
       11 
     | 
    
         
            -
                let(:guest_user) { create(:user) }
         
     | 
| 
       12 
10 
     | 
    
         
             
                let(:order) { Spree::Order.create }
         
     | 
| 
       13 
11 
     | 
    
         
             
                let(:variant) { create(:variant) }
         
     | 
| 
       14 
12 
     | 
    
         | 
| 
         @@ -18,62 +16,45 @@ module Spree 
     | 
|
| 
       18 
16 
     | 
    
         | 
| 
       19 
17 
     | 
    
         
             
                context 'when an order exists in the cookies.signed' do
         
     | 
| 
       20 
18 
     | 
    
         
             
                  let(:token) { 'some_token' }
         
     | 
| 
       21 
     | 
    
         
            -
                  let(:specified_order) { create(:order) }
         
     | 
| 
       22 
19 
     | 
    
         | 
| 
       23 
20 
     | 
    
         
             
                  before do
         
     | 
| 
       24 
21 
     | 
    
         
             
                    allow(controller).to receive_messages current_order: order
         
     | 
| 
       25 
     | 
    
         
            -
                    allow(controller).to receive_messages spree_current_user: user
         
     | 
| 
       26 
22 
     | 
    
         
             
                  end
         
     | 
| 
       27 
23 
     | 
    
         | 
| 
       28 
24 
     | 
    
         
             
                  context '#populate' do
         
     | 
| 
       29 
     | 
    
         
            -
                    it 'should check if user is authorized for : 
     | 
| 
       30 
     | 
    
         
            -
                      expect(controller).to receive(:authorize!).with(: 
     | 
| 
      
 25 
     | 
    
         
            +
                    it 'should check if user is authorized for :update' do
         
     | 
| 
      
 26 
     | 
    
         
            +
                      expect(controller).to receive(:authorize!).with(:update, order, token)
         
     | 
| 
       31 
27 
     | 
    
         
             
                      post :populate, params: { variant_id: variant.id, token: token }
         
     | 
| 
       32 
28 
     | 
    
         
             
                    end
         
     | 
| 
       33 
     | 
    
         
            -
                    it "should check against the specified order" do
         
     | 
| 
       34 
     | 
    
         
            -
                      expect(controller).to receive(:authorize!).with(:edit, specified_order, token)
         
     | 
| 
       35 
     | 
    
         
            -
                      post :populate, params: { id: specified_order.number, variant_id: variant.id, token: token }
         
     | 
| 
       36 
     | 
    
         
            -
                    end
         
     | 
| 
       37 
29 
     | 
    
         
             
                  end
         
     | 
| 
       38 
30 
     | 
    
         | 
| 
       39 
31 
     | 
    
         
             
                  context '#edit' do
         
     | 
| 
       40 
     | 
    
         
            -
                    it 'should check if user is authorized for : 
     | 
| 
       41 
     | 
    
         
            -
                      expect(controller).to receive(:authorize!).with(: 
     | 
| 
      
 32 
     | 
    
         
            +
                    it 'should check if user is authorized for :read' do
         
     | 
| 
      
 33 
     | 
    
         
            +
                      expect(controller).to receive(:authorize!).with(:read, order, token)
         
     | 
| 
       42 
34 
     | 
    
         
             
                      get :edit, params: { token: token }
         
     | 
| 
       43 
35 
     | 
    
         
             
                    end
         
     | 
| 
       44 
     | 
    
         
            -
                    it "should check against the specified order" do
         
     | 
| 
       45 
     | 
    
         
            -
                      expect(controller).to receive(:authorize!).with(:edit, specified_order, token)
         
     | 
| 
       46 
     | 
    
         
            -
                      get :edit, params: { id: specified_order.number, token: token }
         
     | 
| 
       47 
     | 
    
         
            -
                    end
         
     | 
| 
       48 
36 
     | 
    
         
             
                  end
         
     | 
| 
       49 
37 
     | 
    
         | 
| 
       50 
38 
     | 
    
         
             
                  context '#update' do
         
     | 
| 
       51 
     | 
    
         
            -
                    it 'should check if user is authorized for : 
     | 
| 
      
 39 
     | 
    
         
            +
                    it 'should check if user is authorized for :update' do
         
     | 
| 
       52 
40 
     | 
    
         
             
                      allow(order).to receive :update_attributes
         
     | 
| 
       53 
     | 
    
         
            -
                      expect(controller).to receive(:authorize!).with(: 
     | 
| 
      
 41 
     | 
    
         
            +
                      expect(controller).to receive(:authorize!).with(:update, order, token)
         
     | 
| 
       54 
42 
     | 
    
         
             
                      post :update, params: { order: { email: "foo@bar.com" }, token: token }
         
     | 
| 
       55 
43 
     | 
    
         
             
                    end
         
     | 
| 
       56 
     | 
    
         
            -
                    it "should check against the specified order" do
         
     | 
| 
       57 
     | 
    
         
            -
                      allow(order).to receive :update_attributes
         
     | 
| 
       58 
     | 
    
         
            -
                      expect(controller).to receive(:authorize!).with(:edit, specified_order, token)
         
     | 
| 
       59 
     | 
    
         
            -
                      post :update, params: { order: { email: "foo@bar.com" }, id: specified_order.number, token: token }
         
     | 
| 
       60 
     | 
    
         
            -
                    end
         
     | 
| 
       61 
44 
     | 
    
         
             
                  end
         
     | 
| 
       62 
45 
     | 
    
         | 
| 
       63 
46 
     | 
    
         
             
                  context '#empty' do
         
     | 
| 
       64 
     | 
    
         
            -
                    it 'should check if user is authorized for : 
     | 
| 
       65 
     | 
    
         
            -
                      expect(controller).to receive(:authorize!).with(: 
     | 
| 
      
 47 
     | 
    
         
            +
                    it 'should check if user is authorized for :update' do
         
     | 
| 
      
 48 
     | 
    
         
            +
                      expect(controller).to receive(:authorize!).with(:update, order, token)
         
     | 
| 
       66 
49 
     | 
    
         
             
                      post :empty, params: { token: token }
         
     | 
| 
       67 
50 
     | 
    
         
             
                    end
         
     | 
| 
       68 
     | 
    
         
            -
                    it "should check against the specified order" do
         
     | 
| 
       69 
     | 
    
         
            -
                      expect(controller).to receive(:authorize!).with(:edit, specified_order, token)
         
     | 
| 
       70 
     | 
    
         
            -
                      post :empty, params: { id: specified_order.number, token: token }
         
     | 
| 
       71 
     | 
    
         
            -
                    end
         
     | 
| 
       72 
51 
     | 
    
         
             
                  end
         
     | 
| 
       73 
52 
     | 
    
         | 
| 
       74 
53 
     | 
    
         
             
                  context "#show" do
         
     | 
| 
      
 54 
     | 
    
         
            +
                    let(:specified_order) { create(:order) }
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
       75 
56 
     | 
    
         
             
                    it "should check against the specified order" do
         
     | 
| 
       76 
     | 
    
         
            -
                      expect(controller).to receive(:authorize!).with(: 
     | 
| 
      
 57 
     | 
    
         
            +
                      expect(controller).to receive(:authorize!).with(:read, specified_order, token)
         
     | 
| 
       77 
58 
     | 
    
         
             
                      get :show, params: { id: specified_order.number, token: token }
         
     | 
| 
       78 
59 
     | 
    
         
             
                    end
         
     | 
| 
       79 
60 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -105,7 +105,7 @@ describe Spree::OrdersController, type: :controller do 
     | 
|
| 
       105 
105 
     | 
    
         
             
                context "#update" do
         
     | 
| 
       106 
106 
     | 
    
         
             
                  context "with authorization" do
         
     | 
| 
       107 
107 
     | 
    
         
             
                    before do
         
     | 
| 
       108 
     | 
    
         
            -
                      allow(controller).to receive : 
     | 
| 
      
 108 
     | 
    
         
            +
                      allow(controller).to receive :authorize!
         
     | 
| 
       109 
109 
     | 
    
         
             
                      allow(controller).to receive_messages current_order: order
         
     | 
| 
       110 
110 
     | 
    
         
             
                    end
         
     | 
| 
       111 
111 
     | 
    
         | 
| 
         @@ -128,12 +128,63 @@ describe Spree::OrdersController, type: :controller do 
     | 
|
| 
       128 
128 
     | 
    
         
             
                      put :update, params: { checkout: true }
         
     | 
| 
       129 
129 
     | 
    
         
             
                      expect(response).to redirect_to checkout_state_path('address')
         
     | 
| 
       130 
130 
     | 
    
         
             
                    end
         
     | 
| 
      
 131 
     | 
    
         
            +
             
     | 
| 
      
 132 
     | 
    
         
            +
                    context 'trying to apply a coupon code' do
         
     | 
| 
      
 133 
     | 
    
         
            +
                      let(:order) { create(:order_with_line_items, state: 'cart') }
         
     | 
| 
      
 134 
     | 
    
         
            +
                      let(:coupon_code) { "coupon_code" }
         
     | 
| 
      
 135 
     | 
    
         
            +
             
     | 
| 
      
 136 
     | 
    
         
            +
                      context "when coupon code is empty" do
         
     | 
| 
      
 137 
     | 
    
         
            +
                        let(:coupon_code) { "" }
         
     | 
| 
      
 138 
     | 
    
         
            +
             
     | 
| 
      
 139 
     | 
    
         
            +
                        it 'does not try to apply coupon code' do
         
     | 
| 
      
 140 
     | 
    
         
            +
                          expect(Spree::PromotionHandler::Coupon).not_to receive :new
         
     | 
| 
      
 141 
     | 
    
         
            +
             
     | 
| 
      
 142 
     | 
    
         
            +
                          put :update, params: { state: order.state, order: { coupon_code: coupon_code } }
         
     | 
| 
      
 143 
     | 
    
         
            +
             
     | 
| 
      
 144 
     | 
    
         
            +
                          expect(response).to redirect_to(spree.cart_path)
         
     | 
| 
      
 145 
     | 
    
         
            +
                        end
         
     | 
| 
      
 146 
     | 
    
         
            +
                      end
         
     | 
| 
      
 147 
     | 
    
         
            +
             
     | 
| 
      
 148 
     | 
    
         
            +
                      context "when coupon code is applied" do
         
     | 
| 
      
 149 
     | 
    
         
            +
                        let(:promotion_handler) { instance_double('Spree::PromotionHandler::Coupon', error: nil, success: 'Coupon Applied!') }
         
     | 
| 
      
 150 
     | 
    
         
            +
             
     | 
| 
      
 151 
     | 
    
         
            +
                        it "continues checkout flow normally" do
         
     | 
| 
      
 152 
     | 
    
         
            +
                          expect(Spree::Deprecation).to receive(:warn)
         
     | 
| 
      
 153 
     | 
    
         
            +
             
     | 
| 
      
 154 
     | 
    
         
            +
                          expect(Spree::PromotionHandler::Coupon)
         
     | 
| 
      
 155 
     | 
    
         
            +
                            .to receive_message_chain(:new, :apply)
         
     | 
| 
      
 156 
     | 
    
         
            +
                            .and_return(promotion_handler)
         
     | 
| 
      
 157 
     | 
    
         
            +
             
     | 
| 
      
 158 
     | 
    
         
            +
                          put :update, params: { state: order.state, order: { coupon_code: coupon_code } }
         
     | 
| 
      
 159 
     | 
    
         
            +
             
     | 
| 
      
 160 
     | 
    
         
            +
                          expect(response).to redirect_to(spree.cart_path)
         
     | 
| 
      
 161 
     | 
    
         
            +
                          expect(flash.now[:success]).to eq('Coupon Applied!')
         
     | 
| 
      
 162 
     | 
    
         
            +
                        end
         
     | 
| 
      
 163 
     | 
    
         
            +
             
     | 
| 
      
 164 
     | 
    
         
            +
                        context "when coupon code is not applied" do
         
     | 
| 
      
 165 
     | 
    
         
            +
                          let(:promotion_handler) { instance_double('Spree::PromotionHandler::Coupon', error: 'Some error', success: false) }
         
     | 
| 
      
 166 
     | 
    
         
            +
             
     | 
| 
      
 167 
     | 
    
         
            +
                          it "render cart with coupon error" do
         
     | 
| 
      
 168 
     | 
    
         
            +
                            expect(Spree::Deprecation).to receive(:warn)
         
     | 
| 
      
 169 
     | 
    
         
            +
             
     | 
| 
      
 170 
     | 
    
         
            +
                            expect(Spree::PromotionHandler::Coupon)
         
     | 
| 
      
 171 
     | 
    
         
            +
                              .to receive_message_chain(:new, :apply)
         
     | 
| 
      
 172 
     | 
    
         
            +
                              .and_return(promotion_handler)
         
     | 
| 
      
 173 
     | 
    
         
            +
             
     | 
| 
      
 174 
     | 
    
         
            +
                            put :update, params: { state: order.state, order: { coupon_code: coupon_code } }
         
     | 
| 
      
 175 
     | 
    
         
            +
             
     | 
| 
      
 176 
     | 
    
         
            +
                            expect(response).to render_template :edit
         
     | 
| 
      
 177 
     | 
    
         
            +
                            expect(flash.now[:error]).to eq('Some error')
         
     | 
| 
      
 178 
     | 
    
         
            +
                          end
         
     | 
| 
      
 179 
     | 
    
         
            +
                        end
         
     | 
| 
      
 180 
     | 
    
         
            +
                      end
         
     | 
| 
      
 181 
     | 
    
         
            +
                    end
         
     | 
| 
       131 
182 
     | 
    
         
             
                  end
         
     | 
| 
       132 
183 
     | 
    
         
             
                end
         
     | 
| 
       133 
184 
     | 
    
         | 
| 
       134 
185 
     | 
    
         
             
                context "#empty" do
         
     | 
| 
       135 
186 
     | 
    
         
             
                  before do
         
     | 
| 
       136 
     | 
    
         
            -
                    allow(controller).to receive : 
     | 
| 
      
 187 
     | 
    
         
            +
                    allow(controller).to receive :authorize!
         
     | 
| 
       137 
188 
     | 
    
         
             
                  end
         
     | 
| 
       138 
189 
     | 
    
         | 
| 
       139 
190 
     | 
    
         
             
                  it "should destroy line items in the current order" do
         
     | 
| 
         @@ -165,7 +216,7 @@ describe Spree::OrdersController, type: :controller do 
     | 
|
| 
       165 
216 
     | 
    
         
             
                let!(:line_item) { order.contents.add(variant, 1) }
         
     | 
| 
       166 
217 
     | 
    
         | 
| 
       167 
218 
     | 
    
         
             
                before do
         
     | 
| 
       168 
     | 
    
         
            -
                  allow(controller).to receive 
     | 
| 
      
 219 
     | 
    
         
            +
                  allow(controller).to receive :authorize!
         
     | 
| 
       169 
220 
     | 
    
         
             
                  allow(controller).to receive_messages(current_order: order)
         
     | 
| 
       170 
221 
     | 
    
         
             
                end
         
     | 
| 
       171 
222 
     | 
    
         | 
| 
         @@ -7,7 +7,7 @@ describe Spree::ProductsController, type: :controller do 
     | 
|
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
              # Regression test for https://github.com/spree/spree/issues/1390
         
     | 
| 
       9 
9 
     | 
    
         
             
              it "allows admins to view non-active products" do
         
     | 
| 
       10 
     | 
    
         
            -
                allow(controller).to receive_messages  
     | 
| 
      
 10 
     | 
    
         
            +
                allow(controller).to receive_messages try_spree_current_user: mock_model(Spree.user_class, has_spree_role?: true, last_incomplete_spree_order: nil, spree_api_key: 'fake')
         
     | 
| 
       11 
11 
     | 
    
         
             
                get :show, params: { id: product.to_param }
         
     | 
| 
       12 
12 
     | 
    
         
             
                expect(response.status).to eq(200)
         
     | 
| 
       13 
13 
     | 
    
         
             
              end
         
     | 
| 
         @@ -20,7 +20,7 @@ describe Spree::ProductsController, type: :controller do 
     | 
|
| 
       20 
20 
     | 
    
         | 
| 
       21 
21 
     | 
    
         
             
              it "should provide the current user to the searcher class" do
         
     | 
| 
       22 
22 
     | 
    
         
             
                user = mock_model(Spree.user_class, last_incomplete_spree_order: nil, spree_api_key: 'fake')
         
     | 
| 
       23 
     | 
    
         
            -
                allow(controller).to receive_messages  
     | 
| 
      
 23 
     | 
    
         
            +
                allow(controller).to receive_messages try_spree_current_user: user
         
     | 
| 
       24 
24 
     | 
    
         
             
                expect_any_instance_of(Spree::Config.searcher_class).to receive(:current_user=).with(user)
         
     | 
| 
       25 
25 
     | 
    
         
             
                get :index
         
     | 
| 
       26 
26 
     | 
    
         
             
                expect(response.status).to eq(200)
         
     | 
| 
         @@ -29,7 +29,7 @@ describe Spree::ProductsController, type: :controller do 
     | 
|
| 
       29 
29 
     | 
    
         
             
              # Regression test for https://github.com/spree/spree/issues/2249
         
     | 
| 
       30 
30 
     | 
    
         
             
              it "doesn't error when given an invalid referer" do
         
     | 
| 
       31 
31 
     | 
    
         
             
                current_user = mock_model(Spree.user_class, has_spree_role?: true, last_incomplete_spree_order: nil, generate_spree_api_key!: nil)
         
     | 
| 
       32 
     | 
    
         
            -
                allow(controller).to receive_messages  
     | 
| 
      
 32 
     | 
    
         
            +
                allow(controller).to receive_messages try_spree_current_user: current_user
         
     | 
| 
       33 
33 
     | 
    
         
             
                request.env['HTTP_REFERER'] = "not|a$url"
         
     | 
| 
       34 
34 
     | 
    
         | 
| 
       35 
35 
     | 
    
         
             
                # Previously a URI::InvalidURIError exception was being thrown
         
     | 
| 
         @@ -6,7 +6,7 @@ describe Spree::TaxonsController, type: :controller do 
     | 
|
| 
       6 
6 
     | 
    
         
             
              it "should provide the current user to the searcher class" do
         
     | 
| 
       7 
7 
     | 
    
         
             
                taxon = create(:taxon, permalink: "test")
         
     | 
| 
       8 
8 
     | 
    
         
             
                user = mock_model(Spree.user_class, last_incomplete_spree_order: nil, spree_api_key: 'fake')
         
     | 
| 
       9 
     | 
    
         
            -
                allow(controller).to receive_messages  
     | 
| 
      
 9 
     | 
    
         
            +
                allow(controller).to receive_messages try_spree_current_user: user
         
     | 
| 
       10 
10 
     | 
    
         
             
                expect_any_instance_of(Spree::Config.searcher_class).to receive(:current_user=).with(user)
         
     | 
| 
       11 
11 
     | 
    
         
             
                get :show, params: { id: taxon.permalink }
         
     | 
| 
       12 
12 
     | 
    
         
             
                expect(response.status).to eq(200)
         
     | 
| 
         @@ -24,7 +24,7 @@ describe "Address", type: :feature, inaccessible: true do 
     | 
|
| 
       24 
24 
     | 
    
         
             
                let!(:canada) { create(:country, name: "Canada", states_required: true, iso: "CA") }
         
     | 
| 
       25 
25 
     | 
    
         
             
                let!(:uk) { create(:country, name: "United Kingdom", states_required: true, iso: "GB") }
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
                before {  
     | 
| 
      
 27 
     | 
    
         
            +
                before { stub_spree_preferences(default_country_iso: uk.iso) }
         
     | 
| 
       28 
28 
     | 
    
         | 
| 
       29 
29 
     | 
    
         
             
                context "but has no state" do
         
     | 
| 
       30 
30 
     | 
    
         
             
                  it "shows the state input field" do
         
     | 
| 
         @@ -40,10 +40,10 @@ describe "Automatic promotions", type: :feature, js: true do 
     | 
|
| 
       40 
40 
     | 
    
         
             
                it "automatically applies the promotion once the order crosses the threshold" do
         
     | 
| 
       41 
41 
     | 
    
         
             
                  fill_in "order_line_items_attributes_0_quantity", with: 10
         
     | 
| 
       42 
42 
     | 
    
         
             
                  click_button "Update"
         
     | 
| 
       43 
     | 
    
         
            -
                  expect(page).to have_content("Promotion ($10 off when you spend more than $100) -$10.00")
         
     | 
| 
      
 43 
     | 
    
         
            +
                  expect(page).to have_content("Promotion ($10 off when you spend more than $100) -$10.00", normalize_ws: true)
         
     | 
| 
       44 
44 
     | 
    
         
             
                  fill_in "order_line_items_attributes_0_quantity", with: 1
         
     | 
| 
       45 
45 
     | 
    
         
             
                  click_button "Update"
         
     | 
| 
       46 
     | 
    
         
            -
                  expect(page).not_to have_content("Promotion ($10 off when you spend more than $100) -$10.00")
         
     | 
| 
      
 46 
     | 
    
         
            +
                  expect(page).not_to have_content("Promotion ($10 off when you spend more than $100) -$10.00", normalize_ws: true)
         
     | 
| 
       47 
47 
     | 
    
         
             
                end
         
     | 
| 
       48 
48 
     | 
    
         
             
              end
         
     | 
| 
       49 
49 
     | 
    
         
             
            end
         
     | 
| 
         @@ -14,7 +14,7 @@ describe 'taxons', type: :feature, caching: true do 
     | 
|
| 
       14 
14 
     | 
    
         
             
              end
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
              it "busts the cache when max_level_in_taxons_menu conf changes" do
         
     | 
| 
       17 
     | 
    
         
            -
                 
     | 
| 
      
 17 
     | 
    
         
            +
                stub_spree_preferences(max_level_in_taxons_menu: 5)
         
     | 
| 
       18 
18 
     | 
    
         
             
                visit spree.root_path
         
     | 
| 
       19 
19 
     | 
    
         
             
                expect(cache_writes.count).to eq(1)
         
     | 
| 
       20 
20 
     | 
    
         
             
              end
         
     | 
| 
         @@ -0,0 +1,71 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            describe "Checkout confirm page submission", type: :feature do
         
     | 
| 
      
 6 
     | 
    
         
            +
              include_context 'checkout setup'
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
              context "when the product from the order is not backorderable but has enough stock quantity" do
         
     | 
| 
      
 9 
     | 
    
         
            +
                let(:user) { create(:user) }
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                let(:order) { Spree::TestingSupport::OrderWalkthrough.up_to(:payment) }
         
     | 
| 
      
 12 
     | 
    
         
            +
                let(:order_product) { order.products.first }
         
     | 
| 
      
 13 
     | 
    
         
            +
                let(:order_stock_item) { order_product.stock_items.first }
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                before do
         
     | 
| 
      
 16 
     | 
    
         
            +
                  order_stock_item.update! backorderable: false
         
     | 
| 
      
 17 
     | 
    
         
            +
                  order_stock_item.set_count_on_hand(1)
         
     | 
| 
      
 18 
     | 
    
         
            +
                  allow_any_instance_of(Spree::CheckoutController).to receive_messages(current_order: order)
         
     | 
| 
      
 19 
     | 
    
         
            +
                  allow_any_instance_of(Spree::CheckoutController).to receive_messages(try_spree_current_user: user)
         
     | 
| 
      
 20 
     | 
    
         
            +
                  allow_any_instance_of(Spree::OrdersController).to receive_messages(try_spree_current_user: user)
         
     | 
| 
      
 21 
     | 
    
         
            +
                end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                context 'when there are not other backorderable stock locations' do
         
     | 
| 
      
 24 
     | 
    
         
            +
                  context 'when the customer is on the confirm page and the availabilty drops to zero' do
         
     | 
| 
      
 25 
     | 
    
         
            +
                    before do
         
     | 
| 
      
 26 
     | 
    
         
            +
                      visit spree.checkout_state_path(:confirm)
         
     | 
| 
      
 27 
     | 
    
         
            +
                      order_stock_item.set_count_on_hand(0)
         
     | 
| 
      
 28 
     | 
    
         
            +
                    end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                    it 'redirects to cart page and shows an unavailable product message' do
         
     | 
| 
      
 31 
     | 
    
         
            +
                      click_button "Place Order"
         
     | 
| 
      
 32 
     | 
    
         
            +
                      expect(page).to have_content "#{order_product.name} became unavailable"
         
     | 
| 
      
 33 
     | 
    
         
            +
                      expect(page).to have_current_path spree.cart_path
         
     | 
| 
      
 34 
     | 
    
         
            +
                    end
         
     | 
| 
      
 35 
     | 
    
         
            +
                  end
         
     | 
| 
      
 36 
     | 
    
         
            +
                end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                context 'when there is another backorderable stock location' do
         
     | 
| 
      
 39 
     | 
    
         
            +
                  before do
         
     | 
| 
      
 40 
     | 
    
         
            +
                    create :stock_location, backorderable_default: true, default: false
         
     | 
| 
      
 41 
     | 
    
         
            +
                  end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                  context 'when the customer is on the confirm page and the availabilty drops to zero' do
         
     | 
| 
      
 44 
     | 
    
         
            +
                    before do
         
     | 
| 
      
 45 
     | 
    
         
            +
                      visit spree.checkout_state_path(:confirm)
         
     | 
| 
      
 46 
     | 
    
         
            +
                      order_stock_item.set_count_on_hand(0)
         
     | 
| 
      
 47 
     | 
    
         
            +
                    end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                    it "redirects to the address checkout page and shows an availability changed message" do
         
     | 
| 
      
 50 
     | 
    
         
            +
                      click_button "Place Order"
         
     | 
| 
      
 51 
     | 
    
         
            +
                      error_message = "Quantity selected of #{order_product.name} is not available. Still, items may be available from another stock location, please try again."
         
     | 
| 
      
 52 
     | 
    
         
            +
                      expect(page).to have_content error_message
         
     | 
| 
      
 53 
     | 
    
         
            +
                      expect(page).to have_current_path spree.checkout_state_path(:address)
         
     | 
| 
      
 54 
     | 
    
         
            +
                    end
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                    it "can still complete the order using the backorderable stock location by restarting the checkout" do
         
     | 
| 
      
 57 
     | 
    
         
            +
                      click_button "Place Order"
         
     | 
| 
      
 58 
     | 
    
         
            +
                      expect(page).to have_current_path spree.checkout_state_path(:address)
         
     | 
| 
      
 59 
     | 
    
         
            +
                      click_button "Save and Continue"
         
     | 
| 
      
 60 
     | 
    
         
            +
                      expect(page).to have_current_path spree.checkout_state_path(:delivery)
         
     | 
| 
      
 61 
     | 
    
         
            +
                      click_button "Save and Continue"
         
     | 
| 
      
 62 
     | 
    
         
            +
                      expect(page).to have_current_path spree.checkout_state_path(:payment)
         
     | 
| 
      
 63 
     | 
    
         
            +
                      click_button "Save and Continue"
         
     | 
| 
      
 64 
     | 
    
         
            +
                      expect(page).to have_current_path spree.checkout_state_path(:confirm)
         
     | 
| 
      
 65 
     | 
    
         
            +
                      click_button "Place Order"
         
     | 
| 
      
 66 
     | 
    
         
            +
                      expect(page).to have_content 'Your order has been processed successfully'
         
     | 
| 
      
 67 
     | 
    
         
            +
                    end
         
     | 
| 
      
 68 
     | 
    
         
            +
                  end
         
     | 
| 
      
 69 
     | 
    
         
            +
                end
         
     | 
| 
      
 70 
     | 
    
         
            +
              end
         
     | 
| 
      
 71 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -211,6 +211,26 @@ describe "Checkout", type: :feature, inaccessible: true do 
     | 
|
| 
       211 
211 
     | 
    
         
             
                end
         
     | 
| 
       212 
212 
     | 
    
         
             
              end
         
     | 
| 
       213 
213 
     | 
    
         | 
| 
      
 214 
     | 
    
         
            +
              context "when order has only a void payment" do
         
     | 
| 
      
 215 
     | 
    
         
            +
                let(:order) { Spree::TestingSupport::OrderWalkthrough.up_to(:payment) }
         
     | 
| 
      
 216 
     | 
    
         
            +
             
     | 
| 
      
 217 
     | 
    
         
            +
                before do
         
     | 
| 
      
 218 
     | 
    
         
            +
                  user = create(:user)
         
     | 
| 
      
 219 
     | 
    
         
            +
                  order.user = user
         
     | 
| 
      
 220 
     | 
    
         
            +
                  order.recalculate
         
     | 
| 
      
 221 
     | 
    
         
            +
             
     | 
| 
      
 222 
     | 
    
         
            +
                  allow_any_instance_of(Spree::CheckoutController).to receive_messages(current_order: order)
         
     | 
| 
      
 223 
     | 
    
         
            +
                  allow_any_instance_of(Spree::CheckoutController).to receive_messages(try_spree_current_user: user)
         
     | 
| 
      
 224 
     | 
    
         
            +
                end
         
     | 
| 
      
 225 
     | 
    
         
            +
             
     | 
| 
      
 226 
     | 
    
         
            +
                it "does not allow successful order submission" do
         
     | 
| 
      
 227 
     | 
    
         
            +
                  visit spree.checkout_path
         
     | 
| 
      
 228 
     | 
    
         
            +
                  order.payments.first.update state: :void
         
     | 
| 
      
 229 
     | 
    
         
            +
                  click_button 'Place Order'
         
     | 
| 
      
 230 
     | 
    
         
            +
                  expect(page).to have_current_path spree.checkout_state_path(:payment)
         
     | 
| 
      
 231 
     | 
    
         
            +
                end
         
     | 
| 
      
 232 
     | 
    
         
            +
              end
         
     | 
| 
      
 233 
     | 
    
         
            +
             
     | 
| 
       214 
234 
     | 
    
         
             
              # Regression test for https://github.com/spree/spree/issues/2694 and https://github.com/spree/spree/issues/4117
         
     | 
| 
       215 
235 
     | 
    
         
             
              context "doesn't allow bad credit card numbers" do
         
     | 
| 
       216 
236 
     | 
    
         
             
                let!(:payment_method) { create(:credit_card_payment_method) }
         
     | 
| 
         @@ -338,30 +358,21 @@ describe "Checkout", type: :feature, inaccessible: true do 
     | 
|
| 
       338 
358 
     | 
    
         
             
                it "selects first source available and customer moves on" do
         
     | 
| 
       339 
359 
     | 
    
         
             
                  expect(find("#use_existing_card_yes")).to be_checked
         
     | 
| 
       340 
360 
     | 
    
         | 
| 
       341 
     | 
    
         
            -
                   
     | 
| 
       342 
     | 
    
         
            -
                    click_on "Save and Continue"
         
     | 
| 
       343 
     | 
    
         
            -
                  }.not_to change { Spree::CreditCard.count }
         
     | 
| 
       344 
     | 
    
         
            -
             
     | 
| 
      
 361 
     | 
    
         
            +
                  click_on "Save and Continue"
         
     | 
| 
       345 
362 
     | 
    
         
             
                  click_on "Place Order"
         
     | 
| 
       346 
363 
     | 
    
         
             
                  expect(page).to have_current_path(spree.order_path(Spree::Order.last))
         
     | 
| 
      
 364 
     | 
    
         
            +
                  expect(page).to have_current_path(spree.order_path(Spree::Order.last))
         
     | 
| 
      
 365 
     | 
    
         
            +
                  expect(page).to have_content("Ending in #{credit_card.last_digits}")
         
     | 
| 
       347 
366 
     | 
    
         
             
                end
         
     | 
| 
       348 
367 
     | 
    
         | 
| 
       349 
368 
     | 
    
         
             
                it "allows user to enter a new source" do
         
     | 
| 
       350 
369 
     | 
    
         
             
                  choose "use_existing_card_no"
         
     | 
| 
      
 370 
     | 
    
         
            +
                  fill_in_credit_card
         
     | 
| 
       351 
371 
     | 
    
         | 
| 
       352 
     | 
    
         
            -
                   
     | 
| 
       353 
     | 
    
         
            -
                  fill_in_with_force "Card Number", with: '4111 1111 1111 1111'
         
     | 
| 
       354 
     | 
    
         
            -
                  fill_in "card_expiry", with: '04 / 20'
         
     | 
| 
       355 
     | 
    
         
            -
                  fill_in "Card Code", with: '123'
         
     | 
| 
       356 
     | 
    
         
            -
             
     | 
| 
       357 
     | 
    
         
            -
                  expect {
         
     | 
| 
       358 
     | 
    
         
            -
                    click_on "Save and Continue"
         
     | 
| 
       359 
     | 
    
         
            -
                  }.to change { Spree::CreditCard.count }.by 1
         
     | 
| 
       360 
     | 
    
         
            -
             
     | 
| 
       361 
     | 
    
         
            -
                  expect(Spree::CreditCard.last.address).to be_present
         
     | 
| 
       362 
     | 
    
         
            -
             
     | 
| 
      
 372 
     | 
    
         
            +
                  click_on "Save and Continue"
         
     | 
| 
       363 
373 
     | 
    
         
             
                  click_on "Place Order"
         
     | 
| 
       364 
374 
     | 
    
         
             
                  expect(page).to have_current_path(spree.order_path(Spree::Order.last))
         
     | 
| 
      
 375 
     | 
    
         
            +
                  expect(page).to have_content('Ending in 1111')
         
     | 
| 
       365 
376 
     | 
    
         
             
                end
         
     | 
| 
       366 
377 
     | 
    
         
             
              end
         
     | 
| 
       367 
378 
     | 
    
         | 
| 
         @@ -498,7 +509,7 @@ describe "Checkout", type: :feature, inaccessible: true do 
     | 
|
| 
       498 
509 
     | 
    
         
             
                end
         
     | 
| 
       499 
510 
     | 
    
         
             
              end
         
     | 
| 
       500 
511 
     | 
    
         | 
| 
       501 
     | 
    
         
            -
              context "order has only payment step" do
         
     | 
| 
      
 512 
     | 
    
         
            +
              context "order has only payment step", js: true do
         
     | 
| 
       502 
513 
     | 
    
         
             
                before do
         
     | 
| 
       503 
514 
     | 
    
         
             
                  create(:credit_card_payment_method)
         
     | 
| 
       504 
515 
     | 
    
         
             
                  @old_checkout_flow = Spree::Order.checkout_flow
         
     | 
| 
         @@ -523,10 +534,7 @@ describe "Checkout", type: :feature, inaccessible: true do 
     | 
|
| 
       523 
534 
     | 
    
         
             
                  expect(page).to have_current_path(spree.checkout_state_path('payment'))
         
     | 
| 
       524 
535 
     | 
    
         | 
| 
       525 
536 
     | 
    
         
             
                  choose "Credit Card"
         
     | 
| 
       526 
     | 
    
         
            -
                   
     | 
| 
       527 
     | 
    
         
            -
                  fill_in "Card Number", with: '4111 1111 1111 1111'
         
     | 
| 
       528 
     | 
    
         
            -
                  fill_in "card_expiry", with: '04 / 20'
         
     | 
| 
       529 
     | 
    
         
            -
                  fill_in "Card Code", with: '123'
         
     | 
| 
      
 537 
     | 
    
         
            +
                  fill_in_credit_card
         
     | 
| 
       530 
538 
     | 
    
         
             
                  click_button "Save and Continue"
         
     | 
| 
       531 
539 
     | 
    
         | 
| 
       532 
540 
     | 
    
         
             
                  expect(current_path).to eq spree.checkout_state_path('confirm')
         
     | 
| 
         @@ -582,7 +590,7 @@ describe "Checkout", type: :feature, inaccessible: true do 
     | 
|
| 
       582 
590 
     | 
    
         
             
                end
         
     | 
| 
       583 
591 
     | 
    
         | 
| 
       584 
592 
     | 
    
         
             
                it "displays a thank you message" do
         
     | 
| 
       585 
     | 
    
         
            -
                  expect(page).to have_content(I18n.t('spree.thank_you_for_your_order'))
         
     | 
| 
      
 593 
     | 
    
         
            +
                  expect(page).to have_content(I18n.t('spree.thank_you_for_your_order'), normalize_ws: true)
         
     | 
| 
       586 
594 
     | 
    
         
             
                end
         
     | 
| 
       587 
595 
     | 
    
         | 
| 
       588 
596 
     | 
    
         
             
                it "does not display a thank you message on that order future visits" do
         
     | 
| 
         @@ -657,16 +665,17 @@ describe "Checkout", type: :feature, inaccessible: true do 
     | 
|
| 
       657 
665 
     | 
    
         
             
                  click_on "Save and Continue"
         
     | 
| 
       658 
666 
     | 
    
         
             
                  click_on "Save and Continue"
         
     | 
| 
       659 
667 
     | 
    
         | 
| 
       660 
     | 
    
         
            -
                  fill_in_credit_card 
     | 
| 
      
 668 
     | 
    
         
            +
                  fill_in_credit_card
         
     | 
| 
       661 
669 
     | 
    
         
             
                  click_on "Save and Continue"
         
     | 
| 
       662 
670 
     | 
    
         | 
| 
       663 
671 
     | 
    
         
             
                  expect(page).to have_current_path("/checkout/confirm")
         
     | 
| 
       664 
672 
     | 
    
         
             
                end
         
     | 
| 
       665 
673 
     | 
    
         
             
              end
         
     | 
| 
       666 
674 
     | 
    
         | 
| 
       667 
     | 
    
         
            -
              def fill_in_credit_card(number:)
         
     | 
| 
       668 
     | 
    
         
            -
                fill_in " 
     | 
| 
       669 
     | 
    
         
            -
                 
     | 
| 
      
 675 
     | 
    
         
            +
              def fill_in_credit_card(number: "4111 1111 1111 1111")
         
     | 
| 
      
 676 
     | 
    
         
            +
                fill_in "Name on card", with: 'Mary Doe'
         
     | 
| 
      
 677 
     | 
    
         
            +
                fill_in_with_force "Card Number", with: number
         
     | 
| 
      
 678 
     | 
    
         
            +
                fill_in_with_force "Expiration", with: "12 / 24"
         
     | 
| 
       670 
679 
     | 
    
         
             
                fill_in "Card Code", with: "123"
         
     | 
| 
       671 
680 
     | 
    
         
             
              end
         
     | 
| 
       672 
681 
     | 
    
         | 
| 
         @@ -11,7 +11,7 @@ describe "Coupon code promotions", type: :feature, js: true do 
     | 
|
| 
       11 
11 
     | 
    
         
             
              let!(:payment_method) { create(:check_payment_method) }
         
     | 
| 
       12 
12 
     | 
    
         
             
              let!(:product) { create(:product, name: "RoR Mug", price: 20) }
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
              context "visitor makes checkout 
     | 
| 
      
 14 
     | 
    
         
            +
              context "visitor makes checkout" do
         
     | 
| 
       15 
15 
     | 
    
         
             
                def create_basic_coupon_promotion(code)
         
     | 
| 
       16 
16 
     | 
    
         
             
                  promotion = create(
         
     | 
| 
       17 
17 
     | 
    
         
             
                    :promotion,
         
     | 
| 
         @@ -34,49 +34,89 @@ describe "Coupon code promotions", type: :feature, js: true do 
     | 
|
| 
       34 
34 
     | 
    
         | 
| 
       35 
35 
     | 
    
         
             
                let!(:promotion) { create_basic_coupon_promotion("onetwo") }
         
     | 
| 
       36 
36 
     | 
    
         | 
| 
       37 
     | 
    
         
            -
                # OrdersController
         
     | 
| 
       38 
37 
     | 
    
         
             
                context "on the payment page" do
         
     | 
| 
       39 
     | 
    
         
            -
                   
     | 
| 
       40 
     | 
    
         
            -
                     
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
      
 38 
     | 
    
         
            +
                  context "as guest without registration" do
         
     | 
| 
      
 39 
     | 
    
         
            +
                    before do
         
     | 
| 
      
 40 
     | 
    
         
            +
                      visit spree.root_path
         
     | 
| 
      
 41 
     | 
    
         
            +
                      click_link "RoR Mug"
         
     | 
| 
      
 42 
     | 
    
         
            +
                      click_button "add-to-cart-button"
         
     | 
| 
      
 43 
     | 
    
         
            +
                      click_button "Checkout"
         
     | 
| 
      
 44 
     | 
    
         
            +
                      fill_in "order_email", with: "spree@example.com"
         
     | 
| 
      
 45 
     | 
    
         
            +
                      fill_in "First Name", with: "John"
         
     | 
| 
      
 46 
     | 
    
         
            +
                      fill_in "Last Name", with: "Smith"
         
     | 
| 
      
 47 
     | 
    
         
            +
                      fill_in "Street Address", with: "1 John Street"
         
     | 
| 
      
 48 
     | 
    
         
            +
                      fill_in "City", with: "City of John"
         
     | 
| 
      
 49 
     | 
    
         
            +
                      fill_in "Zip", with: "01337"
         
     | 
| 
      
 50 
     | 
    
         
            +
                      select country.name, from: "Country"
         
     | 
| 
      
 51 
     | 
    
         
            +
                      select state.name, from: "order[bill_address_attributes][state_id]"
         
     | 
| 
      
 52 
     | 
    
         
            +
                      fill_in "Phone", with: "555-555-5555"
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                      # To shipping method screen
         
     | 
| 
      
 55 
     | 
    
         
            +
                      click_button "Save and Continue"
         
     | 
| 
      
 56 
     | 
    
         
            +
                      # To payment screen
         
     | 
| 
      
 57 
     | 
    
         
            +
                      click_button "Save and Continue"
         
     | 
| 
      
 58 
     | 
    
         
            +
                    end
         
     | 
| 
       59 
59 
     | 
    
         | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
      
 60 
     | 
    
         
            +
                    it "informs about an invalid coupon code" do
         
     | 
| 
      
 61 
     | 
    
         
            +
                      fill_in "order_coupon_code", with: "coupon_codes_rule_man"
         
     | 
| 
      
 62 
     | 
    
         
            +
                      click_button "Apply Code"
         
     | 
| 
      
 63 
     | 
    
         
            +
                      expect(page).to have_content(I18n.t('spree.coupon_code_not_found'))
         
     | 
| 
      
 64 
     | 
    
         
            +
                    end
         
     | 
| 
       65 
65 
     | 
    
         | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
      
 66 
     | 
    
         
            +
                    it "can enter an invalid coupon code, then a real one" do
         
     | 
| 
      
 67 
     | 
    
         
            +
                      fill_in "order_coupon_code", with: "coupon_codes_rule_man"
         
     | 
| 
      
 68 
     | 
    
         
            +
                      click_button "Apply Code"
         
     | 
| 
      
 69 
     | 
    
         
            +
                      expect(page).to have_content(I18n.t('spree.coupon_code_not_found'))
         
     | 
| 
      
 70 
     | 
    
         
            +
                      fill_in "order_coupon_code", with: "onetwo"
         
     | 
| 
      
 71 
     | 
    
         
            +
                      click_button "Apply Code"
         
     | 
| 
      
 72 
     | 
    
         
            +
                      expect(page).to have_content("Promotion (Onetwo) -$10.00", normalize_ws: true)
         
     | 
| 
      
 73 
     | 
    
         
            +
                    end
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
                    context "with a promotion" do
         
     | 
| 
      
 76 
     | 
    
         
            +
                      it "applies a promotion to an order" do
         
     | 
| 
      
 77 
     | 
    
         
            +
                        fill_in "order_coupon_code", with: "onetwo"
         
     | 
| 
      
 78 
     | 
    
         
            +
                        click_button "Apply Code"
         
     | 
| 
      
 79 
     | 
    
         
            +
                        expect(page).to have_content("Promotion (Onetwo) -$10.00", normalize_ws: true)
         
     | 
| 
      
 80 
     | 
    
         
            +
                      end
         
     | 
| 
      
 81 
     | 
    
         
            +
                    end
         
     | 
| 
       73 
82 
     | 
    
         
             
                  end
         
     | 
| 
       74 
83 
     | 
    
         | 
| 
       75 
     | 
    
         
            -
                  context  
     | 
| 
       76 
     | 
    
         
            -
                     
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
                       
     | 
| 
      
 84 
     | 
    
         
            +
                  context 'as logged user' do
         
     | 
| 
      
 85 
     | 
    
         
            +
                    let!(:user) { create(:user, bill_address: create(:address), ship_address: create(:address)) }
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
      
 87 
     | 
    
         
            +
                    before do
         
     | 
| 
      
 88 
     | 
    
         
            +
                      allow_any_instance_of(Spree::CheckoutController).to receive_messages(try_spree_current_user: user)
         
     | 
| 
      
 89 
     | 
    
         
            +
                      allow_any_instance_of(Spree::OrdersController).to receive_messages(try_spree_current_user: user)
         
     | 
| 
      
 90 
     | 
    
         
            +
                    end
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
                    context 'with saved credit card' do
         
     | 
| 
      
 93 
     | 
    
         
            +
                      let(:bogus) { create(:credit_card_payment_method) }
         
     | 
| 
      
 94 
     | 
    
         
            +
                      let!(:credit_card) do
         
     | 
| 
      
 95 
     | 
    
         
            +
                        create(:credit_card, user_id: user.id, payment_method: bogus, gateway_customer_profile_id: "BGS-WEFWF")
         
     | 
| 
      
 96 
     | 
    
         
            +
                      end
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
                      before do
         
     | 
| 
      
 99 
     | 
    
         
            +
                        user.wallet.add(credit_card)
         
     | 
| 
      
 100 
     | 
    
         
            +
             
     | 
| 
      
 101 
     | 
    
         
            +
                        visit spree.root_path
         
     | 
| 
      
 102 
     | 
    
         
            +
                        click_link "RoR Mug"
         
     | 
| 
      
 103 
     | 
    
         
            +
                        click_button "add-to-cart-button"
         
     | 
| 
      
 104 
     | 
    
         
            +
                        # To Cart
         
     | 
| 
      
 105 
     | 
    
         
            +
                        click_button "Checkout"
         
     | 
| 
      
 106 
     | 
    
         
            +
                        # To shipping method screen, address is auto-populated
         
     | 
| 
      
 107 
     | 
    
         
            +
                        # with user's saved addresses
         
     | 
| 
      
 108 
     | 
    
         
            +
                        click_button "Save and Continue"
         
     | 
| 
      
 109 
     | 
    
         
            +
                        # To payment screen
         
     | 
| 
      
 110 
     | 
    
         
            +
                        click_button "Save and Continue"
         
     | 
| 
      
 111 
     | 
    
         
            +
                      end
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
                      it "shows wallet payments on coupon code errors" do
         
     | 
| 
      
 114 
     | 
    
         
            +
                        fill_in "order_coupon_code", with: "coupon_codes_rule_man"
         
     | 
| 
      
 115 
     | 
    
         
            +
                        click_button "Apply Code"
         
     | 
| 
      
 116 
     | 
    
         
            +
             
     | 
| 
      
 117 
     | 
    
         
            +
                        expect(page).to have_content("The coupon code you entered doesn't exist. Please try again.")
         
     | 
| 
      
 118 
     | 
    
         
            +
                        expect(page).to have_content("Use an existing card")
         
     | 
| 
      
 119 
     | 
    
         
            +
                      end
         
     | 
| 
       80 
120 
     | 
    
         
             
                    end
         
     | 
| 
       81 
121 
     | 
    
         
             
                  end
         
     | 
| 
       82 
122 
     | 
    
         
             
                end
         
     | 
| 
         @@ -90,22 +130,22 @@ describe "Coupon code promotions", type: :feature, js: true do 
     | 
|
| 
       90 
130 
     | 
    
         
             
                  end
         
     | 
| 
       91 
131 
     | 
    
         | 
| 
       92 
132 
     | 
    
         
             
                  it "can enter a coupon code and receives success notification" do
         
     | 
| 
       93 
     | 
    
         
            -
                    fill_in " 
     | 
| 
       94 
     | 
    
         
            -
                    click_button " 
     | 
| 
      
 133 
     | 
    
         
            +
                    fill_in "coupon_code", with: "onetwo"
         
     | 
| 
      
 134 
     | 
    
         
            +
                    click_button "Apply Code"
         
     | 
| 
       95 
135 
     | 
    
         
             
                    expect(page).to have_content(I18n.t('spree.coupon_code_applied'))
         
     | 
| 
       96 
136 
     | 
    
         
             
                  end
         
     | 
| 
       97 
137 
     | 
    
         | 
| 
       98 
138 
     | 
    
         
             
                  it "can enter a promotion code with both upper and lower case letters" do
         
     | 
| 
       99 
     | 
    
         
            -
                    fill_in " 
     | 
| 
       100 
     | 
    
         
            -
                    click_button " 
     | 
| 
      
 139 
     | 
    
         
            +
                    fill_in "coupon_code", with: "ONETwO"
         
     | 
| 
      
 140 
     | 
    
         
            +
                    click_button "Apply Code"
         
     | 
| 
       101 
141 
     | 
    
         
             
                    expect(page).to have_content(I18n.t('spree.coupon_code_applied'))
         
     | 
| 
       102 
142 
     | 
    
         
             
                  end
         
     | 
| 
       103 
143 
     | 
    
         | 
| 
       104 
144 
     | 
    
         
             
                  it "informs the user about a coupon code which has exceeded its usage" do
         
     | 
| 
       105 
145 
     | 
    
         
             
                    expect_any_instance_of(Spree::Promotion).to receive(:usage_limit_exceeded?).and_return(true)
         
     | 
| 
       106 
146 
     | 
    
         | 
| 
       107 
     | 
    
         
            -
                    fill_in " 
     | 
| 
       108 
     | 
    
         
            -
                    click_button " 
     | 
| 
      
 147 
     | 
    
         
            +
                    fill_in "coupon_code", with: "onetwo"
         
     | 
| 
      
 148 
     | 
    
         
            +
                    click_button "Apply Code"
         
     | 
| 
       109 
149 
     | 
    
         
             
                    expect(page).to have_content(I18n.t('spree.coupon_code_max_usage'))
         
     | 
| 
       110 
150 
     | 
    
         
             
                  end
         
     | 
| 
       111 
151 
     | 
    
         | 
| 
         @@ -120,8 +160,8 @@ describe "Coupon code promotions", type: :feature, js: true do 
     | 
|
| 
       120 
160 
     | 
    
         
             
                    specify do
         
     | 
| 
       121 
161 
     | 
    
         
             
                      visit spree.cart_path
         
     | 
| 
       122 
162 
     | 
    
         | 
| 
       123 
     | 
    
         
            -
                      fill_in " 
     | 
| 
       124 
     | 
    
         
            -
                      click_button " 
     | 
| 
      
 163 
     | 
    
         
            +
                      fill_in "coupon_code", with: "onetwo"
         
     | 
| 
      
 164 
     | 
    
         
            +
                      click_button "Apply Code"
         
     | 
| 
       125 
165 
     | 
    
         
             
                      expect(page).to have_content(I18n.t(:item_total_less_than_or_equal, scope: [:spree, :eligibility_errors, :messages], amount: "$100.00"))
         
     | 
| 
       126 
166 
     | 
    
         
             
                    end
         
     | 
| 
       127 
167 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -130,8 +170,8 @@ describe "Coupon code promotions", type: :feature, js: true do 
     | 
|
| 
       130 
170 
     | 
    
         
             
                    promotion.expires_at = Date.today.beginning_of_week
         
     | 
| 
       131 
171 
     | 
    
         
             
                    promotion.starts_at = Date.today.beginning_of_week.advance(day: 3)
         
     | 
| 
       132 
172 
     | 
    
         
             
                    promotion.save!
         
     | 
| 
       133 
     | 
    
         
            -
                    fill_in " 
     | 
| 
       134 
     | 
    
         
            -
                    click_button " 
     | 
| 
      
 173 
     | 
    
         
            +
                    fill_in "coupon_code", with: "onetwo"
         
     | 
| 
      
 174 
     | 
    
         
            +
                    click_button "Apply Code"
         
     | 
| 
       135 
175 
     | 
    
         
             
                    expect(page).to have_content(I18n.t('spree.coupon_code_expired'))
         
     | 
| 
       136 
176 
     | 
    
         
             
                  end
         
     | 
| 
       137 
177 
     | 
    
         | 
| 
         @@ -151,8 +191,8 @@ describe "Coupon code promotions", type: :feature, js: true do 
     | 
|
| 
       151 
191 
     | 
    
         
             
                      click_button "add-to-cart-button"
         
     | 
| 
       152 
192 
     | 
    
         | 
| 
       153 
193 
     | 
    
         
             
                      visit spree.cart_path
         
     | 
| 
       154 
     | 
    
         
            -
                      fill_in " 
     | 
| 
       155 
     | 
    
         
            -
                      click_button " 
     | 
| 
      
 194 
     | 
    
         
            +
                      fill_in "coupon_code", with: "onetwo"
         
     | 
| 
      
 195 
     | 
    
         
            +
                      click_button "Apply Code"
         
     | 
| 
       156 
196 
     | 
    
         | 
| 
       157 
197 
     | 
    
         
             
                      fill_in "order_line_items_attributes_0_quantity", with: 2
         
     | 
| 
       158 
198 
     | 
    
         
             
                      fill_in "order_line_items_attributes_1_quantity", with: 2
         
     | 
| 
         @@ -162,7 +202,7 @@ describe "Coupon code promotions", type: :feature, js: true do 
     | 
|
| 
       162 
202 
     | 
    
         
             
                        # 20% of $40 = 8
         
     | 
| 
       163 
203 
     | 
    
         
             
                        # 20% of $20 = 4
         
     | 
| 
       164 
204 
     | 
    
         
             
                        # Therefore: promotion discount amount is $12.
         
     | 
| 
       165 
     | 
    
         
            -
                        expect(page).to have_content("Promotion (Onetwo) -$12.00")
         
     | 
| 
      
 205 
     | 
    
         
            +
                        expect(page).to have_content("Promotion (Onetwo) -$12.00", normalize_ws: true)
         
     | 
| 
       166 
206 
     | 
    
         
             
                      end
         
     | 
| 
       167 
207 
     | 
    
         | 
| 
       168 
208 
     | 
    
         
             
                      within '.cart-total' do
         
     | 
| 
         @@ -197,11 +237,11 @@ describe "Coupon code promotions", type: :feature, js: true do 
     | 
|
| 
       197 
237 
     | 
    
         
             
                        expect(page).to have_content("$30.00")
         
     | 
| 
       198 
238 
     | 
    
         
             
                      end
         
     | 
| 
       199 
239 
     | 
    
         | 
| 
       200 
     | 
    
         
            -
                      fill_in " 
     | 
| 
       201 
     | 
    
         
            -
                      click_button " 
     | 
| 
      
 240 
     | 
    
         
            +
                      fill_in "coupon_code", with: "onetwo"
         
     | 
| 
      
 241 
     | 
    
         
            +
                      click_button "Apply Code"
         
     | 
| 
       202 
242 
     | 
    
         | 
| 
       203 
243 
     | 
    
         
             
                      within '#cart_adjustments' do
         
     | 
| 
       204 
     | 
    
         
            -
                        expect(page).to have_content("Promotion (Onetwo) -$30.00")
         
     | 
| 
      
 244 
     | 
    
         
            +
                        expect(page).to have_content("Promotion (Onetwo) -$30.00", normalize_ws: true)
         
     | 
| 
       205 
245 
     | 
    
         
             
                      end
         
     | 
| 
       206 
246 
     | 
    
         | 
| 
       207 
247 
     | 
    
         
             
                      within '.cart-total' do
         
     | 
| 
         @@ -213,7 +253,7 @@ describe "Coupon code promotions", type: :feature, js: true do 
     | 
|
| 
       213 
253 
     | 
    
         
             
                      click_button "Update"
         
     | 
| 
       214 
254 
     | 
    
         | 
| 
       215 
255 
     | 
    
         
             
                      within '#cart_adjustments' do
         
     | 
| 
       216 
     | 
    
         
            -
                        expect(page).to have_content("Promotion (Onetwo) -$60.00")
         
     | 
| 
      
 256 
     | 
    
         
            +
                        expect(page).to have_content("Promotion (Onetwo) -$60.00", normalize_ws: true)
         
     | 
| 
       217 
257 
     | 
    
         
             
                      end
         
     | 
| 
       218 
258 
     | 
    
         | 
| 
       219 
259 
     | 
    
         
             
                      within '.cart-total' do
         
     |