-
Notifications
You must be signed in to change notification settings - Fork 213
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
134929249 two flash messages bug #418
134929249 two flash messages bug #418
Conversation
create_invitation_response_object(InviteUnregisteredUserFromProposedOrg.new(@email,org).run, org) | ||
begin | ||
accept_organization | ||
rescue Exception |
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.
Could we rescue a specific error here rather than Exception
?
Also, you can remove the begin ... rescue ... end
, and just have rescue
to spaces to the left. http://seejohncode.com/2012/04/17/short-tip-rescuing-a-method-in-ruby/
def accept_organization | ||
org = @proposed_org.accept_proposal | ||
@result = inform_user org | ||
raise Exception if [Response::NOTIFICATION_SENT, |
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.
To raise a domain-specific error, we could do the following:
class NotificationError < StandardError; end
def accept_organisation
# raise NotificationError if ...
end
Please replace all references to |
Ok, I'll do this! Thank you very much for the feedback :)
2016-12-21 23:47 GMT+02:00 Jon Mohrbacher <notifications@github.com>:
… Please replace all references to organization with organisation 🇬🇧 😉
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#418 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AS9L-Omxa7ak16-s-V9F2qDk7QRPUSiaks5rKZ5vgaJpZM4LTYbo>
.
|
I've changed code according to the recommendations and Code Climate requirements. Thank you! :) |
+1 nice tests |
Thank you! :)
2016-12-28 12:00 GMT+02:00 Jon Mohrbacher <notifications@github.com>:
… +1 nice tests
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#418 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AS9L-OCcc3gGEqv_57s5lRYJAo-R6z_Oks5rMjNPgaJpZM4LTYbo>
.
|
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.
@OlenaCh really good PR just a note about code style in Ruby, avoid adding multiple statement in same line with semicolon.
@@ -1 +0,0 @@ | |||
rvm use 2.3.1@localsupport --create |
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.
is there a reason to delete the .rvmrc file ?
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.
Oh, I'm sorry, I did not delete it on purpose. Perhaps, it was deleted accidentally and I did not notice, so did not create again. I'll fix it.
redirect_to organisation_path(result.accepted_organisation) and return false | ||
rslt = prepare_data_for_update | ||
redirect_to organisation_path(rslt.accepted_org) and return false if rslt.accepted_org | ||
redirect_to proposed_organisations_path |
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.
what about using if/else block like
if rslt.accepted_org
redirect_to organisation_path(rslt.accepted_org)
else
redirect_to proposed_organisations_path
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.
Actually, that was the first version of the code; but CodeClimate analysis marked it as an issue of ABC complexity (too much if/else statements for update method). Should I return back to the previous version?
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.
it's not a blocker for my side when I have two alternatives I pick the one that make my code easier to read.
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, of course, I understand. I am sorry, but may I ask about clarification, please? It will add two additional CC issues (6 instead of 5 allowed lines of code in one method & ABC complexity). It is not a problem to change these lines, but one of first comments on my PR was about necessity to address CodeClimate issues (when we discussed it on Slack with @tansaku).
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.
@OlenaCh that's strange because I saw only the redirection condition on update
method, you can keep the current implementation.
Generally when it comes to CodeClimate warnings, it's always better to address those warnings but sometimes you can ignore it but you need confirmation from reviewers :)
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, thank you very much :) !
|
||
def accept_organisation | ||
org = @proposed_org.accept_proposal; @result = inform_user org | ||
raise NotificationError if success?(@result.status) == false |
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.
when it comes to predicate method (ends with ? like success?
) you don't need to compare with boolean for example we can change the expression to:
raise NotificationError unless success?(@result.status)
Usually I avoid using exception for managing the flow, it's ok to use it but as alternative I would check the status of inform_user
before accepting the organisation.
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.
Thank you! I'll fix it! :)
app/models/proposed_organisation.rb
Outdated
org = becomes!(Organisation) | ||
|
||
def accept_proposal(rollback = false) | ||
org = rollback ? becomes!(ProposedOrganisation) : becomes!(Organisation) |
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 understand that there is change from Organisation
to ProposedOrganisation
it will be better if you add a method to Organisation
instead of adding a control flag (it's called control coupling )
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'll do this. Thank you!
@johnnymo87 @Maroo-b looks like the test coverage slightly dropped :(. It appears that there is one line in AcceptProposedOrganisation service (OTHER_ERROR) which currently I have no idea how to hit. Anyway I'll dig deeper into it during the following week. |
@OlenaCh usually when writing unit test for a service, we usually prefer not depending on the result of outside this service's (class) methods. InviteUnregisteredUserFromProposedOrg.new(@email, @org).run So I suggest to stub that method using the following syntax before the expectation: #create an object that responds to method status,
# other_response.status == Response::OTHER_FAILURE
other_response = double(status: Response::OTHER_FAILURE)
#Now we tell the InviteUnregisteredUserFromProposedOrg to return the other_response object
#InviteUnregisteredUserFromProposedOrg.new(arg1,arg2).run == other_response
#It's possible to use this alternative syntax also:
#allow_any_instance_of(InviteUnregisteredUserFromProposedOrg).to receive(:run).and_return(other_response)
allow(InviteUnregisteredUserFromProposedOrg.to receive_message_chain(:new, :run).and_return(other_response) You can read more about stub from RSpec docs: https://relishapp.com/rspec/rspec-mocks/v/3-5/docs/basics By the way @johnnymo87 do you think that we should inject the service: |
@Maroo-b thank you for a tip! :) |
@OlenaCh we've got a few merge conflicts here now - let me know if you have trouble resolving them |
@tansaku I've resolved the conflict and committed changes. I'll look for a bug and then commit a fix for it. Thank you! |
@OlenaCh there is a failing test, does it pass locally ? |
@Maroo-b, it also fails locally. It appeared after merging branches, but looks like I've fixed it today :). |
@OlenaCh great work getting this green! BTW, we leave the PT tickets in the started state till thinks are actually merged. With the right commit messages the merging of the PR will automatically mark the PT ticket as finished. See https://github.com/AgileVentures/LocalSupport/blob/develop/CONTRIBUTING.md for more details. Even if you don't have the git commits set up to hook into tracker, I can click "Finish" when I merge. I hope to review and merge soon - I've just got to give priority to premium PRs (over several projects including this one) in the first instance http://www.agileventures.org/pricing so sometimes I get a little backed up :-) |
@tansaku oh, sorry for inconvenience! In the future I'll keep about tickets in mind. Thank you! I'm awaiting for your review and feedback; simultaneously, I'm going to choose a new ticket to do. When this one will be merged, I'll be able to proceed to the next task :) |
@johnnymo87 @Maroo-b - if you're all happy with this one I can give it a final review |
@Maroo-b @johnnymo87 any outstanding issues on this one? I'd like to get it merged in, but am struggling to find time to do the detailed review I'd like to |
Nope, my original +1 still stands. |
+1 |
great work @OlenaCh - sorry for delay - I finally got to look through in detail and looks like a big improvement - really appreciate your hard work |
@tansaku thank you very much for the feedback - I am very glad that you liked the PR! Looks like I can proceed with new issues! :) |
* Fixing error flash bug * Without valid email organization is not accepted * Cucumber fix * Solving Code Climate issues - pull AgileVentures#418 * Refactoring flash messages into a service * Fixing Code Climate issues * Fixing Code Climate issues 2.0 * Adding new method to Organisation model * CodeClimate new issue fix * One more fix for CC issues * One more fix for CC issues 2.0 * One more fix for CC issues 3.0 * RSpec refactoring * More RSpec tests for AcceptProposedOrganisation service * Cucumber fix
Fixes: https://www.pivotaltracker.com/story/show/134929249