Commit 2fe13fbc authored by Robert Speicher's avatar Robert Speicher

Use `:empty_project` where possible in helper specs

parent d5583912
...@@ -55,7 +55,7 @@ describe ApplicationHelper do ...@@ -55,7 +55,7 @@ describe ApplicationHelper do
describe 'project_icon' do describe 'project_icon' do
it 'returns an url for the avatar' do it 'returns an url for the avatar' do
project = create(:project, avatar: File.open(uploaded_image_temp_path)) project = create(:empty_project, avatar: File.open(uploaded_image_temp_path))
avatar_url = "http://#{Gitlab.config.gitlab.host}/uploads/project/avatar/#{project.id}/banana_sample.gif" avatar_url = "http://#{Gitlab.config.gitlab.host}/uploads/project/avatar/#{project.id}/banana_sample.gif"
expect(helper.project_icon("#{project.namespace.to_param}/#{project.to_param}").to_s). expect(helper.project_icon("#{project.namespace.to_param}/#{project.to_param}").to_s).
...@@ -63,7 +63,7 @@ describe ApplicationHelper do ...@@ -63,7 +63,7 @@ describe ApplicationHelper do
end end
it 'gives uploaded icon when present' do it 'gives uploaded icon when present' do
project = create(:project) project = create(:empty_project)
allow_any_instance_of(Project).to receive(:avatar_in_git).and_return(true) allow_any_instance_of(Project).to receive(:avatar_in_git).and_return(true)
......
...@@ -70,7 +70,7 @@ describe BlobHelper do ...@@ -70,7 +70,7 @@ describe BlobHelper do
describe "#edit_blob_link" do describe "#edit_blob_link" do
let(:namespace) { create(:namespace, name: 'gitlab' )} let(:namespace) { create(:namespace, name: 'gitlab' )}
let(:project) { create(:project, namespace: namespace) } let(:project) { create(:project, :repository, namespace: namespace) }
before do before do
allow(self).to receive(:current_user).and_return(double) allow(self).to receive(:current_user).and_return(double)
......
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
describe GitlabMarkdownHelper do describe GitlabMarkdownHelper do
include ApplicationHelper include ApplicationHelper
let!(:project) { create(:project) } let!(:project) { create(:project, :repository) }
let(:user) { create(:user, username: 'gfm') } let(:user) { create(:user, username: 'gfm') }
let(:commit) { project.commit } let(:commit) { project.commit }
...@@ -55,18 +55,19 @@ describe GitlabMarkdownHelper do ...@@ -55,18 +55,19 @@ describe GitlabMarkdownHelper do
end end
describe '#link_to_gfm' do describe '#link_to_gfm' do
let(:commit_path) { namespace_project_commit_path(project.namespace, project, commit) } let(:link) { '/commits/0a1b2c3d' }
let(:issues) { create_list(:issue, 2, project: project) } let(:issues) { create_list(:issue, 2) }
let(:project) { issues.first.project }
it 'handles references nested in links with all the text' do it 'handles references nested in links with all the text' do
actual = helper.link_to_gfm("This should finally fix #{issues[0].to_reference} and #{issues[1].to_reference} for real", commit_path) actual = helper.link_to_gfm("This should finally fix #{issues[0].to_reference} and #{issues[1].to_reference} for real", link)
doc = Nokogiri::HTML.parse(actual) doc = Nokogiri::HTML.parse(actual)
# Make sure we didn't create invalid markup # Make sure we didn't create invalid markup
expect(doc.errors).to be_empty expect(doc.errors).to be_empty
# Leading commit link # Leading commit link
expect(doc.css('a')[0].attr('href')).to eq commit_path expect(doc.css('a')[0].attr('href')).to eq link
expect(doc.css('a')[0].text).to eq 'This should finally fix ' expect(doc.css('a')[0].text).to eq 'This should finally fix '
# First issue link # First issue link
...@@ -75,7 +76,7 @@ describe GitlabMarkdownHelper do ...@@ -75,7 +76,7 @@ describe GitlabMarkdownHelper do
expect(doc.css('a')[1].text).to eq issues[0].to_reference expect(doc.css('a')[1].text).to eq issues[0].to_reference
# Internal commit link # Internal commit link
expect(doc.css('a')[2].attr('href')).to eq commit_path expect(doc.css('a')[2].attr('href')).to eq link
expect(doc.css('a')[2].text).to eq ' and ' expect(doc.css('a')[2].text).to eq ' and '
# Second issue link # Second issue link
...@@ -84,12 +85,12 @@ describe GitlabMarkdownHelper do ...@@ -84,12 +85,12 @@ describe GitlabMarkdownHelper do
expect(doc.css('a')[3].text).to eq issues[1].to_reference expect(doc.css('a')[3].text).to eq issues[1].to_reference
# Trailing commit link # Trailing commit link
expect(doc.css('a')[4].attr('href')).to eq commit_path expect(doc.css('a')[4].attr('href')).to eq link
expect(doc.css('a')[4].text).to eq ' for real' expect(doc.css('a')[4].text).to eq ' for real'
end end
it 'forwards HTML options' do it 'forwards HTML options' do
actual = helper.link_to_gfm("Fixed in #{commit.id}", commit_path, class: 'foo') actual = helper.link_to_gfm("Fixed in #{commit.id}", link, class: 'foo')
doc = Nokogiri::HTML.parse(actual) doc = Nokogiri::HTML.parse(actual)
expect(doc.css('a')).to satisfy do |v| expect(doc.css('a')).to satisfy do |v|
...@@ -100,7 +101,7 @@ describe GitlabMarkdownHelper do ...@@ -100,7 +101,7 @@ describe GitlabMarkdownHelper do
it "escapes HTML passed in as the body" do it "escapes HTML passed in as the body" do
actual = "This is a <h1>test</h1> - see #{issues[0].to_reference}" actual = "This is a <h1>test</h1> - see #{issues[0].to_reference}"
expect(helper.link_to_gfm(actual, commit_path)). expect(helper.link_to_gfm(actual, link)).
to match('&lt;h1&gt;test&lt;/h1&gt;') to match('&lt;h1&gt;test&lt;/h1&gt;')
end end
......
...@@ -2,7 +2,7 @@ require 'spec_helper' ...@@ -2,7 +2,7 @@ require 'spec_helper'
describe GraphHelper do describe GraphHelper do
describe '#get_refs' do describe '#get_refs' do
let(:project) { create(:project) } let(:project) { create(:project, :repository) }
let(:commit) { project.commit("master") } let(:commit) { project.commit("master") }
let(:graph) { Network::Graph.new(project, 'master', commit, '') } let(:graph) { Network::Graph.new(project, 'master', commit, '') }
......
require "spec_helper" require "spec_helper"
describe IssuesHelper do describe IssuesHelper do
let(:project) { create :project } let(:project) { create(:empty_project) }
let(:issue) { create :issue, project: project } let(:issue) { create :issue, project: project }
let(:ext_project) { create :redmine_project } let(:ext_project) { create :redmine_project }
......
...@@ -46,7 +46,7 @@ describe MembersHelper do ...@@ -46,7 +46,7 @@ describe MembersHelper do
end end
describe '#leave_confirmation_message' do describe '#leave_confirmation_message' do
let(:project) { build_stubbed(:project) } let(:project) { build_stubbed(:empty_project) }
let(:group) { build_stubbed(:group) } let(:group) { build_stubbed(:group) }
let(:user) { build_stubbed(:user) } let(:user) { build_stubbed(:user) }
......
...@@ -2,7 +2,7 @@ require 'spec_helper' ...@@ -2,7 +2,7 @@ require 'spec_helper'
describe MergeRequestsHelper do describe MergeRequestsHelper do
describe 'ci_build_details_path' do describe 'ci_build_details_path' do
let(:project) { create :project } let(:project) { create(:empty_project) }
let(:merge_request) { MergeRequest.new } let(:merge_request) { MergeRequest.new }
let(:ci_service) { CiService.new } let(:ci_service) { CiService.new }
let(:last_commit) { Ci::Pipeline.new({}) } let(:last_commit) { Ci::Pipeline.new({}) }
...@@ -30,7 +30,7 @@ describe MergeRequestsHelper do ...@@ -30,7 +30,7 @@ describe MergeRequestsHelper do
it { is_expected.to eq('#1, #2, and #3') } it { is_expected.to eq('#1, #2, and #3') }
context 'for JIRA issues' do context 'for JIRA issues' do
let(:project) { create(:project) } let(:project) { create(:empty_project) }
let(:issues) do let(:issues) do
[ [
ExternalIssue.new('JIRA-123', project), ExternalIssue.new('JIRA-123', project),
...@@ -52,8 +52,8 @@ describe MergeRequestsHelper do ...@@ -52,8 +52,8 @@ describe MergeRequestsHelper do
end end
describe 'within different projects' do describe 'within different projects' do
let(:project) { create(:project) } let(:project) { create(:empty_project) }
let(:fork_project) { create(:project, forked_from_project: project) } let(:fork_project) { create(:empty_project, forked_from_project: project) }
let(:merge_request) { create(:merge_request, source_project: fork_project, target_project: project) } let(:merge_request) { create(:merge_request, source_project: fork_project, target_project: project) }
subject { format_mr_branch_names(merge_request) } subject { format_mr_branch_names(merge_request) }
let(:source_title) { "#{fork_project.path_with_namespace}:#{merge_request.source_branch}" } let(:source_title) { "#{fork_project.path_with_namespace}:#{merge_request.source_branch}" }
...@@ -64,8 +64,8 @@ describe MergeRequestsHelper do ...@@ -64,8 +64,8 @@ describe MergeRequestsHelper do
end end
describe 'mr_widget_refresh_url' do describe 'mr_widget_refresh_url' do
let(:project) { create(:empty_project) }
let(:merge_request) { create(:merge_request, source_project: project) } let(:merge_request) { create(:merge_request, source_project: project) }
let(:project) { create(:project) }
it 'returns correct url for MR' do it 'returns correct url for MR' do
expected_url = "#{project.path_with_namespace}/merge_requests/#{merge_request.iid}/merge_widget_refresh" expected_url = "#{project.path_with_namespace}/merge_requests/#{merge_request.iid}/merge_widget_refresh"
......
...@@ -21,24 +21,22 @@ describe MilestonesHelper do ...@@ -21,24 +21,22 @@ describe MilestonesHelper do
end end
describe '#milestone_counts' do describe '#milestone_counts' do
let(:project) { FactoryGirl.create(:project) } let(:project) { create(:empty_project) }
let(:counts) { helper.milestone_counts(project.milestones) } let(:counts) { helper.milestone_counts(project.milestones) }
context 'when there are milestones' do context 'when there are milestones' do
let!(:milestone_1) { FactoryGirl.create(:active_milestone, project: project) }
let!(:milestone_2) { FactoryGirl.create(:active_milestone, project: project) }
let!(:milestone_3) { FactoryGirl.create(:closed_milestone, project: project) }
it 'returns the correct counts' do it 'returns the correct counts' do
create_list(:active_milestone, 2, project: project)
create(:closed_milestone, project: project)
expect(counts).to eq(opened: 2, closed: 1, all: 3) expect(counts).to eq(opened: 2, closed: 1, all: 3)
end end
end end
context 'when there are only milestones of one type' do context 'when there are only milestones of one type' do
let!(:milestone_1) { FactoryGirl.create(:active_milestone, project: project) }
let!(:milestone_2) { FactoryGirl.create(:active_milestone, project: project) }
it 'returns the correct counts' do it 'returns the correct counts' do
create_list(:active_milestone, 2, project: project)
expect(counts).to eq(opened: 2, closed: 0, all: 2) expect(counts).to eq(opened: 2, closed: 0, all: 2)
end end
end end
......
...@@ -110,7 +110,7 @@ describe PreferencesHelper do ...@@ -110,7 +110,7 @@ describe PreferencesHelper do
end end
context 'when repository is not empty' do context 'when repository is not empty' do
let(:project) { create(:project, :public) } let(:project) { create(:project, :public, :repository) }
it 'returns readme if user has repository access' do it 'returns readme if user has repository access' do
allow(helper).to receive(:can?).with(nil, :download_code, project).and_return(true) allow(helper).to receive(:can?).with(nil, :download_code, project).and_return(true)
......
...@@ -10,7 +10,7 @@ describe ProjectsHelper do ...@@ -10,7 +10,7 @@ describe ProjectsHelper do
end end
describe "can_change_visibility_level?" do describe "can_change_visibility_level?" do
let(:project) { create(:project) } let(:project) { create(:project, :repository) }
let(:user) { create(:project_member, :reporter, user: create(:user), project: project).user } let(:user) { create(:project_member, :reporter, user: create(:user), project: project).user }
let(:fork_project) { Projects::ForkService.new(project, user).execute } let(:fork_project) { Projects::ForkService.new(project, user).execute }
...@@ -97,7 +97,7 @@ describe ProjectsHelper do ...@@ -97,7 +97,7 @@ describe ProjectsHelper do
end end
describe '#license_short_name' do describe '#license_short_name' do
let(:project) { create(:project) } let(:project) { create(:empty_project) }
context 'when project.repository has a license_key' do context 'when project.repository has a license_key' do
it 'returns the nickname of the license if present' do it 'returns the nickname of the license if present' do
......
...@@ -42,7 +42,7 @@ describe SearchHelper do ...@@ -42,7 +42,7 @@ describe SearchHelper do
end end
it "includes the user's projects" do it "includes the user's projects" do
project = create(:project, namespace: create(:namespace, owner: user)) project = create(:empty_project, namespace: create(:namespace, owner: user))
expect(search_autocomplete_opts(project.name).size).to eq(1) expect(search_autocomplete_opts(project.name).size).to eq(1)
end end
...@@ -52,7 +52,9 @@ describe SearchHelper do ...@@ -52,7 +52,9 @@ describe SearchHelper do
end end
context "with a current project" do context "with a current project" do
before { @project = create(:project) } before do
@project = create(:project, :repository)
end
it "includes project-specific sections" do it "includes project-specific sections" do
expect(search_autocomplete_opts("Files").size).to eq(1) expect(search_autocomplete_opts("Files").size).to eq(1)
......
...@@ -116,7 +116,7 @@ describe SubmoduleHelper do ...@@ -116,7 +116,7 @@ describe SubmoduleHelper do
context 'submodules with relative links' do context 'submodules with relative links' do
let(:group) { create(:group, name: "Master Project", path: "master-project") } let(:group) { create(:group, name: "Master Project", path: "master-project") }
let(:project) { create(:project, group: group) } let(:project) { create(:empty_project, group: group) }
let(:commit_id) { sample_commit[:id] } let(:commit_id) { sample_commit[:id] }
before do before do
...@@ -145,7 +145,7 @@ describe SubmoduleHelper do ...@@ -145,7 +145,7 @@ describe SubmoduleHelper do
context 'personal project' do context 'personal project' do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project, namespace: user.namespace) } let(:project) { create(:empty_project, namespace: user.namespace) }
it 'one level down with personal project' do it 'one level down with personal project' do
result = relative_self_links('../test.git', commit_id) result = relative_self_links('../test.git', commit_id)
......
...@@ -2,7 +2,7 @@ require 'spec_helper' ...@@ -2,7 +2,7 @@ require 'spec_helper'
describe TreeHelper do describe TreeHelper do
describe 'flatten_tree' do describe 'flatten_tree' do
let(:project) { create(:project) } let(:project) { create(:project, :repository) }
before do before do
@repository = project.repository @repository = project.repository
......
require 'spec_helper' require 'spec_helper'
describe VisibilityLevelHelper do describe VisibilityLevelHelper do
let(:project) { build(:project) } let(:project) { build(:empty_project) }
let(:group) { build(:group) } let(:group) { build(:group) }
let(:personal_snippet) { build(:personal_snippet) } let(:personal_snippet) { build(:personal_snippet) }
let(:project_snippet) { build(:project_snippet) } let(:project_snippet) { build(:project_snippet) }
...@@ -60,8 +60,8 @@ describe VisibilityLevelHelper do ...@@ -60,8 +60,8 @@ describe VisibilityLevelHelper do
describe "skip_level?" do describe "skip_level?" do
describe "forks" do describe "forks" do
let(:project) { create(:project, :internal) } let(:project) { create(:empty_project, :internal) }
let(:fork_project) { create(:project, forked_from_project: project) } let(:fork_project) { create(:empty_project, forked_from_project: project) }
it "skips levels" do it "skips levels" do
expect(skip_level?(fork_project, Gitlab::VisibilityLevel::PUBLIC)).to be_truthy expect(skip_level?(fork_project, Gitlab::VisibilityLevel::PUBLIC)).to be_truthy
...@@ -71,7 +71,7 @@ describe VisibilityLevelHelper do ...@@ -71,7 +71,7 @@ describe VisibilityLevelHelper do
end end
describe "non-forked project" do describe "non-forked project" do
let(:project) { create(:project, :internal) } let(:project) { create(:empty_project, :internal) }
it "skips levels" do it "skips levels" do
expect(skip_level?(project, Gitlab::VisibilityLevel::PUBLIC)).to be_falsey expect(skip_level?(project, Gitlab::VisibilityLevel::PUBLIC)).to be_falsey
......
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