mirror of
https://github.com/samsonjs/grape-active_model_serializers.git
synced 2026-04-27 14:57:43 +00:00
commit
c9bf16b1ce
1 changed files with 11 additions and 10 deletions
|
|
@ -7,6 +7,7 @@ require "grape-active_model_serializers"
|
||||||
|
|
||||||
describe Grape::ActiveModelSerializers do
|
describe Grape::ActiveModelSerializers do
|
||||||
let(:app) { Class.new(Grape::API) }
|
let(:app) { Class.new(Grape::API) }
|
||||||
|
subject { last_response.body }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
app.format :json
|
app.format :json
|
||||||
|
|
@ -19,7 +20,7 @@ describe Grape::ActiveModelSerializers do
|
||||||
User.new
|
User.new
|
||||||
end
|
end
|
||||||
get("/home/users")
|
get("/home/users")
|
||||||
last_response.headers["Content-Type"].should == "application/json"
|
expect(last_response.headers["Content-Type"]).to eql "application/json"
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'serializer is set to nil' do
|
context 'serializer is set to nil' do
|
||||||
|
|
@ -30,7 +31,7 @@ describe Grape::ActiveModelSerializers do
|
||||||
end
|
end
|
||||||
it 'uses the built in grape serializer' do
|
it 'uses the built in grape serializer' do
|
||||||
get("/home")
|
get("/home")
|
||||||
last_response.body.should == "{\"user\":{\"first_name\":\"JR\",\"last_name\":\"HE\"}}"
|
expect(subject).to eql "{\"user\":{\"first_name\":\"JR\",\"last_name\":\"HE\"}}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -43,7 +44,7 @@ describe Grape::ActiveModelSerializers do
|
||||||
|
|
||||||
it 'infers the serializer' do
|
it 'infers the serializer' do
|
||||||
get "/home"
|
get "/home"
|
||||||
last_response.body.should == "{\"user\":{\"first_name\":\"JR\",\"last_name\":\"HE\"}}"
|
expect(subject).to eql "{\"user\":{\"first_name\":\"JR\",\"last_name\":\"HE\"}}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -54,7 +55,7 @@ describe Grape::ActiveModelSerializers do
|
||||||
end
|
end
|
||||||
|
|
||||||
get "/users"
|
get "/users"
|
||||||
last_response.body.should == "{\"users\":[{\"first_name\":\"JR\",\"last_name\":\"HE\"},{\"first_name\":\"JR\",\"last_name\":\"HE\"}]}"
|
expect(subject).to eql "{\"users\":[{\"first_name\":\"JR\",\"last_name\":\"HE\"},{\"first_name\":\"JR\",\"last_name\":\"HE\"}]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
context "models with compound names" do
|
context "models with compound names" do
|
||||||
|
|
@ -64,7 +65,7 @@ describe Grape::ActiveModelSerializers do
|
||||||
end
|
end
|
||||||
|
|
||||||
get "/home"
|
get "/home"
|
||||||
last_response.body.should == "{\"blog_post\":{\"title\":\"Grape AM::S Rocks!\",\"body\":\"Really, it does.\"}}"
|
expect(subject).to eql "{\"blog_post\":{\"title\":\"Grape AM::S Rocks!\",\"body\":\"Really, it does.\"}}"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "generates the proper 'root' node for serialized arrays" do
|
it "generates the proper 'root' node for serialized arrays" do
|
||||||
|
|
@ -74,7 +75,7 @@ describe Grape::ActiveModelSerializers do
|
||||||
end
|
end
|
||||||
|
|
||||||
get "/blog_posts"
|
get "/blog_posts"
|
||||||
last_response.body.should == "{\"blog_posts\":[{\"title\":\"Grape AM::S Rocks!\",\"body\":\"Really, it does.\"},{\"title\":\"Grape AM::S Rocks!\",\"body\":\"Really, it does.\"}]}"
|
expect(subject).to eql "{\"blog_posts\":[{\"title\":\"Grape AM::S Rocks!\",\"body\":\"Really, it does.\"},{\"title\":\"Grape AM::S Rocks!\",\"body\":\"Really, it does.\"}]}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -86,7 +87,7 @@ describe Grape::ActiveModelSerializers do
|
||||||
end
|
end
|
||||||
|
|
||||||
get "/admin/jeff"
|
get "/admin/jeff"
|
||||||
last_response.body.should == "{\"user\":{\"first_name\":\"Jeff\",\"last_name\":null}}"
|
expect(subject).to eql "{\"user\":{\"first_name\":\"Jeff\",\"last_name\":null}}"
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'route is in a namespace' do
|
context 'route is in a namespace' do
|
||||||
|
|
@ -99,7 +100,7 @@ describe Grape::ActiveModelSerializers do
|
||||||
end
|
end
|
||||||
|
|
||||||
get "/admin/jeff"
|
get "/admin/jeff"
|
||||||
last_response.body.should == "{\"admin\":[{\"first_name\":\"Jeff\",\"last_name\":null},{\"first_name\":\"Jeff\",\"last_name\":null}]}"
|
expect(subject).to eql "{\"admin\":[{\"first_name\":\"Jeff\",\"last_name\":null},{\"first_name\":\"Jeff\",\"last_name\":null}]}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -111,7 +112,7 @@ describe Grape::ActiveModelSerializers do
|
||||||
end
|
end
|
||||||
|
|
||||||
get "/people"
|
get "/people"
|
||||||
last_response.body.should == "{\"people\":[{\"first_name\":\"Jeff\",\"last_name\":null},{\"first_name\":\"Jeff\",\"last_name\":null}]}"
|
expect(subject).to eql "{\"people\":[{\"first_name\":\"Jeff\",\"last_name\":null},{\"first_name\":\"Jeff\",\"last_name\":null}]}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue