Skip to content

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

Merged
merged 26 commits into from
Jan 26, 2018

Conversation

sauloperez
Copy link
Collaborator

@sauloperez sauloperez commented Sep 19, 2017

This removes the duplicated action #give_time (along with its views) in users and organizations controllers and moves it to the TransfersController#new.

user_transfer
organization_transfer

Missing

  • Couple screenshots
  • Test and docs for TransferFactory
  • Update current :give_time links for organization

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc please 😬

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@sauloperez sauloperez force-pushed the move-give-time-action-to-transfers-controller branch from dc30890 to 5f4d70e Compare January 4, 2018 14:49
Copy link
Contributor

@enricostano enricostano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc++ but 👏

accountable.display_id(destination_accountable)
end
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

@@ -0,0 +1,19 @@
class AccountOptionTag
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc

@sauloperez
Copy link
Collaborator Author

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
Copy link
Collaborator Author

@sauloperez sauloperez Jan 4, 2018

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. %>
Copy link
Collaborator Author

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

@@ -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)
Copy link
Collaborator Author

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]
Copy link
Collaborator Author

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.

@sauloperez
Copy link
Collaborator Author

sauloperez commented Jan 5, 2018

@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
Copy link
Contributor

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
}

Copy link
Collaborator Author

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
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

@sauloperez
Copy link
Collaborator Author

sauloperez commented Jan 22, 2018

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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Single quote maybe :trollface:

@sauloperez sauloperez force-pushed the move-give-time-action-to-transfers-controller branch from 543c222 to 70efd91 Compare January 22, 2018 17:21
Copy link
Contributor

@enricostano enricostano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

@sseerrggii
Copy link
Contributor

Tested -> Fine :)

@sauloperez sauloperez merged commit ca5e813 into develop Jan 26, 2018
@sauloperez sauloperez deleted the move-give-time-action-to-transfers-controller branch January 26, 2018 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants