[deploy] Start using profile model (#9724)

* Persist attribute_name for profile fields

* Update fields

* Add temporary Rake task for creating profile fields

* Update specs

* Fix problems after splitting branch
This commit is contained in:
Michael Kohl 2020-08-17 09:57:50 +07:00 committed by GitHub
parent adc347580f
commit 2b3242087c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 74 additions and 17 deletions

View file

@ -1,4 +1,8 @@
class ProfileField < ApplicationRecord
before_create :generate_attribute_name
WORD_REGEX = /\w+/.freeze
# Key names follow the Rails form helpers
enum input_type: {
text_field: 0,
@ -9,16 +13,19 @@ class ProfileField < ApplicationRecord
validates :label, presence: true, uniqueness: { case_sensitive: false }
validates :active, inclusion: { in: [true, false] }
validates :attribute_name, presence: true, on: :update
scope :active, -> { where(active: true) }
def attribute_name
label.titleize.delete(" ").underscore
end
def type
return :boolean if check_box?
:string
end
private
def generate_attribute_name
self.attribute_name = label.titleize.scan(WORD_REGEX).join.underscore
end
end

View file

@ -3,17 +3,17 @@ module ProfileFields
include FieldDefinition
group "Links" do
field "Facebook profile URL", :text_field, placeholder: "https://facebook.com/..."
field "Facebook URL", :text_field, placeholder: "https://facebook.com/..."
field "Youtube URL", :text_field, placeholder: "https://www.youtube.com/channel/..."
field "StackOverflow profile URL", :text_field, placeholder: "https://stackoverflow.com/users/..."
field "LinkedIn profile URL", :text_field, placeholder: "https://www.linkedin.com/in/..."
field "Behance profile URL", :text_field, placeholder: "https://..."
field "Dribble profile URL", :text_field, placeholder: "https://dribble.com/..."
field "Medium profile URL", :text_field, placeholder: "https://..."
field "GitLab profile URL", :text_field, placeholder: "https://..."
field "Instagram profile URL", :text_field, placeholder: "https://..."
field "Mastodon profile URL", :text_field, placeholder: "https://..."
field "Twitch profile URL", :text_field, placeholder: "https://..."
field "StackOverflow URL", :text_field, placeholder: "https://stackoverflow.com/users/..."
field "LinkedIn URL", :text_field, placeholder: "https://www.linkedin.com/in/..."
field "Behance URL", :text_field, placeholder: "https://www.behance.net/..."
field "Dribble URL", :text_field, placeholder: "https://dribble.com/..."
field "Medium URL", :text_field, placeholder: "https://medium.com/@..."
field "GitLab URL", :text_field, placeholder: "https://gitlab.com/..."
field "Instagram URL", :text_field, placeholder: "https://www.instagram.com/..."
field "Mastodon URL", :text_field, placeholder: "https://..."
field "Twitch URL", :text_field, placeholder: "https://www.twitch.tv/..."
end
end
end

View file

@ -0,0 +1,5 @@
class AddAttributeNameToProfileField < ActiveRecord::Migration[6.0]
def change
add_column :profile_fields, :attribute_name, :string, null: false
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_08_09_200631) do
ActiveRecord::Schema.define(version: 2020_08_11_044202) do
# These are extensions that must be enabled in order to support this database
enable_extension "citext"
@ -923,6 +923,7 @@ ActiveRecord::Schema.define(version: 2020_08_09_200631) do
create_table "profile_fields", force: :cascade do |t|
t.boolean "active", default: true, null: false
t.string "attribute_name", null: false
t.datetime "created_at", precision: 6, null: false
t.string "description"
t.string "group"

View file

@ -1,4 +1,4 @@
Skills/Languages,text_area,,What tools and languages are you most experienced with? Are you specialized or more of a generalist?,Coding
I'm getting into,text_area,,What are you learning right now? What are the new tools and languages you're picking up right now?,Coding
My projects and hacks,text_area,,What projects are currently occupying most of your time?,Coding
Currently learning,text_area,,What are you learning right now? What are the new tools and languages you're picking up right now?,Coding
Currently hacking on,text_area,,What projects are currently occupying most of your time?,Coding
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

1 Skills/Languages text_area What tools and languages are you most experienced with? Are you specialized or more of a generalist? Coding
2 I'm getting into Currently learning text_area What are you learning right now? What are the new tools and languages you're picking up right now? Coding
3 My projects and hacks Currently hacking on text_area What projects are currently occupying most of your time? Coding
4 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

View file

@ -0,0 +1,29 @@
Display email on profile,check_box,,,Basic
Name,text_field,John Doe,,Basic
Website URL,text_field,https://yoursite.com,,Basic
Summary,text_area,A short bio...,,Basic
Location,text_field,"Halifax, Nova Scotia",,Basic
Facebook URL,text_field,https://facebook.com/...,,Links
Youtube URL,text_field,https://www.youtube.com/channel/...,,Links
StackOverflow URL,text_field,https://stackoverflow.com/users/...,,Links
LinkedIn URL,text_field,https://www.linkedin.com/in/...,,Links
Behance URL,text_field,https://www.behance.net/...,,Links
Dribble URL,text_field,https://dribble.com/...,,Links
Medium URL,text_field,https://medium.com/@...,,Links
GitLab URL,text_field,https://gitlab.com/...,,Links
Instagram URL,text_field,https://www.instagram.com/...,,Links
Mastodon URL,text_field,https://...,,Links
Twitch URL,text_field,https://www.twitch.tv/...,,Links
Education,text_field,,,Work
Employer name,text_field,Acme Inc.,,Work
Employer URL,text_field,https://dev.com,,Work
Employment title,text_field,Junior Frontend Engineer,,Work
Looking for work,check_box,,,Work
"Display ""looking for work"" on profile",check_box,,,Work
Recruiters can contact me about job opportunities,check_box,,,Work
Skills/Languages,text_area,,What tools and languages are you most experienced with? Are you specialized or more of a generalist?,Coding
Currently learning,text_area,,"What are you learning right now? What are the new tools and languages you're picking up right now?",Coding
Currently hacking on,text_area,,What projects are currently occupying most of your time?,Coding
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
Brand color 1,color_field,#000000,"Used for backgrounds, borders etc.",Branding
Brand color 2,color_field,#000000,Used for texts (usually put on Brand color 1).,Branding
1 Display email on profile check_box Basic
2 Name text_field John Doe Basic
3 Website URL text_field https://yoursite.com Basic
4 Summary text_area A short bio... Basic
5 Location text_field Halifax, Nova Scotia Basic
6 Facebook URL text_field https://facebook.com/... Links
7 Youtube URL text_field https://www.youtube.com/channel/... Links
8 StackOverflow URL text_field https://stackoverflow.com/users/... Links
9 LinkedIn URL text_field https://www.linkedin.com/in/... Links
10 Behance URL text_field https://www.behance.net/... Links
11 Dribble URL text_field https://dribble.com/... Links
12 Medium URL text_field https://medium.com/@... Links
13 GitLab URL text_field https://gitlab.com/... Links
14 Instagram URL text_field https://www.instagram.com/... Links
15 Mastodon URL text_field https://... Links
16 Twitch URL text_field https://www.twitch.tv/... Links
17 Education text_field Work
18 Employer name text_field Acme Inc. Work
19 Employer URL text_field https://dev.com Work
20 Employment title text_field Junior Frontend Engineer Work
21 Looking for work check_box Work
22 Display "looking for work" on profile check_box Work
23 Recruiters can contact me about job opportunities check_box Work
24 Skills/Languages text_area What tools and languages are you most experienced with? Are you specialized or more of a generalist? Coding
25 Currently learning text_area What are you learning right now? What are the new tools and languages you're picking up right now? Coding
26 Currently hacking on text_area What projects are currently occupying most of your time? Coding
27 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
28 Brand color 1 color_field #000000 Used for backgrounds, borders etc. Branding
29 Brand color 2 color_field #000000 Used for texts (usually put on Brand color 1). Branding

View file

@ -0,0 +1,7 @@
namespace :temporary do
desc "Create profile fields based on DEV profile"
task create_profile_fields: :environment do
csv = Rails.root.join("lib/data/dev_profile_fields.csv")
ProfileFields::ImportFromCsv.call(csv)
end
end

View file

@ -10,6 +10,14 @@ RSpec.describe ProfileField, type: :model do
it { is_expected.to validate_presence_of(:label) }
it { is_expected.to validate_uniqueness_of(:label).case_insensitive }
it { is_expected.to validate_inclusion_of(:active).in_array([true, false]) }
it { is_expected.to validate_presence_of(:attribute_name).on(:update) }
end
end
describe "callbacks" do
it "automatically generates an attribute name" do
pf = create(:profile_field, label: "Is this a test? This is a test! 1")
expect(pf.attribute_name).to eq "is_this_a_test_this_is_a_test1"
end
end
end