tab/spec/controllers/requests_controller_spec.rb

57 lines
1.5 KiB
Ruby
Raw Normal View History

2017-01-09 15:46:43 +01:00
require 'rails_helper'
RSpec.describe RequestsController, type: :controller do
2019-05-31 04:01:43 +02:00
describe "accepting request" do
2017-01-09 15:46:43 +01:00
2019-05-31 04:01:43 +02:00
let(:request) { create(:request, amount: 10) }
context "a request" do
it "can be accepted by the debtor" do
debtor_balance = request.debtor.balance
creditor_balance = request.creditor.balance
sign_in request.debtor
post :confirm, params: { request_id: request.id }
request.reload
expect(request.status).to eq("confirmed")
expect(debtor_balance - 10).to eq(request.debtor.balance)
expect(creditor_balance + 10).to eq(request.creditor.balance)
end
it "can not be accepted by the creditor" do
debtor_balance = request.debtor.balance
creditor_balance = request.creditor.balance
sign_in request.creditor
post :confirm, params: { request_id: request.id }
request.reload
expect(request.status).to eq("open")
expect(debtor_balance).to eq(request.debtor.balance)
expect(creditor_balance).to eq(request.creditor.balance)
end
it "can not be accepted by the issuer" do
debtor_balance = request.debtor.balance
creditor_balance = request.creditor.balance
sign_in request.issuer
post :confirm, params: { request_id: request.id }
request.reload
expect(request.status).to eq("open")
expect(debtor_balance).to eq(request.debtor.balance)
expect(creditor_balance).to eq(request.creditor.balance)
end
end
end
2017-01-09 15:46:43 +01:00
end