addresses 2.0 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/addresses/cities_controller.rb +0 -2
  3. data/app/controllers/addresses/countries_controller.rb +17 -0
  4. data/app/controllers/addresses/neighborhoods_controller.rb +6 -4
  5. data/app/controllers/addresses/regions_controller.rb +17 -0
  6. data/app/controllers/addresses/states_controller.rb +6 -1
  7. data/app/models/addresses/city.rb +14 -12
  8. data/app/models/addresses/country.rb +8 -1
  9. data/app/models/addresses/neighborhood.rb +6 -2
  10. data/app/models/addresses/region.rb +16 -0
  11. data/app/models/addresses/state.rb +5 -2
  12. data/config/routes.rb +4 -2
  13. data/db/migrate/20191010233002_create_addresses_regions.rb +15 -0
  14. data/db/migrate/20191010233144_add_indexes_to_regions.rb +8 -0
  15. data/db/migrate/20191010233512_add_capital_to_addresses_state.rb +7 -0
  16. data/db/migrate/20191010233947_add_region_id_to_addresses_states.rb +7 -0
  17. data/db/migrate/20191010234112_add_latitude_and_longitude_to_addresses_address.rb +10 -0
  18. data/db/migrate/20191010235008_add_latitude_and_longitude_to_addresses_country.rb +10 -0
  19. data/db/migrate/20191010235050_add_latitude_and_longitude_to_addresses_states.rb +10 -0
  20. data/db/migrate/20191010235112_add_latitude_and_longitude_to_addresses_cities.rb +10 -0
  21. data/db/migrate/20191010235129_add_latitude_and_longitude_to_addresses_neighborhoods.rb +10 -0
  22. data/db/migrate/20191010235145_add_latitude_and_longitude_to_addresses_zipcodes.rb +10 -0
  23. data/spec/controllers/addresses/states_controller_spec.rb +3 -2
  24. data/spec/dummy/Gemfile.lock +3 -3
  25. data/spec/dummy/app/assets/config/manifest.js +2 -0
  26. data/spec/dummy/db/development.sqlite3 +0 -0
  27. data/spec/dummy/db/migrate/{20191008054118_create_addresses_countries.addresses.rb → 20191011003823_create_addresses_countries.addresses.rb} +0 -0
  28. data/spec/dummy/db/migrate/{20191008054119_create_addresses_states.addresses.rb → 20191011003824_create_addresses_states.addresses.rb} +0 -0
  29. data/spec/dummy/db/migrate/{20191008054120_create_addresses_cities.addresses.rb → 20191011003825_create_addresses_cities.addresses.rb} +0 -0
  30. data/spec/dummy/db/migrate/{20191008054121_create_addresses_neighborhoods.addresses.rb → 20191011003826_create_addresses_neighborhoods.addresses.rb} +0 -0
  31. data/spec/dummy/db/migrate/{20191008054122_create_addresses_addresses.addresses.rb → 20191011003827_create_addresses_addresses.addresses.rb} +0 -0
  32. data/spec/dummy/db/migrate/{20191008054123_create_addresses_zipcodes.addresses.rb → 20191011003828_create_addresses_zipcodes.addresses.rb} +0 -0
  33. data/spec/dummy/db/migrate/{20191008054124_remove_zipcode_attributes_from_addresses.addresses.rb → 20191011003829_remove_zipcode_attributes_from_addresses.addresses.rb} +0 -0
  34. data/spec/dummy/db/migrate/{20191008054125_add_indexes.addresses.rb → 20191011003830_add_indexes.addresses.rb} +0 -0
  35. data/spec/dummy/db/migrate/20191011003831_create_addresses_regions.addresses.rb +16 -0
  36. data/spec/dummy/db/migrate/20191011003832_add_indexes_to_regions.addresses.rb +9 -0
  37. data/spec/dummy/db/migrate/20191011003833_add_capital_to_addresses_state.addresses.rb +8 -0
  38. data/spec/dummy/db/migrate/20191011003834_add_region_id_to_addresses_states.addresses.rb +8 -0
  39. data/spec/dummy/db/migrate/20191011003835_add_latitude_and_longitude_to_addresses_address.addresses.rb +11 -0
  40. data/spec/dummy/db/migrate/20191011003836_add_latitude_and_longitude_to_addresses_country.addresses.rb +11 -0
  41. data/spec/dummy/db/migrate/20191011003837_add_latitude_and_longitude_to_addresses_states.addresses.rb +11 -0
  42. data/spec/dummy/db/migrate/20191011003838_add_latitude_and_longitude_to_addresses_cities.addresses.rb +11 -0
  43. data/spec/dummy/db/migrate/20191011003839_add_latitude_and_longitude_to_addresses_neighborhoods.addresses.rb +11 -0
  44. data/spec/dummy/db/migrate/20191011003840_add_latitude_and_longitude_to_addresses_zipcodes.addresses.rb +11 -0
  45. data/spec/dummy/db/schema.rb +41 -1
  46. data/spec/dummy/db/test.sqlite3 +0 -0
  47. data/spec/dummy/log/development.log +1137 -0
  48. data/spec/dummy/log/test.log +8159 -0
  49. data/spec/factories/regions.rb +9 -0
  50. data/spec/models/addresses/city_spec.rb +2 -2
  51. data/spec/models/addresses/region_spec.rb +10 -0
  52. data/spec/requests/countries_spec.rb +31 -0
  53. data/spec/requests/neighborhoods_spec.rb +12 -0
  54. data/spec/requests/regions_spec.rb +31 -0
  55. data/spec/requests/states_spec.rb +31 -0
  56. metadata +63 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b98ad9854e13c11cf4da821241934c2393316f39637c8ab08929d98e696d0b94
4
- data.tar.gz: 16af6871b87ddac66de2e0b38c9d122d2f790f2001f62b5d13acf62820adfae6
3
+ metadata.gz: 075ca513fc5ee9679a0b68dd5cfc5bf77bdd66df03c51007ea1ea8eeb16ec05c
4
+ data.tar.gz: 0f6a47c6941efdb2d4249fcd80af1fcd2e126b39363ba6fcf667ac004d6fa996
5
5
  SHA512:
6
- metadata.gz: 4e3fb674b4957d2daff508d348848fc56adcd521c795be94c2f976f804b836e89308f9833622d66f4db32edc3eebb592948f8c0e626b67b4fc6cbc4bc1e1a87c
7
- data.tar.gz: 828b6de238ac9c6728458cf04e4bd339cf1b64b4ee43ede0778c6c4001f7551ebf6b86bad605a7620e24020067bb9bbfc03fc9eb875c0216e51667b1275ad2df
6
+ metadata.gz: 695120a2a42383f2135985dd584f75038d75e2efc268434b988216d68eceaf80f7888c22ca64dfb8c610363ba1ca1ad7f5786432097947a02244e0a8309cb555
7
+ data.tar.gz: fae24ef00cdeb5679bc83f29b6df96e10973e5dcd2b0a1c94eb57c3751b5d2a2a7ea5fdd3868b544bfb389a5c32ffcda0c7f3635d83c338ca91b65b037f84cd2
@@ -6,13 +6,11 @@ module Addresses
6
6
  class CitiesController < ApplicationController
7
7
  def index
8
8
  @cities = City.filter(params)
9
-
10
9
  render json: @cities
11
10
  end
12
11
 
13
12
  def show
14
13
  @city = City.find(params[:id])
15
-
16
14
  render json: @city
17
15
  end
18
16
  end
@@ -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
- @city = City.find(params[:city_id])
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.order('name asc')
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
- def query_word
26
- adapter == 'postgresql' ? 'ilike' : 'like'
27
- end
28
-
29
- def adapter
30
- ActiveRecord::Base.connection.instance_values["config"][:adapter]
31
- rescue
32
- nil
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
- validates :name, presence: true
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
@@ -2,8 +2,12 @@
2
2
 
3
3
  module Addresses
4
4
  class Neighborhood < ActiveRecord::Base
5
- validates :name, :city_id, presence: true
6
-
7
5
  belongs_to :city
6
+
7
+ default_scope { order('name asc') }
8
+
9
+ has_many :zipcodes
10
+
11
+ validates :name, :city_id, presence: true
8
12
  end
9
13
  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
@@ -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,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddIndexesToRegions < ActiveRecord::Migration[6.0]
4
+ def change
5
+ add_index :addresses_regions, :name
6
+ add_index :addresses_regions, [:name, :country_id]
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddCapitalToAddressesState < ActiveRecord::Migration[6.0]
4
+ def change
5
+ add_column :addresses_states, :capital_id, :int, index: true
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddRegionIdToAddressesStates < ActiveRecord::Migration[6.0]
4
+ def change
5
+ add_reference :addresses_states, :region, index: true
6
+ end
7
+ 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!(:state) { create :state }
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: { state_id: state.id, format: :json } }
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]) }
@@ -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 (3.7.2)
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.1.10)
133
+ zeitwerk (2.2.0)
134
134
 
135
135
  PLATFORMS
136
136
  ruby
@@ -0,0 +1,2 @@
1
+ //= link_tree ../images
2
+ //= link_directory ../stylesheets .css
@@ -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
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+ # This migration comes from addresses (originally 20191010233512)
3
+
4
+ class AddCapitalToAddressesState < ActiveRecord::Migration[6.0]
5
+ def change
6
+ add_column :addresses_states, :capital_id, :int, index: true
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+ # This migration comes from addresses (originally 20191010233947)
3
+
4
+ class AddRegionIdToAddressesStates < ActiveRecord::Migration[6.0]
5
+ def change
6
+ add_reference :addresses_states, :region, index: true
7
+ end
8
+ end