Skip to content
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

Add configurable methods for Rentals#index #81

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

adrian-fernandez
Copy link

Closes #80

@adrian-fernandez adrian-fernandez self-assigned this May 7, 2018
@adrian-fernandez adrian-fernandez requested a review from StoneFrog May 7, 2018 09:46
Copy link
Contributor

@StoneFrog StoneFrog left a comment

Choose a reason for hiding this comment

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

CI is still failing

@@ -18,6 +17,26 @@ def show

private

def not_connected_rentals
BookingsyncPortal.not_connected_rentals || Proc.new {
Copy link
Contributor

Choose a reason for hiding this comment

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

why proc? I think lambda accepting current_account as argument will be cleaner

context "methods from default config" do
render_views

it 'synchronizes rentals' do
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

end
end

it "should call custom 'not_connected_rentals' method" do
Copy link
Contributor

Choose a reason for hiding this comment

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

show some confidence 😉 it "calls ..."

context "using custom methods" do
before do
BookingsyncPortal.setup do |config|
config.not_connected_rentals = Proc.new { "not_connected_rentals" }
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather do some real setup with custom action, and render views

@remote_accounts = current_account.remote_accounts
@remote_rentals_by_account = current_account.remote_rentals.ordered
.includes(:remote_account, :rental).group_by(&:remote_account)
@not_connected_rentals = not_connected_rentals.call
Copy link
Member

Choose a reason for hiding this comment

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

Why not making this entire action an operation itself? This is hardly extendable, what if you want to modify the views and have some extra ivar? you would need to override the method which really defeats the purpose of these changes.

Not sure about the API though, maybe it should be something like:

# use registry so that the operation is overridable easily
BookingsyncPortal::OperationsRegistry.fetch("Admin::RentalsController#index").call(controller)

and that method would probably need to handle the rendering, like:

controller.render :index, locals: {  visible_rentals: visible_rentals, **other_depedencies }

So that might require removing usage of ivars at all and just "normal" injected variables.

This is just an idea, but if we already make some changes here, it should be robust.

private

def not_connected_rentals
BookingsyncPortal.not_connected_rentals || lambda {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm we decided to override full action, therefore customizations for each ivar are not needed. We want to overridde whole action

end

def show
rental
end

def index_arguments
BookingsyncPortal.custom_arguments.dig("Admin", "RentalsController", "index") || {
Copy link
Contributor

Choose a reason for hiding this comment

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

this looks quite static, whole operation should be customizable

Copy link
Author

Choose a reason for hiding this comment

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

if you want to customize all operation, wouldn't be better to override the action?

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be but it's not easy to override just one action from controller, and even more painful to test it, so the point of this operation is to give a mean to do that without all the overhead

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