summaryrefslogtreecommitdiff
path: root/spec/models/diff_note_spec.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2016-07-07 16:13:55 -0400
committerDouwe Maan <douwe@selenight.nl>2016-07-07 16:13:55 -0400
commit6dd71888b310d2615d74ea129431fc6c9791b6b7 (patch)
treecee4fe55b4a85f89e0bd5707a6247f78dc15a171 /spec/models/diff_note_spec.rb
parent70a64f6a57a2b4fd2874b0db03f4fe1f0c3794f8 (diff)
downloadgitlab-ce-6dd71888b310d2615d74ea129431fc6c9791b6b7.tar.gz
Make `DiffNote#update_position` private
Diffstat (limited to 'spec/models/diff_note_spec.rb')
-rw-r--r--spec/models/diff_note_spec.rb83
1 files changed, 44 insertions, 39 deletions
diff --git a/spec/models/diff_note_spec.rb b/spec/models/diff_note_spec.rb
index 9443f7c13f8..af8e890ca95 100644
--- a/spec/models/diff_note_spec.rb
+++ b/spec/models/diff_note_spec.rb
@@ -9,7 +9,7 @@ describe DiffNote, models: true do
let(:path) { "files/ruby/popen.rb" }
- let(:position) do
+ let!(:position) do
Gitlab::Diff::Position.new(
old_path: path,
new_path: path,
@@ -19,7 +19,7 @@ describe DiffNote, models: true do
)
end
- let(:new_position) do
+ let!(:new_position) do
Gitlab::Diff::Position.new(
old_path: path,
new_path: path,
@@ -129,56 +129,61 @@ describe DiffNote, models: true do
end
end
- describe "#update_position" do
- context "when noteable is a commit" do
- subject { create(:diff_note_on_commit, project: project, position: position) }
-
- it "doesn't use the DiffPositionUpdateService" do
- expect(Notes::DiffPositionUpdateService).not_to receive(:new)
-
- subject.update_position
- end
-
- it "doesn't update the position" do
- subject.update_position
-
- expect(subject.original_position).to eq(position)
- expect(subject.position).to eq(position)
- end
- end
+ describe "creation" do
+ describe "updating of position" do
+ context "when noteable is a commit" do
+ let(:diff_note) { create(:diff_note_on_commit, project: project, position: position) }
- context "when noteable is a merge request" do
- context "when the note is active" do
it "doesn't use the DiffPositionUpdateService" do
expect(Notes::DiffPositionUpdateService).not_to receive(:new)
- subject.update_position
+ diff_note
end
it "doesn't update the position" do
- subject.update_position
+ diff_note
- expect(subject.original_position).to eq(position)
- expect(subject.position).to eq(position)
+ expect(diff_note.original_position).to eq(position)
+ expect(diff_note.position).to eq(position)
end
end
- context "when the note is outdated" do
- before do
- allow(subject.noteable).to receive(:diff_refs).and_return(commit.diff_refs)
+ context "when noteable is a merge request" do
+ let(:diff_note) { create(:diff_note_on_merge_request, project: project, position: position, noteable: merge_request) }
+
+ context "when the note is active" do
+ it "doesn't use the DiffPositionUpdateService" do
+ expect(Notes::DiffPositionUpdateService).not_to receive(:new)
+
+ diff_note
+ end
+
+ it "doesn't update the position" do
+ diff_note
+
+ expect(diff_note.original_position).to eq(position)
+ expect(diff_note.position).to eq(position)
+ end
end
- it "uses the DiffPositionUpdateService" do
- expect(Notes::DiffPositionUpdateService).to receive(:new).with(
- project,
- nil,
- old_diff_refs: position.diff_refs,
- new_diff_refs: commit.diff_refs,
- paths: [path]
- ).and_call_original
- expect_any_instance_of(Notes::DiffPositionUpdateService).to receive(:execute).with(subject)
-
- subject.update_position
+ context "when the note is outdated" do
+ before do
+ allow(merge_request).to receive(:diff_refs).and_return(commit.diff_refs)
+ end
+
+ it "uses the DiffPositionUpdateService" do
+ service = instance_double("Notes::DiffPositionUpdateService")
+ expect(Notes::DiffPositionUpdateService).to receive(:new).with(
+ project,
+ nil,
+ old_diff_refs: position.diff_refs,
+ new_diff_refs: commit.diff_refs,
+ paths: [path]
+ ).and_return(service)
+ expect(service).to receive(:execute)
+
+ diff_note
+ end
end
end
end