Permalink
Browse files

Don't double wrap ActiveRecord models returned in JSON (thanks dreamr).

Was returning {'post': {'post': { ... }}}
Now returns   {'post': { ... }}
  • Loading branch information...
1 parent 98cfaff commit d4cc7d78425ab653f64d8e2850aa32351f8adbf2 @xaviershay xaviershay committed Dec 3, 2010
@@ -38,7 +38,7 @@ def destroy
render :json => {
:undo_path => undo_admin_undo_item_path(undo_item),
:undo_message => undo_item.description,
- :comment => @comment
+ :comment => @comment.attributes
}.to_json
}
end
@@ -77,7 +77,7 @@ def destroy
render :json => {
:undo_path => undo_admin_undo_item_path(undo_item),
:undo_message => undo_item.description,
- :page => @page
+ :page => @page.attributes
}.to_json
}
end
@@ -77,8 +77,8 @@ def destroy
render :json => {
:undo_path => undo_admin_undo_item_path(undo_item),
:undo_message => undo_item.description,
- :post => @post
- }.to_json
+ :post => @post.attributes
+ }
}
end
end
@@ -19,7 +19,7 @@ def undo
format.json {
render :json => {
:message => item.complete_description,
- :obj => object
+ :obj => object.attributes
}
}
end
@@ -124,9 +124,9 @@ def do_delete
do_delete
end
- it("renders comment as json") do
+ it("renders json including a description of the comment") do
do_delete
- response.should contain(/#{Regexp.escape(@comment.to_json)}/)
+ JSON.parse(response.body)['undo_message'].should == 'hello'
end
end
end
@@ -161,9 +161,9 @@ def do_delete
do_delete
end
- it("renders post as json") do
+ it("renders json including a description of the post") do
do_delete
- response.should contain(/#{Regexp.escape(@post.to_json)}/)
+ JSON.parse(response.body)['undo_message'].should == 'hello'
end
end
end
@@ -35,7 +35,7 @@ def do_post
describe 'handling POST to undo accepting JSON' do
before do
@item = mock_model(UndoItem, :complete_description => "hello")
- @item.stub!(:process!)
+ @item.stub!(:process!).and_return(Post.new)
UndoItem.stub!(:find).and_return(@item)
end

0 comments on commit d4cc7d7

Please sign in to comment.