From 55b59c4d7b7f3f8d05619b9f76103c7e9b61c054 Mon Sep 17 00:00:00 2001 From: Matthew Thomas Date: Fri, 28 Aug 2026 15:39:42 -0400 Subject: [PATCH 1/8] added Addresses --- app/controllers/addresses_controller.rb | 70 +++++++++++++++++++ app/models/address.rb | 2 + app/views/addresses/_address.html.erb | 12 ++++ app/views/addresses/_address.json.jbuilder | 2 + app/views/addresses/_form.html.erb | 27 +++++++ app/views/addresses/edit.html.erb | 12 ++++ app/views/addresses/index.html.erb | 16 +++++ app/views/addresses/index.json.jbuilder | 1 + app/views/addresses/new.html.erb | 11 +++ app/views/addresses/show.html.erb | 10 +++ app/views/addresses/show.json.jbuilder | 1 + config/routes.rb | 1 + db/migrate/20260828192329_create_addresses.rb | 10 +++ db/schema.rb | 7 ++ test/controllers/addresses_controller_test.rb | 48 +++++++++++++ test/fixtures/addresses.yml | 9 +++ 16 files changed, 239 insertions(+) create mode 100644 app/controllers/addresses_controller.rb create mode 100644 app/models/address.rb create mode 100644 app/views/addresses/_address.html.erb create mode 100644 app/views/addresses/_address.json.jbuilder create mode 100644 app/views/addresses/_form.html.erb create mode 100644 app/views/addresses/edit.html.erb create mode 100644 app/views/addresses/index.html.erb create mode 100644 app/views/addresses/index.json.jbuilder create mode 100644 app/views/addresses/new.html.erb create mode 100644 app/views/addresses/show.html.erb create mode 100644 app/views/addresses/show.json.jbuilder create mode 100644 db/migrate/20260828192329_create_addresses.rb create mode 100644 test/controllers/addresses_controller_test.rb create mode 100644 test/fixtures/addresses.yml diff --git a/app/controllers/addresses_controller.rb b/app/controllers/addresses_controller.rb new file mode 100644 index 0000000..4bc245b --- /dev/null +++ b/app/controllers/addresses_controller.rb @@ -0,0 +1,70 @@ +class AddressesController < ApplicationController + before_action :set_address, only: %i[ show edit update destroy ] + + # GET /addresses or /addresses.json + def index + @addresses = Address.all + end + + # GET /addresses/1 or /addresses/1.json + def show + end + + # GET /addresses/new + def new + @address = Address.new + end + + # GET /addresses/1/edit + def edit + end + + # POST /addresses or /addresses.json + def create + @address = Address.new(address_params) + + respond_to do |format| + if @address.save + format.html { redirect_to @address, notice: "Address was successfully created." } + format.json { render :show, status: :created, location: @address } + else + format.html { render :new, status: :unprocessable_content } + format.json { render json: @address.errors, status: :unprocessable_content } + end + end + end + + # PATCH/PUT /addresses/1 or /addresses/1.json + def update + respond_to do |format| + if @address.update(address_params) + format.html { redirect_to @address, notice: "Address was successfully updated.", status: :see_other } + format.json { render :show, status: :ok, location: @address } + else + format.html { render :edit, status: :unprocessable_content } + format.json { render json: @address.errors, status: :unprocessable_content } + end + end + end + + # DELETE /addresses/1 or /addresses/1.json + def destroy + @address.destroy! + + respond_to do |format| + format.html { redirect_to addresses_path, notice: "Address was successfully destroyed.", status: :see_other } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_address + @address = Address.find(params.expect(:id)) + end + + # Only allow a list of trusted parameters through. + def address_params + params.expect(address: [ :city, :state ]) + end +end diff --git a/app/models/address.rb b/app/models/address.rb new file mode 100644 index 0000000..a19addc --- /dev/null +++ b/app/models/address.rb @@ -0,0 +1,2 @@ +class Address < ApplicationRecord +end diff --git a/app/views/addresses/_address.html.erb b/app/views/addresses/_address.html.erb new file mode 100644 index 0000000..1f0a08b --- /dev/null +++ b/app/views/addresses/_address.html.erb @@ -0,0 +1,12 @@ +
+
+ City: + <%= address.city %> +
+ +
+ State: + <%= address.state %> +
+ +
diff --git a/app/views/addresses/_address.json.jbuilder b/app/views/addresses/_address.json.jbuilder new file mode 100644 index 0000000..95169b4 --- /dev/null +++ b/app/views/addresses/_address.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! address, :id, :city, :state, :created_at, :updated_at +json.url address_url(address, format: :json) diff --git a/app/views/addresses/_form.html.erb b/app/views/addresses/_form.html.erb new file mode 100644 index 0000000..a43421a --- /dev/null +++ b/app/views/addresses/_form.html.erb @@ -0,0 +1,27 @@ +<%= form_with(model: address) do |form| %> + <% if address.errors.any? %> +
+

<%= pluralize(address.errors.count, "error") %> prohibited this address from being saved:

+ + +
+ <% end %> + +
+ <%= form.label :city, style: "display: block" %> + <%= form.text_field :city %> +
+ +
+ <%= form.label :state, style: "display: block" %> + <%= form.text_field :state %> +
+ +
+ <%= form.submit %> +
+<% end %> diff --git a/app/views/addresses/edit.html.erb b/app/views/addresses/edit.html.erb new file mode 100644 index 0000000..172a14d --- /dev/null +++ b/app/views/addresses/edit.html.erb @@ -0,0 +1,12 @@ +<% content_for :title, "Editing address" %> + +

Editing address

+ +<%= render "form", address: @address %> + +
+ +
+ <%= link_to "Show this address", @address %> | + <%= link_to "Back to addresses", addresses_path %> +
diff --git a/app/views/addresses/index.html.erb b/app/views/addresses/index.html.erb new file mode 100644 index 0000000..a7f798a --- /dev/null +++ b/app/views/addresses/index.html.erb @@ -0,0 +1,16 @@ +

<%= notice %>

+ +<% content_for :title, "Addresses" %> + +

Addresses

+ +
+ <% @addresses.each do |address| %> + <%= render address %> +

+ <%= link_to "Show this address", address %> +

+ <% end %> +
+ +<%= link_to "New address", new_address_path %> diff --git a/app/views/addresses/index.json.jbuilder b/app/views/addresses/index.json.jbuilder new file mode 100644 index 0000000..475be0e --- /dev/null +++ b/app/views/addresses/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @addresses, partial: "addresses/address", as: :address diff --git a/app/views/addresses/new.html.erb b/app/views/addresses/new.html.erb new file mode 100644 index 0000000..442443a --- /dev/null +++ b/app/views/addresses/new.html.erb @@ -0,0 +1,11 @@ +<% content_for :title, "New address" %> + +

New address

+ +<%= render "form", address: @address %> + +
+ +
+ <%= link_to "Back to addresses", addresses_path %> +
diff --git a/app/views/addresses/show.html.erb b/app/views/addresses/show.html.erb new file mode 100644 index 0000000..3b6ec63 --- /dev/null +++ b/app/views/addresses/show.html.erb @@ -0,0 +1,10 @@ +

<%= notice %>

+ +<%= render @address %> + +
+ <%= link_to "Edit this address", edit_address_path(@address) %> | + <%= link_to "Back to addresses", addresses_path %> + + <%= button_to "Destroy this address", @address, method: :delete %> +
diff --git a/app/views/addresses/show.json.jbuilder b/app/views/addresses/show.json.jbuilder new file mode 100644 index 0000000..8d0edad --- /dev/null +++ b/app/views/addresses/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "addresses/address", address: @address diff --git a/config/routes.rb b/config/routes.rb index 499ad5c..793dd7e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,6 +3,7 @@ resources :medications resources :medication_types resources :people + resources :addresses # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html # JSON API consumed by the Expo app in mobile/. diff --git a/db/migrate/20260828192329_create_addresses.rb b/db/migrate/20260828192329_create_addresses.rb new file mode 100644 index 0000000..0b35579 --- /dev/null +++ b/db/migrate/20260828192329_create_addresses.rb @@ -0,0 +1,10 @@ +class CreateAddresses < ActiveRecord::Migration[8.1] + def change + create_table :addresses do |t| + t.string :city + t.string :state + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index c2e519c..9a40b67 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,6 +11,13 @@ # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema[8.1].define(version: 2026_08_29_113836) do + create_table "addresses", force: :cascade do |t| + t.string "city" + t.datetime "created_at", null: false + t.string "state" + t.datetime "updated_at", null: false + end + create_table "medication_types", force: :cascade do |t| t.datetime "created_at", null: false t.string "name" diff --git a/test/controllers/addresses_controller_test.rb b/test/controllers/addresses_controller_test.rb new file mode 100644 index 0000000..402d6b9 --- /dev/null +++ b/test/controllers/addresses_controller_test.rb @@ -0,0 +1,48 @@ +require "test_helper" + +class AddressesControllerTest < ActionDispatch::IntegrationTest + setup do + @address = addresses(:one) + end + + test "should get index" do + get addresses_url + assert_response :success + end + + test "should get new" do + get new_address_url + assert_response :success + end + + test "should create address" do + assert_difference("Address.count") do + post addresses_url, params: { address: { city: @address.city, state: @address.state } } + end + + assert_redirected_to address_url(Address.last) + end + + test "should show address" do + get address_url(@address) + assert_response :success + end + + test "should get edit" do + get edit_address_url(@address) + assert_response :success + end + + test "should update address" do + patch address_url(@address), params: { address: { city: @address.city, state: @address.state } } + assert_redirected_to address_url(@address) + end + + test "should destroy address" do + assert_difference("Address.count", -1) do + delete address_url(@address) + end + + assert_redirected_to addresses_url + end +end diff --git a/test/fixtures/addresses.yml b/test/fixtures/addresses.yml new file mode 100644 index 0000000..9e29e86 --- /dev/null +++ b/test/fixtures/addresses.yml @@ -0,0 +1,9 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + city: MyString + state: MyString + +two: + city: MyString + state: MyString From 126a8466e761fb6c274224f8aebeb3c95f24c2c4 Mon Sep 17 00:00:00 2001 From: Matthew Thomas Date: Sat, 29 Aug 2026 10:05:56 -0400 Subject: [PATCH 2/8] added reference to parent class Person --- app/models/address.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/address.rb b/app/models/address.rb index a19addc..0848b5a 100644 --- a/app/models/address.rb +++ b/app/models/address.rb @@ -1,2 +1,3 @@ class Address < ApplicationRecord + belongs_to:person end From 3dd08364d87be840509124c10e396af59e4e889d Mon Sep 17 00:00:00 2001 From: Matthew Thomas Date: Sat, 29 Aug 2026 11:38:11 -0400 Subject: [PATCH 3/8] WIP --- Gemfile | 2 +- Gemfile.lock | 10 ++++++++++ app/models/address.rb | 2 +- app/models/person.rb | 2 ++ db/migrate/20260829145325_add_person_ref_to_address.rb | 5 +++++ db/schema.rb | 5 ++++- test/controllers/addresses_controller_test.rb | 5 ++++- test/fixtures/addresses.yml | 2 ++ 8 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20260829145325_add_person_ref_to_address.rb diff --git a/Gemfile b/Gemfile index 4ceebcc..a8bcce6 100644 --- a/Gemfile +++ b/Gemfile @@ -53,7 +53,7 @@ gem "ruby-vips", "~> 2.0", require: false group :development, :test do # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem gem "debug", platforms: %i[ mri windows ], require: "debug/prelude" - + gem "pry" # Audits gems for known security defects (use config/bundler-audit.yml to ignore issues) gem "bundler-audit", require: false diff --git a/Gemfile.lock b/Gemfile.lock index d923c23..a786622 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -100,6 +100,7 @@ GEM rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) + coderay (1.1.3) concurrent-ruby (1.3.8) connection_pool (3.0.2) crass (1.0.7) @@ -174,6 +175,7 @@ GEM net-smtp marcel (1.2.1) matrix (0.4.3) + method_source (1.1.0) mini_mime (1.1.5) minitest (6.0.6) drb (~> 2.0) @@ -222,6 +224,10 @@ GEM actionpack (>= 7.0.0) activesupport (>= 7.0.0) rack + pry (0.16.0) + coderay (~> 1.1) + method_source (~> 1.0) + reline (>= 0.6.0) public_suffix (7.0.5) puma (8.0.2) nio4r (~> 2.0) @@ -414,6 +420,7 @@ DEPENDENCIES jbuilder kamal propshaft + pry puma (>= 5.0) rack-cors rails (~> 8.1.3) @@ -455,6 +462,7 @@ CHECKSUMS builder (3.3.0) sha256=497918d2f9dca528fdca4b88d84e4ef4387256d984b8154e9d5d3fe5a9c8835f bundler-audit (0.9.3) sha256=81c8766c71e47d0d28a0f98c7eed028539f21a6ea3cd8f685eb6f42333c9b4e9 capybara (3.40.0) sha256=42dba720578ea1ca65fd7a41d163dd368502c191804558f6e0f71b391054aeef + coderay (1.1.3) sha256=dc530018a4684512f8f38143cd2a096c9f02a1fc2459edcfe534787a7fc77d4b concurrent-ruby (1.3.8) sha256=b2f1be836e968ccc78ccfce277ea79c72a88633f22306782c16ff23fb415d1e1 connection_pool (3.0.2) sha256=33fff5ba71a12d2aa26cb72b1db8bba2a1a01823559fb01d29eb74c286e62e0a crass (1.0.7) sha256=94868719948664c89ddcaf0a37c65048413dfcb1c869470a5f7a7ceb5390b295 @@ -491,6 +499,7 @@ CHECKSUMS mail (2.9.1) sha256=06574eca475253d6c18145dd70af80d0eb970182d55053497c5f4d797ea160e8 marcel (1.2.1) sha256=1678e9360e32f9eafa917c80029e2f6d10b2715c66a4b87b6d0da9b9cd1f859f matrix (0.4.3) sha256=a0d5ab7ddcc1973ff690ab361b67f359acbb16958d1dc072b8b956a286564c5b + method_source (1.1.0) sha256=181301c9c45b731b4769bc81e8860e72f9161ad7d66dd99103c9ab84f560f5c5 mini_mime (1.1.5) sha256=8681b7e2e4215f2a159f9400b5816d85e9d8c6c6b491e96a12797e798f8bccef minitest (6.0.6) sha256=153ea36d1d987a62942382b61075745042a2b3123b1cd48f4c3675af9cc7d6f1 msgpack (1.8.3) sha256=8bda4a6428d3244e50d6bd55854d354edbada88a4e1f4f5731a39a0f86bee6a1 @@ -517,6 +526,7 @@ CHECKSUMS prettyprint (0.2.0) sha256=2bc9e15581a94742064a3cc8b0fb9d45aae3d03a1baa6ef80922627a0766f193 prism (1.9.0) sha256=7b530c6a9f92c24300014919c9dcbc055bf4cdf51ec30aed099b06cd6674ef85 propshaft (1.3.2) sha256=1d56a3e56a92c21bfc29caf07406b5386b00d4c47ddf357cf989a5a234b1389e + pry (0.16.0) sha256=d76c69065698ed1f85e717bd33d7942c38a50868f6b0673c636192b3d1b6054e public_suffix (7.0.5) sha256=1a8bb08f1bbea19228d3bed6e5ed908d1cb4f7c2726d18bd9cadf60bc676f623 puma (8.0.2) sha256=c8ed871dfbbe66448ea9ffd46692342d9804d4071522b52b5331b7b6e7b686fb raabro (1.5.0) sha256=3f998a7bc84f9c84df3ab580634d2e0a5bda4f0841168d56035f529c9877440a diff --git a/app/models/address.rb b/app/models/address.rb index 0848b5a..d7153de 100644 --- a/app/models/address.rb +++ b/app/models/address.rb @@ -1,3 +1,3 @@ class Address < ApplicationRecord - belongs_to:person + belongs_to :person end diff --git a/app/models/person.rb b/app/models/person.rb index 9791ac6..e8c2489 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -1,3 +1,5 @@ class Person < ApplicationRecord belongs_to :relationship + + has_one :address, dependent: :destroy end diff --git a/db/migrate/20260829145325_add_person_ref_to_address.rb b/db/migrate/20260829145325_add_person_ref_to_address.rb new file mode 100644 index 0000000..2367ad6 --- /dev/null +++ b/db/migrate/20260829145325_add_person_ref_to_address.rb @@ -0,0 +1,5 @@ +class AddPersonRefToAddress < ActiveRecord::Migration[8.1] + def change + add_reference :addresses, :person, null: false, foreign_key: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 9a40b67..36dd645 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,12 +10,14 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.1].define(version: 2026_08_29_113836) do +ActiveRecord::Schema[8.1].define(version: 2026_08_29_145325) do create_table "addresses", force: :cascade do |t| t.string "city" t.datetime "created_at", null: false + t.integer "person_id", null: false t.string "state" t.datetime "updated_at", null: false + t.index ["person_id"], name: "index_addresses_on_person_id" end create_table "medication_types", force: :cascade do |t| @@ -93,6 +95,7 @@ t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true end + add_foreign_key "addresses", "people" add_foreign_key "medications", "medication_types" add_foreign_key "people", "relationships" end diff --git a/test/controllers/addresses_controller_test.rb b/test/controllers/addresses_controller_test.rb index 402d6b9..992c7c8 100644 --- a/test/controllers/addresses_controller_test.rb +++ b/test/controllers/addresses_controller_test.rb @@ -1,4 +1,5 @@ require "test_helper" +require "pry" class AddressesControllerTest < ActionDispatch::IntegrationTest setup do @@ -16,8 +17,9 @@ class AddressesControllerTest < ActionDispatch::IntegrationTest end test "should create address" do + binding.pry assert_difference("Address.count") do - post addresses_url, params: { address: { city: @address.city, state: @address.state } } + post addresses_url, params: { address: { city: @address.city, state: @address.state, person_id: @address.person_id } } end assert_redirected_to address_url(Address.last) @@ -30,6 +32,7 @@ class AddressesControllerTest < ActionDispatch::IntegrationTest test "should get edit" do get edit_address_url(@address) + assert_response :success end diff --git a/test/fixtures/addresses.yml b/test/fixtures/addresses.yml index 9e29e86..3a1770c 100644 --- a/test/fixtures/addresses.yml +++ b/test/fixtures/addresses.yml @@ -3,7 +3,9 @@ one: city: MyString state: MyString + person: one two: city: MyString state: MyString + person: two From 4a5f0b3dfe7cc4754a0f6b149ad0642f16f7404c Mon Sep 17 00:00:00 2001 From: Matthew Thomas Date: Sat, 29 Aug 2026 11:45:35 -0400 Subject: [PATCH 4/8] added person id to parameter allow list --- app/controllers/addresses_controller.rb | 2 +- test/controllers/addresses_controller_test.rb | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/controllers/addresses_controller.rb b/app/controllers/addresses_controller.rb index 4bc245b..56b8f4d 100644 --- a/app/controllers/addresses_controller.rb +++ b/app/controllers/addresses_controller.rb @@ -65,6 +65,6 @@ def set_address # Only allow a list of trusted parameters through. def address_params - params.expect(address: [ :city, :state ]) + params.expect(address: [ :city, :state, :person_id ]) end end diff --git a/test/controllers/addresses_controller_test.rb b/test/controllers/addresses_controller_test.rb index 992c7c8..d2a026b 100644 --- a/test/controllers/addresses_controller_test.rb +++ b/test/controllers/addresses_controller_test.rb @@ -17,7 +17,6 @@ class AddressesControllerTest < ActionDispatch::IntegrationTest end test "should create address" do - binding.pry assert_difference("Address.count") do post addresses_url, params: { address: { city: @address.city, state: @address.state, person_id: @address.person_id } } end @@ -32,7 +31,7 @@ class AddressesControllerTest < ActionDispatch::IntegrationTest test "should get edit" do get edit_address_url(@address) - + assert_response :success end From 536904cdc624d578de0d4df58abb7bffd7cc535e Mon Sep 17 00:00:00 2001 From: Matthew Thomas Date: Sat, 29 Aug 2026 14:03:16 -0400 Subject: [PATCH 5/8] removed redundant files, and added new revisions to routes --- app/views/addresses/_form.html.erb | 27 --------------------------- app/views/addresses/edit.html.erb | 12 ------------ app/views/addresses/new.html.erb | 11 ----------- config/routes.rb | 5 +++-- 4 files changed, 3 insertions(+), 52 deletions(-) delete mode 100644 app/views/addresses/_form.html.erb delete mode 100644 app/views/addresses/edit.html.erb delete mode 100644 app/views/addresses/new.html.erb diff --git a/app/views/addresses/_form.html.erb b/app/views/addresses/_form.html.erb deleted file mode 100644 index a43421a..0000000 --- a/app/views/addresses/_form.html.erb +++ /dev/null @@ -1,27 +0,0 @@ -<%= form_with(model: address) do |form| %> - <% if address.errors.any? %> -
-

<%= pluralize(address.errors.count, "error") %> prohibited this address from being saved:

- -
    - <% address.errors.each do |error| %> -
  • <%= error.full_message %>
  • - <% end %> -
-
- <% end %> - -
- <%= form.label :city, style: "display: block" %> - <%= form.text_field :city %> -
- -
- <%= form.label :state, style: "display: block" %> - <%= form.text_field :state %> -
- -
- <%= form.submit %> -
-<% end %> diff --git a/app/views/addresses/edit.html.erb b/app/views/addresses/edit.html.erb deleted file mode 100644 index 172a14d..0000000 --- a/app/views/addresses/edit.html.erb +++ /dev/null @@ -1,12 +0,0 @@ -<% content_for :title, "Editing address" %> - -

Editing address

- -<%= render "form", address: @address %> - -
- -
- <%= link_to "Show this address", @address %> | - <%= link_to "Back to addresses", addresses_path %> -
diff --git a/app/views/addresses/new.html.erb b/app/views/addresses/new.html.erb deleted file mode 100644 index 442443a..0000000 --- a/app/views/addresses/new.html.erb +++ /dev/null @@ -1,11 +0,0 @@ -<% content_for :title, "New address" %> - -

New address

- -<%= render "form", address: @address %> - -
- -
- <%= link_to "Back to addresses", addresses_path %> -
diff --git a/config/routes.rb b/config/routes.rb index 793dd7e..c173960 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,8 +2,9 @@ devise_for :users resources :medications resources :medication_types - resources :people - resources :addresses + resources :people do + resource :address, only: [:show, :create, :update, :destroy] + end # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html # JSON API consumed by the Expo app in mobile/. From 4266f5982ee56ae2b889125f5076d099e8eb24ac Mon Sep 17 00:00:00 2001 From: Matthew Thomas Date: Sat, 29 Aug 2026 14:06:47 -0400 Subject: [PATCH 6/8] Police are scary --- config/routes.rb | 2 +- test/controllers/addresses_controller_test.rb | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index c173960..bce874b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,7 +3,7 @@ resources :medications resources :medication_types resources :people do - resource :address, only: [:show, :create, :update, :destroy] + resource :address, only: [ :show, :create, :update, :destroy ] end # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html diff --git a/test/controllers/addresses_controller_test.rb b/test/controllers/addresses_controller_test.rb index d2a026b..cfe2015 100644 --- a/test/controllers/addresses_controller_test.rb +++ b/test/controllers/addresses_controller_test.rb @@ -35,11 +35,6 @@ class AddressesControllerTest < ActionDispatch::IntegrationTest assert_response :success end - test "should update address" do - patch address_url(@address), params: { address: { city: @address.city, state: @address.state } } - assert_redirected_to address_url(@address) - end - test "should destroy address" do assert_difference("Address.count", -1) do delete address_url(@address) From 5f5594b24cd630a57f44dbbfc9fdc411916187e7 Mon Sep 17 00:00:00 2001 From: Domenick Powers Date: Sat, 29 Aug 2026 14:14:22 -0400 Subject: [PATCH 7/8] Fix failing tests --- Gemfile.lock | 3 ++ app/controllers/addresses_controller.rb | 52 +++++++------------ app/views/addresses/show.html.erb | 5 +- test/controllers/addresses_controller_test.rb | 33 +++--------- 4 files changed, 32 insertions(+), 61 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index a786622..7009a24 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -81,6 +81,7 @@ GEM base64 (0.3.0) bcrypt (3.1.22) bcrypt_pbkdf (1.1.2) + bcrypt_pbkdf (1.1.2-arm64-darwin) bigdecimal (4.1.2) bindex (0.8.1) bootsnap (1.24.6) @@ -402,6 +403,7 @@ PLATFORMS aarch64-linux-musl arm-linux-gnu arm-linux-musl + arm64-darwin-22 arm64-darwin-23 arm64-darwin-25 x86_64-linux @@ -455,6 +457,7 @@ CHECKSUMS base64 (0.3.0) sha256=27337aeabad6ffae05c265c450490628ef3ebd4b67be58257393227588f5a97b bcrypt (3.1.22) sha256=1f0072e88c2d705d94aff7f2c5cb02eb3f1ec4b8368671e19112527489f29032 bcrypt_pbkdf (1.1.2) sha256=c2414c23ce66869b3eb9f643d6a3374d8322dfb5078125c82792304c10b94cf6 + bcrypt_pbkdf (1.1.2-arm64-darwin) bigdecimal (4.1.2) sha256=53d217666027eab4280346fba98e7d5b66baaae1b9c3c1c0ffe89d48188a3fbd bindex (0.8.1) sha256=7b1ecc9dc539ed8bccfc8cb4d2732046227b09d6f37582ff12e50a5047ceb17e bootsnap (1.24.6) sha256=c60bab88c70332290f0a2636a288f675299eb4f804a02a3c085b42eca9da164a diff --git a/app/controllers/addresses_controller.rb b/app/controllers/addresses_controller.rb index 56b8f4d..ddfba73 100644 --- a/app/controllers/addresses_controller.rb +++ b/app/controllers/addresses_controller.rb @@ -1,32 +1,17 @@ class AddressesController < ApplicationController - before_action :set_address, only: %i[ show edit update destroy ] + before_action :set_person + before_action :set_address, only: %i[ show update destroy ] - # GET /addresses or /addresses.json - def index - @addresses = Address.all - end - - # GET /addresses/1 or /addresses/1.json def show end - # GET /addresses/new - def new - @address = Address.new - end - - # GET /addresses/1/edit - def edit - end - - # POST /addresses or /addresses.json def create - @address = Address.new(address_params) + @address = @person.build_address(address_params) respond_to do |format| if @address.save - format.html { redirect_to @address, notice: "Address was successfully created." } - format.json { render :show, status: :created, location: @address } + format.html { redirect_to person_address_url(@person), notice: "Address was successfully created." } + format.json { render :show, status: :created, location: person_address_url(@person) } else format.html { render :new, status: :unprocessable_content } format.json { render json: @address.errors, status: :unprocessable_content } @@ -34,12 +19,11 @@ def create end end - # PATCH/PUT /addresses/1 or /addresses/1.json def update respond_to do |format| if @address.update(address_params) - format.html { redirect_to @address, notice: "Address was successfully updated.", status: :see_other } - format.json { render :show, status: :ok, location: @address } + format.html { redirect_to person_address_url(@person), notice: "Address was successfully updated.", status: :see_other } + format.json { render :show, status: :ok, location: person_address_url(@person) } else format.html { render :edit, status: :unprocessable_content } format.json { render json: @address.errors, status: :unprocessable_content } @@ -47,24 +31,26 @@ def update end end - # DELETE /addresses/1 or /addresses/1.json def destroy @address.destroy! respond_to do |format| - format.html { redirect_to addresses_path, notice: "Address was successfully destroyed.", status: :see_other } + format.html { redirect_to person_url(@person), notice: "Address was successfully destroyed.", status: :see_other } format.json { head :no_content } end end private - # Use callbacks to share common setup or constraints between actions. - def set_address - @address = Address.find(params.expect(:id)) - end - # Only allow a list of trusted parameters through. - def address_params - params.expect(address: [ :city, :state, :person_id ]) - end + def set_person + @person = Person.find(params[:person_id]) + end + + def set_address + @address = @person.address + end + + def address_params + params.expect(address: [ :city, :state ]) + end end diff --git a/app/views/addresses/show.html.erb b/app/views/addresses/show.html.erb index 3b6ec63..dd36790 100644 --- a/app/views/addresses/show.html.erb +++ b/app/views/addresses/show.html.erb @@ -3,8 +3,7 @@ <%= render @address %>
- <%= link_to "Edit this address", edit_address_path(@address) %> | - <%= link_to "Back to addresses", addresses_path %> + <%= link_to "Back to person", @person %> - <%= button_to "Destroy this address", @address, method: :delete %> + <%= button_to "Destroy this address", person_address_path(@person), method: :delete %>
diff --git a/test/controllers/addresses_controller_test.rb b/test/controllers/addresses_controller_test.rb index cfe2015..93dfabf 100644 --- a/test/controllers/addresses_controller_test.rb +++ b/test/controllers/addresses_controller_test.rb @@ -1,45 +1,28 @@ require "test_helper" -require "pry" class AddressesControllerTest < ActionDispatch::IntegrationTest setup do @address = addresses(:one) + @person = @address.person end - test "should get index" do - get addresses_url - assert_response :success - end - - test "should get new" do - get new_address_url + test "should show address" do + get person_address_url(@person) assert_response :success end test "should create address" do + @person.address.destroy assert_difference("Address.count") do - post addresses_url, params: { address: { city: @address.city, state: @address.state, person_id: @address.person_id } } + post person_address_url(@person), params: { address: { city: @address.city, state: @address.state } } end - - assert_redirected_to address_url(Address.last) - end - - test "should show address" do - get address_url(@address) - assert_response :success - end - - test "should get edit" do - get edit_address_url(@address) - - assert_response :success + assert_redirected_to person_address_url(@person) end test "should destroy address" do assert_difference("Address.count", -1) do - delete address_url(@address) + delete person_address_url(@person) end - - assert_redirected_to addresses_url + assert_redirected_to person_url(@person) end end From c03cec60112d2611d0a78bb742c6cfe6516903c0 Mon Sep 17 00:00:00 2001 From: Domenick Powers Date: Sat, 29 Aug 2026 14:15:39 -0400 Subject: [PATCH 8/8] lock --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 7009a24..402d23f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -457,7 +457,7 @@ CHECKSUMS base64 (0.3.0) sha256=27337aeabad6ffae05c265c450490628ef3ebd4b67be58257393227588f5a97b bcrypt (3.1.22) sha256=1f0072e88c2d705d94aff7f2c5cb02eb3f1ec4b8368671e19112527489f29032 bcrypt_pbkdf (1.1.2) sha256=c2414c23ce66869b3eb9f643d6a3374d8322dfb5078125c82792304c10b94cf6 - bcrypt_pbkdf (1.1.2-arm64-darwin) + bcrypt_pbkdf (1.1.2-arm64-darwin) sha256=afdd6feb6ed5a97b8e44caacb3f2d641b98af78e6a516d4a3520b69af5cf9fea bigdecimal (4.1.2) sha256=53d217666027eab4280346fba98e7d5b66baaae1b9c3c1c0ffe89d48188a3fbd bindex (0.8.1) sha256=7b1ecc9dc539ed8bccfc8cb4d2732046227b09d6f37582ff12e50a5047ceb17e bootsnap (1.24.6) sha256=c60bab88c70332290f0a2636a288f675299eb4f804a02a3c085b42eca9da164a