Skip to content
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

AO3-3866 update revised_at when a work is revealed #4664

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Switch to time instead of date
  • Loading branch information
eliahhecht committed Nov 18, 2023
commit 220d9d392d62854847507302db4764f80beb6e06
2 changes: 1 addition & 1 deletion app/models/work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def new_recipients_allow_gifts

# If the work is becoming revealed, bump the revised-at date (AO3-3866)
before_save do
set_revised_at(Time.zone.today) if will_save_change_to_in_unrevealed_collection?
set_revised_at(Time.current) if will_save_change_to_in_unrevealed_collection?
end

after_save :post_first_chapter
Expand Down
22 changes: 11 additions & 11 deletions spec/models/work_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -640,13 +640,13 @@
end

describe "#save" do
publication_date = Date.new(2000, 1, 1)
reveal_date = Date.new(2000, 1, 2)
publication_time = Time.zone.local(2000, 1, 1)
reveal_time = Time.zone.local(2000, 1, 2)

let(:collection) { create(:collection) }
let(:work) do
create(:work, collection_names: collection.name, chapters: [
create(:chapter, published_at: publication_date)
create(:chapter, published_at: publication_time)
])
end

Expand All @@ -657,15 +657,15 @@
end

it "updates the revised date" do
travel_to publication_date
travel_to publication_time
work.save!
expect(work.reload.revised_at).to eq publication_date
expect(work.reload.revised_at).to eq publication_time

travel_to reveal_date
travel_to reveal_time
collection.collection_preference.unrevealed = false
collection.collection_preference.save!

expect(work.reload.revised_at).to eq reveal_date
expect(work.reload.revised_at).to eq reveal_time
end
end

Expand All @@ -676,15 +676,15 @@
end

it "does not update the revised date" do
travel_to publication_date
travel_to publication_time
work.save!
expect(work.reload.revised_at).to eq publication_date
expect(work.reload.revised_at).to eq publication_time

travel_to reveal_date
travel_to reveal_time
collection.collection_preference.unrevealed = false
collection.collection_preference.save!

expect(work.reload.revised_at).to eq publication_date
expect(work.reload.revised_at).to eq publication_time
end
end
end
Expand Down