addresses 2.0 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/addresses/cities_controller.rb +0 -2
- data/app/controllers/addresses/countries_controller.rb +17 -0
- data/app/controllers/addresses/neighborhoods_controller.rb +6 -4
- data/app/controllers/addresses/regions_controller.rb +17 -0
- data/app/controllers/addresses/states_controller.rb +6 -1
- data/app/models/addresses/city.rb +14 -12
- data/app/models/addresses/country.rb +8 -1
- data/app/models/addresses/neighborhood.rb +6 -2
- data/app/models/addresses/region.rb +16 -0
- data/app/models/addresses/state.rb +5 -2
- data/config/routes.rb +4 -2
- data/db/migrate/20191010233002_create_addresses_regions.rb +15 -0
- data/db/migrate/20191010233144_add_indexes_to_regions.rb +8 -0
- data/db/migrate/20191010233512_add_capital_to_addresses_state.rb +7 -0
- data/db/migrate/20191010233947_add_region_id_to_addresses_states.rb +7 -0
- data/db/migrate/20191010234112_add_latitude_and_longitude_to_addresses_address.rb +10 -0
- data/db/migrate/20191010235008_add_latitude_and_longitude_to_addresses_country.rb +10 -0
- data/db/migrate/20191010235050_add_latitude_and_longitude_to_addresses_states.rb +10 -0
- data/db/migrate/20191010235112_add_latitude_and_longitude_to_addresses_cities.rb +10 -0
- data/db/migrate/20191010235129_add_latitude_and_longitude_to_addresses_neighborhoods.rb +10 -0
- data/db/migrate/20191010235145_add_latitude_and_longitude_to_addresses_zipcodes.rb +10 -0
- data/spec/controllers/addresses/states_controller_spec.rb +3 -2
- data/spec/dummy/Gemfile.lock +3 -3
- data/spec/dummy/app/assets/config/manifest.js +2 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/{20191008054118_create_addresses_countries.addresses.rb → 20191011003823_create_addresses_countries.addresses.rb} +0 -0
- data/spec/dummy/db/migrate/{20191008054119_create_addresses_states.addresses.rb → 20191011003824_create_addresses_states.addresses.rb} +0 -0
- data/spec/dummy/db/migrate/{20191008054120_create_addresses_cities.addresses.rb → 20191011003825_create_addresses_cities.addresses.rb} +0 -0
- data/spec/dummy/db/migrate/{20191008054121_create_addresses_neighborhoods.addresses.rb → 20191011003826_create_addresses_neighborhoods.addresses.rb} +0 -0
- data/spec/dummy/db/migrate/{20191008054122_create_addresses_addresses.addresses.rb → 20191011003827_create_addresses_addresses.addresses.rb} +0 -0
- data/spec/dummy/db/migrate/{20191008054123_create_addresses_zipcodes.addresses.rb → 20191011003828_create_addresses_zipcodes.addresses.rb} +0 -0
- data/spec/dummy/db/migrate/{20191008054124_remove_zipcode_attributes_from_addresses.addresses.rb → 20191011003829_remove_zipcode_attributes_from_addresses.addresses.rb} +0 -0
- data/spec/dummy/db/migrate/{20191008054125_add_indexes.addresses.rb → 20191011003830_add_indexes.addresses.rb} +0 -0
- data/spec/dummy/db/migrate/20191011003831_create_addresses_regions.addresses.rb +16 -0
- data/spec/dummy/db/migrate/20191011003832_add_indexes_to_regions.addresses.rb +9 -0
- data/spec/dummy/db/migrate/20191011003833_add_capital_to_addresses_state.addresses.rb +8 -0
- data/spec/dummy/db/migrate/20191011003834_add_region_id_to_addresses_states.addresses.rb +8 -0
- data/spec/dummy/db/migrate/20191011003835_add_latitude_and_longitude_to_addresses_address.addresses.rb +11 -0
- data/spec/dummy/db/migrate/20191011003836_add_latitude_and_longitude_to_addresses_country.addresses.rb +11 -0
- data/spec/dummy/db/migrate/20191011003837_add_latitude_and_longitude_to_addresses_states.addresses.rb +11 -0
- data/spec/dummy/db/migrate/20191011003838_add_latitude_and_longitude_to_addresses_cities.addresses.rb +11 -0
- data/spec/dummy/db/migrate/20191011003839_add_latitude_and_longitude_to_addresses_neighborhoods.addresses.rb +11 -0
- data/spec/dummy/db/migrate/20191011003840_add_latitude_and_longitude_to_addresses_zipcodes.addresses.rb +11 -0
- data/spec/dummy/db/schema.rb +41 -1
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +1137 -0
- data/spec/dummy/log/test.log +8159 -0
- data/spec/factories/regions.rb +9 -0
- data/spec/models/addresses/city_spec.rb +2 -2
- data/spec/models/addresses/region_spec.rb +10 -0
- data/spec/requests/countries_spec.rb +31 -0
- data/spec/requests/neighborhoods_spec.rb +12 -0
- data/spec/requests/regions_spec.rb +31 -0
- data/spec/requests/states_spec.rb +31 -0
- metadata +63 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 075ca513fc5ee9679a0b68dd5cfc5bf77bdd66df03c51007ea1ea8eeb16ec05c
|
4
|
+
data.tar.gz: 0f6a47c6941efdb2d4249fcd80af1fcd2e126b39363ba6fcf667ac004d6fa996
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 695120a2a42383f2135985dd584f75038d75e2efc268434b988216d68eceaf80f7888c22ca64dfb8c610363ba1ca1ad7f5786432097947a02244e0a8309cb555
|
7
|
+
data.tar.gz: fae24ef00cdeb5679bc83f29b6df96e10973e5dcd2b0a1c94eb57c3751b5d2a2a7ea5fdd3868b544bfb389a5c32ffcda0c7f3635d83c338ca91b65b037f84cd2
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_dependency 'addresses/application_controller'
|
4
|
+
|
5
|
+
module Addresses
|
6
|
+
class CountriesController < ApplicationController
|
7
|
+
def index
|
8
|
+
@countries = Country.all
|
9
|
+
render json: @countries
|
10
|
+
end
|
11
|
+
|
12
|
+
def show
|
13
|
+
@city = Country.find(params[:id])
|
14
|
+
render json: @city
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -5,11 +5,13 @@ require_dependency 'addresses/application_controller'
|
|
5
5
|
module Addresses
|
6
6
|
class NeighborhoodsController < ApplicationController
|
7
7
|
def index
|
8
|
-
@
|
9
|
-
|
10
|
-
@neighborhoods = @city.neighborhoods.order('name asc')
|
11
|
-
|
8
|
+
@neighborhoods = Neighborhood.where(city_id: params[:city_id])
|
12
9
|
render json: @neighborhoods
|
13
10
|
end
|
11
|
+
|
12
|
+
def show
|
13
|
+
@neighborhood = Neighborhood.find(params[:id])
|
14
|
+
render json: @neighborhood
|
15
|
+
end
|
14
16
|
end
|
15
17
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_dependency 'addresses/application_controller'
|
4
|
+
|
5
|
+
module Addresses
|
6
|
+
class RegionsController < ApplicationController
|
7
|
+
def index
|
8
|
+
@regions = Region.where(country_id: params[:country_id])
|
9
|
+
render json: @regions
|
10
|
+
end
|
11
|
+
|
12
|
+
def show
|
13
|
+
@region = Region.find(params[:id])
|
14
|
+
render json: @region
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -5,8 +5,13 @@ require_dependency 'addresses/application_controller'
|
|
5
5
|
module Addresses
|
6
6
|
class StatesController < ApplicationController
|
7
7
|
def index
|
8
|
-
@states = State.
|
8
|
+
@states = State.where(country_id: params[:country_id])
|
9
9
|
render json: @states
|
10
10
|
end
|
11
|
+
|
12
|
+
def show
|
13
|
+
@state = State.find(params[:id])
|
14
|
+
render json: @state
|
15
|
+
end
|
11
16
|
end
|
12
17
|
end
|
@@ -2,11 +2,14 @@
|
|
2
2
|
|
3
3
|
module Addresses
|
4
4
|
class City < ActiveRecord::Base
|
5
|
-
validates :name, :state_id, presence: true
|
6
|
-
|
7
5
|
belongs_to :state
|
8
6
|
|
7
|
+
default_scope { order('name asc') }
|
8
|
+
|
9
9
|
has_many :neighborhoods
|
10
|
+
has_many :zipcodes
|
11
|
+
|
12
|
+
validates :name, :state_id, presence: true
|
10
13
|
|
11
14
|
class << self
|
12
15
|
def filter(params = {})
|
@@ -21,16 +24,15 @@ module Addresses
|
|
21
24
|
end
|
22
25
|
|
23
26
|
private
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
27
|
+
def query_word
|
28
|
+
adapter == 'postgresql' ? 'ilike' : 'like'
|
29
|
+
end
|
30
|
+
|
31
|
+
def adapter
|
32
|
+
ActiveRecord::Base.connection.instance_values['config'][:adapter]
|
33
|
+
rescue
|
34
|
+
nil
|
35
|
+
end
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|
@@ -2,7 +2,14 @@
|
|
2
2
|
|
3
3
|
module Addresses
|
4
4
|
class Country < ActiveRecord::Base
|
5
|
-
|
5
|
+
default_scope { order('name asc') }
|
6
|
+
|
7
|
+
has_many :regions
|
6
8
|
has_many :states
|
9
|
+
has_many :cities, through: :states
|
10
|
+
has_many :zipcodes, through: :cities
|
11
|
+
has_many :addresses, through: :zipcodes
|
12
|
+
|
13
|
+
validates :name, presence: true
|
7
14
|
end
|
8
15
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Addresses
|
4
|
+
class Region < ActiveRecord::Base
|
5
|
+
belongs_to :country
|
6
|
+
|
7
|
+
default_scope { order('name asc') }
|
8
|
+
|
9
|
+
has_many :states
|
10
|
+
has_many :cities, through: :states
|
11
|
+
has_many :neighborhoods, through: :cities
|
12
|
+
has_many :zipcodes, through: :cities
|
13
|
+
|
14
|
+
validates :name, :country_id, presence: true
|
15
|
+
end
|
16
|
+
end
|
@@ -2,10 +2,13 @@
|
|
2
2
|
|
3
3
|
module Addresses
|
4
4
|
class State < ActiveRecord::Base
|
5
|
-
validates :name, :country_id, presence: true
|
6
|
-
|
7
5
|
belongs_to :country
|
8
6
|
|
7
|
+
default_scope { order('name asc') }
|
8
|
+
|
9
9
|
has_many :cities
|
10
|
+
has_many :zipcodes, through: :cities
|
11
|
+
|
12
|
+
validates :name, :country_id, presence: true
|
10
13
|
end
|
11
14
|
end
|
data/config/routes.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
Addresses::Engine.routes.draw do
|
4
|
+
resources :countries, only: [:index, :show]
|
5
|
+
resources :regions, only: [:index, :show]
|
4
6
|
resources :cities, only: [:index, :show]
|
5
|
-
resources :neighborhoods, only: [:index]
|
6
|
-
resources :states, only: [:index]
|
7
|
+
resources :neighborhoods, only: [:index, :show]
|
8
|
+
resources :states, only: [:index, :show]
|
7
9
|
|
8
10
|
get 'zipcodes/:zipcode', to: 'zipcodes#show', constraints: { zipcode: /\d{8}/ }, as: :zipcode
|
9
11
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class CreateAddressesRegions < ActiveRecord::Migration[6.0]
|
4
|
+
def change
|
5
|
+
create_table :addresses_regions do |t|
|
6
|
+
t.string :name
|
7
|
+
t.string :acronym
|
8
|
+
t.float :latitude
|
9
|
+
t.float :longitude
|
10
|
+
t.references :country, index: true
|
11
|
+
|
12
|
+
t.timestamps
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class AddLatitudeAndLongitudeToAddressesAddress < ActiveRecord::Migration[6.0]
|
4
|
+
def change
|
5
|
+
add_column :addresses_addresses, :latitude, :float
|
6
|
+
add_index :addresses_addresses, :latitude
|
7
|
+
add_column :addresses_addresses, :longitude, :float
|
8
|
+
add_index :addresses_addresses, :longitude
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class AddLatitudeAndLongitudeToAddressesCountry < ActiveRecord::Migration[6.0]
|
4
|
+
def change
|
5
|
+
add_column :addresses_countries, :latitude, :float
|
6
|
+
add_index :addresses_countries, :latitude
|
7
|
+
add_column :addresses_countries, :longitude, :float
|
8
|
+
add_index :addresses_countries, :longitude
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class AddLatitudeAndLongitudeToAddressesStates < ActiveRecord::Migration[6.0]
|
4
|
+
def change
|
5
|
+
add_column :addresses_states, :latitude, :float
|
6
|
+
add_index :addresses_states, :latitude
|
7
|
+
add_column :addresses_states, :longitude, :float
|
8
|
+
add_index :addresses_states, :longitude
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class AddLatitudeAndLongitudeToAddressesCities < ActiveRecord::Migration[6.0]
|
4
|
+
def change
|
5
|
+
add_column :addresses_cities, :latitude, :float
|
6
|
+
add_index :addresses_cities, :latitude
|
7
|
+
add_column :addresses_cities, :longitude, :float
|
8
|
+
add_index :addresses_cities, :longitude
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class AddLatitudeAndLongitudeToAddressesNeighborhoods < ActiveRecord::Migration[6.0]
|
4
|
+
def change
|
5
|
+
add_column :addresses_neighborhoods, :latitude, :float
|
6
|
+
add_index :addresses_neighborhoods, :latitude
|
7
|
+
add_column :addresses_neighborhoods, :longitude, :float
|
8
|
+
add_index :addresses_neighborhoods, :longitude
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class AddLatitudeAndLongitudeToAddressesZipcodes < ActiveRecord::Migration[6.0]
|
4
|
+
def change
|
5
|
+
add_column :addresses_zipcodes, :latitude, :float
|
6
|
+
add_index :addresses_zipcodes, :latitude
|
7
|
+
add_column :addresses_zipcodes, :longitude, :float
|
8
|
+
add_index :addresses_zipcodes, :longitude
|
9
|
+
end
|
10
|
+
end
|
@@ -4,10 +4,11 @@ require 'rails_helper'
|
|
4
4
|
RSpec.describe Addresses::StatesController, type: :controller do
|
5
5
|
routes { Addresses::Engine.routes }
|
6
6
|
|
7
|
-
let!(:
|
7
|
+
let!(:country) { create :country }
|
8
|
+
let!(:state) { create :state, country: country }
|
8
9
|
|
9
10
|
describe "GET #index" do
|
10
|
-
before { get :index, params: {
|
11
|
+
before { get :index, params: { country_id: country.id, format: :json } }
|
11
12
|
|
12
13
|
it { expect(response).to have_http_status(:success) }
|
13
14
|
it { expect(assigns(:states)).to eq([state]) }
|
data/spec/dummy/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../..
|
3
3
|
specs:
|
4
|
-
addresses (2.0)
|
4
|
+
addresses (2.0.1)
|
5
5
|
rails (~> 6.0.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -115,7 +115,7 @@ GEM
|
|
115
115
|
rake (>= 0.8.7)
|
116
116
|
thor (>= 0.20.3, < 2.0)
|
117
117
|
rake (13.0.0)
|
118
|
-
sprockets (
|
118
|
+
sprockets (4.0.0)
|
119
119
|
concurrent-ruby (~> 1.0)
|
120
120
|
rack (> 1, < 3)
|
121
121
|
sprockets-rails (3.2.1)
|
@@ -130,7 +130,7 @@ GEM
|
|
130
130
|
websocket-driver (0.7.1)
|
131
131
|
websocket-extensions (>= 0.1.0)
|
132
132
|
websocket-extensions (0.1.4)
|
133
|
-
zeitwerk (2.
|
133
|
+
zeitwerk (2.2.0)
|
134
134
|
|
135
135
|
PLATFORMS
|
136
136
|
ruby
|
Binary file
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# This migration comes from addresses (originally 20191010233002)
|
3
|
+
|
4
|
+
class CreateAddressesRegions < ActiveRecord::Migration[6.0]
|
5
|
+
def change
|
6
|
+
create_table :addresses_regions do |t|
|
7
|
+
t.string :name
|
8
|
+
t.string :acronym
|
9
|
+
t.float :latitude
|
10
|
+
t.float :longitude
|
11
|
+
t.references :country, index: true
|
12
|
+
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# This migration comes from addresses (originally 20191010233144)
|
3
|
+
|
4
|
+
class AddIndexesToRegions < ActiveRecord::Migration[6.0]
|
5
|
+
def change
|
6
|
+
add_index :addresses_regions, :name
|
7
|
+
add_index :addresses_regions, [:name, :contry_id]
|
8
|
+
end
|
9
|
+
end
|