Clean up forem:setup task (#13998)

This commit is contained in:
Michael Kohl 2021-06-18 09:34:18 +07:00 committed by GitHub
parent 8f42828028
commit 23fe4dd9de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 7 additions and 145 deletions

View file

@ -1,26 +0,0 @@
module ProfileFields
class AddBaseFields
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",
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

View file

@ -1,18 +0,0 @@
module ProfileFields
class AddBrandingFields
include FieldDefinition
group "Branding" do
field "Brand color 1",
:color_field,
placeholder: "#000000",
description: "Used for backgrounds, borders etc.",
display_area: "settings_only"
field "Brand color 2",
:color_field,
placeholder: "#000000",
description: "Used for texts (usually put on Brand color 1).",
display_area: "settings_only"
end
end
end

View file

@ -1,19 +0,0 @@
module ProfileFields
class AddLinkFields
include FieldDefinition
group "Links" do
field "Facebook URL", :text_field, placeholder: "https://facebook.com/...", display_area: "header"
field "Youtube URL", :text_field, placeholder: "https://www.youtube.com/channel/...", display_area: "header"
field "StackOverflow URL", :text_field, placeholder: "https://stackoverflow.com/users/...", display_area: "header"
field "LinkedIn URL", :text_field, placeholder: "https://www.linkedin.com/in/...", display_area: "header"
field "Behance URL", :text_field, placeholder: "https://www.behance.net/...", display_area: "header"
field "Dribbble URL", :text_field, placeholder: "https://dribbble.com/...", display_area: "header"
field "Medium URL", :text_field, placeholder: "https://medium.com/@...", display_area: "header"
field "GitLab URL", :text_field, placeholder: "https://gitlab.com/...", display_area: "header"
field "Instagram URL", :text_field, placeholder: "https://www.instagram.com/...", display_area: "header"
field "Mastodon URL", :text_field, placeholder: "https://...", display_area: "header"
field "Twitch URL", :text_field, placeholder: "https://www.twitch.tv/...", display_area: "header"
end
end
end

View file

@ -1,12 +0,0 @@
module ProfileFields
class AddWorkFields
include FieldDefinition
group "Work" do
field "Education", :text_field, display_area: "header"
field "Employer name", :text_field, placeholder: "Acme Inc.", display_area: "header"
field "Employer URL", :text_field, placeholder: "https://dev.com", display_area: "settings_only"
field "Employment title", :text_field, placeholder: "Junior Frontend Engineer", display_area: "header"
end
end
end

View file

@ -1,41 +0,0 @@
module ProfileFields
# This module defines a tiny DSL for declarative profile field seeders.
module FieldDefinition
extend ActiveSupport::Concern
class_methods do
def call
new.add_fields
end
def group(name = nil)
@group = ProfileFieldGroup.find_or_create_by(name: name)
yield if block_given?
@group = nil
end
def fields
@fields ||= []
end
private
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: 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
def add_fields
self.class.fields.each { |field| ProfileField.find_or_create_by(field) }
end
end
end

View file

@ -5,6 +5,9 @@ namespace :app_initializer do
system("bin/rails db:prepare") || exit!(1)
Rake::Task["db:migrate"].execute # it'll re-alphabetize the columns in `schema.rb`
puts "\n== Performing setup tasks =="
Rake::Task["forem:setup"].execute
puts "\n== Updating Data =="
Rake::Task["data_updates:enqueue_data_update_worker"].execute

View file

@ -1,8 +1,10 @@
namespace :forem do
desc "Performs basic setup for new Forem instances"
# Since we execute this tasks in bin/setup as well as app_initializer:setup
# everything happening here needs to be idempotent.
task setup: :environment do
puts "\n== Setting up profile fields =="
ProfileFields::AddBaseFields.call
# NOTE: There are currently no tasks here. This will change as soon as we
# add/update the task for seeding navigation links to support RFC #237.
end
task health_check_token: :environment do

View file

@ -1,27 +0,0 @@
require "rails_helper"
RSpec.describe ProfileFields::FieldDefinition, type: :service do
let(:test_class) do
Class.new do
include ProfileFields::FieldDefinition
group "DSL Test" do
field "Test 1", :text_area, placeholder: "Test", description: "For testing"
field "Test 2", :check_box
end
end
end
context "when adding fields" do
it "creates all the profile fields in the DB", :aggregate_failures do
expect do
test_class.call
end.to change(ProfileField, :count).by(2)
labels = ProfileField.pluck(:label)
expect(labels).to include("Test 1")
expect(labels).to include("Test 2")
group = ProfileFieldGroup.find_by(name: "DSL Test")
expect(ProfileField.pluck(:profile_field_group_id).count(group.id)).to eq(2)
end
end
end