From 309ca405fa30e1eeaeaeddc0c8918e65c98ebbf7 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Mon, 2 May 2016 18:15:25 +0200 Subject: Don't modify arguments in CommitRange#initialize This method used to call strip! on input strings which will mess with the strings if they're re-used or frozen. --- spec/models/commit_range_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'spec/models/commit_range_spec.rb') diff --git a/spec/models/commit_range_spec.rb b/spec/models/commit_range_spec.rb index 9307d97e214..1cf51d8bab3 100644 --- a/spec/models/commit_range_spec.rb +++ b/spec/models/commit_range_spec.rb @@ -24,6 +24,16 @@ describe CommitRange, models: true do expect { described_class.new("Foo", project) }.to raise_error(ArgumentError) end + describe '#initialize' do + it 'does not modify strings in-place' do + input = "#{sha_from}...#{sha_to} " + + described_class.new(input, project) + + expect(input).to eq("#{sha_from}...#{sha_to} ") + end + end + describe '#to_s' do it 'is correct for three-dot syntax' do expect(range.to_s).to eq "#{full_sha_from}...#{full_sha_to}" -- cgit v1.2.1 From 580d250166d97bd5c2b0526be737d02806e577c2 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Thu, 26 May 2016 13:38:28 +0200 Subject: Refactor Participable There are several changes to this module: 1. The use of an explicit stack in Participable#participants 2. Proc behaviour has been changed 3. Batch permissions checking == Explicit Stack Participable#participants no longer uses recursion to process "self" and all child objects, instead it uses an Array and processes objects in breadth-first order. This allows us to for example create a single Gitlab::ReferenceExtractor instance and pass this to any Procs. Re-using a ReferenceExtractor removes the need for running potentially many SQL queries every time a Proc is called on a new object. == Proc Behaviour Changed Previously a Proc in Participable was expected to return an Array of User instances. This has been changed and instead it's now expected that a Proc modifies the Gitlab::ReferenceExtractor passed to it. The return value of the Proc is ignored. == Permissions Checking The method Participable#participants uses Ability.users_that_can_read_project to check if the returned users have access to the project of "self" _without_ running multiple SQL queries for every user. --- spec/models/commit_range_spec.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'spec/models/commit_range_spec.rb') diff --git a/spec/models/commit_range_spec.rb b/spec/models/commit_range_spec.rb index 1cf51d8bab3..6bc496414a3 100644 --- a/spec/models/commit_range_spec.rb +++ b/spec/models/commit_range_spec.rb @@ -145,4 +145,27 @@ describe CommitRange, models: true do end end end + + describe '#has_been_reverted?' do + it 'returns true if the commit has been reverted' do + issue = create(:issue) + + create(:note_on_issue, + noteable_id: issue.id, + system: true, + note: commit1.revert_description) + + expect_any_instance_of(Commit).to receive(:reverts_commit?). + with(commit1). + and_return(true) + + expect(commit1.has_been_reverted?(nil, issue)).to eq(true) + end + + it 'returns false a commit has not been reverted' do + issue = create(:issue) + + expect(commit1.has_been_reverted?(nil, issue)).to eq(false) + end + end end -- cgit v1.2.1 From 30aa64202b073e33834241589595a58a14080107 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Wed, 1 Jun 2016 09:56:06 -0700 Subject: Fix note validation spec failures --- spec/models/commit_range_spec.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'spec/models/commit_range_spec.rb') diff --git a/spec/models/commit_range_spec.rb b/spec/models/commit_range_spec.rb index 6bc496414a3..384a38ebc69 100644 --- a/spec/models/commit_range_spec.rb +++ b/spec/models/commit_range_spec.rb @@ -151,9 +151,10 @@ describe CommitRange, models: true do issue = create(:issue) create(:note_on_issue, - noteable_id: issue.id, + noteable: issue, system: true, - note: commit1.revert_description) + note: commit1.revert_description, + project: issue.project) expect_any_instance_of(Commit).to receive(:reverts_commit?). with(commit1). -- cgit v1.2.1