From af08ce6a66f72dfdf79a9dfe8cc36ad5925c58ff Mon Sep 17 00:00:00 2001 From: redfast00 Date: Wed, 10 Apr 2019 16:14:02 +0200 Subject: [PATCH] Fix tests --- Gemfile | 2 ++ Gemfile.lock | 5 +++++ spec/controllers/transactions_controller_spec.rb | 14 +++++++------- spec/controllers/users_controller_spec.rb | 2 +- spec/rails_helper.rb | 2 +- spec/spec_helper.rb | 2 ++ 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Gemfile b/Gemfile index dca9a05..a8d3d0b 100644 --- a/Gemfile +++ b/Gemfile @@ -84,6 +84,7 @@ end group :test do gem 'coveralls', require: false + gem 'rails-controller-testing', require: false end group :production do @@ -98,3 +99,4 @@ gem 'airbrake' gem 'bootstrap-sass', '~> 3.3.5' gem 'react-rails', '~> 1.10.0' gem 'rolify' +gem 'rails-controller-testing' diff --git a/Gemfile.lock b/Gemfile.lock index 82f2258..2c828e6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -212,6 +212,10 @@ GEM bundler (>= 1.3.0) railties (= 5.2.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) activesupport (>= 4.2.0) nokogiri (>= 1.6) @@ -349,6 +353,7 @@ DEPENDENCIES omniauth-oauth2 (~> 1.3.1) purecss-rails rails (= 5.2.0) + rails-controller-testing react-rails (~> 1.10.0) rolify rspec-rails diff --git a/spec/controllers/transactions_controller_spec.rb b/spec/controllers/transactions_controller_spec.rb index 6fe6ffe..3c30281 100644 --- a/spec/controllers/transactions_controller_spec.rb +++ b/spec/controllers/transactions_controller_spec.rb @@ -8,12 +8,12 @@ describe TransactionsController, type: :controller do context "with valid attributes" do before :each do - @attributes = { transaction: { + @attributes = { params: { transaction: { debtor: @debtor.name, creditor: @creditor.name, cents: 70, message: "hoi" - } } + } }} end it "should create a new transaction" do @@ -46,12 +46,12 @@ describe TransactionsController, type: :controller do context "with float euros" do it "should set correct amount" do - post :create, transaction: { + post :create, params: { 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 @@ -59,7 +59,7 @@ describe TransactionsController, type: :controller do context "with negative amount" do it "should be refused" 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 end @@ -67,12 +67,12 @@ describe TransactionsController, type: :controller do context "for other user" do it "should be refused" do expect do - post :create, transaction: { + post :create, params:{ transaction: { debtor: @creditor.name, creditor: @debtor.name, euros: 10000000, message: "DIT IS OVERVAL" - } + }} end.not_to change { Transaction.count } end end diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index d04c829..d2390fc 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -6,7 +6,7 @@ describe UsersController, type: :controller do describe "GET show" do before :each do - get :show, id: @user + get :show, params: {id: @user} end it "should be successful" do diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 3f05163..b4f8620 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -3,8 +3,8 @@ ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) # Prevent database truncation if the environment is production abort("The Rails environment is running in production mode!") if Rails.env.production? -require 'spec_helper' require 'rspec/rails' +require 'spec_helper' # Add additional requires below this line. Rails is not loaded until this point! # Requires supporting ruby files with custom matchers and macros, etc, in diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 503f526..0361e72 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,6 @@ # Coveralls integrations +require File.expand_path("../../config/environment", __FILE__) +require 'rspec/rails' require 'coveralls' Coveralls.wear!('rails')