Skip to content

Commit

Permalink
Merge pull request #1182 from jamesotron/json_show_action
Browse files Browse the repository at this point in the history
Add JSON format support in the show action.
  • Loading branch information
mshibuya committed Jun 4, 2012
2 parents 7bfad1a + 3c6d162 commit 8f4af62
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/rails_admin/config/actions/show.rb
Expand Up @@ -18,11 +18,13 @@ class Show < RailsAdmin::Config::Actions::Base

register_instance_option :controller do
Proc.new do
render @action.template_name
respond_to do |format|
format.json { render :json => @object }
format.html { render @action.template_name }
end
end
end


register_instance_option :link_icon do
'icon-info-sign'
end
Expand Down
18 changes: 18 additions & 0 deletions spec/integration/config/show/rails_admin_config_show_spec.rb
Expand Up @@ -13,6 +13,24 @@ def do_request
visit show_path(:model_name => "team", :id => team.id)
end

describe "JSON show view" do
before do
@player = FactoryGirl.create :player
visit uri
end

let(:uri) { show_path(:model_name => 'player', :id => @player.id, :format => :json) }
let(:body) { page.body }

it 'should create a JSON uri' do
uri.should == "/admin/player/#{@player.id}.json"
end

it 'should contain the JSONified object' do
body.should include(@player.to_json)
end
end

describe "compact_show_view" do

it 'should hide empty fields in show view by default' do
Expand Down

0 comments on commit 8f4af62

Please sign in to comment.