-
Notifications
You must be signed in to change notification settings - Fork 6
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
Pass district id as parameter for update
and trigger
#667
Conversation
d70e332
to
bc5f8fe
Compare
@davidsiaw please review 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.
Can we use the same update method and just use district if its provided for now?
def update_with_district | ||
@heritage = BuildHeritage.new(permitted_params, district: @district).execute | ||
@heritage.save_and_deploy!(without_before_deploy: false, | ||
description: "Update to #{@heritage.image_path}") | ||
render json: @heritage |
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't this just be in update
but with district
as an optional?
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.
@davidsiaw ok I updated the logic to pass the value in body as optional.
Let me know what you think 🙏
73a4865
to
bcba35c
Compare
update_with_district
endpointupdate
and trigger
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.
Looks great! We just need more testing to cover some cases
@@ -22,7 +23,7 @@ def create | |||
end | |||
|
|||
def update | |||
@heritage = BuildHeritage.new(permitted_params).execute | |||
@heritage = BuildHeritage.new(permitted_params, district: @district).execute |
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.
Thanks this looks like a very clean way to handle it. Its also a very implicit if
statement, so I think we should have a test to get the heritage for the following cases:
- endpoint has no district, name passed in
- endpoint has no district, name and district passed in
- endpoint has district, name passed in
- endpoint has district, name and district passed in
- endpoint has district, with another endpoint in different district with the same name, name passed in
- endpoint has district, with another endpoint in different district with the same name, name and district passed in
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.
@davidsiaw just to confirm, what do you mean by endpoint
here?
like endpoint has no district, name passed in
this is the case when pass heritage name but there is no district?
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.
Not pass, but the database has an endpoint but district is set to nil
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.
district has endpionts right?
barcelona/app/models/district.rb
Line 12 in 07009e6
has_many :endpoints, inverse_of: :district, dependent: :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.
also district name should be unique
also I could not understand what you mean by 🙏
endpoint has district, with another endpoint in different district with the same name, name passed in
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.
@davidsiaw updated the logic
05f4bae
also existing tests cover for when no district name is given
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.
@Yuuki77 I think it is hard to write this test from what I see, because you are testing the API. You should test BuildHeritage instead, and it will be clearer. What we need to test essentially is all the permutations of
- The various states of the database
- The inputs passed to update
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.
@davidsiaw added the test.
I think the other scenario is that the wrong district is passed (which has always been possible).
So I added the checks.
other that existing tests should cover.
The change I made here was to pass district
in update, which was nil.
dd9fef7
@@ -22,7 +23,7 @@ def create | |||
end | |||
|
|||
def update | |||
@heritage = BuildHeritage.new(permitted_params).execute | |||
@heritage = BuildHeritage.new(permitted_params, district: @district).execute |
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.
@Yuuki77 I think it is hard to write this test from what I see, because you are testing the API. You should test BuildHeritage instead, and it will be clearer. What we need to test essentially is all the permutations of
- The various states of the database
- The inputs passed to update
5c38f2f
to
42a9a9e
Compare
e12dc5e
to
dd9fef7
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.
Just a few more things
Co-authored-by: David Siaw <[email protected]>
Co-authored-by: David Siaw <[email protected]>
Co-authored-by: David Siaw <[email protected]>
3cac758
to
506cbc5
Compare
Thank you for the reviews 🙇 |
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.
LGTM
Part of #617
pass district id as parameter for update and trigger endpoints.
in following pr, I will add the logic to create heritage with district name.
By adding this endpoint, we can make the heritage unique for each district in the future.