Skip to content

Commit

Permalink
Added several scenarios and other stuff:
Browse files Browse the repository at this point in the history
* Started work on checkout.feature
* Improved checkout.feature, added few new scenarios.
* Added opportunity to describe product, which added to cart.
* Improved checkout scenarios.
* Improved user steps.
* Added scenarios for work with cart and for search features.
* Fixed typo in theme_default.
* Added payment methods for cucumber env.

[spree#1239 state:resolved]
  • Loading branch information
romul committed Mar 28, 2010
1 parent 084632f commit 381dbf4
Show file tree
Hide file tree
Showing 10 changed files with 269 additions and 7 deletions.
98 changes: 98 additions & 0 deletions features/checkout.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
Feature: Checkout
In order to be able make checkout
Should be able make checkout


Scenario: Visitor make checkout as guest, without registration
When I add a product with name: "RoR Mug" to cart
Then I should see "Shopping Cart" within "h1"
When I follow "Checkout"
Then I should see "Registration"

When I fill in "Email" with "spree@test.com" within "#guest_checkout"
And press "Continue"
Then I should see "Billing Address" within "legend"
And I should see "Shipping Address" within "legend"

When I fill billing address with correct data
And check "checkout_use_billing"
And press "Save and Continue"
Then I should see "Shipping Method" within "legend"
When I fill in "coupon-code" with "SPREE"
And press "post-summary"
Then I should see "Coupon (SPREE)" within "#summary-order-credits"
And I should see "Shipping Method" within "legend"

When I choose "UPS Ground" as shipping method and "Check" as payment method
Then I should see "Your order has been processed successfully"
And 1 coupon_credits should exist


Scenario: User make checkout
Given I am signed up as "email@person.com/password"
When I add a product with name: "RoR Mug" to cart
Then I should see "Shopping Cart" within "h1"
When I follow "Checkout"
Then I should see "Registration"

When I follow "Log In as Existing Customer"
Then I should see "Log In as Existing Customer" within "h2"
When I sign in as "email@person.com/password"
Then I should see "Billing Address" within "legend"
And I should see "Shipping Address" within "legend"

When I press "Save and Continue"
Then I should see "Shipping Method" within "legend"
When I fill in "coupon-code" with "SPREE"
And press "post-summary"
Then I should see "Coupon (SPREE)" within "#summary-order-credits"
And I should see "Shipping Method" within "legend"

When I choose "UPS Ground" as shipping method and "Check" as payment method
Then I should see "Your order has been processed successfully"
And 1 coupon_credits should exist


Scenario: Uncompleted order associated with user
Given I am signed up as "email@person.com/password"
When I sign in as "email@person.com/password"
Then I should be logged in

When I add a product with price: "14.99" to cart
Then 1 orders should exist with item_total: "14.99"
And 0 orders should exist with user_id: nil

When I follow "Logout"
Then I should be logged out
And cart should be empty
When I add a product with price: "14.99" to cart
Then 2 orders should exist with item_total: "14.99"
And 1 orders should exist with user_id: nil

When I sign in as "email@person.com/password"
Then 1 orders should exist with item_total: "29.98"
And 0 orders should exist with user_id: nil


Scenario: Uncompleted guest order should be associated with user after log in
Given I am signed up as "email@person.com/password"

When I add a product with name: "RoR Mug" to cart
Then 1 orders should exist with user_id: nil

When I go to the sign in page
And sign in as "email@person.com/password"
Then I should be logged in

When I follow "Cart"
Then I should see "Shopping Cart" within "h1"
When I follow "Checkout"
Then I should see "Billing Address"
And I should see "Shipping Address" within "legend"
When I press "Save and Continue"
Then I should see "Shipping Method" within "legend"
When I choose "UPS Ground" as shipping method and "Check" as payment method
Then I should see "Your order has been processed successfully"
And 0 orders should exist with user_id: nil


35 changes: 35 additions & 0 deletions features/search.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Feature: Search products
In order to be able to search products
A visitor

Scenario: Visitor can search products by keywords
Given the following products exist:
| name | price | available_on | taxon |
| Ruby Mug | 15.99 | 2010-03-06 18:48:21 | Ruby |
| Ruby Bag | 19.99 | 2010-03-06 18:48:21 | Bag |
| Apache Bag | 17.99 | 2010-03-06 18:48:21 | Bag |
| Ruby T-Shirt | 16.99 | 2020-03-06 18:48:21 | Ruby |
When I go to the homepage
And fill in "keywords" with "ruby"
And press "Search"
Then I should see "Search results for 'ruby'"
And I should see "Ruby Mug"
And I should see "Ruby Bag"
And I should not see "Apache Bag"
And I should not see "Ruby T-Shirt"

When I go to the homepage
And fill in "keywords" with "ruby"
And select "Ruby" from "taxon"
And press "Search"
Then I should see "Ruby" within "h1"
And I should see "Search results for 'ruby'"
And I should see "Ruby Mug"
And I should not see "Ruby Bag"
And I should not see "Apache Bag"
And I should not see "Ruby T-Shirt"

When I go to the homepage
And fill in "keywords" with "hsgfhagsfg"
And press "Search"
Then I should see "No products found"
52 changes: 50 additions & 2 deletions features/step_definitions/user_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
:email => email,
:login => email,
:password => password,
:password_confirmation => password)
:password_confirmation => password,
:bill_address => Factory(:address),
:ship_address => Factory(:address))
end

When /^I sign in as "([^\"]*)"$/ do |email_and_password|
When /^(?:|I )sign in as "([^\"]*)"$/ do |email_and_password|
email, password = email_and_password.split("/")

visit login_path
Expand All @@ -17,3 +19,49 @@

click_button "Log In"
end


When /^(?:|I )fill (billing|shipping) address with correct data$/ do |address_type|
str_addr = address_type[0...4] + "_address"
address = @me ? @me.send(str_addr) : Factory(:address)
When %{I select "United States" from "Country" within "fieldset##{address_type}"}
['firstname', 'lastname', 'address1', 'city', 'state_name', 'zipcode', 'phone'].each do |field|
When %{I fill in "checkout_#{str_addr}_attributes_#{field}" with "#{address.send(field)}"}
end
end

When /^(?:|I )add a product with (.*?)? to cart$/ do |captured_fields|
fields = {'name' => "RoR Mug", 'count_on_hand' => '10', 'available_on' => "2010-03-06 18:48:21", 'price' => "14.99"}
captured_fields.split(/,\s+/).each do |field|
(name, value) = field.split(/:\s*/, 2)
fields[name] = value.delete('"')
end
price = fields.delete('price')
if Product.master_price_equals(price).count(:conditions => fields) == 0
Factory(:product, fields.merge('price' => price))
end
When %{I go to the products page}
Then %{I should see "#{fields['name']}" within "ul.product-listing"}
When %{I follow "#{fields['name']}"}
Then %{I should see "#{fields['name']}" within "h1"}
And %{I should see "$#{price}" within "span.price"}
When %{I press "Add To Cart"}
end

When /^I choose "(.*?)" as shipping method and "(.*?)" as payment method$/ do |shiping_method, payment_method|
When %{I choose "#{shiping_method}"}
And %{press "Save and Continue"}
Then %{I should see "Payment Information" within "legend"}

When %{I choose "#{payment_method}"}
And %{press "Save and Continue"}
Then %{I should see "Confirm" within "legend"}

When %{I press "Save and Continue"}
end

Then /^cart should be empty$/ do
Then %{I should not see "Cart: ("}
end


7 changes: 6 additions & 1 deletion features/step_definitions/web_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ def with_scope(locator)
if defined?(Spec::Rails::Matchers)
page.should have_content(text)
else
assert page.has_content?(text)
begin
assert page.has_content?(text)
rescue Exception => ex
puts page.body
raise ex
end
end
end
end
Expand Down
23 changes: 22 additions & 1 deletion features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,28 @@
Dir.glob(SPREE_ROOT + '/db/default/*.{yml,csv,rb}').each do |file|
Fixtures.create_fixtures('db/default', File.basename(file, '.*'))
end
Dir.glob(SPREE_ROOT + '/test/fixtures/*.{yml,csv,rb}').each do |file|
Fixtures.create_fixtures('test/fixtures', File.basename(file, '.*'))
end

Zone.class_eval do
def self.global
find_by_name("GlobalZone") || Factory(:global_zone)
end
end

Product.class_eval do
def taxon=(taxon_name)
taxonomy = Taxonomy.find_or_create_by_name("Category")
taxon = Taxon.find_or_create_by_name_and_taxonomy_id(taxon_name, taxonomy)
self.taxons << taxon
end
end

ShippingMethod.create(:name => "UPS Ground", :zone => Zone.global, :calculator => Calculator::FlatRate.new)

coupon = Coupon.create(:code => "SPREE", :description => "$5 off any order", :combine => false, :calculator => Calculator::FlatRate.new)
coupon.calculator.update_attribute(:preferred_amount, 5)

end

Expand Down Expand Up @@ -64,5 +86,4 @@
# http://github.com/bmabey/database_cleaner for more info.
require 'database_cleaner'
DatabaseCleaner.strategy = :truncation

end
3 changes: 2 additions & 1 deletion features/support/paths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def path_to(page_name)
signup_path
when /the sign in page/
login_path

when /the products page/
products_path
# Add more mappings here.
# Here is an example that pulls values out of the Regexp:
#
Expand Down
41 changes: 41 additions & 0 deletions features/work_with_cart.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Feature: Work with cart

Scenario: Visitor can work with cart
When I add a product with name: "RoR Mug", price: "15" to cart
Then I should see "Shopping Cart" within "h1"
And I should see "RoR Mug" within "#line_items h4 a"
And I should see "$15" within "#line_items td"
And I should see "$15" within "#subtotal"

When I add a product with name: "RoR Mug", price: "15" to cart
Then I should see "Shopping Cart" within "h1"
And I should see "RoR Mug" within "#line_items h4 a"
And I should see "$15" within "#line_items td"
And I should see "$30" within "#line_items td"
And I should see "$30" within "#subtotal"

When I add a product with name: "RoR Bag", price: "17" to cart
Then I should see "Shopping Cart" within "h1"
And I should see "RoR Bag" within "#line_items h4 a"
And I should see "$15" within "#line_items td"
And I should see "$17" within "#line_items td"
And I should see "$47" within "#subtotal"

When I fill in "order_line_items_attributes_0_quantity" with "3"
Then the "order_line_items_attributes_0_quantity" field should contain "3"
# When I press "order_line_items_attributes_0_quantity"
# Then I should see "Shopping Cart" within "h1"
# And I should see "$45" within "#line_items td"
# And I should see "$62" within "#subtotal"

# When I fill in "order_line_items_attributes_0_quantity" with "0"
# And follow "Update"
# Then I should see "Shopping Cart" within "h1"
# And I should see "$17" within "#subtotal"


Scenario: Following by cart link should not create order
When I go to the homepage
And follow "Cart"
When 0 orders should exist

12 changes: 12 additions & 0 deletions test/fixtures/payment_methods.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,15 @@ check_payment_method:
environment: test
active: false
type: PaymentMethod::Check
check_payment_method_cucumber:
name: Check Payment Type
description: Check Payment Type for test.
environment: cucumber
active: true
type: PaymentMethod::Check
bogus_cucumber:
name: Bogus Test
description: Bogus payment gateway for test.
environment: cucumber
active: true
type: Gateway::Bogus
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<% if params[:keywords] %>
<h1><%= t(:search_results, :keywords => h(params[:keywords])) %></h1>
<% hook :search_results do %>
<% if @products.empty? %>
<%= t(:no_products_found) %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<%
paginated_products = Spree::Config.searcher.products if params.key?(:keywords)
paginated_products = Spree::Config.searcher.products if params.key?(:keywords)
paginated_products ||= products
%>
<% if products.empty? %>
<%= t(:no_products_found) %>
<% elsif params.key?(:keywords) %>
<h3><%= t(:search_results, :keywords => h(params[:keywords])) %></h3>
<% end %>
<% if products.any? %>
Expand Down

0 comments on commit 381dbf4

Please sign in to comment.