Skip to content

Instantly share code, notes, and snippets.

@plainprogrammer
Created August 29, 2017 17:21
Show Gist options
  • Save plainprogrammer/7fce0abdf4f0027155a314c964900868 to your computer and use it in GitHub Desktop.
Save plainprogrammer/7fce0abdf4f0027155a314c964900868 to your computer and use it in GitHub Desktop.
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