diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/features/admin/admin_users_spec.rb | 40 | ||||
-rw-r--r-- | spec/helpers/application_helper_spec.rb | 12 | ||||
-rw-r--r-- | spec/helpers/groups_helper.rb | 4 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 74 |
4 files changed, 86 insertions, 44 deletions
diff --git a/spec/features/admin/admin_users_spec.rb b/spec/features/admin/admin_users_spec.rb index 7f5cb30cb94..86717761582 100644 --- a/spec/features/admin/admin_users_spec.rb +++ b/spec/features/admin/admin_users_spec.rb @@ -16,6 +16,46 @@ describe "Admin::Users", feature: true do expect(page).to have_content(@user.email) expect(page).to have_content(@user.name) end + + describe 'Two-factor Authentication filters' do + it 'counts users who have enabled 2FA' do + create(:user, two_factor_enabled: true) + + visit admin_users_path + + page.within('.filter-two-factor-enabled small') do + expect(page).to have_content('1') + end + end + + it 'filters by users who have enabled 2FA' do + user = create(:user, two_factor_enabled: true) + + visit admin_users_path + click_link '2FA Enabled' + + expect(page).to have_content(user.email) + end + + it 'counts users who have not enabled 2FA' do + create(:user, two_factor_enabled: false) + + visit admin_users_path + + page.within('.filter-two-factor-disabled small') do + expect(page).to have_content('2') # Including admin + end + end + + it 'filters by users who have not enabled 2FA' do + user = create(:user, two_factor_enabled: false) + + visit admin_users_path + click_link '2FA Disabled' + + expect(page).to have_content(user.email) + end + end end describe "GET /admin/users/new" do diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 582c401c55a..8fd3d8f407b 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -40,15 +40,15 @@ describe ApplicationHelper do end describe 'project_icon' do - avatar_file_path = File.join(Rails.root, 'public', 'gitlab_logo.png') + avatar_file_path = File.join(Rails.root, 'spec', 'fixtures', 'banana_sample.gif') it 'should return an url for the avatar' do project = create(:project) project.avatar = File.open(avatar_file_path) project.save! - avatar_url = "http://localhost/uploads/project/avatar/#{ project.id }/gitlab_logo.png" + avatar_url = "http://localhost/uploads/project/avatar/#{ project.id }/banana_sample.gif" expect(project_icon("#{project.namespace.to_param}/#{project.to_param}").to_s).to eq( - "<img alt=\"Gitlab logo\" src=\"#{avatar_url}\" />" + "<img alt=\"Banana sample\" src=\"#{avatar_url}\" />" ) end @@ -65,14 +65,14 @@ describe ApplicationHelper do end describe 'avatar_icon' do - avatar_file_path = File.join(Rails.root, 'public', 'gitlab_logo.png') + avatar_file_path = File.join(Rails.root, 'spec', 'fixtures', 'banana_sample.gif') it 'should return an url for the avatar' do user = create(:user) user.avatar = File.open(avatar_file_path) user.save! expect(avatar_icon(user.email).to_s). - to match("/uploads/user/avatar/#{ user.id }/gitlab_logo.png") + to match("/uploads/user/avatar/#{ user.id }/banana_sample.gif") end it 'should return an url for the avatar with relative url' do @@ -83,7 +83,7 @@ describe ApplicationHelper do user.avatar = File.open(avatar_file_path) user.save! expect(avatar_icon(user.email).to_s). - to match("/gitlab/uploads/user/avatar/#{ user.id }/gitlab_logo.png") + to match("/gitlab/uploads/user/avatar/#{ user.id }/banana_sample.gif") end it 'should call gravatar_icon when no avatar is present' do diff --git a/spec/helpers/groups_helper.rb b/spec/helpers/groups_helper.rb index 3e99ab84ec9..5d174460681 100644 --- a/spec/helpers/groups_helper.rb +++ b/spec/helpers/groups_helper.rb @@ -2,14 +2,14 @@ require 'spec_helper' describe GroupsHelper do describe 'group_icon' do - avatar_file_path = File.join(Rails.root, 'public', 'gitlab_logo.png') + avatar_file_path = File.join(Rails.root, 'spec', 'fixtures', 'banana_sample.gif') it 'should return an url for the avatar' do group = create(:group) group.avatar = File.open(avatar_file_path) group.save! expect(group_icon(group.path).to_s). - to match("/uploads/group/avatar/#{ group.id }/gitlab_logo.png") + to match("/uploads/group/avatar/#{ group.id }/banana_sample.gif") end it 'should give default avatar_icon when no avatar is present' do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 9f7c83f3476..b80273c053d 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -50,12 +50,12 @@ # bitbucket_access_token :string(255) # bitbucket_access_token_secret :string(255) # location :string(255) -# public_email :string(255) default(""), not null # encrypted_otp_secret :string(255) # encrypted_otp_secret_iv :string(255) # encrypted_otp_secret_salt :string(255) -# otp_required_for_login :boolean +# otp_required_for_login :boolean default(FALSE), not null # otp_backup_codes :text +# public_email :string(255) default(""), not null # dashboard :integer default(0) # @@ -210,30 +210,6 @@ describe User do end end - describe '#two_factor_enabled' do - it 'returns two-factor authentication status' do - enabled = build_stubbed(:user, two_factor_enabled: true) - disabled = build_stubbed(:user) - - expect(enabled).to be_two_factor_enabled - expect(disabled).not_to be_two_factor_enabled - end - end - - describe '#two_factor_enabled=' do - it 'enables two-factor authentication' do - user = build_stubbed(:user, two_factor_enabled: false) - expect { user.two_factor_enabled = true }. - to change { user.two_factor_enabled? }.to(true) - end - - it 'disables two-factor authentication' do - user = build_stubbed(:user, two_factor_enabled: true) - expect { user.two_factor_enabled = false }. - to change { user.two_factor_enabled? }.to(false) - end - end - describe 'authentication token' do it "should have authentication token" do user = create(:user) @@ -308,18 +284,44 @@ describe User do end end - describe 'filter' do - before do - User.delete_all - @user = create :user - @admin = create :user, admin: true - @blocked = create :user, state: :blocked + describe '.filter' do + let(:user) { double } + + it 'filters by active users by default' do + expect(User).to receive(:active).and_return([user]) + + expect(User.filter(nil)).to include user + end + + it 'filters by admins' do + expect(User).to receive(:admins).and_return([user]) + + expect(User.filter('admins')).to include user end - it { expect(User.filter("admins")).to eq([@admin]) } - it { expect(User.filter("blocked")).to eq([@blocked]) } - it { expect(User.filter("wop")).to include(@user, @admin, @blocked) } - it { expect(User.filter(nil)).to include(@user, @admin) } + it 'filters by blocked' do + expect(User).to receive(:blocked).and_return([user]) + + expect(User.filter('blocked')).to include user + end + + it 'filters by two_factor_disabled' do + expect(User).to receive(:without_two_factor).and_return([user]) + + expect(User.filter('two_factor_disabled')).to include user + end + + it 'filters by two_factor_enabled' do + expect(User).to receive(:with_two_factor).and_return([user]) + + expect(User.filter('two_factor_enabled')).to include user + end + + it 'filters by wop' do + expect(User).to receive(:without_projects).and_return([user]) + + expect(User.filter('wop')).to include user + end end describe :not_in_project do |