Skip to content
This repository has been archived by the owner on Apr 17, 2020. It is now read-only.

Commit

Permalink
Cleanup + tweaks to pass all tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveitaly authored and romul committed Nov 5, 2012
1 parent fc990f9 commit 6c9d1bc
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 20 deletions.
2 changes: 2 additions & 0 deletions app/assets/javascripts/store/spree_address_book.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//= require store/spree_core

(function($) {
$(document).ready(function(){
if ($(".select_address").length) {
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/spree/addresses_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Spree::AddressesController < Spree::BaseController
helper Spree::AddressBookHelper
helper Spree::AddressesHelper
rescue_from ActiveRecord::RecordNotFound, :with => :render_404
load_and_authorize_resource

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/spree/checkout_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Spree::CheckoutController.class_eval do
helper Spree::AddressBookHelper
helper Spree::AddressesHelper

after_filter :normalize_addresses, :only => :update
before_filter :set_addresses, :only => :update
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Spree::AddressBookHelper
module Spree::AddressesHelper
def address_field(form, method, id_prefix = "b", &handler)
# stay in line with the default spree method of p#id naming
# this ensures that JS state selection, and other future checkout.js things, will keep working
Expand Down
4 changes: 4 additions & 0 deletions app/models/spree/address_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ def initialize(user)
can :manage, Spree::Address do |address|
address.user == user
end

can :create, Spree::Address do |address|
user.id.present?
end
end
end
2 changes: 1 addition & 1 deletion app/models/spree/address_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def can_be_deleted?
end

def to_s
"#{firstname} #{lastname}: #{zipcode}, #{country}, #{state || state_name}, #{city}, #{address1} #{address2}"
"#{firstname} #{lastname}, #{address1} #{address2}, #{city}, #{state || state_name} #{zipcode}, #{country}"
end

# UPGRADE_CHECK if future versions of spree have a custom destroy function, this will break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
:name => "address_book_account_my_orders",
:insert_after => "[data-hook='account_my_orders'], #account_my_orders[data-hook]",
:partial => "spree/users/addresses",
:disabled => false)
:disabled => false
)
7 changes: 1 addition & 6 deletions app/views/spree/addresses/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
<style>
form p.field input[type=text], form p.field select { width: 80%; float: none; }
.hidden { display: none; }
div.inner label { width: auto; padding-right: 5px; display: inline-block; }
form p.field span.req { float: none; }
</style>
<%= form_for @address do |f| %>
<fieldset>
<%= content_tag(:legend, t(:edit_shipping_address)) %>
<div class="inner">
<%= render :partial => 'spree/addresses/form', :locals => {
:address_name => 'address',
Expand Down
14 changes: 14 additions & 0 deletions app/views/spree/addresses/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<%= content_tag(:h1, ) %>
<%= form_for @address do |f| %>
<fieldset>
<%= content_tag(:legend, t(:new_shipping_address)) %>
<div class="inner">
<%= render :partial => 'spree/addresses/form', :locals => {
:address_name => 'address',
:address_form => f,
:address => @address
} %>
</div>
<%= f.submit t(:update) %>
</fieldset>
<% end %>
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ en:
other_address: "Other address"
add_new_shipping_address: "Add new shipping address"
new_shipping_address: "New Shipping Address"
edit_shipping_address: "Edit Shipping Address"
no_shipping_addresses_on_file: "No shipping addresses on file"
shipping_addresses: "Shipping Addresses"
successfully_saved: "Saved successfully"
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Spree::Core::Engine.routes.prepend do
resources :addresses, :only => [:edit, :update, :destroy]
resources :addresses
end
3 changes: 2 additions & 1 deletion spec/models/address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@

it 'is displayed as string' do
a = address
address.to_s.should eq("#{a.firstname} #{a.lastname}<br/>#{a.address1} #{a.address2}<br/>#{a.city}, #{a.state || a.state_name} #{a.zipcode}<br/>#{a.country}".html_safe)
# address.to_s.should eq("#{a.firstname} #{a.lastname}<br/>#{a.address1} #{a.address2}<br/>#{a.city}, #{a.state || a.state_name} #{a.zipcode}<br/>#{a.country}".html_safe)
address.to_s.should == "#{a.firstname} #{a.lastname}, #{a.address1} #{a.address2}, #{a.city}, #{a.state || a.state_name} #{a.zipcode}, #{a.country}".html_safe
end

it 'is destroyed without saving used' do
Expand Down
13 changes: 6 additions & 7 deletions spec/views/addresses_spec.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
require 'spec_helper'

describe 'spree/addresses/new' do
let(:address) { FactoryGirl.build(:address) }

it 'renders new.html.erb for new address' do
assign(:address, FactoryGirl.build(:address))
render
view.should render_template(:template => 'new')
assign(:address, address)
render :template => 'spree/addresses/new', :address => address

rendered.should have_content('New Shipping Address')

rendered.should have_field('First Name', :type => 'text')
rendered.should have_field('Last Name', :type => 'text')
rendered.should have_field('Street Address', :type => 'text')
rendered.should have_field("Street Address (cont'd)", :type => 'text')
rendered.should have_field(I18n.t('activerecord.attributes.spree/address.address1'), :type => 'text')
rendered.should have_field(I18n.t('activerecord.attributes.spree/address.address2'), :type => 'text')
# Javascript can't be tested in views spec
rendered.should have_selector('select#address_country_id', :type => 'text')
# Javascript can't be tested in views spec
Expand Down Expand Up @@ -46,8 +46,7 @@
end


# Define a few methods to deal with problems in the views, due to the usage of
# form_for @address.
# a few methods to deal with problems in the views, due to the usage of form_for @address.
def address_path(address, format)
return spree.address_path(address, format)
end
Expand Down

0 comments on commit 6c9d1bc

Please sign in to comment.