magic_addresses 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +37 -2
- data/app/models/magic_addresses/address.rb +3 -11
- data/app/models/magic_addresses/association.rb +35 -15
- data/app/models/magic_addresses/country.rb +5 -0
- data/app/models/magic_addresses/district.rb +4 -0
- data/app/models/magic_addresses/state.rb +4 -0
- data/app/models/magic_addresses/subdistrict.rb +2 -0
- data/lib/generators/magic_addresses/templates/magic_addresses_migration.rb +1 -10
- data/lib/generators/magic_addresses/templates/magic_initializer.rb +0 -2
- data/lib/helpers/mgca_helper.rb +6 -13
- data/lib/magic_addresses/configuration.rb +0 -2
- data/lib/magic_addresses/version.rb +1 -1
- data/spec/dummy/config/initializers/magic_addresses.rb +0 -2
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/{20150223223200_add_magic_addresses.rb → 20150225220219_add_magic_addresses.rb} +1 -10
- data/spec/dummy/db/schema.rb +1 -1
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +3729 -0
- data/spec/dummy/log/test.log +37882 -0
- data/spec/models/magic_addresses/address_spec.rb +171 -0
- data/spec/models/magic_addresses/association_spec.rb +93 -8
- metadata +4 -28
- data/app/models/concerns/address_builder.rb +0 -169
- data/app/models/concerns/has_address.rb +0 -67
- data/app/models/location/address.rb +0 -111
- data/app/models/location/city.rb +0 -39
- data/app/models/location/country.rb +0 -39
- data/app/models/location/district.rb +0 -37
- data/app/models/location/state.rb +0 -39
- data/app/models/location/subdistrict.rb +0 -38
- data/app/services/geo_coder.rb +0 -46
- data/lib/generators/magic_addresses/templates/location_addresses_migration.rb +0 -157
- data/spec/models/concerns/has_address_spec.rb +0 -92
- data/spec/models/location/address_spec.rb +0 -227
- data/spec/models/location/city_spec.rb +0 -27
- data/spec/models/location/country_spec.rb +0 -26
- data/spec/models/location/state_spec.rb +0 -27
- data/spec/models/location/subcity_spec.rb +0 -26
- data/spec/models/location/subsubcity_spec.rb +0 -27
@@ -1,111 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
class Location::Address < ActiveRecord::Base
|
3
|
-
|
4
|
-
# =====> R E W R I T E S <================================================================= #
|
5
|
-
include AddressBuilder
|
6
|
-
|
7
|
-
|
8
|
-
# =====> C O N S T A N T S <=============================================================== #
|
9
|
-
MODEL_PARAMS = [ :street_name, :street_number, :street_additional, :zipcode, :city_name, :district_name, :subdistrict_name,
|
10
|
-
:state_name, :country_name, :country_code, :address, :latitude, :longitude, :visibility, :id, :check, :_destroy ]
|
11
|
-
|
12
|
-
|
13
|
-
# =====> A S S O Z I A T I O N S <========================================================= #
|
14
|
-
translates :street, fallbacks_for_empty_translations: true
|
15
|
-
accepts_nested_attributes_for :translations
|
16
|
-
|
17
|
-
belongs_to :owner, polymorphic: true
|
18
|
-
belongs_to :context, polymorphic: true
|
19
|
-
|
20
|
-
belongs_to :subdistrict, class_name: "Location::Subdistrict", foreign_key: :subdistrict_id
|
21
|
-
belongs_to :district, class_name: "Location::District", foreign_key: :district_id
|
22
|
-
belongs_to :city, class_name: "Location::City", foreign_key: :city_id
|
23
|
-
belongs_to :state, class_name: "Location::State", foreign_key: :state_id
|
24
|
-
belongs_to :country, class_name: "Location::Country", foreign_key: :country_id
|
25
|
-
|
26
|
-
|
27
|
-
belongs_to :patient, -> { where(location_addresses: {owner_type: 'Patient'}) }, foreign_key: 'owner_id'
|
28
|
-
|
29
|
-
|
30
|
-
# =====> A T T R I B U T E S <============================================================= #
|
31
|
-
attr_accessor :address, :street_name, :subdistrict_name, :district_name, :city_name, :state_name, :state_short_name, :country_name, :country_code
|
32
|
-
|
33
|
-
acts_as_geolocated lat: 'latitude', lng: 'longitude'
|
34
|
-
|
35
|
-
|
36
|
-
# =====> V A L I D A T I O N <============================================================= #
|
37
|
-
validates_presence_of :city, :country, unless: :is_patient_address
|
38
|
-
validates_presence_of :city_name, :street_name, :street_number, :zipcode, if: :is_patient_address
|
39
|
-
|
40
|
-
|
41
|
-
# =====> C A L L B A C K S <=============================================================== #
|
42
|
-
|
43
|
-
# =====> S C O P E S <===================================================================== #
|
44
|
-
|
45
|
-
# =====> C L A S S - M E T H O D S <======================================================= #
|
46
|
-
def self.search(search)
|
47
|
-
if search
|
48
|
-
with_translations.where('street LIKE ?', "%#{search}%")
|
49
|
-
else
|
50
|
-
with_translations
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
|
55
|
-
# =====> I N S T A N C E - M E T H O D S <================================================= #
|
56
|
-
def with_translations(*locales)
|
57
|
-
locales = translated_locales if locales.empty?
|
58
|
-
includes(:translations).with_locales(locales).with_required_attributes
|
59
|
-
end
|
60
|
-
|
61
|
-
def presentation( type = "full" )
|
62
|
-
adr = []
|
63
|
-
adr << street if street.present?
|
64
|
-
adr << street_number if street_number.present? && street.present? && type != "secure"
|
65
|
-
adr = ["#{adr.join(" ")},"] if adr.count > 0
|
66
|
-
adr << zipcode if zipcode.present?
|
67
|
-
adr << city.name if city.present?
|
68
|
-
if adr.count == 0
|
69
|
-
I18n.t("addresses.no_address_given")
|
70
|
-
else
|
71
|
-
adr.join(" ")
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def street!
|
76
|
-
self.street ? self.street : self.street_default
|
77
|
-
end
|
78
|
-
|
79
|
-
def country!
|
80
|
-
self.country ? self.country.name : nil
|
81
|
-
end
|
82
|
-
|
83
|
-
def state!
|
84
|
-
self.state ? self.state.name : nil
|
85
|
-
end
|
86
|
-
|
87
|
-
def city!
|
88
|
-
self.city ? self.city.name : nil
|
89
|
-
end
|
90
|
-
|
91
|
-
def district!
|
92
|
-
self.district ? self.district.name : nil
|
93
|
-
end
|
94
|
-
|
95
|
-
def subdistrict!
|
96
|
-
self.subdistrict ? self.subdistrict.name : nil
|
97
|
-
end
|
98
|
-
|
99
|
-
|
100
|
-
# =====> P R I V A T E ! <======================================================== # # # # # # # #
|
101
|
-
private
|
102
|
-
def is_patient_address
|
103
|
-
Rails.logger.info "------"
|
104
|
-
Rails.logger.info "#{self.owner && self.owner.class.name.to_s == "Patient"} .. #{self.owner.class.name if self.owner}"
|
105
|
-
Rails.logger.info "#{self.owner_type && self.owner_type == "Patient"} .. #{self.owner_type if self.owner_type}"
|
106
|
-
Rails.logger.info "------"
|
107
|
-
# self.owner && self.owner.class.name.to_s == "Patient"
|
108
|
-
self.owner_type && self.owner_type == "Patient"
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
data/app/models/location/city.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
class Location::City < ActiveRecord::Base
|
3
|
-
|
4
|
-
# =====> R E W R I T E S <================================================================= #
|
5
|
-
include GlobalizedName
|
6
|
-
|
7
|
-
# =====> C O N S T A N T S <=============================================================== #
|
8
|
-
|
9
|
-
# =====> A S S O Z I A T I O N S <========================================================= #
|
10
|
-
belongs_to :state, class_name: "Location::State", foreign_key: :state_id
|
11
|
-
belongs_to :country, class_name: "Location::Country", foreign_key: :country_id
|
12
|
-
|
13
|
-
has_many :addresses, class_name: "Location::Address", foreign_key: :city_id
|
14
|
-
has_many :districts, class_name: "Location::District", foreign_key: :city_id
|
15
|
-
has_many :subdistricts, through: :districts, source: :subdistricts
|
16
|
-
|
17
|
-
|
18
|
-
# =====> A T T R I B U T E S <============================================================= #
|
19
|
-
|
20
|
-
|
21
|
-
# =====> V A L I D A T I O N <============================================================= #
|
22
|
-
|
23
|
-
# =====> C A L L B A C K S <=============================================================== #
|
24
|
-
|
25
|
-
# =====> S C O P E S <===================================================================== #
|
26
|
-
# => default_scope { includes(:translations).with_translations(I18n.locale).order( 'location_city_translations.name ASC' ) }
|
27
|
-
|
28
|
-
|
29
|
-
# =====> C L A S S - M E T H O D S <======================================================= #
|
30
|
-
|
31
|
-
|
32
|
-
# =====> I N S T A N C E - M E T H O D S <================================================= #
|
33
|
-
|
34
|
-
|
35
|
-
# =====> P R I V A T E ! <======================================================== # # # # # # # #
|
36
|
-
# private
|
37
|
-
|
38
|
-
|
39
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
class Location::Country < ActiveRecord::Base
|
3
|
-
|
4
|
-
# =====> R E W R I T E S <================================================================= #
|
5
|
-
include GlobalizedName
|
6
|
-
|
7
|
-
# =====> C O N S T A N T S <=============================================================== #
|
8
|
-
|
9
|
-
# =====> A S S O Z I A T I O N S <========================================================= #
|
10
|
-
has_many :addresses, class_name: "Location::Address", foreign_key: :country_id
|
11
|
-
|
12
|
-
has_many :states, class_name: "Location::State", foreign_key: :country_id
|
13
|
-
has_many :cities, through: :states, source: :cities
|
14
|
-
has_many :districts, through: :cities, source: :districts
|
15
|
-
has_many :subdistricts, through: :districts, source: :subdistricts
|
16
|
-
|
17
|
-
|
18
|
-
# =====> A T T R I B U T E S <============================================================= #
|
19
|
-
|
20
|
-
|
21
|
-
# =====> V A L I D A T I O N <============================================================= #
|
22
|
-
|
23
|
-
# =====> C A L L B A C K S <=============================================================== #
|
24
|
-
|
25
|
-
# =====> S C O P E S <===================================================================== #
|
26
|
-
# => default_scope { includes(:translations).with_translations(I18n.locale).order( 'location_country_translations.name ASC' ) }
|
27
|
-
|
28
|
-
|
29
|
-
# =====> C L A S S - M E T H O D S <======================================================= #
|
30
|
-
|
31
|
-
|
32
|
-
# =====> I N S T A N C E - M E T H O D S <================================================= #
|
33
|
-
|
34
|
-
|
35
|
-
# =====> P R I V A T E ! <======================================================== # # # # # # # #
|
36
|
-
# private
|
37
|
-
|
38
|
-
|
39
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
class Location::District < ActiveRecord::Base
|
3
|
-
|
4
|
-
# =====> R E W R I T E S <================================================================= #
|
5
|
-
include GlobalizedName
|
6
|
-
|
7
|
-
# =====> C O N S T A N T S <=============================================================== #
|
8
|
-
|
9
|
-
# =====> A S S O Z I A T I O N S <========================================================= #
|
10
|
-
belongs_to :city, class_name: "Location::City", foreign_key: :city_id
|
11
|
-
|
12
|
-
has_many :addresses, class_name: "Location::Address", foreign_key: :district_id
|
13
|
-
has_many :subdistricts, class_name: "Location::Subdistrict", foreign_key: :subdistrict_id
|
14
|
-
|
15
|
-
|
16
|
-
# =====> A T T R I B U T E S <============================================================= #
|
17
|
-
|
18
|
-
|
19
|
-
# =====> V A L I D A T I O N <============================================================= #
|
20
|
-
|
21
|
-
# =====> C A L L B A C K S <=============================================================== #
|
22
|
-
|
23
|
-
# =====> S C O P E S <===================================================================== #
|
24
|
-
# => default_scope { includes(:translations).with_translations(I18n.locale).order( 'location_district_translations.name ASC' ) }
|
25
|
-
|
26
|
-
|
27
|
-
# =====> C L A S S - M E T H O D S <======================================================= #
|
28
|
-
|
29
|
-
|
30
|
-
# =====> I N S T A N C E - M E T H O D S <================================================= #
|
31
|
-
|
32
|
-
|
33
|
-
# =====> P R I V A T E ! <======================================================== # # # # # # # #
|
34
|
-
# private
|
35
|
-
|
36
|
-
|
37
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
class Location::State < ActiveRecord::Base
|
3
|
-
|
4
|
-
# =====> R E W R I T E S <================================================================= #
|
5
|
-
include GlobalizedName
|
6
|
-
|
7
|
-
# =====> C O N S T A N T S <=============================================================== #
|
8
|
-
|
9
|
-
# =====> A S S O Z I A T I O N S <========================================================= #
|
10
|
-
belongs_to :country, class_name: "Location::Country", foreign_key: :country_id
|
11
|
-
|
12
|
-
has_many :addresses, class_name: "Location::Address", foreign_key: :state_id
|
13
|
-
has_many :cities, class_name: "Location::City", foreign_key: :state_id
|
14
|
-
has_many :districts, through: :cities, source: :districts
|
15
|
-
has_many :subdistricts, through: :districts, source: :subdistricts
|
16
|
-
|
17
|
-
|
18
|
-
# =====> A T T R I B U T E S <============================================================= #
|
19
|
-
|
20
|
-
|
21
|
-
# =====> V A L I D A T I O N <============================================================= #
|
22
|
-
|
23
|
-
# =====> C A L L B A C K S <=============================================================== #
|
24
|
-
|
25
|
-
# =====> S C O P E S <===================================================================== #
|
26
|
-
# => default_scope { includes(:translations).with_translations(I18n.locale).order( 'location_state_translations.name ASC' ) }
|
27
|
-
|
28
|
-
|
29
|
-
# =====> C L A S S - M E T H O D S <======================================================= #
|
30
|
-
|
31
|
-
|
32
|
-
# =====> I N S T A N C E - M E T H O D S <================================================= #
|
33
|
-
|
34
|
-
|
35
|
-
# =====> P R I V A T E ! <======================================================== # # # # # # # #
|
36
|
-
# private
|
37
|
-
|
38
|
-
|
39
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
class Location::Subdistrict < ActiveRecord::Base
|
3
|
-
|
4
|
-
# =====> R E W R I T E S <================================================================= #
|
5
|
-
include GlobalizedName
|
6
|
-
|
7
|
-
# =====> C O N S T A N T S <=============================================================== #
|
8
|
-
|
9
|
-
# =====> A S S O Z I A T I O N S <========================================================= #
|
10
|
-
belongs_to :city, class_name: "Location::City", foreign_key: :city_id
|
11
|
-
belongs_to :district, class_name: "Location::District", foreign_key: :district_id
|
12
|
-
|
13
|
-
has_many :addresses, class_name: "Location::Address", foreign_key: :subdistrict_id
|
14
|
-
|
15
|
-
|
16
|
-
# =====> A T T R I B U T E S <============================================================= #
|
17
|
-
|
18
|
-
|
19
|
-
# =====> V A L I D A T I O N <============================================================= #
|
20
|
-
|
21
|
-
# =====> C A L L B A C K S <=============================================================== #
|
22
|
-
|
23
|
-
# =====> S C O P E S <===================================================================== #
|
24
|
-
# => default_scope { includes(:translations).with_translations(I18n.locale).order( 'location_subdistrict_translations.name ASC' ) }
|
25
|
-
|
26
|
-
|
27
|
-
# =====> C L A S S - M E T H O D S <======================================================= #
|
28
|
-
|
29
|
-
|
30
|
-
# =====> I N S T A N C E - M E T H O D S <================================================= #
|
31
|
-
|
32
|
-
|
33
|
-
# =====> P R I V A T E ! <======================================================== # # # # # # # #
|
34
|
-
# private
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
|
data/app/services/geo_coder.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
class GeoCoder
|
3
|
-
|
4
|
-
def self.search( q = "", language = "de" )
|
5
|
-
if q.present?
|
6
|
-
log "GeoCode (#{language}): #{q}"
|
7
|
-
attempts = 0
|
8
|
-
begin
|
9
|
-
search_via_google
|
10
|
-
results = Geocoder.search( q, language: language )
|
11
|
-
log "google Geocoded: #{results.to_yaml}"
|
12
|
-
return results
|
13
|
-
rescue Exception => e
|
14
|
-
log "Google -- #{e}"
|
15
|
-
sleep 0.3
|
16
|
-
attempts += 1
|
17
|
-
end while attempts < 3
|
18
|
-
unless results
|
19
|
-
search_via_nominatim
|
20
|
-
results = Geocoder.search( q, language: language )
|
21
|
-
log "nominatim Geocoded: #{results.to_yaml}"
|
22
|
-
end
|
23
|
-
else
|
24
|
-
results = []
|
25
|
-
end
|
26
|
-
return results
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
def self.search_via_google
|
31
|
-
Geocoder.configure( :lookup => :google )
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.search_via_nominatim
|
35
|
-
Geocoder.configure( :lookup => :nominatim )
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.log( stuff = "+ geo + geo + geo + geo + geo + geo + " )
|
39
|
-
if Rails.env.development?
|
40
|
-
Rails.logger.info "+ geo + geo + geo + geo + geo + geo + "
|
41
|
-
Rails.logger.info stuff
|
42
|
-
Rails.logger.info "+ geo + geo + geo + geo + geo + geo + "
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
@@ -1,157 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
class AddMagicAddresses < ActiveRecord::Migration
|
3
|
-
def up
|
4
|
-
|
5
|
-
create_table :location_addresses do |t|
|
6
|
-
t.string :name # => name (if needed)
|
7
|
-
t.string :fetch_address # => if not nil fetch and translate that address
|
8
|
-
|
9
|
-
t.string :street_number
|
10
|
-
t.string :street_additional
|
11
|
-
t.integer :zipcode
|
12
|
-
|
13
|
-
t.string :visibility
|
14
|
-
t.boolean :default
|
15
|
-
|
16
|
-
t.float :longitude
|
17
|
-
t.float :latitude
|
18
|
-
|
19
|
-
t.references :subdistrict
|
20
|
-
t.references :district
|
21
|
-
t.references :city
|
22
|
-
t.references :state
|
23
|
-
t.references :country
|
24
|
-
|
25
|
-
t.references :owner, polymorphic: true
|
26
|
-
t.timestamps
|
27
|
-
end
|
28
|
-
|
29
|
-
add_index :location_addresses, :subdistrict_id
|
30
|
-
add_index :location_addresses, :district_id
|
31
|
-
add_index :location_addresses, :city_id
|
32
|
-
add_index :location_addresses, :state_id
|
33
|
-
add_index :location_addresses, :country_id
|
34
|
-
|
35
|
-
add_index :location_addresses, [:owner_type, :owner_id]
|
36
|
-
|
37
|
-
Location::Address.create_translation_table! :street => :string
|
38
|
-
|
39
|
-
#
|
40
|
-
# Country
|
41
|
-
#
|
42
|
-
create_table :location_countries do |t|
|
43
|
-
t.string :default_name
|
44
|
-
# t.string :name
|
45
|
-
t.string :iso_code, limit: 2
|
46
|
-
t.string :dial_code
|
47
|
-
t.string :fsm_state, default: "new"
|
48
|
-
t.timestamps
|
49
|
-
end
|
50
|
-
|
51
|
-
Location::Country.create_translation_table! :name => :string
|
52
|
-
|
53
|
-
load "#{ ::Rails.root }/db/seed_countries.rb"
|
54
|
-
|
55
|
-
#
|
56
|
-
# State
|
57
|
-
#
|
58
|
-
create_table :location_states do |t|
|
59
|
-
t.string :default_name
|
60
|
-
t.string :short_name
|
61
|
-
# t.string :name
|
62
|
-
t.string :fsm_state, default: "new"
|
63
|
-
t.references :country
|
64
|
-
t.timestamps
|
65
|
-
end
|
66
|
-
|
67
|
-
add_index :location_states, :country_id
|
68
|
-
|
69
|
-
Location::State.create_translation_table! :name => :string
|
70
|
-
|
71
|
-
#
|
72
|
-
# City
|
73
|
-
#
|
74
|
-
create_table :location_cities do |t|
|
75
|
-
t.string :default_name
|
76
|
-
t.string :short_name
|
77
|
-
# t.string :name
|
78
|
-
t.string :fsm_state, default: "new"
|
79
|
-
t.references :state
|
80
|
-
t.references :country
|
81
|
-
t.timestamps
|
82
|
-
end
|
83
|
-
|
84
|
-
add_index :location_cities, :state_id
|
85
|
-
add_index :location_cities, :country_id
|
86
|
-
|
87
|
-
Location::City.create_translation_table! :name => :string
|
88
|
-
|
89
|
-
#
|
90
|
-
# District
|
91
|
-
#
|
92
|
-
create_table :location_districts do |t|
|
93
|
-
t.string :default_name
|
94
|
-
t.string :short_name
|
95
|
-
# t.string :name
|
96
|
-
t.string :fsm_state, default: "new"
|
97
|
-
t.references :city
|
98
|
-
t.timestamps
|
99
|
-
end
|
100
|
-
|
101
|
-
add_index :location_districts, :city_id
|
102
|
-
|
103
|
-
Location::District.create_translation_table! :name => :string
|
104
|
-
|
105
|
-
#
|
106
|
-
# Subdistrict
|
107
|
-
#
|
108
|
-
create_table :location_subdistricts do |t|
|
109
|
-
t.string :default_name
|
110
|
-
t.string :short_name
|
111
|
-
# t.string :name
|
112
|
-
t.string :fsm_state, default: "new"
|
113
|
-
t.references :district
|
114
|
-
t.references :city
|
115
|
-
t.timestamps
|
116
|
-
end
|
117
|
-
|
118
|
-
add_index :location_subdistricts, :district_id
|
119
|
-
add_index :location_subdistricts, :city_id
|
120
|
-
|
121
|
-
Location::Subdistrict.create_translation_table! :name => :string
|
122
|
-
|
123
|
-
end
|
124
|
-
def down
|
125
|
-
|
126
|
-
remove_index :location_addresses, :subdistrict_id
|
127
|
-
remove_index :location_addresses, :district_id
|
128
|
-
remove_index :location_addresses, :city_id
|
129
|
-
remove_index :location_addresses, :state_id
|
130
|
-
remove_index :location_addresses, :country_id
|
131
|
-
remove_index :location_addresses, [:owner_type, :owner_id]
|
132
|
-
drop_table :location_addresses
|
133
|
-
Location::Address.drop_translation_table!
|
134
|
-
|
135
|
-
drop_table :location_countries
|
136
|
-
Location::Country.drop_translation_table!
|
137
|
-
|
138
|
-
remove_index :location_states, :country_id
|
139
|
-
drop_table :location_states
|
140
|
-
Location::State.drop_translation_table!
|
141
|
-
|
142
|
-
remove_index :location_cities, :state_id
|
143
|
-
remove_index :location_cities, :country_id
|
144
|
-
drop_table :location_cities
|
145
|
-
Location::City.drop_translation_table!
|
146
|
-
|
147
|
-
remove_index :location_districts, :city_id
|
148
|
-
drop_table :location_districts
|
149
|
-
Location::District.drop_translation_table!
|
150
|
-
|
151
|
-
remove_index :location_subdistricts, :district_id
|
152
|
-
remove_index :location_subdistricts, :city_id
|
153
|
-
drop_table :location_subdistricts
|
154
|
-
Location::Subdistrict.drop_translation_table!
|
155
|
-
|
156
|
-
end
|
157
|
-
end
|
@@ -1,92 +0,0 @@
|
|
1
|
-
# => require 'spec_helper'
|
2
|
-
# =>
|
3
|
-
# => describe HasAddress do
|
4
|
-
# => class TestPerson < ActiveRecord::Base
|
5
|
-
# => self.table_name = "users"
|
6
|
-
# => has_nested_address
|
7
|
-
# => end
|
8
|
-
# =>
|
9
|
-
# => class TestUser < ActiveRecord::Base
|
10
|
-
# => self.table_name = "users"
|
11
|
-
# => end
|
12
|
-
# =>
|
13
|
-
# => describe "has_one_address => inherit methods" do
|
14
|
-
# =>
|
15
|
-
# => let(:micha){
|
16
|
-
# => TestPerson.create!(name: "Schmidt", first_name: "Micha", email: "micha@example.com")
|
17
|
-
# => }
|
18
|
-
# =>
|
19
|
-
# => let(:ingo){
|
20
|
-
# => TestUser.create!(name: "Mueller", first_name: "Ingo", email: "ingo@example.com")
|
21
|
-
# => }
|
22
|
-
# =>
|
23
|
-
# => it "add address attributes" do
|
24
|
-
# => expect( micha.respond_to?(:address) ).to be true
|
25
|
-
# => expect( micha.address.new_record? ).to be true
|
26
|
-
# => micha.street = "Teststreet"
|
27
|
-
# => micha.city = "Testown"
|
28
|
-
# => micha.save
|
29
|
-
# => expect( micha.address.new_record? ).to be false
|
30
|
-
# => expect( micha.street ).to eql "Teststreet"
|
31
|
-
# => expect( micha.address.street ).to eql "Teststreet"
|
32
|
-
# => expect( micha.city ).to eql "Testown"
|
33
|
-
# => end
|
34
|
-
# =>
|
35
|
-
# => it "add address attributes only if asked for" do
|
36
|
-
# => expect( micha.respond_to?(:address) ).to be true
|
37
|
-
# => expect( ingo.respond_to?(:address) ).to be false
|
38
|
-
# => end
|
39
|
-
# =>
|
40
|
-
# => end
|
41
|
-
# =>
|
42
|
-
# => # Stack level too deep ???
|
43
|
-
# => describe "saves address attributes" do
|
44
|
-
# => class TestTheUser < ActiveRecord::Base
|
45
|
-
# => self.table_name = "users"
|
46
|
-
# => has_nested_address
|
47
|
-
# => end
|
48
|
-
# =>
|
49
|
-
# => # class TestTheCompany < ActiveRecord::Base
|
50
|
-
# => # self.table_name = "companies"
|
51
|
-
# => # has_one_address
|
52
|
-
# => # end
|
53
|
-
# =>
|
54
|
-
# => let(:user){ TestTheUser.create!(name: "Mueller", first_name: "Ingo", email: "ingo@example.com") }
|
55
|
-
# => # let(:company){ TestTheCompany.create!( name: "Mueller Inc." ) }
|
56
|
-
# =>
|
57
|
-
# => it "save as own attributes" do
|
58
|
-
# => user.street = "Fakestr."
|
59
|
-
# => user.number = "14"
|
60
|
-
# => user.zip = "12345"
|
61
|
-
# => user.city = "Berlin"
|
62
|
-
# => expect( user.valid? ).to eq true
|
63
|
-
# => user.save
|
64
|
-
# => expect( user.street ).to eq "Fakestr."
|
65
|
-
# => expect( user.address.street ).to eq "Fakestr."
|
66
|
-
# => expect( user.number ).to eq "14"
|
67
|
-
# => expect( user.address.number ).to eq "14"
|
68
|
-
# => expect( user.zip ).to eq "12345"
|
69
|
-
# => expect( user.address.zip ).to eq "12345"
|
70
|
-
# => expect( user.city).to eq "Berlin"
|
71
|
-
# => expect( user.address.city ).to eq "Berlin"
|
72
|
-
# => end
|
73
|
-
# =>
|
74
|
-
# => it "save as child attributes" do
|
75
|
-
# => expect( user.valid? ).to eq true
|
76
|
-
# => addr = FactoryGirl.attributes_for(:address)
|
77
|
-
# =>
|
78
|
-
# => user.address_attributes = addr
|
79
|
-
# => expect( user.valid? ).to eq true
|
80
|
-
# =>
|
81
|
-
# => expect( user.street ).to eq addr[:street]
|
82
|
-
# => expect( user.address.street ).to eq addr[:street]
|
83
|
-
# => expect( user.number ).to eq addr[:number]
|
84
|
-
# => expect( user.address.number ).to eq addr[:number]
|
85
|
-
# => expect( user.zip ).to eq addr[:zip]
|
86
|
-
# => expect( user.address.zip ).to eq addr[:zip]
|
87
|
-
# => expect( user.city ).to eq addr[:city]
|
88
|
-
# => expect( user.address.city ).to eq addr[:city]
|
89
|
-
# => end
|
90
|
-
# => end
|
91
|
-
# =>
|
92
|
-
# => end
|