campfire_logic 2.0.4 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.4
1
+ 2.0.5
@@ -14,6 +14,8 @@ class Locale
14
14
  field :accuracy, :type => Integer
15
15
  field :coordinates, :type => Array
16
16
  field :kind
17
+ index :kind
18
+ index :name
17
19
  index [[ :coordinates, Mongo::GEO2D ]], :min => -200, :max => 200
18
20
 
19
21
  # Scopes =========================================================================================
@@ -108,6 +110,10 @@ class Locale
108
110
  super unless self.country?
109
111
  end
110
112
 
113
+ def has_other_locations?
114
+ location_locales.count > 1
115
+ end
116
+
111
117
  # Returns location-locales found within this locale.
112
118
  def location_locales
113
119
  self.descendants.valid_location
@@ -161,6 +161,16 @@ class Location
161
161
  self.locale.parent
162
162
  end
163
163
 
164
+ def fix_duplicate_city
165
+ duplicate_city = city_locale
166
+ valid_city = Locale.cities.where(:name => duplicate_city.name).first
167
+
168
+ if valid_city && valid_city.has_other_locations?
169
+ self.locale.parent = valid_city
170
+ self.locale.save
171
+ end
172
+ end
173
+
164
174
  # Returns this location's state locale.
165
175
  def state_locale
166
176
  self.city_locale.parent
@@ -184,6 +194,10 @@ class Location
184
194
  end
185
195
  end
186
196
 
197
+ def city_renamed?
198
+ city != city_locale.name
199
+ end
200
+
187
201
  # Clears all addressing data set by the geocoder.
188
202
  def clear_geocoding
189
203
  self.geocoder_result = nil
@@ -212,8 +226,7 @@ class Location
212
226
  self.locale.name = name
213
227
  self.locale.save
214
228
 
215
- # does its city locale have other locations?
216
- if self.city_locale.children.count > 1
229
+ if city_renamed? && city_locale.has_other_locations?
217
230
  # create a new city
218
231
  self.locale.parent = self.state_locale.children.create(:name => self.city)
219
232
  else
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "campfire_logic"
8
- s.version = "2.0.4"
8
+ s.version = "2.0.5"
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-02-21"
12
+ s.date = "2012-02-29"
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 = [
@@ -63,6 +63,11 @@ describe Location do
63
63
  @two_boots.state_locale.parent.should == Locale.us.first
64
64
  end
65
65
 
66
+ it "doesn't create duplicate cities after re-localization" do
67
+ @two_boots.validate_address_and_localize
68
+ Locale.where(:name => 'Brooklyn').count.should == 1
69
+ end
70
+
66
71
  it 'updates the locale tree of a modified location' do
67
72
  # Locale.any_instance.unstub :geocode
68
73
  # @tea_lounge.unstub :geocode
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: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 4
10
- version: 2.0.4
9
+ - 5
10
+ version: 2.0.5
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-02-21 00:00:00 Z
18
+ date: 2012-02-29 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: bson_ext