-
Notifications
You must be signed in to change notification settings - Fork 64
Improve specs #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve specs #33
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,71 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe ActionController::Base do | ||
it 'exposes the deserialization mapping via the jsonapi_pointers method' do | ||
pointers = { id: '/data/id', type: '/data/type' } | ||
|
||
allow(subject).to receive(:request) do | ||
OpenStruct.new( | ||
env: { | ||
JSONAPI::Rails::ActionController::JSONAPI_POINTERS_KEY => pointers | ||
describe ActionController::Base, type: :controller do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Block has too many lines. [56/25] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Block has too many lines. [57/25] |
||
describe '.deserializable_resource' do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Block has too many lines. [28/25] |
||
controller do | ||
deserializable_resource :user | ||
|
||
def create | ||
render plain: 'ok' | ||
end | ||
end | ||
|
||
let(:payload) do | ||
{ | ||
_jsonapi: { | ||
'data' => { | ||
'type' => 'users', | ||
'attributes' => { 'foo' => 'bar', 'bar' => 'baz' } | ||
} | ||
} | ||
) | ||
} | ||
end | ||
|
||
expect(subject.send(:jsonapi_pointers)).to equal pointers | ||
it 'makes the deserialized resource available in params' do | ||
post :create, params: payload | ||
|
||
expected = { 'type' => 'users', 'foo' => 'bar', 'bar' => 'baz' } | ||
expect(controller.params[:user]).to eq(expected) | ||
end | ||
|
||
it 'makes the deserialization mapping available via #jsonapi_pointers' do | ||
post :create, params: payload | ||
|
||
expected = { foo: '/data/attributes/foo', | ||
bar: '/data/attributes/bar', | ||
type: '/data/type' } | ||
expect(controller.jsonapi_pointers).to eq(expected) | ||
end | ||
end | ||
|
||
describe '#render jsonapi:' do | ||
controller do | ||
def index | ||
serializer = Class.new(JSONAPI::Serializable::Resource) do | ||
type :users | ||
attribute :name | ||
end | ||
user = OpenStruct.new(id: 1, name: 'Lucas') | ||
|
||
render jsonapi: user, class: serializer | ||
end | ||
end | ||
|
||
subject { JSON.parse(response.body) } | ||
let(:serialized_user) do | ||
{ | ||
'data' => { | ||
'id' => '1', | ||
'type' => 'users', | ||
'attributes' => { 'name' => 'Lucas' } } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Closing hash brace must be on the line after the last hash element when opening brace is on a separate line from the first hash element. |
||
} | ||
end | ||
|
||
it 'renders a JSON API document' do | ||
get :index | ||
|
||
expect(response.content_type).to eq('application/vnd.api+json') | ||
is_expected.to eq(serialized_user) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'rails_helper' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing magic comment # frozen_string_literal: true. |
||
|
||
describe JSONAPI::Rails::Railtie do | ||
it 'registers the JSON API MIME type' do | ||
expect(Mime[:jsonapi]).to eq('application/vnd.api+json') | ||
end | ||
|
||
it 'registers the params parser for the JSON API MIME type' do | ||
expect(::ActionDispatch::Request.parameter_parsers[:jsonapi]).not_to be_nil | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block has too many lines. [30/25]