8000 be able to customize Tag resource form · activeadmin/activeadmin@591bf14 · GitHub
[go: up one dir, main page]

Skip to content

Commit 591bf14

Browse files
committed
be able to customize Tag resource form
#8439 improved form attributes rendering but introduced an issue if host app has an admin for Tag resource. The problem is that `tag` (`tag.attributes`) refences the resource and not the `TagHelper`. Let's prefix the call with `helpers`.
1 parent b2de8d6 commit 591bf14

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

features/edit_page.feature

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@ Feature: Edit Page
66
Given a category named "Music" exists
77
And a user named "John Doe" exists
88
And a post with the title "Hello World" written by "John Doe" exists
9+
And a tag named "Bugs" exists
910
And I am logged in
10-
And a configuration of:
11+
12+
Scenario: Default form with no config
13+
Given a configuration of:
1114
"""
1215
ActiveAdmin.register Post do
1316
permit_params :custom_category_id, :author_id, :title,
1417
:body, :position, :published_date, :starred
1518
end
1619
"""
1720
When I am on the index page for posts
18-
19-
Scenario: Default form with no config
20-
Given I follow "Edit"
21+
And I follow "Edit"
2122
Then the "Title" field should contain "Hello World"
2223
And the "Body" field should contain ""
2324
And the "Category" field should contain ""
@@ -47,6 +48,7 @@ Feature: Edit Page
4748
end
4849
end
4950
"""
51+
When I am on the index page for posts
5052
And I follow "Edit"
5153
Then I should see a fieldset titled "Your Post"
5254
And I should see a fieldset titled "Publishing"
@@ -76,6 +78,7 @@ Feature: Edit Page
7678
end
7779
end
7880
"""
81+
When I am on the index page for posts
7982
And I follow "New"
8083
Then I follow "Posts"
8184
And I follow "Edit"
@@ -107,6 +110,7 @@ Feature: Edit Page
107110
form partial: "form"
108111
end
109112
"""
113+
When I am on the index page for posts
110114
And I follow "Edit"
111115
Then the "Title" field should contain "Hello World"
112116
And the "Body" field should contain ""
@@ -115,3 +119,20 @@ Feature: Edit Page
115119
Then I should see "Post was successfully updated."
116120
And I should see the attribute "Title" with "Hello World from update"
117121
And I should see the attribute "Author" with "John Doe"
122+
123+
Scenario: Generating a custom form for Tag resource
124+
Given a configuration of:
125+
"""
126+
ActiveAdmin.register Tag do
127+
form do |f|
128+
f.inputs "Details" do
129+
f.input :name
130+
end
131+
f.actions
132+
end
133+
end
134+
"""
135+
When I am on the index page for tags
136+
And I follow "Edit"
137+
Then I should see a fieldset titled "Details"
138+
And the "Name" field should contain "Bugs"

features/step_definitions/factory_steps.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ def create_user(name, type = "User")
2828
Store.create! name: name
2929
end
3030

31+
Given /^a tag named "([^"]*)" exists$/ do |name|
32+
Tag.create! name: name
33+
end
34+
3135
Given /^I create a new post with the title "([^"]*)"$/ do |title|
3236
first(:link, "Posts").click
3337
click_on "New Post"

lib/active_admin/views/components/active_admin_form.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def build(form_builder, *args, &block)
131131
html_options[:class] ||= "inputs"
132132
legend = args.shift if args.first.is_a?(::String)
133133
legend = html_options.delete(:name) if html_options.key?(:name)
134-
legend_tag = legend ? tag.legend(legend, class: "fieldset-title") : ""
134+
legend_tag = legend ? helpers.tag.legend(legend, class: "fieldset-title") : ""
135135
fieldset_attrs = tag_attributes html_options
136136
@opening_tag = "<fieldset #{fieldset_attrs}>#{legend_tag}<ol>"
137137
@closing_tag = "</ol></fieldset>"
@@ -144,9 +144,9 @@ def tag_attributes(html_options)
144144
if Rails::VERSION::MAJOR <= 6
145145
# Reimplement tag.attributes to backport support for Rails 6.1.
146146
# TODO: this can be removed when support for Rails 6.x is dropped
147-
tag.tag_options(html_options.to_h).to_s.strip.html_safe
147+
helpers.tag.tag_options(html_options.to_h).to_s.strip.html_safe
148148
else
149-
tag.attributes html_options
149+
helpers.tag.attributes html_options
150150
end
151151
end
152152
end

0 commit comments

Comments
 (0)
0