Skip to content

Commit

Permalink
Add Address model, Factory, Addresses::Country and Addresses::Region (#…
Browse files Browse the repository at this point in the history
…635)

* add Addresses::Country and Addresses::Region

* add Address model, factory

* add snail gem

* tangible_thing_test: check address fields refresh on country change

* remove snail gem

* add Addresses::Continent and Addresses::Subcontinent

* tests: fix find_stimulus_controller_for_label to permit multiple controllers

* fix a merge conflict that snuck through

* make the linter happy

---------

Co-authored-by: Jeremy Green <jeremy@octolabs.com>
  • Loading branch information
pascallaliberte and jagthedrummer authored Sep 1, 2023
1 parent 500c1db commit 29768d5
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 3 deletions.
24 changes: 24 additions & 0 deletions app/models/address.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Address < ApplicationRecord
extend ActiveHash::Associations::ActiveRecordExtensions

include Addresses::Base
# 🚅 add concerns above.

# 🚅 add belongs_to associations above.

# 🚅 add has_many associations above.

# 🚅 add oauth providers above.

# 🚅 add has_one associations above.

# 🚅 add scopes above.

# 🚅 add validations above.

# 🚅 add callbacks above.

# 🚅 add delegations above.

# 🚅 add methods above.
end
22 changes: 22 additions & 0 deletions app/models/addresses/continent.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Addresses::Continent < ApplicationHash
include Addresses::Continents::Base
# 🚅 add concerns above.

# 🚅 add belongs_to associations above.

# 🚅 add has_many associations above.

# 🚅 add oauth providers above.

# 🚅 add has_one associations above.

# 🚅 add scopes above.

# 🚅 add validations above.

# 🚅 add callbacks above.

# 🚅 add delegations above.

# 🚅 add methods above.
end
22 changes: 22 additions & 0 deletions app/models/addresses/country.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Addresses::Country < ApplicationHash
include Addresses::Countries::Base
# 🚅 add concerns above.

# 🚅 add belongs_to associations above.

# 🚅 add has_many associations above.

# 🚅 add oauth providers above.

# 🚅 add has_one associations above.

# 🚅 add scopes above.

# 🚅 add validations above.

# 🚅 add callbacks above.

# 🚅 add delegations above.

# 🚅 add methods above.
end
22 changes: 22 additions & 0 deletions app/models/addresses/region.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Addresses::Region < ApplicationHash
include Addresses::Regions::Base
# 🚅 add concerns above.

# 🚅 add belongs_to associations above.

# 🚅 add has_many associations above.

# 🚅 add oauth providers above.

# 🚅 add has_one associations above.

# 🚅 add scopes above.

# 🚅 add validations above.

# 🚅 add callbacks above.

# 🚅 add delegations above.

# 🚅 add methods above.
end
22 changes: 22 additions & 0 deletions app/models/addresses/subcontinent.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Addresses::Subcontinent < ApplicationHash
include Addresses::Subcontinents::Base
# 🚅 add concerns above.

# 🚅 add belongs_to associations above.

# 🚅 add has_many associations above.

# 🚅 add oauth providers above.

# 🚅 add has_one associations above.

# 🚅 add scopes above.

# 🚅 add validations above.

# 🚅 add callbacks above.

# 🚅 add delegations above.

# 🚅 add methods above.
end
16 changes: 16 additions & 0 deletions db/migrate/20230123162616_create_addresses.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class CreateAddresses < ActiveRecord::Migration[7.0]
def change
create_table :addresses do |t|
t.references :addressable, polymorphic: true, null: false
t.string :address_one
t.string :address_two
t.string :city
t.integer :region_id
t.string :region_name
t.integer :country_id
t.string :postal_code

t.timestamps
end
end
end
17 changes: 16 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test/application_system_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,9 @@ def assert_no_js_errors &block
def find_stimulus_controller_for_label(label, stimulus_controller, wrapper = false)
if wrapper
wrapper_el = find("label", text: /\A#{label}\z/).first(:xpath, ".//..//..")
wrapper_el if wrapper_el["data-controller"] == stimulus_controller
wrapper_el if wrapper_el["data-controller"].split(" ").include?(stimulus_controller)
else
find("label", text: /\A#{label}\z/).first(:xpath, ".//..").first('[data-controller="' + stimulus_controller + '"]')
find("label", text: /\A#{label}\z/).first(:xpath, ".//..").first('[data-controller~="' + stimulus_controller + '"]')
end
end

Expand Down
12 changes: 12 additions & 0 deletions test/factories/addresses.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FactoryBot.define do
factory :address do
addressable { nil }
address_one { "1000 Vin Scully Avenue" }
address_two { nil }
city { "Los Angeles" }
region_id { 1416 }
region_name { "California" }
country_id { 233 }
postal_code { "90090" }
end
end
5 changes: 5 additions & 0 deletions test/system/tangible_thing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ class TangibleThingTest < ApplicationSystemTestCase
fill_in "Email Field Value", with: "me@acme.com"
fill_in "Password Field Value", with: "secure-password"
fill_in "Phone Field Value", with: "(201) 551-8321"

assert page.has_content? "State / Province"
select "Japan", from: "Country"
assert page.has_content? "Prefecture"

select "One", from: "Super Select Value"
select2_select "Multiple Super Select Values", ["Five", "Six"]
fill_in "Text Area Value", with: "Long text for this text area field"
Expand Down

0 comments on commit 29768d5

Please sign in to comment.