-
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.
Variants#index - use prebuilt action
- Loading branch information
1 parent
cab307a
commit d41645f
Showing
5 changed files
with
74 additions
and
2 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
37 changes: 37 additions & 0 deletions
37
app/models/spree/admin/actions/variants_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,37 @@ | ||
module Spree | ||
module Admin | ||
module Actions | ||
class VariantsDefaultActionsBuilder | ||
include Spree::Core::Engine.routes.url_helpers | ||
|
||
def build | ||
root = Root.new | ||
add_new_variant_action(root) | ||
root | ||
end | ||
|
||
private | ||
|
||
def add_new_variant_action(root) | ||
action = | ||
ActionBuilder.new(new_variant_config). | ||
with_create_ability_check(::Spree::Variant). | ||
build | ||
|
||
root.add(action) | ||
end | ||
|
||
def new_variant_config | ||
{ | ||
icon_name: 'add.svg', | ||
key: :new_variant, | ||
url: ->(resource) { new_admin_product_variant_path(resource) }, | ||
classes: 'btn-success', | ||
id: 'new_var_link', | ||
data: { update: 'new_variant' } | ||
} | ||
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/variants_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::VariantsDefaultActionsBuilder, type: :model do | ||
let(:builder) { described_class.new } | ||
let(:default_actions) do | ||
[:new_variant] | ||
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 |