Commit 6865bc16 authored by James Lopez's avatar James Lopez

refactored specs, adding more scenarios

parent 07f8ffbd
...@@ -4,23 +4,25 @@ feature 'Issue filtering by Labels', feature: true do ...@@ -4,23 +4,25 @@ 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', 'feature', 'enhancement'].each do |title|
create(:label, bug = create(:label, project: project, title: 'bug')
project: project, feature = create(:label, project: project, title: 'feature')
title: title) enhancement = create(:label, project: project, title: 'enhancement')
end
issue1 = create(:issue, title: "Bugfix1", project: project) issue1 = create(:issue, title: "Bugfix1", project: project)
issue1.labels << project.labels.find_by(title: 'bug') issue1.labels << bug
issue2 = create(:issue, title: "Bugfix2", project: project) issue2 = create(:issue, title: "Bugfix2", project: project)
issue2.labels << project.labels.find_by(title: 'bug') issue2.labels << bug
issue2.labels << project.labels.find_by(title: 'enhancement') issue2.labels << enhancement
issue3 = create(:issue, title: "Feature1", project: project) issue3 = create(:issue, title: "Feature1", project: project)
issue3.labels << project.labels.find_by(title: 'feature') issue3.labels << feature
project.team << [user, :master] project.team << [user, :master]
login_as(user) login_as(user)
...@@ -122,13 +124,9 @@ feature 'Issue filtering by Labels', feature: true do ...@@ -122,13 +124,9 @@ feature 'Issue filtering by Labels', feature: true do
sleep 2 sleep 2
end end
it 'should show issue "Bugfix2" or "Feature1" in issues list' do it 'should not show "Bugfix1" or "Feature1" in issues list' do
expect(page).to have_content "Bugfix2"
expect(page).to have_content "Feature1"
end
it 'should not show "Bugfix1" in issues list' do
expect(page).not_to have_content "Bugfix1" expect(page).not_to have_content "Bugfix1"
expect(page).not_to have_content "Feature1"
end end
it 'should show label "enhancement" and "feature" in filtered-labels' do it 'should show label "enhancement" and "feature" in filtered-labels' do
...@@ -141,7 +139,7 @@ feature 'Issue filtering by Labels', feature: true do ...@@ -141,7 +139,7 @@ feature 'Issue filtering by Labels', feature: true do
end end
end end
context 'filter by label enhancement or bug in issues list', js: true do context 'filter by label enhancement and bug in issues list', js: true do
before do before do
page.find('.js-label-select').click page.find('.js-label-select').click
sleep 0.5 sleep 0.5
...@@ -151,9 +149,8 @@ feature 'Issue filtering by Labels', feature: true do ...@@ -151,9 +149,8 @@ feature 'Issue filtering by Labels', feature: true do
sleep 2 sleep 2
end end
it 'should show issue "Bugfix2" or "Bugfix1" in issues list' do it 'should show issue "Bugfix2" in issues list' do
expect(page).to have_content "Bugfix2" expect(page).to have_content "Bugfix2"
expect(page).to have_content "Bugfix1"
end end
it 'should not show "Feature1"' do it 'should not show "Feature1"' do
......
...@@ -217,16 +217,26 @@ describe Issue, "Issuable" do ...@@ -217,16 +217,26 @@ describe Issue, "Issuable" do
let(:example_label) { 'test1' } let(:example_label) { 'test1' }
let(:example_labels) { ['test1', 'test2'] } let(:example_labels) { ['test1', 'test2'] }
it 'finds issue with 1 label' do before(:each) do
setup_other_issue
end
it 'finds the correct issue with 1 label' do
setup_labels([example_label]) setup_labels([example_label])
expect(Issue.with_label(example_label).size).to eq(1) 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 issue with 2 labels' do it 'finds the correct issue with 1 of 2 labels' do
setup_labels(example_labels) setup_labels(example_labels)
expect(Issue.with_label(example_labels).to_a.size).to eq(1) expect(Issue.with_label(example_label)).to eq([issue])
end end
def setup_labels(label_names) def setup_labels(label_names)
...@@ -235,5 +245,10 @@ describe Issue, "Issuable" do ...@@ -235,5 +245,10 @@ describe Issue, "Issuable" do
end end
issue.labels << labels issue.labels << labels
end end
def setup_other_issue
issue2 = create(:issue)
issue2.labels << create(:label, project: issue2.project, title: 'other_label')
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