spree_frontend 3.2.9 → 3.3.0.rc1
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.
- checksums.yaml +4 -4
- data/app/controllers/spree/checkout_controller.rb +8 -2
- data/app/controllers/spree/orders_controller.rb +7 -3
- data/app/controllers/spree/products_controller.rb +3 -1
- data/app/helpers/spree/frontend_helper.rb +1 -1
- data/app/helpers/spree/taxons_helper.rb +2 -3
- data/app/views/spree/checkout/_confirm.html.erb +3 -0
- data/app/views/spree/checkout/_summary.html.erb +1 -1
- data/app/views/spree/checkout/payment/_storecredit.html.erb +1 -0
- data/app/views/spree/products/_cart_form.html.erb +3 -3
- data/app/views/spree/shared/_main_nav_bar.html.erb +1 -1
- data/app/views/spree/shared/_order_details.html.erb +0 -1
- data/app/views/spree/shared/_products.html.erb +4 -1
- data/spec/controllers/controller_extension_spec.rb +126 -0
- data/spec/controllers/controller_helpers_spec.rb +122 -0
- data/spec/controllers/spree/checkout_controller_spec.rb +547 -0
- data/spec/controllers/spree/checkout_controller_with_views_spec.rb +36 -0
- data/spec/controllers/spree/content_controller_spec.rb +12 -0
- data/spec/controllers/spree/current_order_tracking_spec.rb +44 -0
- data/spec/controllers/spree/home_controller_spec.rb +47 -0
- data/spec/controllers/spree/orders_controller_ability_spec.rb +96 -0
- data/spec/controllers/spree/orders_controller_spec.rb +134 -0
- data/spec/controllers/spree/orders_controller_transitions_spec.rb +31 -0
- data/spec/controllers/spree/products_controller_spec.rb +87 -0
- data/spec/controllers/spree/taxons_controller_spec.rb +12 -0
- data/spec/features/address_spec.rb +93 -0
- data/spec/features/automatic_promotion_adjustments_spec.rb +47 -0
- data/spec/features/caching/products_spec.rb +59 -0
- data/spec/features/caching/taxons_spec.rb +22 -0
- data/spec/features/cart_spec.rb +132 -0
- data/spec/features/checkout_spec.rb +723 -0
- data/spec/features/checkout_unshippable_spec.rb +34 -0
- data/spec/features/coupon_code_spec.rb +88 -0
- data/spec/features/currency_spec.rb +18 -0
- data/spec/features/delivery_spec.rb +64 -0
- data/spec/features/free_shipping_promotions_spec.rb +59 -0
- data/spec/features/locale_spec.rb +60 -0
- data/spec/features/microdata_spec.rb +0 -0
- data/spec/features/order_spec.rb +107 -0
- data/spec/features/page_promotions_spec.rb +36 -0
- data/spec/features/products_spec.rb +345 -0
- data/spec/features/taxons_spec.rb +147 -0
- data/spec/features/template_rendering_spec.rb +19 -0
- data/spec/helpers/frontend_helper_spec.rb +57 -0
- data/spec/helpers/taxons_helper_spec.rb +17 -0
- data/spec/spec_helper.rb +128 -0
- data/spec/support/shared_contexts/checkout_setup.rb +10 -0
- data/spec/support/shared_contexts/custom_products.rb +25 -0
- data/spec/support/shared_contexts/product_prototypes.rb +30 -0
- data/spec/views/spree/checkout/_summary_spec.rb +11 -0
- data/spree_frontend.gemspec +5 -4
- metadata +90 -15
| @@ -0,0 +1,723 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe 'Checkout', type: :feature, inaccessible: true, js: true do
         | 
| 4 | 
            +
              include_context 'checkout setup'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              let(:country) { create(:country, name: 'United States of America', iso_name: 'UNITED STATES') }
         | 
| 7 | 
            +
              let(:state) { create(:state, name: 'Alabama', abbr: 'AL', country: country) }
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              context "visitor makes checkout as guest without registration" do
         | 
| 10 | 
            +
                before(:each) do
         | 
| 11 | 
            +
                  stock_location.stock_items.update_all(count_on_hand: 1)
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                context 'defaults to use billing address' do
         | 
| 15 | 
            +
                  before do
         | 
| 16 | 
            +
                    add_mug_to_cart
         | 
| 17 | 
            +
                    Spree::Order.last.update_column(:email, 'test@example.com')
         | 
| 18 | 
            +
                    click_button 'Checkout'
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                  it 'should default checkbox to checked' do
         | 
| 22 | 
            +
                    expect(find('input#order_use_billing')).to be_checked
         | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  it 'should remain checked when used and visitor steps back to address step' do
         | 
| 26 | 
            +
                    fill_in_address
         | 
| 27 | 
            +
                    expect(find('input#order_use_billing')).to be_checked
         | 
| 28 | 
            +
                  end
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                # Regression test for #4079
         | 
| 32 | 
            +
                context 'persists state when on address page' do
         | 
| 33 | 
            +
                  before do
         | 
| 34 | 
            +
                    add_mug_to_cart
         | 
| 35 | 
            +
                    click_button 'Checkout'
         | 
| 36 | 
            +
                  end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                  specify do
         | 
| 39 | 
            +
                    expect(Spree::Order.count).to eq 1
         | 
| 40 | 
            +
                    expect(Spree::Order.last.state).to eq 'address'
         | 
| 41 | 
            +
                  end
         | 
| 42 | 
            +
                end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                # Regression test for #1596
         | 
| 45 | 
            +
                context 'full checkout' do
         | 
| 46 | 
            +
                  before do
         | 
| 47 | 
            +
                    shipping_method.calculator.update!(preferred_amount: 10)
         | 
| 48 | 
            +
                    mug.shipping_category = shipping_method.shipping_categories.first
         | 
| 49 | 
            +
                    mug.save!
         | 
| 50 | 
            +
                  end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                  it 'does not break the per-item shipping method calculator', js: true do
         | 
| 53 | 
            +
                    add_mug_to_cart
         | 
| 54 | 
            +
                    click_button 'Checkout'
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                    fill_in 'order_email', with: 'test@example.com'
         | 
| 57 | 
            +
                    click_on 'Continue'
         | 
| 58 | 
            +
                    fill_in_address
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                    click_button 'Save and Continue'
         | 
| 61 | 
            +
                    expect(page).to_not have_content("undefined method `promotion'")
         | 
| 62 | 
            +
                    click_button 'Save and Continue'
         | 
| 63 | 
            +
                    expect(page).to have_content('Shipping total: $10.00')
         | 
| 64 | 
            +
                  end
         | 
| 65 | 
            +
                end
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                # Regression test for #4306
         | 
| 68 | 
            +
                context 'free shipping' do
         | 
| 69 | 
            +
                  before do
         | 
| 70 | 
            +
                    add_mug_to_cart
         | 
| 71 | 
            +
                    click_button 'Checkout'
         | 
| 72 | 
            +
                    fill_in 'order_email', with: 'test@example.com'
         | 
| 73 | 
            +
                    click_on 'Continue'
         | 
| 74 | 
            +
                  end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                  it "should not show 'Free Shipping' when there are no shipments" do
         | 
| 77 | 
            +
                    within('#checkout-summary') do
         | 
| 78 | 
            +
                      expect(page).to_not have_content('Free Shipping')
         | 
| 79 | 
            +
                    end
         | 
| 80 | 
            +
                  end
         | 
| 81 | 
            +
                end
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                # Regression test for #4190
         | 
| 84 | 
            +
                it 'updates state_lock_version on form submission', js: true do
         | 
| 85 | 
            +
                  add_mug_to_cart
         | 
| 86 | 
            +
                  click_button "Checkout"
         | 
| 87 | 
            +
             | 
| 88 | 
            +
                  expect(find('input#order_state_lock_version', visible: false).value).to eq '0'
         | 
| 89 | 
            +
             | 
| 90 | 
            +
                  fill_in 'order_email', with: 'test@example.com'
         | 
| 91 | 
            +
                  fill_in_address
         | 
| 92 | 
            +
                  click_button 'Save and Continue'
         | 
| 93 | 
            +
             | 
| 94 | 
            +
                  expect(find('input#order_state_lock_version', visible: false).value).to eq '1'
         | 
| 95 | 
            +
                end
         | 
| 96 | 
            +
              end
         | 
| 97 | 
            +
             | 
| 98 | 
            +
              # Regression test for #2694 and #4117
         | 
| 99 | 
            +
              context "doesn't allow bad credit card numbers" do
         | 
| 100 | 
            +
                before(:each) do
         | 
| 101 | 
            +
                  order = OrderWalkthrough.up_to(:payment)
         | 
| 102 | 
            +
                  allow(order).to receive_messages confirmation_required?: true
         | 
| 103 | 
            +
                  allow(order).to receive_messages(available_payment_methods: [create(:credit_card_payment_method)])
         | 
| 104 | 
            +
             | 
| 105 | 
            +
                  user = create(:user)
         | 
| 106 | 
            +
                  order.user = user
         | 
| 107 | 
            +
                  order.update_with_updater!
         | 
| 108 | 
            +
             | 
| 109 | 
            +
                  allow_any_instance_of(Spree::CheckoutController).to receive_messages(current_order: order)
         | 
| 110 | 
            +
                  allow_any_instance_of(Spree::CheckoutController).to receive_messages(try_spree_current_user: user)
         | 
| 111 | 
            +
                end
         | 
| 112 | 
            +
             | 
| 113 | 
            +
                it 'redirects to payment page', inaccessible: true, js: true do
         | 
| 114 | 
            +
                  visit spree.checkout_state_path(:payment)
         | 
| 115 | 
            +
                  click_button 'Save and Continue'
         | 
| 116 | 
            +
                  choose 'Credit Card'
         | 
| 117 | 
            +
                  fill_in 'Card Number', with: '123'
         | 
| 118 | 
            +
                  fill_in 'card_expiry', with: '04 / 20'
         | 
| 119 | 
            +
                  fill_in 'Card Code', with: '123'
         | 
| 120 | 
            +
                  click_button 'Save and Continue'
         | 
| 121 | 
            +
                  click_button 'Place Order'
         | 
| 122 | 
            +
                  expect(page).to have_content('Bogus Gateway: Forced failure')
         | 
| 123 | 
            +
                  expect(page.current_url).to include('/checkout/payment')
         | 
| 124 | 
            +
                end
         | 
| 125 | 
            +
              end
         | 
| 126 | 
            +
             | 
| 127 | 
            +
              # regression test for #3945
         | 
| 128 | 
            +
              context 'when Spree::Config[:always_include_confirm_step] is true' do
         | 
| 129 | 
            +
                before do
         | 
| 130 | 
            +
                  Spree::Config[:always_include_confirm_step] = true
         | 
| 131 | 
            +
                end
         | 
| 132 | 
            +
             | 
| 133 | 
            +
                it 'displays confirmation step', js: true do
         | 
| 134 | 
            +
                  add_mug_to_cart
         | 
| 135 | 
            +
                  click_button 'Checkout'
         | 
| 136 | 
            +
             | 
| 137 | 
            +
                  fill_in 'order_email', with: 'test@example.com'
         | 
| 138 | 
            +
                  click_on 'Continue'
         | 
| 139 | 
            +
                  fill_in_address
         | 
| 140 | 
            +
             | 
| 141 | 
            +
                  click_button 'Save and Continue'
         | 
| 142 | 
            +
                  click_button 'Save and Continue'
         | 
| 143 | 
            +
                  click_button 'Save and Continue'
         | 
| 144 | 
            +
             | 
| 145 | 
            +
                  continue_button = find('#checkout .btn-success')
         | 
| 146 | 
            +
                  expect(continue_button.value).to eq 'Place Order'
         | 
| 147 | 
            +
                end
         | 
| 148 | 
            +
              end
         | 
| 149 | 
            +
             | 
| 150 | 
            +
              context 'and likes to double click buttons' do
         | 
| 151 | 
            +
                let!(:user) { create(:user) }
         | 
| 152 | 
            +
             | 
| 153 | 
            +
                let!(:order) do
         | 
| 154 | 
            +
                  order = OrderWalkthrough.up_to(:payment)
         | 
| 155 | 
            +
                  allow(order).to receive_messages confirmation_required?: true
         | 
| 156 | 
            +
             | 
| 157 | 
            +
                  order.reload
         | 
| 158 | 
            +
                  order.user = user
         | 
| 159 | 
            +
                  order.update_with_updater!
         | 
| 160 | 
            +
                  order
         | 
| 161 | 
            +
                end
         | 
| 162 | 
            +
             | 
| 163 | 
            +
                before(:each) do
         | 
| 164 | 
            +
                  allow_any_instance_of(Spree::CheckoutController).to receive_messages(current_order: order)
         | 
| 165 | 
            +
                  allow_any_instance_of(Spree::CheckoutController).to receive_messages(try_spree_current_user: user)
         | 
| 166 | 
            +
                  allow_any_instance_of(Spree::CheckoutController).to receive_messages(skip_state_validation?: true)
         | 
| 167 | 
            +
                end
         | 
| 168 | 
            +
             | 
| 169 | 
            +
                it 'prevents double clicking the payment button on checkout', js: true do
         | 
| 170 | 
            +
                  visit spree.checkout_state_path(:payment)
         | 
| 171 | 
            +
             | 
| 172 | 
            +
                  # prevent form submit to verify button is disabled
         | 
| 173 | 
            +
                  page.execute_script("$('#checkout_form_payment').submit(function(){return false;})")
         | 
| 174 | 
            +
             | 
| 175 | 
            +
                  expect(page).to_not have_selector('input.btn.disabled')
         | 
| 176 | 
            +
                  click_button 'Save and Continue'
         | 
| 177 | 
            +
                  expect(page).to have_selector('input.btn.disabled')
         | 
| 178 | 
            +
                end
         | 
| 179 | 
            +
             | 
| 180 | 
            +
                it 'prevents double clicking the confirm button on checkout', js: true do
         | 
| 181 | 
            +
                  order.payments << create(:payment, amount: order.amount)
         | 
| 182 | 
            +
                  visit spree.checkout_state_path(:confirm)
         | 
| 183 | 
            +
             | 
| 184 | 
            +
                  # prevent form submit to verify button is disabled
         | 
| 185 | 
            +
                  page.execute_script("$('#checkout_form_confirm').submit(function(){return false;})")
         | 
| 186 | 
            +
             | 
| 187 | 
            +
                  expect(page).to_not have_selector('input.btn.disabled')
         | 
| 188 | 
            +
                  click_button 'Place Order'
         | 
| 189 | 
            +
                  expect(page).to have_selector('input.btn.disabled')
         | 
| 190 | 
            +
                end
         | 
| 191 | 
            +
              end
         | 
| 192 | 
            +
             | 
| 193 | 
            +
              context 'when several payment methods are available', js: true do
         | 
| 194 | 
            +
                let(:credit_cart_payment) { create(:credit_card_payment_method) }
         | 
| 195 | 
            +
                let(:check_payment) { create(:check_payment_method) }
         | 
| 196 | 
            +
             | 
| 197 | 
            +
                after do
         | 
| 198 | 
            +
                  Capybara.ignore_hidden_elements = true
         | 
| 199 | 
            +
                end
         | 
| 200 | 
            +
             | 
| 201 | 
            +
                before do
         | 
| 202 | 
            +
                  Capybara.ignore_hidden_elements = false
         | 
| 203 | 
            +
                  order = OrderWalkthrough.up_to(:payment)
         | 
| 204 | 
            +
                  allow(order).to receive_messages(available_payment_methods: [check_payment, credit_cart_payment])
         | 
| 205 | 
            +
                  order.user = create(:user)
         | 
| 206 | 
            +
                  order.update_with_updater!
         | 
| 207 | 
            +
             | 
| 208 | 
            +
                  allow_any_instance_of(Spree::CheckoutController).to receive_messages(current_order: order)
         | 
| 209 | 
            +
                  allow_any_instance_of(Spree::CheckoutController).to receive_messages(try_spree_current_user: order.user)
         | 
| 210 | 
            +
             | 
| 211 | 
            +
                  visit spree.checkout_state_path(:payment)
         | 
| 212 | 
            +
                end
         | 
| 213 | 
            +
             | 
| 214 | 
            +
                it 'the first payment method should be selected' do
         | 
| 215 | 
            +
                  payment_method_css = '#order_payments_attributes__payment_method_id_'
         | 
| 216 | 
            +
                  expect(find("#{payment_method_css}#{check_payment.id}")).to be_checked
         | 
| 217 | 
            +
                  expect(find("#{payment_method_css}#{credit_cart_payment.id}")).not_to be_checked
         | 
| 218 | 
            +
                end
         | 
| 219 | 
            +
             | 
| 220 | 
            +
                it 'the fields for the other payment methods should be hidden' do
         | 
| 221 | 
            +
                  payment_method_css = '#payment_method_'
         | 
| 222 | 
            +
                  expect(find("#{payment_method_css}#{check_payment.id}")).to be_visible
         | 
| 223 | 
            +
                  expect(find("#{payment_method_css}#{credit_cart_payment.id}")).not_to be_visible
         | 
| 224 | 
            +
                end
         | 
| 225 | 
            +
              end
         | 
| 226 | 
            +
             | 
| 227 | 
            +
              context 'user has payment sources', js: true do
         | 
| 228 | 
            +
                let(:bogus) { create(:credit_card_payment_method) }
         | 
| 229 | 
            +
                let(:user) { create(:user) }
         | 
| 230 | 
            +
             | 
| 231 | 
            +
                let!(:credit_card) do
         | 
| 232 | 
            +
                  create(:credit_card, user_id: user.id, payment_method: bogus, gateway_customer_profile_id: 'BGS-WEFWF')
         | 
| 233 | 
            +
                end
         | 
| 234 | 
            +
             | 
| 235 | 
            +
                before do
         | 
| 236 | 
            +
                  order = OrderWalkthrough.up_to(:payment)
         | 
| 237 | 
            +
                  allow(order).to receive_messages(available_payment_methods: [bogus])
         | 
| 238 | 
            +
             | 
| 239 | 
            +
                  allow_any_instance_of(Spree::CheckoutController).to receive_messages(current_order: order)
         | 
| 240 | 
            +
                  allow_any_instance_of(Spree::CheckoutController).to receive_messages(try_spree_current_user: user)
         | 
| 241 | 
            +
                  allow_any_instance_of(Spree::OrdersController).to receive_messages(try_spree_current_user: user)
         | 
| 242 | 
            +
             | 
| 243 | 
            +
                  visit spree.checkout_state_path(:payment)
         | 
| 244 | 
            +
                end
         | 
| 245 | 
            +
             | 
| 246 | 
            +
                it 'selects first source available and customer moves on' do
         | 
| 247 | 
            +
                  expect(find('#use_existing_card_yes')).to be_checked
         | 
| 248 | 
            +
             | 
| 249 | 
            +
                  expect { click_on 'Save and Continue' }.not_to change { Spree::CreditCard.count }
         | 
| 250 | 
            +
             | 
| 251 | 
            +
                  click_on 'Place Order'
         | 
| 252 | 
            +
                  expect(current_path).to match(spree.order_path(Spree::Order.last))
         | 
| 253 | 
            +
                end
         | 
| 254 | 
            +
             | 
| 255 | 
            +
                it 'allows user to enter a new source' do
         | 
| 256 | 
            +
                  choose 'use_existing_card_no'
         | 
| 257 | 
            +
             | 
| 258 | 
            +
                  fill_in 'Name on card', with: 'Spree Commerce'
         | 
| 259 | 
            +
                  fill_in 'Card Number', with: '4111111111111111'
         | 
| 260 | 
            +
                  fill_in 'card_expiry', with: '04 / 20'
         | 
| 261 | 
            +
                  fill_in 'Card Code', with: '123'
         | 
| 262 | 
            +
             | 
| 263 | 
            +
                  expect { click_on 'Save and Continue' }.to change { Spree::CreditCard.count }.by 1
         | 
| 264 | 
            +
             | 
| 265 | 
            +
                  click_on 'Place Order'
         | 
| 266 | 
            +
                  expect(current_path).to match(spree.order_path(Spree::Order.last))
         | 
| 267 | 
            +
                end
         | 
| 268 | 
            +
              end
         | 
| 269 | 
            +
             | 
| 270 | 
            +
              # regression for #2921
         | 
| 271 | 
            +
              context 'goes back from payment to add another item', js: true do
         | 
| 272 | 
            +
                let!(:bag) { create(:product, name: 'RoR Bag') }
         | 
| 273 | 
            +
             | 
| 274 | 
            +
                it 'transit nicely through checkout steps again' do
         | 
| 275 | 
            +
                  add_mug_to_cart
         | 
| 276 | 
            +
                  click_on 'Checkout'
         | 
| 277 | 
            +
                  fill_in 'order_email', with: 'test@example.com'
         | 
| 278 | 
            +
                  click_on 'Continue'
         | 
| 279 | 
            +
                  fill_in_address
         | 
| 280 | 
            +
                  click_on 'Save and Continue'
         | 
| 281 | 
            +
                  click_on 'Save and Continue'
         | 
| 282 | 
            +
                  expect(current_path).to eql(spree.checkout_state_path('payment'))
         | 
| 283 | 
            +
             | 
| 284 | 
            +
                  visit spree.root_path
         | 
| 285 | 
            +
                  click_link bag.name
         | 
| 286 | 
            +
                  click_button 'add-to-cart-button'
         | 
| 287 | 
            +
             | 
| 288 | 
            +
                  click_on 'Checkout'
         | 
| 289 | 
            +
                  click_on 'Save and Continue'
         | 
| 290 | 
            +
                  click_on 'Save and Continue'
         | 
| 291 | 
            +
                  click_on 'Save and Continue'
         | 
| 292 | 
            +
             | 
| 293 | 
            +
                  expect(current_path).to match(spree.order_path(Spree::Order.last))
         | 
| 294 | 
            +
                end
         | 
| 295 | 
            +
              end
         | 
| 296 | 
            +
             | 
| 297 | 
            +
              context 'from payment step customer goes back to cart', js: true do
         | 
| 298 | 
            +
                before do
         | 
| 299 | 
            +
                  add_mug_to_cart
         | 
| 300 | 
            +
                  click_on 'Checkout'
         | 
| 301 | 
            +
                  fill_in 'order_email', with: 'test@example.com'
         | 
| 302 | 
            +
                  click_on 'Continue'
         | 
| 303 | 
            +
                  fill_in_address
         | 
| 304 | 
            +
                  click_on 'Save and Continue'
         | 
| 305 | 
            +
                  click_on 'Save and Continue'
         | 
| 306 | 
            +
                  expect(current_path).to eql(spree.checkout_state_path('payment'))
         | 
| 307 | 
            +
                end
         | 
| 308 | 
            +
             | 
| 309 | 
            +
                context 'and updates line item quantity and try to reach payment page' do
         | 
| 310 | 
            +
                  let(:cart_quantity) { 3 }
         | 
| 311 | 
            +
                  before do
         | 
| 312 | 
            +
                    visit spree.cart_path
         | 
| 313 | 
            +
                    within '.cart-item-quantity' do
         | 
| 314 | 
            +
                      fill_in first('input')['name'], with: cart_quantity
         | 
| 315 | 
            +
                    end
         | 
| 316 | 
            +
             | 
| 317 | 
            +
                    click_on 'Update'
         | 
| 318 | 
            +
                  end
         | 
| 319 | 
            +
             | 
| 320 | 
            +
                  it 'redirects user back to address step' do
         | 
| 321 | 
            +
                    visit spree.checkout_state_path('payment')
         | 
| 322 | 
            +
                    expect(current_path).to eql(spree.checkout_state_path('address'))
         | 
| 323 | 
            +
                  end
         | 
| 324 | 
            +
             | 
| 325 | 
            +
                  it 'updates shipments properly through step address -> delivery transitions' do
         | 
| 326 | 
            +
                    visit spree.checkout_state_path('payment')
         | 
| 327 | 
            +
                    click_on 'Save and Continue'
         | 
| 328 | 
            +
                    click_on 'Save and Continue'
         | 
| 329 | 
            +
             | 
| 330 | 
            +
                    expect(Spree::InventoryUnit.count).to eq 1
         | 
| 331 | 
            +
                    expect(Spree::InventoryUnit.first.quantity).to eq cart_quantity
         | 
| 332 | 
            +
                  end
         | 
| 333 | 
            +
                end
         | 
| 334 | 
            +
             | 
| 335 | 
            +
                context 'and adds new product to cart and try to reach payment page' do
         | 
| 336 | 
            +
                  let!(:bag) { create(:product, name: 'RoR Bag') }
         | 
| 337 | 
            +
             | 
| 338 | 
            +
                  before do
         | 
| 339 | 
            +
                    visit spree.root_path
         | 
| 340 | 
            +
                    click_link bag.name
         | 
| 341 | 
            +
                    click_button 'add-to-cart-button'
         | 
| 342 | 
            +
                  end
         | 
| 343 | 
            +
             | 
| 344 | 
            +
                  it 'redirects user back to address step' do
         | 
| 345 | 
            +
                    visit spree.checkout_state_path('payment')
         | 
| 346 | 
            +
                    expect(current_path).to eql(spree.checkout_state_path('address'))
         | 
| 347 | 
            +
                  end
         | 
| 348 | 
            +
             | 
| 349 | 
            +
                  it 'updates shipments properly through step address -> delivery transitions' do
         | 
| 350 | 
            +
                    visit spree.checkout_state_path("payment")
         | 
| 351 | 
            +
                    click_on 'Save and Continue'
         | 
| 352 | 
            +
                    click_on 'Save and Continue'
         | 
| 353 | 
            +
             | 
| 354 | 
            +
                    expect(Spree::InventoryUnit.count).to eq 2
         | 
| 355 | 
            +
                  end
         | 
| 356 | 
            +
                end
         | 
| 357 | 
            +
              end
         | 
| 358 | 
            +
             | 
| 359 | 
            +
              context 'if coupon promotion, submits coupon along with payment', js: true do
         | 
| 360 | 
            +
                let!(:promotion) { Spree::Promotion.create(name: 'Huhuhu', code: 'huhu') }
         | 
| 361 | 
            +
                let!(:calculator) { Spree::Calculator::FlatPercentItemTotal.create(preferred_flat_percent: '10') }
         | 
| 362 | 
            +
                let!(:action) { Spree::Promotion::Actions::CreateItemAdjustments.create(calculator: calculator) }
         | 
| 363 | 
            +
             | 
| 364 | 
            +
                before do
         | 
| 365 | 
            +
                  promotion.actions << action
         | 
| 366 | 
            +
             | 
| 367 | 
            +
                  add_mug_to_cart
         | 
| 368 | 
            +
                  click_on 'Checkout'
         | 
| 369 | 
            +
             | 
| 370 | 
            +
                  fill_in 'order_email', with: 'test@example.com'
         | 
| 371 | 
            +
                  click_on 'Continue'
         | 
| 372 | 
            +
                  fill_in_address
         | 
| 373 | 
            +
                  click_on 'Save and Continue'
         | 
| 374 | 
            +
             | 
| 375 | 
            +
                  click_on 'Save and Continue'
         | 
| 376 | 
            +
                  expect(current_path).to eql(spree.checkout_state_path('payment'))
         | 
| 377 | 
            +
                end
         | 
| 378 | 
            +
             | 
| 379 | 
            +
                it 'makes sure payment reflects order total with discounts' do
         | 
| 380 | 
            +
                  fill_in 'Coupon Code', with: promotion.code
         | 
| 381 | 
            +
                  click_on 'Save and Continue'
         | 
| 382 | 
            +
             | 
| 383 | 
            +
                  expect(page).to have_content(promotion.name)
         | 
| 384 | 
            +
                  expect(Spree::Payment.first.amount.to_f).to eq Spree::Order.last.total.to_f
         | 
| 385 | 
            +
                end
         | 
| 386 | 
            +
             | 
| 387 | 
            +
                context 'invalid coupon' do
         | 
| 388 | 
            +
                  it 'doesnt create a payment record' do
         | 
| 389 | 
            +
                    fill_in 'Coupon Code', with: 'invalid'
         | 
| 390 | 
            +
                    click_on 'Save and Continue'
         | 
| 391 | 
            +
             | 
| 392 | 
            +
                    expect(Spree::Payment.count).to eq 0
         | 
| 393 | 
            +
                    expect(page).to have_content(Spree.t(:coupon_code_not_found))
         | 
| 394 | 
            +
                  end
         | 
| 395 | 
            +
                end
         | 
| 396 | 
            +
             | 
| 397 | 
            +
                context "doesn't fill in coupon code input" do
         | 
| 398 | 
            +
                  it 'advances just fine' do
         | 
| 399 | 
            +
                    click_on 'Save and Continue'
         | 
| 400 | 
            +
                    expect(current_path).to match(spree.order_path(Spree::Order.last))
         | 
| 401 | 
            +
                  end
         | 
| 402 | 
            +
                end
         | 
| 403 | 
            +
             | 
| 404 | 
            +
                context 'the promotion makes order free (downgrade it total to 0.0)' do
         | 
| 405 | 
            +
                  let(:promotion2) { Spree::Promotion.create(name: 'test-7450', code: 'test-7450') }
         | 
| 406 | 
            +
                  let(:calculator2) do
         | 
| 407 | 
            +
                    Spree::Calculator::FlatRate.create(preferences: { currency: 'USD', amount: BigDecimal.new('99999') })
         | 
| 408 | 
            +
                  end
         | 
| 409 | 
            +
                  let(:action2) { Spree::Promotion::Actions::CreateItemAdjustments.create(calculator: calculator2) }
         | 
| 410 | 
            +
             | 
| 411 | 
            +
                  before { promotion2.actions << action2 }
         | 
| 412 | 
            +
             | 
| 413 | 
            +
                  context 'user choose to pay by check' do
         | 
| 414 | 
            +
                    it 'move user to complete checkout step' do
         | 
| 415 | 
            +
                      fill_in 'Coupon Code', with: promotion2.code
         | 
| 416 | 
            +
                      click_on 'Save and Continue'
         | 
| 417 | 
            +
             | 
| 418 | 
            +
                      expect(page).to have_content(promotion2.name)
         | 
| 419 | 
            +
                      expect(Spree::Order.last.total.to_f).to eq(0)
         | 
| 420 | 
            +
                      expect(current_path).to match(spree.order_path(Spree::Order.last))
         | 
| 421 | 
            +
                    end
         | 
| 422 | 
            +
                  end
         | 
| 423 | 
            +
             | 
| 424 | 
            +
                  context 'user choose to pay by card' do
         | 
| 425 | 
            +
                    let(:bogus) { create(:credit_card_payment_method) }
         | 
| 426 | 
            +
                    before do
         | 
| 427 | 
            +
                      order = Spree::Order.last
         | 
| 428 | 
            +
                      allow(order).to receive_messages(available_payment_methods: [bogus])
         | 
| 429 | 
            +
                      allow_any_instance_of(Spree::CheckoutController).to receive_messages(current_order: order)
         | 
| 430 | 
            +
             | 
| 431 | 
            +
                      visit spree.checkout_state_path(:payment)
         | 
| 432 | 
            +
                    end
         | 
| 433 | 
            +
             | 
| 434 | 
            +
                    it 'move user to confirmation checkout step' do
         | 
| 435 | 
            +
                      fill_in 'Name on card', with: 'Spree Commerce'
         | 
| 436 | 
            +
                      fill_in 'Card Number', with: '4111111111111111'
         | 
| 437 | 
            +
                      fill_in 'card_expiry', with: '04 / 20'
         | 
| 438 | 
            +
                      fill_in 'Card Code', with: '123'
         | 
| 439 | 
            +
             | 
| 440 | 
            +
                      fill_in 'Coupon Code', with: promotion2.code
         | 
| 441 | 
            +
                      click_on 'Save and Continue'
         | 
| 442 | 
            +
             | 
| 443 | 
            +
                      expect(page).to have_content(promotion2.name)
         | 
| 444 | 
            +
                      expect(Spree::Order.last.total.to_f).to eq(0)
         | 
| 445 | 
            +
                      expect(current_path).to eql(spree.checkout_state_path('confirm'))
         | 
| 446 | 
            +
                    end
         | 
| 447 | 
            +
                  end
         | 
| 448 | 
            +
                end
         | 
| 449 | 
            +
              end
         | 
| 450 | 
            +
             | 
| 451 | 
            +
              context 'order has only payment step' do
         | 
| 452 | 
            +
                before do
         | 
| 453 | 
            +
                  create(:credit_card_payment_method)
         | 
| 454 | 
            +
                  @old_checkout_flow = Spree::Order.checkout_flow
         | 
| 455 | 
            +
                  Spree::Order.class_eval do
         | 
| 456 | 
            +
                    checkout_flow do
         | 
| 457 | 
            +
                      go_to_state :payment
         | 
| 458 | 
            +
                      go_to_state :confirm
         | 
| 459 | 
            +
                    end
         | 
| 460 | 
            +
                  end
         | 
| 461 | 
            +
             | 
| 462 | 
            +
                  allow_any_instance_of(Spree::Order).to receive_messages email: 'spree@commerce.com'
         | 
| 463 | 
            +
             | 
| 464 | 
            +
                  add_mug_to_cart
         | 
| 465 | 
            +
                  click_on 'Checkout'
         | 
| 466 | 
            +
                end
         | 
| 467 | 
            +
             | 
| 468 | 
            +
                after do
         | 
| 469 | 
            +
                  Spree::Order.checkout_flow(&@old_checkout_flow)
         | 
| 470 | 
            +
                end
         | 
| 471 | 
            +
             | 
| 472 | 
            +
                it 'goes right payment step and place order just fine' do
         | 
| 473 | 
            +
                  expect(current_path).to eq spree.checkout_state_path('payment')
         | 
| 474 | 
            +
             | 
| 475 | 
            +
                  choose 'Credit Card'
         | 
| 476 | 
            +
                  fill_in 'Name on card', with: 'Spree Commerce'
         | 
| 477 | 
            +
                  fill_in 'Card Number', with: '4111111111111111'
         | 
| 478 | 
            +
                  fill_in 'card_expiry', with: '04 / 20'
         | 
| 479 | 
            +
                  fill_in 'Card Code', with: '123'
         | 
| 480 | 
            +
                  click_button 'Save and Continue'
         | 
| 481 | 
            +
             | 
| 482 | 
            +
                  expect(current_path).to eq spree.checkout_state_path('confirm')
         | 
| 483 | 
            +
                  click_button 'Place Order'
         | 
| 484 | 
            +
                end
         | 
| 485 | 
            +
              end
         | 
| 486 | 
            +
             | 
| 487 | 
            +
              context 'save my address' do
         | 
| 488 | 
            +
                before do
         | 
| 489 | 
            +
                  stock_location.stock_items.update_all(count_on_hand: 1)
         | 
| 490 | 
            +
                  add_mug_to_cart
         | 
| 491 | 
            +
                end
         | 
| 492 | 
            +
             | 
| 493 | 
            +
                context 'as a guest' do
         | 
| 494 | 
            +
                  before do
         | 
| 495 | 
            +
                    Spree::Order.last.update_column(:email, 'test@example.com')
         | 
| 496 | 
            +
                    click_button 'Checkout'
         | 
| 497 | 
            +
                  end
         | 
| 498 | 
            +
             | 
| 499 | 
            +
                  it 'should not be displayed' do
         | 
| 500 | 
            +
                    expect(page).to_not have_css('[data-hook=save_user_address]')
         | 
| 501 | 
            +
                  end
         | 
| 502 | 
            +
                end
         | 
| 503 | 
            +
             | 
| 504 | 
            +
                context 'as a User' do
         | 
| 505 | 
            +
                  before do
         | 
| 506 | 
            +
                    user = create(:user)
         | 
| 507 | 
            +
                    Spree::Order.last.update_column :user_id, user.id
         | 
| 508 | 
            +
                    allow_any_instance_of(Spree::OrdersController).to receive_messages(try_spree_current_user: user)
         | 
| 509 | 
            +
                    allow_any_instance_of(Spree::CheckoutController).to receive_messages(try_spree_current_user: user)
         | 
| 510 | 
            +
                    click_button 'Checkout'
         | 
| 511 | 
            +
                  end
         | 
| 512 | 
            +
             | 
| 513 | 
            +
                  it 'should be displayed' do
         | 
| 514 | 
            +
                    expect(page).to have_css('[data-hook=save_user_address]')
         | 
| 515 | 
            +
                  end
         | 
| 516 | 
            +
                end
         | 
| 517 | 
            +
              end
         | 
| 518 | 
            +
             | 
| 519 | 
            +
              context 'when order is completed' do
         | 
| 520 | 
            +
                let!(:user) { create(:user) }
         | 
| 521 | 
            +
                let!(:order) { OrderWalkthrough.up_to(:payment) }
         | 
| 522 | 
            +
             | 
| 523 | 
            +
                before(:each) do
         | 
| 524 | 
            +
                  allow_any_instance_of(Spree::CheckoutController).to receive_messages(current_order: order)
         | 
| 525 | 
            +
                  allow_any_instance_of(Spree::CheckoutController).to receive_messages(try_spree_current_user: user)
         | 
| 526 | 
            +
                  allow_any_instance_of(Spree::OrdersController).to receive_messages(try_spree_current_user: user)
         | 
| 527 | 
            +
             | 
| 528 | 
            +
                  visit spree.checkout_state_path(:payment)
         | 
| 529 | 
            +
                  click_button 'Save and Continue'
         | 
| 530 | 
            +
                end
         | 
| 531 | 
            +
             | 
| 532 | 
            +
                it 'displays a thank you message' do
         | 
| 533 | 
            +
                  expect(page).to have_content(Spree.t(:thank_you_for_your_order))
         | 
| 534 | 
            +
                end
         | 
| 535 | 
            +
             | 
| 536 | 
            +
                it 'does not display a thank you message on that order future visits' do
         | 
| 537 | 
            +
                  visit spree.order_path(order)
         | 
| 538 | 
            +
                  expect(page).to_not have_content(Spree.t(:thank_you_for_your_order))
         | 
| 539 | 
            +
                end
         | 
| 540 | 
            +
              end
         | 
| 541 | 
            +
              context "order's address is outside the default included tax zone" do
         | 
| 542 | 
            +
                context "so that no taxation applies to its product" do
         | 
| 543 | 
            +
                  before do
         | 
| 544 | 
            +
                    usa = Spree::Country.find_by(name: 'United States of America')
         | 
| 545 | 
            +
                    north_america_zone = create(:zone,
         | 
| 546 | 
            +
                                                  name: 'North America',
         | 
| 547 | 
            +
                                                  kind: 'country',
         | 
| 548 | 
            +
                                                  default_tax: true).tap do |zone|
         | 
| 549 | 
            +
                      zone.members << create(:zone_member, zoneable: usa)
         | 
| 550 | 
            +
                    end
         | 
| 551 | 
            +
             | 
| 552 | 
            +
                    australia = create(:country,
         | 
| 553 | 
            +
                                         name: 'Australia',
         | 
| 554 | 
            +
                                         iso: 'AU',
         | 
| 555 | 
            +
                                         iso_name: 'AUSTRALIA',
         | 
| 556 | 
            +
                                         iso3: 'AUS',
         | 
| 557 | 
            +
                                         states_required: true).tap do |country|
         | 
| 558 | 
            +
                      country.states << create(:state,
         | 
| 559 | 
            +
                                                 name: 'New South Wales',
         | 
| 560 | 
            +
                                                 abbr: 'NSW')
         | 
| 561 | 
            +
                    end
         | 
| 562 | 
            +
                    australia_zone = create(:zone,
         | 
| 563 | 
            +
                                              name: 'Australia',
         | 
| 564 | 
            +
                                              kind: 'country',
         | 
| 565 | 
            +
                                              default_tax: false).tap do |zone|
         | 
| 566 | 
            +
                      zone.members << create(:zone_member, zoneable: australia)
         | 
| 567 | 
            +
                    end
         | 
| 568 | 
            +
             | 
| 569 | 
            +
                    default_tax_category = create(:tax_category, name: 'Default', is_default: true)
         | 
| 570 | 
            +
             | 
| 571 | 
            +
                    create(:shipping_method,
         | 
| 572 | 
            +
                             name: 'Default',
         | 
| 573 | 
            +
                             display_on: 'both',
         | 
| 574 | 
            +
                             zones: [australia_zone],
         | 
| 575 | 
            +
                             tax_category: default_tax_category).tap do |sm|
         | 
| 576 | 
            +
                      sm.calculator.preferred_amount = 10
         | 
| 577 | 
            +
                      sm.calculator.preferred_currency = Spree::Config[:currency]
         | 
| 578 | 
            +
                      sm.calculator.save
         | 
| 579 | 
            +
                    end
         | 
| 580 | 
            +
             | 
| 581 | 
            +
                    create(:tax_rate,
         | 
| 582 | 
            +
                             name: 'USA included',
         | 
| 583 | 
            +
                             amount: 0.23,
         | 
| 584 | 
            +
                             zone: north_america_zone,
         | 
| 585 | 
            +
                             tax_category: default_tax_category,
         | 
| 586 | 
            +
                             show_rate_in_label: true,
         | 
| 587 | 
            +
                             included_in_price: true)
         | 
| 588 | 
            +
             | 
| 589 | 
            +
                    create(:product, name: 'Spree Bag', price: 100, tax_category: default_tax_category)
         | 
| 590 | 
            +
                    create(:product, name: 'Spree T-Shirt', price: 100, tax_category: default_tax_category)
         | 
| 591 | 
            +
                  end
         | 
| 592 | 
            +
             | 
| 593 | 
            +
                  it "correctly displays other product taxless price which has been added to cart later" do
         | 
| 594 | 
            +
                    visit spree.root_path
         | 
| 595 | 
            +
             | 
| 596 | 
            +
                    click_link 'Spree Bag'
         | 
| 597 | 
            +
                    click_on 'Add To Cart'
         | 
| 598 | 
            +
                    click_on 'Checkout'
         | 
| 599 | 
            +
             | 
| 600 | 
            +
                    fill_in 'order_email', with: 'test@example.com'
         | 
| 601 | 
            +
             | 
| 602 | 
            +
                    within '#checkout_form_address' do
         | 
| 603 | 
            +
                      address = 'order_bill_address_attributes'
         | 
| 604 | 
            +
             | 
| 605 | 
            +
                      fill_in "#{address}_firstname", with: 'John'
         | 
| 606 | 
            +
                      fill_in "#{address}_lastname", with: 'Doe'
         | 
| 607 | 
            +
                      fill_in "#{address}_address1", with: '199 George Street'
         | 
| 608 | 
            +
                      fill_in "#{address}_city", with: 'Sydney'
         | 
| 609 | 
            +
                      select 'Australia', from: "#{address}_country_id"
         | 
| 610 | 
            +
                      select 'New South Wales', from: "#{address}_state_id"
         | 
| 611 | 
            +
                      fill_in "#{address}_zipcode", with: '2000'
         | 
| 612 | 
            +
                      fill_in "#{address}_phone", with: '123456789'
         | 
| 613 | 
            +
                    end
         | 
| 614 | 
            +
                    click_on 'Save and Continue'
         | 
| 615 | 
            +
             | 
| 616 | 
            +
                    visit spree.root_path
         | 
| 617 | 
            +
             | 
| 618 | 
            +
                    click_link 'Spree T-Shirt'
         | 
| 619 | 
            +
                    click_on 'Add To Cart'
         | 
| 620 | 
            +
             | 
| 621 | 
            +
                    expect(page).not_to have_content('$100.00')
         | 
| 622 | 
            +
             | 
| 623 | 
            +
                    page.all('td.cart-item-price').each do |line_item|
         | 
| 624 | 
            +
                      expect(line_item).to have_content('$81.30')
         | 
| 625 | 
            +
                    end
         | 
| 626 | 
            +
                  end
         | 
| 627 | 
            +
                end
         | 
| 628 | 
            +
              end
         | 
| 629 | 
            +
             | 
| 630 | 
            +
              context 'user has store credits', js: true do
         | 
| 631 | 
            +
                let(:bogus) { create(:credit_card_payment_method) }
         | 
| 632 | 
            +
                let(:store_credit_payment_method) { create(:store_credit_payment_method) }
         | 
| 633 | 
            +
                let(:user) { create(:user) }
         | 
| 634 | 
            +
                let(:order) { OrderWalkthrough.up_to(:payment) }
         | 
| 635 | 
            +
             | 
| 636 | 
            +
                let(:prepare_checkout!) do
         | 
| 637 | 
            +
                  order.update(user: user)
         | 
| 638 | 
            +
                  allow(order).to receive_messages(available_payment_methods: [bogus, store_credit_payment_method])
         | 
| 639 | 
            +
             | 
| 640 | 
            +
                  allow_any_instance_of(Spree::CheckoutController).to receive_messages(current_order: order)
         | 
| 641 | 
            +
                  allow_any_instance_of(Spree::CheckoutController).to receive_messages(try_spree_current_user: user)
         | 
| 642 | 
            +
                  allow_any_instance_of(Spree::OrdersController).to receive_messages(try_spree_current_user: user)
         | 
| 643 | 
            +
                  visit spree.checkout_state_path(:payment)
         | 
| 644 | 
            +
                end
         | 
| 645 | 
            +
             | 
| 646 | 
            +
                context 'when not all Store Credits are used' do
         | 
| 647 | 
            +
                  let!(:store_credit) { create(:store_credit, user: user) }
         | 
| 648 | 
            +
                  let!(:additional_store_credit) { create(:store_credit, user: user, amount: 13) }
         | 
| 649 | 
            +
             | 
| 650 | 
            +
                  before { prepare_checkout! }
         | 
| 651 | 
            +
             | 
| 652 | 
            +
                  it 'page has data for (multiple) Store Credits' do
         | 
| 653 | 
            +
                    expect(page).to have_selector('[data-hook="checkout_payment_store_credit_available"]')
         | 
| 654 | 
            +
                    expect(page).to have_selector('button[name="apply_store_credit"]')
         | 
| 655 | 
            +
             | 
| 656 | 
            +
                    amount = Spree::Money.new(store_credit.amount_remaining + additional_store_credit.amount_remaining)
         | 
| 657 | 
            +
                    expect(page).to have_content(Spree.t('store_credit.available_amount', amount: amount))
         | 
| 658 | 
            +
                  end
         | 
| 659 | 
            +
             | 
| 660 | 
            +
                  it 'apply store credits button should move checkout to next step if amount is sufficient' do
         | 
| 661 | 
            +
                    click_button 'Apply Store Credit'
         | 
| 662 | 
            +
                    expect(current_path).to eq spree.order_path(order)
         | 
| 663 | 
            +
                    expect(page).to have_content(Spree.t('order_processed_successfully'))
         | 
| 664 | 
            +
                  end
         | 
| 665 | 
            +
             | 
| 666 | 
            +
                  it 'apply store credits button should wait on payment step for other payment' do
         | 
| 667 | 
            +
                    store_credit.update(amount_used: 145)
         | 
| 668 | 
            +
                    additional_store_credit.update(amount_used: 12)
         | 
| 669 | 
            +
                    click_button 'Apply Store Credit'
         | 
| 670 | 
            +
             | 
| 671 | 
            +
                    expect(current_path).to eq spree.checkout_state_path(:payment)
         | 
| 672 | 
            +
                    amount = Spree::Money.new(store_credit.amount_remaining + additional_store_credit.amount_remaining)
         | 
| 673 | 
            +
                    remaining_amount = Spree::Money.new(order.total - amount.money.to_f)
         | 
| 674 | 
            +
                    expect(page).to have_content(Spree.t('store_credit.applicable_amount', amount: amount))
         | 
| 675 | 
            +
                    expect(page).to have_content(Spree.t('store_credit.additional_payment_needed', amount: remaining_amount))
         | 
| 676 | 
            +
                    expect(page).to have_content(Spree.t('store_credit.remove'))
         | 
| 677 | 
            +
                  end
         | 
| 678 | 
            +
             | 
| 679 | 
            +
                  context 'remove store credits payments' do
         | 
| 680 | 
            +
                    before do
         | 
| 681 | 
            +
                      store_credit.update(amount: 5)
         | 
| 682 | 
            +
                      additional_store_credit.update(amount: 5)
         | 
| 683 | 
            +
                      click_button 'Apply Store Credit'
         | 
| 684 | 
            +
                    end
         | 
| 685 | 
            +
                    it 'remove store credits button should remove store_credits' do
         | 
| 686 | 
            +
                      click_button 'Remove Store Credit'
         | 
| 687 | 
            +
                      expect(current_path).to eq spree.checkout_state_path(:payment)
         | 
| 688 | 
            +
                      expect(page).to have_content(Spree.t('store_credit.available_amount', amount: order.display_total_available_store_credit))
         | 
| 689 | 
            +
                      expect(page).to have_selector('button[name="apply_store_credit"]')
         | 
| 690 | 
            +
                    end
         | 
| 691 | 
            +
                  end
         | 
| 692 | 
            +
                end
         | 
| 693 | 
            +
             | 
| 694 | 
            +
                context 'when all Store Credits are used' do
         | 
| 695 | 
            +
                  let!(:store_credit) { create(:store_credit, user: user, amount_used: 150) }
         | 
| 696 | 
            +
             | 
| 697 | 
            +
                  before { prepare_checkout! }
         | 
| 698 | 
            +
             | 
| 699 | 
            +
                  it 'page has no data for Store Credits when all Store Credits are used' do
         | 
| 700 | 
            +
                    expect(page).to_not have_selector('[data-hook="checkout_payment_store_credit_available"]')
         | 
| 701 | 
            +
                    expect(page).to_not have_selector('button[name="apply_store_credit"]')
         | 
| 702 | 
            +
                  end
         | 
| 703 | 
            +
                end
         | 
| 704 | 
            +
              end
         | 
| 705 | 
            +
             | 
| 706 | 
            +
              def fill_in_address
         | 
| 707 | 
            +
                address = "order_bill_address_attributes"
         | 
| 708 | 
            +
                fill_in "#{address}_firstname", with: "Ryan"
         | 
| 709 | 
            +
                fill_in "#{address}_lastname", with: "Bigg"
         | 
| 710 | 
            +
                fill_in "#{address}_address1", with: "143 Swan Street"
         | 
| 711 | 
            +
                fill_in "#{address}_city", with: "Richmond"
         | 
| 712 | 
            +
                select country.name, from: "#{address}_country_id"
         | 
| 713 | 
            +
                select state.name, from: "#{address}_state_id"
         | 
| 714 | 
            +
                fill_in "#{address}_zipcode", with: "12345"
         | 
| 715 | 
            +
                fill_in "#{address}_phone", with: "(555) 555-5555"
         | 
| 716 | 
            +
              end
         | 
| 717 | 
            +
             | 
| 718 | 
            +
              def add_mug_to_cart
         | 
| 719 | 
            +
                visit spree.root_path
         | 
| 720 | 
            +
                click_link mug.name
         | 
| 721 | 
            +
                click_button "add-to-cart-button"
         | 
| 722 | 
            +
              end
         | 
| 723 | 
            +
            end
         |