-
-
Notifications
You must be signed in to change notification settings - Fork 498
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
Superadmin Partners View (4682) & Category Dropdown Error (4674) #4703
base: main
Are you sure you want to change the base?
Conversation
Hey @bdeanhardt -- Thank you! -- we'll take a look. One thing for future -- we usually put a PR for each issue we work on -- it's easier for the testers. |
Also for future -- it's a better practice to make a branch, rather than making the changes in your main. |
@bdeanhardt Could you make the order "human alphabetical" -- i.e. case insensitive, aka lower case alphabetical?, rather than "computer alphabetical", which orders all the lowercase after all the upper case, please? (We're in the process of making the order of all the other alphabetical lists case-insensitive) Thanks, |
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.
Hi @bdeanhardt
Welcome aboard! Thanks for your work on this!
The item fix works very well!
For the partner page, I'm afraid we had a slight misunderstanding on what we mean by alphabetical -- we want alphabetical the way English-speaking humans do it -- i.e. both 'A' and 'a' are treated the same.
We'll also need automated tests for both of these. That's what we mean when we need tests.
Please see the other procedural comments I've made, above, for future pull requests.
@bdeanhardt Functionally, this looks great! -- just waiting for those automated tests, then I'll pass it over to our tech lead for a final technical review. |
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.
Can you add or modify an existing test to validate these fixes?
tests are in! Thank you for your patience on this. |
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.
One comment on the newly added test. Shouldn't there be one more added test since there are two issues being fixed here?
post :create, params: bad_params | ||
|
||
expect(response).to render_template(:new) | ||
expect(assigns(:item_categories)).to eq(organization.item_categories.order('name ASC')) |
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 statement is just restating the code itself. You need to create item categories with specific names and validate that the printed categories match those names in alphabetical order.
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.
Should I check for the alphabetical order of the categories in both tests? Or is this OK as is now that the first test is pushed?
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.
Actually, I got confused - this test doesn't actually test the bug, which is that the categories were empty after an error. You should do this in a request test which validates the output HTML.
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.
Ok! I uploaded a new test.
I forgot to push the other test! I'm so sorry totally my bad. |
|
||
it "assigns partners ordered by name (case-insensitive)" do | ||
get :index | ||
expect(assigns(:partners)).to eq([partner1, partner2, partner3].sort_by { |p| p.name.downcase }) |
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.
Suggestion:
expect(assigns(:partners).map(&:name)).to eq(%w(alpha Bravo Zeus))
But if you really want to test this, you should swap the names of partners 1 and 2. This way the default order would not be alphabetical and you'd actually be testing that the sort works. 😄
post :create, params: bad_params | ||
|
||
expect(response).to render_template(:new) | ||
expect(assigns(:item_categories)).to eq(organization.item_categories.order('name ASC')) |
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.
Actually, I got confused - this test doesn't actually test the bug, which is that the categories were empty after an error. You should do this in a request test which validates the output HTML.
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.
Almost there!
expect(response).to render_template(:new) | ||
|
||
# Ensure the item categories are assigned in the controller | ||
expect(assigns(:item_categories)).to eq(organization.item_categories.order('name ASC')) |
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.
I much prefer giving the categories explicit values and testing against those values rather than pulling them from the DB. You end up basically just copying the code you're testing into the test.
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.
Sorry, I'm having trouble understanding exactly what you mean here.
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.
I mean doing something like
let(:categories) do
[
FactoryBot.create(:item_category, name: 'Apples'), # include whatever other IDs need to be passed in
FactoryBot.create(:item_category, name: 'Bananas')
]
end
# ...
expect(assigns(:item_categories)).to eq(categories))
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.
Hey @bdeanhardt -- do you need further guidance on this?
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.
Hey @cielf! Past 2 weeks have been chaos, but I'm back! I'm taking a look today :)
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.
So sorry about the delay! How does it look now?
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.
You shouldn't need to specify an order
in the spec.
To be a bit more directive, here's what I had in mind:
let!(:category1) { FactoryBot.create(:item_category, name: 'Bananas', organization: organization) }
let!(:category2) { FactoryBot.create(:item_category, name: 'Apples' organization: organization) }
let!(:category3) { FactoryBot.create(:item_category, name: 'Umbrella', organization: organization) }
# ...
expect(assigns(:item_categories)).to eq([category2, category1, category3])
Lint also needs to be fixed. |
|
||
it "assigns partners ordered by name (case-insensitive)" do | ||
get :index | ||
expect(assigns(:partners)).to eq([partner1, partner2, partner3].sort_by { |p| p.name.downcase }) |
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.
You shouldn't need to sort since you know the partners' names. :) Just reorder the array to partner2, partner1, partner3
.
Actually... can you switch it so the partner1
line is moved above the partner2
line? That way they'd actually be created out of order. The order of the let!
statements is what matters.
|
||
before do | ||
categories # Ensure categories are created before the request | ||
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.
You can remove this before
block and replace the let
with let!
to ensure they are created.
expect(response).to render_template(:new) | ||
|
||
# Ensure the item categories are assigned in the controller | ||
expect(assigns(:item_categories)).to eq(organization.item_categories.order('name ASC')) |
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.
You shouldn't need to specify an order
in the spec.
To be a bit more directive, here's what I had in mind:
let!(:category1) { FactoryBot.create(:item_category, name: 'Bananas', organization: organization) }
let!(:category2) { FactoryBot.create(:item_category, name: 'Apples' organization: organization) }
let!(:category3) { FactoryBot.create(:item_category, name: 'Umbrella', organization: organization) }
# ...
expect(assigns(:item_categories)).to eq([category2, category1, category3])
Both tests and lint are still failing. :( |
Resolves #4682 and #4674
Description
The super admin partners view is now in alphabetical order.
If you have an error on new item, the category list for selection will not disappear anymore.
Type of change
How Has This Been Tested?
I reopened the super admin page after implementing my changes and the partners are now in alphabetical order.
I tried to reproduce the bug after implement my bug fix and I was unable to do so (categories will show up now despite an error).
Everything else still works as expected.
Screenshots