8000 Merge pull request #4940 from ajw725/attributes-table-title · parse/activeadmin@be4d7ba · GitHub
[go: up one dir, main page]

Skip to content

Commit be4d7ba

Browse files
Merge pull request activeadmin#4940 from ajw725/attributes-table-title
Attributes table title
2 parents d1ce9c2 + b543866 commit be4d7ba

File tree

4 files changed

+80
-1
lines changed

4 files changed

+80
-1
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
# Changelog
2+
3+
## Master (unreleased)
4+
5+
### Enhancements
6+
7+
##### Minor
8+
9+
* Allow custom panel title given with `attributes_table` [#4940][] by [@ajw725][]
10+
211
## 1.0.0 [](https://github.com/activeadmin/activeadmin/compare/v0.6.3...master)
312

413
### Breaking Changes
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
Feature: Show - Attributes Table Title
2+
3+
Modifying the title of the panel wrapping the attributes table
4+
5+
Background:
6+
Given a post with the title "Hello World" written by "Jane Doe" exists
7+
8+
Scenario: Set a string as the title
9+
Given a show configuration of:
10+
"""
11+
ActiveAdmin.register Post do
12+
show do
13+
attributes_table title: "Title From String"
14+
end
15+
end
16+
"""
17+
Then I should see the panel title "Title From String"
18+
And I should see the attributes table
19+
20+
Scenario: Set a method to be called on the resource as the title
21+
Given a show configuration of:
22+
"""
23+
ActiveAdmin.register Post do
24+
show do
25+
attributes_table title: :title
26+
end
27+
end
28+
"""
29+
Then I should see the panel title "Hello World"
30+
And I should see the attributes table
31+
32+
Scenario: Set a proc as the title
33+
Given a show configuration of:
34+
"""
35+
ActiveAdmin.register Post do
36+
show do
37+
attributes_table title: proc{ |post| "Title: #{post.title}" }
38+
end
39+
end
40+
"""
41+
Then I should see the panel title "Title: Hello World"
42+
And I should see the attributes table
43+
44+
Scenario: Should not accept other keys
45+
Given a show configuration of:
46+
"""
47+
ActiveAdmin.register Post do
48+
show do
49+
attributes_table foo: "Title From String"
50+
end
51+
end
52+
"""
53+
Then I should not see the panel title "Title From String"
54+
And I should see the attributes table
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Then /^I should see the panel title "([^"]*)"$/ do |title|
2+
expect(page).to have_css '.panel > h3', text: title
3+
end
4+
5+
Then /^I should not see the panel title "([^"]*)"$/ do |title|
6+
expect(page).to_not have_css '.panel > h3', text: title
7+
end
8+
9+
Then /^I should see the attributes table$/ do
10+
expect(page).to have_css '.panel .attributes_table'
11+
end

lib/active_admin/views/pages/show.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ def main_content
2525
end
2626

2727
def attributes_table(*args, &block)
28-
table_title = ActiveAdmin::Localizers.resource(active_admin_config).t(:details)
28+
opts = args.extract_options!
29+
table_title = if opts.has_key?(:title)
30+
render_or_call_method_or_proc_on(resource, opts[:title])
31+
else
32+
ActiveAdmin::Localizers.resource(active_admin_config).t(:details)
33+
end
2934
panel(table_title) do
3035
attributes_table_for resource, *args, &block
3136
end

0 commit comments

Comments
 (0)
0