Skip to content

Commit

Permalink
Keep HTML attachment slugs between versions
Browse files Browse the repository at this point in the history
  • Loading branch information
evilstreak authored and heathd committed Oct 25, 2013
1 parent 5e4b0d2 commit c45922d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/models/html_attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ def url(options = {})
def extracted_text
Govspeak::Document.new(body).to_text
end

def should_generate_new_friendly_id?
slug.nil? || attachable.nil? || !attachable.document.published?
end
end
29 changes: 28 additions & 1 deletion test/unit/html_attachment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,33 @@ class HtmlAttachmentTest < ActiveSupport::TestCase
end

test "slug is copied from previous edition's attachment" do
skip 'TODO'
attachment = create(:html_attachment, title: "an-html-attachment")
edition = create(:published_publication, attachments: [attachment])
draft = edition.create_draft(create(:policy_writer))

assert_equal "an-html-attachment", draft.attachments.first.slug
end

test "slug is updated when the title is changed if edition is unpublished" do
attachment = create(:html_attachment, title: "an-html-attachment")
edition = create(:draft_publication, attachments: [attachment])

attachment.title = "a-new-title"
attachment.save
attachment.reload

assert_equal "a-new-title", attachment.slug
end

test "slug is not updated when the title is changed if edition is published" do
edition = create(:published_publication, attachments: [create(:html_attachment, title: "an-html-attachment")])
draft = edition.create_draft(create(:policy_writer))
attachment = draft.attachments.first

attachment.title = "a-new-title"
attachment.save
attachment.reload

assert_equal "an-html-attachment", attachment.slug
end
end

0 comments on commit c45922d

Please sign in to comment.