cancelable concern - #73
Conversation
StoneFrog
left a comment
There was a problem hiding this comment.
What do you think about adding restore and cancel callbacks? They might be useful especially since overriding controllers is so painful.
|
|
||
| config.include FactoryGirl::Syntax::Methods | ||
|
|
||
| # Timecop.safe_mode = true |
| s.add_development_dependency 'webmock' | ||
| s.add_development_dependency 'sqlite3' | ||
| s.add_development_dependency 'rubocop' | ||
| s.add_development_dependency 'timecop' |
There was a problem hiding this comment.
Do we need that? I can't see any place in specs where it is used.
| @connection = rental.create_connection(remote_rental: new_remote_rental) | ||
| else | ||
| @connection = rental.create_connection(remote_rental: remote_rental) | ||
| @connection = |
There was a problem hiding this comment.
how does it work here actually? I mean UI-wise. Is customer allowed to disconnect rental and connect another one, doesn't look like that? Do we want to protect customer from him? This might be better but I can see plenty of support tickets to destroy connection because of some reason.
Also how would you reconnect it/restore it? Is UI ready for that? I mean we have disconnect button which will cancel it, but connection is still present so probably rental will not appear to be draggable. If not draggable it's not possible to connect this rental with another remote rental which happens sometimes (or even quite often in case of airbnb)
There was a problem hiding this comment.
Here is how this will work, a new connection is created on a new remote rental connection, for existing remote rentals that have their connection already destroy, we also create a new connection, for remote rentals with canceled connections we simply restore.
If a customer would like to destroy a connection, we can handle that via console.
There was a problem hiding this comment.
Hmm all right so if I imagine it correctly it will act in UI as disconnected. What happens if someone drags and drops new rental on remote rental that was connected to other rental?
Handling destroy via console sounds really painful to me. I see that we want to protect customers from themselves, but this looks like unending pings from support to do that, which is not ideal as well.
| scope :connected, -> { joins(:rental).where(connections: { canceled_at: nil }) } | ||
| scope :not_connected, -> { | ||
| includes(:rental) | ||
| .where("connections.canceled_at IS NOT NULL OR rentals.id IS NULL") |
There was a problem hiding this comment.
scope with canceled connection is not tested, right?
| scope :ordered, -> { order(created_at: :desc) } | ||
| scope :connected, -> { joins(:rental) } | ||
| scope :not_connected, -> { includes(:rental).where(rentals: { id: nil }) } | ||
| scope :connected, -> { joins(:rental).where(connections: { canceled_at: nil }) } |
There was a problem hiding this comment.
same here, is it tested with visible/canceled connection?
| scope :connected, -> { joins(:remote_rental).where(connections: { canceled_at: nil }) } | ||
| scope :not_connected, -> { | ||
| includes(:connection) | ||
| .where("connections.canceled_at IS NOT NULL OR connections.remote_rental_id IS NULL") |
There was a problem hiding this comment.
same here., did you updates specs to test canceled connections?
|
|
||
| def connected? | ||
| rental.present? | ||
| rental.present? && connection.visible? |
There was a problem hiding this comment.
is this covered by specs?
| end | ||
|
|
||
| def connection_canceled? | ||
| rental.present? && connection.canceled? |
There was a problem hiding this comment.
is this covered by specs?
|
|
||
| def connected? | ||
| remote_rental.present? | ||
| remote_rental.present? && connection.visible? |
There was a problem hiding this comment.
is this covered by specs?
|
Also I think factorygirl is complaining in CI |
|
@StoneFrog we agreed that making the connection cancelable is a step in the right direction, not sure if we will need to override the controller methods. |
|
@barthc I'm not saying it's not useful, but airbnb use destroy callbacks on connection, so with this PR it will get broken. Adding cancel callback would help to make transition smooth |
| it { is_expected.to validate_presence_of(:remote_account) } | ||
|
|
||
| describe '.connected' do | ||
| subject { described_class.connected } |
There was a problem hiding this comment.
Why not just use class name?
| let(:remote_rental_2) { connection_2.remote_rental } | ||
| let(:remote_rental_3) { create(:remote_rental, rental: nil) } | ||
|
|
||
| it { is_expected.to eq [remote_rental_1] } |
There was a problem hiding this comment.
I think it would be better to add description here that it returns connected remote rentals, with not canceled connection or sth like that. Much easier to immediately see what's going on here. Also doesn't matter much in this case, but in general it's better to use match_array instead of eq since I think it doesn't care about order of returned results
Might be good idea to name objects more expressive as well - not_connected_remote_rental connected_remote_rental etc.
| let(:remote_rental_2) { connection_2.remote_rental } | ||
| let(:remote_rental_3) { create(:remote_rental, rental: nil) } | ||
|
|
||
| it { is_expected.to eq [remote_rental_2, remote_rental_3] } |
There was a problem hiding this comment.
Please add description to spec it returns either not connected remote rentals or with canceled connection or sth like that.
Also better to use match_array as eq may cause random fails here.
Might be good idea to name objects more expressive as well - not_connected_remote_rental connected_remote_rental etc.
| it { is_expected.to eq [remote_rental_2, remote_rental_3] } | ||
| end | ||
|
|
||
| describe '#connected?' do |
There was a problem hiding this comment.
missing case when connection is canceled
| let(:rental_2) { connection_2.rental } | ||
| let(:rental_3) { create(:rental, remote_rental: nil) } | ||
|
|
||
| it { is_expected.to eq [rental_1] } |
There was a problem hiding this comment.
Same as for remote rental specs
- Please use
match_arrayinstead ofeq - Describe what spec returns
- Optional - adding more expressive naming might be helpful to make it clearer
| let(:rental_2) { connection_2.rental } | ||
| let(:rental_3) { create(:rental, remote_rental: nil) } | ||
|
|
||
| it { is_expected.to eq [rental_2, rental_3] } |
There was a problem hiding this comment.
As above for remote rental specs
- Please use
match_arrayinstead ofeq - Describe what spec returns
- Optional - adding more expressive naming might be helpful to make it clearer
|
@barthc Did you try adding |
No description provided.