Payment methods can be tagged

This commit is contained in:
Rob Harrington
2016-04-27 13:36:49 +10:00
parent 385fd91e70
commit 4d83bf2135
9 changed files with 78 additions and 36 deletions

View File

@@ -1 +1 @@
angular.module("admin.paymentMethods", [])
angular.module("admin.paymentMethods", ['ngTagsInput', 'admin.utils'])

View File

@@ -23,6 +23,10 @@ module Admin
admin_inject_json_ams_array "admin.paymentMethods", "paymentMethods", @payment_methods, Api::Admin::IdNameSerializer
end
def admin_inject_payment_method
admin_inject_json_ams "admin.paymentMethods", "paymentMethod", @payment_method, Api::Admin::PaymentMethodSerializer
end
def admin_inject_shipping_methods
admin_inject_json_ams_array "admin.shippingMethods", "shippingMethods", @shipping_methods, Api::Admin::IdNameSerializer
end

View File

@@ -0,0 +1,7 @@
module Spree
class Gateway::PayPalExpress < Gateway
# Something odd is happening with class inheritance here, this class (defined in spree_paypal_express gem)
# doesn't seem to pick up attr_accessible from the Gateway class, so we redefine the attrs we need here
attr_accessible :tag_list
end
end

View File

@@ -1,4 +1,5 @@
Spree::Gateway.class_eval do
acts_as_taggable
# Due to class load order, when config.cache_classes is enabled (ie. staging and production
# environments), this association isn't inherited from PaymentMethod. As a result, creating
@@ -12,4 +13,6 @@ Spree::Gateway.class_eval do
# Default to live
preference :server, :string, :default => 'live'
preference :test_mode, :boolean, :default => false
attr_accessible :tag_list
end

View File

@@ -1,8 +1,10 @@
Spree::PaymentMethod.class_eval do
acts_as_taggable
# See gateway_decorator.rb when modifying this association
has_and_belongs_to_many :distributors, join_table: 'distributors_payment_methods', :class_name => 'Enterprise', association_foreign_key: 'distributor_id'
attr_accessible :distributor_ids
attr_accessible :distributor_ids, :tag_list
calculated_adjustments

View File

@@ -1,6 +1,6 @@
/ replace "div[data-hook='admin_payment_method_form_fields']"
= render 'data'
= admin_inject_payment_method
%div.alpha.eleven.columns{ "ng-app" => "admin.paymentMethods", "ng-controller" => "paymentMethodCtrl" }
.row
.alpha.three.columns
@@ -34,6 +34,14 @@
= radio_button :payment_method, :active, false
&nbsp;
= label_tag nil, t(:say_no)
.row
.alpha.three.columns
= label(:payment_method, :tags, t(:tags))
.omega.eight.columns
= hidden_field(:payment_method, :tag_list, "ng-value" => "paymentMethod.tag_list")
%tags-with-translation#something{ object: "paymentMethod" }
= render 'providers'
.row

View File

@@ -0,0 +1,11 @@
class Api::Admin::PaymentMethodSerializer < ActiveModel::Serializer
attributes :id, :name, :type, :tag_list, :tags
def tag_list
object.tag_list.join(",")
end
def tags
object.tag_list.map{ |t| { text: t } }
end
end

View File

@@ -1,2 +0,0 @@
:javascript
angular.module('admin.paymentMethods').value('paymentMethod', #{ { id: @payment_method.id, type: @payment_method.type }.to_json })

View File

@@ -29,47 +29,53 @@ feature %q{
payment_method = Spree::PaymentMethod.find_by_name('Cheque payment method')
payment_method.distributors.should == [@distributors[0]]
end
end
scenario "updating a payment method" do
pm = create(:payment_method, distributors: [@distributors[0]])
login_to_admin_section
scenario "updating a payment method", js: true do
pm = create(:payment_method, distributors: [@distributors[0]])
login_to_admin_section
visit spree.edit_admin_payment_method_path pm
visit spree.edit_admin_payment_method_path pm
fill_in 'payment_method_name', :with => 'New PM Name'
fill_in 'payment_method_name', :with => 'New PM Name'
find(:css, "tags-input .tags input").set "member\n"
uncheck "payment_method_distributor_ids_#{@distributors[0].id}"
check "payment_method_distributor_ids_#{@distributors[1].id}"
check "payment_method_distributor_ids_#{@distributors[2].id}"
select2_select "PayPal Express", from: "payment_method_type"
expect(page).to have_field 'Login'
fill_in 'payment_method_preferred_login', with: 'testlogin'
fill_in 'payment_method_preferred_password', with: 'secret'
fill_in 'payment_method_preferred_signature', with: 'sig'
uncheck "payment_method_distributor_ids_#{@distributors[0].id}"
check "payment_method_distributor_ids_#{@distributors[1].id}"
check "payment_method_distributor_ids_#{@distributors[2].id}"
select2_select "PayPal Express", from: "payment_method_type"
expect(page).to have_field 'Login'
fill_in 'payment_method_preferred_login', with: 'testlogin'
fill_in 'payment_method_preferred_password', with: 'secret'
fill_in 'payment_method_preferred_signature', with: 'sig'
click_button 'Update'
click_button 'Update'
expect(flash_message).to eq 'Payment Method has been successfully updated!'
expect(flash_message).to eq 'Payment Method has been successfully updated!'
save_screenshot '/Users/rob/Desktop/ss.png'
payment_method = Spree::PaymentMethod.find_by_name('New PM Name')
expect(payment_method.distributors).to include @distributors[1], @distributors[2]
expect(payment_method.distributors).not_to include @distributors[0]
expect(payment_method.type).to eq "Spree::Gateway::PayPalExpress"
expect(payment_method.preferences[:login]).to eq 'testlogin'
expect(payment_method.preferences[:password]).to eq 'secret'
expect(payment_method.preferences[:signature]).to eq 'sig'
expect(first('tags-input .tag-list ti-tag-item')).to have_content "member"
fill_in 'payment_method_preferred_login', with: 'otherlogin'
click_button 'Update'
payment_method = Spree::PaymentMethod.find_by_name('New PM Name')
expect(payment_method.distributors).to include @distributors[1], @distributors[2]
expect(payment_method.distributors).not_to include @distributors[0]
expect(payment_method.type).to eq "Spree::Gateway::PayPalExpress"
expect(payment_method.preferences[:login]).to eq 'testlogin'
expect(payment_method.preferences[:password]).to eq 'secret'
expect(payment_method.preferences[:signature]).to eq 'sig'
expect(flash_message).to eq 'Payment Method has been successfully updated!'
expect(page).to have_field 'Password', with: ''
fill_in 'payment_method_preferred_login', with: 'otherlogin'
click_button 'Update'
payment_method = Spree::PaymentMethod.find_by_name('New PM Name')
expect(payment_method.preferences[:login]).to eq 'otherlogin'
expect(payment_method.preferences[:password]).to eq 'secret'
expect(payment_method.preferences[:signature]).to eq 'sig'
end
expect(flash_message).to eq 'Payment Method has been successfully updated!'
expect(page).to have_field 'Password', with: ''
expect(first('tags-input .tag-list ti-tag-item')).to have_content "member"
payment_method = Spree::PaymentMethod.find_by_name('New PM Name')
expect(payment_method.tag_list).to eq ["member"]
expect(payment_method.preferences[:login]).to eq 'otherlogin'
expect(payment_method.preferences[:password]).to eq 'secret'
expect(payment_method.preferences[:signature]).to eq 'sig'
end
context "as an enterprise user", js: true do
@@ -102,12 +108,15 @@ feature %q{
fill_in 'payment_method_name', :with => 'Cheque payment method'
check "payment_method_distributor_ids_#{distributor1.id}"
find(:css, "tags-input .tags input").set "local\n"
click_button 'Create'
flash_message.should == 'Payment Method has been successfully created!'
expect(first('tags-input .tag-list ti-tag-item')).to have_content "local"
payment_method = Spree::PaymentMethod.find_by_name('Cheque payment method')
payment_method.distributors.should == [distributor1]
payment_method.tag_list.should == ["local"]
end
it "shows me only payment methods I have access to" do