-
Notifications
You must be signed in to change notification settings - Fork 1
cancelable concern #73
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 all 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 |
|---|---|---|
|
|
@@ -14,15 +14,23 @@ class BookingsyncPortal::RemoteRental < ActiveRecord::Base | |
| validates :remote_account, presence: true | ||
|
|
||
| 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 }) } | ||
|
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. same here, is it tested with visible/canceled connection? |
||
| scope :not_connected, -> { | ||
| includes(:rental) | ||
| .where("connections.canceled_at IS NOT NULL OR rentals.id IS NULL") | ||
|
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. scope with canceled connection is not tested, right? |
||
| .references(:rental) | ||
| } | ||
|
|
||
| def display_name | ||
| uid | ||
| end | ||
|
|
||
| def connected? | ||
| rental.present? | ||
| rental.present? && connection.visible? | ||
|
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. is this covered by specs? |
||
| end | ||
|
|
||
| def connection_canceled? | ||
| rental.present? && connection.canceled? | ||
|
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. is this covered by specs? |
||
| end | ||
|
|
||
| def synchronized? | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,12 +12,16 @@ class BookingsyncPortal::Rental < ActiveRecord::Base | |
| validates :synced_id, uniqueness: true, presence: true | ||
|
|
||
| scope :ordered, -> { order(position: :asc) } | ||
| scope :connected, -> { joins(:remote_rental) } | ||
| scope :not_connected, -> { includes(:connection).where(connections: { remote_rental_id: nil }) } | ||
| 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") | ||
|
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. same here., did you updates specs to test canceled connections? |
||
| .references(:connection) | ||
| } | ||
| scope :visible, -> { all } | ||
|
|
||
| def connected? | ||
| remote_rental.present? | ||
| remote_rental.present? && connection.visible? | ||
|
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. is this covered by specs? |
||
| end | ||
|
|
||
| def ordered_photos | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| module BookingsyncPortal | ||
| module Cancelable | ||
| extend ActiveSupport::Concern | ||
|
|
||
| included do | ||
| scope :visible, -> { where(canceled_at: nil) } | ||
| scope :not_canceled, -> { where(canceled_at: nil) } | ||
| scope :canceled, -> { where.not(canceled_at: nil) } | ||
| end | ||
|
|
||
| def canceled? | ||
| canceled_at.present? | ||
| end | ||
|
|
||
| def visible? | ||
| !canceled? | ||
| end | ||
|
|
||
| def cancel(time = Time.current) | ||
| update_attribute(:canceled_at, time) | ||
| end | ||
|
|
||
| def restore | ||
| cancel(nil) | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,7 @@ Gem::Specification.new do |s| | |
| s.add_development_dependency 'webmock' | ||
| s.add_development_dependency 'sqlite3' | ||
| s.add_development_dependency 'rubocop' | ||
| s.add_development_dependency 'timecop' | ||
|
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. Do we need that? I can't see any place in specs where it is used. |
||
| s.add_development_dependency 'pry-rails' | ||
| s.add_development_dependency 'rails-controller-testing' | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| class AddCanceledAtToConnections < ActiveRecord::Migration[5.0] | ||
| def change | ||
| add_column :connections, :canceled_at, :datetime | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,28 @@ | |
| it { is_expected.to validate_uniqueness_of(:uid).allow_nil } | ||
| it { is_expected.to validate_presence_of(:remote_account) } | ||
|
|
||
| describe '.connected' do | ||
| subject { described_class.connected } | ||
|
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 not just use class name? |
||
| let(:connection_1) { create(:connection) } | ||
| let(:remote_rental_1) { connection_1.remote_rental } | ||
| let(:connection_2) { create(:canceled_connection) } | ||
| 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] } | ||
|
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 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 Might be good idea to name objects more expressive as well - |
||
| end | ||
|
|
||
| describe '.not_connected' do | ||
| subject { described_class.not_connected } | ||
| let(:connection_1) { create(:connection) } | ||
| let(:remote_rental_1) { connection_1.remote_rental } | ||
| let(:connection_2) { create(:canceled_connection) } | ||
| 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] } | ||
|
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. Please add description to spec Might be good idea to name objects more expressive as well - |
||
| end | ||
|
|
||
| describe '#connected?' 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. missing case when connection is canceled |
||
| subject { remote_rental.connected? } | ||
| context 'when rental present' do | ||
|
|
@@ -24,6 +46,26 @@ | |
| end | ||
| end | ||
|
|
||
| describe '#connection_canceled?' do | ||
| subject { remote_rental.connection_canceled? } | ||
| context 'when rental present and connection is visible' do | ||
| let(:connection) { create(:connection) } | ||
| let(:remote_rental) { connection.remote_rental } | ||
| it { is_expected.to eq(false) } | ||
| end | ||
|
|
||
| context 'when rental present and connection is canceled' do | ||
| let(:connection) { create(:canceled_connection) } | ||
| let(:remote_rental) { connection.remote_rental } | ||
| it { is_expected.to eq(true) } | ||
| end | ||
|
|
||
| context 'when rental is nil' do | ||
| let(:remote_rental) { build(:remote_rental, rental: nil) } | ||
| it { is_expected.to eq(false) } | ||
| end | ||
| end | ||
|
|
||
| describe '#synchronized?' do | ||
| subject { remote_rental.synchronized? } | ||
| context 'when synchronized_at is present' do | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,28 @@ | |
| it { is_expected.to validate_presence_of(:synced_id) } | ||
| it { is_expected.to validate_uniqueness_of(:synced_id) } | ||
|
|
||
| describe '.connected' do | ||
| subject { described_class.connected } | ||
| let(:connection_1) { create(:connection) } | ||
| let(:rental_1) { connection_1.rental } | ||
| let(:connection_2) { create(:canceled_connection) } | ||
| let(:rental_2) { connection_2.rental } | ||
| let(:rental_3) { create(:rental, remote_rental: nil) } | ||
|
|
||
| it { is_expected.to eq [rental_1] } | ||
|
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. Same as for remote rental specs
|
||
| end | ||
|
|
||
| describe '.not_connected' do | ||
| subject { described_class.not_connected } | ||
| let(:connection_1) { create(:connection) } | ||
| let(:rental_1) { connection_1.rental } | ||
| let(:connection_2) { create(:canceled_connection) } | ||
| let(:rental_2) { connection_2.rental } | ||
| let(:rental_3) { create(:rental, remote_rental: nil) } | ||
|
|
||
| it { is_expected.to eq [rental_2, rental_3] } | ||
|
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. As above for remote rental specs
|
||
| end | ||
|
|
||
| describe '#connected?' do | ||
| subject { rental.connected? } | ||
| context 'when rental present' do | ||
|
|
||
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.
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.
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.
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.
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.