Created
January 22, 2014 16:41
-
-
Save mattheworiordan/8562145 to your computer and use it in GitHub Desktop.
JSON view test example with shared _item.json partial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe 'JSON view test' do | |
let(:partial) { 'admin/case_studies/_item.json' } | |
let(:case_study) { build_stubbed(:case_study) } | |
it 'should render item partial' do | |
JSON.parse(render_item_partial).should == { | |
id: case_study.id, | |
title: case_study.title, | |
whatever: case_study.title | |
} | |
end | |
describe 'admin/case_studies/show.json' do | |
it 'should render item' do | |
assign :case_study, case_study | |
render | |
JSON.parse(rendered).should == JSON.parse(render_item_partial) | |
end | |
end | |
describe 'admin/case_studies/index.json' do | |
it 'should render items array' do | |
assign :case_studies, [case_study, case_study] | |
render | |
JSON.parse(rendered).should == JSON.parse("[#{render_item_partial},#{render_item_partial}]") | |
end | |
end | |
def render_item_partial | |
render :partial => partial, :locals => { :case_study => case_study } | |
rendered | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment