Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'test_helper'
- class AccountsTest < ActionDispatch::IntegrationTest
- DEFAULT_HEAD = { "CONTENT_TYPE" => "application/json", "ACCEPTS" => "application/json" }
- def valid_account
- { account: FactoryGirl.attributes_for(:account) }
- end
- def head(options = {})
- DEFAULT_HEAD.merge options
- end
- def head_with_access_key(options = {}, access_key)
- head options.merge! "AUTHORIZATION" => "Token token=#{access_key}"
- end
- def body(hash = {})
- hash.to_json
- end
- test "POST /accounts returns status created" do
- post api_v1_accounts_path, body(valid_account), head
- expected = 201
- actual = response.status
- assert_equal expected, actual
- end
- test "POST /accounts returns account id" do
- post api_v1_accounts_path, body(valid_account), head
- account = Account.first
- expected = account.id
- actual = Oj.load(response.body)["account"]["id"]
- assert_equal(expected, actual)
- end
- test "POST /accounts returns account access key" do
- post api_v1_accounts_path, body(valid_account), head
- account = Account.first
- expected = account.access_key
- actual = Oj.load(response.body)["account"]["access_key"]
- assert_equal(expected, actual)
- end
- test "GET /accounts/:id returns status ok" do
- account = FactoryGirl.create :account
- get api_v1_account_path(account), nil, head_with_access_key(account.access_key)
- expected = 200
- actual = response.status
- assert_equal(expected, actual)
- end
- test "GET /accounts/:id returns account email" do
- account = FactoryGirl.create :account
- get api_v1_account_path(account), nil, head_with_access_key(account.access_key)
- expected = account.email
- actual = Oj.load(response.body)["account"]["email"]
- assert_equal(expected, actual)
- end
- test "GET /accounts/:id returns account name" do
- account = FactoryGirl.create :account
- get api_v1_account_path(account), nil, head_with_access_key(account.access_key)
- expected = account.name
- actual = Oj.load(response.body)["account"]["name"]
- assert_equal(expected, actual)
- end
- end
Add Comment
Please, Sign In to add comment