diff --git a/spec/controllers/transactions_controller_spec.rb b/spec/controllers/transactions_controller_spec.rb index 7ba1232..fd1135d 100644 --- a/spec/controllers/transactions_controller_spec.rb +++ b/spec/controllers/transactions_controller_spec.rb @@ -1,4 +1,5 @@ require 'rails_helper' +require 'spec_helper' RSpec.describe TransactionsController, type: :controller do describe "creating transaction" do @@ -8,14 +9,36 @@ RSpec.describe TransactionsController, type: :controller do sign_in @debtor end - it "should create a valid transaction" do - expect do - put :create, { transaction: { + context "with valid attributes" do + before :each do + @attributes = { transaction: { creditor: @creditor.name, amount: 20, - message: "hoi" + message: 'hoi' }} - end.to change {Transaction.count}.by(1) + 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 end end end