2015-09-08 15:25:54 +02:00
|
|
|
require 'rails_helper'
|
2015-09-09 15:07:14 +02:00
|
|
|
require 'spec_helper'
|
2015-09-08 15:25:54 +02:00
|
|
|
|
|
|
|
RSpec.describe TransactionsController, type: :controller do
|
2015-09-09 14:37:40 +02:00
|
|
|
describe "creating transaction" do
|
|
|
|
before :each do
|
|
|
|
@debtor = create(:user)
|
|
|
|
@creditor = create(:user)
|
|
|
|
sign_in @debtor
|
|
|
|
end
|
2015-09-08 15:25:54 +02:00
|
|
|
|
2015-09-09 15:07:14 +02:00
|
|
|
context "with valid attributes" do
|
|
|
|
before :each do
|
|
|
|
@attributes = { transaction: {
|
2015-09-09 14:37:40 +02:00
|
|
|
creditor: @creditor.name,
|
|
|
|
amount: 20,
|
2015-09-09 15:07:14 +02:00
|
|
|
message: 'hoi'
|
2015-09-09 14:37:40 +02:00
|
|
|
}}
|
2015-09-09 15:07:14 +02:00
|
|
|
post :create, @attributes
|
|
|
|
@transaction = Transaction.last
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should create a new transaction" do
|
|
|
|
expect {post :create, @attributes}.to change {Transaction.count}.by(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should set debtor" do
|
|
|
|
expect(@transaction.debtor).to eq(@debtor)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should set amount" do
|
|
|
|
expect(@transaction.amount).to eq(20)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should set creditor" do
|
|
|
|
expect(@transaction.creditor).to eq(@creditor)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should set issuer" do
|
|
|
|
expect(@transaction.issuer).to eq(@debtor)
|
|
|
|
end
|
2015-09-09 14:37:40 +02:00
|
|
|
end
|
2015-09-09 15:21:08 +02:00
|
|
|
|
|
|
|
context "with negative amount" do
|
|
|
|
it "should be refused" do
|
|
|
|
expect do
|
|
|
|
post :create, transaction: attributes_for(:transaction, amount: -20)
|
|
|
|
end.not_to change {Transaction.count}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "for other user" do
|
|
|
|
it "should be refused" do
|
|
|
|
expect do
|
|
|
|
post :create, transaction: {
|
|
|
|
debtor: @creditor,
|
|
|
|
creditor: @debtor,
|
|
|
|
amount: 10000000000000,
|
|
|
|
message: 'DIT IS OVERVAL'
|
|
|
|
}
|
|
|
|
end.not_to change {Transaction.count}
|
|
|
|
end
|
|
|
|
end
|
2015-09-09 14:37:40 +02:00
|
|
|
end
|
2015-09-08 15:25:54 +02:00
|
|
|
end
|