diff --git a/app/views/spree/shared/_paypal_cart_button.html.erb b/app/views/spree/shared/_paypal_cart_button.html.erb index cc7a1e20..c640f0c6 100644 --- a/app/views/spree/shared/_paypal_cart_button.html.erb +++ b/app/views/spree/shared/_paypal_cart_button.html.erb @@ -6,7 +6,15 @@ var paypalOptions = { flow: 'vault', enableShippingAddress: true, - environment: '<%= Rails.env.production? ? "production" : "sandbox" %>' + environment: '<%= Rails.env.production? ? "production" : "sandbox" %>', + locale: '<%= paypal_button_preference(:paypal_button_locale, store: current_store) %>', + style: { + color: '<%= paypal_button_preference(:paypal_button_color, store: current_store) %>', + size: '<%= paypal_button_preference(:paypal_button_size, store: current_store) %>', + shape: '<%= paypal_button_preference(:paypal_button_shape, store: current_store) %>', + label: '<%= paypal_button_preference(:paypal_button_label, store: current_store) %>', + tagline: '<%= paypal_button_preference(:paypal_button_tagline, store: current_store) %>' + } } var options = { restart_checkout: true diff --git a/config/initializers/braintree.rb b/config/initializers/braintree.rb index 77c51874..1f370736 100644 --- a/config/initializers/braintree.rb +++ b/config/initializers/braintree.rb @@ -4,4 +4,5 @@ if SolidusSupport.frontend_available? Spree::CheckoutController.helper :braintree_checkout + Spree::OrdersController.helper :braintree_checkout end diff --git a/spec/features/frontend/paypal_checkout_spec.rb b/spec/features/frontend/paypal_checkout_spec.rb index d223eb1c..a5c2a981 100644 --- a/spec/features/frontend/paypal_checkout_spec.rb +++ b/spec/features/frontend/paypal_checkout_spec.rb @@ -5,9 +5,11 @@ let!(:store) do create(:store, payment_methods: [payment_method]).tap do |s| - s.braintree_configuration.update!(paypal: true) + s.braintree_configuration.update!(braintree_preferences) end end + let(:braintree_preferences) { {paypal: true }.merge(paypal_options) } + let(:paypal_options) { {} } let!(:country) { create(:country, states_required: true) } let!(:state) { create(:state, country: country, abbr: "CA", name: "California") } @@ -34,21 +36,11 @@ end context 'using custom paypal button style' do - before do - store.braintree_configuration.tap do |conf| - conf.set_preference(:paypal_button_color, 'blue') - conf.save! - end - end + let(:paypal_options) { { preferred_paypal_button_color: 'blue' } } it 'should display required PayPal button style' do - pend_if_paypal_slow do - expect_any_instance_of(Spree::Order).to receive(:restart_checkout_flow) - move_through_paypal_popup - - within(find('#paypal-button iframe')) do - expect(page).to have_selector('[class="paypal-button-color-blue]') - end + within_frame find('#paypal-button iframe') do + expect(page).to have_selector('.paypal-button-color-blue') end end end diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index b52d6b70..a7852a4e 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -3,3 +3,18 @@ page.driver.browser.manage.window.resize_to(1600, 1024) end end + +# From Capybara gem - drivers.rb: +Capybara.register_driver :chrome_headless do |app| + Capybara::Selenium::Driver.load_selenium + browser_options = ::Selenium::WebDriver::Chrome::Options.new.tap do |opts| + opts.args << '--headless' + opts.args << '--disable-gpu' if Gem.win_platform? + end + Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options) +end + +Capybara.javascript_driver = :chrome_headless + +# You can enable the following to see the specs running +# Capybara.javascript_driver = :selenium_chrome