Skip to content

cancelable concern - #73

Open
barthc wants to merge 3 commits into
masterfrom
cancelable-concern
Open

cancelable concern#73
barthc wants to merge 3 commits into
masterfrom
cancelable-concern

Conversation

@barthc

@barthc barthc commented Aug 25, 2017

Copy link
Copy Markdown

No description provided.

@barthc
barthc requested a review from Azdaroth August 25, 2017 12:23

@StoneFrog StoneFrog left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What do you think about adding restore and cancel callbacks? They might be useful especially since overriding controllers is so painful.

Comment thread spec/rails_helper.rb Outdated

config.include FactoryGirl::Syntax::Methods

# Timecop.safe_mode = true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Better to switch it on

s.add_development_dependency 'webmock'
s.add_development_dependency 'sqlite3'
s.add_development_dependency 'rubocop'
s.add_development_dependency 'timecop'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 }) }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same here., did you updates specs to test canceled connections?


def connected?
rental.present?
rental.present? && connection.visible?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this covered by specs?

end

def connection_canceled?
rental.present? && connection.canceled?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this covered by specs?


def connected?
remote_rental.present?
remote_rental.present? && connection.visible?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this covered by specs?

@StoneFrog

Copy link
Copy Markdown
Contributor

Also I think factorygirl is complaining in CI Looking up factories by class is deprecated and will be removed in 5.0 Good to fix it now

@barthc

barthc commented Aug 28, 2017

Copy link
Copy Markdown
Author

@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.

@StoneFrog

Copy link
Copy Markdown
Contributor

@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 }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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] }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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] }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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] }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same as for remote rental specs

  1. Please use match_array instead of eq
  2. Describe what spec returns
  3. 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] }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As above for remote rental specs

  1. Please use match_array instead of eq
  2. Describe what spec returns
  3. Optional - adding more expressive naming might be helpful to make it clearer

@StoneFrog

StoneFrog commented Aug 29, 2017

Copy link
Copy Markdown
Contributor

@barthc Did you try adding
require "timecop" on top of spec/rails_helper.rb?

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.

2 participants