Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add User.decorate method
**Why**: Encourage use of UserDecorator by making it easier
to construct.
  • Loading branch information
Peter Karman committed Aug 2, 2016
1 parent d6efc4b commit ed9465f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Expand Up @@ -32,7 +32,7 @@ def analytics
private

def decorated_user
UserDecorator.new(current_user)
@_decorated_user ||= current_user.decorate
end

def after_sign_in_path_for(resource)
Expand Down
4 changes: 4 additions & 0 deletions app/models/user.rb
Expand Up @@ -75,4 +75,8 @@ def active_profile
def send_devise_notification(notification, *args)
devise_mailer.send(notification, self, *args).deliver_later
end

def decorate
UserDecorator.new(self)
end
end
8 changes: 8 additions & 0 deletions spec/models/user_spec.rb
Expand Up @@ -244,4 +244,12 @@
expect(user.direct_otp.length).to eq 6
end
end

describe '#decorate' do
it 'returns a UserDecorator' do
user = build(:user)

expect(user.decorate).to be_a(UserDecorator)
end
end
end

0 comments on commit ed9465f

Please sign in to comment.