Add test for placing order
This commit is contained in:
parent
ec597ff1aa
commit
35fc8ecc77
7 changed files with 81 additions and 23 deletions
5
Gemfile
5
Gemfile
|
@ -41,6 +41,11 @@ group :production do
|
||||||
gem 'mysql2' # Database
|
gem 'mysql2' # Database
|
||||||
end
|
end
|
||||||
|
|
||||||
|
group :test do
|
||||||
|
gem 'capybara'
|
||||||
|
gem 'launchy'
|
||||||
|
end
|
||||||
|
|
||||||
#bootstrap
|
#bootstrap
|
||||||
gem 'bootstrap-sass', '3.2.0.0'
|
gem 'bootstrap-sass', '3.2.0.0'
|
||||||
|
|
||||||
|
|
13
Gemfile.lock
13
Gemfile.lock
|
@ -36,6 +36,7 @@ GEM
|
||||||
minitest (~> 5.1)
|
minitest (~> 5.1)
|
||||||
thread_safe (~> 0.3, >= 0.3.4)
|
thread_safe (~> 0.3, >= 0.3.4)
|
||||||
tzinfo (~> 1.1)
|
tzinfo (~> 1.1)
|
||||||
|
addressable (2.3.7)
|
||||||
annotate (2.6.5)
|
annotate (2.6.5)
|
||||||
activerecord (>= 2.3.0)
|
activerecord (>= 2.3.0)
|
||||||
rake (>= 0.8.7)
|
rake (>= 0.8.7)
|
||||||
|
@ -67,6 +68,12 @@ GEM
|
||||||
capistrano (~> 3.0)
|
capistrano (~> 3.0)
|
||||||
sshkit (~> 1.2)
|
sshkit (~> 1.2)
|
||||||
capistrano-stats (1.1.1)
|
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)
|
climate_control (0.0.3)
|
||||||
activesupport (>= 3.0)
|
activesupport (>= 3.0)
|
||||||
cocaine (0.5.5)
|
cocaine (0.5.5)
|
||||||
|
@ -114,6 +121,8 @@ GEM
|
||||||
railties (>= 4.2.0)
|
railties (>= 4.2.0)
|
||||||
thor (>= 0.14, < 2.0)
|
thor (>= 0.14, < 2.0)
|
||||||
json (1.8.2)
|
json (1.8.2)
|
||||||
|
launchy (2.4.3)
|
||||||
|
addressable (~> 2.3)
|
||||||
loofah (2.0.1)
|
loofah (2.0.1)
|
||||||
nokogiri (>= 1.5.9)
|
nokogiri (>= 1.5.9)
|
||||||
mail (2.6.3)
|
mail (2.6.3)
|
||||||
|
@ -228,6 +237,8 @@ GEM
|
||||||
warden (1.2.3)
|
warden (1.2.3)
|
||||||
rack (>= 1.0)
|
rack (>= 1.0)
|
||||||
will_paginate (3.0.7)
|
will_paginate (3.0.7)
|
||||||
|
xpath (2.0.0)
|
||||||
|
nokogiri (~> 1.3)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
ruby
|
ruby
|
||||||
|
@ -242,6 +253,7 @@ DEPENDENCIES
|
||||||
capistrano (~> 3.1)
|
capistrano (~> 3.1)
|
||||||
capistrano-rails (~> 1.1)
|
capistrano-rails (~> 1.1)
|
||||||
capistrano-rvm
|
capistrano-rvm
|
||||||
|
capybara
|
||||||
codeclimate-test-reporter
|
codeclimate-test-reporter
|
||||||
coffee-rails (~> 4.0.0)
|
coffee-rails (~> 4.0.0)
|
||||||
coveralls
|
coveralls
|
||||||
|
@ -249,6 +261,7 @@ DEPENDENCIES
|
||||||
faker (= 1.4.2)
|
faker (= 1.4.2)
|
||||||
jbuilder (~> 2.0)
|
jbuilder (~> 2.0)
|
||||||
jquery-rails
|
jquery-rails
|
||||||
|
launchy
|
||||||
mysql2
|
mysql2
|
||||||
paper_trail (~> 4.0.0.beta)
|
paper_trail (~> 4.0.0.beta)
|
||||||
paperclip
|
paperclip
|
||||||
|
|
|
@ -83,6 +83,20 @@ class FormattedFormBuilder < ActionView::Helpers::FormBuilder
|
||||||
end
|
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
|
||||||
|
|
||||||
private
|
private
|
||||||
def label_class
|
def label_class
|
||||||
"control-label"
|
"control-label"
|
||||||
|
@ -162,18 +176,4 @@ class FormattedFormBuilder < ActionView::Helpers::FormBuilder
|
||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<%= csrf_meta_tags %>
|
<%= csrf_meta_tags %>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<% if current_user && current_user.koelkast? %>
|
<% if current_user && current_user.koelkast? && !Rails.env.development? %>
|
||||||
<body oncontextmenu="return false">
|
<body oncontextmenu="return false">
|
||||||
<% else %>
|
<% else %>
|
||||||
<body>
|
<body>
|
||||||
|
|
20
test/fixtures/products.yml
vendored
20
test/fixtures/products.yml
vendored
|
@ -18,21 +18,25 @@
|
||||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
fanta:
|
fanta:
|
||||||
name: 'Fanta'
|
id: 1
|
||||||
|
name: 'Fanta'
|
||||||
price_cents: 60
|
price_cents: 60
|
||||||
stock: 100
|
stock: 100
|
||||||
|
|
||||||
cola:
|
cola:
|
||||||
name: 'Cola'
|
id: 2
|
||||||
|
name: 'Cola'
|
||||||
price_cents: 60
|
price_cents: 60
|
||||||
stock: 0
|
stock: 0
|
||||||
|
|
||||||
mate:
|
mate:
|
||||||
name: 'Club Mate'
|
id: 3
|
||||||
|
name: 'Club Mate'
|
||||||
price_cents: 120
|
price_cents: 120
|
||||||
stock: 100
|
stock: 100
|
||||||
|
|
||||||
bueno:
|
bueno:
|
||||||
name: 'Kinder Bueno'
|
id: 4
|
||||||
stock: 50
|
name: 'Kinder Bueno'
|
||||||
|
stock: 50
|
||||||
price_cents: 120
|
price_cents: 120
|
||||||
|
|
22
test/integration/order_integration_test.rb
Normal file
22
test/integration/order_integration_test.rb
Normal file
|
@ -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
|
|
@ -8,9 +8,23 @@ ENV['RAILS_ENV'] ||= 'test'
|
||||||
require File.expand_path('../../config/environment', __FILE__)
|
require File.expand_path('../../config/environment', __FILE__)
|
||||||
require 'rails/test_help'
|
require 'rails/test_help'
|
||||||
|
|
||||||
|
require 'capybara/rails'
|
||||||
|
|
||||||
class ActiveSupport::TestCase
|
class ActiveSupport::TestCase
|
||||||
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
|
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
|
||||||
fixtures :all
|
fixtures :all
|
||||||
|
|
||||||
# Add more helper methods to be used by all tests here...
|
# Add more helper methods to be used by all tests here...
|
||||||
end
|
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
|
||||||
|
|
Loading…
Reference in a new issue