require 'spec_helper'
require_relative '../formatter'

describe 'AddressFormatter' do
  let(:data)  { [ { building_name:      "1-2",
                    thoroughfare:       "Nursery Lane",
                    dependent_locality: "Penn",
                    town:               "High Wycombe",
                    postcode:           "HP10 8LS" },
                  { building_name:      "12A",
                    thoroughfare:       "Upperkirkgate",
                    town:               "Aberdeen",
                    postcode:           "AB10 1BA" },
                  { building_name:      "K",
                    thoroughfare:       "Portland Road",
                    town:               "Dorking",
                    postcode:           "RH4 1EW" },
                  { organisation:       "The Tambourine Warehouse",
                    building_name:      "Unit 1-3",
                    dependent_thoroughfare: "Industrial Estate",
                    thoroughfare:       "Tame Road",
                    town:               "London",
                    postcode:           "E6 7HS" },
                  { organisation:       "Quirky Candles Ltd",
                    building_name:      "Stall 4-5",
                    thoroughfare:       "Market Square",
                    town:               "Liverpool",
                    postcode:           "L8 1LH" },
                  { organisation:       "The Fudge Factory",
                    building_name:      "Unit 1a",
                    thoroughfare:       "Dyce Industrial Estate",
                    dependent_locality: "Dyce",
                    town:               "Glasgow",
                    postcode:           "G21 7EZ" },
                  { organisation:       "Fiona's Flowers",
                    building_name:      "Rear Of 5a",
                    thoroughfare:       "High Street",
                    town:               "Gateshead",
                    postcode:           "NE8 1BH" },
                  { organisation:       "Platinum Finance",
                    building_name:      "Suite 1-3",
                    thoroughfare:       "Station Road",
                    town:               "Musselburgh",
                    postcode:           "EH21 7PB" },
                  { organisation:       "Leda Engineering Ltd",
                    dependent_locality: "Appleford",
                    town:               "Abingdon",
                    postcode:           "OX14 4PG" },
                  { building_number:    1,
                    thoroughfare:       "Acacia Avenue",
                    town:               "Abingdon",
                    postcode:           "OX14 4PG" },
                  { building_name:      "1a",
                    dependent_thoroughfare: "Seastone Court",
                    thoroughfare:       "Station Road",
                    town:               "Holt",
                    postcode:           "NR25 7HG" },
                  { building_name:      "The Manor",
                    thoroughfare:       "Upper Hill",
                    town:               "Horley",
                    postcode:           "RH6 0HP" },
                  { organisation:       "S D Alcott Florists",
                    building_name:      "Flower House 189a",
                    thoroughfare:       "Pye Green Road",
                    town:               "Cannock",
                    postcode:           "WS11 5SB" },
                  { organisation:       "James Villa Holidays",
                    building_name:      "Centre 30",
                    thoroughfare:       "St. Laurence Avenue",
                    town:               "Grafton",
                    postcode:           "ME16 0LP" },
                  { building_name:      "Victoria House",
                    building_number:    15,
                    thoroughfare:       "The Street",
                    town:               "Christchurch",
                    postcode:           "BH23 6AA" },
                  { sub_building_name:  "Flat 1",
                    building_number:    12,
                    thoroughfare:       "Lime Tree Avenue",
                    town:               "Bristol",
                    postcode:           "BS8 4AB" },
                  { sub_building_name:  "A",
                    building_number:    12,
                    thoroughfare:       "High Street North",
                    dependent_locality: "Coombe Bissett",
                    town:               "Salisbury",
                    postcode:           "SP5 4NA",
                    concat_indicator:   "Y" },
                  { sub_building_name:  "10B",
                    building_name:      "Barry Jackson Tower",
                    thoroughfare:       "Estone Walk",
                    town:               "Birmingham",
                    postcode:           "B6 5BA" },
                  { sub_building_name:  "Caretakers Flat",
                    building_name:      "110-114",
                    thoroughfare:       "High Street West",
                    town:               "Bristol",
                    postcode:           "BS1 2AW" },
                  { sub_building_name:  "Stables Flat",
                    building_name:      "The Manor",
                    thoroughfare:       "Upper Hill",
                    town:               "Horley",
                    postcode:           "RH6 0HP" },
                  { sub_building_name:  "2B",
                    building_name:      "The Tower",
                    building_number:    27,
                    thoroughfare:       "John Street",
                    town:               "Winchester",
                    postcode:           "SO23 9AP" },
                  { sub_building_name:  "Basement Flat",
                    building_name:      "Victoria House",
                    building_number:    15,
                    thoroughfare:       "The Street",
                    town:               "Coryton",
                    postcode:           "BP23 6AA" } ] }
  let(:addrs)   { [ "1-2 Nursery Lane\nPenn\nHIGH WYCOMBE\nHP10 8LS",
                    "12A Upperkirkgate\nABERDEEN\nAB10 1BA",
                    "K, Portland Road\nDORKING\nRH4 1EW",
                    "The Tambourine Warehouse\nUnit 1-3\nIndustrial Estate\nTame Road\nLONDON\nE6 7HS",
                    "Quirky Candles Ltd\nStall 4-5\nMarket Square\nLIVERPOOL\nL8 1LH",
                    "The Fudge Factory\nUnit 1a\nDyce Industrial Estate\nDyce\nGLASGOW\nG21 7EZ",
                    "Fiona's Flowers\nRear Of 5a\nHigh Street\nGATESHEAD\nNE8 1BH",
                    "Platinum Finance\nSuite 1-3\nStation Road\nMUSSELBURGH\nEH21 7PB",
                    "Leda Engineering Ltd\nAppleford\nABINGDON\nOX14 4PG",
                    "1 Acacia Avenue\nABINGDON\nOX14 4PG",
                    "1a Seastone Court\nStation Road\nHOLT\nNR25 7HG",
                    "The Manor\nUpper Hill\nHORLEY\nRH6 0HP",
                    "S D Alcott Florists\nFlower House\n189a Pye Green Road\nCANNOCK\nWS11 5SB",
                    "James Villa Holidays\nCentre 30\nSt. Laurence Avenue\nGRAFTON\nME16 0LP",
                    "Victoria House\n15 The Street\nCHRISTCHURCH\nBH23 6AA",
                    "Flat 1\n12 Lime Tree Avenue\nBRISTOL\nBS8 4AB",
                    "12A High Street North\nCoombe Bissett\nSALISBURY\nSP5 4NA",
                    "10B Barry Jackson Tower\nEstone Walk\nBIRMINGHAM\nB6 5BA",
                    "Caretakers Flat\n110-114 High Street West\nBRISTOL\nBS1 2AW",
                    "Stables Flat\nThe Manor\nUpper Hill\nHORLEY\nRH6 0HP",
                    "2B The Tower\n27 John Street\nWINCHESTER\nSO23 9AP",
                    "Basement Flat\nVictoria House\n15 The Street\nCORYTON\nBP23 6AA" ] }
  it "properly formats addresses" do
    data.each_with_index do |addr_data, idx|
      result = AddressFormatter.format_address(addr_data)
      result.should == addrs[idx]
    end
  end
end




