Commit a539bb29 authored by Brett Walker's avatar Brett Walker
Browse files

use a delegate for `username` to be more future friendly

parent 9b6d509f1298
......@@ -15,8 +15,7 @@
if signed_in?(:user)
after_sign_in(resource)
else
username = (resource_name == :email ? resource.user.username : resource.username)
Gitlab::AppLogger.info("Email Confirmed: username=#{username} email=#{resource.email} ip=#{request.remote_ip}")
Gitlab::AppLogger.info("Email Confirmed: username=#{resource.username} email=#{resource.email} ip=#{request.remote_ip}")
flash[:notice] += " Please sign in."
new_session_path(:user)
end
......
......@@ -14,6 +14,8 @@
devise :confirmable
self.reconfirmable = false # currently email can't be changed, no need to reconfirm
delegate :username, to: :user
def email=(value)
write_attribute(:email, value.downcase.strip)
end
......
......@@ -40,4 +40,12 @@
expect(user.emails.confirmed.count).to eq 1
end
end
describe 'delegation' do
let(:user) { create(:user) }
it 'delegates to :user' do
expect(build(:email, user: user).username).to eq user.username
end
end
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment