From a5dbe99d27d5d83c5c4ab4bd4da658f9772b77ed Mon Sep 17 00:00:00 2001 From: benji Date: Tue, 10 Mar 2015 08:52:16 +0100 Subject: [PATCH] Add tests for ordering and quickpay --- test/fixtures/users.yml | 20 +++++++++++------ test/integration/order_integration_test.rb | 25 ++++++++++++++++++---- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index fdb1fa1..a03ce63 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -29,14 +29,20 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html benji: - nickname: 'benji' - name: 'Benjamin' - last_name: 'Cousaert' + nickname: benji + name: Benjamin + last_name: Cousaert + dagschotel_id: 1 + +iasoon: + nickname: iasoon + name: Ilion + last_name: Beyst admin: - nickname: 'admin' - admin: 1 + nickname: admin + admin: 1 koelkast: - nickname: koelkast - koelkast: 1 + nickname: koelkast + koelkast: 1 diff --git a/test/integration/order_integration_test.rb b/test/integration/order_integration_test.rb index 3f87fe8..f2efda5 100644 --- a/test/integration/order_integration_test.rb +++ b/test/integration/order_integration_test.rb @@ -1,15 +1,16 @@ require 'test_helper' class OrderIntegrationTest < ActionDispatch::IntegrationTest - test 'orders are saved for the right user' do - allproducts = [products(:fanta), products(:cola), products(:mate), products(:bueno)] - - allproducts.each do |product| + def setup + Product.all.each do |product| product.avatar = File.new('public/seeds/products/fanta.jpg', 'r') product.save end sign_in users(:koelkast) + end + + test 'orders are saved for the right user' do visit new_user_order_path(users(:benji)) assert page.has_content? 'Order for benji' @@ -19,4 +20,20 @@ class OrderIntegrationTest < ActionDispatch::IntegrationTest click_button "Order!" end end + + test 'quickpay' do + assert_difference "User.find(users(:benji).id).balance_cents", -User.find(users(:benji).id).dagschotel.price_cents do + visit user_quickpay_path(users(:benji)) + assert page.has_content? 'Success!' + end + end + + test 'cancelling quickpay' do + visit user_quickpay_path(users(:benji)) + + assert_difference "User.find(users(:benji).id).balance_cents", User.find(users(:benji).id).dagschotel.price_cents do + click_link 'Undo' + assert page.has_content? 'Success!' + end + end end