Skip to content

Commit

Permalink
API: fixed double decoration
Browse files Browse the repository at this point in the history
Decorators should implement `Magic::Decoratable` API not to fail upon an accidental double decoration. They shouldn't be in fact decorated though.
  • Loading branch information
Alexander-Senko committed Oct 27, 2024
1 parent 8a5760c commit 27fe21f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
- Improved extendability: one may override `Magic::Decoratable#decorator_base` to be used for lookups.
- `Magic::Decoratable.classes` for all the decoratables.

## Fixed

- Failures on double decoration attempts.

## [0.2.0] — 2024-10-17

Expand Down
3 changes: 2 additions & 1 deletion lib/magic/decorator/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
module Magic
module Decorator
class Base < SimpleDelegator
extend Lookup
extend Lookup
include Decoratable

class << self
def name_for(object_class) = "#{object_class}Decorator"
Expand Down
6 changes: 6 additions & 0 deletions spec/magic/decorator/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ def in?(collection) = collection.include? self
end
end
end

context 'when double-decorated' do
subject { decorated.decorate }

it { is_expected.to be_nil }
end
end
end
end

0 comments on commit 27fe21f

Please sign in to comment.