diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2017-05-10 14:21:58 +0100 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2017-05-10 14:21:58 +0100 |
commit | cc8073653ea5f4bf54026b849f1e0b23a10de15a (patch) | |
tree | 4dce464e49374b1c67f86f006415bbbc7ecbfa7d /spec/models | |
parent | a3074085cd01c0c062cb5f07e848375714dfd6d0 (diff) | |
parent | 09c2aab4aa4661b147545e2c41b6a0100fc57b11 (diff) | |
download | gitlab-ce-30286-vue-loadin-icon.tar.gz |
Merge branch 'master' into 30286-vue-loadin-icon30286-vue-loadin-icon
* master: (62 commits)
Fix broken test - load correct data
Remove redirect for old issue url containing id instead of iid
Use vue file for table pagination component
stub error handlers where uncaught Promise rejections currently exist
Revert "Fix OpenID spec failure that assumed current_sign_in_at would be set"
Add :redis keyword to some specs clear state of trackable attributes
Fix OpenID spec failure that assumed current_sign_in_at would be set
Kubernetes Helm Chart Install docs
Add Repository subnav to 'Find files'
Make tree, blob and blame pages more consistent
Add screenshots to Triggered Build docs
Add Prometheus memory sparkline to MR widget
Fix test failure in job vue componenFix test failure in job vue componentt
Remove unnecessary if check
Fix links in code review docs
Improve readability of code
Remove some unused Gitlab::Git code
Use Rails 'delegate'
Remove CI/CD models directory from `eager_load_paths`
Don't make Commit#raw_deltas private
...
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/ci/pipeline_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/cycle_analytics/test_spec.rb | 1 | ||||
-rw-r--r-- | spec/models/merge_request_spec.rb | 15 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 29 |
4 files changed, 38 insertions, 9 deletions
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 208c8cb1c3d..06e990a0574 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -1044,8 +1044,8 @@ describe Ci::Pipeline, models: true do let(:pipeline) { create(:ci_empty_pipeline, status: 'created', project: project, ref: 'master', sha: 'a288a022a53a5a944fae87bcec6efc87b7061808') } it "returns merge requests whose `diff_head_sha` matches the pipeline's SHA" do - merge_request = create(:merge_request, source_project: project, source_branch: pipeline.ref) allow_any_instance_of(MergeRequest).to receive(:diff_head_sha) { 'a288a022a53a5a944fae87bcec6efc87b7061808' } + merge_request = create(:merge_request, source_project: project, head_pipeline: pipeline, source_branch: pipeline.ref) expect(pipeline.merge_requests).to eq([merge_request]) end diff --git a/spec/models/cycle_analytics/test_spec.rb b/spec/models/cycle_analytics/test_spec.rb index c2ba012a0e6..d0b919efcf9 100644 --- a/spec/models/cycle_analytics/test_spec.rb +++ b/spec/models/cycle_analytics/test_spec.rb @@ -14,6 +14,7 @@ describe 'CycleAnalytics#test', feature: true do issue = context.create(:issue, project: context.project) merge_request = context.create_merge_request_closing_issue(issue) pipeline = context.create(:ci_pipeline, ref: merge_request.source_branch, sha: merge_request.diff_head_sha, project: context.project) + merge_request.update(head_pipeline: pipeline) { pipeline: pipeline, issue: issue } end, start_time_conditions: [["pipeline is started", -> (context, data) { data[:pipeline].run! }]], diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index 6cf3dd30ead..ef349530761 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -760,13 +760,8 @@ describe MergeRequest, models: true do describe '#head_pipeline' do describe 'when the source project exists' do it 'returns the latest pipeline' do - pipeline = double(:ci_pipeline, ref: 'master') - - allow(subject).to receive(:diff_head_sha).and_return('123abc') - - expect(subject.source_project).to receive(:pipeline_for). - with('master', '123abc'). - and_return(pipeline) + pipeline = create(:ci_empty_pipeline, project: subject.source_project, ref: 'master', status: 'running', sha: "123abc") + subject.update(head_pipeline: pipeline) expect(subject.head_pipeline).to eq(pipeline) end @@ -1504,11 +1499,15 @@ describe MergeRequest, models: true do describe '#mergeable_with_slash_command?' do def create_pipeline(status) - create(:ci_pipeline_with_one_job, + pipeline = create(:ci_pipeline_with_one_job, project: project, ref: merge_request.source_branch, sha: merge_request.diff_head_sha, status: status) + + merge_request.update(head_pipeline: pipeline) + + pipeline end let(:project) { create(:project, :public, :repository, only_allow_merge_if_pipeline_succeeds: true) } diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 63e71f5ff2f..c7ddd17872b 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -344,6 +344,35 @@ describe User, models: true do end end + describe '#update_tracked_fields!', :redis do + let(:request) { OpenStruct.new(remote_ip: "127.0.0.1") } + let(:user) { create(:user) } + + it 'writes trackable attributes' do + expect do + user.update_tracked_fields!(request) + end.to change { user.reload.current_sign_in_at } + end + + it 'does not write trackable attributes when called a second time within the hour' do + user.update_tracked_fields!(request) + + expect do + user.update_tracked_fields!(request) + end.not_to change { user.reload.current_sign_in_at } + end + + it 'writes trackable attributes for a different user' do + user2 = create(:user) + + user.update_tracked_fields!(request) + + expect do + user2.update_tracked_fields!(request) + end.to change { user2.reload.current_sign_in_at } + end + end + shared_context 'user keys' do let(:user) { create(:user) } let!(:key) { create(:key, user: user) } |