* 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>
106 lines
3.3 KiB
Ruby
106 lines
3.3 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe "Users", type: :request do
|
|
describe "GET /users" do
|
|
let(:user) { create(:user, username: "Sloan") }
|
|
let!(:suggested_users_list) { %w[eeyore] }
|
|
let!(:suggested_user_profile) do
|
|
create(
|
|
:profile,
|
|
user: create(:user, :without_profile, username: "eeyore", name: "Eeyore"),
|
|
summary: "I am always sad",
|
|
)
|
|
end
|
|
let!(:suggested_user) { suggested_user_profile.user }
|
|
|
|
before do
|
|
allow(SiteConfig).to receive(:suggested_users).and_return(suggested_users_list)
|
|
end
|
|
|
|
context "when no state params are present" do
|
|
it "returns no users" do
|
|
sign_in user
|
|
get users_path
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
expect(response.parsed_body).to be_empty
|
|
end
|
|
end
|
|
|
|
context "when follow_suggestions params are present and no suggestions are found" do
|
|
it "returns the default suggested_users from SiteConfig if they are present" do
|
|
sign_in user
|
|
|
|
get users_path(state: "follow_suggestions")
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
expect(response.parsed_body.first).to include(
|
|
"id" => suggested_user.id,
|
|
"name" => suggested_user.name,
|
|
"username" => suggested_user.username,
|
|
"summary" => suggested_user.summary,
|
|
"profile_image_url" => Images::Profile.call(suggested_user.profile_image_url, length: 90),
|
|
"following" => false,
|
|
)
|
|
end
|
|
end
|
|
|
|
context "when follow_suggestions params are present" do
|
|
let(:user) { create(:user) }
|
|
let(:tag) { create(:tag) }
|
|
let(:other_user) { create(:user) }
|
|
|
|
before do
|
|
# Prepare auto-generated user suggestions
|
|
user.follow(tag)
|
|
create(:article, user: other_user, tags: [tag.name])
|
|
end
|
|
|
|
it "returns follow suggestions for an authenticated user" do
|
|
sign_in user
|
|
|
|
get users_path(state: "follow_suggestions")
|
|
|
|
response_user = response.parsed_body.first
|
|
expect(response_user["id"]).to eq(other_user.id)
|
|
end
|
|
|
|
it "returns follow suggestions that have profile images" do
|
|
sign_in user
|
|
|
|
get users_path(state: "follow_suggestions")
|
|
|
|
response_user = response.parsed_body.first
|
|
expect(response_user["profile_image_url"]).to eq(other_user.profile_image_url)
|
|
end
|
|
|
|
it "returns the default suggested_users from SiteConfig if prefer_manual_suggested_users is true" do
|
|
allow(SiteConfig).to receive(:prefer_manual_suggested_users).and_return(true)
|
|
|
|
sign_in user
|
|
|
|
get users_path(state: "follow_suggestions")
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
expect(response.parsed_body.first).to include(
|
|
"id" => suggested_user.id,
|
|
"name" => suggested_user.name,
|
|
"username" => suggested_user.username,
|
|
"summary" => suggested_user.summary,
|
|
"profile_image_url" => Images::Profile.call(suggested_user.profile_image_url, length: 90),
|
|
"following" => false,
|
|
)
|
|
end
|
|
end
|
|
|
|
context "when sidebar_suggestions params are present" do
|
|
it "returns no sidebar suggestions for an authenticated user" do
|
|
sign_in create(:user)
|
|
|
|
get users_path(state: "sidebar_suggestions")
|
|
|
|
expect(response.parsed_body).to be_empty
|
|
end
|
|
end
|
|
end
|
|
end
|