Commit ac26518f authored by Michael Kozono's avatar Michael Kozono

Capture email opt-in IP

parent 4f0b3463
module EE module EE
module RegistrationsController module RegistrationsController
extend ActiveSupport::Concern extend ActiveSupport::Concern
private private
def sign_up_params def sign_up_params
params.require(:user).permit(:username, :email, :email_confirmation, :name, :password, :email_opted_in) 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
clean_params
end end
end end
end end
...@@ -3,7 +3,7 @@ module EE ...@@ -3,7 +3,7 @@ module EE
module BuildService module BuildService
private private
def signup_params def signup_params
[ [
:email, :email,
...@@ -12,7 +12,8 @@ module EE ...@@ -12,7 +12,8 @@ module EE
:name, :name,
:password, :password,
:username, :username,
:email_opted_in :email_opted_in,
:email_opted_in_ip
] ]
end end
end end
......
require 'spec_helper'
describe RegistrationsController do
describe '#create' do
let(:user_params) { { user: { name: 'new_user', username: 'new_username', email: 'new@user.com', password: 'Any_password', email_opted_in: email_opted_in } } }
context 'when the user opted-in' do
let(:email_opted_in) { '1' }
it 'sets email_opted_in_ip to an IP' do
post :create, user_params
user = User.find_by_username('new_username')
expect(user.email_opted_in_ip).to be_present
end
end
context 'when the user opted-out' do
let(:email_opted_in) { '0' }
it 'sets email_opted_in_ip to nil' do
post :create, user_params
user = User.find_by_username('new_username')
expect(user.email_opted_in_ip).to be_nil
end
end
end
end
...@@ -22,6 +22,7 @@ feature 'Signup on EE' do ...@@ -22,6 +22,7 @@ feature 'Signup on EE' do
user = User.find_by_username!(user.username) user = User.find_by_username!(user.username)
expect(user.email_opted_in).to be_truthy expect(user.email_opted_in).to be_truthy
expect(user.email_opted_in_ip).to be_present
end end
end end
...@@ -40,6 +41,7 @@ feature 'Signup on EE' do ...@@ -40,6 +41,7 @@ feature 'Signup on EE' do
user = User.find_by_username!(user.username) user = User.find_by_username!(user.username)
expect(user.email_opted_in).to be_falsey expect(user.email_opted_in).to be_falsey
expect(user.email_opted_in_ip).to be_nil
end end
end end
end end
...@@ -65,6 +67,7 @@ feature 'Signup on EE' do ...@@ -65,6 +67,7 @@ feature 'Signup on EE' do
user = User.find_by_username!(user.username) user = User.find_by_username!(user.username)
expect(user.email_opted_in).to be_falsey expect(user.email_opted_in).to be_falsey
expect(user.email_opted_in_ip).to be_nil
end end
end 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