Commit 65230022 authored by ZJ van de Weg's avatar ZJ van de Weg

Remove old tests, and use right factories

parent 9777a3d3
...@@ -192,14 +192,14 @@ class Spinach::Features::ProjectIssues < Spinach::FeatureSteps ...@@ -192,14 +192,14 @@ class Spinach::Features::ProjectIssues < Spinach::FeatureSteps
step 'issue "Release 0.4" have 2 upvotes and 1 downvote' do step 'issue "Release 0.4" have 2 upvotes and 1 downvote' do
awardable = Issue.find_by(title: 'Release 0.4') awardable = Issue.find_by(title: 'Release 0.4')
create_list(:upvote, 2, project: project, awardable: awardable) create_list(:award_emoji, 2, awardable: awardable)
create(:downvote, project: project, awardable: awardable) create(:award_emoji, :downvote, awardable: awardable)
end end
step 'issue "Tweet control" have 1 upvote and 2 downvotes' do step 'issue "Tweet control" have 1 upvote and 2 downvotes' do
issue = Issue.find_by(title: 'Tweet control') awardable = Issue.find_by(title: 'Tweet control')
create(:upvote, project: project, noteable: issue) create(:award_emoji, :upvote, awardable: awardable)
create_list(:downvote, 2, project: project, noteable: issue) create_list(:award_emoji, 2, awardable: awardable, name: 'thumbsdown')
end end
step 'The list should be sorted by "Least popular"' do step 'The list should be sorted by "Least popular"' do
......
...@@ -179,14 +179,14 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps ...@@ -179,14 +179,14 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
step 'merge request "Bug NS-04" have 2 upvotes and 1 downvote' do step 'merge request "Bug NS-04" have 2 upvotes and 1 downvote' do
merge_request = MergeRequest.find_by(title: 'Bug NS-04') merge_request = MergeRequest.find_by(title: 'Bug NS-04')
create_list(:upvote, 2, project: project, awardable: merge_request) create_list(:award_emoji, 2, awardable: merge_request)
create(:downvote, project: project, awardable: merge_request) create(:award_emoji, :downvote, awardable: merge_request)
end end
step 'merge request "Bug NS-06" have 1 upvote and 2 downvotes' do step 'merge request "Bug NS-06" have 1 upvote and 2 downvotes' do
awardable = MergeRequest.find_by(title: 'Bug NS-06') awardable = MergeRequest.find_by(title: 'Bug NS-06')
create(:upvote, project: project, awardable: awardable) create(:award_emoji, awardable: awardable)
create_list(:downvote, 2, project: project, awardable: awardable) create_list(:award_emoji, 2, awardable: awardable, name: "thumbsdown")
end end
step 'The list should be sorted by "Least popular"' do step 'The list should be sorted by "Least popular"' do
......
...@@ -113,66 +113,6 @@ describe Note, models: true do ...@@ -113,66 +113,6 @@ describe Note, models: true do
end end
end end
describe '#active?' do
it 'is always true when the note has no associated diff' do
note = build(:note)
expect(note).to receive(:diff).and_return(nil)
expect(note).to be_active
end
it 'is never true when the note has no noteable associated' do
note = build(:note)
expect(note).to receive(:diff).and_return(double)
expect(note).to receive(:noteable).and_return(nil)
expect(note).not_to be_active
end
it 'returns the memoized value if defined' do
note = build(:note)
expect(note).to receive(:diff).and_return(double)
expect(note).to receive(:noteable).and_return(double)
note.instance_variable_set(:@active, 'foo')
expect(note).not_to receive(:find_noteable_diff)
expect(note.active?).to eq 'foo'
end
context 'for a merge request noteable' do
it 'is false when noteable has no matching diff' do
merge = build_stubbed(:merge_request, :simple)
note = build(:note, noteable: merge)
allow(note).to receive(:diff).and_return(double)
expect(note).to receive(:find_noteable_diff).and_return(nil)
expect(note).not_to be_active
end
it 'is true when noteable has a matching diff' do
merge = create(:merge_request, :simple)
# Generate a real line_code value so we know it will match. We use a
# random line from a random diff just for funsies.
diff = merge.diffs.to_a.sample
line = Gitlab::Diff::Parser.new.parse(diff.diff.each_line).to_a.sample
code = Gitlab::Diff::LineCode.generate(diff.new_path, line.new_pos, line.old_pos)
# We're persisting in order to trigger the set_diff callback
note = create(:note, noteable: merge, line_code: code)
# Make sure we don't get a false positive from a guard clause
expect(note).to receive(:find_noteable_diff).and_call_original
expect(note).to be_active
end
end
end
describe "editable?" do describe "editable?" do
it "returns true" do it "returns true" do
note = build(:note) note = build(:note)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment