Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 997bd339a7
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 75 lines (59 sloc) 2.821 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
require File.dirname(__FILE__) + '/test_helper.rb'

class TestAddresslogic < Test::Unit::TestCase
  def test_uk_uk_address_parts
    assert_equal ["12 Fancy House", "Bond Street", "London W1 8AJ", "United Kingdom"], uk_address.address_parts
    
    uk_address.street2 = ""
    assert_equal ["12 Fancy House", "London W1 8AJ", "United Kingdom"], uk_address.address_parts
    
    uk_address.country = ""
    assert_equal ["12 Fancy House", "London W1 8AJ"], uk_address.address_parts
    
    uk_address.city = ""
    assert_equal ["12 Fancy House", "W1 8AJ"], uk_address.address_parts
    
    uk_address.street1 = ""
    assert_equal ["W1 8AJ"], uk_address.address_parts
    
    uk_address.zip = ""
    assert_equal [], uk_address.address_parts
  end
  
  def test_american_address_parts
    assert_equal ["12 Fancy House", "Bond Street", "Tampa, Florida 45334", "United States"], american_address.address_parts
    
    american_address.street2 = ""
    assert_equal ["12 Fancy House", "Tampa, Florida 45334", "United States"], american_address.address_parts
    
    american_address.country = ""
    assert_equal ["12 Fancy House", "Tampa, Florida 45334"], american_address.address_parts
    
    american_address.city = ""
    assert_equal ["12 Fancy House", "Florida 45334"], american_address.address_parts
    
    american_address.state = ""
    assert_equal ["12 Fancy House", "45334"], american_address.address_parts

    american_address.street1 = ""
    assert_equal ["45334"], american_address.address_parts
    
    american_address.zip = ""
    assert_equal [], american_address.address_parts
  end
  
  def test_options
    assert_equal ["Bond Street"], uk_address.address_parts(:only => :street2)
    assert_equal ["12 Fancy House", "Bond Street"], uk_address.address_parts(:only => [:street1, :street2])
    assert_equal ["12 Fancy House", "London W1 8AJ", "United Kingdom"], uk_address.address_parts(:except => :street2)
    assert_equal ["London W1 8AJ", "United Kingdom"], uk_address.address_parts(:except => [:street1, :street2])
  end
  
  private
    def uk_address
      return @uk_address if @uk_address
      @uk_address = UKAddress.new
      @uk_address.street1 = "12 Fancy House"
      @uk_address.street2 = "Bond Street"
      @uk_address.city = "London"
      @uk_address.zip = "W1 8AJ"
      @uk_address.country = "United Kingdom"
      @uk_address
    end
    
    def american_address
      return @american_address if @american_address
      @american_address = AmericanAddress.new
      @american_address.street1 = "12 Fancy House"
      @american_address.street2 = "Bond Street"
      @american_address.city = "Tampa"
      @american_address.zip = "45334"
      @american_address.state = "Florida"
      @american_address.country = "United States"
      @american_address
    end
end
Something went wrong with that request. Please try again.