* Remove hardcoded instances of education field * WIP Access display_email_on_profile via User Settings * Remove unused profile column * WIP Fix reference to bg_color_hex and text_color_hex * WIP fix issues revealed by systems specs * WIP fix issues revealed by services specs * WIP Fix failing tests * WIP Fix spec failures * wip * Move two attributes from controller to decorator * Update comment * Match user settings changes * More consistently use user.tag_line Even before the profile changes we sometimes used the user.summary attribute directly but used the user.tag_line method in other places. * Remove delegation, rename inline concern * Drop profile columns from users table * Remove duplicated work display from header * Update work profile field handling * Update DUS + spec * Delegate more carefully * Update delegation guard * Adapt for removed delegation * Undo accidental schema changes * Fix seeds * Remove accidentaly change * Fix User#processed_website_url * Update guard clause * Update profile card content * Add Organization#profile * Be more conservative with profile fields * Spec fixes round 1 * Fix typo * Update spec * Limit number of header fields and update card content * Decorate correct model * Update factory * Update schema.rb * Fix validation * How bad could this possibly be? * Pretty bad, nevermind * Remove obsolete code * Reset profile fields during test runs * Move profile fields back to before(:suite) * Spec fixes * Remove accidentally re-added files * More spec fixes * Specs * Change User#tag_keywords_for_search * More spec fixes * Add comment * Undo accidental schema changes * Attempt spec fix * Remove fix attempt * Fix e2e test * Update spec * Remove guard clause * Remove hardcoded instances of education field * WIP Access display_email_on_profile via User Settings * Remove unused profile column * WIP fix issues revealed by systems specs * WIP fix issues revealed by services specs * WIP Fix failing tests * WIP Fix spec failures * wip * Move two attributes from controller to decorator * Update comment * More consistently use user.tag_line Even before the profile changes we sometimes used the user.summary attribute directly but used the user.tag_line method in other places. * Remove education * Add comment * WIP * Clean up mostly_work_with * WIP * Update work profile field handling * More work-related changes * Remove settings_only from display_area enum * Remove quickfix from _metadata partial * Remove special attributes * Remove leftover spec * Retrieve location from profile, not user * Profile.special_attributes no longer exists * Update specs * More spec fixes * Update UsersController * Update UsersController and spec * Fix e2e seeds * Minor cleanup * More e2e seed fixes * Fix profile field CSV * Fix e2e seeds * Move one more attribute in e2e seeds * Remove duplicate line * Clear inputs before typing in them * Fix formatting issues * Profiles::Update -> Users::Update * Remove RegistrationsController#resolve_profile_field_issues * Fix schema.rb * More cleanup * Fix specs * Fix remaining spec Co-authored-by: Jacob Herrington <jacobherringtondeveloper@gmail.com>
121 lines
4.3 KiB
Ruby
121 lines
4.3 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe Users::Update, type: :service do
|
|
def sidekiq_assert_resave_article_worker(user, &block)
|
|
sidekiq_assert_enqueued_with(
|
|
job: Users::ResaveArticlesWorker,
|
|
args: [user.id],
|
|
queue: "medium_priority",
|
|
&block
|
|
)
|
|
end
|
|
|
|
let(:profile) do
|
|
create(:profile, data: { education: "maybe", removed: "Bla" })
|
|
end
|
|
let(:user) { profile.user }
|
|
|
|
it "correctly typecasts new attributes", :aggregate_failures do
|
|
described_class.call(user, profile: { location: 123 })
|
|
expect(user.profile.location).to eq "123"
|
|
end
|
|
|
|
it "removes old attributes from the profile" do
|
|
expect do
|
|
described_class.call(user, profile: {})
|
|
end.to change { profile.data.key?("removed") }.to(false)
|
|
end
|
|
|
|
it "propagates changes to user", :agregate_failures do
|
|
new_name = "Sloan Doe"
|
|
described_class.call(user, profile: {}, user: { name: new_name })
|
|
expect(profile.user.name).to eq new_name
|
|
end
|
|
|
|
it "updates the profile_updated_at column" do
|
|
expect do
|
|
described_class.call(user, profile: { education: "false" })
|
|
end.to change { user.reload.profile_updated_at }
|
|
end
|
|
|
|
it "returns an error if Profile image is too large" do
|
|
profile_image = fixture_file_upload("large_profile_img.jpg", "image/jpeg")
|
|
service = described_class.call(user, profile: {}, user: { profile_image: profile_image })
|
|
|
|
expect(service.success?).to be false
|
|
expect(service.errors_as_sentence).to eq "Profile image File size should be less than 2 MB"
|
|
end
|
|
|
|
it "returns an error if Profile image is not a file" do
|
|
profile_image = "A String"
|
|
service = described_class.call(user, profile: {}, user: { profile_image: profile_image })
|
|
|
|
expect(service.success?).to be false
|
|
expect(service.errors_as_sentence).to eq "invalid file type. Please upload a valid image."
|
|
end
|
|
|
|
it "returns an error if Profile image file name is too long" do
|
|
profile_image = fixture_file_upload("800x600.png", "image/png")
|
|
allow(profile_image).to receive(:original_filename).and_return("#{'a_very_long_filename' * 15}.png")
|
|
service = described_class.call(user, profile: {}, user: { profile_image: profile_image })
|
|
|
|
expect(service.success?).to be false
|
|
expect(service.errors_as_sentence).to eq "filename too long - the max is 250 characters."
|
|
end
|
|
|
|
context "when conditionally resaving articles" do
|
|
it "enqueues resave articles job when changing username" do
|
|
sidekiq_assert_resave_article_worker(user) do
|
|
described_class.call(user, user: { username: "#{user.username}_changed" })
|
|
end
|
|
end
|
|
|
|
it "enqueues resave articles job when changing profile_image" do
|
|
profile_image = fixture_file_upload("800x600.jpg")
|
|
|
|
sidekiq_assert_resave_article_worker(user) do
|
|
described_class.call(user, user: { profile_image: profile_image })
|
|
end
|
|
end
|
|
|
|
it "enqueues resave articles job when changing name" do
|
|
sidekiq_assert_resave_article_worker(user) do
|
|
described_class.call(user, user: { name: "#{user.name} changed" })
|
|
end
|
|
end
|
|
|
|
it "enqueues resave articles job when changing summary" do
|
|
sidekiq_assert_resave_article_worker(user) do
|
|
described_class.call(user, profile: { summary: "#{user.profile.summary} changed" })
|
|
end
|
|
end
|
|
|
|
it "enqueues resave articles job when changing bg_color_hex" do
|
|
sidekiq_assert_resave_article_worker(user) do
|
|
described_class.call(user, user_settings: { brand_color1: "#12345F" })
|
|
end
|
|
end
|
|
|
|
it "enqueues resave articles job when changing text_color_hex" do
|
|
sidekiq_assert_resave_article_worker(user) do
|
|
described_class.call(user, user_settings: { brand_color2: "#12345F" })
|
|
end
|
|
end
|
|
|
|
Authentication::Providers.username_fields.each do |username_field|
|
|
it "enqueues resave articles job when changing #{username_field}" do
|
|
sidekiq_assert_resave_article_worker(user) do
|
|
described_class.call(user, user: { username_field => "greatnewusername" })
|
|
end
|
|
end
|
|
|
|
it "doesn't enqueue resave articles job when changing #{username_field} for a suspended user" do
|
|
suspended_user = create(:user, :suspended)
|
|
|
|
expect do
|
|
described_class.call(suspended_user, user: { username_field => "greatnewusername" })
|
|
end.not_to change(Users::ResaveArticlesWorker.jobs, :size)
|
|
end
|
|
end
|
|
end
|
|
end
|