tab/spec/apis/transactions_controller_spec.rb

29 lines
739 B
Ruby
Raw Normal View History

2015-09-09 21:52:16 +02:00
describe TransactionsController, type: :api do
2015-09-10 11:39:52 +02:00
let(:api_attributes) do
{
debtor: create(:user).name,
creditor: create(:user).name,
message: Faker::Lorem.sentence,
euros: rand(2),
cents: 1 + rand(100)
}
end
2015-09-09 21:52:16 +02:00
before :each do
@client = Client.create name: "Tap"
@key = @client.key
end
describe "Authentication" do
it "should require a client authentication key" do
post '/transactions'
expect(last_response.status).to eq(401)
end
it "should work with valid key" do
2015-09-10 11:39:52 +02:00
post '/transactions', { transaction: api_attributes }, { 'HTTP_ACCEPT' => "application/json", "X_API_KEY" => @key }
2015-09-09 21:52:16 +02:00
expect(last_response.status).to eq(201)
end
end
end