diff options
author | Guilherme Garnier <guilherme.garnier@gmail.com> | 2015-10-03 11:46:29 -0500 |
---|---|---|
committer | Guilherme Garnier <guilherme.garnier@gmail.com> | 2015-10-03 11:46:29 -0500 |
commit | 1cfb48ddd005f599a453dcd9a4471fb003e6c222 (patch) | |
tree | 28037a6ffa676455ad64bdc3450d7d5099244a6c /spec | |
parent | 848d7b2a2be28982d0f164d4e3a966c300e7c322 (diff) | |
parent | 662f8af497656754c7ad27c0250d2aae825b8545 (diff) | |
download | gitlab-ce-1cfb48ddd005f599a453dcd9a4471fb003e6c222.tar.gz |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'spec')
-rw-r--r-- | spec/features/login_spec.rb | 2 | ||||
-rw-r--r-- | spec/features/password_reset_spec.rb | 54 | ||||
-rw-r--r-- | spec/helpers/projects_helper_spec.rb | 4 | ||||
-rw-r--r-- | spec/models/project_services/gitlab_ci_service_spec.rb | 21 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 3 | ||||
-rw-r--r-- | spec/models/project_team_spec.rb | 12 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 20 | ||||
-rw-r--r-- | spec/services/ci/create_project_service_spec.rb | 37 | ||||
-rw-r--r-- | spec/services/projects/fork_service_spec.rb | 12 |
9 files changed, 62 insertions, 103 deletions
diff --git a/spec/features/login_spec.rb b/spec/features/login_spec.rb index cef432e512b..922c76285d1 100644 --- a/spec/features/login_spec.rb +++ b/spec/features/login_spec.rb @@ -95,7 +95,7 @@ feature 'Login', feature: true do user = create(:user, password: 'not-the-default') login_with(user) - expect(page).to have_content('Invalid email or password.') + expect(page).to have_content('Invalid login or password.') end end end diff --git a/spec/features/password_reset_spec.rb b/spec/features/password_reset_spec.rb index abf66f2356d..85e70b4d47f 100644 --- a/spec/features/password_reset_spec.rb +++ b/spec/features/password_reset_spec.rb @@ -1,53 +1,43 @@ require 'spec_helper' feature 'Password reset', feature: true do - describe 'with two-factor authentication' do - let(:user) { create(:user, :two_factor) } - - it 'requires login after password reset' do + describe 'throttling' do + it 'sends reset instructions when not previously sent' do visit root_path + forgot_password(create(:user)) - forgot_password - reset_password - - expect(page).to have_content("Your password was changed successfully.") - expect(page).not_to have_content("You are now signed in.") + expect(page).to have_content(I18n.t('devise.passwords.send_instructions')) expect(current_path).to eq new_user_session_path end - end - describe 'without two-factor authentication' do - let(:user) { create(:user) } + it 'sends reset instructions when previously sent more than a minute ago' do + user = create(:user) + user.send_reset_password_instructions + user.update_attribute(:reset_password_sent_at, 5.minutes.ago) - it 'requires login after password reset' do visit root_path + forgot_password(user) - forgot_password - reset_password - - expect(page).to have_content("Your password was changed successfully.") + expect(page).to have_content(I18n.t('devise.passwords.send_instructions')) expect(current_path).to eq new_user_session_path end + + it "throttles multiple resets in a short timespan" do + user = create(:user) + user.send_reset_password_instructions + + visit root_path + forgot_password(user) + + expect(page).to have_content(I18n.t('devise.passwords.recently_reset')) + expect(current_path).to eq new_user_password_path + end end - def forgot_password + def forgot_password(user) click_on 'Forgot your password?' fill_in 'Email', with: user.email click_button 'Reset password' user.reload end - - def get_reset_token - mail = ActionMailer::Base.deliveries.last - body = mail.body.encoded - body.scan(/reset_password_token=(.+)\"/).flatten.first - end - - def reset_password(password = 'password') - visit edit_user_password_path(reset_password_token: get_reset_token) - - fill_in 'New password', with: password - fill_in 'Confirm new password', with: password - click_button 'Change your password' - end end diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index 99abb95d906..53e56ebff44 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -61,13 +61,13 @@ describe ProjectsHelper do end it "returns a valid cach key" do - expect(helper.send(:readme_cache_key)).to eq("#{project.id}-#{project.commit.id}-readme") + expect(helper.send(:readme_cache_key)).to eq("#{project.path_with_namespace}-#{project.commit.id}-readme") end it "returns a valid cache key if HEAD does not exist" do allow(project).to receive(:commit) { nil } - expect(helper.send(:readme_cache_key)).to eq("#{project.id}-nil-readme") + expect(helper.send(:readme_cache_key)).to eq("#{project.path_with_namespace}-nil-readme") end end end diff --git a/spec/models/project_services/gitlab_ci_service_spec.rb b/spec/models/project_services/gitlab_ci_service_spec.rb index ab5d0ccd3ca..683a403a907 100644 --- a/spec/models/project_services/gitlab_ci_service_spec.rb +++ b/spec/models/project_services/gitlab_ci_service_spec.rb @@ -55,25 +55,4 @@ describe GitlabCiService do end end end - - describe "Fork registration" do - before do - @old_project = create(:ci_project).gl_project - @project = create(:empty_project) - @user = create(:user) - - @service = GitlabCiService.new - allow(@service).to receive_messages( - service_hook: true, - project_url: 'http://ci.gitlab.org/projects/2', - token: 'verySecret', - project: @old_project - ) - end - - it "creates fork on CI" do - expect_any_instance_of(Ci::CreateProjectService).to receive(:execute) - @service.fork_registration(@project, @user) - end - end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 3df5300fe38..8b5d2c3a1c1 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -417,9 +417,8 @@ describe Project do describe :enable_ci do let(:project) { create :project } - let(:user) { create :user } - before { project.enable_ci(user) } + before { project.enable_ci } it { expect(project.gitlab_ci?).to be_truthy } it { expect(project.gitlab_ci_project).to be_a(Ci::Project) } diff --git a/spec/models/project_team_spec.rb b/spec/models/project_team_spec.rb index cc1138490a0..26e8fdae472 100644 --- a/spec/models/project_team_spec.rb +++ b/spec/models/project_team_spec.rb @@ -66,4 +66,16 @@ describe ProjectTeam do it { expect(project.team.member?(guest)).to be_truthy } end end + + describe "#human_max_access" do + it "return master role" do + user = create :user + group = create :group + group.add_users([user.id], GroupMember::MASTER) + project = create(:project, namespace: group) + project.team << [user, :guest] + + expect(project.team.human_max_access(user.id)).to eq("Master") + end + end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index b7b525bfca2..c71cfb3ebe3 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -228,6 +228,26 @@ describe User do end end + describe '#recently_sent_password_reset?' do + it 'is false when reset_password_sent_at is nil' do + user = build_stubbed(:user, reset_password_sent_at: nil) + + expect(user.recently_sent_password_reset?).to eq false + end + + it 'is false when sent more than one minute ago' do + user = build_stubbed(:user, reset_password_sent_at: 5.minutes.ago) + + expect(user.recently_sent_password_reset?).to eq false + end + + it 'is true when sent less than one minute ago' do + user = build_stubbed(:user, reset_password_sent_at: Time.now) + + expect(user.recently_sent_password_reset?).to eq true + end + end + describe '#disable_two_factor!' do it 'clears all 2FA-related fields' do user = create(:user, :two_factor) diff --git a/spec/services/ci/create_project_service_spec.rb b/spec/services/ci/create_project_service_spec.rb deleted file mode 100644 index 2de7b0deca7..00000000000 --- a/spec/services/ci/create_project_service_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -require 'spec_helper' - -describe Ci::CreateProjectService do - let(:service) { Ci::CreateProjectService.new } - let(:current_user) { double.as_null_object } - let(:project) { FactoryGirl.create :project } - - describe :execute do - context 'valid params' do - subject { service.execute(current_user, project) } - - it { is_expected.to be_kind_of(Ci::Project) } - it { is_expected.to be_persisted } - end - - context 'without project dump' do - it 'should raise exception' do - expect { service.execute(current_user, '', '') }. - to raise_error(NoMethodError) - end - end - - context "forking" do - let(:ci_origin_project) do - FactoryGirl.create(:ci_project, shared_runners_enabled: true, public: true, allow_git_fetch: true) - end - - subject { service.execute(current_user, project, ci_origin_project) } - - it "uses project as a template for settings and jobs" do - expect(subject.shared_runners_enabled).to be_truthy - expect(subject.public).to be_truthy - expect(subject.allow_git_fetch).to be_truthy - end - end - end -end diff --git a/spec/services/projects/fork_service_spec.rb b/spec/services/projects/fork_service_spec.rb index 18ab333c1d1..65a8c81204d 100644 --- a/spec/services/projects/fork_service_spec.rb +++ b/spec/services/projects/fork_service_spec.rb @@ -43,14 +43,10 @@ describe Projects::ForkService do end context 'GitLab CI is enabled' do - it "calls fork registrator for CI" do - create(:ci_project, gl_project: @from_project) - @from_project.build_missing_services - @from_project.gitlab_ci_service.update_attributes(active: true) - - expect_any_instance_of(Ci::CreateProjectService).to receive(:execute) - - fork_project(@from_project, @to_user) + it "fork and enable CI for fork" do + @from_project.enable_ci + @to_project = fork_project(@from_project, @to_user) + expect(@to_project.gitlab_ci?).to be_truthy end end end |