Skip to content

Instantly share code, notes, and snippets.

@plainprogrammer plainprogrammer/task_spec.rb Secret
Created Aug 29, 2017

Embed
What would you like to do?
describe Task do
describe "#reset" do
subject { build :task, started_at: past_timestamp, completed_at: past_timestamp, failed_at: past_timestamp }
let(:past_timestamp) { 3.weeks.ago }
it "resets the started_at timestamp to now" do
expect { subject.reset }.to change { subject.started_at }.from(past_timestamp).to(DateTime.now)
end
it "clears the completed_at timestamp" do
expect { subject.reset }.to change { subject.completed_at }.from(past_timestamp).to(nil)
end
it "clears the failed_at timestamp" do
expect { subject.reset }.to change { subject.failed_at }.from(past_timestamp).to(nil)
end
it "destroys all associated TaskActions" do
expect(subject).to receive_message_chain(:task_actions, :destroy_all)
subject.reset
end
it "calls #reset_completed on all associated FeedItems" do
double = Object.new
expect(subject).to receive(:feed_items).and_return([double])
expect(double).to receive(:reset_completed)
subject.reset
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.