* Prepare to drop profile columns from user * Update code and factory * Also remove unused constant * Move validation from user to profile * Remove Profiles::ExtractData service object * Add more comments * Simplify sameAs attribute generation * Obey me machine, I am your master * Fix condition order in guard clause * Temporarily disable callback * Fix specs * Reduce usage of Profile#refresh_attributes! * Remove leftover comment * Handle social media links differently * More spec fixes * Fix specs for admin profile fields controller * Fix specs after merge * Fix remaining specs * Update user show request spec * Add comment for follow_hiring_tag * Only save profile when user is valid * Fix seeds.rb for profile fields * Switch from before_save to after_save * Undo unrelated formattin change * Update spec/fixtures/files/profile_fields.csv Co-authored-by: Molly Struve <mollylbs@gmail.com> * Remove data update script and spec * Fix spec * Fix typo in comment * Fix typo in comment * Move article resave logic to service object * Move profile field creation to before(:suite) * Refactor error handling in Profiles::Update * Fix Profiles::Update specs and refactor * Temporarily disable spec * Add ProfileValidator * Clean up * Move DB ready check into app/lib * Refresh attributes after importing from CSV * Fix specs * Remove unused file * A girl has no name. A profile neither. * Fix specs * Add responds_to? check * Spec fix * Add name to user fields in profile settings page Co-authored-by: Molly Struve <mollylbs@gmail.com>
107 lines
2.9 KiB
Ruby
107 lines
2.9 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe "UserShow", type: :request do
|
|
let!(:profile) do
|
|
create(
|
|
:profile,
|
|
:with_DEV_info,
|
|
user: create(:user, :without_profile),
|
|
display_email_on_profile: true,
|
|
)
|
|
end
|
|
let(:user) { profile.user }
|
|
|
|
describe "GET /:slug (user)" do
|
|
it "returns a 200 status when navigating to the user's page" do
|
|
get user.path
|
|
expect(response).to have_http_status(:ok)
|
|
end
|
|
|
|
# rubocop:disable RSpec/ExampleLength
|
|
it "renders the proper JSON-LD for a user" do
|
|
get user.path
|
|
text = Nokogiri::HTML(response.body).at('script[type="application/ld+json"]').text
|
|
response_json = JSON.parse(text)
|
|
expect(response_json).to include(
|
|
"@context" => "http://schema.org",
|
|
"@type" => "Person",
|
|
"mainEntityOfPage" => {
|
|
"@type" => "WebPage",
|
|
"@id" => URL.user(user)
|
|
},
|
|
"url" => URL.user(user),
|
|
"sameAs" => [
|
|
"https://twitter.com/#{user.twitter_username}",
|
|
"https://github.com/#{user.github_username}",
|
|
"http://example.com",
|
|
],
|
|
"image" => Images::Profile.call(user.profile_image_url, length: 320),
|
|
"name" => user.name,
|
|
"email" => user.email,
|
|
"jobTitle" => user.employment_title,
|
|
"description" => user.summary,
|
|
"disambiguatingDescription" => [
|
|
user.mostly_work_with,
|
|
user.currently_hacking_on,
|
|
user.currently_learning,
|
|
],
|
|
"worksFor" => [
|
|
{
|
|
"@type" => "Organization",
|
|
"name" => user.employer_name,
|
|
"url" => user.employer_url
|
|
},
|
|
],
|
|
"alumniOf" => user.education,
|
|
)
|
|
end
|
|
# rubocop:enable RSpec/ExampleLength
|
|
|
|
it "does not render a key if no value is given" do
|
|
incomplete_user = create(:user)
|
|
get incomplete_user.path
|
|
text = Nokogiri::HTML(response.body).at('script[type="application/ld+json"]').text
|
|
response_json = JSON.parse(text)
|
|
expect(response_json).not_to include("worksFor")
|
|
expect(response_json.value?(nil)).to be(false)
|
|
expect(response_json.value?("")).to be(false)
|
|
end
|
|
end
|
|
|
|
context "when user signed in" do
|
|
before do
|
|
sign_in user
|
|
get user.path
|
|
end
|
|
|
|
describe "GET /:slug (user)" do
|
|
it "does not render json ld" do
|
|
expect(response.body).not_to include "application/ld+json"
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when user not signed in" do
|
|
before do
|
|
get user.path
|
|
end
|
|
|
|
describe "GET /:slug (user)" do
|
|
it "does not render json ld" do
|
|
expect(response.body).to include "application/ld+json"
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when user not signed in but internal nav triggered" do
|
|
before do
|
|
get "#{user.path}?i=i"
|
|
end
|
|
|
|
describe "GET /:slug (user)" do
|
|
it "does not render json ld" do
|
|
expect(response.body).not_to include "application/ld+json"
|
|
end
|
|
end
|
|
end
|
|
end
|