-
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.
- Loading branch information
1 parent
bc758e0
commit cbd95ed
Showing
6 changed files
with
165 additions
and
4 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 |
---|---|---|
|
@@ -3,7 +3,8 @@ language: ruby | |
sudo: false | ||
|
||
rvm: | ||
- 2.1.1 | ||
- 2.3.1 | ||
- 2.2.5 | ||
- 1.9.3 | ||
- rbx-2.2.10 | ||
- jruby-19mode | ||
|
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module Grape | ||
module ActiveModelSerializers | ||
VERSION = '1.3.1' | ||
VERSION = '1.4.0' | ||
end | ||
end |
67 changes: 67 additions & 0 deletions
67
spec/grape-active_model_serializers/versioned_api_formatter_spec.rb
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
require 'spec_helper' | ||
require 'grape-active_model_serializers/formatter' | ||
|
||
describe Grape::Formatter::ActiveModelSerializers do | ||
describe 'with a versioned API' do | ||
subject { Grape::Formatter::ActiveModelSerializers } | ||
|
||
describe 'serializer options from namespace' do | ||
let(:app) { Class.new(Grape::API) } | ||
|
||
before do | ||
app.format :json | ||
app.formatter :json, Grape::Formatter::ActiveModelSerializers | ||
app.version 'v1', using: :param | ||
|
||
app.namespace('space') do |ns| | ||
ns.get('/', root: false, apiver: 'v1') do | ||
{ 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 | ||
end | ||
end | ||
|
||
describe '.fetch_serializer' do | ||
let(:user) { User.new(first_name: 'John', email: '[email protected]') } | ||
|
||
if Grape::Util.const_defined?('InheritableSetting') | ||
let(:endpoint) { Grape::Endpoint.new(Grape::Util::InheritableSetting.new, path: '/', method: 'foo', version: 'v1', root: false) } | ||
else | ||
let(:endpoint) { Grape::Endpoint.new({}, path: '/', method: 'foo', version: 'v1', root: false) } | ||
end | ||
|
||
let(:env) { { 'api.endpoint' => endpoint } } | ||
|
||
before do | ||
def endpoint.current_user | ||
@current_user ||= User.new(first_name: 'Current user') | ||
end | ||
|
||
def endpoint.default_serializer_options | ||
{ only: :only, except: :except } | ||
end | ||
end | ||
|
||
subject { described_class.fetch_serializer(user, env) } | ||
|
||
it { should be_a V1::UserSerializer } | ||
|
||
it 'should have correct scope set' do | ||
expect(subject.scope.current_user).to eq(endpoint.current_user) | ||
end | ||
|
||
it 'should read default serializer options' do | ||
expect(subject.instance_variable_get('@only')).to eq([:only]) | ||
expect(subject.instance_variable_get('@except')).to eq([:except]) | ||
end | ||
|
||
it 'should read serializer options like "root"' do | ||
expect(described_class.build_options_from_endpoint(endpoint).keys).to include :root | ||
end | ||
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module V1 | ||
class UserSerializer < ActiveModel::Serializer | ||
attributes :first_name, :last_name, :email | ||
end | ||
end |