-
-
Notifications
You must be signed in to change notification settings - Fork 508
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
Add missing kit rspecs, DRY up kit base items and report service #4665
Conversation
* Another typo in docs
* Clearer name * Add rspecs to test :housing_a_kit and :loose scopes
… deletion * Move seed_base_items code into one static function * Move kit base item creation code into one static function * Add code to prevent calling destroy on kit base item and corresponding rspec * Added comments - not sure about whether other base item request specs are useful or what the purpose of destroy is in the controller if it can't be called
* All SQL code is duplicated in AcquisitionReportService * RSpec is close enough to what is in AcquisitionReportService Spec that it can be removed without merging in (only difference is Diapers - Adult Briefs category is not created, but that shouldn't matter because the SQL looks for %diaper% so this category isn't testing anything different)
* Rename to snake case * Add docs noting base items will be changed
@@ -31,47 +31,8 @@ def average_children_monthly | |||
total_children_served / 12.0 | |||
end | |||
|
|||
def disposable_diapers_from_kits_total | |||
organization_id = @organization.id |
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.
(continuing conversation from #4585)
these lines were removed because they're unused in this service and duplicated in AcquisitionReportService (probably the author copied AcquisitionReportService as a template when creating this service and forgot to delete them)
@jimmyli97 FYI: We had an urgent fix that required all the senior contributors this week , so we didn't get to look at this again. Hopefully this week will go better. |
@@ -40,7 +42,9 @@ def show | |||
|
|||
def destroy | |||
@base_item = BaseItem.includes(:items).find(params[:id]) | |||
if @base_item.items.any? && @base_item.destroy | |||
if (@base_item.id = KitCreateService.find_or_create_kit_base_item!.id) |
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.
Assignment inside a condition is pretty prone to bugs. Can we separate them out into two lines?
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 think this was a typo, fixed to ==
in commit 94030f7
if @base_item.items.any? && @base_item.destroy | ||
if (@base_item.id = KitCreateService.find_or_create_kit_base_item!.id) | ||
redirect_to admin_base_items_path, alert: "You cannot delete the Kits base item. This is reserved for all Kits." | ||
elsif @base_item.items.any? && @base_item.destroy |
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.
Shouldn't this be @base_item.items.empty?
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.
yes, fixed in commit 94030f7
lib/seed_base_items.rb
Outdated
@@ -0,0 +1,19 @@ | |||
def seed_base_items |
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.
Top-level functions look kind of weird in a Rails app. Can this be wrapped in a module?
It worked in rails_helper
because those kind of helper methods are fine if used specifically for test setup.
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.
added to module seeds
in commit 94030f7
end | ||
end | ||
|
||
# TODO aren't organization_admins not allowed to view base items? | ||
# also, some of these tests are sending organization.id instead of BaseItem.id as args |
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.
Pretty sure they can't. @cielf ?
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.
Org admins can't see the base items pages.
They see a list of base items that they pick from when setting up items, and there are places they can filter by base item, but they can't view or edit the base item information.
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.
fixed specs to clarify that org admins can't access or edit base items in commit 44c42be
@@ -42,6 +42,7 @@ | |||
create_list(:line_item, 5, :distribution, quantity: 200, item: disposable_item, itemizable: dist) | |||
create_list(:line_item, 5, :distribution, quantity: 300, item: non_disposable_item, itemizable: dist) | |||
end | |||
# within_time total distributed i |
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.
accidental commit?
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.
fixed in commit 94030f7
9472525
to
94030f7
Compare
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! One last suggestion.
context "When logged in as an organization admin" do | ||
before do | ||
sign_in(organization_admin) | ||
end | ||
|
||
describe "GET #new" do | ||
it "returns http success" do | ||
it "denies access and redirects" do |
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 don't think you even need these specs - every route under admin
is blocked to every user besides admins. We don't need specs for every one of those routes. Maybe pick one representative one (index?) and leave it at that.
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.
addressed in commit a861839
@jimmyli97 are you able to finish this off? |
Hey @jimmyli97 -- Just checking if you are still working on this. If we don't hear from you in a couple weeks, we'll assume not. Thank you for all your work on this in either case! |
If someone wants to finish this that's fine, otherwise I can hopefully get to this next week |
All good on my side. @cielf did you want to kick the tires? |
Yes. Should be able to fit it in today or tomorrow. |
Looks good after a light kicking. |
@jimmyli97: Your PR |
Split off from PR #4585
Various refactors and documentation changes
Description
Type of change
How Has This Been Tested?
passes test suite