From ae28317b07ff12c1c0d72ebd83f7590ca1d186bc Mon Sep 17 00:00:00 2001 From: benji Date: Wed, 2 Sep 2015 20:33:35 +0200 Subject: [PATCH] Remove minitest and add rspec with factories --- .rspec | 3 + Gemfile | 8 +- Gemfile.lock | 27 ++++- app/models/product.rb | 3 +- app/models/user.rb | 3 +- .../factories/order_items.rb | 7 +- spec/factories/orders.rb | 22 ++++ .../factories/products.rb | 37 +++---- .../users.yml => spec/factories/users.rb | 26 ++--- spec/models/order_item_spec.rb | 9 ++ .../orders.yml => spec/models/order_spec.rb | 10 +- .../models/product_spec.rb | 20 ++-- .../user_test.rb => spec/models/user_spec.rb | 15 ++- spec/rails_helper.rb | 52 +++++++++ spec/spec_helper.rb | 101 ++++++++++++++++++ test/controllers/.keep | 0 test/controllers/admins_controller_test.rb | 7 -- test/controllers/callbacks_controller_test.rb | 7 -- test/controllers/orders_controller_test.rb | 7 -- test/controllers/products_controller_test.rb | 4 - test/controllers/sessions_controller_test.rb | 7 -- test/controllers/stock_controller_test.rb | 7 -- test/controllers/users_controller_test.rb | 4 - test/controllers/welcome_controller_test.rb | 7 -- test/fixtures/.keep | 0 test/helpers/.keep | 0 test/integration/.keep | 0 test/integration/generate_order_items_test.rb | 19 ---- test/integration/order_integration_test.rb | 39 ------- test/integration/product_attributes_test.rb | 20 ---- test/integration/stock_test.rb | 16 --- test/integration/stock_validator_test.rb | 12 --- test/mailers/.keep | 0 test/models/.keep | 0 test/models/order_test.rb | 29 ----- test/models/stock_entry_test.rb | 7 -- test/test_helper.rb | 30 ------ 37 files changed, 274 insertions(+), 291 deletions(-) create mode 100644 .rspec rename test/fixtures/order_items.yml => spec/factories/order_items.rb (71%) create mode 100644 spec/factories/orders.rb rename test/fixtures/products.yml => spec/factories/products.rb (55%) rename test/fixtures/users.yml => spec/factories/users.rb (74%) create mode 100644 spec/models/order_item_spec.rb rename test/fixtures/orders.yml => spec/models/order_spec.rb (66%) rename test/models/product_test.rb => spec/models/product_spec.rb (66%) rename test/models/user_test.rb => spec/models/user_spec.rb (78%) create mode 100644 spec/rails_helper.rb create mode 100644 spec/spec_helper.rb delete mode 100644 test/controllers/.keep delete mode 100644 test/controllers/admins_controller_test.rb delete mode 100644 test/controllers/callbacks_controller_test.rb delete mode 100644 test/controllers/orders_controller_test.rb delete mode 100644 test/controllers/products_controller_test.rb delete mode 100644 test/controllers/sessions_controller_test.rb delete mode 100644 test/controllers/stock_controller_test.rb delete mode 100644 test/controllers/users_controller_test.rb delete mode 100644 test/controllers/welcome_controller_test.rb delete mode 100644 test/fixtures/.keep delete mode 100644 test/helpers/.keep delete mode 100644 test/integration/.keep delete mode 100644 test/integration/generate_order_items_test.rb delete mode 100644 test/integration/order_integration_test.rb delete mode 100644 test/integration/product_attributes_test.rb delete mode 100644 test/integration/stock_test.rb delete mode 100644 test/integration/stock_validator_test.rb delete mode 100644 test/mailers/.keep delete mode 100644 test/models/.keep delete mode 100644 test/models/order_test.rb delete mode 100644 test/models/stock_entry_test.rb delete mode 100644 test/test_helper.rb diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..a472683 --- /dev/null +++ b/.rspec @@ -0,0 +1,3 @@ +--color +--require spec_helper +--require rails_helper diff --git a/Gemfile b/Gemfile index 05f47fb..3997cb2 100644 --- a/Gemfile +++ b/Gemfile @@ -37,7 +37,10 @@ end group :test do gem 'capybara' gem 'launchy' - gem "codeclimate-test-reporter", require: nil + gem 'codeclimate-test-reporter', require: nil + gem 'rspec-rails' + gem 'factory_girl_rails' + gem 'faker', '1.4.2' end group :development do @@ -60,9 +63,6 @@ end # Airbrake gem 'airbrake' -# Generate seed data -gem 'faker', '1.4.2' - # Debug stuff gem 'byebug' diff --git a/Gemfile.lock b/Gemfile.lock index db4f0ce..5349d13 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -112,9 +112,15 @@ GEM responders thread_safe (~> 0.1) warden (~> 1.2.3) + diff-lcs (1.2.5) docile (1.1.5) erubis (2.7.0) execjs (2.3.0) + factory_girl (4.5.0) + activesupport (>= 3.0.0) + factory_girl_rails (4.5.0) + factory_girl (~> 4.5.0) + railties (>= 3.0.0) faker (1.4.2) i18n (~> 0.5) faraday (0.9.1) @@ -222,6 +228,23 @@ GEM ffi (~> 1.9) mime-types (>= 1.16, < 3.0) netrc (~> 0.7) + rspec-core (3.3.2) + rspec-support (~> 3.3.0) + rspec-expectations (3.3.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.3.0) + rspec-mocks (3.3.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.3.0) + rspec-rails (3.3.3) + actionpack (>= 3.0, < 4.3) + activesupport (>= 3.0, < 4.3) + railties (>= 3.0, < 4.3) + rspec-core (~> 3.3.0) + rspec-expectations (~> 3.3.0) + rspec-mocks (~> 3.3.0) + rspec-support (~> 3.3.0) + rspec-support (3.3.0) sass (3.2.19) sass-rails (4.0.5) railties (>= 4.0.0, < 5.0) @@ -298,6 +321,7 @@ DEPENDENCIES coffee-rails (~> 4.0.0) coveralls devise + factory_girl_rails faker (= 1.4.2) identicon jbuilder (~> 2.0) @@ -309,6 +333,7 @@ DEPENDENCIES paperclip rails (= 4.2) responders (~> 2.0) + rspec-rails sass-rails (~> 4.0.3) sdoc (~> 0.4.0) spring @@ -320,4 +345,4 @@ DEPENDENCIES will_paginate (= 3.0.7) BUNDLED WITH - 1.10.5 + 1.10.6 diff --git a/app/models/product.rb b/app/models/product.rb index 64d4bf4..1481c36 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -13,7 +13,8 @@ # avatar_updated_at :datetime # category :integer default("0") # stock :integer default("0"), not null -# calories :integer default("0") // expressed in kcal +# calories :integer +# deleted :boolean default("f") # class Product < ActiveRecord::Base diff --git a/app/models/user.rb b/app/models/user.rb index 8160ac8..91b3b25 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -22,7 +22,8 @@ # koelkast :boolean default("f") # provider :string # uid :string -# encrypted_password :string +# encrypted_password :string default(""), not null +# private :boolean default("f") # require 'identicon' diff --git a/test/fixtures/order_items.yml b/spec/factories/order_items.rb similarity index 71% rename from test/fixtures/order_items.yml rename to spec/factories/order_items.rb index 5236ccc..70ce515 100644 --- a/test/fixtures/order_items.yml +++ b/spec/factories/order_items.rb @@ -8,4 +8,9 @@ # count :integer default("0") # -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html +FactoryGirl.define do + factory :order_item do + order + product + end +end diff --git a/spec/factories/orders.rb b/spec/factories/orders.rb new file mode 100644 index 0000000..33a0ccd --- /dev/null +++ b/spec/factories/orders.rb @@ -0,0 +1,22 @@ +# == Schema Information +# +# Table name: orders +# +# id :integer not null, primary key +# user_id :integer +# price_cents :integer +# created_at :datetime not null +# updated_at :datetime not null +# cancelled :boolean default("f") +# + +require 'faker' + +FactoryGirl.define do + factory :order do + user + before(:create) do |order| + order.order_items << build(:order_item, order: order) + end + end +end diff --git a/test/fixtures/products.yml b/spec/factories/products.rb similarity index 55% rename from test/fixtures/products.yml rename to spec/factories/products.rb index fc33fd8..e5eab1b 100644 --- a/test/fixtures/products.yml +++ b/spec/factories/products.rb @@ -13,30 +13,19 @@ # avatar_updated_at :datetime # category :integer default("0") # stock :integer default("0"), not null +# calories :integer +# deleted :boolean default("f") # -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html +require 'faker' +require 'identicon' -fanta: - id: 1 - name: 'Fanta' - price_cents: 60 - stock: 100 - -cola: - id: 2 - name: 'Cola' - price_cents: 60 - stock: 0 - -mate: - id: 3 - name: 'Club Mate' - price_cents: 120 - stock: 100 - -bueno: - id: 4 - name: 'Kinder Bueno' - stock: 50 - price_cents: 120 +FactoryGirl.define do + factory :product do + name { Faker::Name.name } + price_cents { rand 120 } + stock { rand 30 } + calories { rand 20 } + avatar { Identicon.data_url_for name } + end +end diff --git a/test/fixtures/users.yml b/spec/factories/users.rb similarity index 74% rename from test/fixtures/users.yml rename to spec/factories/users.rb index 52b2bd9..bbff558 100644 --- a/test/fixtures/users.yml +++ b/spec/factories/users.rb @@ -22,22 +22,16 @@ # koelkast :boolean default("f") # provider :string # uid :string -# encrypted_password :string +# encrypted_password :string default(""), not null +# private :boolean default("f") # -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html +require 'faker' +require 'identicon' -benji: - uid: benji - dagschotel_id: 1 - -iasoon: - uid: iasoon - -admin: - uid: admin - admin: 1 - -koelkast: - uid: koelkast - koelkast: 1 +FactoryGirl.define do + factory :user do + uid { Faker::Name.name } + avatar { Identicon.data_url_for uid } + end +end diff --git a/spec/models/order_item_spec.rb b/spec/models/order_item_spec.rb new file mode 100644 index 0000000..eb08bd1 --- /dev/null +++ b/spec/models/order_item_spec.rb @@ -0,0 +1,9 @@ +describe OrderItem do + before :each do + @order_item = create :order_item + end + + it 'has a valid factory' do + expect(@order_item).to be_valid + end +end diff --git a/test/fixtures/orders.yml b/spec/models/order_spec.rb similarity index 66% rename from test/fixtures/orders.yml rename to spec/models/order_spec.rb index f000b4a..b71e006 100644 --- a/test/fixtures/orders.yml +++ b/spec/models/order_spec.rb @@ -10,4 +10,12 @@ # cancelled :boolean default("f") # -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html +describe Order do + before :each do + @order = create :order + end + + it 'has a valid factory' do + expect(@order).to be_valid + end +end diff --git a/test/models/product_test.rb b/spec/models/product_spec.rb similarity index 66% rename from test/models/product_test.rb rename to spec/models/product_spec.rb index d5e391f..68b0a90 100644 --- a/test/models/product_test.rb +++ b/spec/models/product_spec.rb @@ -13,20 +13,16 @@ # avatar_updated_at :datetime # category :integer default("0") # stock :integer default("0"), not null +# calories :integer +# deleted :boolean default("f") # -require 'test_helper' +describe Product do + before :each do + @product = create :product + end -class ProductTest < ActiveSupport::TestCase - test "price behaves correctly" do - p = products(:fanta) - - assert_equal p.price_cents, 60 - assert_equal p.price, 0.6 - - p.price = 1.3 - - assert_equal p.price, 1.3 - assert_equal p.price_cents, 130 + it 'has a valid factory' do + expect(@product).to be_valid end end diff --git a/test/models/user_test.rb b/spec/models/user_spec.rb similarity index 78% rename from test/models/user_test.rb rename to spec/models/user_spec.rb index a783767..3dfa9b2 100644 --- a/test/models/user_test.rb +++ b/spec/models/user_spec.rb @@ -22,17 +22,16 @@ # koelkast :boolean default("f") # provider :string # uid :string -# encrypted_password :string +# encrypted_password :string default(""), not null +# private :boolean default("f") # -require 'test_helper' - -class UserTest < ActiveSupport::TestCase - def setup - @user = users(:benji) +describe User do + before :each do + @user = create :user end - test "to_param" do - assert_equal @user.to_param, "#{@user.id}-benji" + it 'has a valid factory' do + expect(@user).to be_valid end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb new file mode 100644 index 0000000..88ff2d0 --- /dev/null +++ b/spec/rails_helper.rb @@ -0,0 +1,52 @@ +# This file is copied to spec/ when you run 'rails generate rspec:install' +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' +# Add additional requires below this line. Rails is not loaded until this point! + +# Requires supporting ruby files with custom matchers and macros, etc, in +# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are +# run as spec files by default. This means that files in spec/support that end +# in _spec.rb will both be required and run as specs, causing the specs to be +# run twice. It is recommended that you do not name files matching this glob to +# end with _spec.rb. You can configure this pattern with the --pattern +# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. +# +# The following line is provided for convenience purposes. It has the downside +# of increasing the boot-up time by auto-requiring all files in the support +# directory. Alternatively, in the individual `*_spec.rb` files, manually +# require only the support files necessary. +# +# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } + +# Checks for pending migrations before tests are run. +# If you are not using ActiveRecord, you can remove this line. +ActiveRecord::Migration.maintain_test_schema! + +RSpec.configure do |config| + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures + config.fixture_path = "#{::Rails.root}/spec/fixtures" + + # If you're not using ActiveRecord, or you'd prefer not to run each of your + # examples within a transaction, remove the following line or assign false + # instead of true. + config.use_transactional_fixtures = true + + # RSpec Rails can automatically mix in different behaviours to your tests + # based on their file location, for example enabling you to call `get` and + # `post` in specs under `spec/controllers`. + # + # You can disable this behaviour by removing the line below, and instead + # explicitly tag your specs with their type, e.g.: + # + # RSpec.describe UsersController, :type => :controller do + # # ... + # end + # + # The different available types are documented in the features, such as in + # https://relishapp.com/rspec/rspec-rails/docs + config.infer_spec_type_from_file_location! +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..0bb4bbb --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,101 @@ +require 'coveralls' +Coveralls.wear! + +# This file was generated by the `rails generate rspec:install` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# The `.rspec` file also contains a few flags that are not defaults but that +# users commonly want. +# +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +require 'factory_girl' +require 'devise' + +RSpec.configure do |config| + config.include FactoryGirl::Syntax::Methods + config.include Devise::TestHelpers, type: :controller + + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # These two settings work together to allow you to limit a spec run + # to individual examples or groups you care about by tagging them with + # `:focus` metadata. When nothing is tagged with `:focus`, all examples + # get run. + config.filter_run :focus + config.run_all_when_everything_filtered = true + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax + # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching + config.disable_monkey_patching! + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = 'doc' + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed +=end +end diff --git a/test/controllers/.keep b/test/controllers/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/controllers/admins_controller_test.rb b/test/controllers/admins_controller_test.rb deleted file mode 100644 index 3168556..0000000 --- a/test/controllers/admins_controller_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class AdminsControllerTest < ActionController::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/controllers/callbacks_controller_test.rb b/test/controllers/callbacks_controller_test.rb deleted file mode 100644 index 6d160fc..0000000 --- a/test/controllers/callbacks_controller_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class CallbacksControllerTest < ActionController::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/controllers/orders_controller_test.rb b/test/controllers/orders_controller_test.rb deleted file mode 100644 index 0afece1..0000000 --- a/test/controllers/orders_controller_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class OrdersControllerTest < ActionController::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/controllers/products_controller_test.rb b/test/controllers/products_controller_test.rb deleted file mode 100644 index 1376a26..0000000 --- a/test/controllers/products_controller_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class ProductsControllerTest < ActionController::TestCase -end diff --git a/test/controllers/sessions_controller_test.rb b/test/controllers/sessions_controller_test.rb deleted file mode 100644 index d30ebc3..0000000 --- a/test/controllers/sessions_controller_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class SessionsControllerTest < ActionController::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/controllers/stock_controller_test.rb b/test/controllers/stock_controller_test.rb deleted file mode 100644 index 099e641..0000000 --- a/test/controllers/stock_controller_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class StockControllerTest < ActionController::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb deleted file mode 100644 index c67c56b..0000000 --- a/test/controllers/users_controller_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class UsersControllerTest < ActionController::TestCase -end diff --git a/test/controllers/welcome_controller_test.rb b/test/controllers/welcome_controller_test.rb deleted file mode 100644 index fb50856..0000000 --- a/test/controllers/welcome_controller_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class WelcomeControllerTest < ActionController::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/fixtures/.keep b/test/fixtures/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/helpers/.keep b/test/helpers/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/integration/.keep b/test/integration/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/integration/generate_order_items_test.rb b/test/integration/generate_order_items_test.rb deleted file mode 100644 index 80e6e48..0000000 --- a/test/integration/generate_order_items_test.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'test_helper' - -class GenerateOrderItemsTest < ActiveSupport::TestCase - test "g_order_items works" do - order = Order.new - products = Product.all.where("stock > 0") - size = products.size - - order.order_items.build(product: products(:fanta), count: 150) - order.order_items.build(product: products(:mate), count: 50) - order.g_order_items(products) - - assert_equal order.order_items.size, size - assert_equal order.order_items.select { |oi| oi.product == products(:fanta) }.first.count, products(:fanta).stock - assert_equal order.order_items.select { |oi| oi.product == products(:cola) }.size, 0 - assert_equal order.order_items.select { |oi| oi.product == products(:mate) }.first.count, 50 - assert_equal order.order_items.select { |oi| oi.product == products(:bueno) }.first.count, 0 - end -end diff --git a/test/integration/order_integration_test.rb b/test/integration/order_integration_test.rb deleted file mode 100644 index 4f49845..0000000 --- a/test/integration/order_integration_test.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'test_helper' - -class OrderIntegrationTest < ActionDispatch::IntegrationTest - def setup - Product.all.each do |product| - product.avatar = File.new('public/seeds/products/1.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' - - # assert_difference "User.find(users(:benji).id).debt_cents", 240 do - # fill_in 'order_order_items_attributes_2_count', with: 2 - # click_button "Order!" - # end - # end - - # test 'quickpay' do - # assert_difference "User.find(users(:benji).id).debt_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).debt_cents", -User.find(users(:benji).id).dagschotel.price_cents do - # click_link 'Undo' - # assert page.has_content? 'Success!' - # end - # end -end diff --git a/test/integration/product_attributes_test.rb b/test/integration/product_attributes_test.rb deleted file mode 100644 index ec7ccfa..0000000 --- a/test/integration/product_attributes_test.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'test_helper' - -class ProductAttributesTest < ActiveSupport::TestCase - test "product_attributes are read correctly" do - params = { - order_items_attributes: [ - { - count: "5", - product_attributes: { - id: products(:fanta).id - } - } - ] - } - - o = Order.create(params) - - assert_equal o.order_items.first.product, products(:fanta) - end -end diff --git a/test/integration/stock_test.rb b/test/integration/stock_test.rb deleted file mode 100644 index 970e0ab..0000000 --- a/test/integration/stock_test.rb +++ /dev/null @@ -1,16 +0,0 @@ -require 'test_helper' - -class StockTest < ActiveSupport::TestCase - test "creating and deleting orders updates stock of products" do - order = users(:benji).orders.build - order.order_items.build(product: products(:fanta), count: 2) - - assert_difference "products(:fanta).stock", -2 do - order.save(validate: false) - end - - assert_difference "products(:fanta).stock", +2 do - order.cancel - end - end -end diff --git a/test/integration/stock_validator_test.rb b/test/integration/stock_validator_test.rb deleted file mode 100644 index 338111a..0000000 --- a/test/integration/stock_validator_test.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'test_helper' - -class StockValidatorTest < ActiveSupport::TestCase - test "form gives error when product out of stock" do - order = users(:benji).orders.build - order.order_items.build(product: products(:cola), count: 10) - - order.save - - assert_includes order.errors[:base], "There is not enough stock for your order of the following products: Cola" - end -end diff --git a/test/mailers/.keep b/test/mailers/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/models/.keep b/test/models/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/models/order_test.rb b/test/models/order_test.rb deleted file mode 100644 index 16f6ae3..0000000 --- a/test/models/order_test.rb +++ /dev/null @@ -1,29 +0,0 @@ -# == Schema Information -# -# Table name: orders -# -# id :integer not null, primary key -# user_id :integer -# price_cents :integer -# created_at :datetime not null -# updated_at :datetime not null -# cancelled :boolean default("f") -# - -require 'test_helper' - -class OrderTest < ActiveSupport::TestCase - def setup - @order = Order.new - @order.order_items.build(product: products(:fanta), count: 1) - @order.order_items.build(product: products(:bueno), count: 2) - end - - test "order total price is correct" do - assert_equal @order.price, 3.00 - end - - test "to_sentence is correct" do - assert_equal @order.to_sentence, "1 Fanta and 2 Kinder Buenos" - end -end diff --git a/test/models/stock_entry_test.rb b/test/models/stock_entry_test.rb deleted file mode 100644 index ebe8120..0000000 --- a/test/models/stock_entry_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class StockEntryTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/test_helper.rb b/test/test_helper.rb deleted file mode 100644 index 5ec70b7..0000000 --- a/test/test_helper.rb +++ /dev/null @@ -1,30 +0,0 @@ -require "codeclimate-test-reporter" -CodeClimate::TestReporter.start - -require 'coveralls' -Coveralls.wear! - -ENV['RAILS_ENV'] ||= 'test' -require File.expand_path('../../config/environment', __FILE__) -require 'rails/test_help' - -require 'capybara/rails' - -class ActiveSupport::TestCase - # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. - fixtures :all - - # Add more helper methods to be used by all tests here... -end - -class ActionDispatch::IntegrationTest - include Warden::Test::Helpers - Warden.test_mode! - - def sign_in(user) - login_as user, scope: :user - end - - # Make the Capybara DSL available in all integration tests - include Capybara::DSL -end