Commit 1012b1c2 authored by Michael Kozono's avatar Michael Kozono

Capture email opt-in source and timestamp

parent 72f8a090
......@@ -7,7 +7,11 @@ module EE
def sign_up_params
clean_params = params.require(:user).permit(:username, :email, :email_confirmation, :name, :password, :email_opted_in)
clean_params[:email_opted_in_ip] = clean_params[:email_opted_in] == '1' ? request.remote_ip : nil
if clean_params[:email_opted_in] == '1'
clean_params[:email_opted_in_ip] = request.remote_ip
clean_params[:email_opted_in_source] = 'GitLab.com'
clean_params[:email_opted_in_at] = Time.zone.now
end
clean_params
end
......
......@@ -13,7 +13,9 @@ module EE
:password,
:username,
:email_opted_in,
:email_opted_in_ip
:email_opted_in_ip,
:email_opted_in_source,
:email_opted_in_at
]
end
end
......
......@@ -7,20 +7,26 @@ describe RegistrationsController do
context 'when the user opted-in' do
let(:email_opted_in) { '1' }
it 'sets email_opted_in_ip to an IP' do
it 'sets the rest of the email_opted_in fields' do
post :create, user_params
user = User.find_by_username('new_username')
expect(user.email_opted_in).to be_truthy
expect(user.email_opted_in_ip).to be_present
expect(user.email_opted_in_source).to eq('GitLab.com')
expect(user.email_opted_in_at).not_to be_nil
end
end
context 'when the user opted-out' do
let(:email_opted_in) { '0' }
it 'sets email_opted_in_ip to nil' do
it 'does not set the rest of the email_opted_in fields' do
post :create, user_params
user = User.find_by_username('new_username')
expect(user.email_opted_in_ip).to be_nil
expect(user.email_opted_in).to be_falsey
expect(user.email_opted_in_ip).to be_blank
expect(user.email_opted_in_source).to be_blank
expect(user.email_opted_in_at).to be_nil
end
end
end
......
......@@ -23,6 +23,8 @@ feature 'Signup on EE' do
user = User.find_by_username!(user.username)
expect(user.email_opted_in).to be_truthy
expect(user.email_opted_in_ip).to be_present
expect(user.email_opted_in_source).to eq('GitLab.com')
expect(user.email_opted_in_at).not_to be_nil
end
end
......@@ -41,7 +43,9 @@ feature 'Signup on EE' do
user = User.find_by_username!(user.username)
expect(user.email_opted_in).to be_falsey
expect(user.email_opted_in_ip).to be_nil
expect(user.email_opted_in_ip).to be_blank
expect(user.email_opted_in_source).to be_blank
expect(user.email_opted_in_at).to be_nil
end
end
end
......@@ -67,7 +71,9 @@ feature 'Signup on EE' do
user = User.find_by_username!(user.username)
expect(user.email_opted_in).to be_falsey
expect(user.email_opted_in_ip).to be_nil
expect(user.email_opted_in_ip).to be_blank
expect(user.email_opted_in_source).to be_blank
expect(user.email_opted_in_at).to be_nil
end
end
end
Markdown is supported
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