Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

Commit

Permalink
fixed test
Browse files Browse the repository at this point in the history
  • Loading branch information
sbounmy committed Apr 21, 2012
1 parent 69dac4e commit 26cd7fe
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 31 deletions.
2 changes: 1 addition & 1 deletion lib/spree_variant_options/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Engine < Rails::Engine
end
end

initializer "spree_variant_options.environment", :before => :load_config_initializers, :after => "spree.environment" do |app|
initializer "spree_variant_options.environment", :after => "spree.environment" do |app|
Dir.glob(File.join(File.dirname(__FILE__), "../../app/models/spree/app_configuration/*.rb")) do |c|
Rails.application.config.cache_classes ? require(c) : load(c)
end
Expand Down
114 changes: 84 additions & 30 deletions test/integration/variant_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
require 'test_helper'

module Spree
class WishedProduct
include ActiveModel::Conversion
extend ActiveModel::Naming

attr_accessor :variant_id

def persisted?
false
end
end
end

class ProductTest < ActionDispatch::IntegrationTest

setup do
Expand All @@ -15,38 +28,79 @@ class ProductTest < ActionDispatch::IntegrationTest
@variant2 = Factory(:variant, :product => @product, :option_values => [@s, @green], :on_hand => 0)
@variant3 = Factory(:variant, :product => @product, :option_values => [@m, @red], :on_hand => 0)
@variant4 = Factory(:variant, :product => @product, :option_values => [@m, @green], :on_hand => 1)
end

test 'allow choose out of stock variants' do
SpreeVariantOptions::VariantConfig.allow_select_outofstock = true

visit spree.product_path(@product)
within("#product-variants") do
size = find_link('S')
size.click
assert size["class"].include?("selected")
color = find_link('Green')
color.click
assert color["class"].include?("selected")
Deface::Override.new( :virtual_path => "spree/products/show",
:name => "add_other_form_to_spree_variant_options",
:insert_after => "div#cart-form",
:text => %q{
<div id="wishlist-form">
<%= form_for Spree::WishedProduct.new, :url => "foo", :html => {:"data-form-type" => "variant"} do |f| %>
<%= f.hidden_field :variant_id, :value => @product.master.id %>
<button type="submit">
<%= t(:add_to_wishlist) %>
</button>
<% end %>
</div>
}
)
end
# add to cart button is still disabled
assert find_button("Add To Cart")["disabled"]
end

test 'disallow choose out of stock variants' do
SpreeVariantOptions::VariantConfig.allow_select_outofstock = false

visit spree.product_path(@product)
within("#product-variants") do
size = find_link('M')
size.click
assert size["class"].include?("selected")
color = find_link('Red')
color.click
assert !color["class"].include?("selected")
test 'disallow choose out of stock variants' do

SpreeVariantOptions::VariantConfig.allow_select_outofstock = false

visit spree.product_path(@product)

# variant options are not selectable
within("#product-variants") do
size = find_link('S')
size.click
assert !size["class"].include?("selected")
color = find_link('Green')
color.click
assert !color["class"].include?("selected")
end

# add to cart button is still disabled
assert_equal "true", find_button("Add To Cart")["disabled"]
# add to wishlist button is still disabled
assert_equal "true", find_button("Add To Wishlist")["disabled"]
end

test 'allow choose out of stock variants' do
SpreeVariantOptions::VariantConfig.allow_select_outofstock = true

visit spree.product_path(@product)

# variant options are selectable
within("#product-variants") do
size = find_link('S')
size.click
assert size["class"].include?("selected")
color = find_link('Green')
color.click
assert color["class"].include?("selected")
end
# add to cart button is still disabled
assert_equal "true", find_button("Add To Cart")["disabled"]
# add to wishlist button is enabled
assert_equal "false", find_button("Add To Wishlist")["disabled"]
end

test "choose in stock variant" do
visit spree.product_path(@product)
within("#product-variants") do
size = find_link('M')
size.click
assert size["class"].include?("selected")
color = find_link('Green')
color.click
assert color["class"].include?("selected")
end
# add to cart button is enabled
assert_equal "false", find_button("Add To Wishlist")["disabled"]
# add to wishlist button is enabled
assert_equal "false", find_button("Add To Wishlist")["disabled"]
end
# add to cart button is still disabled
assert find_button("Add To Cart")["disabled"]
end

end
end

0 comments on commit 26cd7fe

Please sign in to comment.