-
Notifications
You must be signed in to change notification settings - Fork 7
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
Bugs/aperta 12001 cancel passive events on rr submit #3820
Changes from 6 commits
fc90dd2
97ec21b
be7c1fc
7bea1d5
dd03fbd
4d47299
923ea66
5e96f3f
0b33211
e771820
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,6 +14,7 @@ class ScheduledEvent < ActiveRecord::Base | |
scope :passive, -> { where(state: 'passive') } | ||
scope :due_to_trigger, -> { active.where('dispatch_at < ?', DateTime.now.in_time_zone) } | ||
scope :serviceable, -> { where(state: ['passive', 'active', 'completed', 'inactive']) } | ||
scope :cancelable, -> { where(state: ['passive', 'active']) } | ||
|
||
before_save :deactivate, if: :should_deactivate? | ||
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 grepped pretty hard, I think this event is only used internally. 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 believe you |
||
before_save :reactivate, if: :should_reactivate? | ||
|
@@ -68,7 +69,7 @@ def finished? | |
end | ||
|
||
event(:cancel) do | ||
transitions from: :active, to: :canceled | ||
transitions from: [:active, :passive], to: :canceled | ||
end | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,15 +12,5 @@ export default DS.Model.extend({ | |
errored: Ember.computed.equal('state', 'errored'), | ||
inactive: Ember.computed.equal('state', 'inactive'), | ||
active: Ember.computed.equal('state', 'active'), | ||
canceled: Ember.computed.equal('state', 'canceled'), | ||
|
||
restless: Ember.inject.service(), | ||
|
||
updateState: function(newState) { | ||
const url = `/api/scheduled_events/${this.get('id')}/update_state`; | ||
return this.get('restless').put(url, {state: newState}).then(() => { | ||
this.set('state', newState); | ||
}); | ||
} | ||
|
||
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. 💯 |
||
canceled: Ember.computed.equal('state', 'canceled') | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,8 @@ export default Ember.Component.extend({ | |
actions: { | ||
changeEventState(newVal) { | ||
const state = newVal ? 'active' : 'passive'; | ||
this.get('event').updateState(state); | ||
this.set('event.state', state); | ||
this.get('event').save(); | ||
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. yay, we're using ember now :) |
||
} | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,4 +161,25 @@ def add_invitation(state) | |
expect { subject.set_due_datetime }.to change { subject.scheduled_events.count }.by(3) | ||
end | ||
end | ||
|
||
describe '#cancel_reminders' do | ||
before do | ||
FactoryGirl.create(:feature_flag, name: 'REVIEW_DUE_AT') | ||
FactoryGirl.create(:feature_flag, name: 'REVIEW_DUE_DATE') | ||
FactoryGirl.create :review_duration_period_setting_template | ||
end | ||
|
||
it 'cancels all events with passive or active state' do | ||
subject.set_due_datetime # makes 3 scheduled events with active state | ||
subject.scheduled_events.first.switch_off! # passive state | ||
subject.scheduled_events.last.cancel! # cancel state | ||
cancelable = subject.scheduled_events.select(&:may_cancel?) # omg it compares object ids and not row id. | ||
allow(subject.scheduled_events).to receive(:cancelable).and_return(cancelable) | ||
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. What's the motivation behind stubbing this instead of using the real scope? If it's so you can test the scope in a non-tautological way it's probably worth breaking out a separate test for the scope. 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. @egh watched me struggle with this, basically when 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. ah yeah, I just talked to @egh. I understand now that this was necessary for the subsequent message expectations to be set up properly (otherwise they're set up on different objects than those used inside of However, if you ditch those expectations (my comment below), you can also ditch this stubbing and make the test a lot more clear. |
||
subject.scheduled_events.each do |event| | ||
count = event.canceled? ? 0 : 1 | ||
expect(event).to receive(:cancel!).exactly(count).times | ||
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. WDYTA setting up expectations about the ending data state rather than setting up message expectations? I think a test that essentially said "all three scheduled events should be cancelled" rather than "some number of models should have the 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. In my old age, I've started to shy away from test mocks and stubs unless there's a really good reason to use them (test speed, or an external service). I find that it's nice to get the extra coverage of integrations where you're able. I'm going to paste this article without reading it: https://blog.kentcdodds.com/write-tests-not-too-many-mostly-integration-5e8c7fff591c hopefully it supports my point. 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. diff --git a/spec/models/reviewer_report_spec.rb b/spec/models/reviewer_report_spec.rb
index ff46118346..79079bd9d0 100644
--- a/spec/models/reviewer_report_spec.rb
+++ b/spec/models/reviewer_report_spec.rb
@@ -173,13 +173,8 @@ describe ReviewerReport do
subject.set_due_datetime # makes 3 scheduled events with active state
subject.scheduled_events.first.switch_off! # passive state
subject.scheduled_events.last.cancel! # cancel state
- cancelable = subject.scheduled_events.select(&:may_cancel?) # omg it compares object ids and not row id.
- allow(subject.scheduled_events).to receive(:cancelable).and_return(cancelable)
- subject.scheduled_events.each do |event|
- count = event.canceled? ? 0 : 1
- expect(event).to receive(:cancel!).exactly(count).times
- end
subject.send(:cancel_reminders)
+ expect(subject.scheduled_events.all?(&:canceled?)).to be(true)
end
end
end does that look good? 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. love it. Thanks ben! |
||
end | ||
subject.send(:cancel_reminders) | ||
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.
props on spelling cancelable correctly. I definitely did not.
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.
machty/ember-concurrency#41 my fav