Commit b09b175d authored by James Lopez's avatar James Lopez

refactored specs based on feedback

parent 2d2b73ae
...@@ -6,12 +6,8 @@ feature 'Issue filtering by Labels', feature: true do ...@@ -6,12 +6,8 @@ feature 'Issue filtering by Labels', feature: true do
let(:project) { create(:project, :public) } let(:project) { create(:project, :public) }
let!(:user) { create(:user)} let!(:user) { create(:user)}
let!(:label) { create(:label, project: project) } let!(:label) { create(:label, project: project) }
let(:bug) { create(:label, project: project, title: 'bug') }
let(:feature) { create(:label, project: project, title: 'feature') }
let(:enhancement) { create(:label, project: project, title: 'enhancement') }
before do before do
bug = create(:label, project: project, title: 'bug') bug = create(:label, project: project, title: 'bug')
feature = create(:label, project: project, title: 'feature') feature = create(:label, project: project, title: 'feature')
enhancement = create(:label, project: project, title: 'enhancement') enhancement = create(:label, project: project, title: 'enhancement')
......
...@@ -214,41 +214,32 @@ describe Issue, "Issuable" do ...@@ -214,41 +214,32 @@ describe Issue, "Issuable" do
end end
describe ".with_label" do describe ".with_label" do
let(:example_label) { 'test1' } let(:project) { create(:project, :public) }
let(:example_labels) { ['test1', 'test2'] } let(:bug) { create(:label, project: project, title: 'bug') }
let(:feature) { create(:label, project: project, title: 'feature') }
let(:enhancement) { create(:label, project: project, title: 'enhancement') }
let(:issue1) { create(:issue, title: "Bugfix1", project: project) }
let(:issue2) { create(:issue, title: "Bugfix2", project: project) }
let(:issue3) { create(:issue, title: "Feature1", project: project) }
before(:each) do before(:each) do
setup_other_issue issue1.labels << bug
issue1.labels << feature
issue2.labels << bug
issue2.labels << enhancement
issue3.labels << feature
end end
it 'finds the correct issue with 1 label' do it 'finds the correct issue containing just enhancement label' do
setup_labels([example_label]) expect(Issue.with_label(enhancement.title)).to match_array([issue2])
expect(Issue.with_label(example_label)).to eq([issue])
end
it 'finds the correct issue with 2 labels' do
setup_labels(example_labels)
expect(Issue.with_label(example_labels)).to eq([issue])
end end
it 'finds the correct issue with 1 of 2 labels' do it 'finds the correct issues containing the same label' do
setup_labels(example_labels) expect(Issue.with_label(bug.title)).to match_array([issue1, issue2])
expect(Issue.with_label(example_label)).to eq([issue])
end
def setup_labels(label_names)
labels = label_names.map do |label|
create(:label, project: issue.project, title: label)
end
issue.labels << labels
end end
def setup_other_issue it 'finds the correct issues containing only both labels' do
issue2 = create(:issue) expect(Issue.with_label([bug.title, enhancement.title])).to match_array([issue2])
issue2.labels << create(:label, project: issue2.project, title: 'other_label')
end end
end end
end end
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