-
-
Notifications
You must be signed in to change notification settings - Fork 572
3797 improving the child functionality #4126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ee27105
29a4187
791a882
781afa2
2284dcd
30ca7ac
f803c7d
2ccbb64
36b5fce
7b7a3a1
166eb5e
c18c5a4
399683d
3a43674
8cee0f6
a94971f
6227f72
0e957ef
912c6e9
2114d33
7e9749d
e5ef123
5958c6b
2ef7ffd
05c5142
9513c9b
a9f8bc2
8a823fe
cc81a69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| json.extract! child, :id, :first_name, :last_name, :date_of_birth, :gender, :child_lives_with, :race, :agency_child_id, :health_insurance, :item_needed_diaperid, :comments, :created_at, :updated_at | ||
| json.extract! child, :id, :first_name, :last_name, :date_of_birth, :gender, :child_lives_with, :race, :agency_child_id, :health_insurance, :needed_item_ids, :comments, :created_at, :updated_at | ||
| json.url child_url(child, format: :json) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,10 +17,10 @@ | |
| <%= form.text_field :last_name, class: "form-control" %> | ||
|
|
||
| <%= form.label :item_needed, "Diaper/Item Used" %> | ||
| <%= form.select :item_needed_diaperid, @formatted_requestable_items, | ||
| {include_blank: 'Select an item'}, | ||
| {class: 'form-control'} %> | ||
| <br> | ||
| <span>(select multiple by holding `ctrl`)</span> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cielf thoughts about this? Typically we have an interface similar to the line item where we give them an "add new" button. Is there going to be confusion / difficulty using the interface if it requires a select-click?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just saw this - will try to take a look tomorrow.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My take: I like the aesthetics of the select-many approach better, but I think having to use 'ctrl' does have the potential to be confusing . One issue is that the key that is acting as 'ctrl' is actually 'command' on Macs -- using 'control', which is what you'd think would work, doesn't. (I tried it out) The add new pattern is relatively clunky, aesthetically, but since having more than 2 items per child is relatively rare, I think it's workable. |
||
| <%= form.select :needed_item_ids, @formatted_requestable_items, | ||
| {include_blank: false, include_hidden: false, selected: child.needed_item_ids}, | ||
| {class: 'form-control', multiple: true} %> | ||
|
|
||
| <%= form.input :date_of_birth, as: :date, start_year: 20.years.ago.year, end_year: Time.current.year, label: "Date of Birth" %> | ||
| <%= form.input :gender, collection: ["Male", "Female"], class: "form-control" %> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| class CreateJoinTableChildItem < ActiveRecord::Migration[7.0] | ||
| def change | ||
| create_table :children_items do |t| | ||
| t.references :child, null: false, foreign_key: true | ||
| t.references :item, null: false, foreign_key: true | ||
|
|
||
| t.timestamps | ||
| end | ||
|
|
||
| add_index :children_items, [:child_id, :item_id], unique: true | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| class PopulateNeededItems < ActiveRecord::Migration[7.0] | ||
| def change | ||
| Partners::Child.find_each do |child| | ||
| child.needed_item_ids = [child.item_needed_diaperid] if child.item_needed_diaperid.present? | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,13 +10,13 @@ | |
| end | ||
|
|
||
| describe "for children with different items, from different families" do | ||
| let(:item_id) { Item.all.sample.id } | ||
| let(:item_ids) { Item.pluck(:id).sample(2).sort } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just create new items? I'm not a fan of using auto-generated data for testing. (In other words, auto-generated data is great when you *don't care* about the values - but if you're testing that the values are correct, it's much better to set them yourself.)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right. Also spec file should be self sufficient and describe all dependencies at least with
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i like the "boy scout rule". But here its relatively complex change because of current
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry if I was unclear - I don't think we have to stop creating the other data when it's created automatically. But here at least we can create 2 new items that we can test against.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understood you perfectly. I don't want to do it to be honest.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK... can you explain why? |
||
| let!(:children) do | ||
| [ | ||
| create(:partners_child, family: family), | ||
| create(:partners_child, family: family, item_needed_diaperid: item_id), | ||
| create(:partners_child, family: family, item_needed_diaperid: item_id), | ||
| create(:partners_child, family: other_family, item_needed_diaperid: item_id), | ||
| create(:partners_child, family: family, needed_item_ids: item_ids), | ||
| create(:partners_child, family: family, needed_item_ids: item_ids), | ||
| create(:partners_child, family: other_family, needed_item_ids: item_ids), | ||
| create(:partners_child, family: other_family) | ||
| ] | ||
| end | ||
|
|
@@ -28,8 +28,16 @@ | |
| expect(page).to have_text("Request Details") | ||
| click_link "Your Previous Requests" | ||
| expect(page).to have_text("Request History") | ||
| expect(Partners::ChildItemRequest.pluck(:child_id)).to match_array(children.pluck(:id)) | ||
| expect(Partners::ItemRequest.pluck(:item_id)).to match_array(children.pluck(:item_needed_diaperid).uniq) | ||
|
|
||
| expect(children[0].child_item_requests.size).to eq(1) | ||
| expect(children[1].child_item_requests.size).to eq(2) | ||
| expect(children[2].child_item_requests.size).to eq(2) | ||
| expect(children[3].child_item_requests.size).to eq(2) | ||
| expect(children[4].child_item_requests.size).to eq(1) | ||
| expect(children[1].child_item_requests.map(&:item_request).map(&:item_id).sort).to eq(item_ids) | ||
| expect(children[2].child_item_requests.map(&:item_request).map(&:item_id).sort).to eq(item_ids) | ||
| expect(children[3].child_item_requests.map(&:item_request).map(&:item_id).sort).to eq(item_ids) | ||
| expect(Partners::ItemRequest.pluck(:item_id)).to match_array(children.map(&:needed_item_ids).flatten.uniq) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. None of the specs actually show that we now support multiple items... let's make sure we have some examples of that in all the specs that are relevant.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. addressed 2114d33 |
||
| end | ||
| end | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should still just be
has_many, no?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in that case
itemsmust havechild_id. Orhas_many .... throughThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, can we change to
has_many :through? That's more accurate for the actual relationship here.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it does not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, took another look and you're right - this is a HABTM. I'm not used to using this relationship because it's rare that it's legitimately cross-join.
Still have a question though - the table is now called
children_itemsbut the relationship is calledneeded_items... I don't actually see the table being referenced. Is there some Rails magic I'm missing?