Replace the "setup onboarding profile fields" temp rake task with a data update script (#11800)
* feat: replace the temp rake task with a data update script * oops we need a user
This commit is contained in:
parent
71ad902315
commit
bae2571ad6
3 changed files with 44 additions and 10 deletions
|
|
@ -0,0 +1,13 @@
|
|||
module DataUpdateScripts
|
||||
class SetOnboardingProfileFieldsForExistingForems
|
||||
def run
|
||||
return unless User.count.positive?
|
||||
|
||||
ProfileField.where(attribute_name: "summary").update(label: "Bio", show_in_onboarding: true)
|
||||
ProfileField.where(attribute_name: "location").update(label: "Location", show_in_onboarding: true)
|
||||
ProfileField.where(attribute_name: "employment_title").update(label: "Employer title",
|
||||
show_in_onboarding: true)
|
||||
ProfileField.where(attribute_name: "employer_name").update(label: "Employer name", show_in_onboarding: true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
namespace :profile_onboarding_fields do
|
||||
desc "Setup Onboarding with previously shown fields"
|
||||
task update: :environment do
|
||||
ProfileField.where(attribute_name: "summary").update(label: "Bio", show_in_onboarding: true)
|
||||
ProfileField.where(attribute_name: "location").update(label: "Location", show_in_onboarding: true)
|
||||
ProfileField.where(attribute_name: "employment_title").update(label: "Employer title",
|
||||
show_in_onboarding: true)
|
||||
ProfileField.where(attribute_name: "employer_name").update(label: "Employer name", show_in_onboarding: true)
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
require "rails_helper"
|
||||
require Rails.root.join(
|
||||
"lib/data_update_scripts/20201208151516_set_onboarding_profile_fields_for_existing_forems.rb",
|
||||
)
|
||||
|
||||
describe DataUpdateScripts::SetOnboardingProfileFieldsForExistingForems do
|
||||
before do
|
||||
ProfileField.destroy_all
|
||||
end
|
||||
|
||||
let!(:user) { create(:user) }
|
||||
let!(:profile_field1) { create(:profile_field, label: "summary") }
|
||||
let!(:profile_field2) { create(:profile_field, label: "random") }
|
||||
let(:profile_field3) { create(:profile_field, label: "location") }
|
||||
|
||||
it "toggles show_in_onboarding to true for specific profile fields" do
|
||||
expect do
|
||||
described_class.new.run
|
||||
end.to change { profile_field1.reload.show_in_onboarding }.from(false).to(true)
|
||||
expect(profile_field2.reload.show_in_onboarding).to be false
|
||||
end
|
||||
|
||||
it "updates the labels for specific profile fields" do
|
||||
# note: we update the label manually here because when
|
||||
# we create the profile field the attribute_name is a
|
||||
# underscored version of the label.
|
||||
profile_field3.update(label: "Where are you located?")
|
||||
described_class.new.run
|
||||
expect(profile_field3.reload.label).to eq("Location")
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue