Skip to content
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
4 changes: 2 additions & 2 deletions app/helpers/rails_admin_next/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def breadcrumb(action = @action, _acc = [])
content_tag(:li, class: ["breadcrumb-item", current_action?(a, am, o) && "active"]) do
if current_action?(a, am, o)
wording_for(:breadcrumb, a, am, o)
elsif a.http_methods.include?(:get)
elsif a.linkable?
link_to rails_admin_next.url_for(action: a.action_name, controller: "rails_admin_next/main", model_name: am.try(:to_param), id: o.try(:persisted?) && o.try(:id) || nil) do
wording_for(:breadcrumb, a, am, o)
end
Expand All @@ -159,7 +159,7 @@ def breadcrumb(action = @action, _acc = [])
# parent => :root, :collection, :member
# perf matters here (no action view trickery)
def menu_for(parent, abstract_model = nil, object = nil, only_icon = false)
actions = actions(parent, abstract_model, object).select { |a| a.http_methods.include?(:get) && a.show_in_menu }
actions = actions(parent, abstract_model, object).select { |a| a.linkable? && a.show_in_menu }
actions.collect do |action|
wording = wording_for(:menu, action)
li_class = ["nav-item", "icon", "#{action.key}_#{parent}_link"]
Expand Down
7 changes: 7 additions & 0 deletions lib/rails_admin_next/config/actions/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ class Base

# Off API.

# Whether visiting the action's URL performs it, so it can be rendered as a
# plain link rather than a button. Verbs are host-supplied, so they may be
# written as :GET or "get".
def linkable?
http_methods.include?(:get) || http_methods.any? { |verb| verb.to_s.casecmp?("get") }
end

def key
self.class.key
end
Expand Down
13 changes: 13 additions & 0 deletions spec/helpers/rails_admin_next/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,19 @@
expect(helper.menu_for(:root)).not_to match(/Dashboard/)
end

it "includes actions whose verbs name GET in any case" do
RailsAdminNext.config do |config|
config.actions do
dashboard do
http_methods %i[GET]
end
end
end

@action = RailsAdminNext::Config::Actions.find :dashboard
expect(helper.menu_for(:root)).to match(/Dashboard/)
end

it "shows actions which are marked as show_in_menu" do
I18n.backend.store_translations(
:en, admin: {actions: {
Expand Down
34 changes: 34 additions & 0 deletions spec/rails_admin_next/config/actions/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,38 @@
expect(RailsAdminNext::Config::Actions.find(:delete, controller: double(authorized?: true), abstract_model: RailsAdminNext::AbstractModel.new(ReadOnlyComment), object: ReadOnlyComment.new)).to be_nil
end
end

describe "#linkable?" do
def index_action
RailsAdminNext::Config::Actions.find(:index, controller: double(authorized?: true), abstract_model: RailsAdminNext::AbstractModel.new(Player))
end

it "is true for the default GET-only action" do
expect(index_action).to be_linkable
end

it "is true when the verb is written as an uppercase symbol" do
RailsAdminNext.config do |config|
config.actions { index { http_methods %i[GET] } }
end

expect(index_action).to be_linkable
end

it "is true when the verb is written as a string" do
RailsAdminNext.config do |config|
config.actions { index { http_methods %w[get] } }
end

expect(index_action).to be_linkable
end

it "is false without a GET among the verbs" do
RailsAdminNext.config do |config|
config.actions { index { http_methods %i[post put] } }
end

expect(index_action).not_to be_linkable
end
end
end