Skip to content

Commit

Permalink
Merge pull request #9746 from alphagov/remove_sti_name
Browse files Browse the repository at this point in the history
Refactoring: Reduce usages of sti_name to minimum
  • Loading branch information
minhngocd authored Dec 17, 2024
2 parents a416b7c + deaa70c commit a9e0be4
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 18 deletions.
4 changes: 0 additions & 4 deletions app/models/announcement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ class Announcement < Edition
include Edition::WorldLocations
include Edition::TopicalEvents

def self.sti_names
([self] + descendants).map(&:sti_name)
end

def self.published_with_eager_loading(ids)
published.with_translations.includes([:document, { organisations: :translations }]).where(id: ids)
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/edition/publishing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def by_major_change_published_at

def unpublished_as(slug)
document = Document.at_slug(document_type, slug)
document && document.latest_edition && document.latest_edition.unpublishing
document&.latest_edition&.unpublishing
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/edition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def self.concrete_descendant_search_format_types

def self.scheduled_for_publication_as(slug)
document = Document.at_slug(document_type, slug)
document && document.scheduled_edition
document&.scheduled_edition
end

def skip_main_validation?
Expand Down
4 changes: 0 additions & 4 deletions app/models/publicationesque.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ class Publicationesque < Edition

include ::Attachable

def self.sti_names
([self] + descendants).map(&:sti_name)
end

def self.published_with_eager_loading(ids)
published.with_translations.includes([:document, { organisations: :translations }]).where(id: ids)
end
Expand Down
8 changes: 0 additions & 8 deletions test/unit/app/models/edition/identifiable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ class Edition::IdentifiableTest < ActiveSupport::TestCase
assert_equal publication.document.slug, news_article.document.slug
end

test "should allow the same slug to be used for a news article and a speech" do
same_title = "same-title"
news_article = create(:news_article, title: same_title)
speech = create(:speech, title: same_title)

assert_equal news_article.document.slug, speech.document.slug
end

test "should return the edition of the correct type when matching slugs for other types exist" do
same_title = "same-title"
news_article = create(:published_news_article, title: same_title)
Expand Down

0 comments on commit a9e0be4

Please sign in to comment.