Skip to content

Commit

Permalink
Namespace VersionDecorator under PaginatedTimeline
Browse files Browse the repository at this point in the history
This makes it clearer what the purpose of this decorator is
  • Loading branch information
pezholio committed Jan 6, 2025
1 parent 7f27892 commit cb2fa03
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class VersionDecorator < SimpleDelegator
class Document::PaginatedTimeline::VersionDecorator < SimpleDelegator
def initialize(version, is_first_edition: false, previous_version: nil)
@is_first_edition = is_first_edition
@preloaded_previous_version = previous_version
Expand Down
2 changes: 1 addition & 1 deletion app/models/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def decorated_edition_versions_by_ids(version_ids)
versions = active_edition_versions.where(id: version_ids)

versions.map.with_index { |version, index|
version = VersionDecorator.new(
version = Document::PaginatedTimeline::VersionDecorator.new(
version,
is_first_edition: version.item_id == first_edition_id,
previous_version: versions[index - 1],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Admin::Editions::AuditTrailEntryComponentTest < ViewComponent::TestCase
edition = build_stubbed(:edition)
version = edition.versions.new(event: "create", created_at: Time.zone.local(2020, 1, 1, 11, 11))
version.stubs(:user).returns(actor)
audit = VersionDecorator.new(version, is_first_edition: true)
audit = Document::PaginatedTimeline::VersionDecorator.new(version, is_first_edition: true)

render_inline(Admin::Editions::AuditTrailEntryComponent.new(entry: audit, edition:))

Expand All @@ -23,7 +23,7 @@ class Admin::Editions::AuditTrailEntryComponentTest < ViewComponent::TestCase
test "it constructs output based on the entry when an actor is absent" do
edition = build_stubbed(:edition)
version = edition.versions.new(event: "create", created_at: Time.zone.local(2020, 1, 1, 11, 11), whodunnit: nil)
audit = VersionDecorator.new(version, is_first_edition: true)
audit = Document::PaginatedTimeline::VersionDecorator.new(version, is_first_edition: true)

render_inline(Admin::Editions::AuditTrailEntryComponent.new(entry: audit, edition:))

Expand All @@ -37,7 +37,7 @@ class Admin::Editions::AuditTrailEntryComponentTest < ViewComponent::TestCase
edition.versions.new(event: "create", created_at: Time.zone.local(2020, 1, 1, 11, 11), whodunnit: actor.id)
version = edition.versions.new(event: "published", created_at: Time.zone.local(2020, 1, 1, 11, 11), state: "published")
version.stubs(:user).returns(actor)
audit = VersionDecorator.new(version, is_first_edition: true)
audit = Document::PaginatedTimeline::VersionDecorator.new(version, is_first_edition: true)
newer_edition = build_stubbed(:edition, :draft)

render_inline(Admin::Editions::AuditTrailEntryComponent.new(entry: audit, edition: newer_edition))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class VersionDecoratorTest < ActiveSupport::TestCase
class Document::PaginatedTimeline::VersionDecoratorTest < ActiveSupport::TestCase
extend Minitest::Spec::DSL

let(:user) { build(:user) }
Expand All @@ -10,18 +10,18 @@ class VersionDecoratorTest < ActiveSupport::TestCase
let(:is_first_edition) { false }
let(:previous_version) { build(:version, user:, item: edition) }

let(:decorator) { VersionDecorator.new(version, is_first_edition:, previous_version:) }
let(:decorator) { Document::PaginatedTimeline::VersionDecorator.new(version, is_first_edition:, previous_version:) }

describe "#==" do
it "is true if the class, ID and action are the same" do
other_decorator = VersionDecorator.new(version, is_first_edition:, previous_version:)
other_decorator = Document::PaginatedTimeline::VersionDecorator.new(version, is_first_edition:, previous_version:)

assert decorator == other_decorator
end

it "is not true if the class ID and action are different" do
other_version = build(:version, user:, item: edition, id: 444)
other_decorator = VersionDecorator.new(other_version, is_first_edition:, previous_version:)
other_decorator = Document::PaginatedTimeline::VersionDecorator.new(other_version, is_first_edition:, previous_version:)

assert_not decorator == other_decorator
end
Expand Down
18 changes: 9 additions & 9 deletions test/unit/app/models/document/paginated_timeline_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class PaginatedTimelineTest < ActiveSupport::TestCase
assert_equal entry_timestamps.sort.reverse, entry_timestamps
end

it "is a list of VersionDecorator and EditorialRemark objects when 'only' argument is not present" do
it "is a list of Document::PaginatedTimeline::VersionDecorator and EditorialRemark objects when 'only' argument is not present" do
timeline = Document::PaginatedTimeline.new(document: @document, page: 1)
assert_equal [VersionDecorator, EditorialRemark].to_set,
assert_equal [Document::PaginatedTimeline::VersionDecorator, EditorialRemark].to_set,
timeline.entries.map(&:class).to_set
end

Expand Down Expand Up @@ -48,7 +48,7 @@ class PaginatedTimelineTest < ActiveSupport::TestCase
it "correctly determines actions" do
mock_pagination(per_page: 30) do
timeline = Document::PaginatedTimeline.new(document: @document, page: 1)
entries = timeline.entries.select { |e| e.instance_of?(VersionDecorator) }
entries = timeline.entries.select { |e| e.instance_of?(Document::PaginatedTimeline::VersionDecorator) }
expected_actions = %w[updated
editioned
published
Expand All @@ -64,7 +64,7 @@ class PaginatedTimelineTest < ActiveSupport::TestCase

it "correctly determines actors" do
timeline = Document::PaginatedTimeline.new(document: @document, page: 1)
entries = timeline.entries.select { |e| e.instance_of?(VersionDecorator) }
entries = timeline.entries.select { |e| e.instance_of?(Document::PaginatedTimeline::VersionDecorator) }
expected_actors = [@user,
@user,
@user2,
Expand All @@ -89,9 +89,9 @@ class PaginatedTimelineTest < ActiveSupport::TestCase
assert_equal entry_timestamps.sort.reverse, entry_timestamps
end

it "is a list of VersionDecorator and EditorialRemark and HostContentUpdateEvent objects when 'only' argument is not present" do
it "is a list of Document::PaginatedTimeline::VersionDecorator and EditorialRemark and HostContentUpdateEvent objects when 'only' argument is not present" do
timeline = Document::PaginatedTimeline.new(document: @document, page: 1)
assert_equal [VersionDecorator, EditorialRemark, HostContentUpdateEvent].to_set,
assert_equal [Document::PaginatedTimeline::VersionDecorator, EditorialRemark, HostContentUpdateEvent].to_set,
timeline.entries.map(&:class).to_set
end

Expand Down Expand Up @@ -174,7 +174,7 @@ class PaginatedTimelineTest < ActiveSupport::TestCase
end

describe "when only argument is set to history" do
it "is a list of VersionDecorator objects" do
it "is a list of Document::PaginatedTimeline::VersionDecorator objects" do
timeline = Document::PaginatedTimeline.new(document: @document, page: 1, only: "history")
expected_actions = %w[updated
editioned
Expand Down Expand Up @@ -212,7 +212,7 @@ class PaginatedTimelineTest < ActiveSupport::TestCase
end

describe "#total_count" do
it "counts the list of VersionDecorator and EditorialRemark objects when no 'only' argument is passed in" do
it "counts the list of Document::PaginatedTimeline::VersionDecorator and EditorialRemark objects when no 'only' argument is passed in" do
timeline = Document::PaginatedTimeline.new(document: @document, page: 1)
assert_equal 11, timeline.total_count
end
Expand All @@ -222,7 +222,7 @@ class PaginatedTimelineTest < ActiveSupport::TestCase
assert_equal 3, timeline.total_count
end

it "counts the total VersionDecorator objects when 'history' is passed into the 'only' argument" do
it "counts the total Document::PaginatedTimeline::VersionDecorator objects when 'history' is passed into the 'only' argument" do
timeline = Document::PaginatedTimeline.new(document: @document, page: 1, only: "history")
assert_equal 8, timeline.total_count
end
Expand Down
8 changes: 4 additions & 4 deletions test/unit/app/models/document_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ class DocumentTest < ActiveSupport::TestCase
end

describe "#decorated_edition_versions_by_ids" do
it "returns all the versions, presented as VersionDecorator items" do
it "returns all the versions, presented as Document::PaginatedTimeline::VersionDecorator items" do
document = create(:document)
edition1 = create(:published_edition, document: document)
edition2 = create(:published_edition, document: document)
Expand All @@ -639,19 +639,19 @@ class DocumentTest < ActiveSupport::TestCase
version2_stub = stub(id: version2.id)
version3_stub = stub(id: version3.id)

VersionDecorator.stubs(:new).with { |v, **args|
Document::PaginatedTimeline::VersionDecorator.stubs(:new).with { |v, **args|
v.id == version1.id &&
args[:is_first_edition] == true &&
args[:previous_version] == version3
}.returns(version1_stub)

VersionDecorator.stubs(:new).with { |v, **args|
Document::PaginatedTimeline::VersionDecorator.stubs(:new).with { |v, **args|
v.id == version2.id &&
args[:is_first_edition] == false &&
args[:previous_version] == version1
}.returns(version2_stub)

VersionDecorator.stubs(:new).with { |v, **args|
Document::PaginatedTimeline::VersionDecorator.stubs(:new).with { |v, **args|
v.id == version3.id &&
args[:is_first_edition] == false &&
args[:previous_version] == version2
Expand Down

0 comments on commit cb2fa03

Please sign in to comment.