Skip to content

Instantly share code, notes, and snippets.

@iamajvillalobos
Created May 24, 2016 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamajvillalobos/bc6709444baa602ea1b6264d373f22d9 to your computer and use it in GitHub Desktop.
Save iamajvillalobos/bc6709444baa602ea1b6264d373f22d9 to your computer and use it in GitHub Desktop.
jsonapi controller sample test
require 'rails_helper'
RSpec.describe UsersController, type: :controller do
describe 'GET #index' do
it "populates an array of all users" do
christa = FactoryGirl.create(:user, name: "Christa")
jayne = FactoryGirl.create(:user, name: "Jayne")
get "index", nil, { 'Content-Type' => 'application/vnd.api+json' }
response_body = JSON.parse(response.body)
expect(response.status).to eq(200)
expect(response_body['data'].count).to eq 2
expect(response_body['data'].first['attributes']['name']).to eq("Christa")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment