-
Notifications
You must be signed in to change notification settings - Fork 1
Add configurable methods for Rentals#index #81
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,11 +5,10 @@ class RentalsController < Admin::BaseController | |
| before_action :fetch_remote_rentals, only: :index | ||
|
|
||
| def index | ||
| @not_connected_rentals = current_account.rentals.visible.ordered.not_connected | ||
| @visible_rentals = current_account.rentals.visible | ||
| @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 | ||
| @visible_rentals = visible_rentals.call | ||
| @remote_accounts = remote_account.call | ||
| @remote_rentals_by_account = remote_rentals_by_account.call | ||
| end | ||
|
|
||
| def show | ||
|
|
@@ -18,6 +17,26 @@ def show | |
|
|
||
| private | ||
|
|
||
| def not_connected_rentals | ||
| BookingsyncPortal.not_connected_rentals || Proc.new { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why proc? I think lambda accepting |
||
| current_account.rentals.visible.ordered.not_connected | ||
| } | ||
| end | ||
|
|
||
| def visible_rentals | ||
| BookingsyncPortal.visible_rentals || Proc.new { current_account.rentals.visible } | ||
| end | ||
|
|
||
| def remote_account | ||
| BookingsyncPortal.remote_accounts || Proc.new { current_account.remote_accounts } | ||
| end | ||
|
|
||
| def remote_rentals_by_account | ||
| BookingsyncPortal.remote_rentals_by_account || Proc.new { | ||
| current_account.remote_rentals.ordered.includes(:remote_account, :rental).group_by(&:remote_account) | ||
| } | ||
| end | ||
|
|
||
| def synchronize_rentals | ||
| BookingsyncPortal.rental_model.constantize.synchronize(scope: current_account) | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,6 @@ | ||
| require 'rails_helper' | ||
|
|
||
| describe BookingsyncPortal::Admin::RentalsController do | ||
| render_views | ||
| routes { BookingsyncPortal::Engine.routes } | ||
|
|
||
| let!(:account) { create(:account) } | ||
|
|
@@ -23,8 +22,47 @@ | |
| end | ||
| end | ||
|
|
||
| it 'synchronizes rentals' do | ||
| expect { get :index }.to change { Rental.count } | ||
| context "methods from default config" do | ||
| render_views | ||
|
|
||
| it 'synchronizes rentals' do | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. single quote |
||
| expect { get :index }.to change { Rental.count } | ||
| end | ||
| end | ||
|
|
||
| context "using custom methods" do | ||
| before do | ||
| BookingsyncPortal.setup do |config| | ||
| config.not_connected_rentals = Proc.new { "not_connected_rentals" } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| config.visible_rentals = Proc.new { "visible_rentals" } | ||
| config.remote_accounts = Proc.new { "remote_accounts" } | ||
| config.remote_rentals_by_account = Proc.new { "remote_rentals_by_account" } | ||
| end | ||
| end | ||
|
|
||
| it "should call custom 'not_connected_rentals' method" do | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. show some confidence 😉 |
||
| get :index | ||
| expect(BookingsyncPortal.not_connected_rentals.call).to eq("not_connected_rentals") | ||
| expect(assigns(:not_connected_rentals)).to eq("not_connected_rentals") | ||
| end | ||
|
|
||
| it "should call custom 'visible_rentals' method" do | ||
| get :index | ||
| expect(BookingsyncPortal.visible_rentals.call).to eq("visible_rentals") | ||
| expect(assigns(:visible_rentals)).to eq("visible_rentals") | ||
| end | ||
|
|
||
| it "should call custom 'remote_accounts' method" do | ||
| get :index | ||
| expect(BookingsyncPortal.remote_accounts.call).to eq("remote_accounts") | ||
| expect(assigns(:remote_accounts)).to eq("remote_accounts") | ||
| end | ||
|
|
||
| it "should call custom 'remote_rentals_by_account' method" do | ||
| get :index | ||
| expect(BookingsyncPortal.remote_rentals_by_account.call).to eq("remote_rentals_by_account") | ||
| expect(assigns(:remote_rentals_by_account)).to eq("remote_rentals_by_account") | ||
| end | ||
| end | ||
| 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.
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:
and that method would probably need to handle the rendering, like:
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.