diff --git a/Gemfile b/Gemfile index c62e729..13b9adc 100644 --- a/Gemfile +++ b/Gemfile @@ -41,6 +41,11 @@ group :production do gem 'mysql2' # Database end +group :test do + gem 'capybara' + gem 'launchy' +end + #bootstrap gem 'bootstrap-sass', '3.2.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index 22c975d..2e9083f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -36,6 +36,7 @@ GEM minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) + addressable (2.3.7) annotate (2.6.5) activerecord (>= 2.3.0) rake (>= 0.8.7) @@ -67,6 +68,12 @@ GEM capistrano (~> 3.0) sshkit (~> 1.2) capistrano-stats (1.1.1) + capybara (2.4.4) + mime-types (>= 1.16) + nokogiri (>= 1.3.3) + rack (>= 1.0.0) + rack-test (>= 0.5.4) + xpath (~> 2.0) climate_control (0.0.3) activesupport (>= 3.0) cocaine (0.5.5) @@ -114,6 +121,8 @@ GEM railties (>= 4.2.0) thor (>= 0.14, < 2.0) json (1.8.2) + launchy (2.4.3) + addressable (~> 2.3) loofah (2.0.1) nokogiri (>= 1.5.9) mail (2.6.3) @@ -228,6 +237,8 @@ GEM warden (1.2.3) rack (>= 1.0) will_paginate (3.0.7) + xpath (2.0.0) + nokogiri (~> 1.3) PLATFORMS ruby @@ -242,6 +253,7 @@ DEPENDENCIES capistrano (~> 3.1) capistrano-rails (~> 1.1) capistrano-rvm + capybara codeclimate-test-reporter coffee-rails (~> 4.0.0) coveralls @@ -249,6 +261,7 @@ DEPENDENCIES faker (= 1.4.2) jbuilder (~> 2.0) jquery-rails + launchy mysql2 paper_trail (~> 4.0.0.beta) paperclip diff --git a/app/form_builders/formatted_form_builder.rb b/app/form_builders/formatted_form_builder.rb index aac2dcc..956a645 100644 --- a/app/form_builders/formatted_form_builder.rb +++ b/app/form_builders/formatted_form_builder.rb @@ -83,6 +83,20 @@ class FormattedFormBuilder < ActionView::Helpers::FormBuilder end end + def error_header + content_tag(:div, class: "panel-heading") do + "#{pluralize(object.errors.count, "error")} prohibited this #{object.class.name.downcase} from being saved:" + end + end + + def error_messages + content_tag :ul do + object.errors.full_messages.map do |msg| + content_tag :li, msg + end.join.html_safe + end + end + private def label_class "control-label" @@ -162,18 +176,4 @@ class FormattedFormBuilder < ActionView::Helpers::FormBuilder end end end - - def error_header - content_tag(:div, class: "panel-heading") do - "#{pluralize(object.errors.count, "error")} prohibited this #{object.class.name.downcase} from being saved:" - end - end - - def error_messages - content_tag :ul do - object.errors.full_messages.map do |msg| - content_tag :li, msg - end.join.html_safe - end - end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 75fe2a2..5a0c969 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -7,7 +7,7 @@ <%= csrf_meta_tags %> - <% if current_user && current_user.koelkast? %> + <% if current_user && current_user.koelkast? && !Rails.env.development? %> <% else %> diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml index daa15a9..34ff39b 100644 --- a/test/fixtures/products.yml +++ b/test/fixtures/products.yml @@ -18,21 +18,25 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html fanta: - name: 'Fanta' + id: 1 + name: 'Fanta' price_cents: 60 - stock: 100 + stock: 100 cola: - name: 'Cola' + id: 2 + name: 'Cola' price_cents: 60 - stock: 0 + stock: 0 mate: - name: 'Club Mate' + id: 3 + name: 'Club Mate' price_cents: 120 - stock: 100 + stock: 100 bueno: - name: 'Kinder Bueno' - stock: 50 + id: 4 + name: 'Kinder Bueno' + stock: 50 price_cents: 120 diff --git a/test/integration/order_integration_test.rb b/test/integration/order_integration_test.rb new file mode 100644 index 0000000..3f87fe8 --- /dev/null +++ b/test/integration/order_integration_test.rb @@ -0,0 +1,22 @@ +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| + product.avatar = File.new('public/seeds/products/fanta.jpg', 'r') + product.save + end + + sign_in users(:koelkast) + visit new_user_order_path(users(:benji)) + + assert page.has_content? 'Order for benji' + + assert_difference "User.find(users(:benji).id).balance_cents", -240 do + fill_in 'order_order_items_attributes_2_count', with: 2 + click_button "Order!" + end + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index cf9b45e..5ec70b7 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -8,9 +8,23 @@ 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