Skip to content

Instantly share code, notes, and snippets.

@plainprogrammer
Created August 29, 2017 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plainprogrammer/0cf56d3b3fe02e6c96d0e09b95fedb01 to your computer and use it in GitHub Desktop.
Save plainprogrammer/0cf56d3b3fe02e6c96d0e09b95fedb01 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.reset }.to change { subject.task_actions.count }.from(2).to(0)
end
it "resets completion state for all associated FeedItems" do
expect { subject.reset }.to change { FeedItems.for(subject).completed.count }.from(3).to(0)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment