-
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
Merged
tansaku
merged 18 commits into
AgileVentures:develop
from
OlenaCh:134929249_two_flash_messages_bug
Feb 21, 2017
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
7251c6d
Fixing error flash bug
c2bb75a
Without valid email organization is not accepted
e717715
Merge branch 'master' into develop
19f1437
Cucumber fix
fb2ad2b
Solving Code Climate issues - pull #418
e8aa731
Refactoring flash messages into a service
e587ffc
Fixing Code Climate issues
c938f70
Fixing Code Climate issues 2.0
ed7850d
Adding new method to Organisation model
83f1258
CodeClimate new issue fix
06a7796
One more fix for CC issues
201bff8
One more fix for CC issues 2.0
7815f11
One more fix for CC issues 3.0
f182fab
RSpec refactoring
150e110
More RSpec tests for AcceptProposedOrganisation service
70697cb
Merge branch 'develop' into 134929249_two_flash_messages_bug
OlenaCh d29ca55
Cucumber fix
d94f37e
Merge branch 'develop' into 134929249_two_flash_messages_bug
tansaku File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
class CreateFlashForProposedOrganisation | ||
ACCEPTED = { | ||
invited: AcceptProposedOrganisation::Response::INVITATION_SENT, | ||
notified: AcceptProposedOrganisation::Response::NOTIFICATION_SENT | ||
}.freeze | ||
|
||
NOT_ACCEPTED = { | ||
invalid_email: AcceptProposedOrganisation::Response::INVALID_EMAIL, | ||
no_email: AcceptProposedOrganisation::Response::NO_EMAIL | ||
}.freeze | ||
|
||
def initialize obj | ||
@obj = obj | ||
@rsl = {} | ||
end | ||
|
||
def accepted? | ||
return true if [ ACCEPTED[:invited], | ||
ACCEPTED[:notified] ].include?(@obj.status) | ||
false | ||
end | ||
|
||
def flashes_for_accepted_org | ||
@rsl[:notice] = ['You have approved the following organisation'] | ||
if_invitation_or_notification_sent | ||
@rsl | ||
end | ||
|
||
def flash_for_not_accepted_org | ||
@rsl[:error] = "No mail was sent because: #{@obj.error_msg}" | ||
if_invalid_email | ||
if_no_email | ||
@rsl | ||
end | ||
|
||
def if_invalid_email | ||
@rsl[:error] = 'No invitation email was sent because the email ' \ | ||
"associated with #{@obj.not_accepted_org.name}," \ | ||
" #{@obj.not_accepted_org.email}, seems" \ | ||
' invalid' if @obj.status == NOT_ACCEPTED[:invalid_email] | ||
end | ||
|
||
def if_invitation_or_notification_sent | ||
email_type = sent_email_type | ||
@rsl[:notice] << "#{email_type} was sent to " \ | ||
"#{@obj.accepted_org.email}" unless email_type.empty? | ||
end | ||
|
||
def if_no_email | ||
@rsl[:error] = 'No invitation email was sent' \ | ||
' because no email is associated with the' \ | ||
' organisation' if @obj.status == NOT_ACCEPTED[:no_email] | ||
end | ||
|
||
def run | ||
accepted? ? flashes_for_accepted_org : flash_for_not_accepted_org | ||
end | ||
|
||
def sent_email_type | ||
return 'A notification of acceptance' if @obj.status == ACCEPTED[:notified] | ||
return 'An invitation email' if @obj.status == ACCEPTED[:invited] | ||
'' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<div class="row"> | ||
<div class="span8 offset2"> | ||
<div id="flash_<%= "#{name}" %>" class="alert <%= bootstrap_class_for(name)%>"> | ||
<a class="close" data-dismiss="alert">×</a> | ||
<%= content_tag :div, msg %> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
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 :) !