Skip to content

Instantly share code, notes, and snippets.

@narkai
Last active August 29, 2015 14:27
Show Gist options
  • Save narkai/c0a75d4e729a10fab928 to your computer and use it in GitHub Desktop.
Save narkai/c0a75d4e729a10fab928 to your computer and use it in GitHub Desktop.
json api request spec
require 'rails_helper'
describe "users", :type => :request do
describe 'users#create' do
context "when is successfully created" do
before(:each) do
params = {
data: {
type: "users",
attributes: {
name: "rian",
email: "[email protected]",
password: "rody"
}
}
}
headers = {
'Content-Type' => "application/vnd.api+json",
'Accept' => "application/vnd.api+json"
}
# post api_v1_users_path, params, headers
post "/api/v1/users", params, headers
end
it "responds with 200" do
p response
# expect(response).to be_success
end
end
end
end
@thibaudgg
Copy link

require 'rails_helper'

describe 'users', type: :request do
  describe 'POST /users' do
    context 'when is successfully created' do
      let(:params) {
        {
          data: {
            type: 'users',
            attributes: {
              name: 'rian',
              email: '[email protected]',
              password: 'rody'
            }
          }
        }.to_json
      }
      let(:headers) {
        {
          'Content-Type' => 'application/vnd.api+json',
          'Accept' => 'application/vnd.api+json'
        }
      }

      it 'responds with 200' do
        post api_v1_users_url, params, headers
        expect(response).to be_success
      end
    end
  end
end

@narkai
Copy link
Author

narkai commented Aug 10, 2015

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment