Commit df206331 authored by Michael Kozono's avatar Michael Kozono

Switch source to source_id

parent 84dd5610
......@@ -9,7 +9,7 @@ class AddEmailOptedInFieldsToUsers < ActiveRecord::Migration
def change
add_column :users, :email_opted_in, :boolean, null: true
add_column :users, :email_opted_in_ip, :string, null: true
add_column :users, :email_opted_in_source, :string, null: true
add_column :users, :email_opted_in_source_id, :integer, null: true
add_column :users, :email_opted_in_at, :datetime_with_timezone, null: true
end
end
......@@ -1906,7 +1906,7 @@ ActiveRecord::Schema.define(version: 20170808163512) do
t.string "email_provider"
t.boolean "email_opted_in"
t.string "email_opted_in_ip"
t.string "email_opted_in_source"
t.integer "email_opted_in_source_id"
t.datetime_with_timezone "email_opted_in_at"
end
......
......@@ -11,7 +11,7 @@ module EE
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_source_id] = User::EMAIL_OPT_IN_SOURCE_ID_GITLAB_COM
clean_params[:email_opted_in_at] = Time.zone.now
end
......
......@@ -8,6 +8,8 @@ module EE
include AuditorUserHelper
included do
EMAIL_OPT_IN_SOURCE_ID_GITLAB_COM = 1
# We aren't using the `auditor?` method for the `if` condition here
# because `auditor?` returns `false` when the `auditor` column is `true`
# and the auditor add-on absent. We want to run this validation
......@@ -91,5 +93,9 @@ module EE
return if ::Gitlab::Geo.secondary?
super
end
def email_opted_in_source
email_opted_in_source_id == EMAIL_OPT_IN_SOURCE_ID_GITLAB_COM ? 'GitLab.com' : ''
end
end
end
......@@ -14,7 +14,7 @@ module EE
:username,
:email_opted_in,
:email_opted_in_ip,
:email_opted_in_source,
:email_opted_in_source_id,
:email_opted_in_at
]
end
......
......@@ -105,4 +105,30 @@ describe EE::User do
expect { subject.remember_me! }.not_to change(subject, :remember_created_at)
end
end
describe '#email_opted_in_source' do
context 'for GitLab.com' do
let(:user) { build(:user, email_opted_in_source_id: 1) }
it 'returns GitLab.com' do
expect(user.email_opted_in_source).to eq('GitLab.com')
end
end
context 'for nil source id' do
let(:user) { build(:user, email_opted_in_source_id: nil) }
it 'returns blank' do
expect(user.email_opted_in_source).to be_blank
end
end
context 'for non-existent source id' do
let(:user) { build(:user, email_opted_in_source_id: 2) }
it 'returns blank' do
expect(user.email_opted_in_source).to be_blank
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