Skip to content

Commit

Permalink
Fix decorators by making methods non-private
Browse files Browse the repository at this point in the history
The issue was caused by `draper` gem upgrade (which was a result of
upgrading Ruby to v3). The issue was here:
https://github.com/drapergem/draper/blob/v4.0.2/lib/draper/automatic_delegation.rb#L10-L26

In decorators we delegate all methods to the decorated object. But this version of the library
only does that when there is no private method with the same name on the decorator.
In this case, as `admin_user`  was a private method on AccountDecorator, draper tried to call
`admin_user `on superclass, but it was not there, so it was failing with:
```
ActionView::Template::Error (super: no superclass method `admin_user' for #<AccountDecorator:0x00007f8784266d18
  @object=#<Account id: 11, org_name: "Testing" ...> Did you mean? admin_user_email):
```

Removing it from `private_methods` fixed the issue.
  • Loading branch information
mayorova committed Sep 18, 2024
1 parent 5ef5c6f commit fed96e3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/decorators/account_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class AccountDecorator < ApplicationDecorator
delegate :display_name, :email, to: :admin_user, prefix: true

private
protected

def admin_user
@admin_user ||= (super || User.new).decorate
Expand Down
2 changes: 1 addition & 1 deletion app/decorators/proxy_config_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class ProxyConfigDecorator < ApplicationDecorator
delegate :display_name, to: :user, prefix: true

private
protected

def user
@user ||= (super || User.new).decorate
Expand Down

0 comments on commit fed96e3

Please sign in to comment.