Fix tests

This commit is contained in:
redfast00 2019-04-10 16:14:02 +02:00
parent 4eb84e1c91
commit af08ce6a66
No known key found for this signature in database
GPG key ID: 5946E0E34FD0553C
6 changed files with 18 additions and 9 deletions

View file

@ -84,6 +84,7 @@ end
group :test do group :test do
gem 'coveralls', require: false gem 'coveralls', require: false
gem 'rails-controller-testing', require: false
end end
group :production do group :production do
@ -98,3 +99,4 @@ gem 'airbrake'
gem 'bootstrap-sass', '~> 3.3.5' gem 'bootstrap-sass', '~> 3.3.5'
gem 'react-rails', '~> 1.10.0' gem 'react-rails', '~> 1.10.0'
gem 'rolify' gem 'rolify'
gem 'rails-controller-testing'

View file

@ -212,6 +212,10 @@ GEM
bundler (>= 1.3.0) bundler (>= 1.3.0)
railties (= 5.2.0) railties (= 5.2.0)
sprockets-rails (>= 2.0.0) sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.4)
actionpack (>= 5.0.1.x)
actionview (>= 5.0.1.x)
activesupport (>= 5.0.1.x)
rails-dom-testing (2.0.3) rails-dom-testing (2.0.3)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
nokogiri (>= 1.6) nokogiri (>= 1.6)
@ -349,6 +353,7 @@ DEPENDENCIES
omniauth-oauth2 (~> 1.3.1) omniauth-oauth2 (~> 1.3.1)
purecss-rails purecss-rails
rails (= 5.2.0) rails (= 5.2.0)
rails-controller-testing
react-rails (~> 1.10.0) react-rails (~> 1.10.0)
rolify rolify
rspec-rails rspec-rails

View file

@ -8,12 +8,12 @@ describe TransactionsController, type: :controller do
context "with valid attributes" do context "with valid attributes" do
before :each do before :each do
@attributes = { transaction: { @attributes = { params: { transaction: {
debtor: @debtor.name, debtor: @debtor.name,
creditor: @creditor.name, creditor: @creditor.name,
cents: 70, cents: 70,
message: "hoi" message: "hoi"
} } } }}
end end
it "should create a new transaction" do it "should create a new transaction" do
@ -46,12 +46,12 @@ describe TransactionsController, type: :controller do
context "with float euros" do context "with float euros" do
it "should set correct amount" do it "should set correct amount" do
post :create, transaction: { post :create, params: { transaction: {
debtor: @debtor.name, debtor: @debtor.name,
creditor: @creditor.name, creditor: @creditor.name,
euros: 10.5, euros: 10.5,
message: "Omdat je een leuke jongen bent!" message: "Omdat je een leuke jongen bent!"
} }}
expect(Transaction.last.amount).to eq(1050) expect(Transaction.last.amount).to eq(1050)
end end
end end
@ -59,7 +59,7 @@ describe TransactionsController, type: :controller do
context "with negative amount" do context "with negative amount" do
it "should be refused" do it "should be refused" do
expect do expect do
post :create, transaction: attributes_for(:transaction, cents: -20) post :create, params: {transaction: attributes_for(:transaction, cents: -20)}
end.not_to change { Transaction.count } end.not_to change { Transaction.count }
end end
end end
@ -67,12 +67,12 @@ describe TransactionsController, type: :controller do
context "for other user" do context "for other user" do
it "should be refused" do it "should be refused" do
expect do expect do
post :create, transaction: { post :create, params:{ transaction: {
debtor: @creditor.name, debtor: @creditor.name,
creditor: @debtor.name, creditor: @debtor.name,
euros: 10000000, euros: 10000000,
message: "DIT IS OVERVAL" message: "DIT IS OVERVAL"
} }}
end.not_to change { Transaction.count } end.not_to change { Transaction.count }
end end
end end

View file

@ -6,7 +6,7 @@ describe UsersController, type: :controller do
describe "GET show" do describe "GET show" do
before :each do before :each do
get :show, id: @user get :show, params: {id: @user}
end end
it "should be successful" do it "should be successful" do

View file

@ -3,8 +3,8 @@ ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__) require File.expand_path('../../config/environment', __FILE__)
# Prevent database truncation if the environment is production # Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production? abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'spec_helper'
require 'rspec/rails' require 'rspec/rails'
require 'spec_helper'
# Add additional requires below this line. Rails is not loaded until this point! # Add additional requires below this line. Rails is not loaded until this point!
# Requires supporting ruby files with custom matchers and macros, etc, in # Requires supporting ruby files with custom matchers and macros, etc, in

View file

@ -1,4 +1,6 @@
# Coveralls integrations # Coveralls integrations
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'coveralls' require 'coveralls'
Coveralls.wear!('rails') Coveralls.wear!('rails')