Permalink
Browse files

Restored use_billing checkbox;

Extracted address fields to constant to allow easily reorder or change field set;
Added several cucumber scenarios;
Fixed few typos
  • Loading branch information...
1 parent b78bffc commit c7b6882ba66f83be3d5c536136b2e2b4e1f0669c @romul romul committed Mar 7, 2011
View
@@ -42,7 +42,7 @@ task :default => [ :spec ]
desc "Regenerates a rails 3 app for testing"
task :test_app do
require '../spree/lib/generators/spree/test_app_generator'
- class AdvancedCartTestAppGenerator < Spree::Generators::TestAppGenerator
+ class AddressBookTestAppGenerator < Spree::Generators::TestAppGenerator
def install_gems
inside "test_app" do
@@ -66,7 +66,7 @@ gem 'spree_address_book', :path => \'#{File.dirname(__FILE__)}\'
end
end
- AdvancedCartTestAppGenerator.start
+ AddressBookTestAppGenerator.start
end
namespace :test_app do
@@ -21,7 +21,7 @@ def set_addresses
end
def normalize_addresses
- return unless @order.bill_address_id && @order.ship_address_id
+ return unless params[:state] == "address" && @order.bill_address_id && @order.ship_address_id
@order.bill_address.reload
@order.ship_address.reload
if @order.bill_address_id != @order.ship_address_id && @order.bill_address.same_as?(@order.ship_address)
@@ -11,7 +11,7 @@ def can_be_deleted?
end
def to_s
- "#{firstname} #{lastname}: #{zipcode}, #{country}, #{state}, #{address1} #{address2}"
+ "#{firstname} #{lastname}: #{zipcode}, #{country}, #{state || state_name}, #{city}, #{address1} #{address2}"
end
def destroy_with_saving_used
@@ -2,8 +2,8 @@
attr_accessible :bill_address_id, :ship_address_id
def clone_billing_address
- if bill_address and self.ship_address.nil?
- self.ship_address_id = bill_address.id
+ if self.bill_address
+ self.ship_address = self.bill_address
end
true
end
@@ -1,4 +1,4 @@
-<% ["firstname", "lastname", "address1", "address2", "city", "state", "zipcode", "country", "phone"].each do |field| %>
+<% ADDRESS_FIELDS.each do |field| %>
<p id="<%= [address_name, field].join('_') %>" class="field">
<% if field == "country" %>
<%= address_form.label :country_id, t(field, :scope => [:activerecord, :attributes, :address]) %>
@@ -10,15 +10,22 @@
<% address_name = "#{address_type[0...4]}_address" %>
<fieldset id="<%= address_type %>">
<legend><%= t(address_type + "_address")%></legend>
+ <% if address_type == 'shipping' %>
+ <p class="field checkbox">
+ <label for="order_use_billing" id="use_billing">
+ <%= check_box_tag 'order[use_billing]', '1', (!(@order.bill_address.empty? && @order.ship_address.empty?) && @order.bill_address.eql?(@order.ship_address)) %> <%= t("use_billing_address") %>
+ </label>
+ </p>
+ <% end %>
<div class="select_address">
<p class="field">
<% if @addresses.present? %>
<% @addresses.each do |address| %>
<span id="<%= [address_type, dom_id(address)].join('_') %>">
- <label><%= form.radio_button "#{address_name}_id", address.id %> <%= address %></label> <%= link_to 'remove', address, :method => :delete, :remote => true %><br />
+ <label><%= form.radio_button "#{address_name}_id", address.id %> <%= address %></label> <%= link_to t(:remove), address, :method => :delete, :remote => true %><br />
</span>
<% end %>
- <label><%= form.radio_button "#{address_name}_id", 0 %> <%= ('other') %></label>
+ <label><%= form.radio_button "#{address_name}_id", 0 %> <%= t('other_address') %></label>
<% end %>
</p>
</div>
@@ -0,0 +1 @@
+ADDRESS_FIELDS = ["firstname", "lastname", "address1", "address2", "city", "state", "zipcode", "country", "phone"]
@@ -0,0 +1,2 @@
+en:
+ other_address: "Other address"
@@ -4,7 +4,7 @@ Feature: Address Book
Scenario: User fill new address
Given an order from registered user "email@person.com/password", who has 0 addresses, at address step
When I fill billing address with correct data
- And I fill shipping address with correct data
+ And check "order_use_billing"
And press "Save and Continue"
Then user "email@person.com" should have 1 address
When I choose "UPS Ground" as shipping method and "Check" as payment method
@@ -19,7 +19,39 @@ Feature: Address Book
Then user "email@person.com" should have 1 address
When I choose "UPS Ground" as shipping method and "Check" as payment method
Then I should see "Your order has been processed successfully"
-
+
+ @selenium @wip @stop
+ Scenario: User select address
+ Given an order from registered user "email@person.com/password", who has 1 addresses, at address step
+ When I choose "order_bill_address_id_1"
+ And check "order_use_billing"
+ And press "Save and Continue"
+ Then user "email@person.com" should have 1 address
+ When I choose "UPS Ground" as shipping method and "Check" as payment method
+ Then I should see "Your order has been processed successfully"
+
+ @selenium @wip @stop
+ Scenario: User select address
+ Given an order from registered user "email@person.com/password", who has 1 addresses, at address step
+ When I choose "order_bill_address_id_0"
+ And I fill billing address with correct data
+ And I choose "order_ship_address_id_0"
+ And I fill shipping address with correct data
+ And press "Save and Continue"
+ Then user "email@person.com" should have 2 address
+ When I choose "UPS Ground" as shipping method and "Check" as payment method
+ Then I should see "Your order has been processed successfully"
+
+ @selenium @wip @stop
+ Scenario: User select address
+ Given an order from registered user "email@person.com/password", who has 1 addresses, at address step
+ When I choose "order_bill_address_id_0"
+ And I fill billing address with correct data
+ And I check "order_use_billing"
+ And press "Save and Continue"
+ Then user "email@person.com" should have 2 address
+ When I choose "UPS Ground" as shipping method and "Check" as payment method
+ Then I should see "Your order has been processed successfully"
@selenium @wip @stop
Scenario: User can edit address, if it was not used by another order
@@ -0,0 +1,73 @@
+(function($){
+ $(document).ready(function(){
+
+ $('#checkout_form_address').validate();
+
+ var get_states = function(region){
+ var country = $('p#' + region + 'country' + ' span#' + region + 'country :only-child').val();
+ return state_mapper[country];
+ }
+
+ var update_state = function(region) {
+ var states = get_states(region);
+
+ var state_select = $('span#' + region + 'state select');
+ var state_input = $('span#' + region + 'state input');
+
+ if(states) {
+ var selected = state_select.val();
+ state_select.html('');
+ var states_with_blank = [["",""]].concat(states);
+ $.each(states_with_blank, function(pos,id_nm) {
+ var opt = $(document.createElement('option'))
+ .attr('value', id_nm[0])
+ .html(id_nm[1]);
+ if(selected==id_nm[0]){
+ opt.attr('selected', 'selected');
+ }
+ state_select.append(opt);
+ });
+ state_select.removeAttr('disabled').show();
+ state_input.hide().attr('disabled', 'disabled');
+
+ } else {
+ state_input.removeAttr('disabled').show();
+ state_select.hide().attr('disabled', 'disabled');
+ }
+
+ };
+
+ // Show fields for the selected payment method
+ $("input[type='radio'][name='order[payments_attributes][][payment_method_id]']").click(function(){
+ $('#payment-methods li').hide();
+ if(this.checked){ $('#payment_method_'+this.value).show(); }
+ }).triggerHandler('click');
+
+ $('p#bcountry span#bcountry select').change(function() { update_state('b'); });
+ $('p#scountry span#scountry select').change(function() { update_state('s'); });
+ update_state('b');
+ update_state('s');
+
+ $('input#order_use_billing').click(function() {
+ if($(this).is(':checked')) {
+ $("#shipping .inner input").attr('disabled', 'disabled');
+ $("#shipping .inner select").attr('disabled', 'disabled');
+ $("#shipping .inner").fadeOut();
+ $("#shipping .select_address").fadeOut();
+ } else {
+ if ($("input[name='order[ship_address_id]']:checked").val() == '0') {
+ $("#shipping .inner input").removeAttr('disabled');
+ $("#shipping .inner select").removeAttr('disabled');
+ $("#shipping .inner").fadeIn();
+ }
+ $("#shipping .select_address").fadeIn();
+ }
+ }).triggerHandler('click');
+
+ $('form.edit_checkout').submit(function() {
+ $(this).find(':submit, :image').attr('disabled', true).removeClass('primary').addClass('disabled');
+ });
+
+
+ });
+})(jQuery);
@@ -0,0 +1,5 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe Address do
+
+end
View
@@ -8,6 +8,8 @@
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
+require 'spree_core/testing_support/factories'
+
RSpec.configure do |config|
# == Mock Framework
#

0 comments on commit c7b6882

Please sign in to comment.