2015-09-12 13:03:04 +02:00
|
|
|
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 15:25:02 +02:00
|
|
|
debtor: @debtor.name,
|
2015-09-09 14:37:40 +02:00
|
|
|
creditor: @creditor.name,
|
2015-09-09 16:26:06 +02:00
|
|
|
cents: 70,
|
2015-09-12 13:03:04 +02:00
|
|
|
message: "hoi"
|
|
|
|
} }
|
2015-09-09 15:07:14 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should create a new transaction" do
|
2015-09-12 13:03:04 +02:00
|
|
|
expect { post :create, @attributes }.to change { Transaction.count }.by(1)
|
2015-09-09 15:07:14 +02:00
|
|
|
end
|
|
|
|
|
2015-09-11 16:11:56 +02:00
|
|
|
describe "fields" do
|
|
|
|
before :each do
|
|
|
|
post :create, @attributes
|
|
|
|
@transaction = Transaction.last
|
|
|
|
end
|
2015-09-09 15:07:14 +02:00
|
|
|
|
2015-09-11 16:11:56 +02:00
|
|
|
it "should set debtor" do
|
|
|
|
expect(@transaction.debtor).to eq(@debtor)
|
|
|
|
end
|
2015-09-09 15:07:14 +02:00
|
|
|
|
2015-09-11 16:11:56 +02:00
|
|
|
it "should set amount" do
|
|
|
|
expect(@transaction.amount).to eq(70)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should set creditor" do
|
|
|
|
expect(@transaction.creditor).to eq(@creditor)
|
|
|
|
end
|
2015-09-09 15:07:14 +02:00
|
|
|
|
2015-09-11 16:11:56 +02:00
|
|
|
it "should set issuer" do
|
|
|
|
expect(@transaction.issuer).to eq(@debtor)
|
|
|
|
end
|
2015-09-09 15:07:14 +02:00
|
|
|
end
|
2015-09-09 14:37:40 +02:00
|
|
|
end
|
2015-09-09 15:21:08 +02:00
|
|
|
|
2015-09-09 16:26:06 +02:00
|
|
|
context "with float euros" do
|
|
|
|
it "should set correct amount" do
|
|
|
|
post :create, transaction: {
|
|
|
|
debtor: @debtor.name,
|
|
|
|
creditor: @creditor.name,
|
|
|
|
euros: 10.5,
|
|
|
|
message: "Omdat je een leuke jongen bent!"
|
|
|
|
}
|
|
|
|
expect(Transaction.last.amount).to eq(1050)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-09 15:21:08 +02:00
|
|
|
context "with negative amount" do
|
|
|
|
it "should be refused" do
|
|
|
|
expect do
|
2015-09-09 16:26:06 +02:00
|
|
|
post :create, transaction: attributes_for(:transaction, cents: -20)
|
2015-09-12 13:03:04 +02:00
|
|
|
end.not_to change { Transaction.count }
|
2015-09-09 15:21:08 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "for other user" do
|
|
|
|
it "should be refused" do
|
|
|
|
expect do
|
|
|
|
post :create, transaction: {
|
2015-09-09 16:26:06 +02:00
|
|
|
debtor: @creditor.name,
|
|
|
|
creditor: @debtor.name,
|
2015-09-09 16:28:11 +02:00
|
|
|
euros: 10000000,
|
2015-09-12 13:03:04 +02:00
|
|
|
message: "DIT IS OVERVAL"
|
2015-09-09 15:21:08 +02:00
|
|
|
}
|
2015-09-12 13:03:04 +02:00
|
|
|
end.not_to change { Transaction.count }
|
2015-09-09 15:21:08 +02:00
|
|
|
end
|
|
|
|
end
|
2015-09-09 14:37:40 +02:00
|
|
|
end
|
2015-09-08 15:25:54 +02:00
|
|
|
end
|