Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/site/developers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def show
@profile = Developers::Profile.find_by!(handle: params[:handle].to_s.downcase)
raise ActiveRecord::RecordNotFound unless @profile.visible_to?(current_user)

@experiences = @profile.experiences
@experiences = @profile.experiences.includes(profile_skills: :skill)
@profile_skills = @profile.profile_skills.includes(:skill).sort_by { |ps| [-ps.endorsements_count, -(ps.years || 0), ps.skill.name] }
@own = current_user && @profile.user_id == current_user.id
# Gigs and jobs they've posted as themselves.
Expand Down
10 changes: 10 additions & 0 deletions app/views/site/developers/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@
<p class="font-semibold"><%= experience.title %></p>
<p class="text-sm text-[#555]"><%= [experience.company_name, experience.location.presence].compact.join(" · ") %></p>
<p class="text-xs text-[#6b6b6b]"><%= experience.started_on.strftime("%b %Y") %> – <%= experience.ended_on&.strftime("%b %Y") || "Present" %></p>
<% if experience.profile_skills.any? %>
<ul class="experience-skills mt-2 flex flex-wrap gap-1.5" aria-label="Skills used in <%= experience.to_label %>">
<% experience.profile_skills.sort_by { |profile_skill| profile_skill.skill.name }.each do |profile_skill| %>
<li>
<%= link_to profile_skill.skill.name, developers_directory_path(skill: profile_skill.skill.slug),
class: "inline-flex rounded-full border border-[#111] bg-[#f5f2e8] px-2 py-0.5 text-xs font-medium hover:bg-[#f5e642]" %>
</li>
<% end %>
</ul>
<% end %>
<% if experience.description.present? %><div class="prose prose-sm mt-2 max-w-none"><%= render_markdown(experience.description) %></div><% end %>
</li>
<% end %>
Expand Down
13 changes: 12 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ class ExperienceDefinition < Developers::ResourceDefinition
input :title, placeholder: "e.g. Senior Backend Engineer"
input :company_name, label: "Company"
input :location, placeholder: "e.g. Accra, Ghana or Remote"
input :profile_skills, as: :secure_association,
label: "Skills used",
hint: "Choose skills already listed on your profile.",
choices: ->(form) { form.view_context.current_scoped_entity.profile_skills.includes(:skill).order("skills.name") },
wrapper: {class: "col-span-full"}
input :ended_on, hint: "Leave blank if this is your current role"
field :started_on, label: "Started"
field :ended_on, label: "Ended"
Expand All @@ -22,13 +27,15 @@ class ExperienceDefinition < Developers::ResourceDefinition
form_layout do
section :role, :title, :company_name, :location, columns: 2, label: "Role"
section :dates, :started_on, :ended_on, columns: 2, label: "Dates"
section :skills, :profile_skills, label: "Skills used"
section :details, :description, label: "What you did"
ungrouped label: "Other"
end

display_layout do
section :role, :title, :company_name, :location, label: "Role"
section :dates, :started_on, :ended_on, label: "Dates"
section :skills, :profile_skills, label: "Skills used"
section :details, :description, label: "What you did"
ungrouped label: "Other"
end
Expand Down
2 changes: 2 additions & 0 deletions packages/developers/app/models/developers/experience.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class Developers::Experience < Developers::ResourceRecord

# add has_one associations above.

has_many :experience_skills, class_name: "Developers::ExperienceSkill", inverse_of: :experience, dependent: :delete_all
has_many :profile_skills, through: :experience_skills
# add has_many associations above.

# add attachments above.
Expand Down
38 changes: 38 additions & 0 deletions packages/developers/app/models/developers/experience_skill.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# == Schema Information
#
# Table name: developers_experience_skills
#
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# experience_id :integer not null
# profile_skill_id :integer not null
#
# Indexes
#
# idx_on_experience_id_profile_skill_id_491a95c723 (experience_id,profile_skill_id) UNIQUE
# index_developers_experience_skills_on_profile_skill_id (profile_skill_id)
#
# Foreign Keys
#
# experience_id (experience_id => developers_experiences.id) ON DELETE => cascade
# profile_skill_id (profile_skill_id => developers_profile_skills.id) ON DELETE => cascade
#
require_relative "../developers"

class Developers::ExperienceSkill < Developers::ResourceRecord
belongs_to :experience, class_name: "Developers::Experience", inverse_of: :experience_skills
belongs_to :profile_skill, class_name: "Developers::ProfileSkill", inverse_of: :experience_skills

validates :profile_skill, uniqueness: {scope: :experience_id}
validate :profile_skill_belongs_to_experience_profile

private

def profile_skill_belongs_to_experience_profile
return if experience.nil? || profile_skill.nil?
return if experience.profile_id == profile_skill.profile_id

errors.add(:profile_skill, "must belong to the same profile as the experience")
end
end
2 changes: 2 additions & 0 deletions packages/developers/app/models/developers/profile_skill.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class Developers::ProfileSkill < Developers::ResourceRecord

# add has_one associations above.

has_many :experience_skills, class_name: "Developers::ExperienceSkill", inverse_of: :profile_skill, dependent: :delete_all
has_many :experiences, through: :experience_skills
has_many :endorsements, class_name: "Network::Endorsement", dependent: :delete_all
has_many :endorsers, through: :endorsements
# add has_many associations above.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def update? = true
def destroy? = true

def permitted_attributes_for_create
%i[title company_name location started_on ended_on description]
%i[title company_name location started_on ended_on description profile_skills]
end

def permitted_attributes_for_read
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CreateDevelopersExperienceSkills < ActiveRecord::Migration[8.1]
def change
create_table :developers_experience_skills do |t|
t.belongs_to :experience, null: false, index: false,
foreign_key: {to_table: :developers_experiences, on_delete: :cascade}
t.belongs_to :profile_skill, null: false,
foreign_key: {to_table: :developers_profile_skills, on_delete: :cascade}

t.timestamps

t.index [:experience_id, :profile_skill_id], unique: true
end
end
end
25 changes: 25 additions & 0 deletions test/integration/developer_portal_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,31 @@ class DeveloperPortalTest < ActionDispatch::IntegrationTest
assert_not_includes response.body, "US Navy"
end

test "links experience to skills from the owner's profile only" do
ruby = @profile.profile_skills.create!(skill: Skill.create!(name: "Ruby"))
elixir = @profile.profile_skills.create!(skill: Skill.create!(name: "Elixir"))
other_skill = @other.profile_skills.create!(skill: Skill.create!(name: "COBOL"))

get "/developer/ada/developers/experiences/new"
assert_response :success
assert_includes response.body, "Ruby"
assert_includes response.body, "Elixir"
assert_not_includes response.body, "COBOL"

post "/developer/ada/developers/experiences", params: {developers_experience: {
title: "Analyst", company_name: "Analytical Engines", started_on: "1842-01-01",
profile_skills: [ruby.to_signed_global_id.to_s, other_skill.to_signed_global_id.to_s]
}}
experience = @profile.experiences.find_by!(title: "Analyst")
assert_equal [ruby], experience.profile_skills.to_a

patch "/developer/ada/developers/experiences/#{experience.id}", params: {developers_experience: {
profile_skills: [elixir.to_signed_global_id.to_s]
}}
assert_response :redirect
assert_equal [elixir], experience.profile_skills.reload
end

test "adds skills from the shared taxonomy" do
skill = Skill.create!(name: "Ruby")

Expand Down
11 changes: 11 additions & 0 deletions test/integration/public_site_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ class PublicSiteTest < ActionDispatch::IntegrationTest
assert_not_includes response.body, "<script>alert(1)</script>"
end

test "experience entries show the profile skills used there" do
experience = @public.experiences.create!(title: "Engineer", company_name: "Acme", started_on: Date.new(2020, 1, 1))
experience.profile_skills << @public.profile_skills.sole

get "/@pat"

assert_select ".experience-skills[aria-label=?]", "Skills used in Engineer at Acme" do
assert_select "a[href=?]", "/devs?skill=elixir", text: "Elixir"
end
end

test "guests see only public, active jobs" do
get "/jobs"
assert_response :success
Expand Down
30 changes: 30 additions & 0 deletions test/models/developers/experience_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,34 @@ class Developers::ExperienceTest < ActiveSupport::TestCase
assert_not experience.valid?
assert experience.errors[:ended_on].any?
end

test "links only profile skills belonging to the same profile" do
profile = create_profile!
experience = profile.experiences.create!(title: "Developer", company_name: "Acme", started_on: Date.new(2020, 1, 1))
own_profile_skill = profile.profile_skills.create!(skill: Skill.create!(name: "Ruby"))
other_profile_skill = create_profile!.profile_skills.create!(skill: Skill.create!(name: "Elixir"))

experience.profile_skills << own_profile_skill
assert_equal [own_profile_skill], experience.profile_skills.reload

link = experience.experience_skills.new(profile_skill: other_profile_skill)
assert_not link.valid?
assert_includes link.errors[:profile_skill], "must belong to the same profile as the experience"
end

test "removing an experience or profile skill removes its links" do
profile = create_profile!
first_experience = profile.experiences.create!(title: "Developer", company_name: "Acme", started_on: Date.new(2020, 1, 1))
second_experience = profile.experiences.create!(title: "Lead", company_name: "Beta", started_on: Date.new(2022, 1, 1))
first_profile_skill = profile.profile_skills.create!(skill: Skill.create!(name: "Ruby"))
second_profile_skill = profile.profile_skills.create!(skill: Skill.create!(name: "Rails"))
first_link = first_experience.experience_skills.create!(profile_skill: first_profile_skill)
second_link = second_experience.experience_skills.create!(profile_skill: second_profile_skill)

first_experience.destroy!
assert_not Developers::ExperienceSkill.exists?(first_link.id)

second_profile_skill.destroy!
assert_not Developers::ExperienceSkill.exists?(second_link.id)
end
end
Loading