From 19a048ecec30363b61db3891001808b3ea9b37c5 Mon Sep 17 00:00:00 2001 From: Ridhwana Date: Mon, 7 Dec 2020 21:57:18 +0200 Subject: [PATCH] Deployment Task: Update onboarding fields prior to #11629 (#11704) --- .../profile_fields/add_base_fields.rb | 22 ++++++-- .../profile_fields/field_definition.rb | 12 ++-- .../profile_fields/import_from_csv.rb | 2 +- lib/data/dev_profile_fields.csv | 56 +++++++++---------- .../temporary/profile_onboarding_fields.rake | 10 ++++ spec/fixtures/files/profile_fields.csv | 6 +- .../profile_field_groups_request_spec.rb | 9 ++- 7 files changed, 73 insertions(+), 44 deletions(-) create mode 100644 lib/tasks/temporary/profile_onboarding_fields.rake diff --git a/app/services/profile_fields/add_base_fields.rb b/app/services/profile_fields/add_base_fields.rb index c84ac363a..8ee6bed11 100644 --- a/app/services/profile_fields/add_base_fields.rb +++ b/app/services/profile_fields/add_base_fields.rb @@ -3,10 +3,24 @@ module ProfileFields include FieldDefinition group "Basic" do - field "Display email on profile", :check_box, display_area: "settings_only" - field "Website URL", :text_field, placeholder: "https://yoursite.com", display_area: "header" - field "Summary", :text_area, placeholder: "A short bio...", display_area: "header" - field "Location", :text_field, placeholder: "Halifax, Nova Scotia", display_area: "header" + field "Display email on profile", + :check_box, + display_area: "settings_only" + field "Website URL", + :text_field, + placeholder: "https://yoursite.com", + display_area: "header", + show_in_onboarding: true + field "Summary", + :text_area, + placeholder: "A short bio...", + display_area: "header", + show_in_onboarding: true + field "Location", + :text_field, + placeholder: "Halifax, Nova Scotia", + display_area: "header", + show_in_onboarding: true end end end diff --git a/app/services/profile_fields/field_definition.rb b/app/services/profile_fields/field_definition.rb index 1dcdd7e66..4bdaa4db4 100644 --- a/app/services/profile_fields/field_definition.rb +++ b/app/services/profile_fields/field_definition.rb @@ -20,14 +20,16 @@ module ProfileFields private - def field(label, input_type, placeholder: nil, description: nil, group: @group, display_area: "left_sidebar") + def field(label, input_type, **attributes) + attributes = attributes.reverse_merge(group: @group, display_area: "left_sidebar") fields << { label: label, input_type: input_type, - placeholder_text: placeholder, - description: description, - profile_field_group: group, - display_area: display_area + placeholder_text: attributes[:placeholder], + description: attributes[:description], + profile_field_group: attributes[:group], + display_area: attributes[:display_area], + show_in_onboarding: attributes[:show_in_onboarding] }.compact end end diff --git a/app/services/profile_fields/import_from_csv.rb b/app/services/profile_fields/import_from_csv.rb index 3fa2bfdc8..e69f98460 100644 --- a/app/services/profile_fields/import_from_csv.rb +++ b/app/services/profile_fields/import_from_csv.rb @@ -1,6 +1,6 @@ module ProfileFields class ImportFromCsv - HEADERS = %i[label input_type placeholder_text description group display_area].freeze + HEADERS = %i[label input_type placeholder_text description group display_area show_in_onboarding].freeze def self.call(file) CSV.foreach(file, headers: HEADERS, skip_blanks: true) do |row| diff --git a/lib/data/dev_profile_fields.csv b/lib/data/dev_profile_fields.csv index 3f89e5e86..b0b7d569f 100644 --- a/lib/data/dev_profile_fields.csv +++ b/lib/data/dev_profile_fields.csv @@ -1,28 +1,28 @@ -Display email on profile,check_box,,,Basic,settings_only -Website URL,text_field,https://yoursite.com,,Basic,header -Summary,text_area,A short bio...,,Basic,header -Location,text_field,"Halifax, Nova Scotia",,Basic,header -Facebook URL,text_field,https://facebook.com/...,,Links,header -Youtube URL,text_field,https://www.youtube.com/channel/...,,Links,header -StackOverflow URL,text_field,https://stackoverflow.com/users/...,,Links,header -LinkedIn URL,text_field,https://www.linkedin.com/in/...,,Links,header -Behance URL,text_field,https://www.behance.net/...,,Links,header -Dribbble URL,text_field,https://dribbble.com/...,,Links,header -Medium URL,text_field,https://medium.com/@...,,Links,header -GitLab URL,text_field,https://gitlab.com/...,,Links,header -Instagram URL,text_field,https://www.instagram.com/...,,Links,header -Mastodon URL,text_field,https://...,,Links,header -Twitch URL,text_field,https://www.twitch.tv/...,,Links,header -Education,text_field,,,Work,header -Employer name,text_field,Acme Inc.,,Work,header -Employer URL,text_field,https://dev.com,,Work,header -Employment title,text_field,Junior Frontend Engineer,,Work,header -Looking for work,check_box,,,Work,settings_only -"Display ""looking for work"" on profile",check_box,,,Work,settings_only -Recruiters can contact me about job opportunities,check_box,,,Work,settings_only -Skills/Languages,text_area,,What tools and languages are you most experienced with? Are you specialized or more of a generalist?,Coding,left_sidebar -Currently learning,text_area,,"What are you learning right now? What are the new tools and languages you're picking up right now?",Coding,left_sidebar -Currently hacking on,text_area,,What projects are currently occupying most of your time?,Coding,left_sidebar -Available for,text_area,,"What kinds of collaborations or discussions are you available for? What's a good reason to say Hey! to you these days?",Coding,left_sidebar -Brand color 1,color_field,#000000,"Used for backgrounds, borders etc.",Branding,settings_only -Brand color 2,color_field,#000000,Used for texts (usually put on Brand color 1).,Branding,settings_only +Display email on profile,check_box,,,Basic,settings_only,false +Website URL,text_field,https://yoursite.com,,Basic,header,true +Summary,text_area,A short bio...,,Basic,header,true +Location,text_field,"Halifax, Nova Scotia",,Basic,header,true +Facebook URL,text_field,https://facebook.com/...,,Links,header,false +Youtube URL,text_field,https://www.youtube.com/channel/...,,Links,header,false +StackOverflow URL,text_field,https://stackoverflow.com/users/...,,Links,header,false +LinkedIn URL,text_field,https://www.linkedin.com/in/...,,Links,header,false +Behance URL,text_field,https://www.behance.net/...,,Links,header,false +Dribbble URL,text_field,https://dribbble.com/...,,Links,header,false +Medium URL,text_field,https://medium.com/@...,,Links,header,false +GitLab URL,text_field,https://gitlab.com/...,,Links,header,false +Instagram URL,text_field,https://www.instagram.com/...,,Links,header,false +Mastodon URL,text_field,https://...,,Links,header,false +Twitch URL,text_field,https://www.twitch.tv/...,,Links,header,false +Education,text_field,,,Work,header,false +Employer name,text_field,Acme Inc.,,Work,header,false +Employer URL,text_field,https://dev.com,,Work,header,false +Employment title,text_field,Junior Frontend Engineer,,Work,header,false +Looking for work,check_box,,,Work,settings_only,false +"Display ""looking for work"" on profile",check_box,,,Work,settings_only,false +Recruiters can contact me about job opportunities,check_box,,,Work,settings_only,false +Skills/Languages,text_area,,What tools and languages are you most experienced with? Are you specialized or more of a generalist?,Coding,left_sidebar,false +Currently learning,text_area,,"What are you learning right now? What are the new tools and languages you're picking up right now?",Coding,left_sidebar,false +Currently hacking on,text_area,,What projects are currently occupying most of your time?,Coding,left_sidebar,false +Available for,text_area,,"What kinds of collaborations or discussions are you available for? What's a good reason to say Hey! to you these days?",Coding,left_sidebar,false +Brand color 1,color_field,#000000,"Used for backgrounds, borders etc.",Branding,settings_only,false +Brand color 2,color_field,#000000,Used for texts (usually put on Brand color 1).,Branding,settings_only,false diff --git a/lib/tasks/temporary/profile_onboarding_fields.rake b/lib/tasks/temporary/profile_onboarding_fields.rake new file mode 100644 index 000000000..9786287da --- /dev/null +++ b/lib/tasks/temporary/profile_onboarding_fields.rake @@ -0,0 +1,10 @@ +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 diff --git a/spec/fixtures/files/profile_fields.csv b/spec/fixtures/files/profile_fields.csv index 7391e16ff..872accaba 100644 --- a/spec/fixtures/files/profile_fields.csv +++ b/spec/fixtures/files/profile_fields.csv @@ -1,4 +1,4 @@ -Test name,text_field,John Doe,,Basic,header -Test languages,text_area,,Programming languages,Coding,left_sidebar +Test name,text_field,John Doe,,Basic,header,false +Test languages,text_area,,Programming languages,Coding,left_sidebar,false -Test color,color_field,#000000,"Used for backgrounds, borders etc.",Branding,settings_only +Test color,color_field,#000000,"Used for backgrounds, borders etc.",Branding,settings_only,false diff --git a/spec/requests/profile_field_groups_request_spec.rb b/spec/requests/profile_field_groups_request_spec.rb index 87005a4c9..26fad7d6e 100644 --- a/spec/requests/profile_field_groups_request_spec.rb +++ b/spec/requests/profile_field_groups_request_spec.rb @@ -27,16 +27,19 @@ RSpec.describe "ProfileFieldGroups", type: :request do expect(json_response[:profile_field_groups].size).to eq ProfileFieldGroup.all.size end - it "returns only groups with onboarding fields when onboarding=true" do + it "returns only groups with onboarding fields when onboarding=true", :aggregate_failures do get profile_field_groups_path, params: { onboarding: true } json_response = JSON.parse(response.body, symbolize_names: true) - expect(json_response[:profile_field_groups].size).to eq 1 + groups = json_response[:profile_field_groups] + expect(groups.any? { |g| g[:name] == group1.name }).to be true + expect(groups.any? { |g| g[:name] == group2.name }).to be false end it "only returns the onboarding fields in the group", :aggregate_failures do get profile_field_groups_path, params: { onboarding: true } json_response = JSON.parse(response.body, symbolize_names: true) - group = json_response[:profile_field_groups].first + groups = json_response[:profile_field_groups] + group = groups.detect { |g| g[:name] == group1.name } expect(group[:profile_fields].size).to eq 1 field1 = ProfileField.find_by(label: "Field 1") expect(group[:profile_fields].first[:id]).to eq field1.id