Skip to content

Instantly share code, notes, and snippets.

@mattheworiordan
Created January 22, 2014 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattheworiordan/8562145 to your computer and use it in GitHub Desktop.
Save mattheworiordan/8562145 to your computer and use it in GitHub Desktop.
JSON view test example with shared _item.json partial
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