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 all commits
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
5 changes: 5 additions & 0 deletions app/models/work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ def new_recipients_allow_gifts

before_save :clean_and_validate_title, :validate_published_at, :ensure_revised_at

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

after_save :post_first_chapter
before_save :set_word_count

Expand Down
50 changes: 50 additions & 0 deletions spec/models/work_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -638,4 +638,54 @@
end
end
end

describe "#save" do
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_time)
])
end

context "when visibility is changed" do
before do
collection.collection_preference.unrevealed = true
collection.collection_preference.save!
end

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

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

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

context "when visibility is not changed" do
before do
collection.collection_preference.unrevealed = false
collection.collection_preference.save!
end

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

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

expect(work.reload.revised_at).to eq publication_time
end
end
end
end