-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from drn/line-length-linter
Solve line length linter issues.
- Loading branch information
Showing
7 changed files
with
109 additions
and
31 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
inherit_from: .rubocop_todo.yml | ||
|
||
AllCops: | ||
Exclude: | ||
- Guardfile | ||
- grape-active_model_serializers.gemspec |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,25 +15,34 @@ | |
|
||
app.namespace('space') do |ns| | ||
ns.get('/', root: false, apiver: 'v1') do | ||
{ user: { first_name: 'JR', last_name: 'HE', email: '[email protected]' } } | ||
{ | ||
user: { | ||
first_name: 'JR', | ||
last_name: 'HE', | ||
email: '[email protected]' | ||
} | ||
} | ||
end | ||
end | ||
end | ||
|
||
it 'should read serializer options like "root"' do | ||
expect(described_class.build_options_from_endpoint(app.endpoints.first)).to include :root | ||
expect( | ||
described_class.build_options_from_endpoint(app.endpoints.first) | ||
).to include(:root) | ||
end | ||
end | ||
|
||
describe '.fetch_serializer' do | ||
let(:user) { User.new(first_name: 'John', email: '[email protected]') } | ||
|
||
let(:params) { { path: '/', method: 'foo', version: 'v1', root: false } } | ||
if Grape::Util.const_defined?('InheritableSetting') | ||
let(:endpoint) { Grape::Endpoint.new(Grape::Util::InheritableSetting.new, path: '/', method: 'foo', version: 'v1', root: false) } | ||
let(:setting) { Grape::Util::InheritableSetting.new } | ||
else | ||
let(:endpoint) { Grape::Endpoint.new({}, path: '/', method: 'foo', version: 'v1', root: false) } | ||
let(:setting) { {} } | ||
end | ||
|
||
let(:endpoint) { Grape::Endpoint.new(setting, params) } | ||
let(:env) { { 'api.endpoint' => endpoint } } | ||
|
||
before do | ||
|
@@ -49,7 +58,7 @@ def endpoint.default_serializer_options | |
let(:options) { described_class.build_options(user, env) } | ||
subject { described_class.fetch_serializer(user, options) } | ||
|
||
let(:instance_options) { subject.instance_variable_get(:@instance_options) } | ||
let(:instance_options) { subject.send(:instance_options) } | ||
|
||
it { should be_a V1::UserSerializer } | ||
|
||
|
@@ -63,7 +72,9 @@ def endpoint.default_serializer_options | |
end | ||
|
||
it 'should read serializer options like "root"' do | ||
expect(described_class.build_options_from_endpoint(endpoint).keys).to include :root | ||
expect( | ||
described_class.build_options_from_endpoint(endpoint).keys | ||
).to include(:root) | ||
end | ||
end | ||
end | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,31 +31,48 @@ | |
end | ||
it 'uses the built in grape serializer' do | ||
get('/home') | ||
expect(subject).to eql "{\"user\":{\"first_name\":\"JR\",\"last_name\":\"HE\"}}" | ||
expect(subject).to eq( | ||
'{"user":{"first_name":"JR","last_name":"HE"}}' | ||
) | ||
end | ||
end | ||
|
||
context "serializer isn't set" do | ||
before do | ||
app.get('/home') do | ||
User.new(first_name: 'JR', last_name: 'HE', email: '[email protected]') | ||
User.new( | ||
first_name: 'JR', | ||
last_name: 'HE', | ||
email: '[email protected]' | ||
) | ||
end | ||
end | ||
|
||
it 'infers the serializer' do | ||
get '/home' | ||
expect(subject).to eql "{\"user\":{\"first_name\":\"JR\",\"last_name\":\"HE\"}}" | ||
expect(subject).to eq( | ||
'{"user":{"first_name":"JR","last_name":"HE"}}' | ||
) | ||
end | ||
end | ||
|
||
it 'serializes arrays of objects' do | ||
app.get('/users') do | ||
user = User.new(first_name: 'JR', last_name: 'HE', email: '[email protected]') | ||
user = User.new( | ||
first_name: 'JR', | ||
last_name: 'HE', | ||
email: '[email protected]' | ||
) | ||
[user, user] | ||
end | ||
|
||
get '/users' | ||
expect(subject).to eql "{\"users\":[{\"first_name\":\"JR\",\"last_name\":\"HE\"},{\"first_name\":\"JR\",\"last_name\":\"HE\"}]}" | ||
expect(subject).to eq( | ||
'{"users":['\ | ||
'{"first_name":"JR","last_name":"HE"},'\ | ||
'{"first_name":"JR","last_name":"HE"}'\ | ||
']}' | ||
) | ||
end | ||
|
||
context 'models with compound names' do | ||
|
@@ -65,17 +82,29 @@ | |
end | ||
|
||
get '/home' | ||
expect(subject).to eql "{\"blog_post\":{\"title\":\"Grape AM::S Rocks!\",\"body\":\"Really, it does.\"}}" | ||
expect(subject).to eq( | ||
'{"blog_post":'\ | ||
'{"title":"Grape AM::S Rocks!","body":"Really, it does."}'\ | ||
'}' | ||
) | ||
end | ||
|
||
it "generates the proper 'root' node for serialized arrays" do | ||
app.get('/blog_posts') do | ||
blog_post = BlogPost.new(title: 'Grape AM::S Rocks!', body: 'Really, it does.') | ||
blog_post = BlogPost.new( | ||
title: 'Grape AM::S Rocks!', | ||
body: 'Really, it does.' | ||
) | ||
[blog_post, blog_post] | ||
end | ||
|
||
get '/blog_posts' | ||
expect(subject).to eql "{\"blog_posts\":[{\"title\":\"Grape AM::S Rocks!\",\"body\":\"Really, it does.\"},{\"title\":\"Grape AM::S Rocks!\",\"body\":\"Really, it does.\"}]}" | ||
expect(subject).to eq( | ||
'{"blog_posts":['\ | ||
'{"title":"Grape AM::S Rocks!","body":"Really, it does."},'\ | ||
'{"title":"Grape AM::S Rocks!","body":"Really, it does."}'\ | ||
']}' | ||
) | ||
end | ||
end | ||
|
||
|
@@ -87,7 +116,9 @@ | |
end | ||
|
||
get '/admin/jeff' | ||
expect(subject).to eql "{\"user\":{\"first_name\":\"Jeff\",\"last_name\":null}}" | ||
expect(subject).to eq( | ||
'{"user":{"first_name":"Jeff","last_name":null}}' | ||
) | ||
end | ||
|
||
context 'route is in a namespace' do | ||
|
@@ -100,7 +131,12 @@ | |
end | ||
|
||
get '/admin/jeff' | ||
expect(subject).to eql "{\"admin\":[{\"first_name\":\"Jeff\",\"last_name\":null},{\"first_name\":\"Jeff\",\"last_name\":null}]}" | ||
expect(subject).to eq( | ||
'{"admin":['\ | ||
'{"first_name":"Jeff","last_name":null},'\ | ||
'{"first_name":"Jeff","last_name":null}'\ | ||
']}' | ||
) | ||
end | ||
end | ||
|
||
|
@@ -112,7 +148,12 @@ | |
end | ||
|
||
get '/people' | ||
expect(subject).to eql "{\"people\":[{\"first_name\":\"Jeff\",\"last_name\":null},{\"first_name\":\"Jeff\",\"last_name\":null}]}" | ||
expect(subject).to eq( | ||
'{"people":['\ | ||
'{"first_name":"Jeff","last_name":null},'\ | ||
'{"first_name":"Jeff","last_name":null}'\ | ||
']}' | ||
) | ||
end | ||
end | ||
end |