diff options
Diffstat (limited to 'spec/models/user_spec.rb')
-rw-r--r-- | spec/models/user_spec.rb | 257 |
1 files changed, 141 insertions, 116 deletions
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index ca4c38d4663..db805a804c8 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -79,6 +79,9 @@ RSpec.describe User do it { is_expected.to delegate_method(:bio).to(:user_detail).allow_nil } it { is_expected.to delegate_method(:bio=).to(:user_detail).with_arguments(:args).allow_nil } + + it { is_expected.to delegate_method(:registration_objective).to(:user_detail).allow_nil } + it { is_expected.to delegate_method(:registration_objective=).to(:user_detail).with_arguments(:args).allow_nil } end describe 'associations' do @@ -123,7 +126,7 @@ RSpec.describe User do it { is_expected.to have_many(:callouts).class_name('UserCallout') } it { is_expected.to have_many(:group_callouts).class_name('Users::GroupCallout') } - describe "#user_detail" do + describe '#user_detail' do it 'does not persist `user_detail` by default' do expect(create(:user).user_detail).not_to be_persisted end @@ -160,25 +163,25 @@ RSpec.describe User do end end - describe "#abuse_report" do + describe '#abuse_report' do let(:current_user) { create(:user) } let(:other_user) { create(:user) } it { is_expected.to have_one(:abuse_report) } - it "refers to the abuse report whose user_id is the current user" do + it 'refers to the abuse report whose user_id is the current user' do abuse_report = create(:abuse_report, reporter: other_user, user: current_user) expect(current_user.abuse_report).to eq(abuse_report) end - it "does not refer to the abuse report whose reporter_id is the current user" do + it 'does not refer to the abuse report whose reporter_id is the current user' do create(:abuse_report, reporter: current_user, user: other_user) expect(current_user.abuse_report).to be_nil end - it "does not update the user_id of an abuse report when the user is updated" do + it 'does not update the user_id of an abuse report when the user is updated' do abuse_report = create(:abuse_report, reporter: current_user, user: other_user) current_user.block @@ -343,8 +346,9 @@ RSpec.describe User do it 'falls back to english when I18n.default_locale is not an available language' do I18n.default_locale = :kl + default_preferred_language = user.send(:default_preferred_language) - expect(user.preferred_language).to eq 'en' + expect(user.preferred_language).to eq default_preferred_language end end end @@ -374,7 +378,7 @@ RSpec.describe User do end context 'when username is changed' do - let(:user) { build_stubbed(:user, username: 'old_path', namespace: build_stubbed(:namespace)) } + let(:user) { build_stubbed(:user, username: 'old_path', namespace: build_stubbed(:user_namespace)) } it 'validates move_dir is allowed for the namespace' do expect(user.namespace).to receive(:any_project_has_container_registry_tags?).and_return(true) @@ -401,7 +405,7 @@ RSpec.describe User do user = build(:user, username: "test.#{type}") expect(user).not_to be_valid - expect(user.errors.full_messages).to include('Username ending with a file extension is not allowed.') + expect(user.errors.full_messages).to include('Username ending with a reserved file extension is not allowed.') expect(build(:user, username: "test#{type}")).to be_valid end end @@ -490,6 +494,8 @@ RSpec.describe User do end describe 'email' do + let(:expected_error) { _('is not allowed for sign-up. Check with your administrator.') } + context 'when no signup domains allowed' do before do stub_application_setting(domain_allowlist: []) @@ -533,7 +539,7 @@ RSpec.describe User do it 'rejects example@test.com' do user = build(:user, email: "example@test.com") expect(user).to be_invalid - expect(user.errors.messages[:email].first).to eq(_('domain is not authorized for sign-up.')) + expect(user.errors.messages[:email].first).to eq(expected_error) end end @@ -550,13 +556,13 @@ RSpec.describe User do it 'rejects info@test.example.com' do user = build(:user, email: "info@test.example.com") expect(user).to be_invalid - expect(user.errors.messages[:email].first).to eq(_('domain is not authorized for sign-up.')) + expect(user.errors.messages[:email].first).to eq(expected_error) end it 'rejects example@test.com' do user = build(:user, email: "example@test.com") expect(user).to be_invalid - expect(user.errors.messages[:email].first).to eq(_('domain is not authorized for sign-up.')) + expect(user.errors.messages[:email].first).to eq(expected_error) end it 'accepts example@test.com when added by another user' do @@ -594,7 +600,7 @@ RSpec.describe User do it 'rejects info@example.com' do user = build(:user, email: 'info@example.com') expect(user).not_to be_valid - expect(user.errors.messages[:email].first).to eq(_('is not from an allowed domain.')) + expect(user.errors.messages[:email].first).to eq(expected_error) end it 'accepts info@example.com when added by another user' do @@ -628,7 +634,7 @@ RSpec.describe User do it 'rejects info@example.com' do user = build(:user, email: 'info@example.com') expect(user).not_to be_valid - expect(user.errors.messages[:email].first).to eq(_('domain is not authorized for sign-up.')) + expect(user.errors.messages[:email].first).to eq(expected_error) end end end @@ -669,7 +675,7 @@ RSpec.describe User do user = build(:user, email: 'info@gitlab.com') expect(user).not_to be_valid - expect(user.errors.messages[:email].first).to eq(_('is not allowed. Try again with a different email address, or contact your GitLab admin.')) + expect(user.errors.messages[:email].first).to eq(expected_error) end it 'does accept a valid email address' do @@ -715,7 +721,7 @@ RSpec.describe User do end end - describe "scopes" do + describe 'scopes' do context 'blocked users' do let_it_be(:active_user) { create(:user) } let_it_be(:blocked_user) { create(:user, :blocked) } @@ -753,8 +759,8 @@ RSpec.describe User do end end - describe ".with_two_factor" do - it "returns users with 2fa enabled via OTP" do + describe '.with_two_factor' do + it 'returns users with 2fa enabled via OTP' do user_with_2fa = create(:user, :two_factor_via_otp) user_without_2fa = create(:user) users_with_two_factor = described_class.with_two_factor.pluck(:id) @@ -763,8 +769,8 @@ RSpec.describe User do expect(users_with_two_factor).not_to include(user_without_2fa.id) end - shared_examples "returns the right users" do |trait| - it "returns users with 2fa enabled via hardware token" do + shared_examples 'returns the right users' do |trait| + it 'returns users with 2fa enabled via hardware token' do user_with_2fa = create(:user, trait) user_without_2fa = create(:user) users_with_two_factor = described_class.with_two_factor.pluck(:id) @@ -773,7 +779,7 @@ RSpec.describe User do expect(users_with_two_factor).not_to include(user_without_2fa.id) end - it "returns users with 2fa enabled via OTP and hardware token" do + it 'returns users with 2fa enabled via OTP and hardware token' do user_with_2fa = create(:user, :two_factor_via_otp, trait) user_without_2fa = create(:user) users_with_two_factor = described_class.with_two_factor.pluck(:id) @@ -791,17 +797,17 @@ RSpec.describe User do end end - describe "and U2F" do + describe 'and U2F' do it_behaves_like "returns the right users", :two_factor_via_u2f end - describe "and WebAuthn" do + describe 'and WebAuthn' do it_behaves_like "returns the right users", :two_factor_via_webauthn end end - describe ".without_two_factor" do - it "excludes users with 2fa enabled via OTP" do + describe '.without_two_factor' do + it 'excludes users with 2fa enabled via OTP' do user_with_2fa = create(:user, :two_factor_via_otp) user_without_2fa = create(:user) users_without_two_factor = described_class.without_two_factor.pluck(:id) @@ -810,8 +816,8 @@ RSpec.describe User do expect(users_without_two_factor).not_to include(user_with_2fa.id) end - describe "and u2f" do - it "excludes users with 2fa enabled via U2F" do + describe 'and u2f' do + it 'excludes users with 2fa enabled via U2F' do user_with_2fa = create(:user, :two_factor_via_u2f) user_without_2fa = create(:user) users_without_two_factor = described_class.without_two_factor.pluck(:id) @@ -820,7 +826,7 @@ RSpec.describe User do expect(users_without_two_factor).not_to include(user_with_2fa.id) end - it "excludes users with 2fa enabled via OTP and U2F" do + it 'excludes users with 2fa enabled via OTP and U2F' do user_with_2fa = create(:user, :two_factor_via_otp, :two_factor_via_u2f) user_without_2fa = create(:user) users_without_two_factor = described_class.without_two_factor.pluck(:id) @@ -830,8 +836,8 @@ RSpec.describe User do end end - describe "and webauthn" do - it "excludes users with 2fa enabled via WebAuthn" do + describe 'and webauthn' do + it 'excludes users with 2fa enabled via WebAuthn' do user_with_2fa = create(:user, :two_factor_via_webauthn) user_without_2fa = create(:user) users_without_two_factor = described_class.without_two_factor.pluck(:id) @@ -840,7 +846,7 @@ RSpec.describe User do expect(users_without_two_factor).not_to include(user_with_2fa.id) end - it "excludes users with 2fa enabled via OTP and WebAuthn" do + it 'excludes users with 2fa enabled via OTP and WebAuthn' do user_with_2fa = create(:user, :two_factor_via_otp, :two_factor_via_webauthn) user_without_2fa = create(:user) users_without_two_factor = described_class.without_two_factor.pluck(:id) @@ -1073,7 +1079,7 @@ RSpec.describe User do end end - describe "Respond to" do + describe 'Respond to' do it { is_expected.to respond_to(:admin?) } it { is_expected.to respond_to(:name) } it { is_expected.to respond_to(:external?) } @@ -1095,7 +1101,7 @@ RSpec.describe User do let(:user) { create(:user) } let(:external_user) { create(:user, external: true) } - it "sets other properties as well" do + it 'sets other properties as well' do expect(external_user.can_create_team).to be_falsey expect(external_user.can_create_group).to be_falsey expect(external_user.projects_limit).to be 0 @@ -1514,7 +1520,7 @@ RSpec.describe User do end describe '#generate_password' do - it "does not generate password by default" do + it 'does not generate password by default' do user = create(:user, password: 'abcdefghe') expect(user.password).to eq('abcdefghe') @@ -1882,14 +1888,14 @@ RSpec.describe User do describe 'deactivating a user' do let(:user) { create(:user, name: 'John Smith') } - context "an active user" do - it "can be deactivated" do + context 'an active user' do + it 'can be deactivated' do user.deactivate expect(user.deactivated?).to be_truthy end - context "when user deactivation emails are disabled" do + context 'when user deactivation emails are disabled' do before do stub_application_setting(user_deactivation_emails_enabled: false) end @@ -1900,7 +1906,7 @@ RSpec.describe User do end end - context "when user deactivation emails are enabled" do + context 'when user deactivation emails are enabled' do it 'sends deactivated user an email' do expect_next_instance_of(NotificationService) do |notification| allow(notification).to receive(:user_deactivated).with(user.name, user.notification_email_or_default) @@ -1911,12 +1917,12 @@ RSpec.describe User do end end - context "a user who is blocked" do + context 'a user who is blocked' do before do user.block end - it "cannot be deactivated" do + it 'cannot be deactivated' do user.deactivate expect(user.reload.deactivated?).to be_falsy @@ -2083,7 +2089,7 @@ RSpec.describe User do describe 'with defaults' do let(:user) { described_class.new } - it "applies defaults to user" do + it 'applies defaults to user' do expect(user.projects_limit).to eq(Gitlab.config.gitlab.default_projects_limit) expect(user.can_create_group).to eq(Gitlab.config.gitlab.default_can_create_group) expect(user.theme_id).to eq(Gitlab.config.gitlab.default_theme) @@ -2095,7 +2101,7 @@ RSpec.describe User do describe 'with default overrides' do let(:user) { described_class.new(projects_limit: 123, can_create_group: false, can_create_team: true) } - it "applies defaults to user" do + it 'applies defaults to user' do expect(user.projects_limit).to eq(123) expect(user.can_create_group).to be_falsey expect(user.theme_id).to eq(1) @@ -2114,7 +2120,7 @@ RSpec.describe User do stub_application_setting(user_default_external: true) end - it "creates external user by default" do + it 'creates external user by default' do user = create(:user) expect(user.external).to be_truthy @@ -2123,7 +2129,7 @@ RSpec.describe User do end describe 'with default overrides' do - it "creates a non-external user" do + it 'creates a non-external user' do user = create(:user, external: false) expect(user.external).to be_falsey @@ -2139,7 +2145,7 @@ RSpec.describe User do } protocol_and_expectation.each do |protocol, expected| - it "has correct require_ssh_key?" do + it 'has correct require_ssh_key?' do stub_application_setting(enabled_git_access_protocol: protocol) user = build(:user) @@ -2542,71 +2548,79 @@ RSpec.describe User do end describe '.find_by_full_path' do - let!(:user) { create(:user) } + using RSpec::Parameterized::TableSyntax - context 'with a route matching the given path' do - let!(:route) { user.namespace.route } + # TODO: this `where/when` can be removed in issue https://gitlab.com/gitlab-org/gitlab/-/issues/341070 + # At that point we only need to check `user_namespace` + where(namespace_type: [:namespace, :user_namespace]) - it 'returns the user' do - expect(described_class.find_by_full_path(route.path)).to eq(user) - end + with_them do + let!(:user) { create(:user, namespace: create(namespace_type)) } - it 'is case-insensitive' do - expect(described_class.find_by_full_path(route.path.upcase)).to eq(user) - expect(described_class.find_by_full_path(route.path.downcase)).to eq(user) - end - end + context 'with a route matching the given path' do + let!(:route) { user.namespace.route } - context 'with a redirect route matching the given path' do - let!(:redirect_route) { user.namespace.redirect_routes.create!(path: 'foo') } + it 'returns the user' do + expect(described_class.find_by_full_path(route.path)).to eq(user) + end - context 'without the follow_redirects option' do - it 'returns nil' do - expect(described_class.find_by_full_path(redirect_route.path)).to eq(nil) + it 'is case-insensitive' do + expect(described_class.find_by_full_path(route.path.upcase)).to eq(user) + expect(described_class.find_by_full_path(route.path.downcase)).to eq(user) end end - context 'with the follow_redirects option set to true' do - it 'returns the user' do - expect(described_class.find_by_full_path(redirect_route.path, follow_redirects: true)).to eq(user) + context 'with a redirect route matching the given path' do + let!(:redirect_route) { user.namespace.redirect_routes.create!(path: 'foo') } + + context 'without the follow_redirects option' do + it 'returns nil' do + expect(described_class.find_by_full_path(redirect_route.path)).to eq(nil) + end end - it 'is case-insensitive' do - expect(described_class.find_by_full_path(redirect_route.path.upcase, follow_redirects: true)).to eq(user) - expect(described_class.find_by_full_path(redirect_route.path.downcase, follow_redirects: true)).to eq(user) + context 'with the follow_redirects option set to true' do + it 'returns the user' do + expect(described_class.find_by_full_path(redirect_route.path, follow_redirects: true)).to eq(user) + end + + it 'is case-insensitive' do + expect(described_class.find_by_full_path(redirect_route.path.upcase, follow_redirects: true)).to eq(user) + expect(described_class.find_by_full_path(redirect_route.path.downcase, follow_redirects: true)).to eq(user) + end end end - end - context 'without a route or a redirect route matching the given path' do - context 'without the follow_redirects option' do - it 'returns nil' do - expect(described_class.find_by_full_path('unknown')).to eq(nil) + context 'without a route or a redirect route matching the given path' do + context 'without the follow_redirects option' do + it 'returns nil' do + expect(described_class.find_by_full_path('unknown')).to eq(nil) + end end - end - context 'with the follow_redirects option set to true' do - it 'returns nil' do - expect(described_class.find_by_full_path('unknown', follow_redirects: true)).to eq(nil) + context 'with the follow_redirects option set to true' do + it 'returns nil' do + expect(described_class.find_by_full_path('unknown', follow_redirects: true)).to eq(nil) + end end end - end - context 'with a group route matching the given path' do - let!(:group) { create(:group, path: 'group_path') } + context 'with a group route matching the given path' do + let!(:group) { create(:group, path: 'group_path') } - context 'when the group namespace has an owner_id (legacy data)' do - before do - group.update!(owner_id: user.id) - end + context 'when the group namespace has an owner_id (legacy data)' do + before do + group.update!(owner_id: user.id) + end - it 'returns nil' do - expect(described_class.find_by_full_path('group_path')).to eq(nil) + it 'returns nil' do + expect(described_class.find_by_full_path('group_path')).to eq(nil) + end end - end - context 'when the group namespace does not have an owner_id' do - it 'returns nil' do - expect(described_class.find_by_full_path('group_path')).to eq(nil) + context 'when the group namespace does not have an owner_id' do + it 'returns nil' do + expect(described_class.find_by_full_path('group_path')).to eq(nil) + end end end end @@ -2615,7 +2629,7 @@ RSpec.describe User do describe 'all_ssh_keys' do it { is_expected.to have_many(:keys).dependent(:destroy) } - it "has all ssh keys" do + it 'has all ssh keys' do user = create :user key = create :key, key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD33bWLBxu48Sev9Fert1yzEO4WGcWglWF7K/AwblIUFselOt/QdOL9DSjpQGxLagO1s9wl53STIO8qGS4Ms0EJZyIXOEFMjFJ5xmjSy+S37By4sG7SsltQEHMxtbtFOaW5LV2wCrX+rUsRNqLMamZjgjcPO0/EgGCXIGMAYW4O7cwGZdXWYIhQ1Vwy+CsVMDdPkPgBXqK7nR/ey8KMs8ho5fMNgB5hBw/AL9fNGhRw3QTD6Q12Nkhl4VZES2EsZqlpNnJttnPdp847DUsT6yuLRlfiQfz5Cn9ysHFdXObMN5VYIiPFwHeYCZp1X2S4fDZooRE8uOLTfxWHPXwrhqSH", user_id: user.id @@ -2651,10 +2665,10 @@ RSpec.describe User do end end - describe "#clear_avatar_caches" do + describe '#clear_avatar_caches' do let(:user) { create(:user) } - it "clears the avatar cache when saving" do + it 'clears the avatar cache when saving' do allow(user).to receive(:avatar_changed?).and_return(true) expect(Gitlab::AvatarCache).to receive(:delete_by_email).with(*user.verified_emails) @@ -3180,7 +3194,7 @@ RSpec.describe User do end end - describe "#last_active_at" do + describe '#last_active_at' do let(:last_activity_on) { 5.days.ago.to_date } let(:current_sign_in_at) { 8.days.ago } @@ -3218,7 +3232,7 @@ RSpec.describe User do end end - describe "#can_be_deactivated?" do + describe '#can_be_deactivated?' do let(:activity) { {} } let(:user) { create(:user, name: 'John Smith', **activity) } let(:day_within_minium_inactive_days_threshold) { User::MINIMUM_INACTIVE_DAYS.pred.days.ago } @@ -3236,7 +3250,7 @@ RSpec.describe User do end end - context "a user who is not active" do + context 'a user who is not active' do before do user.block end @@ -3277,7 +3291,7 @@ RSpec.describe User do end end - describe "#contributed_projects" do + describe '#contributed_projects' do subject { create(:user) } let!(:project1) { create(:project) } @@ -3292,11 +3306,11 @@ RSpec.describe User do project2.add_maintainer(subject) end - it "includes IDs for projects the user has pushed to" do + it 'includes IDs for projects the user has pushed to' do expect(subject.contributed_projects).to include(project1) end - it "includes IDs for projects the user has had merge requests merged into" do + it 'includes IDs for projects the user has had merge requests merged into' do expect(subject.contributed_projects).to include(project3) end @@ -3390,7 +3404,7 @@ RSpec.describe User do end end - describe "#recent_push" do + describe '#recent_push' do let(:user) { build(:user) } let(:project) { build(:project) } let(:event) { build(:push_event) } @@ -3554,7 +3568,7 @@ RSpec.describe User do expect(user.authorized_projects).to include(project) end - it "includes personal projects user has been given access to" do + it 'includes personal projects user has been given access to' do user1 = create(:user) user2 = create(:user) project = create(:project, :private, namespace: user1.namespace) @@ -3564,7 +3578,7 @@ RSpec.describe User do expect(user2.authorized_projects).to include(project) end - it "includes projects of groups user has been added to" do + it 'includes projects of groups user has been added to' do group = create(:group) project = create(:project, group: group) user = create(:user) @@ -3574,7 +3588,7 @@ RSpec.describe User do expect(user.authorized_projects).to include(project) end - it "does not include projects of groups user has been removed from" do + it 'does not include projects of groups user has been removed from', :sidekiq_inline do group = create(:group) project = create(:project, group: group) user = create(:user) @@ -3599,7 +3613,7 @@ RSpec.describe User do expect(user.authorized_projects).to include(project) end - it "does not include destroyed projects user had access to" do + it 'does not include destroyed projects user had access to' do user1 = create(:user) user2 = create(:user) project = create(:project, :private, namespace: user1.namespace) @@ -3613,7 +3627,7 @@ RSpec.describe User do expect(user2.authorized_projects).not_to include(project) end - it "does not include projects of destroyed groups user had access to" do + it 'does not include projects of destroyed groups user had access to' do group = create(:group) project = create(:project, namespace: group) user = create(:user) @@ -3841,7 +3855,7 @@ RSpec.describe User do end context 'with runner in a personal project' do - let!(:namespace) { create(:namespace, owner: user) } + let!(:namespace) { create(:user_namespace, owner: user) } let!(:project) { create(:project, namespace: namespace) } let!(:runner) { create(:ci_runner, :project, projects: [project]) } @@ -3909,7 +3923,7 @@ RSpec.describe User do end context 'with personal project runner in an owned group in an owned namespace and a group runner in that group' do - let!(:namespace) { create(:namespace, owner: user) } + let!(:namespace) { create(:user_namespace, owner: user) } let!(:group) { create(:group) } let!(:group_runner) { create(:ci_runner, :group, groups: [group]) } let!(:project) { create(:project, namespace: namespace, group: group) } @@ -3923,7 +3937,7 @@ RSpec.describe User do end context 'with personal project runner in an owned namespace, an owned group, a subgroup and a group runner in that subgroup' do - let!(:namespace) { create(:namespace, owner: user) } + let!(:namespace) { create(:user_namespace, owner: user) } let!(:group) { create(:group) } let!(:subgroup) { create(:group, parent: group) } let!(:group_runner) { create(:ci_runner, :group, groups: [subgroup]) } @@ -4166,7 +4180,7 @@ RSpec.describe User do expect(user.admin).to be true end - it "accepts string values in addition to symbols" do + it 'accepts string values in addition to symbols' do user.access_level = 'admin' expect(user.access_level).to eq(:admin) @@ -4247,7 +4261,7 @@ RSpec.describe User do expect(ghost.user_type).to eq 'ghost' end - it "does not create a second ghost user if one is already present" do + it 'does not create a second ghost user if one is already present' do expect do described_class.ghost described_class.ghost @@ -4256,7 +4270,7 @@ RSpec.describe User do end context "when a regular user exists with the username 'ghost'" do - it "creates a ghost user with a non-conflicting username" do + it 'creates a ghost user with a non-conflicting username' do create(:user, username: 'ghost') ghost = described_class.ghost @@ -4266,7 +4280,7 @@ RSpec.describe User do end context "when a regular user exists with the email 'ghost@example.com'" do - it "creates a ghost user with a non-conflicting email" do + it 'creates a ghost user with a non-conflicting email' do create(:user, email: 'ghost@example.com') ghost = described_class.ghost @@ -4605,6 +4619,7 @@ RSpec.describe User do user.save! expect(user.namespace).not_to be_nil + expect(user.namespace).to be_kind_of(Namespaces::UserNamespace) end it 'creates the namespace setting' do @@ -4746,7 +4761,7 @@ RSpec.describe User do it { is_expected.to be true } end - context 'when email and username aren\'t changed' do + context "when email and username aren't changed" do before do user.name = 'new_name' end @@ -5057,26 +5072,26 @@ RSpec.describe User do subject { user.required_terms_not_accepted? } - context "when terms are not enforced" do + context 'when terms are not enforced' do it { is_expected.to be_falsey } end - context "when terms are enforced" do + context 'when terms are enforced' do before do enforce_terms end - it "is not accepted by the user" do + it 'is not accepted by the user' do expect(subject).to be_truthy end - it "is accepted by the user" do + it 'is accepted by the user' do accept_terms(user) expect(subject).to be_falsey end - it "auto accepts the term for project bots" do + it 'auto accepts the term for project bots' do expect(project_bot.required_terms_not_accepted?).to be_falsey end end @@ -6165,4 +6180,14 @@ RSpec.describe User do it_behaves_like 'groups_with_developer_maintainer_project_access examples' end end + + describe '.get_ids_by_username' do + let(:user_name) { 'user_name' } + let!(:user) { create(:user, username: user_name) } + let(:user_id) { user.id } + + it 'returns the id of each record matching username' do + expect(described_class.get_ids_by_username([user_name])).to match_array([user_id]) + end + end end |