-
Notifications
You must be signed in to change notification settings - Fork 69
Move give time action to transfers controller #264
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
Move give time action to transfers controller #264
Conversation
This duplicates the UsersController#give_time to TransferController#new as it should be by Rails conventions. We aim to stick to REST conventions of the Transfer resource instead of having custom actions on users and organizations controllers.
This duplicates the OrganizationsController#give_time to TransferController#new as it should be by Rails conventions. We aim to stick to REST conventions of the Transfer resource instead of having custom actions on users and organizations controllers.
This is slowly turning "turning difference into sameness" following Sandi Metz style.
By specifying the account id we can abstract away from User or Organization objects and trust just the account. As a result, this removes ifs and therefore complexity.
Then each particular view knows what type the accountable has and uses the appropriate methods like user_path or organization_path.
This makes the controller specs integration-like enough to ensure things keep working when we later refactor the views and the controller ivars.
Now transfers/new.html.erb and transfers/new_organization.html.erb are identical. All their differences were moved to partials as if we extracted abstract methods in a class and moved the conditionals within them.
Now there's no point on using one for user/member and another one for organization.
@@ -0,0 +1,26 @@ | |||
class TransferSourcesOptions |
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.
Doc please 😬
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.
true
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.
done
dc30890
to
5f4d70e
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.
Doc++ but 👏
app/models/account_option_tag.rb
Outdated
accountable.display_id(destination_accountable) | ||
end | ||
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.
🔥
app/models/account_option_tag.rb
Outdated
@@ -0,0 +1,19 @@ | |||
class AccountOptionTag |
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.
Doc
I'll add any missing bits of doc but essentially this is what this first refactor is all about. As it stands out now, there are some odd pieces that need to be worked on in an upcoming PR. |
@@ -0,0 +1,79 @@ | |||
class TransferFactory |
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 is the first try at encapsulating all this transfer building logic. It's more of a patch to let us move code around until we figure out how the data model really works.
<% if admin? %> | ||
<div class="form-group"> | ||
<%= f.label :source %> | ||
<%# TODO: refactor. it's very complex for a view. %> |
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.
Most of this complexity it's been moved to TransferSourcesOptions
app/models/organization.rb
Outdated
@@ -53,4 +57,12 @@ def ensure_url | |||
errors.add(:web, :url_format_invalid) | |||
end | |||
end | |||
|
|||
def display_id(destination_accountable) | |||
if destination_accountable.is_a?(Organization) |
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.
There are quite a lot of this type checking on Organization. Very smelly 👃 so I guess this should be our next focus.
current_organization, | ||
current_user, | ||
params[:offer], | ||
params[:destination_account_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.
The term destination_account
would be better off as payee. Seems more appropriate to this domain.
@sseerrggii could you please test this? it affects both, transfers to a member and to an organization. |
accountable: accountable, | ||
transfer: transfer, | ||
offer: offer, | ||
sources: transfer_sources |
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 directly:
{
accountable: transfer_factory.accountable,
transfer: transfer_factory.build_transfer,
offer: transfer_factory.offer,
sources: transfer_factory.transfer_sources
}
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.
no problem
else | ||
user_path(accountable.user) | ||
end | ||
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.
Is there any reason why this can't be an AccountableMixin
extending Organization
and User
models? Could we share an interface to expose the 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.
I'm not sure. I'd just do whatever it takes to follow Rails convention so that we don't have to define any path helper. But because we made this standout, we can work on it in an upcoming iteration, not here.
If you agree @enricostano I'll prepare this branch for @sseerrggii to test it. My work here is done. |
@@ -0,0 +1,14 @@ | |||
require "spec_helper" |
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.
Single quote maybe
543c222
to
70efd91
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.
👏
Tested -> Fine :) |
This removes the duplicated action
#give_time
(along with its views) in users and organizations controllers and moves it to theTransfersController#new
.Missing
TransferFactory
:give_time
links for organization