Skip to content

Commit

Permalink
Merge pull request #3358 from mikz/patch-1
Browse files Browse the repository at this point in the history
Easier extending default show page
  • Loading branch information
seanlinsley committed Aug 30, 2014
2 parents 6d54d9d + e96f75e commit d4b4e7f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/active_admin/views/pages/show.rb
Expand Up @@ -43,8 +43,8 @@ def default_title
end

module DefaultMainContent
def default_main_content
attributes_table *default_attribute_table_rows
def default_main_content(&block)
attributes_table(*default_attribute_table_rows, &block)
end

def default_attribute_table_rows
Expand Down
15 changes: 14 additions & 1 deletion spec/unit/views/pages/show_spec.rb
Expand Up @@ -5,16 +5,29 @@
describe "the resource" do
let(:helpers) { double resource: resource }
let(:arbre_context) { Arbre::Context.new({}, helpers) }
subject(:page) { ActiveAdmin::Views::Pages::Show.new(arbre_context) }

context 'when the resource does not respond to #decorator' do
let(:resource) { 'Test Resource' }

it "normally returns the resource" do
page = ActiveAdmin::Views::Pages::Show.new(arbre_context)
expect(page.resource).to eq 'Test Resource'
end
end

context 'when you pass a block to main content' do
let(:block) { lambda { } }
let(:resource_class) { double(columns: [double('column', name: 'field')]) }
let(:resource) { double('resource', class: resource_class) }

before { allow(page).to receive(:active_admin_config).and_return(double(comments?: false))}

it 'appends it to the output' do
expect(page).to receive(:attributes_table).with(:field).and_yield
page.default_main_content(&block)
end
end

end

end

0 comments on commit d4b4e7f

Please sign in to comment.