-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Payments#index - use prebuilt action
- Loading branch information
1 parent
5d16081
commit 4b89f74
Showing
5 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
app/models/spree/admin/actions/payments_default_actions_builder.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module Spree | ||
module Admin | ||
module Actions | ||
class PaymentsDefaultActionsBuilder | ||
include Spree::Core::Engine.routes.url_helpers | ||
|
||
def build | ||
root = Root.new | ||
add_new_payment_action(root) | ||
root | ||
end | ||
|
||
private | ||
|
||
def add_new_payment_action(root) | ||
action = | ||
ActionBuilder.new(new_payment_config). | ||
with_availability_check( | ||
lambda do |ability, resource| | ||
ability.can?(:create, ::Spree::Payment) && resource.outstanding_balance? | ||
end | ||
). | ||
build | ||
|
||
root.add(action) | ||
end | ||
|
||
def new_payment_config | ||
{ | ||
icon_name: 'add.svg', | ||
key: :new_payment, | ||
url: ->(resource) { new_admin_order_payment_path(resource) }, | ||
classes: 'btn-success', | ||
id: 'new_payment_section' | ||
} | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
spec/models/spree/admin/actions/payments_default_actions_builder_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'spec_helper' | ||
|
||
module Spree | ||
module Admin | ||
describe Actions::PaymentsDefaultActionsBuilder, type: :model do | ||
let(:builder) { described_class.new } | ||
let(:default_actions) do | ||
[:new_payment] | ||
end | ||
|
||
describe '#build' do | ||
subject { builder.build } | ||
|
||
it 'builds default tabs' do | ||
expect(subject.items.map(&:key)).to match(default_actions) | ||
end | ||
end | ||
end | ||
end | ||
end |