campfire_logic 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.0
1
+ 1.2.1
@@ -8,8 +8,7 @@ class DirectoryController < ApplicationController
8
8
  end
9
9
 
10
10
  def show
11
- @locale = find_location_locale || find_city || find_state || find_country || Locale.init_root
12
- @location = find_location_locale.location if find_location_locale
11
+ @locale = find_locale || Locale.init_root
13
12
  Rails.logger.info "Found a #{@locale.kind} locale: #{@locale.name}"
14
13
  end
15
14
 
@@ -19,20 +18,8 @@ class DirectoryController < ApplicationController
19
18
 
20
19
  private
21
20
 
22
- def find_city
23
- @city ||= find_state.children.to_a.detect{ |c| c.slug == params[:city] } if params[:city]
24
- end
25
-
26
- def find_country
27
- @country ||= Locale.root.children.to_a.detect{ |c| c.slug == params[:country] } if params[:country]
28
- end
29
-
30
- def find_location_locale
31
- @location_locale ||= find_city.children.to_a.detect{ |c| c.slug == params[:location] } if params[:location]
32
- end
33
-
34
- def find_state
35
- @state ||= Locale.first(:conditions => {:slug => params[:state]}) if params[:state]
21
+ def find_locale
22
+ Locale.first(:conditions => {:slug => params[:slug]})
36
23
  end
37
24
 
38
25
  def search_by_string
@@ -7,7 +7,7 @@ module ApplicationHelper
7
7
  html << link_to( 'Locations', locations_path ) if controller?('locations')
8
8
  html << link_to( 'Search', directory_search_root_path ) if controller?('directory') && action?('search')
9
9
  html << link_to( 'Services', services_path ) if controller?('services')
10
- html << @locale.non_root_ancestors_and_self.map{ |l| link_to l.name, l.to_url } if @locale && ! @locale.country?
10
+ html << @locale.non_root_ancestors_and_self.map{ |l| link_to l.name, l.to_param } if @locale && ! @locale.country?
11
11
  (html * ' &gt; ').html_safe
12
12
  end
13
13
 
data/app/models/locale.rb CHANGED
@@ -28,6 +28,7 @@ class Locale
28
28
 
29
29
  # Callbacks ======================================================================================
30
30
  after_create :post_process
31
+ before_save :set_slug
31
32
 
32
33
  # Macros =========================================================================================
33
34
  attr_accessor :skip_geocoding
@@ -51,9 +52,8 @@ class Locale
51
52
  # Instance methods: Initialization ===============================================================
52
53
 
53
54
  def post_process
54
- self.set_slug
55
- self.geocode unless self.skip_geocoding || self.geocoding_address.blank?
56
55
  self.set_kind
56
+ self.geocode unless self.skip_geocoding || self.geocoding_address.blank?
57
57
  self.save
58
58
  end
59
59
 
@@ -135,12 +135,12 @@ class Locale
135
135
 
136
136
  # Sets the slug for this locale. Slugs from the locale tree are used to build this locale's URL.
137
137
  def set_slug
138
- self.slug = self.root? ? nil : self.name.to_s.to_url
138
+ self.slug = self.root? ? nil : "#{(non_root_ancestors_and_self_names * '/').to_url.gsub('-slash-', '/')}"
139
139
  end
140
140
 
141
141
  # Returns the permalink for this locale.
142
- def to_url
143
- "/directory/#{(non_root_ancestors_and_self_names * '/').to_url.gsub('-slash-', '/')}"
142
+ def to_param
143
+ "/#{CampfireLogic.directory_slug}/#{slug}"
144
144
  end
145
145
 
146
146
  # Instance Methods: Typing =======================================================================
@@ -38,11 +38,7 @@ class Location
38
38
  # Macros =========================================================================================
39
39
  attr_accessor :geocoder_result
40
40
  geocoded_by :geocoding_address do |location, results|
41
- if geo = results.first
42
- location.geocoder_result = GeocoderGoogleResult.new geo.data
43
- location.country, location.country_long_name, location[:state], location.state_long_name = geo.country_code, geo.country, geo.state_code, geo.state
44
- location.coordinates = [geo.longitude, geo.latitude]
45
- end
41
+ parse_geo location, results.first if results.first
46
42
  end
47
43
 
48
44
  trimmed_fields :address1, :address2, :city, :email, :fax, :location_number, :name, :phone, :state, :zip
@@ -71,6 +67,19 @@ class Location
71
67
  end
72
68
  end
73
69
 
70
+ def self.parse_geo location, geo
71
+ if Geocoder::Configuration.lookup == :google
72
+ location.geocoder_result = GeocoderGoogleResult.new geo.data
73
+ else
74
+ location.address1 = geo.data['line1']
75
+ location.city = geo.data['city']
76
+ location.state = geo.data['state']
77
+ end
78
+
79
+ location.country, location.country_long_name, location[:state], location.state_long_name = geo.country_code, geo.country, geo.state_code, geo.state
80
+ location.coordinates = [geo.longitude, geo.latitude]
81
+ end
82
+
74
83
  # Instance methods: Overrides ====================================================================
75
84
  def address1=(value)
76
85
  clear_geocoding if self.address1 != value
@@ -91,7 +100,7 @@ class Location
91
100
 
92
101
  # Returns this location's address for geocoding. It omits the second address field to simplify post-processing.
93
102
  def geocoding_address
94
- [address1, city, state].select{|s| ! s.blank?} * ' '
103
+ [address1, city, state].select{|s| ! s.blank?} * ', '
95
104
  end
96
105
 
97
106
  # Returns this location's street address, combining the two address fields with the specified delimiter. Latter defaults to a space.
@@ -105,6 +114,7 @@ class Location
105
114
  def call_geocode
106
115
  return :new if self.geocoding_address.blank?
107
116
  geocode
117
+ return :new unless Geocoder::Configuration.lookup == :google
108
118
  audit_address
109
119
  self.geocoder_result.try(:partial_match?) ? :partial_match : :validated
110
120
  end
@@ -21,7 +21,7 @@
21
21
  <%- @locale.sorted_children.in_groups(2, false).each do |group| -%>
22
22
  <ul style="float: left; margin-right: 1em; width: 40%;">
23
23
  <%- group.each do |_child| -%>
24
- <li><%= link_to _child.name, _child.to_url -%></li>
24
+ <li><%= link_to _child.name, _child.to_param -%></li>
25
25
  <%- end -%>
26
26
  </ul>
27
27
  <%- end -%>
@@ -1,4 +1,4 @@
1
- <%- set_title "Location Directory - #{ @location.name }" -%>
1
+ <%- set_title "Location Directory - #{ (@location || @locale).name }" -%>
2
2
 
3
3
  <%= render 'shared/location' -%><br style="clear: both;" />
4
4
  <br style="clear: both;" />
@@ -24,7 +24,7 @@
24
24
  <td><%= location.geocoding_address -%></td>
25
25
  <td>
26
26
  <%- if location.locale -%>
27
- <%= link_to location.locale.to_url, location.locale.to_url -%>
27
+ <%= link_to location.locale.to_param, location.locale.to_param -%>
28
28
  <%- end -%>
29
29
  </td>
30
30
  <td class="crud_links"><%= crud_links(location, [:show, :edit, :destroy]) -%></td>
@@ -1,18 +1,18 @@
1
- <div class="vcard">
2
- <div class="fn org"><%= link_to @location.name, @location.locale.to_url -%></div>
3
- <p class="adr">
4
- <span class="street-address"><%= h @location.street_address('<br />') -%></span><br />
5
- <span class="locality"><%= h @location.city -%></span>,
6
- <span class="region"><%= h @location.state.upcase -%></span>
7
- <span class="postal-code"><%= h @location.zip -%></span><br />
8
- <span class="tel">Phone
9
- <span class="type" style="display: none;">Work</span>
10
- <span class="value"><%= h @location.phone -%></span>
1
+ <div class=vcard>
2
+ <div class="fn org"><%= link_to @location.name, @location.locale.to_param -%></div>
3
+ <p class=adr>
4
+ <span class=street-address><%= h @location.street_address('<br/>') -%></span><br />
5
+ <span class=locality><%= h @location.city -%></span>,
6
+ <span class=region><%= h @location.state.upcase -%></span>
7
+ <span class=postal-code><%= h @location.zip -%></span><br />
8
+ <span class=tel>Phone
9
+ <span class=type style="display: none;">Work</span>
10
+ <span class=value><%= h @location.phone -%></span>
11
11
  </span><br />
12
12
  <%- if @location.fax && @location.fax.size > 3 -%>
13
- <span class="tel">Fax
14
- <span class="value"><%= h @location.fax -%></span>
13
+ <span class=tel>Fax
14
+ <span class=value><%= h @location.fax -%></span>
15
15
  </span><br />
16
16
  <%- end -%>
17
17
  </p>
18
- </div>
18
+ </div>
@@ -5,28 +5,28 @@
5
5
  var directionsService = new google.maps.DirectionsService();
6
6
  var locations = [
7
7
  <%- if place && place.location? && place.geocoded? -%>
8
- <%= raw "['#{h(escape_javascript place.location.name)}', #{place.coordinates[0]}, #{place.coordinates[1]}, '#{h(escape_javascript place.location.name)}<br />#{h(escape_javascript place.location.address1)}<br />#{h(escape_javascript place.location.city)}, #{h(escape_javascript place.location.state)} #{h(escape_javascript place.location.zip)}<br /><br />Directions: <a href=\"javascript:showDirectionsTo(0)\">To here<\/a> / <a href=\"javascript:showDirectionsFrom(0)\">From here<\/a>']" -%>
8
+ <%= raw "['#{h(escape_javascript place.location.name)}', #{place.coordinates[1]}, #{place.coordinates[0]}, '#{h(escape_javascript place.location.name)}<br />#{h(escape_javascript place.location.address1)}<br />#{h(escape_javascript place.location.city)}, #{h(escape_javascript place.location.state)} #{h(escape_javascript place.location.zip)}<br /><br />Directions: <a href=\"javascript:showDirectionsTo(0)\">To here<\/a> / <a href=\"javascript:showDirectionsFrom(0)\">From here<\/a>']" -%>
9
9
  <%- else -%>
10
- <%= raw locations.select{ |l| l.geocoded? }.inject([]) { |a, l| i = a.size; a << "['#{h(escape_javascript l.name)}', #{l.coordinates[0]}, #{l.coordinates[1]}, '#{link_to h(escape_javascript l.name), l.locale.to_url}<br />#{h(escape_javascript l.address1)}<br />#{h(escape_javascript l.city)}, #{h(escape_javascript l.state)} #{h(escape_javascript l.zip)}<br /><br />Directions: <a href=\"javascript:showDirectionsTo(#{i})\">To here<\/a> / <a href=\"javascript:showDirectionsFrom(#{i})\">From here<\/a>']"; a } * ",\r" -%>
10
+ <%= raw locations.select{ |l| l.geocoded? }.inject([]) { |a, l| i = a.size; a << "['#{h(escape_javascript l.name)}', #{l.coordinates[1]}, #{l.coordinates[0]}, '#{link_to h(escape_javascript l.name), l.locale.to_param}<br />#{h(escape_javascript l.address1)}<br />#{h(escape_javascript l.city)}, #{h(escape_javascript l.state)} #{h(escape_javascript l.zip)}<br /><br />Directions: <a href=\"javascript:showDirectionsTo(#{i})\">To here<\/a> / <a href=\"javascript:showDirectionsFrom(#{i})\">From here<\/a>']"; a } * ",\r" -%>
11
11
  <%- end -%>
12
12
  ];
13
13
  var map;
14
14
  var markers = [];
15
15
  var openWindow;
16
16
 
17
- function initializeMap() {
17
+ function initializeMap(id) {
18
18
  var myOptions = {
19
19
  zoom: <%= place && place.zoom_level || 4 -%>,
20
20
  <%- if place && place.geocoded? -%>
21
- center: new google.maps.LatLng(<%= place.coordinates[0] -%>, <%= place.coordinates[1] -%>),
21
+ center: new google.maps.LatLng(<%= place.coordinates[1] -%>, <%= place.coordinates[0] -%>),
22
22
  <%- elsif place && place.parent && place.parent.geocoded? -%>
23
- center: new google.maps.LatLng(<%= place.parent.coordinates[0] -%>, <%= place.parent.coordinates[1] -%>),
23
+ center: new google.maps.LatLng(<%= place.parent.coordinates[1] -%>, <%= place.parent.coordinates[0] -%>),
24
24
  <%- else -%>
25
25
  center: new google.maps.LatLng(37.09024, -95.712891),
26
26
  <%- end -%>
27
27
  mapTypeId: google.maps.MapTypeId.ROADMAP
28
28
  };
29
- map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
29
+ map = new google.maps.Map(document.getElementById(id), myOptions);
30
30
  directionsDisplay.setMap(map);
31
31
  directionsDisplay.setPanel($('#directions_panel')[0]);
32
32
  for (var i = 0; i < locations.length; i++) {
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "campfire_logic"
8
- s.version = "1.2.0"
8
+ s.version = "1.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Roderick Monje"]
12
- s.date = "2012-01-29"
12
+ s.date = "2012-01-31"
13
13
  s.description = "Users can browse locations by country, city, and state and search locations by string or zip code. Administrators can manage locations and the services they offer."
14
14
  s.email = "rod@seologic.com"
15
15
  s.extra_rdoc_files = [
data/config/routes.rb CHANGED
@@ -24,10 +24,7 @@ Rails.application.routes.draw do
24
24
  end
25
25
 
26
26
  constraints(LocaleConstraint.new) do
27
- get "#{CampfireLogic.directory_slug}/:country" => 'directory#show', :as => 'directory_show_country'
28
- get "#{CampfireLogic.directory_slug}/:country/:state" => 'directory#show', :as => 'directory_show_state'
29
- get "#{CampfireLogic.directory_slug}/:country/:state/:city" => 'directory#show', :as => 'directory_show_city'
30
- get "#{CampfireLogic.directory_slug}/:country/:state/:city/:location" => 'directory#show', :as => 'directory_show_location'
27
+ get "#{CampfireLogic.directory_slug}/*slug" => 'directory#show'
31
28
  end
32
29
 
33
30
  resources :locations do
@@ -4,7 +4,13 @@ describe Locale do
4
4
  before :all do
5
5
  Locale.delete_all
6
6
  Locale.init_root
7
- location = Location.new :address1 => '450 Flatbush Avenue', :city => 'Brooklyn', :name => 'Prospect Park Zoo', :state => 'NY'
7
+ Location.delete_all
8
+ # Locale.any_instance.stubs :geocode
9
+ # Location.any_instance.stubs(:country_long_name).returns 'United States'
10
+ # Location.any_instance.stubs(:state_long_name).returns 'New York'
11
+ # Location.any_instance.stubs :geocode
12
+ # GeocoderGoogleResult.stubs(:new).returns stub('prospect park zoo', :city => 'Brooklyn', :country_long_name => 'United States', :country_short_name => 'US', :formatted_address => '450 Flatbush Avenue', :formatted_street_address => '450 Flatbush Avenue', :lat => 1, :lng => 1, :partial_match? => false, :postal_code => '11217', :state_long_name => 'New York', :state_short_name => 'NY')
13
+ location = Location.new :address1 => '25 Columbia Heights', :city => 'Brooklyn', :name => 'Prospect Park Zoo', :state => 'NY'
8
14
  location.validate_address!
9
15
  location.localize
10
16
  end
@@ -27,6 +33,7 @@ describe Locale do
27
33
  specify { subject.name.should == 'United States' }
28
34
  specify { subject.should be_country }
29
35
  specify { subject.geocoding_address.should == 'United States' }
36
+ specify { subject.geocoded?.should be_true }
30
37
  end
31
38
 
32
39
  context 'when state' do
@@ -35,6 +42,7 @@ describe Locale do
35
42
  specify { subject.should be_state }
36
43
  specify { subject.geocoding_address.should == 'New York' }
37
44
  specify { subject.friendly_name.should == 'New York' }
45
+ specify { subject.geocoded?.should be_true }
38
46
  end
39
47
 
40
48
  context 'when city' do
@@ -43,6 +51,7 @@ describe Locale do
43
51
  specify { subject.should be_city }
44
52
  specify { subject.geocoding_address.should == 'Brooklyn New York' }
45
53
  specify { subject.friendly_name.should == 'Brooklyn, New York' }
54
+ specify { subject.geocoded?.should be_true }
46
55
  end
47
56
 
48
57
  context 'when location' do
@@ -50,6 +59,7 @@ describe Locale do
50
59
  specify { subject.name.should == 'Prospect Park Zoo' }
51
60
  specify { subject.should be_location }
52
61
  specify { subject.geocoding_address.should be_nil }
53
- specify { subject.to_url.should =~ /united-states\/new-york\/brooklyn\/prospect-park-zoo$/ }
62
+ specify { subject.to_param.should =~ /united-states\/new-york\/brooklyn\/prospect-park-zoo$/ }
63
+ specify { subject.geocoded?.should be_true }
54
64
  end
55
65
  end
@@ -10,82 +10,151 @@ describe Location do
10
10
  Location.delete_all
11
11
  end
12
12
 
13
- before(:each) do
14
- @white_house = Location.new :address1 => '1600 Pennsylvania', :city => 'Washington', :name => 'White House'
15
- @white_house.validate_address!
16
- @white_house.localize
17
-
18
- @tea_lounge = Location.new :address1 => ' 837 Union St ', :address2 => ' Suite 1 ', :city => ' Brooklyn ', :name => ' Tea Lounge ', :state => ' NY ', :zip => ' 11215 '
19
- @tea_lounge.validate_address!
20
- @tea_lounge.localize
21
-
22
- @two_boots = Location.new(:address1 => '514 2nd Street', :city => 'Brooklyn', :name => 'Two Boots of Brooklyn', :state => 'NY')
23
- @two_boots.validate_address!
24
- @two_boots.localize
25
-
26
- @new_park = Location.new(:address1 => '15671 Crossbay Boulevard', :city => 'Howard Beach', :name => 'New Park Pizza', :state => 'NY')
27
- @new_park.validate_address!
28
- @new_park.localize
29
- end
30
-
31
- context 'addressing' do
32
- it 'returns an address for geocoding' do
33
- @tea_lounge.geocoding_address.should == '837 Union St Brooklyn NY'
34
- @white_house.geocoding_address.should == '1600 Pennsylvania Washington DC'
35
- end
36
-
37
- it 'returns a concatenated street address' do
38
- @tea_lounge.street_address.should == '837 Union St Suite 1'
39
- @white_house.street_address.should == '1600 Pennsylvania'
13
+ context '' do
14
+ before(:all) { create_locations }
15
+
16
+ context 'addressing' do
17
+ it 'returns an address for geocoding' do
18
+ @tea_lounge.geocoding_address.should == '837 Union St, Brooklyn, NY'
19
+ @white_house.geocoding_address.should == '1600 Pennsylvania Ave, Washington, DC'
20
+ end
21
+
22
+ it 'returns a concatenated street address' do
23
+ @tea_lounge.street_address.should == '837 Union St Suite 1'
24
+ @white_house.street_address.should == '1600 Pennsylvania Ave'
25
+ end
26
+
27
+ it 'approves user-validated addresses' do
28
+ if Geocoder::Configuration.lookup == :google
29
+ @white_house.approve_address!
30
+ @white_house.should be_validated
31
+ else
32
+ pending 'For address validation, you must geocode with Google'
33
+ end
34
+ end
40
35
  end
41
36
 
42
- it 'approves user-validated addresses' do
43
- @white_house.approve_address!
44
- @white_house.should be_validated
37
+ context 'localization' do
38
+ it 'creates a locale tree for a new location' do
39
+ @tea_lounge.locale.name.should == 'Tea Lounge'
40
+ @tea_lounge.city_locale.city?.should be_true
41
+ @tea_lounge.city_locale.name.should == 'Brooklyn'
42
+ @tea_lounge.state_locale.state?.should be_true
43
+ @tea_lounge.state_locale.name.should == 'New York'
44
+ @tea_lounge.state_locale.parent.should == Locale.us.first
45
+ end
46
+
47
+ it 'merges a new location into a matching city tree' do
48
+ @two_boots.locale.name.should == 'Brooklyn Museum'
49
+ @two_boots.locale.sibling_of?(@tea_lounge.locale).should be_true
50
+ @two_boots.city_locale.should == @tea_lounge.city_locale
51
+ @two_boots.state_locale.should == @tea_lounge.state_locale
52
+ @two_boots.state_locale.parent.should == Locale.us.first
53
+ end
54
+
55
+ it 'merges a new location into a matching state tree' do
56
+ @new_park.locale.name.should == 'New Park Pizza'
57
+ @new_park.city_locale.city?.should be_true
58
+ @new_park.city_locale.name.should == 'Howard Beach'
59
+ @new_park.state_locale.should == @tea_lounge.state_locale
60
+ @new_park.state_locale.parent.should == Locale.us.first
61
+ end
62
+
63
+ it 'leaves the locale tree intact if other locations belong to it' do
64
+ @two_boots.city_locale.city?.should be_true
65
+ @two_boots.city_locale.name.should == 'Brooklyn'
66
+ @two_boots.state_locale.state?.should be_true
67
+ @two_boots.state_locale.name.should == 'New York'
68
+ @two_boots.state_locale.parent.should == Locale.us.first
69
+ end
70
+
71
+ it 'updates the locale tree of a modified location' do
72
+ # Locale.any_instance.unstub :geocode
73
+ # @tea_lounge.unstub :geocode
74
+ # @tea_lounge.unstub :geocoder_result
75
+ @tea_lounge.locale.to_param.should == '/directory/united-states/new-york/brooklyn/tea-lounge'
76
+ @tea_lounge.name = 'White House'
77
+ @tea_lounge.address1 = '1600 Pennsylvania Ave NW'
78
+ @tea_lounge.city = 'Washington'
79
+ @tea_lounge.state = 'DC'
80
+ @tea_lounge.validate_address!
81
+ @tea_lounge.localize
82
+ @tea_lounge.reload
83
+ @tea_lounge.locale.to_param.should == '/directory/united-states/district-of-columbia/washington/white-house'
84
+ @tea_lounge.city_locale.city?.should be_true
85
+ @tea_lounge.city_locale.name.should == 'Washington'
86
+ @tea_lounge.city_locale.to_param.should == '/directory/united-states/district-of-columbia/washington'
87
+ @tea_lounge.state_locale.state?.should be_true
88
+ @tea_lounge.state_locale.name.should == 'District of Columbia'
89
+ @tea_lounge.state_locale.to_param.should == '/directory/united-states/district-of-columbia'
90
+ @tea_lounge.state_locale.parent.should == Locale.us.first
91
+ @tea_lounge.state_locale.parent.to_param.should == '/directory/united-states'
92
+ end
45
93
  end
46
94
  end
47
95
 
48
- context 'geocoding' do
49
- it 'geocodes itself' do
50
- @tea_lounge.geocoded?.should be_true
51
- @white_house.geocoded?.should be_true
52
- end
53
-
54
- it 'validates addresses with Google Maps' do
55
- @tea_lounge.country_long_name.should == 'United States'
56
- @tea_lounge.state_long_name.should == 'New York'
57
- @tea_lounge.validated_address1.should be_blank
58
- @tea_lounge.validated_city.should be_blank
59
- @tea_lounge.validated_zip.should be_blank
60
- @tea_lounge.should be_validated
61
-
62
- @white_house.should be_partial_match
63
- @white_house.country_long_name.should == 'United States'
64
- @white_house.state_long_name.should == 'District of Columbia'
65
- @white_house.validated_address1.should == '1600 Pennsylvania Ave NW'
66
- @white_house.validated_city.should be_blank
67
- @white_house.validated_zip.should == '20500'
68
- end
69
-
70
- it 'detects matching address fields' do
71
- @tea_lounge.matches_geocoder?(:address1).should be_true
72
- @tea_lounge.matches_geocoder?(:city).should be_true
73
- @tea_lounge.matches_geocoder?(:zip).should be_true
74
- end
75
-
76
- it 'detects mismatching address fields' do
77
- @white_house.matches_geocoder?(:address1).should be_false
78
- @white_house.matches_geocoder?(:zip).should be_false
96
+ context '' do
97
+ before(:each) { create_locations }
98
+
99
+ context 'geocoding' do
100
+ it 'geocodes itself' do
101
+ @tea_lounge.geocoded?.should be_true
102
+ @white_house.geocoded?.should be_true
103
+ end
104
+
105
+ it 'validates addresses with Google Maps' do
106
+ if Geocoder::Configuration.lookup == :google
107
+ @tea_lounge.country_long_name.should == 'United States'
108
+ @tea_lounge.state_long_name.should == 'New York'
109
+ @tea_lounge.validated_address1.should be_blank
110
+ @tea_lounge.validated_city.should be_blank
111
+ @tea_lounge.validated_zip.should be_blank
112
+ @tea_lounge.should be_validated
113
+
114
+ @white_house.should be_partial_match
115
+ @white_house.country_long_name.should == 'United States'
116
+ @white_house.state_long_name.should == 'District of Columbia'
117
+ @white_house.validated_address1.should == '1600 Pennsylvania Ave NW'
118
+ @white_house.validated_city.should be_blank
119
+ @white_house.validated_zip.should == '20500'
120
+ else
121
+ pending 'For address validation, you must geocode with Google'
122
+ end
123
+ end
124
+
125
+ it 'detects matching address fields' do
126
+ if Geocoder::Configuration.lookup == :google
127
+ @tea_lounge.matches_geocoder?(:address1).should be_true
128
+ @tea_lounge.matches_geocoder?(:city).should be_true
129
+ @tea_lounge.matches_geocoder?(:zip).should be_true
130
+ else
131
+ pending 'For address validation, you must geocode with Google'
132
+ end
133
+ end
134
+
135
+ it 'detects mismatching address fields' do
136
+ if Geocoder::Configuration.lookup == :google
137
+ @white_house.matches_geocoder?(:address1).should be_false
138
+ @white_house.matches_geocoder?(:zip).should be_false
139
+ else
140
+ pending 'For address validation, you must geocode with Google'
141
+ end
142
+ end
79
143
  end
80
144
 
81
145
  it 're-validates modified addresses with Google Maps' do
82
- @white_house.address1 = ''
83
- @white_house.validate_address!
84
- @white_house.should be_validated
146
+ if Geocoder::Configuration.lookup == :google
147
+ @white_house.address1 = '900 Ohio Drive'
148
+ @white_house.validate_address!
149
+ @white_house.approve_address!
150
+ @white_house.should be_validated
151
+ else
152
+ pending 'For address validation, you must geocode with Google'
153
+ end
85
154
  end
86
155
 
87
156
  it 'preserves geocoding if updated with irrelevant changes' do
88
- @white_house.update_attributes :name => 'The White House', :city => 'Washington'
157
+ @white_house.update_attributes :name => 'The White House'
89
158
  @white_house.geocoded?.should be_true
90
159
  end
91
160
 
@@ -98,88 +167,79 @@ describe Location do
98
167
  @white_house.validated_zip.should be_nil
99
168
  @white_house.should be_new
100
169
  end
101
- end
102
170
 
103
- context 'localization' do
104
- it 'creates a locale tree for a new location' do
105
- @tea_lounge.locale.name.should == 'Tea Lounge'
106
- @tea_lounge.city_locale.city?.should be_true
107
- @tea_lounge.city_locale.name.should == 'Brooklyn'
108
- @tea_lounge.state_locale.state?.should be_true
109
- @tea_lounge.state_locale.name.should == 'New York'
110
- @tea_lounge.state_locale.parent.should == Locale.us.first
171
+ it "destroys its city when it's the only location" do
172
+ Locale.exists?(:conditions => {:name => 'Tea Lounge'}).should be_true
173
+ Locale.exists?(:conditions => {:name => 'Brooklyn'}).should be_true
174
+ Locale.exists?(:conditions => {:name => 'New York'}).should be_true
175
+ @tea_lounge.destroy
176
+ # TODO: strangely, this assertion fails even though destroys work in the app and all subsequent assertions pass
177
+ # Location.exists?(:conditions => {:name => 'Tea Lounge'}).should be_false
178
+ Locale.exists?(:conditions => {:name => 'Tea Lounge'}).should be_false
179
+ Locale.exists?(:conditions => {:name => 'Brooklyn'}).should be_true
180
+ Locale.exists?(:conditions => {:name => 'New York'}).should be_true
181
+
182
+ Locale.exists?(:conditions => {:name => 'Brooklyn Museum'}).should be_true
183
+ Locale.exists?(:conditions => {:name => 'Brooklyn'}).should be_true
184
+ Locale.exists?(:conditions => {:name => 'New York'}).should be_true
185
+ @two_boots.destroy
186
+ # TODO: strangely, this assertion fails even though destroys work in the app and all subsequent assertions pass
187
+ # Location.exists?(:conditions => {:name => 'Brooklyn Museum'}).should be_false
188
+ Locale.exists?(:conditions => {:name => 'Brooklyn Museum'}).should be_false
189
+ Locale.exists?(:conditions => {:name => 'Brooklyn'}).should be_false
190
+ Locale.exists?(:conditions => {:name => 'New York'}).should be_true
111
191
  end
112
192
 
113
- it 'merges a new location into a matching city tree' do
114
- @two_boots.locale.name.should == 'Two Boots of Brooklyn'
115
- @two_boots.locale.sibling_of?(@tea_lounge.locale).should be_true
116
- @two_boots.city_locale.should == @tea_lounge.city_locale
117
- @two_boots.state_locale.should == @tea_lounge.state_locale
118
- @two_boots.state_locale.parent.should == Locale.us.first
119
- end
120
-
121
- it 'merges a new location into a matching state tree' do
122
- @new_park.locale.name.should == 'New Park Pizza'
123
- @new_park.city_locale.city?.should be_true
124
- @new_park.city_locale.name.should == 'Howard Beach'
125
- @new_park.state_locale.should == @tea_lounge.state_locale
126
- @new_park.state_locale.parent.should == Locale.us.first
127
- end
128
-
129
- it 'leaves the locale tree intact if other locations belong to it' do
130
- @two_boots.city_locale.city?.should be_true
131
- @two_boots.city_locale.name.should == 'Brooklyn'
132
- @two_boots.state_locale.state?.should be_true
133
- @two_boots.state_locale.name.should == 'New York'
134
- @two_boots.state_locale.parent.should == Locale.us.first
135
- end
136
-
137
- it 'updates the locale tree of a modified location' do
138
- @tea_lounge.name = 'White House'
139
- @tea_lounge.address1 = '1600 Pennsylvania Ave NW'
140
- @tea_lounge.city = 'Washington'
141
- @tea_lounge.state = 'DC'
142
- @tea_lounge.validate_address!
143
- @tea_lounge.localize
144
- @tea_lounge.city_locale.city?.should be_true
145
- @tea_lounge.city_locale.name.should == 'Washington'
146
- @tea_lounge.state_locale.state?.should be_true
147
- @tea_lounge.state_locale.name.should == 'District of Columbia'
148
- @tea_lounge.state_locale.parent.should == Locale.us.first
193
+ it "destroys its state when it's the only location" do
194
+ Locale.exists?(:conditions => {:name => 'White House'}).should be_true
195
+ Locale.exists?(:conditions => {:name => /Washington/}).should be_true
196
+ Locale.exists?(:conditions => {:name => 'District of Columbia'}).should be_true
197
+ @white_house.destroy
198
+ # TODO: strangely, this assertion fails even though destroys work in the app and all subsequent assertions pass
199
+ # Location.exists?(:conditions => {:name => 'White House'}).should be_false
200
+ Locale.exists?(:conditions => {:name => 'White House'}).should be_false
201
+ Locale.exists?(:conditions => {:name => 'Washington'}).should be_false
202
+ Locale.exists?(:conditions => {:name => 'District of Columbia'}).should be_false
149
203
  end
150
204
  end
151
-
152
- it "destroys its city when it's the only location" do
153
- Locale.exists?(:conditions => {:name => 'Tea Lounge'}).should be_true
154
- Locale.exists?(:conditions => {:name => 'Brooklyn'}).should be_true
155
- Locale.exists?(:conditions => {:name => 'New York'}).should be_true
156
- @tea_lounge.destroy
157
- # TODO: strangely, this assertion fails even though destroys work in the app and all subsequent assertions pass
158
- # Location.exists?(:conditions => {:name => 'Tea Lounge'}).should be_false
159
- Locale.exists?(:conditions => {:name => 'Tea Lounge'}).should be_false
160
- Locale.exists?(:conditions => {:name => 'Brooklyn'}).should be_true
161
- Locale.exists?(:conditions => {:name => 'New York'}).should be_true
162
-
163
- Locale.exists?(:conditions => {:name => 'Two Boots of Brooklyn'}).should be_true
164
- Locale.exists?(:conditions => {:name => 'Brooklyn'}).should be_true
165
- Locale.exists?(:conditions => {:name => 'New York'}).should be_true
166
- @two_boots.destroy
167
- # TODO: strangely, this assertion fails even though destroys work in the app and all subsequent assertions pass
168
- # Location.exists?(:conditions => {:name => 'Two Boots of Brooklyn'}).should be_false
169
- Locale.exists?(:conditions => {:name => 'Two Boots of Brooklyn'}).should be_false
170
- Locale.exists?(:conditions => {:name => 'Brooklyn'}).should be_false
171
- Locale.exists?(:conditions => {:name => 'New York'}).should be_true
172
- end
173
-
174
- it "destroys its state when it's the only location" do
175
- Locale.exists?(:conditions => {:name => 'White House'}).should be_true
176
- Locale.exists?(:conditions => {:name => 'Washington'}).should be_true
177
- Locale.exists?(:conditions => {:name => 'District of Columbia'}).should be_true
178
- @white_house.destroy
179
- # TODO: strangely, this assertion fails even though destroys work in the app and all subsequent assertions pass
180
- # Location.exists?(:conditions => {:name => 'White House'}).should be_false
181
- Locale.exists?(:conditions => {:name => 'White House'}).should be_false
182
- Locale.exists?(:conditions => {:name => 'Washington'}).should be_false
183
- Locale.exists?(:conditions => {:name => 'District of Columbia'}).should be_false
184
- end
185
205
  end
206
+
207
+ def create_locations
208
+ Locale.delete_all
209
+ Location.delete_all
210
+ # Locale.any_instance.stubs :geocode
211
+ # Location.any_instance.stubs :geocode
212
+ # Location.any_instance.stubs(:country_long_name).returns 'United States'
213
+
214
+ @white_house = Location.new :address1 => '1600 Pennsylvania Ave', :city => 'Washington', :name => 'White House'
215
+ # @white_house.stubs(:geocoder_result).returns stub('white house', :city => 'Washington', :country_short_name => 'US', :country_long_name => 'United States', :formatted_address => '1600 Pennsylvania Ave NW', :formatted_street_address => '1600 Pennsylvania Ave NW', :partial_match? => true, :postal_code => '20500', :state_long_name => 'District of Columbia', :state_short_name => 'DC')
216
+ # @white_house.state = @white_house.geocoder_result.state_short_name
217
+ # @white_house.state_long_name = @white_house.geocoder_result.state_long_name
218
+ # @white_house.coordinates = []
219
+ @white_house.validate_address!
220
+ @white_house.localize
221
+
222
+ @tea_lounge = Location.new :address1 => '837 Union St', :address2 => ' Suite 1 ', :city => 'Brooklyn', :name => ' Tea Lounge ', :state => 'NY', :zip => ' 11215 '
223
+ # @tea_lounge.stubs(:geocoder_result).returns stub('tea lounge', :city => 'Brooklyn', :country_short_name => 'US', :country_long_name => 'United States', :formatted_address => '837 Union St', :formatted_street_address => '837 Union St', :partial_match? => false, :postal_code => '11215', :state_long_name => 'New York', :state_short_name => 'NY')
224
+ # @tea_lounge.state = @tea_lounge.geocoder_result.state_short_name
225
+ # @tea_lounge.state_long_name = @tea_lounge.geocoder_result.state_long_name
226
+ # @tea_lounge.coordinates = []
227
+ @tea_lounge.validate_address!
228
+ @tea_lounge.localize
229
+
230
+ @two_boots = Location.new(:address1 => '200 Eastern Pkwy', :city => 'Brooklyn', :name => 'Brooklyn Museum', :state => 'NY')
231
+ # @two_boots.stubs(:geocoder_result).returns stub('tea lounge', :city => 'Brooklyn', :country_short_name => 'US', :country_long_name => 'United States', :formatted_address => '837 Union St', :formatted_street_address => '837 Union St', :partial_match? => false, :postal_code => '11217', :state_long_name => 'New York', :state_short_name => 'NY')
232
+ # @two_boots.state = @two_boots.geocoder_result.state_short_name
233
+ # @two_boots.state_long_name = @two_boots.geocoder_result.state_long_name
234
+ # @two_boots.coordinates = []
235
+ @two_boots.validate_address!
236
+ @two_boots.localize
237
+
238
+ @new_park = Location.new(:address1 => '15671 Crossbay Boulevard', :city => 'Howard Beach', :name => 'New Park Pizza', :state => 'NY')
239
+ # @new_park.stubs(:geocoder_result).returns stub('tea lounge', :city => 'Brooklyn', :country_short_name => 'US', :country_long_name => 'United new_park', :formatted_address => '837 Union St', :formatted_street_address => '837 Union St', :partial_match? => false, :postal_code => '11217', :state_long_name => 'New York', :state_short_name => 'NY')
240
+ # @new_park.state = @new_park.geocoder_result.state_short_name
241
+ # @new_park.state_long_name = @new_park.geocoder_result.state_long_name
242
+ # @new_park.coordinates = []
243
+ @new_park.validate_address!
244
+ @new_park.localize
245
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: campfire_logic
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 0
10
- version: 1.2.0
9
+ - 1
10
+ version: 1.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Roderick Monje
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-29 00:00:00 Z
18
+ date: 2012-01-31 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: bson_ext