Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Add a partial for the hash preference field #136

Merged
merged 2 commits into from
Nov 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/solidus_paypal_braintree.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'solidus_core'
require 'solidus_support'
require 'solidus_paypal_braintree/engine'
require 'solidus_paypal_braintree/country_mapper'
require 'solidus_paypal_braintree/request_protection'
Expand Down
22 changes: 11 additions & 11 deletions lib/solidus_paypal_braintree/engine.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'solidus_support'

module SolidusPaypalBraintree
class Engine < Rails::Engine
isolate_namespace SolidusPaypalBraintree
Expand All @@ -21,15 +23,7 @@ def self.activate

config.to_prepare(&method(:activate).to_proc)

def self.frontend_available?
defined?(Spree::Frontend::Engine) == "constant"
end

def self.backend_available?
defined?(Spree::Backend::Engine) == "constant"
end

if frontend_available?
if SolidusSupport.frontend_available?
config.assets.precompile += [
'solidus_paypal_braintree/checkout.js',
'solidus_paypal_braintree/frontend.js',
Expand All @@ -40,13 +34,19 @@ def self.backend_available?
paths["app/views"] << "lib/views/frontend"
end

if backend_available?
if SolidusSupport.backend_available?
config.assets.precompile += ["spree/backend/solidus_paypal_braintree.js"]
paths["app/controllers"] << "lib/controllers/backend"

# We support Solidus v1.2, which requires some different markup in the
# source form partial. This will take precedence over lib/views/backend.
paths["app/views"] << "lib/views/backend_v1.2" if Gem::Version.new(Spree.solidus_version) < Gem::Version.new('1.3')
paths["app/views"] << "lib/views/backend_v1.2" if SolidusSupport.solidus_gem_version < Gem::Version.new('1.3')

# Solidus v2.4 introduced preference field partials but does not ship a hash field type.
# This is solved in Solidus v2.5.
if SolidusSupport.solidus_gem_version <= Gem::Version.new('2.5.0')
paths["app/views"] << "lib/views/backend_v2.4"
end

paths["app/views"] << "lib/views/backend"
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<% label = local_assigns[:label].presence %>
<% html_options = {class: 'input_hash fullwidth'}.update(local_assigns[:html_options] || {}) %>

<div class="field">
<% if local_assigns[:form] %>
<%= form.label attribute, label %>
<%= form.text_area attribute, html_options %>
<% else %>
<%= label_tag name, label %>
<%= text_area_tag name, value, html_options %>
<% end %>
</div>
14 changes: 13 additions & 1 deletion spec/features/backend/configuration_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
require 'spec_helper'

RSpec.describe "viewing the configuration interface", js: true do
RSpec.describe "viewing the configuration interface" do
stub_authorization!

# Regression to ensure this page still renders on old versions of solidus
scenario "should not raise any errors due to unavailable route helpers" do
visit "/solidus_paypal_braintree/configurations/list"
expect(page).to have_content("Braintree Configurations")
end

# Regression to ensure this page renders on Solidus 2.4
scenario 'should not raise any errors due to unavailable preference field partial' do
Rails.application.config.spree.payment_methods << SolidusPaypalBraintree::Gateway
Spree::PaymentMethod.create!(
type: 'SolidusPaypalBraintree::Gateway',
name: 'Braintree Payments'
)
visit '/admin/payment_methods'
page.find('a[title="Edit"]').click
expect(page).to have_field 'Name', with: 'Braintree Payments'
end
end