From 62d7990b9bb30cf33ed87017c5c633d1cccc75c2 Mon Sep 17 00:00:00 2001 From: Toon Claes Date: Thu, 28 Feb 2019 19:57:34 +0100 Subject: Ran standardrb --fix on the whole codebase Inspired by https://twitter.com/searls/status/1101137953743613952 I decided to try https://github.com/testdouble/standard on our codebase. It's opinionated, but at least it's a _standard_. --- spec/helpers/appearances_helper_spec.rb | 40 ++-- spec/helpers/application_helper_spec.rb | 125 +++++----- spec/helpers/application_settings_helper_spec.rb | 18 +- spec/helpers/auth_helper_spec.rb | 56 ++--- spec/helpers/auto_devops_helper_spec.rb | 28 +-- spec/helpers/avatars_helper_spec.rb | 192 ++++++++-------- spec/helpers/award_emoji_helper_spec.rb | 24 +- spec/helpers/blame_helper_spec.rb | 36 +-- spec/helpers/blob_helper_spec.rb | 114 ++++----- spec/helpers/boards_helper_spec.rb | 26 +-- spec/helpers/broadcast_messages_helper_spec.rb | 44 ++-- spec/helpers/button_helper_spec.rb | 134 +++++------ spec/helpers/calendar_helper_spec.rb | 8 +- spec/helpers/ci_status_helper_spec.rb | 48 ++-- spec/helpers/commits_helper_spec.rb | 46 ++-- spec/helpers/components_helper_spec.rb | 16 +- spec/helpers/dashboard_helper_spec.rb | 8 +- spec/helpers/defer_script_tag_helper_spec.rb | 9 +- spec/helpers/diff_helper_spec.rb | 204 ++++++++-------- spec/helpers/emails_helper_spec.rb | 118 +++++----- spec/helpers/events_helper_spec.rb | 60 ++--- spec/helpers/explore_helper_spec.rb | 6 +- spec/helpers/form_helper_spec.rb | 30 +-- spec/helpers/git_helper_spec.rb | 8 +- spec/helpers/gitlab_routing_helper_spec.rb | 44 ++-- spec/helpers/graph_helper_spec.rb | 12 +- spec/helpers/groups_helper_spec.rb | 86 +++---- spec/helpers/hooks_helper_spec.rb | 10 +- spec/helpers/icons_helper_spec.rb | 182 +++++++-------- spec/helpers/import_helper_spec.rb | 38 +-- spec/helpers/instance_configuration_helper_spec.rb | 44 ++-- spec/helpers/issuables_helper_spec.rb | 80 +++---- spec/helpers/issues_helper_spec.rb | 46 ++-- spec/helpers/labels_helper_spec.rb | 172 +++++++------- spec/helpers/markup_helper_spec.rb | 240 +++++++++---------- spec/helpers/members_helper_spec.rb | 16 +- spec/helpers/merge_requests_helper_spec.rb | 26 +-- spec/helpers/milestones_helper_spec.rb | 36 +-- spec/helpers/milestones_routing_helper_spec.rb | 22 +- spec/helpers/namespaces_helper_spec.rb | 32 +-- spec/helpers/nav_helper_spec.rb | 20 +- spec/helpers/notes_helper_spec.rb | 124 +++++----- spec/helpers/notifications_helper_spec.rb | 18 +- spec/helpers/page_layout_helper_spec.rb | 74 +++--- spec/helpers/pagination_helper_spec.rb | 8 +- spec/helpers/preferences_helper_spec.rb | 78 +++---- spec/helpers/profiles_helper_spec.rb | 42 ++-- .../helpers/projects/error_tracking_helper_spec.rb | 28 +-- spec/helpers/projects_helper_spec.rb | 256 ++++++++++----------- spec/helpers/rss_helper_spec.rb | 8 +- spec/helpers/runners_helper_spec.rb | 20 +- spec/helpers/search_helper_spec.rb | 70 +++--- spec/helpers/sidekiq_helper_spec.rb | 58 ++--- spec/helpers/snippets_helper_spec.rb | 22 +- spec/helpers/sorting_helper_spec.rb | 41 ++-- spec/helpers/submodule_helper_spec.rb | 182 +++++++-------- spec/helpers/tab_helper_spec.rb | 54 ++--- spec/helpers/time_helper_spec.rb | 4 +- spec/helpers/todos_helper_spec.rb | 26 +-- spec/helpers/tree_helper_spec.rb | 104 ++++----- spec/helpers/user_callouts_helper_spec.rb | 18 +- spec/helpers/users_helper_spec.rb | 70 +++--- spec/helpers/version_check_helper_spec.rb | 20 +- spec/helpers/visibility_level_helper_spec.rb | 56 ++--- spec/helpers/wiki_helper_spec.rb | 20 +- 65 files changed, 1952 insertions(+), 1953 deletions(-) (limited to 'spec/helpers') diff --git a/spec/helpers/appearances_helper_spec.rb b/spec/helpers/appearances_helper_spec.rb index 8d717b968dd..b8d131dd47c 100644 --- a/spec/helpers/appearances_helper_spec.rb +++ b/spec/helpers/appearances_helper_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" describe AppearancesHelper do before do @@ -8,15 +8,15 @@ describe AppearancesHelper do allow(helper).to receive(:current_user).and_return(user) end - describe '#header_message' do - it 'returns nil when header message field is not set' do + describe "#header_message" do + it "returns nil when header message field is not set" do create(:appearance) expect(helper.header_message).to be_nil end - context 'when header message is set' do - it 'includes current message' do + context "when header message is set" do + it "includes current message" do message = "Foo bar" create(:appearance, header_message: message) @@ -25,15 +25,15 @@ describe AppearancesHelper do end end - describe '#footer_message' do - it 'returns nil when footer message field is not set' do + describe "#footer_message" do + it "returns nil when footer message field is not set" do create(:appearance) expect(helper.footer_message).to be_nil end - context 'when footer message is set' do - it 'includes current message' do + context "when footer message is set" do + it "includes current message" do message = "Foo bar" create(:appearance, footer_message: message) @@ -42,35 +42,35 @@ describe AppearancesHelper do end end - describe '#brand_image' do + describe "#brand_image" do let!(:appearance) { create(:appearance, :with_logo) } - context 'when there is a logo' do - it 'returns a path' do - expect(helper.brand_image).to match(%r(img data-src="/uploads/-/system/appearance/.*png)) + context "when there is a logo" do + it "returns a path" do + expect(helper.brand_image).to match(%r{img data-src="/uploads/-/system/appearance/.*png}) end end - context 'when there is a logo but no associated upload' do + context "when there is a logo but no associated upload" do before do # Legacy attachments were not tracked in the uploads table appearance.logo.upload.destroy appearance.reload end - it 'falls back to using the original path' do - expect(helper.brand_image).to match(%r(img data-src="/uploads/-/system/appearance/.*png)) + it "falls back to using the original path" do + expect(helper.brand_image).to match(%r{img data-src="/uploads/-/system/appearance/.*png}) end end end - describe '#brand_title' do - it 'returns the default CE title when no appearance is present' do + describe "#brand_title" do + it "returns the default CE title when no appearance is present" do allow(helper) .to receive(:current_appearance) - .and_return(nil) + .and_return(nil) - expect(helper.brand_title).to eq('GitLab Community Edition') + expect(helper.brand_title).to eq("GitLab Community Edition") end end end diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index b81249a1e29..2229490410f 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -1,40 +1,39 @@ -# coding: utf-8 -require 'spec_helper' +require "spec_helper" describe ApplicationHelper do - describe 'current_controller?' do + describe "current_controller?" do before do - stub_controller_name('foo') + stub_controller_name("foo") end - it 'returns true when controller matches argument' do + it "returns true when controller matches argument" do expect(helper.current_controller?(:foo)).to be_truthy end - it 'returns false when controller does not match argument' do + it "returns false when controller does not match argument" do expect(helper.current_controller?(:bar)).to be_falsey end - it 'takes any number of arguments' do + it "takes any number of arguments" do expect(helper.current_controller?(:baz, :bar)).to be_falsey expect(helper.current_controller?(:baz, :bar, :foo)).to be_truthy end - context 'when namespaced' do + context "when namespaced" do before do - stub_controller_path('bar/foo') + stub_controller_path("bar/foo") end - it 'returns true when controller matches argument' do + it "returns true when controller matches argument" do expect(helper.current_controller?(:foo)).to be_truthy end - it 'returns true when controller and namespace matches argument in path notation' do - expect(helper.current_controller?('bar/foo')).to be_truthy + it "returns true when controller and namespace matches argument in path notation" do + expect(helper.current_controller?("bar/foo")).to be_truthy end - it 'returns false when namespace doesnt match' do - expect(helper.current_controller?('foo/foo')).to be_falsey + it "returns false when namespace doesnt match" do + expect(helper.current_controller?("foo/foo")).to be_falsey end end @@ -47,20 +46,20 @@ describe ApplicationHelper do end end - describe 'current_action?' do + describe "current_action?" do before do - stub_action_name('foo') + stub_action_name("foo") end - it 'returns true when action matches' do + it "returns true when action matches" do expect(helper.current_action?(:foo)).to be_truthy end - it 'returns false when action does not match' do + it "returns false when action does not match" do expect(helper.current_action?(:bar)).to be_falsey end - it 'takes any number of arguments' do + it "takes any number of arguments" do expect(helper.current_action?(:baz, :bar)).to be_falsey expect(helper.current_action?(:baz, :bar, :foo)).to be_truthy end @@ -70,124 +69,124 @@ describe ApplicationHelper do end end - describe 'simple_sanitize' do + describe "simple_sanitize" do let(:a_tag) { 'Foo' } - it 'allows the a tag' do + it "allows the a tag" do expect(helper.simple_sanitize(a_tag)).to eq(a_tag) end - it 'allows the span tag' do + it "allows the span tag" do input = 'Bar' expect(helper.simple_sanitize(input)).to eq(input) end - it 'disallows other tags' do + it "disallows other tags" do input = "#{a_tag}" expect(helper.simple_sanitize(input)).to eq(a_tag) end end - describe 'time_ago_with_tooltip' do + describe "time_ago_with_tooltip" do def element(*arguments) - Time.zone = 'UTC' - @time = Time.zone.parse('2015-07-02 08:23') + Time.zone = "UTC" + @time = Time.zone.parse("2015-07-02 08:23") element = helper.time_ago_with_tooltip(@time, *arguments) Nokogiri::HTML::DocumentFragment.parse(element).first_element_child end - it 'returns a time element' do - expect(element.name).to eq 'time' + it "returns a time element" do + expect(element.name).to eq "time" end - it 'includes the date string' do + it "includes the date string" do expect(element.text).to eq @time.strftime("%b %d, %Y") end - it 'has a datetime attribute' do - expect(element.attr('datetime')).to eq '2015-07-02T08:23:00Z' + it "has a datetime attribute" do + expect(element.attr("datetime")).to eq "2015-07-02T08:23:00Z" end - it 'has a formatted title attribute' do - expect(element.attr('title')).to eq 'Jul 2, 2015 8:23am' + it "has a formatted title attribute" do + expect(element.attr("title")).to eq "Jul 2, 2015 8:23am" end - it 'includes a default js-timeago class' do - expect(element.attr('class')).to eq 'js-timeago' + it "includes a default js-timeago class" do + expect(element.attr("class")).to eq "js-timeago" end - it 'accepts a custom html_class' do - expect(element(html_class: 'custom_class').attr('class')).to eq 'js-timeago custom_class' + it "accepts a custom html_class" do + expect(element(html_class: "custom_class").attr("class")).to eq "js-timeago custom_class" end - it 'accepts a custom tooltip placement' do - expect(element(placement: 'bottom').attr('data-placement')).to eq 'bottom' + it "accepts a custom tooltip placement" do + expect(element(placement: "bottom").attr("data-placement")).to eq "bottom" end - it 'converts to Time' do + it "converts to Time" do expect { helper.time_ago_with_tooltip(Date.today) }.not_to raise_error end - it 'add class for the short format' do - timeago_element = element(short_format: 'short') + it "add class for the short format" do + timeago_element = element(short_format: "short") - expect(timeago_element.attr('class')).to eq 'js-short-timeago' + expect(timeago_element.attr("class")).to eq "js-short-timeago" expect(timeago_element.next_element).to eq nil end end - describe '#active_when' do - it { expect(helper.active_when(true)).to eq('active') } + describe "#active_when" do + it { expect(helper.active_when(true)).to eq("active") } it { expect(helper.active_when(false)).to eq(nil) } end - describe '#support_url' do - context 'when alternate support url is specified' do - let(:alternate_url) { 'http://company.example.com/getting-help' } + describe "#support_url" do + context "when alternate support url is specified" do + let(:alternate_url) { "http://company.example.com/getting-help" } - it 'returns the alternate support url' do + it "returns the alternate support url" do stub_application_setting(help_page_support_url: alternate_url) expect(helper.support_url).to eq(alternate_url) end end - context 'when alternate support url is not specified' do - it 'builds the support url from the promo_url' do - expect(helper.support_url).to eq(helper.promo_url + '/getting-help/') + context "when alternate support url is not specified" do + it "builds the support url from the promo_url" do + expect(helper.support_url).to eq(helper.promo_url + "/getting-help/") end end end - describe '#locale_path' do - it 'returns the locale path with an `_`' do - Gitlab::I18n.with_locale('pt-BR') do - expect(helper.locale_path).to include('assets/locale/pt_BR/app') + describe "#locale_path" do + it "returns the locale path with an `_`" do + Gitlab::I18n.with_locale("pt-BR") do + expect(helper.locale_path).to include("assets/locale/pt_BR/app") end end end - describe '#client_class_list' do - it 'returns string containing CSS classes representing client browser and platform' do + describe "#client_class_list" do + it "returns string containing CSS classes representing client browser and platform" do class_list = helper.client_class_list - expect(class_list).to eq('gl-browser-generic gl-platform-other') + expect(class_list).to eq("gl-browser-generic gl-platform-other") end end - describe '#client_js_flags' do - it 'returns map containing JS flags representing client browser and platform' do + describe "#client_js_flags" do + it "returns map containing JS flags representing client browser and platform" do flags_list = helper.client_js_flags expect(flags_list[:isGeneric]).to eq(true) expect(flags_list[:isOther]).to eq(true) end end - describe '#autocomplete_data_sources' do + describe "#autocomplete_data_sources" do let(:project) { create(:project) } let(:noteable_type) { Issue } - it 'returns paths for autocomplete_sources_controller' do + it "returns paths for autocomplete_sources_controller" do sources = helper.autocomplete_data_sources(project, noteable_type) expect(sources.keys).to match_array([:members, :issues, :mergeRequests, :labels, :milestones, :commands, :snippets]) sources.keys.each do |key| diff --git a/spec/helpers/application_settings_helper_spec.rb b/spec/helpers/application_settings_helper_spec.rb index 705523f1110..bec7bbb7923 100644 --- a/spec/helpers/application_settings_helper_spec.rb +++ b/spec/helpers/application_settings_helper_spec.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" describe ApplicationSettingsHelper do - context 'when all protocols in use' do + context "when all protocols in use" do before do - stub_application_setting(enabled_git_access_protocol: '') + stub_application_setting(enabled_git_access_protocol: "") end it { expect(all_protocols_enabled?).to be_truthy } @@ -13,9 +13,9 @@ describe ApplicationSettingsHelper do it { expect(ssh_enabled?).to be_truthy } end - context 'when SSH is only in use' do + context "when SSH is only in use" do before do - stub_application_setting(enabled_git_access_protocol: 'ssh') + stub_application_setting(enabled_git_access_protocol: "ssh") end it { expect(all_protocols_enabled?).to be_falsey } @@ -23,10 +23,10 @@ describe ApplicationSettingsHelper do it { expect(ssh_enabled?).to be_truthy } end - shared_examples 'when HTTP protocol is in use' do |protocol| + shared_examples "when HTTP protocol is in use" do |protocol| before do allow(Gitlab.config.gitlab).to receive(:protocol).and_return(protocol) - stub_application_setting(enabled_git_access_protocol: 'http') + stub_application_setting(enabled_git_access_protocol: "http") end it { expect(all_protocols_enabled?).to be_falsey } @@ -34,6 +34,6 @@ describe ApplicationSettingsHelper do it { expect(ssh_enabled?).to be_falsey } end - it_behaves_like 'when HTTP protocol is in use', 'https' - it_behaves_like 'when HTTP protocol is in use', 'http' + it_behaves_like "when HTTP protocol is in use", "https" + it_behaves_like "when HTTP protocol is in use", "http" end diff --git a/spec/helpers/auth_helper_spec.rb b/spec/helpers/auth_helper_spec.rb index f0c2e4768ec..04c69d80734 100644 --- a/spec/helpers/auth_helper_spec.rb +++ b/spec/helpers/auth_helper_spec.rb @@ -2,48 +2,48 @@ require "spec_helper" describe AuthHelper do describe "button_based_providers" do - it 'returns all enabled providers from devise' do + it "returns all enabled providers from devise" do allow(helper).to receive(:auth_providers) { [:twitter, :github] } - expect(helper.button_based_providers).to include(*[:twitter, :github]) + expect(helper.button_based_providers).to include(:twitter, :github) end - it 'does not return ldap provider' do + it "does not return ldap provider" do allow(helper).to receive(:auth_providers) { [:twitter, :ldapmain] } expect(helper.button_based_providers).to include(:twitter) end - it 'returns empty array' do + it "returns empty array" do allow(helper).to receive(:auth_providers) { [] } expect(helper.button_based_providers).to eq([]) end end describe "providers_for_base_controller" do - it 'returns all enabled providers from devise' do + it "returns all enabled providers from devise" do allow(helper).to receive(:auth_providers) { [:twitter, :github] } - expect(helper.providers_for_base_controller).to include(*[:twitter, :github]) + expect(helper.providers_for_base_controller).to include(:twitter, :github) end - it 'excludes ldap providers' do + it "excludes ldap providers" do allow(helper).to receive(:auth_providers) { [:twitter, :ldapmain] } expect(helper.providers_for_base_controller).not_to include(:ldapmain) end end describe "form_based_providers" do - it 'includes LDAP providers' do + it "includes LDAP providers" do allow(helper).to receive(:auth_providers) { [:twitter, :ldapmain] } - expect(helper.form_based_providers).to eq %i(ldapmain) + expect(helper.form_based_providers).to eq %i[ldapmain] end - it 'includes crowd provider' do + it "includes crowd provider" do allow(helper).to receive(:auth_providers) { [:twitter, :crowd] } - expect(helper.form_based_providers).to eq %i(crowd) + expect(helper.form_based_providers).to eq %i[crowd] end end - describe 'form_based_auth_provider_has_active_class?' do - it 'selects main LDAP server' do + describe "form_based_auth_provider_has_active_class?" do + it "selects main LDAP server" do allow(helper).to receive(:auth_providers) { [:twitter, :ldapprimary, :ldapsecondary, :kerberos] } expect(helper.form_based_auth_provider_has_active_class?(:twitter)).to be(false) expect(helper.form_based_auth_provider_has_active_class?(:ldapprimary)).to be(true) @@ -52,44 +52,44 @@ describe AuthHelper do end end - describe 'enabled_button_based_providers' do + describe "enabled_button_based_providers" do before do allow(helper).to receive(:auth_providers) { [:twitter, :github] } end - context 'all providers are enabled to sign in' do - it 'returns all the enabled providers from settings' do - expect(helper.enabled_button_based_providers).to include('twitter', 'github') + context "all providers are enabled to sign in" do + it "returns all the enabled providers from settings" do + expect(helper.enabled_button_based_providers).to include("twitter", "github") end end - context 'GitHub OAuth sign in is disabled from application setting' do + context "GitHub OAuth sign in is disabled from application setting" do it "doesn't return github as provider" do stub_application_setting( - disabled_oauth_sign_in_sources: ['github'] + disabled_oauth_sign_in_sources: ["github"] ) - expect(helper.enabled_button_based_providers).to include('twitter') - expect(helper.enabled_button_based_providers).not_to include('github') + expect(helper.enabled_button_based_providers).to include("twitter") + expect(helper.enabled_button_based_providers).not_to include("github") end end end - describe 'button_based_providers_enabled?' do + describe "button_based_providers_enabled?" do before do allow(helper).to receive(:auth_providers) { [:twitter, :github] } end - context 'button based providers enabled' do - it 'returns true' do + context "button based providers enabled" do + it "returns true" do expect(helper.button_based_providers_enabled?).to be true end end - context 'all the button based providers are disabled via application_setting' do - it 'returns false' do + context "all the button based providers are disabled via application_setting" do + it "returns false" do stub_application_setting( - disabled_oauth_sign_in_sources: %w(github twitter) + disabled_oauth_sign_in_sources: %w[github twitter] ) expect(helper.button_based_providers_enabled?).to be false @@ -97,7 +97,7 @@ describe AuthHelper do end end - describe 'unlink_allowed?' do + describe "unlink_allowed?" do [:saml, :cas3].each do |provider| it "returns true if the provider is #{provider}" do expect(helper.unlink_allowed?(provider)).to be false diff --git a/spec/helpers/auto_devops_helper_spec.rb b/spec/helpers/auto_devops_helper_spec.rb index 223e562238d..21ce44e40ba 100644 --- a/spec/helpers/auto_devops_helper_spec.rb +++ b/spec/helpers/auto_devops_helper_spec.rb @@ -1,10 +1,10 @@ -require 'spec_helper' +require "spec_helper" describe AutoDevopsHelper do set(:project) { create(:project) } set(:user) { create(:user) } - describe '.show_auto_devops_callout?' do + describe ".show_auto_devops_callout?" do let(:allowed) { true } before do @@ -16,11 +16,11 @@ describe AutoDevopsHelper do subject { helper.show_auto_devops_callout?(project) } - context 'when auto devops is implicitly enabled' do + context "when auto devops is implicitly enabled" do it { is_expected.to eq(false) } end - context 'when auto devops is not implicitly enabled' do + context "when auto devops is not implicitly enabled" do before do Gitlab::CurrentSettings.update!(auto_devops_enabled: false) end @@ -28,29 +28,29 @@ describe AutoDevopsHelper do it { is_expected.to eq(true) } end - context 'when the banner is disabled by feature flag' do - it 'allows the feature flag to disable' do + context "when the banner is disabled by feature flag" do + it "allows the feature flag to disable" do Feature.get(:auto_devops_banner_disabled).enable expect(subject).to be(false) end end - context 'when dismissed' do + context "when dismissed" do before do - helper.request.cookies[:auto_devops_settings_dismissed] = 'true' + helper.request.cookies[:auto_devops_settings_dismissed] = "true" end it { is_expected.to eq(false) } end - context 'when user cannot admin project' do + context "when user cannot admin project" do let(:allowed) { false } it { is_expected.to eq(false) } end - context 'when auto devops is enabled system-wide' do + context "when auto devops is enabled system-wide" do before do stub_application_setting(auto_devops_enabled: true) end @@ -58,7 +58,7 @@ describe AutoDevopsHelper do it { is_expected.to eq(false) } end - context 'when auto devops is explicitly enabled for project' do + context "when auto devops is explicitly enabled for project" do before do project.create_auto_devops!(enabled: true) end @@ -66,7 +66,7 @@ describe AutoDevopsHelper do it { is_expected.to eq(false) } end - context 'when auto devops is explicitly disabled for project' do + context "when auto devops is explicitly disabled for project" do before do project.create_auto_devops!(enabled: false) end @@ -74,7 +74,7 @@ describe AutoDevopsHelper do it { is_expected.to eq(false) } end - context 'when master contains a .gitlab-ci.yml file' do + context "when master contains a .gitlab-ci.yml file" do before do allow(project.repository).to receive(:gitlab_ci_yml).and_return("script: ['test']") end @@ -82,7 +82,7 @@ describe AutoDevopsHelper do it { is_expected.to eq(false) } end - context 'when another service is enabled' do + context "when another service is enabled" do before do create(:service, project: project, category: :ci, active: true) end diff --git a/spec/helpers/avatars_helper_spec.rb b/spec/helpers/avatars_helper_spec.rb index aa0442ab847..122ee9dc476 100644 --- a/spec/helpers/avatars_helper_spec.rb +++ b/spec/helpers/avatars_helper_spec.rb @@ -1,87 +1,87 @@ -require 'rails_helper' +require "rails_helper" describe AvatarsHelper do include UploadHelpers let(:user) { create(:user) } - describe '#project_icon & #group_icon' do - shared_examples 'resource with a default avatar' do |source_type| - it 'returns a default avatar div' do + describe "#project_icon & #group_icon" do + shared_examples "resource with a default avatar" do |source_type| + it "returns a default avatar div" do expect(public_send("#{source_type}_icon", *helper_args)) .to match(%r{
F
}) end end - shared_examples 'resource with a custom avatar' do |source_type| - it 'returns a custom avatar image' do + shared_examples "resource with a custom avatar" do |source_type| + it "returns a custom avatar image" do expect(public_send("#{source_type}_icon", *helper_args)) .to eq "\"Banana" end end - context 'when providing a project' do - it_behaves_like 'resource with a default avatar', 'project' do - let(:resource) { create(:project, name: 'foo') } + context "when providing a project" do + it_behaves_like "resource with a default avatar", "project" do + let(:resource) { create(:project, name: "foo") } let(:helper_args) { [resource] } end - it_behaves_like 'resource with a custom avatar', 'project' do + it_behaves_like "resource with a custom avatar", "project" do let(:resource) { create(:project, :public, avatar: File.open(uploaded_image_temp_path)) } let(:helper_args) { [resource] } end end - context 'when providing a group' do - it_behaves_like 'resource with a default avatar', 'group' do - let(:resource) { create(:group, name: 'foo') } + context "when providing a group" do + it_behaves_like "resource with a default avatar", "group" do + let(:resource) { create(:group, name: "foo") } let(:helper_args) { [resource] } end - it_behaves_like 'resource with a custom avatar', 'group' do + it_behaves_like "resource with a custom avatar", "group" do let(:resource) { create(:group, avatar: File.open(uploaded_image_temp_path)) } let(:helper_args) { [resource] } end end end - describe '#avatar_icon_for' do - let!(:user) { create(:user, avatar: File.open(uploaded_image_temp_path), email: 'bar@example.com') } - let(:email) { 'foo@example.com' } + describe "#avatar_icon_for" do + let!(:user) { create(:user, avatar: File.open(uploaded_image_temp_path), email: "bar@example.com") } + let(:email) { "foo@example.com" } let!(:another_user) { create(:user, avatar: File.open(uploaded_image_temp_path), email: email) } - it 'prefers the user to retrieve the avatar_url' do + it "prefers the user to retrieve the avatar_url" do expect(helper.avatar_icon_for(user, email).to_s) .to eq(user.avatar.url) end - it 'falls back to email lookup if no user given' do + it "falls back to email lookup if no user given" do expect(helper.avatar_icon_for(nil, email).to_s) .to eq(another_user.avatar.url) end end - describe '#avatar_icon_for_email' do + describe "#avatar_icon_for_email" do let(:user) { create(:user, avatar: File.open(uploaded_image_temp_path)) } - context 'using an email' do - context 'when there is a matching user' do - it 'returns a relative URL for the avatar' do + context "using an email" do + context "when there is a matching user" do + it "returns a relative URL for the avatar" do expect(helper.avatar_icon_for_email(user.email).to_s) .to eq(user.avatar.url) end end - context 'when no user exists for the email' do - it 'calls gravatar_icon' do - expect(helper).to receive(:gravatar_icon).with('foo@example.com', 20, 2) + context "when no user exists for the email" do + it "calls gravatar_icon" do + expect(helper).to receive(:gravatar_icon).with("foo@example.com", 20, 2) - helper.avatar_icon_for_email('foo@example.com', 20, 2) + helper.avatar_icon_for_email("foo@example.com", 20, 2) end end - context 'without an email passed' do - it 'calls gravatar_icon' do + context "without an email passed" do + it "calls gravatar_icon" do expect(helper).to receive(:gravatar_icon).with(nil, 20, 2) helper.avatar_icon_for_email(nil, 20, 2) @@ -90,18 +90,18 @@ describe AvatarsHelper do end end - describe '#avatar_icon_for_user' do + describe "#avatar_icon_for_user" do let(:user) { create(:user, avatar: File.open(uploaded_image_temp_path)) } - context 'with a user object passed' do - it 'returns a relative URL for the avatar' do + context "with a user object passed" do + it "returns a relative URL for the avatar" do expect(helper.avatar_icon_for_user(user).to_s) .to eq(user.avatar.url) end end - context 'without a user object passed' do - it 'calls gravatar_icon' do + context "without a user object passed" do + it "calls gravatar_icon" do expect(helper).to receive(:gravatar_icon).with(nil, 20, 2) helper.avatar_icon_for_user(nil, 20, 2) @@ -109,71 +109,71 @@ describe AvatarsHelper do end end - describe '#gravatar_icon' do - let(:user_email) { 'user@email.com' } + describe "#gravatar_icon" do + let(:user_email) { "user@email.com" } - context 'with Gravatar disabled' do + context "with Gravatar disabled" do before do stub_application_setting(gravatar_enabled?: false) end - it 'returns a generic avatar' do - expect(helper.gravatar_icon(user_email)).to match_asset_path('no_avatar.png') + it "returns a generic avatar" do + expect(helper.gravatar_icon(user_email)).to match_asset_path("no_avatar.png") end end - context 'with Gravatar enabled' do + context "with Gravatar enabled" do before do stub_application_setting(gravatar_enabled?: true) end - it 'returns a generic avatar when email is blank' do - expect(helper.gravatar_icon('')).to match_asset_path('no_avatar.png') + it "returns a generic avatar when email is blank" do + expect(helper.gravatar_icon("")).to match_asset_path("no_avatar.png") end - it 'returns a valid Gravatar URL' do + it "returns a valid Gravatar URL" do stub_config_setting(https: false) expect(helper.gravatar_icon(user_email)) - .to match('https://www.gravatar.com/avatar/b58c6f14d292556214bd64909bcdb118') + .to match("https://www.gravatar.com/avatar/b58c6f14d292556214bd64909bcdb118") end - it 'uses HTTPs when configured' do + it "uses HTTPs when configured" do stub_config_setting(https: true) expect(helper.gravatar_icon(user_email)) - .to match('https://secure.gravatar.com') + .to match("https://secure.gravatar.com") end - it 'returns custom gravatar path when gravatar_url is set' do - stub_gravatar_setting(plain_url: 'http://example.local/?s=%{size}&hash=%{hash}') + it "returns custom gravatar path when gravatar_url is set" do + stub_gravatar_setting(plain_url: "http://example.local/?s=%{size}&hash=%{hash}") expect(gravatar_icon(user_email, 20)) - .to eq('http://example.local/?s=40&hash=b58c6f14d292556214bd64909bcdb118') + .to eq("http://example.local/?s=40&hash=b58c6f14d292556214bd64909bcdb118") end - it 'accepts a custom size argument' do - expect(helper.gravatar_icon(user_email, 64)).to include '?s=128' + it "accepts a custom size argument" do + expect(helper.gravatar_icon(user_email, 64)).to include "?s=128" end - it 'defaults size to 40@2x when given an invalid size' do - expect(helper.gravatar_icon(user_email, nil)).to include '?s=80' + it "defaults size to 40@2x when given an invalid size" do + expect(helper.gravatar_icon(user_email, nil)).to include "?s=80" end - it 'accepts a scaling factor' do - expect(helper.gravatar_icon(user_email, 40, 3)).to include '?s=120' + it "accepts a scaling factor" do + expect(helper.gravatar_icon(user_email, 40, 3)).to include "?s=120" end - it 'ignores case and surrounding whitespace' do - normal = helper.gravatar_icon('foo@example.com') - upcase = helper.gravatar_icon(' FOO@EXAMPLE.COM ') + it "ignores case and surrounding whitespace" do + normal = helper.gravatar_icon("foo@example.com") + upcase = helper.gravatar_icon(" FOO@EXAMPLE.COM ") expect(normal).to eq upcase end end end - describe '#user_avatar' do + describe "#user_avatar" do subject { helper.user_avatar(user: user) } it "links to the user's profile" do @@ -189,101 +189,101 @@ describe AvatarsHelper do end end - describe '#user_avatar_without_link' do - let(:options) { { user: user } } + describe "#user_avatar_without_link" do + let(:options) { {user: user} } subject { helper.user_avatar_without_link(options) } - it 'displays user avatar' do + it "displays user avatar" do is_expected.to eq tag( :img, alt: "#{user.name}'s avatar", src: avatar_icon_for_user(user, 16), - data: { container: 'body' }, - class: 'avatar s16 has-tooltip', + data: {container: "body"}, + class: "avatar s16 has-tooltip", title: user.name ) end - context 'with css_class parameter' do - let(:options) { { user: user, css_class: '.cat-pics' } } + context "with css_class parameter" do + let(:options) { {user: user, css_class: ".cat-pics"} } - it 'uses provided css_class' do + it "uses provided css_class" do is_expected.to eq tag( :img, alt: "#{user.name}'s avatar", src: avatar_icon_for_user(user, 16), - data: { container: 'body' }, + data: {container: "body"}, class: "avatar s16 #{options[:css_class]} has-tooltip", title: user.name ) end end - context 'with size parameter' do - let(:options) { { user: user, size: 99 } } + context "with size parameter" do + let(:options) { {user: user, size: 99} } - it 'uses provided size' do + it "uses provided size" do is_expected.to eq tag( :img, alt: "#{user.name}'s avatar", src: avatar_icon_for_user(user, options[:size]), - data: { container: 'body' }, + data: {container: "body"}, class: "avatar s#{options[:size]} has-tooltip", title: user.name ) end end - context 'with url parameter' do - let(:options) { { user: user, url: '/over/the/rainbow.png' } } + context "with url parameter" do + let(:options) { {user: user, url: "/over/the/rainbow.png"} } - it 'uses provided url' do + it "uses provided url" do is_expected.to eq tag( :img, alt: "#{user.name}'s avatar", src: options[:url], - data: { container: 'body' }, + data: {container: "body"}, class: "avatar s16 has-tooltip", title: user.name ) end end - context 'with lazy parameter' do - let(:options) { { user: user, lazy: true } } + context "with lazy parameter" do + let(:options) { {user: user, lazy: true} } - it 'adds `lazy` class to class list, sets `data-src` with avatar URL and `src` with placeholder image' do + it "adds `lazy` class to class list, sets `data-src` with avatar URL and `src` with placeholder image" do is_expected.to eq tag( :img, alt: "#{user.name}'s avatar", src: LazyImageTagHelper.placeholder_image, - data: { container: 'body', src: avatar_icon_for_user(user, 16) }, + data: {container: "body", src: avatar_icon_for_user(user, 16)}, class: "avatar s16 has-tooltip lazy", title: user.name ) end end - context 'with has_tooltip parameter' do - context 'with has_tooltip set to true' do - let(:options) { { user: user, has_tooltip: true } } + context "with has_tooltip parameter" do + context "with has_tooltip set to true" do + let(:options) { {user: user, has_tooltip: true} } - it 'adds has-tooltip' do + it "adds has-tooltip" do is_expected.to eq tag( :img, alt: "#{user.name}'s avatar", src: avatar_icon_for_user(user, 16), - data: { container: 'body' }, + data: {container: "body"}, class: "avatar s16 has-tooltip", title: user.name ) end end - context 'with has_tooltip set to false' do - let(:options) { { user: user, has_tooltip: false } } + context "with has_tooltip set to false" do + let(:options) { {user: user, has_tooltip: false} } - it 'does not add has-tooltip or data container' do + it "does not add has-tooltip or data container" do is_expected.to eq tag( :img, alt: "#{user.name}'s avatar", @@ -295,30 +295,30 @@ describe AvatarsHelper do end end - context 'with user_name parameter' do - let(:options) { { user_name: 'Tinky Winky', user_email: 'no@f.un' } } + context "with user_name parameter" do + let(:options) { {user_name: "Tinky Winky", user_email: "no@f.un"} } - context 'with user parameter' do - let(:options) { { user: user, user_name: 'Tinky Winky' } } + context "with user parameter" do + let(:options) { {user: user, user_name: "Tinky Winky"} } - it 'prefers user parameter' do + it "prefers user parameter" do is_expected.to eq tag( :img, alt: "#{user.name}'s avatar", src: avatar_icon_for_user(user, 16), - data: { container: 'body' }, + data: {container: "body"}, class: "avatar s16 has-tooltip", title: user.name ) end end - it 'uses user_name and user_email parameter if user is not present' do + it "uses user_name and user_email parameter if user is not present" do is_expected.to eq tag( :img, alt: "#{options[:user_name]}'s avatar", src: avatar_icon_for_email(options[:user_email], 16), - data: { container: 'body' }, + data: {container: "body"}, class: "avatar s16 has-tooltip", title: options[:user_name] ) diff --git a/spec/helpers/award_emoji_helper_spec.rb b/spec/helpers/award_emoji_helper_spec.rb index 035960ed96e..5ec08901b58 100644 --- a/spec/helpers/award_emoji_helper_spec.rb +++ b/spec/helpers/award_emoji_helper_spec.rb @@ -1,21 +1,21 @@ -require 'spec_helper' +require "spec_helper" describe AwardEmojiHelper do - describe '.toggle_award_url' do - context 'note on personal snippet' do + describe ".toggle_award_url" do + context "note on personal snippet" do let(:note) { create(:note_on_personal_snippet) } - it 'returns correct url' do + it "returns correct url" do expected_url = "/snippets/#{note.noteable.id}/notes/#{note.id}/toggle_award_emoji" expect(helper.toggle_award_url(note)).to eq(expected_url) end end - context 'note on project item' do + context "note on project item" do let(:note) { create(:note_on_project_snippet) } - it 'returns correct url' do + it "returns correct url" do @project = note.noteable.project expected_url = "/#{@project.namespace.path}/#{@project.path}/notes/#{note.id}/toggle_award_emoji" @@ -24,20 +24,20 @@ describe AwardEmojiHelper do end end - context 'personal snippet' do + context "personal snippet" do let(:snippet) { create(:personal_snippet) } - it 'returns correct url' do + it "returns correct url" do expected_url = "/snippets/#{snippet.id}/toggle_award_emoji" expect(helper.toggle_award_url(snippet)).to eq(expected_url) end end - context 'merge request' do + context "merge request" do let(:merge_request) { create(:merge_request) } - it 'returns correct url' do + it "returns correct url" do @project = merge_request.project expected_url = "/#{@project.namespace.path}/#{@project.path}/merge_requests/#{merge_request.iid}/toggle_award_emoji" @@ -46,10 +46,10 @@ describe AwardEmojiHelper do end end - context 'issue' do + context "issue" do let(:issue) { create(:issue) } - it 'returns correct url' do + it "returns correct url" do @project = issue.project expected_url = "/#{@project.namespace.path}/#{@project.path}/issues/#{issue.iid}/toggle_award_emoji" diff --git a/spec/helpers/blame_helper_spec.rb b/spec/helpers/blame_helper_spec.rb index 722d21c566f..00003d912e1 100644 --- a/spec/helpers/blame_helper_spec.rb +++ b/spec/helpers/blame_helper_spec.rb @@ -1,23 +1,23 @@ -require 'spec_helper' +require "spec_helper" describe BlameHelper do - describe '#get_age_map_start_date' do + describe "#get_age_map_start_date" do let(:dates) do [Time.zone.local(2014, 3, 17, 0, 0, 0), Time.zone.local(2011, 11, 2, 0, 0, 0), Time.zone.local(2015, 7, 9, 0, 0, 0), Time.zone.local(2013, 2, 24, 0, 0, 0), - Time.zone.local(2010, 9, 22, 0, 0, 0)] + Time.zone.local(2010, 9, 22, 0, 0, 0),] end let(:blame_groups) do [ - { commit: double(committed_date: dates[0]) }, - { commit: double(committed_date: dates[1]) }, - { commit: double(committed_date: dates[2]) } + {commit: double(committed_date: dates[0])}, + {commit: double(committed_date: dates[1])}, + {commit: double(committed_date: dates[2])}, ] end - it 'returns the earliest date from a blame group' do + it "returns the earliest date from a blame group" do project = double(created_at: dates[3]) duration = helper.age_map_duration(blame_groups, project) @@ -25,7 +25,7 @@ describe BlameHelper do expect(duration[:started_days_ago]).to eq((duration[:now] - dates[1]).to_i / 1.day) end - it 'returns the earliest date from a project' do + it "returns the earliest date from a project" do project = double(created_at: dates[4]) duration = helper.age_map_duration(blame_groups, project) @@ -34,32 +34,32 @@ describe BlameHelper do end end - describe '#age_map_class' do + describe "#age_map_class" do let(:date) { Time.zone.local(2014, 3, 17, 0, 0, 0) } - let(:blame_groups) { [{ commit: double(committed_date: date) }] } + let(:blame_groups) { [{commit: double(committed_date: date)}] } let(:duration) do project = double(created_at: date) helper.age_map_duration(blame_groups, project) end - it 'returns blame-commit-age-9 when oldest' do - expect(helper.age_map_class(date, duration)).to eq 'blame-commit-age-9' + it "returns blame-commit-age-9 when oldest" do + expect(helper.age_map_class(date, duration)).to eq "blame-commit-age-9" end - it 'returns blame-commit-age-0 class when newest' do - expect(helper.age_map_class(duration[:now], duration)).to eq 'blame-commit-age-0' + it "returns blame-commit-age-0 class when newest" do + expect(helper.age_map_class(duration[:now], duration)).to eq "blame-commit-age-0" end - context 'when called on the same day as project creation' do + context "when called on the same day as project creation" do let(:same_day_duration) do project = double(created_at: now) helper.age_map_duration(today_blame_groups, project) end - let(:today_blame_groups) { [{ commit: double(committed_date: now) }] } + let(:today_blame_groups) { [{commit: double(committed_date: now)}] } let(:now) { Time.zone.now } - it 'returns blame-commit-age-0 class' do - expect(helper.age_map_class(duration[:now], same_day_duration)).to eq 'blame-commit-age-0' + it "returns blame-commit-age-0 class" do + expect(helper.age_map_class(duration[:now], same_day_duration)).to eq "blame-commit-age-0" end end end diff --git a/spec/helpers/blob_helper_spec.rb b/spec/helpers/blob_helper_spec.rb index 2bc3933809f..8be0a360b6d 100644 --- a/spec/helpers/blob_helper_spec.rb +++ b/spec/helpers/blob_helper_spec.rb @@ -1,31 +1,31 @@ -require 'spec_helper' +require "spec_helper" describe BlobHelper do include TreeHelper - describe '#highlight' do - it 'wraps highlighted content' do - expect(helper.highlight('test.rb', '52')).to eq(%q[
52
]) + describe "#highlight" do + it "wraps highlighted content" do + expect(helper.highlight("test.rb", "52")).to eq('
52
') end - it 'handles plain version' do - expect(helper.highlight('test.rb', '52', plain: true)).to eq(%q[
52
]) + it "handles plain version" do + expect(helper.highlight("test.rb", "52", plain: true)).to eq('
52
') end end describe "#sanitize_svg_data" do - let(:input_svg_path) { File.join(Rails.root, 'spec', 'fixtures', 'unsanitized.svg') } + let(:input_svg_path) { File.join(Rails.root, "spec", "fixtures", "unsanitized.svg") } let(:data) { File.read(input_svg_path) } - let(:expected_svg_path) { File.join(Rails.root, 'spec', 'fixtures', 'sanitized.svg') } + let(:expected_svg_path) { File.join(Rails.root, "spec", "fixtures", "sanitized.svg") } let(:expected) { File.read(expected_svg_path) } - it 'retains essential elements' do + it "retains essential elements" do expect(sanitize_svg_data(data)).to eq(expected) end end describe "#edit_blob_link" do - let(:namespace) { create(:namespace, name: 'gitlab' )} + let(:namespace) { create(:namespace, name: "gitlab")} let(:project) { create(:project, :repository, namespace: namespace) } before do @@ -33,44 +33,44 @@ describe BlobHelper do allow(self).to receive(:can_collaborate_with_project?).and_return(true) end - it 'verifies blob is text' do + it "verifies blob is text" do expect(helper).not_to receive(:blob_text_viewable?) - button = edit_blob_button(project, 'refs/heads/master', 'README.md') + button = edit_blob_button(project, "refs/heads/master", "README.md") - expect(button).to start_with('alert("XSS")') - commit = double(author: user, author_name: '', author_email: '') + commit = double(author: user, author_name: "", author_email: "") expect(helper.commit_author_link(commit)) - .to include('Foo <script>') + .to include("Foo <script>") expect(helper.commit_author_link(commit, avatar: true)) - .to include('commit-author-name', 'js-user-link', 'Foo <script>') + .to include("commit-author-name", "js-user-link", "Foo <script>") end end - describe 'commit_committer_link' do - it 'escapes the committer email' do + describe "commit_committer_link" do + it "escapes the committer email" do commit = double( committer: nil, - committer_name: 'Persistent XSS', + committer_name: "Persistent XSS", committer_email: 'my@email.com" onmouseover="alert(1)' ) @@ -37,34 +37,34 @@ describe CommitsHelper do .not_to include('onmouseover="alert(1)"') end - it 'escapes the committer name' do + it "escapes the committer name" do user = build_stubbed(:user, name: 'Foo ') - commit = double(committer: user, committer_name: '', committer_email: '') + commit = double(committer: user, committer_name: "", committer_email: "") expect(helper.commit_committer_link(commit)) - .to include('Foo <script>') + .to include("Foo <script>") expect(helper.commit_committer_link(commit, avatar: true)) - .to include('commit-committer-name', 'Foo <script>') + .to include("commit-committer-name", "Foo <script>") end end - describe '#view_on_environment_button' do + describe "#view_on_environment_button" do let(:project) { create(:project) } - let(:environment) { create(:environment, external_url: 'http://example.com') } - let(:path) { 'source/file.html' } + let(:environment) { create(:environment, external_url: "http://example.com") } + let(:path) { "source/file.html" } let(:sha) { RepoHelpers.sample_commit.id } before do - allow(environment).to receive(:external_url_for).with(path, sha).and_return('http://example.com/file.html') + allow(environment).to receive(:external_url_for).with(path, sha).and_return("http://example.com/file.html") end - it 'returns a link tag linking to the file in the environment' do + it "returns a link tag linking to the file in the environment" do html = helper.view_on_environment_button(sha, path, environment) - node = Nokogiri::HTML.parse(html).at_css('a') + node = Nokogiri::HTML.parse(html).at_css("a") - expect(node[:title]).to eq('View on example.com') - expect(node[:href]).to eq('http://example.com/file.html') + expect(node[:title]).to eq("View on example.com") + expect(node[:href]).to eq("http://example.com/file.html") end end end diff --git a/spec/helpers/components_helper_spec.rb b/spec/helpers/components_helper_spec.rb index 94a59193be8..65ea8d8b337 100644 --- a/spec/helpers/components_helper_spec.rb +++ b/spec/helpers/components_helper_spec.rb @@ -1,20 +1,20 @@ -require 'spec_helper' +require "spec_helper" describe ComponentsHelper do - describe '#gitlab_workhorse_version' do - context 'without a Gitlab-Workhorse header' do - it 'shows the version from Gitlab::Workhorse.version' do + describe "#gitlab_workhorse_version" do + context "without a Gitlab-Workhorse header" do + it "shows the version from Gitlab::Workhorse.version" do expect(helper.gitlab_workhorse_version).to eq Gitlab::Workhorse.version end end - context 'with a Gitlab-Workhorse header' do + context "with a Gitlab-Workhorse header" do before do - helper.request.headers['Gitlab-Workhorse'] = '42.42.0-rc3' + helper.request.headers["Gitlab-Workhorse"] = "42.42.0-rc3" end - it 'shows the actual GitLab Workhorse version currently in use' do - expect(helper.gitlab_workhorse_version).to eq '42.42.0' + it "shows the actual GitLab Workhorse version currently in use" do + expect(helper.gitlab_workhorse_version).to eq "42.42.0" end end end diff --git a/spec/helpers/dashboard_helper_spec.rb b/spec/helpers/dashboard_helper_spec.rb index 7ba24ba2956..91a5ff8819e 100644 --- a/spec/helpers/dashboard_helper_spec.rb +++ b/spec/helpers/dashboard_helper_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe DashboardHelper do let(:user) { build(:user) } @@ -8,14 +8,14 @@ describe DashboardHelper do allow(helper).to receive(:can?) { true } end - describe '#dashboard_nav_links' do - it 'has all the expected links by default' do + describe "#dashboard_nav_links" do + it "has all the expected links by default" do menu_items = [:projects, :groups, :activity, :milestones, :snippets] expect(helper.dashboard_nav_links).to contain_exactly(*menu_items) end - it 'does not contain cross project elements when the user cannot read cross project' do + it "does not contain cross project elements when the user cannot read cross project" do expect(helper).to receive(:can?).with(user, :read_cross_project) { false } expect(helper.dashboard_nav_links).not_to include(:activity, :milestones) diff --git a/spec/helpers/defer_script_tag_helper_spec.rb b/spec/helpers/defer_script_tag_helper_spec.rb index d10b6f134e4..4aa7a46ee06 100644 --- a/spec/helpers/defer_script_tag_helper_spec.rb +++ b/spec/helpers/defer_script_tag_helper_spec.rb @@ -1,11 +1,10 @@ -# coding: utf-8 -require 'spec_helper' +require "spec_helper" describe DeferScriptTagHelper do - describe 'script tag' do - script_url = 'test.js' + describe "script tag" do + script_url = "test.js" - it 'returns an script tag with defer=true' do + it "returns an script tag with defer=true" do expect(javascript_include_tag(script_url).to_s) .to eq "" end diff --git a/spec/helpers/diff_helper_spec.rb b/spec/helpers/diff_helper_spec.rb index 5396243f44d..d6cb3dce92c 100644 --- a/spec/helpers/diff_helper_spec.rb +++ b/spec/helpers/diff_helper_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe DiffHelper do include RepoHelpers @@ -11,117 +11,117 @@ describe DiffHelper do let(:diff_refs) { commit.diff_refs } let(:diff_file) { Gitlab::Diff::File.new(diff, diff_refs: diff_refs, repository: repository) } - describe 'diff_view' do - it 'uses the view param over the cookie' do - controller.params[:view] = 'parallel' - helper.request.cookies[:diff_view] = 'inline' + describe "diff_view" do + it "uses the view param over the cookie" do + controller.params[:view] = "parallel" + helper.request.cookies[:diff_view] = "inline" expect(helper.diff_view).to eq :parallel end - it 'returns the default value when the view param is invalid' do - controller.params[:view] = 'invalid' + it "returns the default value when the view param is invalid" do + controller.params[:view] = "invalid" expect(helper.diff_view).to eq :inline end - it 'returns a valid value when cookie is set' do - helper.request.cookies[:diff_view] = 'parallel' + it "returns a valid value when cookie is set" do + helper.request.cookies[:diff_view] = "parallel" expect(helper.diff_view).to eq :parallel end - it 'returns the default value when cookie is invalid' do - helper.request.cookies[:diff_view] = 'invalid' + it "returns the default value when cookie is invalid" do + helper.request.cookies[:diff_view] = "invalid" expect(helper.diff_view).to eq :inline end - it 'returns the default value when cookie is nil' do + it "returns the default value when cookie is nil" do expect(helper.request.cookies).to be_empty expect(helper.diff_view).to eq :inline end end - describe 'diff_options' do - it 'returns no collapse false' do + describe "diff_options" do + it "returns no collapse false" do expect(diff_options).to include(expanded: false) end - it 'returns no collapse true if expanded' do - allow(controller).to receive(:params) { { expanded: true } } + it "returns no collapse true if expanded" do + allow(controller).to receive(:params) { {expanded: true} } expect(diff_options).to include(expanded: true) end - it 'returns no collapse true if action name diff_for_path' do - allow(controller).to receive(:action_name) { 'diff_for_path' } + it "returns no collapse true if action name diff_for_path" do + allow(controller).to receive(:action_name) { "diff_for_path" } expect(diff_options).to include(expanded: true) end - it 'returns paths if action name diff_for_path and param old path' do - allow(controller).to receive(:params) { { old_path: 'lib/wadus.rb' } } - allow(controller).to receive(:action_name) { 'diff_for_path' } - expect(diff_options[:paths]).to include('lib/wadus.rb') + it "returns paths if action name diff_for_path and param old path" do + allow(controller).to receive(:params) { {old_path: "lib/wadus.rb"} } + allow(controller).to receive(:action_name) { "diff_for_path" } + expect(diff_options[:paths]).to include("lib/wadus.rb") end - it 'returns paths if action name diff_for_path and param new path' do - allow(controller).to receive(:params) { { new_path: 'lib/wadus.rb' } } - allow(controller).to receive(:action_name) { 'diff_for_path' } - expect(diff_options[:paths]).to include('lib/wadus.rb') + it "returns paths if action name diff_for_path and param new path" do + allow(controller).to receive(:params) { {new_path: "lib/wadus.rb"} } + allow(controller).to receive(:action_name) { "diff_for_path" } + expect(diff_options[:paths]).to include("lib/wadus.rb") end end - describe '#diff_line_content' do - context 'when the line is empty' do - it 'returns a non breaking space' do - expect(diff_line_content(nil)).to eq(' ') + describe "#diff_line_content" do + context "when the line is empty" do + it "returns a non breaking space" do + expect(diff_line_content(nil)).to eq(" ") end - it 'returns an HTML-safe string' do + it "returns an HTML-safe string" do expect(diff_line_content(nil)).to be_html_safe end end - context 'when the line is not empty' do - context 'when the line starts with +, -, or a space' do - it 'strips the first character' do - expect(diff_line_content('+new line')).to eq('new line') - expect(diff_line_content('-new line')).to eq('new line') - expect(diff_line_content(' new line')).to eq('new line') + context "when the line is not empty" do + context "when the line starts with +, -, or a space" do + it "strips the first character" do + expect(diff_line_content("+new line")).to eq("new line") + expect(diff_line_content("-new line")).to eq("new line") + expect(diff_line_content(" new line")).to eq("new line") end - context 'when the line is HTML-safe' do - it 'returns an HTML-safe string' do - expect(diff_line_content('+new line'.html_safe)).to be_html_safe - expect(diff_line_content('-new line'.html_safe)).to be_html_safe - expect(diff_line_content(' new line'.html_safe)).to be_html_safe + context "when the line is HTML-safe" do + it "returns an HTML-safe string" do + expect(diff_line_content("+new line".html_safe)).to be_html_safe + expect(diff_line_content("-new line".html_safe)).to be_html_safe + expect(diff_line_content(" new line".html_safe)).to be_html_safe end end - context 'when the line is not HTML-safe' do - it 'returns a non-HTML-safe string' do - expect(diff_line_content('+new line')).not_to be_html_safe - expect(diff_line_content('-new line')).not_to be_html_safe - expect(diff_line_content(' new line')).not_to be_html_safe + context "when the line is not HTML-safe" do + it "returns a non-HTML-safe string" do + expect(diff_line_content("+new line")).not_to be_html_safe + expect(diff_line_content("-new line")).not_to be_html_safe + expect(diff_line_content(" new line")).not_to be_html_safe end end end - context 'when the line does not start with a +, -, or a space' do - it 'returns the string' do - expect(diff_line_content('@@ -6,12 +6,18 @@ module Popen')).to eq('@@ -6,12 +6,18 @@ module Popen') + context "when the line does not start with a +, -, or a space" do + it "returns the string" do + expect(diff_line_content("@@ -6,12 +6,18 @@ module Popen")).to eq("@@ -6,12 +6,18 @@ module Popen") end - context 'when the line is HTML-safe' do - it 'returns an HTML-safe string' do - expect(diff_line_content('@@ -6,12 +6,18 @@ module Popen'.html_safe)).to be_html_safe + context "when the line is HTML-safe" do + it "returns an HTML-safe string" do + expect(diff_line_content("@@ -6,12 +6,18 @@ module Popen".html_safe)).to be_html_safe end end - context 'when the line is not HTML-safe' do - it 'returns a non-HTML-safe string' do - expect(diff_line_content('@@ -6,12 +6,18 @@ module Popen')).not_to be_html_safe + context "when the line is not HTML-safe" do + it "returns a non-HTML-safe string" do + expect(diff_line_content("@@ -6,12 +6,18 @@ module Popen")).not_to be_html_safe end end end @@ -129,139 +129,139 @@ describe DiffHelper do end describe "#mark_inline_diffs" do - let(:old_line) { %{abc 'def'} } - let(:new_line) { %{abc "def"} } + let(:old_line) { %(abc 'def') } + let(:new_line) { %(abc "def") } it "returns strings with marked inline diffs" do marked_old_line, marked_new_line = mark_inline_diffs(old_line, new_line) - expect(marked_old_line).to eq(%q{abc 'def'}) + expect(marked_old_line).to eq('abc 'def'') expect(marked_old_line).to be_html_safe - expect(marked_new_line).to eq(%q{abc "def"}) + expect(marked_new_line).to eq('abc "def"') expect(marked_new_line).to be_html_safe end - context 'when given HTML' do - it 'sanitizes it' do - old_line = %{test.txt} + context "when given HTML" do + it "sanitizes it" do + old_line = %(test.txt) new_line = %{} marked_old_line, marked_new_line = mark_inline_diffs(old_line, new_line) - expect(marked_old_line).to eq(%q{test.txt}) + expect(marked_old_line).to eq('test.txt') expect(marked_old_line).to be_html_safe - expect(marked_new_line).to eq(%q{<img src=x onerror=alert(document.domain)>}) + expect(marked_new_line).to eq('<img src=x onerror=alert(document.domain)>') expect(marked_new_line).to be_html_safe end - it 'sanitizes the entire line, not just the changes' do + it "sanitizes the entire line, not just the changes" do old_line = %{} new_line = %{} marked_old_line, marked_new_line = mark_inline_diffs(old_line, new_line) - expect(marked_old_line).to eq(%q{<img src=x onerror=alert(document.domain)>}) + expect(marked_old_line).to eq('<img src=x onerror=alert(document.domain)>') expect(marked_old_line).to be_html_safe - expect(marked_new_line).to eq(%q{<img src=y onerror=alert(document.domain)>}) + expect(marked_new_line).to eq('<img src=y onerror=alert(document.domain)>') expect(marked_new_line).to be_html_safe end end end - describe '#parallel_diff_discussions' do - let(:discussion) { { 'abc_3_3' => 'comment' } } - let(:diff_file) { double(line_code: 'abc_3_3') } + describe "#parallel_diff_discussions" do + let(:discussion) { {"abc_3_3" => "comment"} } + let(:diff_file) { double(line_code: "abc_3_3") } before do helper.instance_variable_set(:@grouped_diff_discussions, discussion) end - it 'does not put comments on nonewline lines' do - left = Gitlab::Diff::Line.new('\\nonewline', 'old-nonewline', 3, 3, 3) - right = Gitlab::Diff::Line.new('\\nonewline', 'new-nonewline', 3, 3, 3) + it "does not put comments on nonewline lines" do + left = Gitlab::Diff::Line.new('\\nonewline', "old-nonewline", 3, 3, 3) + right = Gitlab::Diff::Line.new('\\nonewline', "new-nonewline", 3, 3, 3) result = helper.parallel_diff_discussions(left, right, diff_file) expect(result).to eq([nil, nil]) end - it 'puts comments on added lines' do - left = Gitlab::Diff::Line.new('\\nonewline', 'old-nonewline', 3, 3, 3) - right = Gitlab::Diff::Line.new('new line', 'new', 3, 3, 3) + it "puts comments on added lines" do + left = Gitlab::Diff::Line.new('\\nonewline', "old-nonewline", 3, 3, 3) + right = Gitlab::Diff::Line.new("new line", "new", 3, 3, 3) result = helper.parallel_diff_discussions(left, right, diff_file) - expect(result).to eq([nil, 'comment']) + expect(result).to eq([nil, "comment"]) end - it 'puts comments on unchanged lines' do - left = Gitlab::Diff::Line.new('unchanged line', nil, 3, 3, 3) - right = Gitlab::Diff::Line.new('unchanged line', nil, 3, 3, 3) + it "puts comments on unchanged lines" do + left = Gitlab::Diff::Line.new("unchanged line", nil, 3, 3, 3) + right = Gitlab::Diff::Line.new("unchanged line", nil, 3, 3, 3) result = helper.parallel_diff_discussions(left, right, diff_file) - expect(result).to eq(['comment', nil]) + expect(result).to eq(["comment", nil]) end end describe "#diff_match_line" do let(:old_pos) { 40 } let(:new_pos) { 50 } - let(:text) { 'some_text' } + let(:text) { "some_text" } it "generates foldable top match line for inline view with empty text by default" do output = diff_match_line old_pos, new_pos expect(output).to be_html_safe - expect(output).to have_css "td:nth-child(1):not(.js-unfold-bottom).diff-line-num.unfold.js-unfold.old_line[data-linenumber='#{old_pos}']", text: '...' - expect(output).to have_css "td:nth-child(2):not(.js-unfold-bottom).diff-line-num.unfold.js-unfold.new_line[data-linenumber='#{new_pos}']", text: '...' - expect(output).to have_css 'td:nth-child(3):not(.parallel).line_content.match', text: '' + expect(output).to have_css "td:nth-child(1):not(.js-unfold-bottom).diff-line-num.unfold.js-unfold.old_line[data-linenumber='#{old_pos}']", text: "..." + expect(output).to have_css "td:nth-child(2):not(.js-unfold-bottom).diff-line-num.unfold.js-unfold.new_line[data-linenumber='#{new_pos}']", text: "..." + expect(output).to have_css "td:nth-child(3):not(.parallel).line_content.match", text: "" end it "allows to define text and bottom option" do output = diff_match_line old_pos, new_pos, text: text, bottom: true expect(output).to be_html_safe - expect(output).to have_css "td:nth-child(1).diff-line-num.unfold.js-unfold.js-unfold-bottom.old_line[data-linenumber='#{old_pos}']", text: '...' - expect(output).to have_css "td:nth-child(2).diff-line-num.unfold.js-unfold.js-unfold-bottom.new_line[data-linenumber='#{new_pos}']", text: '...' - expect(output).to have_css 'td:nth-child(3):not(.parallel).line_content.match', text: text + expect(output).to have_css "td:nth-child(1).diff-line-num.unfold.js-unfold.js-unfold-bottom.old_line[data-linenumber='#{old_pos}']", text: "..." + expect(output).to have_css "td:nth-child(2).diff-line-num.unfold.js-unfold.js-unfold-bottom.new_line[data-linenumber='#{new_pos}']", text: "..." + expect(output).to have_css "td:nth-child(3):not(.parallel).line_content.match", text: text end it "generates match line for parallel view" do output = diff_match_line old_pos, new_pos, text: text, view: :parallel expect(output).to be_html_safe - expect(output).to have_css "td:nth-child(1):not(.js-unfold-bottom).diff-line-num.unfold.js-unfold.old_line[data-linenumber='#{old_pos}']", text: '...' - expect(output).to have_css 'td:nth-child(2).line_content.match.parallel', text: text - expect(output).to have_css "td:nth-child(3):not(.js-unfold-bottom).diff-line-num.unfold.js-unfold.new_line[data-linenumber='#{new_pos}']", text: '...' - expect(output).to have_css 'td:nth-child(4).line_content.match.parallel', text: text + expect(output).to have_css "td:nth-child(1):not(.js-unfold-bottom).diff-line-num.unfold.js-unfold.old_line[data-linenumber='#{old_pos}']", text: "..." + expect(output).to have_css "td:nth-child(2).line_content.match.parallel", text: text + expect(output).to have_css "td:nth-child(3):not(.js-unfold-bottom).diff-line-num.unfold.js-unfold.new_line[data-linenumber='#{new_pos}']", text: "..." + expect(output).to have_css "td:nth-child(4).line_content.match.parallel", text: text end it "allows to generate only left match line for parallel view" do output = diff_match_line old_pos, nil, text: text, view: :parallel expect(output).to be_html_safe - expect(output).to have_css "td:nth-child(1):not(.js-unfold-bottom).diff-line-num.unfold.js-unfold.old_line[data-linenumber='#{old_pos}']", text: '...' - expect(output).to have_css 'td:nth-child(2).line_content.match.parallel', text: text - expect(output).not_to have_css 'td:nth-child(3)' + expect(output).to have_css "td:nth-child(1):not(.js-unfold-bottom).diff-line-num.unfold.js-unfold.old_line[data-linenumber='#{old_pos}']", text: "..." + expect(output).to have_css "td:nth-child(2).line_content.match.parallel", text: text + expect(output).not_to have_css "td:nth-child(3)" end it "allows to generate only right match line for parallel view" do output = diff_match_line nil, new_pos, text: text, view: :parallel expect(output).to be_html_safe - expect(output).to have_css "td:nth-child(1):not(.js-unfold-bottom).diff-line-num.unfold.js-unfold.new_line[data-linenumber='#{new_pos}']", text: '...' - expect(output).to have_css 'td:nth-child(2).line_content.match.parallel', text: text - expect(output).not_to have_css 'td:nth-child(3)' + expect(output).to have_css "td:nth-child(1):not(.js-unfold-bottom).diff-line-num.unfold.js-unfold.new_line[data-linenumber='#{new_pos}']", text: "..." + expect(output).to have_css "td:nth-child(2).line_content.match.parallel", text: text + expect(output).not_to have_css "td:nth-child(3)" end end - context '#diff_file_path_text' do - it 'returns full path by default' do + context "#diff_file_path_text" do + it "returns full path by default" do expect(diff_file_path_text(diff_file)).to eq(diff_file.new_path) end - it 'returns truncated path' do + it "returns truncated path" do expect(diff_file_path_text(diff_file, max: 10)).to eq("...open.rb") end end diff --git a/spec/helpers/emails_helper_spec.rb b/spec/helpers/emails_helper_spec.rb index 03b4c19ec22..7358cc0ebc5 100644 --- a/spec/helpers/emails_helper_spec.rb +++ b/spec/helpers/emails_helper_spec.rb @@ -1,94 +1,94 @@ -require 'spec_helper' +require "spec_helper" describe EmailsHelper do - describe 'sanitize_name' do - context 'when name contains a valid URL string' do - it 'returns name with `.` replaced with `_` to prevent mail clients from auto-linking URLs' do - expect(sanitize_name('https://about.gitlab.com')).to eq('https://about_gitlab_com') - expect(sanitize_name('www.gitlab.com')).to eq('www_gitlab_com') - expect(sanitize_name('//about.gitlab.com/handbook/security/#best-practices')).to eq('//about_gitlab_com/handbook/security/#best-practices') + describe "sanitize_name" do + context "when name contains a valid URL string" do + it "returns name with `.` replaced with `_` to prevent mail clients from auto-linking URLs" do + expect(sanitize_name("https://about.gitlab.com")).to eq("https://about_gitlab_com") + expect(sanitize_name("www.gitlab.com")).to eq("www_gitlab_com") + expect(sanitize_name("//about.gitlab.com/handbook/security/#best-practices")).to eq("//about_gitlab_com/handbook/security/#best-practices") end - it 'returns name as it is when it does not contain a URL' do - expect(sanitize_name('Foo Bar')).to eq('Foo Bar') + it "returns name as it is when it does not contain a URL" do + expect(sanitize_name("Foo Bar")).to eq("Foo Bar") end end end - describe 'password_reset_token_valid_time' do + describe "password_reset_token_valid_time" do def validate_time_string(time_limit, expected_string) Devise.reset_password_within = time_limit expect(password_reset_token_valid_time).to eq(expected_string) end - context 'when time limit is less than 2 hours' do - it 'displays the time in hours using a singular unit' do - validate_time_string(1.hour, '1 hour') + context "when time limit is less than 2 hours" do + it "displays the time in hours using a singular unit" do + validate_time_string(1.hour, "1 hour") end end - context 'when time limit is 2 or more hours' do - it 'displays the time in hours using a plural unit' do - validate_time_string(2.hours, '2 hours') + context "when time limit is 2 or more hours" do + it "displays the time in hours using a plural unit" do + validate_time_string(2.hours, "2 hours") end end - context 'when time limit contains fractions of an hour' do - it 'rounds down to the nearest hour' do - validate_time_string(96.minutes, '1 hour') + context "when time limit contains fractions of an hour" do + it "rounds down to the nearest hour" do + validate_time_string(96.minutes, "1 hour") end end - context 'when time limit is 24 or more hours' do - it 'displays the time in days using a singular unit' do - validate_time_string(24.hours, '1 day') + context "when time limit is 24 or more hours" do + it "displays the time in days using a singular unit" do + validate_time_string(24.hours, "1 day") end end - context 'when time limit is 2 or more days' do - it 'displays the time in days using a plural unit' do - validate_time_string(2.days, '2 days') + context "when time limit is 2 or more days" do + it "displays the time in days using a plural unit" do + validate_time_string(2.days, "2 days") end end - context 'when time limit contains fractions of a day' do - it 'rounds down to the nearest day' do - validate_time_string(57.hours, '2 days') + context "when time limit contains fractions of a day" do + it "rounds down to the nearest day" do + validate_time_string(57.hours, "2 days") end end end - describe '#header_logo' do - context 'there is a brand item with a logo' do - it 'returns the brand header logo' do - appearance = create :appearance, header_logo: fixture_file_upload('spec/fixtures/dk.png') + describe "#header_logo" do + context "there is a brand item with a logo" do + it "returns the brand header logo" do + appearance = create :appearance, header_logo: fixture_file_upload("spec/fixtures/dk.png") expect(header_logo).to eq( - %{Dk} + %(Dk) ) end end - context 'there is a brand item without a logo' do - it 'returns the default header logo' do + context "there is a brand item without a logo" do + it "returns the default header logo" do create :appearance, header_logo: nil expect(header_logo).to eq( - %{GitLab} + %(GitLab) ) end end - context 'there is no brand item' do - it 'returns the default header logo' do + context "there is no brand item" do + it "returns the default header logo" do expect(header_logo).to eq( - %{GitLab} + %(GitLab) ) end end end - describe '#create_list_id_string' do + describe "#create_list_id_string" do using RSpec::Parameterized::TableSyntax where(:full_path, :list_id_path) do @@ -108,7 +108,7 @@ describe EmailsHelper do end with_them do - it 'ellipcizes different variants' do + it "ellipcizes different variants" do project = double("project") allow(project).to receive(:full_path).and_return(full_path) allow(project).to receive(:id).and_return(12345) @@ -122,7 +122,7 @@ describe EmailsHelper do end end - describe 'Create realistic List-Id identifier' do + describe "Create realistic List-Id identifier" do using RSpec::Parameterized::TableSyntax where(:full_path, :list_id_path) do @@ -131,7 +131,7 @@ describe EmailsHelper do end with_them do - it 'Produces the right List-Id' do + it "Produces the right List-Id" do project = double("project") allow(project).to receive(:full_path).and_return(full_path) allow(project).to receive(:id).and_return(12345) @@ -143,22 +143,22 @@ describe EmailsHelper do end end - describe 'header and footer messages' do - context 'when email_header_and_footer_enabled is enabled' do - it 'returns header and footer messages' do - create :appearance, header_message: 'Foo', footer_message: 'Bar', email_header_and_footer_enabled: true + describe "header and footer messages" do + context "when email_header_and_footer_enabled is enabled" do + it "returns header and footer messages" do + create :appearance, header_message: "Foo", footer_message: "Bar", email_header_and_footer_enabled: true aggregate_failures do - expect(html_header_message).to eq(%{

Foo

}) - expect(html_footer_message).to eq(%{}) - expect(text_header_message).to eq('Foo') - expect(text_footer_message).to eq('Bar') + expect(html_header_message).to eq(%(

Foo

)) + expect(html_footer_message).to eq(%()) + expect(text_header_message).to eq("Foo") + expect(text_footer_message).to eq("Bar") end end - context 'when header and footer messages are empty' do - it 'returns nil' do - create :appearance, header_message: '', footer_message: '', email_header_and_footer_enabled: true + context "when header and footer messages are empty" do + it "returns nil" do + create :appearance, header_message: "", footer_message: "", email_header_and_footer_enabled: true aggregate_failures do expect(html_header_message).to eq(nil) @@ -169,8 +169,8 @@ describe EmailsHelper do end end - context 'when header and footer messages are nil' do - it 'returns nil' do + context "when header and footer messages are nil" do + it "returns nil" do create :appearance, header_message: nil, footer_message: nil, email_header_and_footer_enabled: true aggregate_failures do @@ -183,9 +183,9 @@ describe EmailsHelper do end end - context 'when email_header_and_footer_enabled is disabled' do - it 'returns header and footer messages' do - create :appearance, header_message: 'Foo', footer_message: 'Bar', email_header_and_footer_enabled: false + context "when email_header_and_footer_enabled is disabled" do + it "returns header and footer messages" do + create :appearance, header_message: "Foo", footer_message: "Bar", email_header_and_footer_enabled: false aggregate_failures do expect(html_header_message).to eq(nil) diff --git a/spec/helpers/events_helper_spec.rb b/spec/helpers/events_helper_spec.rb index 3d15306d4d2..4a2b46ea67a 100644 --- a/spec/helpers/events_helper_spec.rb +++ b/spec/helpers/events_helper_spec.rb @@ -1,83 +1,83 @@ -require 'spec_helper' +require "spec_helper" describe EventsHelper do - describe '#event_commit_title' do - let(:message) { 'foo & bar ' + 'A' * 70 + '\n' + 'B' * 80 } + describe "#event_commit_title" do + let(:message) { "foo & bar " + "A" * 70 + '\n' + "B" * 80 } subject { helper.event_commit_title(message) } - it 'returns the first line, truncated to 70 chars' do + it "returns the first line, truncated to 70 chars" do is_expected.to eq(message[0..66] + "...") end - it 'is not html-safe' do + it "is not html-safe" do is_expected.not_to be_a(ActiveSupport::SafeBuffer) end - it 'handles empty strings' do + it "handles empty strings" do expect(helper.event_commit_title("")).to eq("") end - it 'handles nil values' do - expect(helper.event_commit_title(nil)).to eq('') + it "handles nil values" do + expect(helper.event_commit_title(nil)).to eq("") end - it 'does not escape HTML entities' do - expect(helper.event_commit_title('foo & bar')).to eq('foo & bar') + it "does not escape HTML entities" do + expect(helper.event_commit_title("foo & bar")).to eq("foo & bar") end end - describe '#event_feed_url' do + describe "#event_feed_url" do let(:event) { create(:event) } let(:project) { create(:project, :public, :repository) } - context 'issue' do + context "issue" do before do event.target = create(:issue) end - it 'returns the project issue url' do + it "returns the project issue url" do expect(helper.event_feed_url(event)).to eq(project_issue_url(event.project, event.target)) end - it 'contains the project issue IID link' do + it "contains the project issue IID link" do expect(helper.event_feed_title(event)).to include("##{event.target.iid}") end end - context 'merge request' do + context "merge request" do before do event.target = create(:merge_request) end - it 'returns the project merge request url' do + it "returns the project merge request url" do expect(helper.event_feed_url(event)).to eq(project_merge_request_url(event.project, event.target)) end - it 'contains the project merge request IID link' do + it "contains the project merge request IID link" do expect(helper.event_feed_title(event)).to include("!#{event.target.iid}") end end - it 'returns project commit url' do + it "returns project commit url" do event.target = create(:note_on_commit, project: project) expect(helper.event_feed_url(event)).to eq(project_commit_url(event.project, event.note_target)) end - it 'returns event note target url' do + it "returns event note target url" do event.target = create(:note) expect(helper.event_feed_url(event)).to eq(event_note_target_url(event)) end - it 'returns project url' do + it "returns project url" do event.project = project event.action = 1 expect(helper.event_feed_url(event)).to eq(project_url(event.project)) end - it 'returns push event feed url' do + it "returns push event feed url" do event = create(:push_event) create(:push_event_payload, event: event, action: :pushed) @@ -85,33 +85,33 @@ describe EventsHelper do end end - describe '#event_note_target_url' do + describe "#event_note_target_url" do let(:project) { create(:project, :public, :repository) } let(:event) { create(:event, project: project) } let(:project_base_url) { namespace_project_url(namespace_id: project.namespace, id: project) } subject { helper.event_note_target_url(event) } - it 'returns a commit note url' do - event.target = create(:note_on_commit, note: '+1 from me') + it "returns a commit note url" do + event.target = create(:note_on_commit, note: "+1 from me") expect(subject).to eq("#{project_base_url}/commit/#{event.target.commit_id}#note_#{event.target.id}") end - it 'returns a project snippet note url' do - event.target = create(:note, :on_snippet, note: 'keep going') + it "returns a project snippet note url" do + event.target = create(:note, :on_snippet, note: "keep going") expect(subject).to eq("#{project_base_url}/snippets/#{event.note_target.id}#note_#{event.target.id}") end - it 'returns a project issue url' do - event.target = create(:note_on_issue, note: 'nice work') + it "returns a project issue url" do + event.target = create(:note_on_issue, note: "nice work") expect(subject).to eq("#{project_base_url}/issues/#{event.note_target.iid}#note_#{event.target.id}") end - it 'returns a merge request url' do - event.target = create(:note_on_merge_request, note: 'LGTM!') + it "returns a merge request url" do + event.target = create(:note_on_merge_request, note: "LGTM!") expect(subject).to eq("#{project_base_url}/merge_requests/#{event.note_target.iid}#note_#{event.target.id}") end diff --git a/spec/helpers/explore_helper_spec.rb b/spec/helpers/explore_helper_spec.rb index 12651d80e36..5c655782468 100644 --- a/spec/helpers/explore_helper_spec.rb +++ b/spec/helpers/explore_helper_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe ExploreHelper do let(:user) { build(:user) } @@ -8,8 +8,8 @@ describe ExploreHelper do allow(helper).to receive(:can?) { true } end - describe '#explore_nav_links' do - it 'has all the expected links by default' do + describe "#explore_nav_links" do + it "has all the expected links by default" do menu_items = [:projects, :groups, :snippets] expect(helper.explore_nav_links).to contain_exactly(*menu_items) diff --git a/spec/helpers/form_helper_spec.rb b/spec/helpers/form_helper_spec.rb index 18cf0031d5f..ebd22fb4520 100644 --- a/spec/helpers/form_helper_spec.rb +++ b/spec/helpers/form_helper_spec.rb @@ -1,39 +1,39 @@ -require 'rails_helper' +require "rails_helper" describe FormHelper do - describe 'form_errors' do - it 'returns nil when model has no errors' do + describe "form_errors" do + it "returns nil when model has no errors" do model = double(errors: []) expect(helper.form_errors(model)).to be_nil end - it 'renders an alert div' do - model = double(errors: errors_stub('Error 1')) + it "renders an alert div" do + model = double(errors: errors_stub("Error 1")) expect(helper.form_errors(model)) .to include('
') end - it 'contains a summary message' do - single_error = double(errors: errors_stub('A')) - multi_errors = double(errors: errors_stub('A', 'B', 'C')) + it "contains a summary message" do + single_error = double(errors: errors_stub("A")) + multi_errors = double(errors: errors_stub("A", "B", "C")) expect(helper.form_errors(single_error)) - .to include('

The form contains the following error:') + .to include("

The form contains the following error:") expect(helper.form_errors(multi_errors)) - .to include('

The form contains the following errors:') + .to include("

The form contains the following errors:") end - it 'renders each message' do - model = double(errors: errors_stub('Error 1', 'Error 2', 'Error 3')) + it "renders each message" do + model = double(errors: errors_stub("Error 1", "Error 2", "Error 3")) errors = helper.form_errors(model) aggregate_failures do - expect(errors).to include('
  • Error 1
  • ') - expect(errors).to include('
  • Error 2
  • ') - expect(errors).to include('
  • Error 3
  • ') + expect(errors).to include("
  • Error 1
  • ") + expect(errors).to include("
  • Error 2
  • ") + expect(errors).to include("
  • Error 3
  • ") end end diff --git a/spec/helpers/git_helper_spec.rb b/spec/helpers/git_helper_spec.rb index 9b1ef1e05a2..b48872ec0b8 100644 --- a/spec/helpers/git_helper_spec.rb +++ b/spec/helpers/git_helper_spec.rb @@ -1,9 +1,9 @@ -require 'spec_helper' +require "spec_helper" describe GitHelper do - describe '#short_sha' do - let(:short_sha) { helper.short_sha('d4e043f6c20749a3ab3f4b8e23f2a8979f4b9100') } + describe "#short_sha" do + let(:short_sha) { helper.short_sha("d4e043f6c20749a3ab3f4b8e23f2a8979f4b9100") } - it { expect(short_sha).to eq('d4e043f6') } + it { expect(short_sha).to eq("d4e043f6") } end end diff --git a/spec/helpers/gitlab_routing_helper_spec.rb b/spec/helpers/gitlab_routing_helper_spec.rb index 143b28728a3..14c22db97d0 100644 --- a/spec/helpers/gitlab_routing_helper_spec.rb +++ b/spec/helpers/gitlab_routing_helper_spec.rb @@ -1,104 +1,104 @@ -require 'spec_helper' +require "spec_helper" describe GitlabRoutingHelper do let(:project) { build_stubbed(:project) } let(:group) { build_stubbed(:group) } - describe 'Project URL helpers' do - describe '#project_member_path' do + describe "Project URL helpers" do + describe "#project_member_path" do let(:project_member) { create(:project_member) } it { expect(project_member_path(project_member)).to eq project_project_member_path(project_member.source, project_member) } end - describe '#request_access_project_members_path' do + describe "#request_access_project_members_path" do it { expect(request_access_project_members_path(project)).to eq request_access_project_project_members_path(project) } end - describe '#leave_project_members_path' do + describe "#leave_project_members_path" do it { expect(leave_project_members_path(project)).to eq leave_project_project_members_path(project) } end - describe '#approve_access_request_project_member_path' do + describe "#approve_access_request_project_member_path" do let(:project_member) { create(:project_member) } it { expect(approve_access_request_project_member_path(project_member)).to eq approve_access_request_project_project_member_path(project_member.source, project_member) } end - describe '#resend_invite_project_member_path' do + describe "#resend_invite_project_member_path" do let(:project_member) { create(:project_member) } it { expect(resend_invite_project_member_path(project_member)).to eq resend_invite_project_project_member_path(project_member.source, project_member) } end end - describe 'Group URL helpers' do - describe '#group_members_url' do + describe "Group URL helpers" do + describe "#group_members_url" do it { expect(group_members_url(group)).to eq group_group_members_url(group) } end - describe '#group_member_path' do + describe "#group_member_path" do let(:group_member) { create(:group_member) } it { expect(group_member_path(group_member)).to eq group_group_member_path(group_member.source, group_member) } end - describe '#request_access_group_members_path' do + describe "#request_access_group_members_path" do it { expect(request_access_group_members_path(group)).to eq request_access_group_group_members_path(group) } end - describe '#leave_group_members_path' do + describe "#leave_group_members_path" do it { expect(leave_group_members_path(group)).to eq leave_group_group_members_path(group) } end - describe '#approve_access_request_group_member_path' do + describe "#approve_access_request_group_member_path" do let(:group_member) { create(:group_member) } it { expect(approve_access_request_group_member_path(group_member)).to eq approve_access_request_group_group_member_path(group_member.source, group_member) } end - describe '#resend_invite_group_member_path' do + describe "#resend_invite_group_member_path" do let(:group_member) { create(:group_member) } it { expect(resend_invite_group_member_path(group_member)).to eq resend_invite_group_group_member_path(group_member.source, group_member) } end end - describe '#preview_markdown_path' do + describe "#preview_markdown_path" do let(:project) { create(:project) } - it 'returns group preview markdown path for a group parent' do + it "returns group preview markdown path for a group parent" do group = create(:group) expect(preview_markdown_path(group)).to eq("/groups/#{group.path}/preview_markdown") end - it 'returns project preview markdown path for a project parent' do + it "returns project preview markdown path for a project parent" do expect(preview_markdown_path(project)).to eq("/#{project.full_path}/preview_markdown") end - it 'returns snippet preview markdown path for a personal snippet' do + it "returns snippet preview markdown path for a personal snippet" do @snippet = create(:personal_snippet) expect(preview_markdown_path(nil)).to eq("/snippets/preview_markdown") end - it 'returns project preview markdown path for a project snippet' do + it "returns project preview markdown path for a project snippet" do @snippet = create(:project_snippet, project: project) expect(preview_markdown_path(project)).to eq("/#{project.full_path}/preview_markdown") end end - describe '#edit_milestone_path' do - it 'returns group milestone edit path when given entity parent is a Group' do + describe "#edit_milestone_path" do + it "returns group milestone edit path when given entity parent is a Group" do group = create(:group) milestone = create(:milestone, group: group) expect(edit_milestone_path(milestone)).to eq("/groups/#{group.path}/-/milestones/#{milestone.iid}/edit") end - it 'returns project milestone edit path when given entity parent is not a Group' do + it "returns project milestone edit path when given entity parent is not a Group" do milestone = create(:milestone, group: nil) expect(edit_milestone_path(milestone)).to eq("/#{milestone.project.full_path}/milestones/#{milestone.iid}/edit") diff --git a/spec/helpers/graph_helper_spec.rb b/spec/helpers/graph_helper_spec.rb index 1f8a38dc697..ba68674e657 100644 --- a/spec/helpers/graph_helper_spec.rb +++ b/spec/helpers/graph_helper_spec.rb @@ -1,16 +1,16 @@ -require 'spec_helper' +require "spec_helper" describe GraphHelper do - describe '#get_refs' do + describe "#get_refs" do let(:project) { create(:project, :repository) } let(:commit) { project.commit("master") } - let(:graph) { Network::Graph.new(project, 'master', commit, '') } + let(:graph) { Network::Graph.new(project, "master", commit, "") } - it 'filters our refs used by GitLab' do - self.instance_variable_set(:@graph, graph) + it "filters our refs used by GitLab" do + instance_variable_set(:@graph, graph) refs = refs(project.repository, commit) - expect(refs).to match('master') + expect(refs).to match("master") end end end diff --git a/spec/helpers/groups_helper_spec.rb b/spec/helpers/groups_helper_spec.rb index 540a8674ec2..b5b22174faf 100644 --- a/spec/helpers/groups_helper_spec.rb +++ b/spec/helpers/groups_helper_spec.rb @@ -1,11 +1,11 @@ -require 'spec_helper' +require "spec_helper" describe GroupsHelper do include ApplicationHelper - describe 'group_icon_url' do - it 'returns an url for the avatar' do - avatar_file_path = File.join('spec', 'fixtures', 'banana_sample.gif') + describe "group_icon_url" do + it "returns an url for the avatar" do + avatar_file_path = File.join("spec", "fixtures", "banana_sample.gif") group = create(:group) group.avatar = fixture_file_upload(avatar_file_path) @@ -14,14 +14,14 @@ describe GroupsHelper do .to match(group.avatar.url) end - it 'gives default avatar_icon when no avatar is present' do + it "gives default avatar_icon when no avatar is present" do group = create(:group) group.save! - expect(group_icon_url(group.path)).to match_asset_path('group_avatar.png') + expect(group_icon_url(group.path)).to match_asset_path("group_avatar.png") end end - describe 'group_lfs_status' do + describe "group_lfs_status" do let(:group) { create(:group) } let!(:project) { create(:project, namespace_id: group.id) } @@ -29,75 +29,75 @@ describe GroupsHelper do allow(Gitlab.config.lfs).to receive(:enabled).and_return(true) end - context 'only one project in group' do + context "only one project in group" do before do group.update_attribute(:lfs_enabled, true) end - it 'returns all projects as enabled' do - expect(group_lfs_status(group)).to include('Enabled for all projects') + it "returns all projects as enabled" do + expect(group_lfs_status(group)).to include("Enabled for all projects") end - it 'returns all projects as disabled' do + it "returns all projects as disabled" do project.update_attribute(:lfs_enabled, false) - expect(group_lfs_status(group)).to include('Enabled for 0 out of 1 project') + expect(group_lfs_status(group)).to include("Enabled for 0 out of 1 project") end end - context 'more than one project in group' do + context "more than one project in group" do before do create(:project, namespace_id: group.id) end - context 'LFS enabled in group' do + context "LFS enabled in group" do before do group.update_attribute(:lfs_enabled, true) end - it 'returns both projects as enabled' do - expect(group_lfs_status(group)).to include('Enabled for all projects') + it "returns both projects as enabled" do + expect(group_lfs_status(group)).to include("Enabled for all projects") end - it 'returns only one as enabled' do + it "returns only one as enabled" do project.update_attribute(:lfs_enabled, false) - expect(group_lfs_status(group)).to include('Enabled for 1 out of 2 projects') + expect(group_lfs_status(group)).to include("Enabled for 1 out of 2 projects") end end - context 'LFS disabled in group' do + context "LFS disabled in group" do before do group.update_attribute(:lfs_enabled, false) end - it 'returns both projects as disabled' do - expect(group_lfs_status(group)).to include('Disabled for all projects') + it "returns both projects as disabled" do + expect(group_lfs_status(group)).to include("Disabled for all projects") end - it 'returns only one as disabled' do + it "returns only one as disabled" do project.update_attribute(:lfs_enabled, true) - expect(group_lfs_status(group)).to include('Disabled for 1 out of 2 projects') + expect(group_lfs_status(group)).to include("Disabled for 1 out of 2 projects") end end end end - describe 'group_title', :nested_groups do + describe "group_title", :nested_groups do let(:group) { create(:group) } let(:nested_group) { create(:group, parent: group) } let(:deep_nested_group) { create(:group, parent: nested_group) } let!(:very_deep_nested_group) { create(:group, parent: deep_nested_group) } - it 'outputs the groups in the correct order' do + it "outputs the groups in the correct order" do expect(helper.group_title(very_deep_nested_group)) .to match(%r{
  • #{deep_nested_group.name}.*
  • .*#{very_deep_nested_group.name}}m) end end # rubocop:disable Layout/SpaceBeforeComma - describe '#share_with_group_lock_help_text', :nested_groups do + describe "#share_with_group_lock_help_text", :nested_groups do let!(:root_group) { create(:group) } let!(:subgroup) { create(:group, parent: root_group) } let!(:sub_subgroup) { create(:group, parent: subgroup) } @@ -109,20 +109,20 @@ describe GroupsHelper do default_help: "This setting will be applied to all subgroups unless overridden by a group owner", ancestor_locked_but_you_can_override: %r{This setting is applied on .+\. You can override the setting or .+}, ancestor_locked_so_ask_the_owner: /This setting is applied on .+\. To share projects in this group with another group, ask the owner to override the setting or remove the share with group lock from .+/, - ancestor_locked_and_has_been_overridden: /This setting is applied on .+ and has been overridden on this subgroup/ + ancestor_locked_and_has_been_overridden: /This setting is applied on .+ and has been overridden on this subgroup/, } end let(:possible_linked_ancestors) do { root_group: root_group, - subgroup: subgroup + subgroup: subgroup, } end let(:users) do { root_owner: root_owner, sub_owner: sub_owner, - sub_sub_owner: sub_sub_owner + sub_sub_owner: sub_sub_owner, } end subject { helper.share_with_group_lock_help_text(sub_subgroup) } @@ -152,7 +152,7 @@ describe GroupsHelper do [true , true , false , :sub_sub_owner , :ancestor_locked_and_has_been_overridden , :root_group], [true , true , true , :root_owner , :ancestor_locked_but_you_can_override , :root_group], [true , true , true , :sub_owner , :ancestor_locked_so_ask_the_owner , :root_group], - [true , true , true , :sub_sub_owner , :ancestor_locked_so_ask_the_owner , :root_group] + [true , true , true , :sub_sub_owner , :ancestor_locked_so_ask_the_owner , :root_group], ] end @@ -168,28 +168,28 @@ describe GroupsHelper do allow(helper).to receive(:current_user).and_return(users[current_user]) allow(helper).to receive(:can?) - .with(users[current_user], :change_share_with_group_lock, subgroup) - .and_return(Ability.allowed?(users[current_user], :change_share_with_group_lock, subgroup)) + .with(users[current_user], :change_share_with_group_lock, subgroup) + .and_return(Ability.allowed?(users[current_user], :change_share_with_group_lock, subgroup)) ancestor = possible_linked_ancestors[linked_ancestor] if ancestor allow(helper).to receive(:can?) - .with(users[current_user], :read_group, ancestor) - .and_return(Ability.allowed?(users[current_user], :read_group, ancestor)) + .with(users[current_user], :read_group, ancestor) + .and_return(Ability.allowed?(users[current_user], :read_group, ancestor)) allow(helper).to receive(:can?) - .with(users[current_user], :admin_group, ancestor) - .and_return(Ability.allowed?(users[current_user], :admin_group, ancestor)) + .with(users[current_user], :admin_group, ancestor) + .and_return(Ability.allowed?(users[current_user], :admin_group, ancestor)) end end - it 'has the correct help text with correct ancestor links' do + it "has the correct help text with correct ancestor links" do expect(subject).to match(possible_help_texts[help_text]) expect(subject).to match(possible_linked_ancestors[linked_ancestor].name) unless help_text == :default_help end end end - describe '#group_sidebar_links' do + describe "#group_sidebar_links" do let(:group) { create(:group, :public) } let(:user) { create(:user) } before do @@ -199,25 +199,25 @@ describe GroupsHelper do helper.instance_variable_set(:@group, group) end - it 'returns all the expected links' do + it "returns all the expected links" do links = [ :overview, :activity, :issues, :labels, :milestones, :merge_requests, - :group_members, :settings + :group_members, :settings, ] expect(helper.group_sidebar_links).to include(*links) end - it 'includes settings when the user can admin the group' do + it "includes settings when the user can admin the group" do expect(helper).to receive(:current_user) { user } expect(helper).to receive(:can?).with(user, :admin_group, group) { false } expect(helper.group_sidebar_links).not_to include(:settings) end - it 'excludes cross project features when the user cannot read cross project' do + it "excludes cross project features when the user cannot read cross project" do cross_project_features = [:activity, :issues, :labels, :milestones, - :merge_requests] + :merge_requests,] allow(Ability).to receive(:allowed?).and_call_original cross_project_features.each do |feature| diff --git a/spec/helpers/hooks_helper_spec.rb b/spec/helpers/hooks_helper_spec.rb index 2e21f1134b1..91cfd90875f 100644 --- a/spec/helpers/hooks_helper_spec.rb +++ b/spec/helpers/hooks_helper_spec.rb @@ -1,18 +1,18 @@ -require 'spec_helper' +require "spec_helper" describe HooksHelper do let(:project) { create(:project) } let(:project_hook) { create(:project_hook, project: project) } let(:system_hook) { create(:system_hook) } - let(:trigger) { 'push_events' } + let(:trigger) { "push_events" } - describe '#link_to_test_hook' do - it 'returns project namespaced link' do + describe "#link_to_test_hook" do + it "returns project namespaced link" do expect(helper.link_to_test_hook(project_hook, trigger)) .to include("href=\"#{test_project_hook_path(project, project_hook, trigger: trigger)}\"") end - it 'returns admin namespaced link' do + it "returns admin namespaced link" do expect(helper.link_to_test_hook(system_hook, trigger)) .to include("href=\"#{test_admin_hook_path(system_hook, trigger: trigger)}\"") end diff --git a/spec/helpers/icons_helper_spec.rb b/spec/helpers/icons_helper_spec.rb index 4b40d523287..f271cb984d2 100644 --- a/spec/helpers/icons_helper_spec.rb +++ b/spec/helpers/icons_helper_spec.rb @@ -1,77 +1,77 @@ -require 'spec_helper' +require "spec_helper" describe IconsHelper do let(:icons_path) { ActionController::Base.helpers.image_path("icons.svg") } - describe 'icon' do - it 'returns aria-hidden by default' do - star = icon('star') + describe "icon" do + it "returns aria-hidden by default" do + star = icon("star") - expect(star['aria-hidden']).to eq 'aria-hidden' + expect(star["aria-hidden"]).to eq "aria-hidden" end - it 'does not return aria-hidden if aria-label is set' do - up = icon('up', 'aria-label' => 'up') + it "does not return aria-hidden if aria-label is set" do + up = icon("up", "aria-label" => "up") - expect(up['aria-hidden']).to be_nil - expect(up['aria-label']).to eq 'aria-label' + expect(up["aria-hidden"]).to be_nil + expect(up["aria-label"]).to eq "aria-label" end end - describe 'sprite_icon_path' do - it 'returns relative path' do + describe "sprite_icon_path" do + it "returns relative path" do expect(sprite_icon_path) .to eq icons_path end - context 'when an asset_host is set in the config it will return an absolute local URL' do - let(:asset_host) { 'http://assets' } + context "when an asset_host is set in the config it will return an absolute local URL" do + let(:asset_host) { "http://assets" } before do allow(ActionController::Base).to receive(:asset_host).and_return(asset_host) end - it 'returns an absolute URL on that asset host' do + it "returns an absolute URL on that asset host" do expect(sprite_icon_path) .to eq ActionController::Base.helpers.image_path("icons.svg", host: Gitlab.config.gitlab.url) end end end - describe 'sprite_icon' do - icon_name = 'clock' + describe "sprite_icon" do + icon_name = "clock" - it 'returns svg icon html' do + it "returns svg icon html" do expect(sprite_icon(icon_name).to_s) .to eq "" end - it 'returns svg icon html + size classes' do + it "returns svg icon html + size classes" do expect(sprite_icon(icon_name, size: 72).to_s) .to eq "" end - it 'returns svg icon html + size classes + additional class' do - expect(sprite_icon(icon_name, size: 72, css_class: 'icon-danger').to_s) + it "returns svg icon html + size classes + additional class" do + expect(sprite_icon(icon_name, size: 72, css_class: "icon-danger").to_s) .to eq "" end - describe 'non existing icon' do - non_existing = 'non_existing_icon_sprite' + describe "non existing icon" do + non_existing = "non_existing_icon_sprite" - it 'should raise in development mode' do + it "should raise in development mode" do allow(Rails.env).to receive(:development?).and_return(true) expect { sprite_icon(non_existing) }.to raise_error(ArgumentError, /is not a known icon/) end - it 'should raise in test mode' do + it "should raise in test mode" do allow(Rails.env).to receive(:test?).and_return(true) expect { sprite_icon(non_existing) }.to raise_error(ArgumentError, /is not a known icon/) end - it 'should not raise in production mode' do + it "should not raise in production mode" do allow(Rails.env).to receive(:test?).and_return(false) allow(Rails.env).to receive(:development?).and_return(false) @@ -80,135 +80,135 @@ describe IconsHelper do end end - describe 'audit icon' do - it 'returns right icon name for standard auth' do - icon_name = 'standard' + describe "audit icon" do + it "returns right icon name for standard auth" do + icon_name = "standard" expect(audit_icon(icon_name).to_s) - .to eq '' + .to eq '' end - it 'returns right icon name for two-factor auth' do - icon_name = 'two-factor' + it "returns right icon name for two-factor auth" do + icon_name = "two-factor" expect(audit_icon(icon_name).to_s) - .to eq '' + .to eq '' end - it 'returns right icon name for google_oauth2 auth' do - icon_name = 'google_oauth2' + it "returns right icon name for google_oauth2 auth" do + icon_name = "google_oauth2" expect(audit_icon(icon_name).to_s) - .to eq '' + .to eq '' end end - describe 'file_type_icon_class' do - it 'returns folder class' do - expect(file_type_icon_class('folder', 0, 'folder_name')).to eq 'folder' + describe "file_type_icon_class" do + it "returns folder class" do + expect(file_type_icon_class("folder", 0, "folder_name")).to eq "folder" end - it 'returns share class' do - expect(file_type_icon_class('file', '120000', 'link')).to eq 'share' + it "returns share class" do + expect(file_type_icon_class("file", "120000", "link")).to eq "share" end - it 'returns file-pdf-o class with .pdf' do - expect(file_type_icon_class('file', 0, 'filename.pdf')).to eq 'file-pdf-o' + it "returns file-pdf-o class with .pdf" do + expect(file_type_icon_class("file", 0, "filename.pdf")).to eq "file-pdf-o" end - it 'returns file-image-o class with .jpg' do - expect(file_type_icon_class('file', 0, 'filename.jpg')).to eq 'file-image-o' + it "returns file-image-o class with .jpg" do + expect(file_type_icon_class("file", 0, "filename.jpg")).to eq "file-image-o" end - it 'returns file-image-o class with .JPG' do - expect(file_type_icon_class('file', 0, 'filename.JPG')).to eq 'file-image-o' + it "returns file-image-o class with .JPG" do + expect(file_type_icon_class("file", 0, "filename.JPG")).to eq "file-image-o" end - it 'returns file-image-o class with .png' do - expect(file_type_icon_class('file', 0, 'filename.png')).to eq 'file-image-o' + it "returns file-image-o class with .png" do + expect(file_type_icon_class("file", 0, "filename.png")).to eq "file-image-o" end - it 'returns file-archive-o class with .tar' do - expect(file_type_icon_class('file', 0, 'filename.tar')).to eq 'file-archive-o' + it "returns file-archive-o class with .tar" do + expect(file_type_icon_class("file", 0, "filename.tar")).to eq "file-archive-o" end - it 'returns file-archive-o class with .TAR' do - expect(file_type_icon_class('file', 0, 'filename.TAR')).to eq 'file-archive-o' + it "returns file-archive-o class with .TAR" do + expect(file_type_icon_class("file", 0, "filename.TAR")).to eq "file-archive-o" end - it 'returns file-archive-o class with .tar.gz' do - expect(file_type_icon_class('file', 0, 'filename.tar.gz')).to eq 'file-archive-o' + it "returns file-archive-o class with .tar.gz" do + expect(file_type_icon_class("file", 0, "filename.tar.gz")).to eq "file-archive-o" end - it 'returns file-audio-o class with .mp3' do - expect(file_type_icon_class('file', 0, 'filename.mp3')).to eq 'file-audio-o' + it "returns file-audio-o class with .mp3" do + expect(file_type_icon_class("file", 0, "filename.mp3")).to eq "file-audio-o" end - it 'returns file-audio-o class with .MP3' do - expect(file_type_icon_class('file', 0, 'filename.MP3')).to eq 'file-audio-o' + it "returns file-audio-o class with .MP3" do + expect(file_type_icon_class("file", 0, "filename.MP3")).to eq "file-audio-o" end - it 'returns file-audio-o class with .wav' do - expect(file_type_icon_class('file', 0, 'filename.wav')).to eq 'file-audio-o' + it "returns file-audio-o class with .wav" do + expect(file_type_icon_class("file", 0, "filename.wav")).to eq "file-audio-o" end - it 'returns file-video-o class with .avi' do - expect(file_type_icon_class('file', 0, 'filename.avi')).to eq 'file-video-o' + it "returns file-video-o class with .avi" do + expect(file_type_icon_class("file", 0, "filename.avi")).to eq "file-video-o" end - it 'returns file-video-o class with .AVI' do - expect(file_type_icon_class('file', 0, 'filename.AVI')).to eq 'file-video-o' + it "returns file-video-o class with .AVI" do + expect(file_type_icon_class("file", 0, "filename.AVI")).to eq "file-video-o" end - it 'returns file-video-o class with .mp4' do - expect(file_type_icon_class('file', 0, 'filename.mp4')).to eq 'file-video-o' + it "returns file-video-o class with .mp4" do + expect(file_type_icon_class("file", 0, "filename.mp4")).to eq "file-video-o" end - it 'returns file-word-o class with .doc' do - expect(file_type_icon_class('file', 0, 'filename.doc')).to eq 'file-word-o' + it "returns file-word-o class with .doc" do + expect(file_type_icon_class("file", 0, "filename.doc")).to eq "file-word-o" end - it 'returns file-word-o class with .DOC' do - expect(file_type_icon_class('file', 0, 'filename.DOC')).to eq 'file-word-o' + it "returns file-word-o class with .DOC" do + expect(file_type_icon_class("file", 0, "filename.DOC")).to eq "file-word-o" end - it 'returns file-word-o class with .docx' do - expect(file_type_icon_class('file', 0, 'filename.docx')).to eq 'file-word-o' + it "returns file-word-o class with .docx" do + expect(file_type_icon_class("file", 0, "filename.docx")).to eq "file-word-o" end - it 'returns file-excel-o class with .xls' do - expect(file_type_icon_class('file', 0, 'filename.xls')).to eq 'file-excel-o' + it "returns file-excel-o class with .xls" do + expect(file_type_icon_class("file", 0, "filename.xls")).to eq "file-excel-o" end - it 'returns file-excel-o class with .XLS' do - expect(file_type_icon_class('file', 0, 'filename.XLS')).to eq 'file-excel-o' + it "returns file-excel-o class with .XLS" do + expect(file_type_icon_class("file", 0, "filename.XLS")).to eq "file-excel-o" end - it 'returns file-excel-o class with .xlsx' do - expect(file_type_icon_class('file', 0, 'filename.xlsx')).to eq 'file-excel-o' + it "returns file-excel-o class with .xlsx" do + expect(file_type_icon_class("file", 0, "filename.xlsx")).to eq "file-excel-o" end - it 'returns file-excel-o class with .ppt' do - expect(file_type_icon_class('file', 0, 'filename.ppt')).to eq 'file-powerpoint-o' + it "returns file-excel-o class with .ppt" do + expect(file_type_icon_class("file", 0, "filename.ppt")).to eq "file-powerpoint-o" end - it 'returns file-excel-o class with .PPT' do - expect(file_type_icon_class('file', 0, 'filename.PPT')).to eq 'file-powerpoint-o' + it "returns file-excel-o class with .PPT" do + expect(file_type_icon_class("file", 0, "filename.PPT")).to eq "file-powerpoint-o" end - it 'returns file-excel-o class with .pptx' do - expect(file_type_icon_class('file', 0, 'filename.pptx')).to eq 'file-powerpoint-o' + it "returns file-excel-o class with .pptx" do + expect(file_type_icon_class("file", 0, "filename.pptx")).to eq "file-powerpoint-o" end - it 'returns file-text-o class with .unknow' do - expect(file_type_icon_class('file', 0, 'filename.unknow')).to eq 'file-text-o' + it "returns file-text-o class with .unknow" do + expect(file_type_icon_class("file", 0, "filename.unknow")).to eq "file-text-o" end - it 'returns file-text-o class with no extension' do - expect(file_type_icon_class('file', 0, 'CHANGELOG')).to eq 'file-text-o' + it "returns file-text-o class with no extension" do + expect(file_type_icon_class("file", 0, "CHANGELOG")).to eq "file-text-o" end end - describe '#external_snippet_icon' do - it 'returns external snippet icon' do - expect(external_snippet_icon('download').to_s) + describe "#external_snippet_icon" do + it "returns external snippet icon" do + expect(external_snippet_icon("download").to_s) .to eq("") end end diff --git a/spec/helpers/import_helper_spec.rb b/spec/helpers/import_helper_spec.rb index 6e8c13db9fe..406f8c53ae6 100644 --- a/spec/helpers/import_helper_spec.rb +++ b/spec/helpers/import_helper_spec.rb @@ -1,50 +1,50 @@ -require 'rails_helper' +require "rails_helper" describe ImportHelper do - describe '#sanitize_project_name' do - it 'removes leading tildes' do - expect(helper.sanitize_project_name('~~root')).to eq('root') + describe "#sanitize_project_name" do + it "removes leading tildes" do + expect(helper.sanitize_project_name("~~root")).to eq("root") end - it 'removes whitespace' do - expect(helper.sanitize_project_name('my test repo')).to eq('my-test-repo') + it "removes whitespace" do + expect(helper.sanitize_project_name("my test repo")).to eq("my-test-repo") end - it 'removes disallowed characters' do - expect(helper.sanitize_project_name('Test&me$over*h_ere')).to eq('Test-me-over-h_ere') + it "removes disallowed characters" do + expect(helper.sanitize_project_name("Test&me$over*h_ere")).to eq("Test-me-over-h_ere") end end - describe '#import_project_target' do + describe "#import_project_target" do let(:user) { create(:user) } before do allow(helper).to receive(:current_user).and_return(user) end - context 'when current user can create namespaces' do - it 'returns project namespace' do + context "when current user can create namespaces" do + it "returns project namespace" do user.update_attribute(:can_create_group, true) - expect(helper.import_project_target('asd', 'vim')).to eq 'asd/vim' + expect(helper.import_project_target("asd", "vim")).to eq "asd/vim" end end - context 'when current user can not create namespaces' do + context "when current user can not create namespaces" do it "takes the current user's namespace" do user.update_attribute(:can_create_group, false) - expect(helper.import_project_target('asd', 'vim')).to eq "#{user.namespace_path}/vim" + expect(helper.import_project_target("asd", "vim")).to eq "#{user.namespace_path}/vim" end end end - describe '#provider_project_link_url' do - let(:full_path) { '/repo/path' } - let(:host_url) { 'http://provider.com/' } + describe "#provider_project_link_url" do + let(:full_path) { "/repo/path" } + let(:host_url) { "http://provider.com/" } - it 'appends repo full path to provider host url' do - expect(helper.provider_project_link_url(host_url, full_path)).to match('http://provider.com/repo/path') + it "appends repo full path to provider host url" do + expect(helper.provider_project_link_url(host_url, full_path)).to match("http://provider.com/repo/path") end end end diff --git a/spec/helpers/instance_configuration_helper_spec.rb b/spec/helpers/instance_configuration_helper_spec.rb index 5d716b9191d..db7dd65da31 100644 --- a/spec/helpers/instance_configuration_helper_spec.rb +++ b/spec/helpers/instance_configuration_helper_spec.rb @@ -1,51 +1,51 @@ -require 'spec_helper' +require "spec_helper" describe InstanceConfigurationHelper do - describe '#instance_configuration_cell_html' do - describe 'if not block is passed' do - it 'returns the parameter if present' do - expect(helper.instance_configuration_cell_html('gitlab')).to eq('gitlab') + describe "#instance_configuration_cell_html" do + describe "if not block is passed" do + it "returns the parameter if present" do + expect(helper.instance_configuration_cell_html("gitlab")).to eq("gitlab") end it 'returns "-" if the parameter is blank' do - expect(helper.instance_configuration_cell_html(nil)).to eq('-') - expect(helper.instance_configuration_cell_html('')).to eq('-') + expect(helper.instance_configuration_cell_html(nil)).to eq("-") + expect(helper.instance_configuration_cell_html("")).to eq("-") end end - describe 'if a block is passed' do + describe "if a block is passed" do let(:upcase_block) { ->(value) { value.upcase } } - it 'returns the result of the block' do - expect(helper.instance_configuration_cell_html('gitlab', &upcase_block)).to eq('GITLAB') - expect(helper.instance_configuration_cell_html('gitlab') { |v| v.upcase }).to eq('GITLAB') + it "returns the result of the block" do + expect(helper.instance_configuration_cell_html("gitlab", &upcase_block)).to eq("GITLAB") + expect(helper.instance_configuration_cell_html("gitlab") { |v| v.upcase }).to eq("GITLAB") end it 'returns "-" if the parameter is blank' do - expect(helper.instance_configuration_cell_html(nil, &upcase_block)).to eq('-') - expect(helper.instance_configuration_cell_html(nil) { |v| v.upcase }).to eq('-') - expect(helper.instance_configuration_cell_html('', &upcase_block)).to eq('-') + expect(helper.instance_configuration_cell_html(nil, &upcase_block)).to eq("-") + expect(helper.instance_configuration_cell_html(nil) { |v| v.upcase }).to eq("-") + expect(helper.instance_configuration_cell_html("", &upcase_block)).to eq("-") end end - it 'boolean are valid values to display' do + it "boolean are valid values to display" do expect(helper.instance_configuration_cell_html(true)).to eq(true) expect(helper.instance_configuration_cell_html(false)).to eq(false) end end - describe '#instance_configuration_human_size_cell' do + describe "#instance_configuration_human_size_cell" do it 'returns "-" if the parameter is blank' do - expect(helper.instance_configuration_human_size_cell(nil)).to eq('-') - expect(helper.instance_configuration_human_size_cell('')).to eq('-') + expect(helper.instance_configuration_human_size_cell(nil)).to eq("-") + expect(helper.instance_configuration_human_size_cell("")).to eq("-") end - it 'accepts the value in bytes' do - expect(helper.instance_configuration_human_size_cell(1024)).to eq('1 KB') + it "accepts the value in bytes" do + expect(helper.instance_configuration_human_size_cell(1024)).to eq("1 KB") end - it 'returns the value in human size readable format' do - expect(helper.instance_configuration_human_size_cell(1048576)).to eq('1 MB') + it "returns the value in human size readable format" do + expect(helper.instance_configuration_human_size_cell(1048576)).to eq("1 MB") end end end diff --git a/spec/helpers/issuables_helper_spec.rb b/spec/helpers/issuables_helper_spec.rb index 8b82dea2524..0c191a3e99c 100644 --- a/spec/helpers/issuables_helper_spec.rb +++ b/spec/helpers/issuables_helper_spec.rb @@ -1,68 +1,68 @@ -require 'spec_helper' +require "spec_helper" describe IssuablesHelper do let(:label) { build_stubbed(:label) } let(:label2) { build_stubbed(:label) } - describe '#users_dropdown_label' do + describe "#users_dropdown_label" do let(:user) { build_stubbed(:user) } let(:user2) { build_stubbed(:user) } - it 'returns unassigned' do - expect(users_dropdown_label([])).to eq('Unassigned') + it "returns unassigned" do + expect(users_dropdown_label([])).to eq("Unassigned") end - it 'returns selected user\'s name' do + it "returns selected user's name" do expect(users_dropdown_label([user])).to eq(user.name) end - it 'returns selected user\'s name and counter' do + it "returns selected user's name and counter" do expect(users_dropdown_label([user, user2])).to eq("#{user.name} + 1 more") end end - describe '#group_dropdown_label' do + describe "#group_dropdown_label" do let(:group) { create(:group) } - let(:default) { 'default label' } + let(:default) { "default label" } - it 'returns default group label when group_id is nil' do - expect(group_dropdown_label(nil, default)).to eq('default label') + it "returns default group label when group_id is nil" do + expect(group_dropdown_label(nil, default)).to eq("default label") end it 'returns "any group" when group_id is 0' do - expect(group_dropdown_label('0', default)).to eq('Any group') + expect(group_dropdown_label("0", default)).to eq("Any group") end - it 'returns group full path when a group was found for the provided id' do + it "returns group full path when a group was found for the provided id" do expect(group_dropdown_label(group.id, default)).to eq(group.full_name) end - it 'returns default label when a group was not found for the provided id' do - expect(group_dropdown_label(9999, default)).to eq('default label') + it "returns default label when a group was not found for the provided id" do + expect(group_dropdown_label(9999, default)).to eq("default label") end end - describe '#issuable_labels_tooltip' do + describe "#issuable_labels_tooltip" do let(:label_entity) { LabelEntity.represent(label).as_json } let(:label2_entity) { LabelEntity.represent(label2).as_json } - it 'returns label text with no labels' do + it "returns label text with no labels" do expect(issuable_labels_tooltip([])).to eq("Labels") end - it 'returns label text with labels within max limit' do + it "returns label text with labels within max limit" do expect(issuable_labels_tooltip([label_entity])).to eq(label[:title]) end - it 'returns label text with labels exceeding max limit' do + it "returns label text with labels exceeding max limit" do expect(issuable_labels_tooltip([label_entity, label2_entity], limit: 1)).to eq("#{label[:title]}, and 1 more") end end - describe '#issuables_state_counter_text' do + describe "#issuables_state_counter_text" do let(:user) { create(:user) } - describe 'state text' do + describe "state text" do before do allow(helper).to receive(:issuables_count_for_state).and_return(42) end @@ -89,9 +89,9 @@ describe IssuablesHelper do end end - describe '#issuable_reference' do - context 'when show_full_reference truthy' do - it 'display issuable full reference' do + describe "#issuable_reference" do + context "when show_full_reference truthy" do + it "display issuable full reference" do assign(:show_full_reference, true) issue = build_stubbed(:issue) @@ -99,9 +99,9 @@ describe IssuablesHelper do end end - context 'when show_full_reference falsey' do - context 'when @group present' do - it 'display issuable reference to @group' do + context "when show_full_reference falsey" do + context "when @group present" do + it "display issuable reference to @group" do project = build_stubbed(:project) assign(:show_full_reference, nil) @@ -113,8 +113,8 @@ describe IssuablesHelper do end end - context 'when @project present' do - it 'display issuable reference to @project' do + context "when @project present" do + it "display issuable reference to @project" do project = build_stubbed(:project) assign(:show_full_reference, nil) @@ -129,7 +129,7 @@ describe IssuablesHelper do end end - describe '#updated_at_by' do + describe "#updated_at_by" do let(:user) { create(:user) } let(:unedited_issuable) { create(:issue) } let(:edited_issuable) { create(:issue, last_edited_by: user, created_at: 3.days.ago, updated_at: 1.day.ago, last_edited_at: 2.days.ago) } @@ -138,22 +138,22 @@ describe IssuablesHelper do updatedAt: edited_issuable.last_edited_at.to_time.iso8601, updatedBy: { name: user.name, - path: user_path(user) - } + path: user_path(user), + }, } end it { expect(helper.updated_at_by(unedited_issuable)).to eq({}) } it { expect(helper.updated_at_by(edited_issuable)).to eq(edited_updated_at_by) } - context 'when updated by a deleted user' do + context "when updated by a deleted user" do let(:edited_updated_at_by) do { updatedAt: edited_issuable.last_edited_at.to_time.iso8601, updatedBy: { name: User.ghost.name, - path: user_path(User.ghost) - } + path: user_path(User.ghost), + }, } end @@ -167,7 +167,7 @@ describe IssuablesHelper do end end - describe '#issuable_initial_data' do + describe "#issuable_initial_data" do let(:user) { create(:user) } before do @@ -176,8 +176,8 @@ describe IssuablesHelper do stub_commonmark_sourcepos_disabled end - it 'returns the correct json for an issue' do - issue = create(:issue, author: user, description: 'issue text') + it "returns the correct json for an issue" do + issue = create(:issue, author: user, description: "issue text") @project = issue.project expected_data = { @@ -187,7 +187,7 @@ describe IssuablesHelper do canDestroy: true, issuableRef: "##{issue.iid}", markdownPreviewPath: "/#{@project.full_path}/preview_markdown", - markdownDocsPath: '/help/user/markdown', + markdownDocsPath: "/help/user/markdown", issuableTemplates: [], lockVersion: issue.lock_version, projectPath: @project.path, @@ -195,8 +195,8 @@ describe IssuablesHelper do initialTitleHtml: issue.title, initialTitleText: issue.title, initialDescriptionHtml: '

    issue text

    ', - initialDescriptionText: 'issue text', - initialTaskStatus: '0 of 0 tasks completed' + initialDescriptionText: "issue text", + initialTaskStatus: "0 of 0 tasks completed", } expect(helper.issuable_initial_data(issue)).to eq(expected_data) end diff --git a/spec/helpers/issues_helper_spec.rb b/spec/helpers/issues_helper_spec.rb index 039143eb8d7..1b829842a3c 100644 --- a/spec/helpers/issues_helper_spec.rb +++ b/spec/helpers/issues_helper_spec.rb @@ -7,7 +7,7 @@ describe IssuesHelper do describe "url_for_issue" do let(:issues_url) { ext_project.external_issue_tracker.issues_url} - let(:ext_expected) { issues_url.gsub(':id', issue.iid.to_s).gsub(':project_id', ext_project.id.to_s) } + let(:ext_expected) { issues_url.gsub(":id", issue.iid.to_s).gsub(":project_id", ext_project.id.to_s) } let(:int_expected) { polymorphic_path([@project.namespace, @project, issue]) } it "returns internal path if used internal tracker" do @@ -34,16 +34,16 @@ describe IssuesHelper do expect(url_for_issue(issue.iid)).to eq "" end - it 'returns an empty string if issue_url is invalid' do - expect(project).to receive_message_chain('issues_tracker.issue_url') { 'javascript:alert("foo");' } + it "returns an empty string if issue_url is invalid" do + expect(project).to receive_message_chain("issues_tracker.issue_url") { 'javascript:alert("foo");' } - expect(url_for_issue(issue.iid, project)).to eq '' + expect(url_for_issue(issue.iid, project)).to eq "" end - it 'returns an empty string if issue_path is invalid' do - expect(project).to receive_message_chain('issues_tracker.issue_path') { 'javascript:alert("foo");' } + it "returns an empty string if issue_path is invalid" do + expect(project).to receive_message_chain("issues_tracker.issue_path") { 'javascript:alert("foo");' } - expect(url_for_issue(issue.iid, project, only_path: true)).to eq '' + expect(url_for_issue(issue.iid, project, only_path: true)).to eq "" end describe "when external tracker was enabled and then config removed" do @@ -58,35 +58,35 @@ describe IssuesHelper do end end - describe '#award_user_list' do + describe "#award_user_list" do it "returns a comma-separated list of the first X users" do - user = build_stubbed(:user, name: 'Joe') + user = build_stubbed(:user, name: "Joe") awards = Array.new(3, build_stubbed(:award_emoji, user: user)) expect(award_user_list(awards, nil, limit: 3)) - .to eq('Joe, Joe, and Joe') + .to eq("Joe, Joe, and Joe") end it "displays the current user's name as 'You'" do - user = build_stubbed(:user, name: 'Joe') + user = build_stubbed(:user, name: "Joe") award = build_stubbed(:award_emoji, user: user) - expect(award_user_list([award], user)).to eq('You') - expect(award_user_list([award], nil)).to eq 'Joe' + expect(award_user_list([award], user)).to eq("You") + expect(award_user_list([award], nil)).to eq "Joe" end it "truncates lists" do - user = build_stubbed(:user, name: 'Jane') + user = build_stubbed(:user, name: "Jane") awards = Array.new(5, build_stubbed(:award_emoji, user: user)) expect(award_user_list(awards, nil, limit: 3)) - .to eq('Jane, Jane, Jane, and 2 more.') + .to eq("Jane, Jane, Jane, and 2 more.") end it "displays the current user in front of other users" do current_user = build_stubbed(:user) my_award = build_stubbed(:award_emoji, user: current_user) - award = build_stubbed(:award_emoji, user: build_stubbed(:user, name: 'Jane')) + award = build_stubbed(:award_emoji, user: build_stubbed(:user, name: "Jane")) awards = Array.new(5, award).push(my_award) expect(award_user_list(awards, current_user, limit: 2)) @@ -94,7 +94,7 @@ describe IssuesHelper do end end - describe '#award_state_class' do + describe "#award_state_class" do let!(:upvote) { create(:award_emoji) } let(:awardable) { upvote.awardable } let(:user) { upvote.user } @@ -127,8 +127,8 @@ describe IssuesHelper do describe "awards_sort" do it "sorts a hash so thumbsup and thumbsdown are always on top" do - data = { "thumbsdown" => "some value", "lifter" => "some value", "thumbsup" => "some value" } - expect(awards_sort(data).keys).to eq(%w(thumbsup thumbsdown lifter)) + data = {"thumbsdown" => "some value", "lifter" => "some value", "thumbsup" => "some value"} + expect(awards_sort(data).keys).to eq(%w[thumbsup thumbsdown lifter]) end end @@ -164,20 +164,20 @@ describe IssuesHelper do end end - describe '#show_new_issue_link?' do + describe "#show_new_issue_link?" do before do allow(helper).to receive(:current_user) end - it 'is false when no project there is no project' do + it "is false when no project there is no project" do expect(helper.show_new_issue_link?(nil)).to be_falsey end - it 'is true when there is a project and no logged in user' do + it "is true when there is a project and no logged in user" do expect(helper.show_new_issue_link?(build(:project))).to be_truthy end - it 'is true when the current user does not have access to the project' do + it "is true when the current user does not have access to the project" do project = build(:project) allow(helper).to receive(:current_user).and_return(project.owner) diff --git a/spec/helpers/labels_helper_spec.rb b/spec/helpers/labels_helper_spec.rb index 012678db9c2..a0787584ae7 100644 --- a/spec/helpers/labels_helper_spec.rb +++ b/spec/helpers/labels_helper_spec.rb @@ -1,248 +1,248 @@ -require 'spec_helper' +require "spec_helper" describe LabelsHelper do - describe '#show_label_issuables_link?' do - shared_examples 'a valid response to show_label_issuables_link?' do |issuables_type, when_enabled = true, when_disabled = false| + describe "#show_label_issuables_link?" do + shared_examples "a valid response to show_label_issuables_link?" do |issuables_type, when_enabled = true, when_disabled = false| let(:context_project) { project } context "when asking for a #{issuables_type} link" do subject { show_label_issuables_link?(label, issuables_type, project: context_project) } context "when #{issuables_type} are enabled for the project" do - let(:project) { create(:project, "#{issuables_type}_access_level": ProjectFeature::ENABLED) } + let(:project) { create(:project, :"#{issuables_type}_access_level" => ProjectFeature::ENABLED) } it { is_expected.to be(when_enabled) } end context "when #{issuables_type} are disabled for the project" do - let(:project) { create(:project, :public, "#{issuables_type}_access_level": ProjectFeature::DISABLED) } + let(:project) { create(:project, :public, :"#{issuables_type}_access_level" => ProjectFeature::DISABLED) } it { is_expected.to be(when_disabled) } end end end - context 'with a project label' do - let(:label) { create(:label, project: project, title: 'bug') } + context "with a project label" do + let(:label) { create(:label, project: project, title: "bug") } - context 'when asking for an issue link' do - it_behaves_like 'a valid response to show_label_issuables_link?', :issues + context "when asking for an issue link" do + it_behaves_like "a valid response to show_label_issuables_link?", :issues end - context 'when asking for a merge requests link' do - it_behaves_like 'a valid response to show_label_issuables_link?', :merge_requests + context "when asking for a merge requests link" do + it_behaves_like "a valid response to show_label_issuables_link?", :merge_requests end end - context 'with a group label' do + context "with a group label" do set(:group) { create(:group) } - let(:label) { create(:group_label, group: group, title: 'bug') } + let(:label) { create(:group_label, group: group, title: "bug") } - context 'when asking for an issue link' do - context 'in the context of a project' do - it_behaves_like 'a valid response to show_label_issuables_link?', :issues, true, true + context "when asking for an issue link" do + context "in the context of a project" do + it_behaves_like "a valid response to show_label_issuables_link?", :issues, true, true end - context 'in the context of a group' do + context "in the context of a group" do let(:context_project) { nil } - it_behaves_like 'a valid response to show_label_issuables_link?', :issues, true, true + it_behaves_like "a valid response to show_label_issuables_link?", :issues, true, true end end - context 'when asking for a merge requests link' do - context 'in the context of a project' do - it_behaves_like 'a valid response to show_label_issuables_link?', :merge_requests, true, true + context "when asking for a merge requests link" do + context "in the context of a project" do + it_behaves_like "a valid response to show_label_issuables_link?", :merge_requests, true, true end - context 'in the context of a group' do + context "in the context of a group" do let(:context_project) { nil } - it_behaves_like 'a valid response to show_label_issuables_link?', :merge_requests, true, true + it_behaves_like "a valid response to show_label_issuables_link?", :merge_requests, true, true end end end end - describe 'link_to_label' do + describe "link_to_label" do let(:project) { create(:project) } let(:label) { create(:label, project: project) } - context 'without subject' do + context "without subject" do it "uses the label's project" do expect(link_to_label(label)).to match %r{.*} end end - context 'with a project as subject' do - let(:namespace) { build(:namespace, name: 'foo3') } - let(:another_project) { build(:project, namespace: namespace, name: 'bar3') } + context "with a project as subject" do + let(:namespace) { build(:namespace, name: "foo3") } + let(:another_project) { build(:project, namespace: namespace, name: "bar3") } - it 'links to project issues page' do + it "links to project issues page" do expect(link_to_label(label, subject: another_project)).to match %r{.*} end end - context 'with a group as subject' do - let(:group) { build(:group, name: 'bar') } + context "with a group as subject" do + let(:group) { build(:group, name: "bar") } - it 'links to group issues page' do + it "links to group issues page" do expect(link_to_label(label, subject: group)).to match %r{.*} end end - context 'with a type argument' do - ['issue', :issue, 'merge_request', :merge_request].each do |type| + context "with a type argument" do + ["issue", :issue, "merge_request", :merge_request].each do |type| context "set to #{type}" do - it 'links to correct page' do + it "links to correct page" do expect(link_to_label(label, type: type)).to match %r{.*} end end end end - context 'with a tooltip argument' do - context 'set to false' do - it 'does not include the has-tooltip class' do + context "with a tooltip argument" do + context "set to false" do + it "does not include the has-tooltip class" do expect(link_to_label(label, tooltip: false)).not_to match /has-tooltip/ end end end - context 'with block' do - it 'passes the block to link_to' do - link = link_to_label(label) { 'Foo' } - expect(link).to match('Foo') + context "with block" do + it "passes the block to link_to" do + link = link_to_label(label) { "Foo" } + expect(link).to match("Foo") end end - context 'without block' do - it 'uses render_colored_label as the link content' do + context "without block" do + it "uses render_colored_label as the link content" do expect(self).to receive(:render_colored_label) - .with(label, tooltip: true).and_return('Foo') - expect(link_to_label(label)).to match('Foo') + .with(label, tooltip: true).and_return("Foo") + expect(link_to_label(label)).to match("Foo") end end end - describe 'text_color_for_bg' do - it 'uses light text on dark backgrounds' do - expect(text_color_for_bg('#222E2E')).to eq('#FFFFFF') + describe "text_color_for_bg" do + it "uses light text on dark backgrounds" do + expect(text_color_for_bg("#222E2E")).to eq("#FFFFFF") end - it 'uses dark text on light backgrounds' do - expect(text_color_for_bg('#EEEEEE')).to eq('#333333') + it "uses dark text on light backgrounds" do + expect(text_color_for_bg("#EEEEEE")).to eq("#333333") end - it 'supports RGB triplets' do - expect(text_color_for_bg('#FFF')).to eq '#333333' - expect(text_color_for_bg('#000')).to eq '#FFFFFF' + it "supports RGB triplets" do + expect(text_color_for_bg("#FFF")).to eq "#333333" + expect(text_color_for_bg("#000")).to eq "#FFFFFF" end end - describe 'create_label_title' do + describe "create_label_title" do set(:group) { create(:group) } - context 'with a group as subject' do + context "with a group as subject" do it 'returns "Create group label"' do - expect(create_label_title(group)).to eq 'Create group label' + expect(create_label_title(group)).to eq "Create group label" end end - context 'with a project as subject' do + context "with a project as subject" do set(:project) { create(:project, namespace: group) } it 'returns "Create project label"' do - expect(create_label_title(project)).to eq 'Create project label' + expect(create_label_title(project)).to eq "Create project label" end end - context 'with no subject' do + context "with no subject" do it 'returns "Create new label"' do - expect(create_label_title(nil)).to eq 'Create new label' + expect(create_label_title(nil)).to eq "Create new label" end end end - describe 'manage_labels_title' do + describe "manage_labels_title" do set(:group) { create(:group) } - context 'with a group as subject' do + context "with a group as subject" do it 'returns "Manage group labels"' do - expect(manage_labels_title(group)).to eq 'Manage group labels' + expect(manage_labels_title(group)).to eq "Manage group labels" end end - context 'with a project as subject' do + context "with a project as subject" do set(:project) { create(:project, namespace: group) } it 'returns "Manage project labels"' do - expect(manage_labels_title(project)).to eq 'Manage project labels' + expect(manage_labels_title(project)).to eq "Manage project labels" end end - context 'with no subject' do + context "with no subject" do it 'returns "Manage labels"' do - expect(manage_labels_title(nil)).to eq 'Manage labels' + expect(manage_labels_title(nil)).to eq "Manage labels" end end end - describe 'view_labels_title' do + describe "view_labels_title" do set(:group) { create(:group) } - context 'with a group as subject' do + context "with a group as subject" do it 'returns "View group labels"' do - expect(view_labels_title(group)).to eq 'View group labels' + expect(view_labels_title(group)).to eq "View group labels" end end - context 'with a project as subject' do + context "with a project as subject" do set(:project) { create(:project, namespace: group) } it 'returns "View project labels"' do - expect(view_labels_title(project)).to eq 'View project labels' + expect(view_labels_title(project)).to eq "View project labels" end end - context 'with no subject' do + context "with no subject" do it 'returns "View labels"' do - expect(view_labels_title(nil)).to eq 'View labels' + expect(view_labels_title(nil)).to eq "View labels" end end end - describe 'labels_filter_path' do + describe "labels_filter_path" do let(:group) { create(:group) } let(:project) { create(:project) } - it 'links to the dashboard labels page' do + it "links to the dashboard labels page" do expect(labels_filter_path).to eq(dashboard_labels_path) end - it 'links to the group labels page' do + it "links to the group labels page" do assign(:group, group) expect(helper.labels_filter_path).to eq(group_labels_path(group)) end - it 'links to the project labels page' do + it "links to the project labels page" do assign(:project, project) expect(helper.labels_filter_path).to eq(project_labels_path(project)) end - it 'supports json format' do + it "supports json format" do expect(labels_filter_path(format: :json)).to eq(dashboard_labels_path(format: :json)) end end - describe 'labels_sorted_by_title' do - it 'sorts labels alphabetically' do - label1 = double(:label, title: 'a') - label2 = double(:label, title: 'B') - label3 = double(:label, title: 'c') - label4 = double(:label, title: 'D') + describe "labels_sorted_by_title" do + it "sorts labels alphabetically" do + label1 = double(:label, title: "a") + label2 = double(:label, title: "B") + label3 = double(:label, title: "c") + label4 = double(:label, title: "D") labels = [label1, label2, label3, label4] expect(labels_sorted_by_title(labels)) diff --git a/spec/helpers/markup_helper_spec.rb b/spec/helpers/markup_helper_spec.rb index c3956ba08fd..868a8b41c79 100644 --- a/spec/helpers/markup_helper_spec.rb +++ b/spec/helpers/markup_helper_spec.rb @@ -1,9 +1,9 @@ -require 'spec_helper' +require "spec_helper" describe MarkupHelper do let!(:project) { create(:project, :repository) } - let(:user) { create(:user, username: 'gfm') } + let(:user) { create(:user, username: "gfm") } let(:commit) { project.commit } let(:issue) { create(:issue, project: project) } let(:merge_request) { create(:merge_request, source_project: project, target_project: project) } @@ -45,28 +45,28 @@ describe MarkupHelper do let(:second_project) { create(:project, :public) } let(:second_issue) { create(:issue, project: second_project) } - it 'links to the issue' do + it "links to the issue" do expected = urls.project_issue_path(second_project, second_issue) expect(markdown(actual, project: second_project)).to match(expected) end end end - describe '#markdown_field' do + describe "#markdown_field" do let(:attribute) { :title } - describe 'with already redacted attribute' do - it 'returns the redacted attribute' do - commit.redacted_title_html = 'commit title' + describe "with already redacted attribute" do + it "returns the redacted attribute" do + commit.redacted_title_html = "commit title" expect(Banzai).not_to receive(:render_field) - expect(helper.markdown_field(commit, attribute)).to eq('commit title') + expect(helper.markdown_field(commit, attribute)).to eq("commit title") end end - describe 'without redacted attribute' do - it 'renders the markdown value' do + describe "without redacted attribute" do + it "renders the markdown value" do expect(Banzai).to receive(:render_field).with(commit, attribute, {}).and_call_original helper.markdown_field(commit, attribute) @@ -74,11 +74,11 @@ describe MarkupHelper do end end - describe '#link_to_markdown_field' do - let(:link) { '/commits/0a1b2c3d' } + describe "#link_to_markdown_field" do + let(:link) { "/commits/0a1b2c3d" } let(:issues) { create_list(:issue, 2, project: project) } - it 'handles references nested in links with all the text' do + it "handles references nested in links with all the text" do allow(commit).to receive(:title).and_return("This should finally fix #{issues[0].to_reference} and #{issues[1].to_reference} for real") actual = helper.link_to_markdown_field(commit, :title, link) @@ -88,34 +88,34 @@ describe MarkupHelper do expect(doc.errors).to be_empty # Leading commit link - 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].attr("href")).to eq link + expect(doc.css("a")[0].text).to eq "This should finally fix " # First issue link - expect(doc.css('a')[1].attr('href')) + expect(doc.css("a")[1].attr("href")) .to eq urls.project_issue_path(project, issues[0]) - 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 - expect(doc.css('a')[2].attr('href')).to eq link - expect(doc.css('a')[2].text).to eq ' and ' + expect(doc.css("a")[2].attr("href")).to eq link + expect(doc.css("a")[2].text).to eq " and " # Second issue link - expect(doc.css('a')[3].attr('href')) + expect(doc.css("a")[3].attr("href")) .to eq urls.project_issue_path(project, issues[1]) - 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 - 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].attr("href")).to eq link + expect(doc.css("a")[4].text).to eq " for real" end end - describe '#link_to_markdown' do - let(:link) { '/commits/0a1b2c3d' } + describe "#link_to_markdown" do + let(:link) { "/commits/0a1b2c3d" } let(:issues) { create_list(:issue, 2, project: 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_markdown("This should finally fix #{issues[0].to_reference} and #{issues[1].to_reference} for real", link) doc = Nokogiri::HTML.parse(actual) @@ -123,89 +123,89 @@ describe MarkupHelper do expect(doc.errors).to be_empty # Leading commit link - 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].attr("href")).to eq link + expect(doc.css("a")[0].text).to eq "This should finally fix " # First issue link - expect(doc.css('a')[1].attr('href')) + expect(doc.css("a")[1].attr("href")) .to eq urls.project_issue_path(project, issues[0]) - 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 - expect(doc.css('a')[2].attr('href')).to eq link - expect(doc.css('a')[2].text).to eq ' and ' + expect(doc.css("a")[2].attr("href")).to eq link + expect(doc.css("a")[2].text).to eq " and " # Second issue link - expect(doc.css('a')[3].attr('href')) + expect(doc.css("a")[3].attr("href")) .to eq urls.project_issue_path(project, issues[1]) - 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 - 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].attr("href")).to eq link + expect(doc.css("a")[4].text).to eq " for real" end - it 'forwards HTML options' do - actual = helper.link_to_markdown("Fixed in #{commit.id}", link, class: 'foo') + it "forwards HTML options" do + actual = helper.link_to_markdown("Fixed in #{commit.id}", link, class: "foo") doc = Nokogiri::HTML.parse(actual) - expect(doc.css('a')).to satisfy do |v| + expect(doc.css("a")).to satisfy do |v| # 'foo' gets added to all links - v.all? { |a| a.attr('class').match(/foo$/) } + v.all? { |a| a.attr("class").match(/foo$/) } end end it "escapes HTML passed in as the body" do actual = "This is a

    test

    - see #{issues[0].to_reference}" expect(helper.link_to_markdown(actual, link)) - .to match('<h1>test</h1>') + .to match("<h1>test</h1>") end - it 'ignores reference links when they are the entire body' do + it "ignores reference links when they are the entire body" do text = issues[0].to_reference - act = helper.link_to_markdown(text, '/foo') - expect(act).to eq %Q(#{issues[0].to_reference}) + act = helper.link_to_markdown(text, "/foo") + expect(act).to eq %(#{issues[0].to_reference}) end - it 'replaces commit message with emoji to link' do - actual = link_to_markdown(':book: Book', '/foo') + it "replaces commit message with emoji to link" do + actual = link_to_markdown(":book: Book", "/foo") expect(actual) .to eq '📖 Book' end end - describe '#link_to_html' do - it 'wraps the rendered content in a link' do - link = '/commits/0a1b2c3d' + describe "#link_to_html" do + it "wraps the rendered content in a link" do + link = "/commits/0a1b2c3d" issue = create(:issue, project: project) rendered = helper.markdown("This should finally fix #{issue.to_reference} for real", pipeline: :single_line) doc = Nokogiri::HTML.parse(rendered) - expect(doc.css('a')[0].attr('href')) + expect(doc.css("a")[0].attr("href")) .to eq urls.project_issue_path(project, issue) - expect(doc.css('a')[0].text).to eq issue.to_reference + expect(doc.css("a")[0].text).to eq issue.to_reference wrapped = helper.link_to_html(rendered, link) doc = Nokogiri::HTML.parse(wrapped) - 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].attr("href")).to eq link + expect(doc.css("a")[0].text).to eq "This should finally fix " end end - describe '#render_wiki_content' do + describe "#render_wiki_content" do before do - @wiki = double('WikiPage') - allow(@wiki).to receive(:content).and_return('wiki content') - allow(@wiki).to receive(:slug).and_return('nested/page') + @wiki = double("WikiPage") + allow(@wiki).to receive(:content).and_return("wiki content") + allow(@wiki).to receive(:slug).and_return("nested/page") helper.instance_variable_set(:@project_wiki, @wiki) end it "uses Wiki pipeline for markdown files" do allow(@wiki).to receive(:format).and_return(:markdown) - expect(helper).to receive(:markdown_unsafe).with('wiki content', + expect(helper).to receive(:markdown_unsafe).with("wiki content", pipeline: :wiki, project: project, project_wiki: @wiki, page_slug: "nested/page", issuable_state_filter_enabled: true) @@ -215,14 +215,14 @@ describe MarkupHelper do it "uses Asciidoctor for asciidoc files" do allow(@wiki).to receive(:format).and_return(:asciidoc) - expect(helper).to receive(:asciidoc_unsafe).with('wiki content') + expect(helper).to receive(:asciidoc_unsafe).with("wiki content") helper.render_wiki_content(@wiki) end it "uses the Gollum renderer for all other file types" do allow(@wiki).to receive(:format).and_return(:rdoc) - formatted_content_stub = double('formatted_content') + formatted_content_stub = double("formatted_content") expect(formatted_content_stub).to receive(:html_safe) allow(@wiki).to receive(:formatted_content).and_return(formatted_content_stub) @@ -230,86 +230,86 @@ describe MarkupHelper do end end - describe 'markup' do - let(:content) { 'Noël' } + describe "markup" do + let(:content) { "Noël" } - it 'preserves encoding' do - expect(content.encoding.name).to eq('UTF-8') - expect(helper.markup('foo.rst', content).encoding.name).to eq('UTF-8') + it "preserves encoding" do + expect(content.encoding.name).to eq("UTF-8") + expect(helper.markup("foo.rst", content).encoding.name).to eq("UTF-8") end - it 'delegates to #markdown_unsafe when file name corresponds to Markdown' do - expect(helper).to receive(:gitlab_markdown?).with('foo.md').and_return(true) - expect(helper).to receive(:markdown_unsafe).and_return('NOEL') + it "delegates to #markdown_unsafe when file name corresponds to Markdown" do + expect(helper).to receive(:gitlab_markdown?).with("foo.md").and_return(true) + expect(helper).to receive(:markdown_unsafe).and_return("NOEL") - expect(helper.markup('foo.md', content)).to eq('NOEL') + expect(helper.markup("foo.md", content)).to eq("NOEL") end - it 'delegates to #asciidoc_unsafe when file name corresponds to AsciiDoc' do - expect(helper).to receive(:asciidoc?).with('foo.adoc').and_return(true) - expect(helper).to receive(:asciidoc_unsafe).and_return('NOEL') + it "delegates to #asciidoc_unsafe when file name corresponds to AsciiDoc" do + expect(helper).to receive(:asciidoc?).with("foo.adoc").and_return(true) + expect(helper).to receive(:asciidoc_unsafe).and_return("NOEL") - expect(helper.markup('foo.adoc', content)).to eq('NOEL') + expect(helper.markup("foo.adoc", content)).to eq("NOEL") end - it 'uses passed in rendered content' do + it "uses passed in rendered content" do expect(helper).not_to receive(:gitlab_markdown?) expect(helper).not_to receive(:markdown_unsafe) - expect(helper.markup('foo.md', content, rendered: '

    NOEL

    ')).to eq('

    NOEL

    ') + expect(helper.markup("foo.md", content, rendered: "

    NOEL

    ")).to eq("

    NOEL

    ") end - it 'defaults to CommonMark' do - expect(helper.markup('foo.md', 'x^2')).to include('x^2') + it "defaults to CommonMark" do + expect(helper.markup("foo.md", "x^2")).to include("x^2") end end - describe '#first_line_in_markdown' do - shared_examples_for 'common markdown examples' do + describe "#first_line_in_markdown" do + shared_examples_for "common markdown examples" do let(:project_base) { build(:project, :repository) } - it 'displays inline code' do - object = create_object('Text with `inline code`') - expected = 'Text with inline code' + it "displays inline code" do + object = create_object("Text with `inline code`") + expected = "Text with inline code" expect(first_line_in_markdown(object, attribute, 100, project: project)).to match(expected) end - it 'truncates the text with multiple paragraphs' do + it "truncates the text with multiple paragraphs" do object = create_object("Paragraph 1\n\nParagraph 2") - expected = 'Paragraph 1...' + expected = "Paragraph 1..." expect(first_line_in_markdown(object, attribute, 100, project: project)).to match(expected) end - it 'displays the first line of a code block' do + it "displays the first line of a code block" do object = create_object("```\nCode block\nwith two lines\n```") expected = %r{Code block\.\.\.\n} expect(first_line_in_markdown(object, attribute, 100, project: project)).to match(expected) end - it 'truncates a single long line of text' do - text = 'The quick brown fox jumped over the lazy dog twice' # 50 chars + it "truncates a single long line of text" do + text = "The quick brown fox jumped over the lazy dog twice" # 50 chars object = create_object(text * 4) - expected = (text * 2).sub(/.{3}/, '...') + expected = (text * 2).sub(/.{3}/, "...") expect(first_line_in_markdown(object, attribute, 150, project: project)).to match(expected) end - it 'preserves a link href when link text is truncated' do - text = 'The quick brown fox jumped over the lazy dog' # 44 chars + it "preserves a link href when link text is truncated" do + text = "The quick brown fox jumped over the lazy dog" # 44 chars input = "#{text}#{text}#{text} " # 133 chars - link_url = 'http://example.com/foo/bar/baz' # 30 chars + link_url = "http://example.com/foo/bar/baz" # 30 chars input << link_url object = create_object(input) - expected_link_text = 'http://example...' + expected_link_text = "http://example..." expect(first_line_in_markdown(object, attribute, 150, project: project)).to match(link_url) expect(first_line_in_markdown(object, attribute, 150, project: project)).to match(expected_link_text) end - it 'preserves code color scheme' do + it "preserves code color scheme" do object = create_object("```ruby\ndef test\n 'hello world'\nend\n```") expected = "
    " \
               "def test...\n" \
    @@ -318,51 +318,51 @@ describe MarkupHelper do
             expect(first_line_in_markdown(object, attribute, 150, project: project)).to eq(expected)
           end
     
    -      context 'when images are allowed' do
    -        it 'preserves data-src for lazy images' do
    +      context "when images are allowed" do
    +        it "preserves data-src for lazy images" do
               object    = create_object("![ImageTest](/uploads/test.png)")
               image_url = "data-src=\".*/uploads/test.png\""
               text      = first_line_in_markdown(object, attribute, 150, project: project, allow_images: true)
     
               expect(text).to match(image_url)
    -          expect(text).to match('#{label_title}

    ") end end - it 'truncates Markdown properly' do + it "truncates Markdown properly" do object = create_object("@#{user.username}, can you look at this?\nHello world\n") actual = first_line_in_markdown(object, attribute, 100, project: project) @@ -372,14 +372,14 @@ describe MarkupHelper do expect(doc.errors).to be_empty # Leading user link - expect(doc.css('a').length).to eq(1) - expect(doc.css('a')[0].attr('href')).to eq user_path(user) - expect(doc.css('a')[0].text).to eq "@#{user.username}" + expect(doc.css("a").length).to eq(1) + expect(doc.css("a")[0].attr("href")).to eq user_path(user) + expect(doc.css("a")[0].text).to eq "@#{user.username}" expect(doc.content).to eq "@#{user.username}, can you look at this?..." end - it 'truncates Markdown with emoji properly' do + it "truncates Markdown with emoji properly" do object = create_object("foo :wink:\nbar :grinning:") actual = first_line_in_markdown(object, attribute, 100, project: project) @@ -389,16 +389,16 @@ describe MarkupHelper do # But also account for the 2 errors caused by the unknown `gl-emoji` elements expect(doc.errors.length).to eq(2) - expect(doc.css('gl-emoji').length).to eq(2) - expect(doc.css('gl-emoji')[0].attr('data-name')).to eq 'wink' - expect(doc.css('gl-emoji')[1].attr('data-name')).to eq 'grinning' + expect(doc.css("gl-emoji").length).to eq(2) + expect(doc.css("gl-emoji")[0].attr("data-name")).to eq "wink" + expect(doc.css("gl-emoji")[1].attr("data-name")).to eq "grinning" expect(doc.content).to eq "foo 😉\nbar 😀" end end - context 'when the asked attribute can be redacted' do - include_examples 'common markdown examples' do + context "when the asked attribute can be redacted" do + include_examples "common markdown examples" do let(:attribute) { :note } def create_object(title, project: project_base) build(:note, note: title, project: project) @@ -406,8 +406,8 @@ describe MarkupHelper do end end - context 'when the asked attribute can not be redacted' do - include_examples 'common markdown examples' do + context "when the asked attribute can not be redacted" do + include_examples "common markdown examples" do let(:attribute) { :body } def create_object(title, project: project_base) issue = build(:issue, title: title) @@ -417,12 +417,12 @@ describe MarkupHelper do end end - describe '#cross_project_reference' do - it 'shows the full MR reference' do + describe "#cross_project_reference" do + it "shows the full MR reference" do expect(helper.cross_project_reference(project, merge_request)).to include(project.full_path) end - it 'shows the full issue reference' do + it "shows the full issue reference" do expect(helper.cross_project_reference(project, issue)).to include(project.full_path) end end diff --git a/spec/helpers/members_helper_spec.rb b/spec/helpers/members_helper_spec.rb index 908e8960f37..c684c5a9ad6 100644 --- a/spec/helpers/members_helper_spec.rb +++ b/spec/helpers/members_helper_spec.rb @@ -1,7 +1,7 @@ -require 'spec_helper' +require "spec_helper" describe MembersHelper do - describe '#remove_member_message' do + describe "#remove_member_message" do let(:requester) { create(:user) } let(:project) { create(:project, :public, :access_requestable) } let(:project_member) { build(:project_member, project: project) } @@ -22,7 +22,7 @@ describe MembersHelper do it { expect(remove_member_message(group_member_request, user: requester)).to eq "Are you sure you want to withdraw your access request for the #{group.name} group?" } end - describe '#remove_member_title' do + describe "#remove_member_title" do let(:requester) { create(:user) } let(:project) { create(:project, :public, :access_requestable) } let(:project_member) { build(:project_member, project: project) } @@ -31,13 +31,13 @@ describe MembersHelper do let(:group_member) { build(:group_member, group: group) } let(:group_member_request) { group.request_access(requester) } - it { expect(remove_member_title(project_member)).to eq 'Remove user from project' } - it { expect(remove_member_title(project_member_request)).to eq 'Deny access request from project' } - it { expect(remove_member_title(group_member)).to eq 'Remove user from group and any subresources' } - it { expect(remove_member_title(group_member_request)).to eq 'Deny access request from group' } + it { expect(remove_member_title(project_member)).to eq "Remove user from project" } + it { expect(remove_member_title(project_member_request)).to eq "Deny access request from project" } + it { expect(remove_member_title(group_member)).to eq "Remove user from group and any subresources" } + it { expect(remove_member_title(group_member_request)).to eq "Deny access request from group" } end - describe '#leave_confirmation_message' do + describe "#leave_confirmation_message" do let(:project) { build_stubbed(:project) } let(:group) { build_stubbed(:group) } let(:user) { build_stubbed(:user) } diff --git a/spec/helpers/merge_requests_helper_spec.rb b/spec/helpers/merge_requests_helper_spec.rb index 885204062fe..dd11bfea465 100644 --- a/spec/helpers/merge_requests_helper_spec.rb +++ b/spec/helpers/merge_requests_helper_spec.rb @@ -1,10 +1,10 @@ -require 'spec_helper' +require "spec_helper" describe MergeRequestsHelper do include ActionView::Helpers::UrlHelper include ProjectForksHelper - describe 'ci_build_details_path' do + describe "ci_build_details_path" do let(:project) { create(:project) } let(:merge_request) { MergeRequest.new } let(:ci_service) { CiService.new } @@ -14,25 +14,25 @@ describe MergeRequestsHelper do allow(merge_request).to receive(:source_project).and_return(project) allow(merge_request).to receive(:last_commit).and_return(last_commit) allow(project).to receive(:ci_service).and_return(ci_service) - allow(last_commit).to receive(:sha).and_return('12d65c') + allow(last_commit).to receive(:sha).and_return("12d65c") end - it 'does not include api credentials in a link' do + it "does not include api credentials in a link" do allow(ci_service) .to receive(:build_page).and_return("http://secretuser:secretpass@jenkins.example.com:8888/job/test1/scm/bySHA1/12d65c") expect(helper.ci_build_details_path(merge_request)).not_to match("secret") end end - describe '#format_mr_branch_names' do - describe 'within the same project' do + describe "#format_mr_branch_names" do + describe "within the same project" do let(:merge_request) { create(:merge_request) } subject { format_mr_branch_names(merge_request) } it { is_expected.to eq([merge_request.source_branch, merge_request.target_branch]) } end - describe 'within different projects' do + describe "within different projects" do let(:project) { create(:project) } let(:forked_project) { fork_project(project) } let(:merge_request) { create(:merge_request, source_project: forked_project, target_project: project) } @@ -44,16 +44,16 @@ describe MergeRequestsHelper do end end - describe '#tab_link_for' do + describe "#tab_link_for" do let(:merge_request) { create(:merge_request, :simple) } - let(:options) { Hash.new } + let(:options) { {} } - subject { tab_link_for(merge_request, :show, options) { 'Discussion' } } + subject { tab_link_for(merge_request, :show, options) { "Discussion" } } - describe 'supports the :force_link option' do - let(:options) { { force_link: true } } + describe "supports the :force_link option" do + let(:options) { {force_link: true} } - it 'removes the data-toggle attributes' do + it "removes the data-toggle attributes" do is_expected.not_to match(/data-toggle="tabvue"/) end end diff --git a/spec/helpers/milestones_helper_spec.rb b/spec/helpers/milestones_helper_spec.rb index f5185cb2857..8b2ced3a526 100644 --- a/spec/helpers/milestones_helper_spec.rb +++ b/spec/helpers/milestones_helper_spec.rb @@ -1,37 +1,37 @@ -require 'spec_helper' +require "spec_helper" describe MilestonesHelper do - describe '#milestones_filter_dropdown_path' do + describe "#milestones_filter_dropdown_path" do let(:project) { create(:project) } let(:project2) { create(:project) } let(:group) { create(:group) } - context 'when @project present' do - it 'returns project milestones JSON URL' do + context "when @project present" do + it "returns project milestones JSON URL" do assign(:project, project) expect(helper.milestones_filter_dropdown_path).to eq(project_milestones_path(project, :json)) end end - context 'when @target_project present' do - it 'returns targeted project milestones JSON URL' do + context "when @target_project present" do + it "returns targeted project milestones JSON URL" do assign(:target_project, project2) expect(helper.milestones_filter_dropdown_path).to eq(project_milestones_path(project2, :json)) end end - context 'when @group present' do - it 'returns group milestones JSON URL' do + context "when @group present" do + it "returns group milestones JSON URL" do assign(:group, group) expect(helper.milestones_filter_dropdown_path).to eq(group_milestones_path(group, :json)) end end - context 'when neither of @project/@target_project/@group present' do - it 'returns dashboard milestones JSON URL' do + context "when neither of @project/@target_project/@group present" do + it "returns dashboard milestones JSON URL" do expect(helper.milestones_filter_dropdown_path).to eq(dashboard_milestones_path(:json)) end end @@ -44,7 +44,7 @@ describe MilestonesHelper do let(:yesterday) { Date.yesterday } let(:tomorrow) { yesterday + 2 } - let(:format) { '%b %-d, %Y' } + let(:format) { "%b %-d, %Y" } let(:yesterday_formatted) { yesterday.strftime(format) } let(:tomorrow_formatted) { tomorrow.strftime(format) } @@ -56,12 +56,12 @@ describe MilestonesHelper do it { expect(result_for(start_date: yesterday, due_date: tomorrow)).to eq("#{yesterday_formatted}–#{tomorrow_formatted}") } end - describe '#milestone_counts' do + describe "#milestone_counts" do let(:project) { create(:project) } let(:counts) { helper.milestone_counts(project.milestones) } - context 'when there are milestones' do - it 'returns the correct counts' do + context "when there are milestones" do + it "returns the correct counts" do create_list(:active_milestone, 2, project: project) create(:closed_milestone, project: project) @@ -69,16 +69,16 @@ describe MilestonesHelper do end end - context 'when there are only milestones of one type' do - it 'returns the correct counts' do + context "when there are only milestones of one type" do + it "returns the correct counts" do create_list(:active_milestone, 2, project: project) expect(counts).to eq(opened: 2, closed: 0, all: 2) end end - context 'when there are no milestones' do - it 'returns the correct counts' do + context "when there are no milestones" do + it "returns the correct counts" do expect(counts).to eq(opened: 0, closed: 0, all: 0) end end diff --git a/spec/helpers/milestones_routing_helper_spec.rb b/spec/helpers/milestones_routing_helper_spec.rb index dc13a43c2ab..89b7c2b792d 100644 --- a/spec/helpers/milestones_routing_helper_spec.rb +++ b/spec/helpers/milestones_routing_helper_spec.rb @@ -1,43 +1,43 @@ -require 'spec_helper' +require "spec_helper" describe MilestonesRoutingHelper do let(:project) { build_stubbed(:project) } let(:group) { build_stubbed(:group) } - describe '#milestone_path' do - context 'for a group milestone' do + describe "#milestone_path" do + context "for a group milestone" do let(:milestone) { build_stubbed(:milestone, group: group, iid: 1) } - it 'links to the group milestone page' do + it "links to the group milestone page" do expect(milestone_path(milestone)) .to eq(group_milestone_path(group, milestone)) end end - context 'for a project milestone' do + context "for a project milestone" do let(:milestone) { build_stubbed(:milestone, project: project, iid: 1) } - it 'links to the project milestone page' do + it "links to the project milestone page" do expect(milestone_path(milestone)) .to eq(project_milestone_path(project, milestone)) end end end - describe '#milestone_url' do - context 'for a group milestone' do + describe "#milestone_url" do + context "for a group milestone" do let(:milestone) { build_stubbed(:milestone, group: group, iid: 1) } - it 'links to the group milestone page' do + it "links to the group milestone page" do expect(milestone_url(milestone)) .to eq(group_milestone_url(group, milestone)) end end - context 'for a project milestone' do + context "for a project milestone" do let(:milestone) { build_stubbed(:milestone, project: project, iid: 1) } - it 'links to the project milestone page' do + it "links to the project milestone page" do expect(milestone_url(milestone)) .to eq(project_milestone_url(project, milestone)) end diff --git a/spec/helpers/namespaces_helper_spec.rb b/spec/helpers/namespaces_helper_spec.rb index 7ccbdcd1332..a1d91363165 100644 --- a/spec/helpers/namespaces_helper_spec.rb +++ b/spec/helpers/namespaces_helper_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe NamespacesHelper do let!(:admin) { create(:admin) } @@ -11,8 +11,8 @@ describe NamespacesHelper do user_group.add_owner(user) end - describe '#namespaces_options' do - it 'returns groups without being a member for admin' do + describe "#namespaces_options" do + it "returns groups without being a member for admin" do allow(helper).to receive(:current_user).and_return(admin) options = helper.namespaces_options(user_group.id, display_path: true, extra_group: user_group.id) @@ -21,7 +21,7 @@ describe NamespacesHelper do expect(options).to include(user_group.name) end - it 'returns only allowed namespaces for user' do + it "returns only allowed namespaces for user" do allow(helper).to receive(:current_user).and_return(user) options = helper.namespaces_options @@ -31,7 +31,7 @@ describe NamespacesHelper do expect(options).to include(user.name) end - it 'avoids duplicate groups when extra_group is used' do + it "avoids duplicate groups when extra_group is used" do allow(helper).to receive(:current_user).and_return(admin) options = helper.namespaces_options(user_group.id, display_path: true, extra_group: build(:group, name: admin_group.name)) @@ -40,7 +40,7 @@ describe NamespacesHelper do expect(options).to include(admin_group.name) end - it 'selects existing group' do + it "selects existing group" do allow(helper).to receive(:current_user).and_return(admin) options = helper.namespaces_options(:extra_group, display_path: true, extra_group: user_group) @@ -49,20 +49,20 @@ describe NamespacesHelper do expect(options).to include(admin_group.name) end - it 'selects the new group by default' do + it "selects the new group by default" do # Ensure we don't select a group with the same name - create(:group, name: 'new-group', path: 'another-path') + create(:group, name: "new-group", path: "another-path") allow(helper).to receive(:current_user).and_return(user) - options = helper.namespaces_options(:extra_group, display_path: true, extra_group: build(:group, name: 'new-group', path: 'new-group')) + options = helper.namespaces_options(:extra_group, display_path: true, extra_group: build(:group, name: "new-group", path: "new-group")) expect(options).to include(user_group.name) expect(options).not_to include(admin_group.name) expect(options).to include("selected=\"selected\" value=\"-1\"") end - it 'falls back to current user selection' do + it "falls back to current user selection" do allow(helper).to receive(:current_user).and_return(user) options = helper.namespaces_options(:extra_group, display_path: true, extra_group: build(:group, name: admin_group.name)) @@ -72,7 +72,7 @@ describe NamespacesHelper do expect(options).to include("selected=\"selected\" value=\"#{user.namespace.id}\"") end - it 'returns only groups if groups_only option is true' do + it "returns only groups if groups_only option is true" do allow(helper).to receive(:current_user).and_return(user) options = helper.namespaces_options(nil, groups_only: true) @@ -81,8 +81,8 @@ describe NamespacesHelper do expect(options).to include(user_group.name) end - context 'when nested groups are available', :nested_groups do - it 'includes groups nested in groups the user can administer' do + context "when nested groups are available", :nested_groups do + it "includes groups nested in groups the user can administer" do allow(helper).to receive(:current_user).and_return(user) child_group = create(:group, :private, parent: user_group) @@ -91,15 +91,15 @@ describe NamespacesHelper do expect(options).to include(child_group.name) end - it 'orders the groups correctly' do + it "orders the groups correctly" do allow(helper).to receive(:current_user).and_return(user) child_group = create(:group, :private, parent: user_group) other_child = create(:group, :private, parent: user_group) sub_child = create(:group, :private, parent: child_group) expect(helper).to receive(:options_for_group) - .with([user_group, child_group, sub_child, other_child], anything) - .and_call_original + .with([user_group, child_group, sub_child, other_child], anything) + .and_call_original allow(helper).to receive(:options_for_group).and_call_original helper.namespaces_options diff --git a/spec/helpers/nav_helper_spec.rb b/spec/helpers/nav_helper_spec.rb index e840c927d59..cfd677f8cbd 100644 --- a/spec/helpers/nav_helper_spec.rb +++ b/spec/helpers/nav_helper_spec.rb @@ -1,12 +1,12 @@ -require 'spec_helper' +require "spec_helper" describe NavHelper do - describe '#header_links' do + describe "#header_links" do before do allow(helper).to receive(:session) { {} } end - context 'when the user is logged in' do + context "when the user is logged in" do let(:user) { build(:user) } before do @@ -14,28 +14,28 @@ describe NavHelper do allow(helper).to receive(:can?) { true } end - it 'has all the expected links by default' do + it "has all the expected links by default" do menu_items = [:user_dropdown, :search, :issues, :merge_requests, :todos] expect(helper.header_links).to contain_exactly(*menu_items) end - it 'contains the impersonation link while impersonating' do - expect(helper).to receive(:session) { { impersonator_id: 1 } } + it "contains the impersonation link while impersonating" do + expect(helper).to receive(:session) { {impersonator_id: 1} } expect(helper.header_links).to include(:admin_impersonation) end - context 'when the user cannot read cross project' do + context "when the user cannot read cross project" do before do allow(helper).to receive(:can?).with(user, :read_cross_project) { false } end - it 'does not contain cross project elements when the user cannot read cross project' do + it "does not contain cross project elements when the user cannot read cross project" do expect(helper.header_links).not_to include(:issues, :merge_requests, :todos, :search) end - it 'shows the search box when the user cannot read cross project and he is visiting a project' do + it "shows the search box when the user cannot read cross project and he is visiting a project" do helper.instance_variable_set(:@project, create(:project)) expect(helper.header_links).to include(:search) @@ -43,7 +43,7 @@ describe NavHelper do end end - it 'returns only the sign in and search when the user is not logged in' do + it "returns only the sign in and search when the user is not logged in" do allow(helper).to receive(:current_user).and_return(nil) allow(helper).to receive(:can?).with(nil, :read_cross_project) { true } diff --git a/spec/helpers/notes_helper_spec.rb b/spec/helpers/notes_helper_spec.rb index 0715f34dafe..6d64ddf54fe 100644 --- a/spec/helpers/notes_helper_spec.rb +++ b/spec/helpers/notes_helper_spec.rb @@ -23,13 +23,13 @@ describe NotesHelper do end describe "#notes_max_access_for_users" do - it 'returns access levels' do + it "returns access levels" do expect(helper.note_max_access_for_user(owner_note)).to eq(Gitlab::Access::OWNER) expect(helper.note_max_access_for_user(maintainer_note)).to eq(Gitlab::Access::MAINTAINER) expect(helper.note_max_access_for_user(reporter_note)).to eq(Gitlab::Access::REPORTER) end - it 'handles access in different projects' do + it "handles access in different projects" do second_project = create(:project) second_project.add_reporter(maintainer) other_note = create(:note, author: maintainer, project: second_project) @@ -39,26 +39,26 @@ describe NotesHelper do end end - describe '#discussion_path' do + describe "#discussion_path" do let(:project) { create(:project, :repository) } let(:anchor) { discussion.line_code } - context 'for a merge request discusion' do + context "for a merge request discusion" do let(:merge_request) { create(:merge_request, source_project: project, target_project: project, importing: true) } - let!(:merge_request_diff1) { merge_request.merge_request_diffs.create(head_commit_sha: '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9') } + let!(:merge_request_diff1) { merge_request.merge_request_diffs.create(head_commit_sha: "6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9") } let!(:merge_request_diff2) { merge_request.merge_request_diffs.create(head_commit_sha: nil) } - let!(:merge_request_diff3) { merge_request.merge_request_diffs.create(head_commit_sha: '5937ac0a7beb003549fc5fd26fc247adbce4a52e') } + let!(:merge_request_diff3) { merge_request.merge_request_diffs.create(head_commit_sha: "5937ac0a7beb003549fc5fd26fc247adbce4a52e") } - context 'for a diff discussion' do - context 'when the discussion is active' do + context "for a diff discussion" do + context "when the discussion is active" do let(:discussion) { create(:diff_note_on_merge_request, noteable: merge_request, project: project).to_discussion } - it 'returns the diff path with the line code' do + it "returns the diff path with the line code" do expect(helper.discussion_path(discussion)).to eq(diffs_project_merge_request_path(project, merge_request, anchor: discussion.line_code)) end end - context 'when the discussion is on an older merge request version' do + context "when the discussion is on an older merge request version" do let(:position) do Gitlab::Diff::Position.new( old_path: ".gitmodules", @@ -77,12 +77,12 @@ describe NotesHelper do diff_note.save! end - it 'returns the diff version path with the line code' do + it "returns the diff version path with the line code" do expect(helper.discussion_path(discussion)).to eq(diffs_project_merge_request_path(project, merge_request, diff_id: merge_request_diff1, anchor: discussion.line_code)) end end - context 'when the discussion is on a comparison between merge request versions' do + context "when the discussion is on a comparison between merge request versions" do let(:position) do Gitlab::Diff::Position.new( old_path: ".gitmodules", @@ -101,12 +101,12 @@ describe NotesHelper do diff_note.save! end - it 'returns the diff version comparison path with the line code' do + it "returns the diff version comparison path with the line code" do expect(helper.discussion_path(discussion)).to eq(diffs_project_merge_request_path(project, merge_request, diff_id: merge_request_diff3, start_sha: merge_request_diff1.head_commit_sha, anchor: discussion.line_code)) end end - context 'when the discussion does not have a merge request version' do + context "when the discussion does not have a merge request version" do let(:outdated_diff_note) { create(:diff_note_on_merge_request, noteable: merge_request, project: project, diff_refs: project.commit(sample_commit.id).diff_refs) } let(:discussion) { outdated_diff_note.to_discussion } @@ -115,182 +115,182 @@ describe NotesHelper do outdated_diff_note.save! end - it 'returns nil' do + it "returns nil" do expect(helper.discussion_path(discussion)).to be_nil end end end - context 'for a legacy diff discussion' do + context "for a legacy diff discussion" do let(:discussion) { create(:legacy_diff_note_on_merge_request, noteable: merge_request, project: project).to_discussion } - context 'when the discussion is active' do + context "when the discussion is active" do before do allow(discussion).to receive(:active?).and_return(true) end - it 'returns the diff path with the line code' do + it "returns the diff path with the line code" do expect(helper.discussion_path(discussion)).to eq(diffs_project_merge_request_path(project, merge_request, anchor: discussion.line_code)) end end - context 'when the discussion is outdated' do + context "when the discussion is outdated" do before do allow(discussion).to receive(:active?).and_return(false) end - it 'returns nil' do + it "returns nil" do expect(helper.discussion_path(discussion)).to be_nil end end end - context 'for a non-diff discussion' do + context "for a non-diff discussion" do let(:discussion) { create(:discussion_note_on_merge_request, noteable: merge_request, project: project).to_discussion } - it 'returns nil' do + it "returns nil" do expect(helper.discussion_path(discussion)).to be_nil end end - context 'for a contextual commit discussion' do + context "for a contextual commit discussion" do let(:commit) { merge_request.commits.last } let(:discussion) { create(:diff_note_on_merge_request, noteable: merge_request, project: project, commit_id: commit.id).to_discussion } - it 'returns the merge request diff discussion scoped in the commit' do + it "returns the merge request diff discussion scoped in the commit" do expect(helper.discussion_path(discussion)).to eq(diffs_project_merge_request_path(project, merge_request, commit_id: commit.id, anchor: anchor)) end end end - context 'for a commit discussion' do + context "for a commit discussion" do let(:commit) { discussion.noteable } - context 'for a diff discussion' do + context "for a diff discussion" do let(:discussion) { create(:diff_note_on_commit, project: project).to_discussion } - it 'returns the commit path with the line code' do + it "returns the commit path with the line code" do expect(helper.discussion_path(discussion)).to eq(project_commit_path(project, commit, anchor: anchor)) end end - context 'for a legacy diff discussion' do + context "for a legacy diff discussion" do let(:discussion) { create(:legacy_diff_note_on_commit, project: project).to_discussion } - it 'returns the commit path with the line code' do + it "returns the commit path with the line code" do expect(helper.discussion_path(discussion)).to eq(project_commit_path(project, commit, anchor: anchor)) end end - context 'for a non-diff discussion' do + context "for a non-diff discussion" do let(:discussion) { create(:discussion_note_on_commit, project: project).to_discussion } - it 'returns the commit path with the note anchor' do + it "returns the commit path with the note anchor" do expect(helper.discussion_path(discussion)).to eq(project_commit_path(project, commit, anchor: "note_#{discussion.first_note.id}")) end end end end - describe '#notes_url' do - it 'return snippet notes path for personal snippet' do + describe "#notes_url" do + it "return snippet notes path for personal snippet" do @snippet = create(:personal_snippet) expect(helper.notes_url).to eq("/snippets/#{@snippet.id}/notes") end - it 'return project notes path for project snippet' do - namespace = create(:namespace, path: 'nm') - @project = create(:project, path: 'test', namespace: namespace) + it "return project notes path for project snippet" do + namespace = create(:namespace, path: "nm") + @project = create(:project, path: "test", namespace: namespace) @snippet = create(:project_snippet, project: @project) @noteable = @snippet expect(helper.notes_url).to eq("/nm/test/noteable/project_snippet/#{@noteable.id}/notes") end - it 'return project notes path for other noteables' do - namespace = create(:namespace, path: 'nm') - @project = create(:project, path: 'test', namespace: namespace) + it "return project notes path for other noteables" do + namespace = create(:namespace, path: "nm") + @project = create(:project, path: "test", namespace: namespace) @noteable = create(:issue, project: @project) expect(helper.notes_url).to eq("/nm/test/noteable/issue/#{@noteable.id}/notes") end end - describe '#note_url' do - it 'return snippet notes path for personal snippet' do + describe "#note_url" do + it "return snippet notes path for personal snippet" do note = create(:note_on_personal_snippet) expect(helper.note_url(note)).to eq("/snippets/#{note.noteable.id}/notes/#{note.id}") end - it 'return project notes path for project snippet' do - namespace = create(:namespace, path: 'nm') - @project = create(:project, path: 'test', namespace: namespace) + it "return project notes path for project snippet" do + namespace = create(:namespace, path: "nm") + @project = create(:project, path: "test", namespace: namespace) note = create(:note_on_project_snippet, project: @project) expect(helper.note_url(note)).to eq("/nm/test/notes/#{note.id}") end - it 'return project notes path for other noteables' do - namespace = create(:namespace, path: 'nm') - @project = create(:project, path: 'test', namespace: namespace) + it "return project notes path for other noteables" do + namespace = create(:namespace, path: "nm") + @project = create(:project, path: "test", namespace: namespace) note = create(:note_on_issue, project: @project) expect(helper.note_url(note)).to eq("/nm/test/notes/#{note.id}") end end - describe '#form_resources' do - it 'returns note for personal snippet' do + describe "#form_resources" do + it "returns note for personal snippet" do @snippet = create(:personal_snippet) @note = create(:note_on_personal_snippet) expect(helper.form_resources).to eq([@note]) end - it 'returns namespace, project and note for project snippet' do - namespace = create(:namespace, path: 'nm') - @project = create(:project, path: 'test', namespace: namespace) + it "returns namespace, project and note for project snippet" do + namespace = create(:namespace, path: "nm") + @project = create(:project, path: "test", namespace: namespace) @snippet = create(:project_snippet, project: @project) @note = create(:note_on_personal_snippet) expect(helper.form_resources).to eq([@project.namespace, @project, @note]) end - it 'returns namespace, project and note path for other noteables' do - namespace = create(:namespace, path: 'nm') - @project = create(:project, path: 'test', namespace: namespace) + it "returns namespace, project and note path for other noteables" do + namespace = create(:namespace, path: "nm") + @project = create(:project, path: "test", namespace: namespace) @note = create(:note_on_issue, project: @project) expect(helper.form_resources).to eq([@project.namespace, @project, @note]) end end - describe '#noteable_note_url' do + describe "#noteable_note_url" do let(:project) { create(:project) } let(:issue) { create(:issue, project: project) } let(:note) { create(:note_on_issue, noteable: issue, project: project) } - it 'returns the noteable url with an anchor to the note' do + it "returns the noteable url with an anchor to the note" do expect(noteable_note_url(note)).to match("/#{project.namespace.path}/#{project.path}/issues/#{issue.iid}##{dom_id(note)}") end end - describe '#discussion_resolved_intro' do - context 'when the discussion was resolved by a push' do + describe "#discussion_resolved_intro" do + context "when the discussion was resolved by a push" do let(:discussion) { double(:discussion, resolved_by_push?: true) } it 'returns "Automatically resolved"' do - expect(discussion_resolved_intro(discussion)).to eq('Automatically resolved') + expect(discussion_resolved_intro(discussion)).to eq("Automatically resolved") end end - context 'when the discussion was not resolved by a push' do + context "when the discussion was not resolved by a push" do let(:discussion) { double(:discussion, resolved_by_push?: false) } it 'returns "Resolved"' do - expect(discussion_resolved_intro(discussion)).to eq('Resolved') + expect(discussion_resolved_intro(discussion)).to eq("Resolved") end end end diff --git a/spec/helpers/notifications_helper_spec.rb b/spec/helpers/notifications_helper_spec.rb index 9ecaabc04ed..b6d615be3d0 100644 --- a/spec/helpers/notifications_helper_spec.rb +++ b/spec/helpers/notifications_helper_spec.rb @@ -1,7 +1,7 @@ -require 'spec_helper' +require "spec_helper" describe NotificationsHelper do - describe 'notification_icon' do + describe "notification_icon" do it { expect(notification_icon(:disabled)).to match('class="fa fa-microphone-slash fa-fw"') } it { expect(notification_icon(:participating)).to match('class="fa fa-volume-up fa-fw"') } it { expect(notification_icon(:mention)).to match('class="fa fa-at fa-fw"') } @@ -9,14 +9,14 @@ describe NotificationsHelper do it { expect(notification_icon(:watch)).to match('class="fa fa-eye fa-fw"') } end - describe 'notification_title' do - it { expect(notification_title(:watch)).to match('Watch') } - it { expect(notification_title(:mention)).to match('On mention') } - it { expect(notification_title(:global)).to match('Global') } + describe "notification_title" do + it { expect(notification_title(:watch)).to match("Watch") } + it { expect(notification_title(:mention)).to match("On mention") } + it { expect(notification_title(:global)).to match("Global") } end - describe '#notification_event_name' do - it { expect(notification_event_name(:success_pipeline)).to match('Successful pipeline') } - it { expect(notification_event_name(:failed_pipeline)).to match('Failed pipeline') } + describe "#notification_event_name" do + it { expect(notification_event_name(:success_pipeline)).to match("Successful pipeline") } + it { expect(notification_event_name(:failed_pipeline)).to match("Failed pipeline") } end end diff --git a/spec/helpers/page_layout_helper_spec.rb b/spec/helpers/page_layout_helper_spec.rb index cf98eed27f1..00823197b41 100644 --- a/spec/helpers/page_layout_helper_spec.rb +++ b/spec/helpers/page_layout_helper_spec.rb @@ -1,26 +1,26 @@ -require 'rails_helper' +require "rails_helper" describe PageLayoutHelper do - describe 'page_description' do - it 'defaults to nil' do + describe "page_description" do + it "defaults to nil" do expect(helper.page_description).to eq nil end - it 'returns the last-pushed description' do - helper.page_description('Foo') - helper.page_description('Bar') - helper.page_description('Baz') + it "returns the last-pushed description" do + helper.page_description("Foo") + helper.page_description("Bar") + helper.page_description("Baz") - expect(helper.page_description).to eq 'Baz' + expect(helper.page_description).to eq "Baz" end - it 'squishes multiple newlines' do + it "squishes multiple newlines" do helper.page_description("Foo\nBar\nBaz") - expect(helper.page_description).to eq 'Foo Bar Baz' + expect(helper.page_description).to eq "Foo Bar Baz" end - it 'truncates' do + it "truncates" do helper.page_description <<-LOREM.strip_heredoc Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis @@ -30,81 +30,81 @@ describe PageLayoutHelper do arcu. LOREM - expect(helper.page_description).to end_with 'quam felis,...' + expect(helper.page_description).to end_with "quam felis,..." end - it 'sanitizes all HTML' do + it "sanitizes all HTML" do helper.page_description("Bold

    Header

    ") - expect(helper.page_description).to eq 'Bold Header' + expect(helper.page_description).to eq "Bold Header" end end - describe 'page_image' do - it 'defaults to the GitLab logo' do - expect(helper.page_image).to match_asset_path 'assets/gitlab_logo.png' + describe "page_image" do + it "defaults to the GitLab logo" do + expect(helper.page_image).to match_asset_path "assets/gitlab_logo.png" end - %w(project user group).each do |type| + %w[project user group].each do |type| context "with @#{type} assigned" do it "uses #{type.titlecase} avatar if available" do - object = double(avatar_url: 'http://example.com/uploads/-/system/avatar.png') + object = double(avatar_url: "http://example.com/uploads/-/system/avatar.png") assign(type, object) expect(helper.page_image).to eq object.avatar_url end - it 'falls back to the default when avatar_url is nil' do + it "falls back to the default when avatar_url is nil" do object = double(avatar_url: nil) assign(type, object) - expect(helper.page_image).to match_asset_path 'assets/gitlab_logo.png' + expect(helper.page_image).to match_asset_path "assets/gitlab_logo.png" end end context "with no assignments" do - it 'falls back to the default' do - expect(helper.page_image).to match_asset_path 'assets/gitlab_logo.png' + it "falls back to the default" do + expect(helper.page_image).to match_asset_path "assets/gitlab_logo.png" end end end end - describe 'page_card_attributes' do - it 'raises ArgumentError when given more than two attributes' do - map = { foo: 'foo', bar: 'bar', baz: 'baz' } + describe "page_card_attributes" do + it "raises ArgumentError when given more than two attributes" do + map = {foo: "foo", bar: "bar", baz: "baz"} expect { helper.page_card_attributes(map) } .to raise_error(ArgumentError, /more than two attributes/) end - it 'rejects blank values' do - map = { foo: 'foo', bar: '' } + it "rejects blank values" do + map = {foo: "foo", bar: ""} helper.page_card_attributes(map) - expect(helper.page_card_attributes).to eq({ foo: 'foo' }) + expect(helper.page_card_attributes).to eq({foo: "foo"}) end end - describe 'page_card_meta_tags' do - it 'returns the twitter:label and twitter:data tags' do - allow(helper).to receive(:page_card_attributes).and_return(foo: 'bar') + describe "page_card_meta_tags" do + it "returns the twitter:label and twitter:data tags" do + allow(helper).to receive(:page_card_attributes).and_return(foo: "bar") tags = helper.page_card_meta_tags aggregate_failures do - expect(tags).to include %q() - expect(tags).to include %q() + expect(tags).to include '' + expect(tags).to include '' end end - it 'escapes content' do + it "escapes content" do allow(helper).to receive(:page_card_attributes) - .and_return(foo: %q{foo" http-equiv="refresh}.html_safe) + .and_return(foo: 'foo" http-equiv="refresh'.html_safe) tags = helper.page_card_meta_tags - expect(tags).to include(%q{content="foo" http-equiv="refresh"}) + expect(tags).to include('content="foo" http-equiv="refresh"') end end end diff --git a/spec/helpers/pagination_helper_spec.rb b/spec/helpers/pagination_helper_spec.rb index e235475fb47..448cc768185 100644 --- a/spec/helpers/pagination_helper_spec.rb +++ b/spec/helpers/pagination_helper_spec.rb @@ -1,10 +1,10 @@ -require 'spec_helper' +require "spec_helper" describe PaginationHelper do - describe '#paginate_collection' do + describe "#paginate_collection" do let(:collection) { User.all.page(1) } - it 'paginates a collection without using a COUNT' do + it "paginates a collection without using a COUNT" do without_count = collection.without_count expect(helper).to receive(:paginate_without_count) @@ -14,7 +14,7 @@ describe PaginationHelper do helper.paginate_collection(without_count) end - it 'paginates a collection using a COUNT' do + it "paginates a collection using a COUNT" do expect(helper).to receive(:paginate_with_count).and_call_original helper.paginate_collection(collection) diff --git a/spec/helpers/preferences_helper_spec.rb b/spec/helpers/preferences_helper_spec.rb index e0e8ebd0c3c..c0bc484accb 100644 --- a/spec/helpers/preferences_helper_spec.rb +++ b/spec/helpers/preferences_helper_spec.rb @@ -1,7 +1,7 @@ -require 'spec_helper' +require "spec_helper" describe PreferencesHelper do - describe '#dashboard_choices' do + describe "#dashboard_choices" do let(:user) { build(:user) } before do @@ -9,75 +9,75 @@ describe PreferencesHelper do allow(helper).to receive(:can?).and_return(false) end - it 'raises an exception when defined choices may be missing' do - expect(User).to receive(:dashboards).and_return(foo: 'foo') + it "raises an exception when defined choices may be missing" do + expect(User).to receive(:dashboards).and_return(foo: "foo") expect { helper.dashboard_choices }.to raise_error(RuntimeError) end - it 'raises an exception when defined choices may be using the wrong key' do + it "raises an exception when defined choices may be using the wrong key" do dashboards = User.dashboards.dup dashboards[:projects_changed] = dashboards.delete :projects expect(User).to receive(:dashboards).and_return(dashboards) expect { helper.dashboard_choices }.to raise_error(KeyError) end - it 'provides better option descriptions' do + it "provides better option descriptions" do expect(helper.dashboard_choices).to match_array [ - ['Your Projects (default)', 'projects'], - ['Starred Projects', 'stars'], - ["Your Projects' Activity", 'project_activity'], - ["Starred Projects' Activity", 'starred_project_activity'], - ["Your Groups", 'groups'], - ["Your Todos", 'todos'], - ["Assigned Issues", 'issues'], - ["Assigned Merge Requests", 'merge_requests'] + ["Your Projects (default)", "projects"], + ["Starred Projects", "stars"], + ["Your Projects' Activity", "project_activity"], + ["Starred Projects' Activity", "starred_project_activity"], + ["Your Groups", "groups"], + ["Your Todos", "todos"], + ["Assigned Issues", "issues"], + ["Assigned Merge Requests", "merge_requests"], ] end end - describe '#first_day_of_week_choices' do - it 'returns Sunday and Monday as choices' do + describe "#first_day_of_week_choices" do + it "returns Sunday and Monday as choices" do expect(helper.first_day_of_week_choices).to eq [ - ['Sunday', 0], - ['Monday', 1] + ["Sunday", 0], + ["Monday", 1], ] end end - describe '#first_day_of_week_choices_with_default' do - it 'returns choices including system default' do + describe "#first_day_of_week_choices_with_default" do + it "returns choices including system default" do expect(helper.first_day_of_week_choices_with_default).to eq [ - ['System default (Sunday)', nil], ['Sunday', 0], ['Monday', 1] + ["System default (Sunday)", nil], ["Sunday", 0], ["Monday", 1], ] end - it 'returns choices including system default set to Monday' do + it "returns choices including system default set to Monday" do stub_application_setting(first_day_of_week: 1) expect(helper.first_day_of_week_choices_with_default).to eq [ - ['System default (Monday)', nil], ['Sunday', 0], ['Monday', 1] + ["System default (Monday)", nil], ["Sunday", 0], ["Monday", 1], ] end end - describe '#user_application_theme' do - context 'with a user' do + describe "#user_application_theme" do + context "with a user" do it "returns user's theme's css_class" do stub_user(theme_id: 3) - expect(helper.user_application_theme).to eq 'ui-light' + expect(helper.user_application_theme).to eq "ui-light" end - it 'returns the default when id is invalid' do + it "returns the default when id is invalid" do stub_user(theme_id: Gitlab::Themes.count + 5) allow(Gitlab.config.gitlab).to receive(:default_theme).and_return(1) - expect(helper.user_application_theme).to eq 'ui-indigo' + expect(helper.user_application_theme).to eq "ui-indigo" end end - context 'without a user' do - it 'returns the default theme' do + context "without a user" do + it "returns the default theme" do stub_user expect(helper.user_application_theme).to eq Gitlab::Themes.default.css_class @@ -85,23 +85,23 @@ describe PreferencesHelper do end end - describe '#user_color_scheme' do - context 'with a user' do + describe "#user_color_scheme" do + context "with a user" do it "returns user's scheme's css_class" do allow(helper).to receive(:current_user) .and_return(double(color_scheme_id: 3)) - expect(helper.user_color_scheme).to eq 'solarized-light' + expect(helper.user_color_scheme).to eq "solarized-light" end - it 'returns the default when id is invalid' do + it "returns the default when id is invalid" do allow(helper).to receive(:current_user) .and_return(double(color_scheme_id: Gitlab::ColorSchemes.count + 5)) end end - context 'without a user' do - it 'returns the default theme' do + context "without a user" do + it "returns the default theme" do stub_user expect(helper.user_color_scheme) @@ -110,8 +110,8 @@ describe PreferencesHelper do end end - describe '#language_choices' do - it 'returns an array of all available languages' do + describe "#language_choices" do + it "returns an array of all available languages" do expect(helper.language_choices).to be_an(Array) expect(helper.language_choices.map(&:second)).to eq(Gitlab::I18n.available_locales) end @@ -122,7 +122,7 @@ describe PreferencesHelper do allow(helper).to receive(:current_user).and_return(nil) else allow(helper).to receive(:current_user) - .and_return(double('user', messages)) + .and_return(double("user", messages)) end end end diff --git a/spec/helpers/profiles_helper_spec.rb b/spec/helpers/profiles_helper_spec.rb index 8e336469c27..1ecb732f0b4 100644 --- a/spec/helpers/profiles_helper_spec.rb +++ b/spec/helpers/profiles_helper_spec.rb @@ -1,8 +1,8 @@ -require 'rails_helper' +require "rails_helper" describe ProfilesHelper do - describe '#commit_email_select_options' do - it 'returns an array with private commit email along with all the verified emails' do + describe "#commit_email_select_options" do + it "returns an array with private commit email along with all the verified emails" do user = create(:user) create(:email, user: user) confirmed_email1 = create(:email, :confirmed, user: user) @@ -14,28 +14,28 @@ describe ProfilesHelper do ["Use a private email - #{private_email}", Gitlab::PrivateCommitEmail::TOKEN], user.email, confirmed_email1.email, - confirmed_email2.email + confirmed_email2.email, ] expect(helper.commit_email_select_options(user)).to match_array(emails) end end - describe '#selected_commit_email' do + describe "#selected_commit_email" do let(:user) { create(:user) } - it 'returns main email when commit email attribute is nil' do + it "returns main email when commit email attribute is nil" do expect(helper.selected_commit_email(user)).to eq(user.email) end - it 'returns DB stored commit_email' do + it "returns DB stored commit_email" do user.update(commit_email: Gitlab::PrivateCommitEmail::TOKEN) expect(helper.selected_commit_email(user)).to eq(Gitlab::PrivateCommitEmail::TOKEN) end end - describe '#email_provider_label' do + describe "#email_provider_label" do it "returns nil for users without external email" do user = create(:user) allow(helper).to receive(:current_user).and_return(user) @@ -44,28 +44,28 @@ describe ProfilesHelper do end it "returns omniauth provider label for users with external attributes" do - stub_omniauth_setting(sync_profile_from_provider: ['cas3']) + stub_omniauth_setting(sync_profile_from_provider: ["cas3"]) stub_omniauth_setting(sync_profile_attributes: true) stub_cas_omniauth_provider - cas_user = create(:omniauth_user, provider: 'cas3') - cas_user.create_user_synced_attributes_metadata(provider: 'cas3', name_synced: true, email_synced: true, location_synced: true) + cas_user = create(:omniauth_user, provider: "cas3") + cas_user.create_user_synced_attributes_metadata(provider: "cas3", name_synced: true, email_synced: true, location_synced: true) allow(helper).to receive(:current_user).and_return(cas_user) - expect(helper.attribute_provider_label(:email)).to eq('CAS') - expect(helper.attribute_provider_label(:name)).to eq('CAS') - expect(helper.attribute_provider_label(:location)).to eq('CAS') + expect(helper.attribute_provider_label(:email)).to eq("CAS") + expect(helper.attribute_provider_label(:name)).to eq("CAS") + expect(helper.attribute_provider_label(:location)).to eq("CAS") end it "returns the correct omniauth provider label for users with some external attributes" do - stub_omniauth_setting(sync_profile_from_provider: ['cas3']) + stub_omniauth_setting(sync_profile_from_provider: ["cas3"]) stub_omniauth_setting(sync_profile_attributes: true) stub_cas_omniauth_provider - cas_user = create(:omniauth_user, provider: 'cas3') - cas_user.create_user_synced_attributes_metadata(provider: 'cas3', name_synced: false, email_synced: true, location_synced: false) + cas_user = create(:omniauth_user, provider: "cas3") + cas_user.create_user_synced_attributes_metadata(provider: "cas3", name_synced: false, email_synced: true, location_synced: false) allow(helper).to receive(:current_user).and_return(cas_user) expect(helper.attribute_provider_label(:name)).to be_nil - expect(helper.attribute_provider_label(:email)).to eq('CAS') + expect(helper.attribute_provider_label(:email)).to eq("CAS") expect(helper.attribute_provider_label(:location)).to be_nil end @@ -74,14 +74,14 @@ describe ProfilesHelper do ldap_user.create_user_synced_attributes_metadata(email_synced: true) allow(helper).to receive(:current_user).and_return(ldap_user) - expect(helper.attribute_provider_label(:email)).to eq('LDAP') + expect(helper.attribute_provider_label(:email)).to eq("LDAP") end end def stub_cas_omniauth_provider provider = OpenStruct.new( - 'name' => 'cas3', - 'label' => 'CAS' + "name" => "cas3", + "label" => "CAS" ) stub_omniauth_setting(providers: [provider]) diff --git a/spec/helpers/projects/error_tracking_helper_spec.rb b/spec/helpers/projects/error_tracking_helper_spec.rb index 7516a636c93..436e6bac9fb 100644 --- a/spec/helpers/projects/error_tracking_helper_spec.rb +++ b/spec/helpers/projects/error_tracking_helper_spec.rb @@ -1,55 +1,55 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" describe Projects::ErrorTrackingHelper do include Gitlab::Routing.url_helpers set(:project) { create(:project) } - describe '#error_tracking_data' do + describe "#error_tracking_data" do let(:setting_path) { project_settings_operations_path(project) } let(:index_path) do project_error_tracking_index_path(project, format: :json) end - context 'without error_tracking_setting' do - it 'returns frontend configuration' do + context "without error_tracking_setting" do + it "returns frontend configuration" do expect(error_tracking_data(project)).to eq( - 'index-path' => index_path, - 'enable-error-tracking-link' => setting_path, - 'error-tracking-enabled' => 'false', + "index-path" => index_path, + "enable-error-tracking-link" => setting_path, + "error-tracking-enabled" => "false", "illustration-path" => "/images/illustrations/cluster_popover.svg" ) end end - context 'with error_tracking_setting' do + context "with error_tracking_setting" do let(:error_tracking_setting) do create(:project_error_tracking_setting, project: project) end - context 'when enabled' do + context "when enabled" do before do error_tracking_setting.update!(enabled: true) end - it 'show error tracking enabled' do + it "show error tracking enabled" do expect(error_tracking_data(project)).to include( - 'error-tracking-enabled' => 'true' + "error-tracking-enabled" => "true" ) end end - context 'when disabled' do + context "when disabled" do before do error_tracking_setting.update!(enabled: false) end - it 'show error tracking not enabled' do + it "show error tracking not enabled" do expect(error_tracking_data(project)).to include( - 'error-tracking-enabled' => 'false' + "error-tracking-enabled" => "false" ) end end diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index 49895b0680b..5a1eed2af87 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe ProjectsHelper do include ProjectForksHelper @@ -28,7 +28,7 @@ describe ProjectsHelper do expect(helper.can_change_visibility_level?(project, user)).to be_truthy end - it 'allows visibility level to be changed if the project is forked' do + it "allows visibility level to be changed if the project is forked" do allow(helper).to receive(:can?).with(user, :change_visibility_level, project) { true } project.update!(visibility_level: Gitlab::VisibilityLevel::PRIVATE) fork_project(project) @@ -114,11 +114,11 @@ describe ProjectsHelper do end it "includes a version" do - expect(helper.project_list_cache_key(project).last).to start_with('v') + expect(helper.project_list_cache_key(project).last).to start_with("v") end - it 'includes wether or not the user can read cross project' do - expect(helper.project_list_cache_key(project)).to include('cross-project:true') + it "includes wether or not the user can read cross project" do + expect(helper.project_list_cache_key(project)).to include("cross-project:true") end it "includes the pipeline status when there is a status" do @@ -128,37 +128,37 @@ describe ProjectsHelper do end it "includes the user max member access" do - expect(helper.project_list_cache_key(project)).to include('access:40') + expect(helper.project_list_cache_key(project)).to include("access:40") end end - describe '#load_pipeline_status' do - it 'loads the pipeline status in batch' do + describe "#load_pipeline_status" do + it "loads the pipeline status in batch" do project = build(:project) helper.load_pipeline_status([project]) # Skip lazy loading of the `pipeline_status` attribute - pipeline_status = project.instance_variable_get('@pipeline_status') + pipeline_status = project.instance_variable_get("@pipeline_status") expect(pipeline_status).to be_a(Gitlab::Cache::Ci::ProjectPipelineStatus) end end - describe '#show_no_ssh_key_message?' do + describe "#show_no_ssh_key_message?" do let(:user) { create(:user) } before do allow(helper).to receive(:current_user).and_return(user) end - context 'user has no keys' do - it 'returns true' do + context "user has no keys" do + it "returns true" do expect(helper.show_no_ssh_key_message?).to be_truthy end end - context 'user has an ssh key' do - it 'returns false' do + context "user has an ssh key" do + it "returns false" do create(:personal_key, user: user) expect(helper.show_no_ssh_key_message?).to be_falsey @@ -166,37 +166,37 @@ describe ProjectsHelper do end end - describe '#show_no_password_message?' do + describe "#show_no_password_message?" do let(:user) { create(:user) } before do allow(helper).to receive(:current_user).and_return(user) end - context 'user has password set' do - it 'returns false' do + context "user has password set" do + it "returns false" do expect(helper.show_no_password_message?).to be_falsey end end - context 'user has hidden the message' do - it 'returns false' do + context "user has hidden the message" do + it "returns false" do allow(helper).to receive(:cookies).and_return(hide_no_password_message: true) expect(helper.show_no_password_message?).to be_falsey end end - context 'user requires a password for Git' do - it 'returns true' do + context "user requires a password for Git" do + it "returns true" do allow(user).to receive(:require_password_creation_for_git?).and_return(true) expect(helper.show_no_password_message?).to be_truthy end end - context 'user requires a personal access token for Git' do - it 'returns true' do + context "user requires a personal access token for Git" do + it "returns true" do allow(user).to receive(:require_password_creation_for_git?).and_return(false) allow(user).to receive(:require_personal_access_token_creation_for_git_auth?).and_return(true) @@ -205,23 +205,23 @@ describe ProjectsHelper do end end - describe '#link_to_set_password' do + describe "#link_to_set_password" do let(:user) { create(:user, password_automatically_set: true) } before do allow(helper).to receive(:current_user).and_return(user) end - context 'password authentication is enabled for Git' do - it 'returns link to set a password' do + context "password authentication is enabled for Git" do + it "returns link to set a password" do stub_application_setting(password_authentication_enabled_for_git?: true) expect(helper.link_to_set_password).to match %r{set a password} end end - context 'password authentication is disabled for Git' do - it 'returns link to create a personal access token' do + context "password authentication is disabled for Git" do + it "returns link to create a personal access token" do stub_application_setting(password_authentication_enabled_for_git?: false) expect(helper.link_to_set_password).to match %r{create a personal access token} @@ -229,19 +229,19 @@ describe ProjectsHelper do end end - describe '#link_to_project' do - let(:group) { create(:group, name: 'group name with space') } - let(:project) { create(:project, group: group, name: 'project name with space') } + describe "#link_to_project" do + let(:group) { create(:group, name: "group name with space") } + let(:project) { create(:project, group: group, name: "project name with space") } subject { link_to_project(project) } - it 'returns an HTML link to the project' do + it "returns an HTML link to the project" do expect(subject).to match(%r{/#{group.full_path}/#{project.path}}) - expect(subject).to include('group name with space /') - expect(subject).to include('project name with space') + expect(subject).to include("group name with space /") + expect(subject).to include("project name with space") end end - describe '#link_to_member_avatar' do + describe "#link_to_member_avatar" do let(:user) { build_stubbed(:user) } let(:expected) { double } @@ -249,32 +249,32 @@ describe ProjectsHelper do expect(helper).to receive(:avatar_icon_for_user).with(user, 16).and_return(expected) end - it 'returns image tag for member avatar' do - expect(helper).to receive(:image_tag).with(expected, { width: 16, class: ["avatar", "avatar-inline", "s16"], alt: "", "data-src" => anything }) + it "returns image tag for member avatar" do + expect(helper).to receive(:image_tag).with(expected, {:width => 16, :class => ["avatar", "avatar-inline", "s16"], :alt => "", "data-src" => anything}) helper.link_to_member_avatar(user) end - it 'returns image tag with avatar class' do - expect(helper).to receive(:image_tag).with(expected, { width: 16, class: ["avatar", "avatar-inline", "s16", "any-avatar-class"], alt: "", "data-src" => anything }) + it "returns image tag with avatar class" do + expect(helper).to receive(:image_tag).with(expected, {:width => 16, :class => ["avatar", "avatar-inline", "s16", "any-avatar-class"], :alt => "", "data-src" => anything}) helper.link_to_member_avatar(user, avatar_class: "any-avatar-class") end end - describe '#link_to_member' do + describe "#link_to_member" do let(:group) { build_stubbed(:group) } let(:project) { build_stubbed(:project, group: group) } - let(:user) { build_stubbed(:user, name: '

    Administrator

    ') } + let(:user) { build_stubbed(:user, name: "

    Administrator

    ") } - describe 'using the default options' do - it 'returns an HTML link to the user' do + describe "using the default options" do + it "returns an HTML link to the user" do link = helper.link_to_member(project, user) expect(link).to match(%r{/#{user.username}}) end - it 'HTML escapes the name of the user' do + it "HTML escapes the name of the user" do link = helper.link_to_member(project, user) expect(link).to include(ERB::Util.html_escape(user.name)) @@ -283,26 +283,26 @@ describe ProjectsHelper do end end - describe 'default_clone_protocol' do - context 'when user is not logged in and gitlab protocol is HTTP' do - it 'returns HTTP' do + describe "default_clone_protocol" do + context "when user is not logged in and gitlab protocol is HTTP" do + it "returns HTTP" do allow(helper).to receive(:current_user).and_return(nil) - expect(helper.send(:default_clone_protocol)).to eq('http') + expect(helper.send(:default_clone_protocol)).to eq("http") end end - context 'when user is not logged in and gitlab protocol is HTTPS' do - it 'returns HTTPS' do - stub_config_setting(protocol: 'https') + context "when user is not logged in and gitlab protocol is HTTPS" do + it "returns HTTPS" do + stub_config_setting(protocol: "https") allow(helper).to receive(:current_user).and_return(nil) - expect(helper.send(:default_clone_protocol)).to eq('https') + expect(helper.send(:default_clone_protocol)).to eq("https") end end end - describe '#last_push_event' do + describe "#last_push_event" do let(:user) { double(:user, fork_of: nil) } let(:project) { double(:project, id: 1) } @@ -311,15 +311,15 @@ describe ProjectsHelper do helper.instance_variable_set(:@project, project) end - context 'when there is no current_user' do + context "when there is no current_user" do let(:user) { nil } - it 'returns nil' do + it "returns nil" do expect(helper.last_push_event).to eq(nil) end end - it 'returns recent push on the current project' do + it "returns recent push on the current project" do event = double(:event) expect(user).to receive(:recent_push).with(project).and_return(event) @@ -327,7 +327,7 @@ describe ProjectsHelper do end end - describe '#get_project_nav_tabs' do + describe "#get_project_nav_tabs" do let(:project) { create(:project) } let(:user) { create(:user) } @@ -339,7 +339,7 @@ describe ProjectsHelper do helper.send(:get_project_nav_tabs, project, user) end - context 'when builds feature is enabled' do + context "when builds feature is enabled" do before do allow(project).to receive(:builds_enabled?).and_return(true) end @@ -349,18 +349,18 @@ describe ProjectsHelper do end end - context 'when builds feature is disabled' do + context "when builds feature is disabled" do before do allow(project).to receive(:builds_enabled?).and_return(false) end - context 'when user has access to builds' do + context "when user has access to builds" do it "does include pipelines tab" do is_expected.to include(:pipelines) end end - context 'when user does not have access to builds' do + context "when user does not have access to builds" do before do allow(helper).to receive(:can?) { false } end @@ -371,138 +371,138 @@ describe ProjectsHelper do end end - context 'when project has external wiki' do - it 'includes external wiki tab' do - project.create_external_wiki_service(active: true, properties: { 'external_wiki_url' => 'https://gitlab.com' }) + context "when project has external wiki" do + it "includes external wiki tab" do + project.create_external_wiki_service(active: true, properties: {"external_wiki_url" => "https://gitlab.com"}) is_expected.to include(:external_wiki) end end - context 'when project does not have external wiki' do - it 'does not include external wiki tab' do + context "when project does not have external wiki" do + it "does not include external wiki tab" do expect(project.external_wiki).to be_nil is_expected.not_to include(:external_wiki) end end end - describe '#show_projects' do + describe "#show_projects" do let(:projects) do create(:project) Project.all end - it 'returns true when there are projects' do + it "returns true when there are projects" do expect(helper.show_projects?(projects, {})).to eq(true) end - it 'returns true when there are no projects but a name is given' do - expect(helper.show_projects?(Project.none, name: 'foo')).to eq(true) + it "returns true when there are no projects but a name is given" do + expect(helper.show_projects?(Project.none, name: "foo")).to eq(true) end - it 'returns true when there are no projects but personal is present' do - expect(helper.show_projects?(Project.none, personal: 'true')).to eq(true) + it "returns true when there are no projects but personal is present" do + expect(helper.show_projects?(Project.none, personal: "true")).to eq(true) end - it 'returns false when there are no projects and there is no name' do + it "returns false when there are no projects and there is no name" do expect(helper.show_projects?(Project.none, {})).to eq(false) end end - describe('#push_to_create_project_command') do - let(:user) { create(:user, username: 'john') } + describe("#push_to_create_project_command") do + let(:user) { create(:user, username: "john") } - it 'returns the command to push to create project over HTTP' do - allow(Gitlab::CurrentSettings.current_application_settings).to receive(:enabled_git_access_protocol) { 'http' } + it "returns the command to push to create project over HTTP" do + allow(Gitlab::CurrentSettings.current_application_settings).to receive(:enabled_git_access_protocol) { "http" } - expect(helper.push_to_create_project_command(user)).to eq('git push --set-upstream http://test.host/john/$(git rev-parse --show-toplevel | xargs basename).git $(git rev-parse --abbrev-ref HEAD)') + expect(helper.push_to_create_project_command(user)).to eq("git push --set-upstream http://test.host/john/$(git rev-parse --show-toplevel | xargs basename).git $(git rev-parse --abbrev-ref HEAD)") end - it 'returns the command to push to create project over SSH' do - allow(Gitlab::CurrentSettings.current_application_settings).to receive(:enabled_git_access_protocol) { 'ssh' } + it "returns the command to push to create project over SSH" do + allow(Gitlab::CurrentSettings.current_application_settings).to receive(:enabled_git_access_protocol) { "ssh" } - expect(helper.push_to_create_project_command(user)).to eq('git push --set-upstream git@localhost:john/$(git rev-parse --show-toplevel | xargs basename).git $(git rev-parse --abbrev-ref HEAD)') + expect(helper.push_to_create_project_command(user)).to eq("git push --set-upstream git@localhost:john/$(git rev-parse --show-toplevel | xargs basename).git $(git rev-parse --abbrev-ref HEAD)") end end - describe '#any_projects?' do + describe "#any_projects?" do let!(:project) { create(:project) } - it 'returns true when projects will be returned' do + it "returns true when projects will be returned" do expect(helper.any_projects?(Project.all)).to eq(true) end - it 'returns false when no projects will be returned' do + it "returns false when no projects will be returned" do expect(helper.any_projects?(Project.none)).to eq(false) end - it 'returns true when using a non-empty Array' do + it "returns true when using a non-empty Array" do expect(helper.any_projects?([project])).to eq(true) end - it 'returns false when using an empty Array' do + it "returns false when using an empty Array" do expect(helper.any_projects?([])).to eq(false) end - it 'only executes a single query when a LIMIT is applied' do + it "only executes a single query when a LIMIT is applied" do relation = Project.limit(1) - recorder = ActiveRecord::QueryRecorder.new do + recorder = ActiveRecord::QueryRecorder.new { 2.times do helper.any_projects?(relation) end - end + } expect(recorder.count).to eq(1) end end - describe '#git_user_name' do + describe "#git_user_name" do let(:user) { double(:user, name: 'John "A" Doe53') } before do allow(helper).to receive(:current_user).and_return(user) end - it 'parses quotes in name' do + it "parses quotes in name" do expect(helper.send(:git_user_name)).to eq('John \"A\" Doe53') end end - describe 'show_xcode_link' do + describe "show_xcode_link" do let!(:project) { create(:project) } - let(:mac_ua) { 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36' } - let(:ios_ua) { 'Mozilla/5.0 (iPad; CPU OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48.3' } + let(:mac_ua) { "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36" } + let(:ios_ua) { "Mozilla/5.0 (iPad; CPU OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48.3" } - context 'when the repository is xcode compatible' do + context "when the repository is xcode compatible" do before do allow(project.repository).to receive(:xcode_project?).and_return(true) end - it 'returns false if the visitor is not using macos' do + it "returns false if the visitor is not using macos" do allow(helper).to receive(:browser).and_return(Browser.new(ios_ua)) expect(helper.show_xcode_link?(project)).to eq(false) end - it 'returns true if the visitor is using macos' do + it "returns true if the visitor is using macos" do allow(helper).to receive(:browser).and_return(Browser.new(mac_ua)) expect(helper.show_xcode_link?(project)).to eq(true) end end - context 'when the repository is not xcode compatible' do + context "when the repository is not xcode compatible" do before do allow(project.repository).to receive(:xcode_project?).and_return(false) end - it 'returns false if the visitor is not using macos' do + it "returns false if the visitor is not using macos" do allow(helper).to receive(:browser).and_return(Browser.new(ios_ua)) expect(helper.show_xcode_link?(project)).to eq(false) end - it 'returns false if the visitor is using macos' do + it "returns false if the visitor is using macos" do allow(helper).to receive(:browser).and_return(Browser.new(mac_ua)) expect(helper.show_xcode_link?(project)).to eq(false) @@ -510,10 +510,10 @@ describe ProjectsHelper do end end - describe 'link_to_bfg' do + describe "link_to_bfg" do subject { helper.link_to_bfg } - it 'generates a hardcoded link to the BFG Repo-Cleaner' do + it "generates a hardcoded link to the BFG Repo-Cleaner" do result = helper.link_to_bfg doc = Nokogiri::HTML.fragment(result) @@ -524,18 +524,18 @@ describe ProjectsHelper do aggregate_failures do expect(result).to be_html_safe - expect(link.name).to eq('a') - expect(link[:target]).to eq('_blank') - expect(link[:rel]).to eq('noopener noreferrer') - expect(link[:href]).to eq('https://rtyley.github.io/bfg-repo-cleaner/') - expect(link.inner_html).to eq('BFG') + expect(link.name).to eq("a") + expect(link[:target]).to eq("_blank") + expect(link[:rel]).to eq("noopener noreferrer") + expect(link[:href]).to eq("https://rtyley.github.io/bfg-repo-cleaner/") + expect(link.inner_html).to eq("BFG") expect(result).to be_html_safe end end end - describe '#explore_projects_tab?' do + describe "#explore_projects_tab?" do subject { helper.explore_projects_tab? } it 'returns true when on the "All" tab under "Explore projects"' do @@ -563,89 +563,89 @@ describe ProjectsHelper do end end - describe '#show_merge_request_count' do - context 'when the feature flag is enabled' do + describe "#show_merge_request_count" do + context "when the feature flag is enabled" do before do stub_feature_flags(project_list_show_mr_count: true) end - it 'returns true if compact mode is disabled' do + it "returns true if compact mode is disabled" do expect(helper.show_merge_request_count?).to be_truthy end - it 'returns false if compact mode is enabled' do + it "returns false if compact mode is enabled" do expect(helper.show_merge_request_count?(compact_mode: true)).to be_falsey end end - context 'when the feature flag is disabled' do + context "when the feature flag is disabled" do before do stub_feature_flags(project_list_show_mr_count: false) end - it 'always returns false' do + it "always returns false" do expect(helper.show_merge_request_count?(disabled: false)).to be_falsy expect(helper.show_merge_request_count?(disabled: true)).to be_falsy end end - context 'disabled flag' do + context "disabled flag" do before do stub_feature_flags(project_list_show_mr_count: true) end - it 'returns false if disabled flag is true' do + it "returns false if disabled flag is true" do expect(helper.show_merge_request_count?(disabled: true)).to be_falsey end - it 'returns true if disabled flag is false' do + it "returns true if disabled flag is false" do expect(helper.show_merge_request_count?).to be_truthy end end end - describe '#show_issue_count?' do - context 'when the feature flag is enabled' do + describe "#show_issue_count?" do + context "when the feature flag is enabled" do before do stub_feature_flags(project_list_show_issue_count: true) end - it 'returns true if compact mode is disabled' do + it "returns true if compact mode is disabled" do expect(helper.show_issue_count?).to be_truthy end - it 'returns false if compact mode is enabled' do + it "returns false if compact mode is enabled" do expect(helper.show_issue_count?(compact_mode: true)).to be_falsey end end - context 'when the feature flag is disabled' do + context "when the feature flag is disabled" do before do stub_feature_flags(project_list_show_issue_count: false) end - it 'always returns false' do + it "always returns false" do expect(helper.show_issue_count?(disabled: false)).to be_falsy expect(helper.show_issue_count?(disabled: true)).to be_falsy end end - context 'disabled flag' do + context "disabled flag" do before do stub_feature_flags(project_list_show_issue_count: true) end - it 'returns false if disabled flag is true' do + it "returns false if disabled flag is true" do expect(helper.show_issue_count?(disabled: true)).to be_falsey end - it 'returns true if disabled flag is false' do + it "returns true if disabled flag is false" do expect(helper.show_issue_count?).to be_truthy end end end - describe '#show_auto_devops_implicitly_enabled_banner?' do + describe "#show_auto_devops_implicitly_enabled_banner?" do using RSpec::Parameterized::TableSyntax let(:user) { create(:user) } @@ -653,7 +653,7 @@ describe ProjectsHelper do let(:feature_visibilities) do { enabled: ProjectFeature::ENABLED, - disabled: ProjectFeature::DISABLED + disabled: ProjectFeature::DISABLED, } end diff --git a/spec/helpers/rss_helper_spec.rb b/spec/helpers/rss_helper_spec.rb index a7f9bdf07e4..fa68c8f403b 100644 --- a/spec/helpers/rss_helper_spec.rb +++ b/spec/helpers/rss_helper_spec.rb @@ -1,8 +1,8 @@ -require 'spec_helper' +require "spec_helper" describe RssHelper do - describe '#rss_url_options' do - context 'when signed in' do + describe "#rss_url_options" do + context "when signed in" do it "includes the current_user's feed_token" do current_user = create(:user) allow(helper).to receive(:current_user).and_return(current_user) @@ -10,7 +10,7 @@ describe RssHelper do end end - context 'when signed out' do + context "when signed out" do it "does not have a feed_token" do allow(helper).to receive(:current_user).and_return(nil) expect(helper.rss_url_options[:feed_token]).to be_nil diff --git a/spec/helpers/runners_helper_spec.rb b/spec/helpers/runners_helper_spec.rb index bf00841fcb6..45c3ea4303c 100644 --- a/spec/helpers/runners_helper_spec.rb +++ b/spec/helpers/runners_helper_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe RunnersHelper do it "returns - not contacted yet" do @@ -16,7 +16,7 @@ describe RunnersHelper do expect(runner_status_icon(runner)).to include("Runner is online") end - describe '#runner_contacted_at' do + describe "#runner_contacted_at" do let(:contacted_at_stored) { 1.hour.ago.change(usec: 0) } let(:contacted_at_cached) { 1.second.ago.change(usec: 0) } let(:runner) { create(:ci_runner, contacted_at: contacted_at_stored) } @@ -25,28 +25,28 @@ describe RunnersHelper do runner.cache_attributes(contacted_at: contacted_at_cached) end - context 'without sorting' do - it 'returns cached value' do + context "without sorting" do + it "returns cached value" do expect(runner_contacted_at(runner)).to eq(contacted_at_cached) end end - context 'with sorting set to created_date' do + context "with sorting set to created_date" do before do - controller.params[:sort] = 'created_date' + controller.params[:sort] = "created_date" end - it 'returns cached value' do + it "returns cached value" do expect(runner_contacted_at(runner)).to eq(contacted_at_cached) end end - context 'with sorting set to contacted_asc' do + context "with sorting set to contacted_asc" do before do - controller.params[:sort] = 'contacted_asc' + controller.params[:sort] = "contacted_asc" end - it 'returns stored value' do + it "returns stored value" do expect(runner_contacted_at(runner)).to eq(contacted_at_stored) end end diff --git a/spec/helpers/search_helper_spec.rb b/spec/helpers/search_helper_spec.rb index 9cff0291250..49aa7e1d08b 100644 --- a/spec/helpers/search_helper_spec.rb +++ b/spec/helpers/search_helper_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe SearchHelper do # Override simple_sanitize for our testing purposes @@ -6,7 +6,7 @@ describe SearchHelper do str end - describe 'search_autocomplete_source' do + describe "search_autocomplete_source" do context "with no current user" do before do allow(self).to receive(:current_user).and_return(nil) @@ -46,8 +46,8 @@ describe SearchHelper do end it "includes nested group" do - create(:group, :nested, name: 'foo').add_owner(user) - expect(search_autocomplete_opts('foo').size).to eq(1) + create(:group, :nested, name: "foo").add_owner(user) + expect(search_autocomplete_opts("foo").size).to eq(1) end it "includes the user's projects" do @@ -86,7 +86,7 @@ describe SearchHelper do end end - context 'with an admin user' do + context "with an admin user" do let(:admin) { create(:admin) } before do @@ -99,74 +99,74 @@ describe SearchHelper do end end - describe 'search_filter_input_options' do - context 'project' do + describe "search_filter_input_options" do + context "project" do before do @project = create(:project, :repository) end - it 'includes id with type' do - expect(search_filter_input_options('type')[:id]).to eq('filtered-search-type') + it "includes id with type" do + expect(search_filter_input_options("type")[:id]).to eq("filtered-search-type") end - it 'includes project-id' do - expect(search_filter_input_options('')[:data]['project-id']).to eq(@project.id) + it "includes project-id" do + expect(search_filter_input_options("")[:data]["project-id"]).to eq(@project.id) end - it 'includes project base-endpoint' do - expect(search_filter_input_options('')[:data]['base-endpoint']).to eq(project_path(@project)) + it "includes project base-endpoint" do + expect(search_filter_input_options("")[:data]["base-endpoint"]).to eq(project_path(@project)) end - it 'includes autocomplete=off flag' do - expect(search_filter_input_options('')[:autocomplete]).to eq('off') + it "includes autocomplete=off flag" do + expect(search_filter_input_options("")[:autocomplete]).to eq("off") end end - context 'group' do + context "group" do before do - @group = create(:group, name: 'group') + @group = create(:group, name: "group") end - it 'does not includes project-id' do - expect(search_filter_input_options('')[:data]['project-id']).to eq(nil) + it "does not includes project-id" do + expect(search_filter_input_options("")[:data]["project-id"]).to eq(nil) end - it 'includes group base-endpoint' do - expect(search_filter_input_options('')[:data]['base-endpoint']).to eq("/groups#{group_path(@group)}") + it "includes group base-endpoint" do + expect(search_filter_input_options("")[:data]["base-endpoint"]).to eq("/groups#{group_path(@group)}") end end - context 'dashboard' do - it 'does not include group-id and project-id' do - expect(search_filter_input_options('')[:data]['project-id']).to eq(nil) - expect(search_filter_input_options('')[:data]['group-id']).to eq(nil) + context "dashboard" do + it "does not include group-id and project-id" do + expect(search_filter_input_options("")[:data]["project-id"]).to eq(nil) + expect(search_filter_input_options("")[:data]["group-id"]).to eq(nil) end - it 'includes dashboard base-endpoint' do - expect(search_filter_input_options('')[:data]['base-endpoint']).to eq("/dashboard") + it "includes dashboard base-endpoint" do + expect(search_filter_input_options("")[:data]["base-endpoint"]).to eq("/dashboard") end end end - describe 'search_history_storage_prefix' do - context 'project' do - it 'returns project full_path' do + describe "search_history_storage_prefix" do + context "project" do + it "returns project full_path" do @project = create(:project, :repository) expect(search_history_storage_prefix).to eq(@project.full_path) end end - context 'group' do - it 'returns group full_path' do - @group = create(:group, :nested, name: 'group-name') + context "group" do + it "returns group full_path" do + @group = create(:group, :nested, name: "group-name") expect(search_history_storage_prefix).to eq(@group.full_path) end end - context 'dashboard' do - it 'returns dashboard' do + context "dashboard" do + it "returns dashboard" do expect(search_history_storage_prefix).to eq("dashboard") end end diff --git a/spec/helpers/sidekiq_helper_spec.rb b/spec/helpers/sidekiq_helper_spec.rb index 117abc9c556..141c4b5350c 100644 --- a/spec/helpers/sidekiq_helper_spec.rb +++ b/spec/helpers/sidekiq_helper_spec.rb @@ -1,71 +1,71 @@ -require 'spec_helper' +require "spec_helper" describe SidekiqHelper do - describe 'parse_sidekiq_ps' do - it 'parses line with time' do - line = '55137 10,0 2,1 S+ 2:30pm sidekiq 4.1.4 gitlab [0 of 25 busy] ' + describe "parse_sidekiq_ps" do + it "parses line with time" do + line = "55137\t10,0\t2,1\tS+\t2:30pm\tsidekiq 4.1.4 gitlab [0 of 25 busy] " parts = helper.parse_sidekiq_ps(line) - expect(parts).to eq(['55137', '10,0', '2,1', 'S+', '2:30pm', 'sidekiq 4.1.4 gitlab [0 of 25 busy]']) + expect(parts).to eq(["55137", "10,0", "2,1", "S+", "2:30pm", "sidekiq 4.1.4 gitlab [0 of 25 busy]"]) end - it 'parses line with date' do - line = '55137 10,0 2,1 S+ Aug 4 sidekiq 4.1.4 gitlab [0 of 25 busy] ' + it "parses line with date" do + line = "55137\t10,0\t2,1\tS+\tAug 4\tsidekiq 4.1.4 gitlab [0 of 25 busy] " parts = helper.parse_sidekiq_ps(line) - expect(parts).to eq(['55137', '10,0', '2,1', 'S+', 'Aug 4', 'sidekiq 4.1.4 gitlab [0 of 25 busy]']) + expect(parts).to eq(["55137", "10,0", "2,1", "S+", "Aug 4", "sidekiq 4.1.4 gitlab [0 of 25 busy]"]) end - it 'parses line with two digit date' do - line = '55137 10,0 2,1 S+ Aug 04 sidekiq 4.1.4 gitlab [0 of 25 busy] ' + it "parses line with two digit date" do + line = "55137\t10,0\t2,1\tS+\tAug 04\tsidekiq 4.1.4 gitlab [0 of 25 busy] " parts = helper.parse_sidekiq_ps(line) - expect(parts).to eq(['55137', '10,0', '2,1', 'S+', 'Aug 04', 'sidekiq 4.1.4 gitlab [0 of 25 busy]']) + expect(parts).to eq(["55137", "10,0", "2,1", "S+", "Aug 04", "sidekiq 4.1.4 gitlab [0 of 25 busy]"]) end - it 'parses line with dot as float separator' do - line = '55137 10.0 2.1 S+ 2:30pm sidekiq 4.1.4 gitlab [0 of 25 busy] ' + it "parses line with dot as float separator" do + line = "55137\t10.0\t2.1\tS+\t2:30pm\tsidekiq 4.1.4 gitlab [0 of 25 busy] " parts = helper.parse_sidekiq_ps(line) - expect(parts).to eq(['55137', '10.0', '2.1', 'S+', '2:30pm', 'sidekiq 4.1.4 gitlab [0 of 25 busy]']) + expect(parts).to eq(["55137", "10.0", "2.1", "S+", "2:30pm", "sidekiq 4.1.4 gitlab [0 of 25 busy]"]) end - it 'parses OSX output' do - line = ' 1641 1.5 3.8 S+ 4:04PM sidekiq 4.2.1 gitlab [0 of 25 busy]' + it "parses OSX output" do + line = " 1641 1.5 3.8 S+ 4:04PM sidekiq 4.2.1 gitlab [0 of 25 busy]" parts = helper.parse_sidekiq_ps(line) - expect(parts).to eq(['1641', '1.5', '3.8', 'S+', '4:04PM', 'sidekiq 4.2.1 gitlab [0 of 25 busy]']) + expect(parts).to eq(["1641", "1.5", "3.8", "S+", "4:04PM", "sidekiq 4.2.1 gitlab [0 of 25 busy]"]) end - it 'parses Ubuntu output' do + it "parses Ubuntu output" do # Ubuntu Linux 16.04 LTS / procps-3.3.10-4ubuntu2 - line = ' 938 1.4 2.5 Sl+ 21:23:21 sidekiq 4.2.1 gitlab [0 of 25 busy] ' + line = " 938 1.4 2.5 Sl+ 21:23:21 sidekiq 4.2.1 gitlab [0 of 25 busy] " parts = helper.parse_sidekiq_ps(line) - expect(parts).to eq(['938', '1.4', '2.5', 'Sl+', '21:23:21', 'sidekiq 4.2.1 gitlab [0 of 25 busy]']) + expect(parts).to eq(["938", "1.4", "2.5", "Sl+", "21:23:21", "sidekiq 4.2.1 gitlab [0 of 25 busy]"]) end - it 'parses Debian output' do + it "parses Debian output" do # Debian Linux Wheezy/Jessie - line = '17725 1.0 12.1 Ssl 19:20:15 sidekiq 4.2.1 gitlab-rails [0 of 25 busy] ' + line = "17725 1.0 12.1 Ssl 19:20:15 sidekiq 4.2.1 gitlab-rails [0 of 25 busy] " parts = helper.parse_sidekiq_ps(line) - expect(parts).to eq(['17725', '1.0', '12.1', 'Ssl', '19:20:15', 'sidekiq 4.2.1 gitlab-rails [0 of 25 busy]']) + expect(parts).to eq(["17725", "1.0", "12.1", "Ssl", "19:20:15", "sidekiq 4.2.1 gitlab-rails [0 of 25 busy]"]) end - it 'parses OpenBSD output' do + it "parses OpenBSD output" do # OpenBSD 6.1 - line = '49258 0.5 2.3 R/0 Fri10PM ruby23: sidekiq 4.2.7 gitlab [0 of 25 busy] (ruby23)' + line = "49258 0.5 2.3 R/0 Fri10PM ruby23: sidekiq 4.2.7 gitlab [0 of 25 busy] (ruby23)" parts = helper.parse_sidekiq_ps(line) - expect(parts).to eq(['49258', '0.5', '2.3', 'R/0', 'Fri10PM', 'ruby23: sidekiq 4.2.7 gitlab [0 of 25 busy] (ruby23)']) + expect(parts).to eq(["49258", "0.5", "2.3", "R/0", "Fri10PM", "ruby23: sidekiq 4.2.7 gitlab [0 of 25 busy] (ruby23)"]) end - it 'does fail gracefully on line not matching the format' do - line = '55137 10.0 2.1 S+ 2:30pm something' + it "does fail gracefully on line not matching the format" do + line = "55137\t10.0\t2.1\tS+\t2:30pm\tsomething" parts = helper.parse_sidekiq_ps(line) - expect(parts).to eq(['?', '?', '?', '?', '?', '?']) + expect(parts).to eq(["?", "?", "?", "?", "?", "?"]) end end end diff --git a/spec/helpers/snippets_helper_spec.rb b/spec/helpers/snippets_helper_spec.rb index ce5e037f88d..1051d001ff0 100644 --- a/spec/helpers/snippets_helper_spec.rb +++ b/spec/helpers/snippets_helper_spec.rb @@ -1,33 +1,33 @@ -require 'spec_helper' +require "spec_helper" describe SnippetsHelper do include IconsHelper - describe '#embedded_snippet_raw_button' do - it 'gives view raw button of embedded snippets for project snippets' do + describe "#embedded_snippet_raw_button" do + it "gives view raw button of embedded snippets for project snippets" do @snippet = create(:project_snippet, :public) - expect(embedded_snippet_raw_button.to_s).to eq("#{external_snippet_icon('doc-code')}") + expect(embedded_snippet_raw_button.to_s).to eq("#{external_snippet_icon("doc-code")}") end - it 'gives view raw button of embedded snippets for personal snippets' do + it "gives view raw button of embedded snippets for personal snippets" do @snippet = create(:personal_snippet, :public) - expect(embedded_snippet_raw_button.to_s).to eq("#{external_snippet_icon('doc-code')}") + expect(embedded_snippet_raw_button.to_s).to eq("#{external_snippet_icon("doc-code")}") end end - describe '#embedded_snippet_download_button' do - it 'gives download button of embedded snippets for project snippets' do + describe "#embedded_snippet_download_button" do + it "gives download button of embedded snippets for project snippets" do @snippet = create(:project_snippet, :public) - expect(embedded_snippet_download_button.to_s).to eq("#{external_snippet_icon('download')}") + expect(embedded_snippet_download_button.to_s).to eq("#{external_snippet_icon("download")}") end - it 'gives download button of embedded snippets for personal snippets' do + it "gives download button of embedded snippets for personal snippets" do @snippet = create(:personal_snippet, :public) - expect(embedded_snippet_download_button.to_s).to eq("#{external_snippet_icon('download')}") + expect(embedded_snippet_download_button.to_s).to eq("#{external_snippet_icon("download")}") end end end diff --git a/spec/helpers/sorting_helper_spec.rb b/spec/helpers/sorting_helper_spec.rb index f405268d198..27c83c9cb3b 100644 --- a/spec/helpers/sorting_helper_spec.rb +++ b/spec/helpers/sorting_helper_spec.rb @@ -1,47 +1,48 @@ # frozen_string_literal: true -require 'spec_helper' + +require "spec_helper" describe SortingHelper do include ApplicationHelper include IconsHelper - describe '#issuable_sort_option_title' do - it 'returns correct title for issuable_sort_option_overrides key' do - expect(issuable_sort_option_title('created_asc')).to eq('Created date') + describe "#issuable_sort_option_title" do + it "returns correct title for issuable_sort_option_overrides key" do + expect(issuable_sort_option_title("created_asc")).to eq("Created date") end - it 'returns correct title for a valid sort value' do - expect(issuable_sort_option_title('priority')).to eq('Priority') + it "returns correct title for a valid sort value" do + expect(issuable_sort_option_title("priority")).to eq("Priority") end - it 'returns nil for invalid sort value' do - expect(issuable_sort_option_title('invalid_key')).to eq(nil) + it "returns nil for invalid sort value" do + expect(issuable_sort_option_title("invalid_key")).to eq(nil) end end - describe '#issuable_sort_direction_button' do + describe "#issuable_sort_direction_button" do before do - allow(self).to receive(:request).and_return(double(path: 'http://test.com', query_parameters: { label_name: 'test_label' })) + allow(self).to receive(:request).and_return(double(path: "http://test.com", query_parameters: {label_name: "test_label"})) end - it 'keeps label filter param' do - expect(issuable_sort_direction_button('created_date')).to include('label_name=test_label') + it "keeps label filter param" do + expect(issuable_sort_direction_button("created_date")).to include("label_name=test_label") end - it 'returns icon with sort-highest when sort is created_date' do - expect(issuable_sort_direction_button('created_date')).to include('sort-highest') + it "returns icon with sort-highest when sort is created_date" do + expect(issuable_sort_direction_button("created_date")).to include("sort-highest") end - it 'returns icon with sort-lowest when sort is asc' do - expect(issuable_sort_direction_button('created_asc')).to include('sort-lowest') + it "returns icon with sort-lowest when sort is asc" do + expect(issuable_sort_direction_button("created_asc")).to include("sort-lowest") end - it 'returns icon with sort-lowest when sorting by milestone' do - expect(issuable_sort_direction_button('milestone')).to include('sort-lowest') + it "returns icon with sort-lowest when sorting by milestone" do + expect(issuable_sort_direction_button("milestone")).to include("sort-lowest") end - it 'returns icon with sort-lowest when sorting by due_date' do - expect(issuable_sort_direction_button('due_date')).to include('sort-lowest') + it "returns icon with sort-lowest when sorting by due_date" do + expect(issuable_sort_direction_button("due_date")).to include("sort-lowest") end end end diff --git a/spec/helpers/submodule_helper_spec.rb b/spec/helpers/submodule_helper_spec.rb index ea48c69e0ae..c0acd7411d4 100644 --- a/spec/helpers/submodule_helper_spec.rb +++ b/spec/helpers/submodule_helper_spec.rb @@ -1,167 +1,167 @@ -require 'spec_helper' +require "spec_helper" describe SubmoduleHelper do include RepoHelpers - describe 'submodule links' do - let(:submodule_item) { double(id: 'hash', path: 'rack') } + describe "submodule links" do + let(:submodule_item) { double(id: "hash", path: "rack") } let(:config) { Gitlab.config.gitlab } let(:repo) { double } before do - self.instance_variable_set(:@repository, repo) + instance_variable_set(:@repository, repo) end - context 'submodule on self' do + context "submodule on self" do before do - allow(Gitlab.config.gitlab).to receive(:protocol).and_return('http') # set this just to be sure + allow(Gitlab.config.gitlab).to receive(:protocol).and_return("http") # set this just to be sure end - it 'detects ssh on standard port' do + it "detects ssh on standard port" do allow(Gitlab.config.gitlab_shell).to receive(:ssh_port).and_return(22) # set this just to be sure allow(Gitlab.config.gitlab_shell).to receive(:ssh_path_prefix).and_return(Settings.send(:build_gitlab_shell_ssh_path_prefix)) - stub_url([config.user, '@', config.host, ':gitlab-org/gitlab-ce.git'].join('')) - expect(submodule_links(submodule_item)).to eq([namespace_project_path('gitlab-org', 'gitlab-ce'), namespace_project_tree_path('gitlab-org', 'gitlab-ce', 'hash')]) + stub_url([config.user, "@", config.host, ":gitlab-org/gitlab-ce.git"].join("")) + expect(submodule_links(submodule_item)).to eq([namespace_project_path("gitlab-org", "gitlab-ce"), namespace_project_tree_path("gitlab-org", "gitlab-ce", "hash")]) end - it 'detects ssh on non-standard port' do + it "detects ssh on non-standard port" do allow(Gitlab.config.gitlab_shell).to receive(:ssh_port).and_return(2222) allow(Gitlab.config.gitlab_shell).to receive(:ssh_path_prefix).and_return(Settings.send(:build_gitlab_shell_ssh_path_prefix)) - stub_url(['ssh://', config.user, '@', config.host, ':2222/gitlab-org/gitlab-ce.git'].join('')) - expect(submodule_links(submodule_item)).to eq([namespace_project_path('gitlab-org', 'gitlab-ce'), namespace_project_tree_path('gitlab-org', 'gitlab-ce', 'hash')]) + stub_url(["ssh://", config.user, "@", config.host, ":2222/gitlab-org/gitlab-ce.git"].join("")) + expect(submodule_links(submodule_item)).to eq([namespace_project_path("gitlab-org", "gitlab-ce"), namespace_project_tree_path("gitlab-org", "gitlab-ce", "hash")]) end - it 'detects http on standard port' do + it "detects http on standard port" do allow(Gitlab.config.gitlab).to receive(:port).and_return(80) allow(Gitlab.config.gitlab).to receive(:url).and_return(Settings.send(:build_gitlab_url)) - stub_url(['http://', config.host, '/gitlab-org/gitlab-ce.git'].join('')) - expect(submodule_links(submodule_item)).to eq([namespace_project_path('gitlab-org', 'gitlab-ce'), namespace_project_tree_path('gitlab-org', 'gitlab-ce', 'hash')]) + stub_url(["http://", config.host, "/gitlab-org/gitlab-ce.git"].join("")) + expect(submodule_links(submodule_item)).to eq([namespace_project_path("gitlab-org", "gitlab-ce"), namespace_project_tree_path("gitlab-org", "gitlab-ce", "hash")]) end - it 'detects http on non-standard port' do + it "detects http on non-standard port" do allow(Gitlab.config.gitlab).to receive(:port).and_return(3000) allow(Gitlab.config.gitlab).to receive(:url).and_return(Settings.send(:build_gitlab_url)) - stub_url(['http://', config.host, ':3000/gitlab-org/gitlab-ce.git'].join('')) - expect(submodule_links(submodule_item)).to eq([namespace_project_path('gitlab-org', 'gitlab-ce'), namespace_project_tree_path('gitlab-org', 'gitlab-ce', 'hash')]) + stub_url(["http://", config.host, ":3000/gitlab-org/gitlab-ce.git"].join("")) + expect(submodule_links(submodule_item)).to eq([namespace_project_path("gitlab-org", "gitlab-ce"), namespace_project_tree_path("gitlab-org", "gitlab-ce", "hash")]) end - it 'works with relative_url_root' do + it "works with relative_url_root" do allow(Gitlab.config.gitlab).to receive(:port).and_return(80) # set this just to be sure - allow(Gitlab.config.gitlab).to receive(:relative_url_root).and_return('/gitlab/root') + allow(Gitlab.config.gitlab).to receive(:relative_url_root).and_return("/gitlab/root") allow(Gitlab.config.gitlab).to receive(:url).and_return(Settings.send(:build_gitlab_url)) - stub_url(['http://', config.host, '/gitlab/root/gitlab-org/gitlab-ce.git'].join('')) - expect(submodule_links(submodule_item)).to eq([namespace_project_path('gitlab-org', 'gitlab-ce'), namespace_project_tree_path('gitlab-org', 'gitlab-ce', 'hash')]) + stub_url(["http://", config.host, "/gitlab/root/gitlab-org/gitlab-ce.git"].join("")) + expect(submodule_links(submodule_item)).to eq([namespace_project_path("gitlab-org", "gitlab-ce"), namespace_project_tree_path("gitlab-org", "gitlab-ce", "hash")]) end - it 'works with subgroups' do + it "works with subgroups" do allow(Gitlab.config.gitlab).to receive(:port).and_return(80) # set this just to be sure - allow(Gitlab.config.gitlab).to receive(:relative_url_root).and_return('/gitlab/root') + allow(Gitlab.config.gitlab).to receive(:relative_url_root).and_return("/gitlab/root") allow(Gitlab.config.gitlab).to receive(:url).and_return(Settings.send(:build_gitlab_url)) - stub_url(['http://', config.host, '/gitlab/root/gitlab-org/sub/gitlab-ce.git'].join('')) - expect(submodule_links(submodule_item)).to eq([namespace_project_path('gitlab-org/sub', 'gitlab-ce'), namespace_project_tree_path('gitlab-org/sub', 'gitlab-ce', 'hash')]) + stub_url(["http://", config.host, "/gitlab/root/gitlab-org/sub/gitlab-ce.git"].join("")) + expect(submodule_links(submodule_item)).to eq([namespace_project_path("gitlab-org/sub", "gitlab-ce"), namespace_project_tree_path("gitlab-org/sub", "gitlab-ce", "hash")]) end end - context 'submodule on github.com' do - it 'detects ssh' do - stub_url('git@github.com:gitlab-org/gitlab-ce.git') - expect(submodule_links(submodule_item)).to eq(['https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash']) + context "submodule on github.com" do + it "detects ssh" do + stub_url("git@github.com:gitlab-org/gitlab-ce.git") + expect(submodule_links(submodule_item)).to eq(["https://github.com/gitlab-org/gitlab-ce", "https://github.com/gitlab-org/gitlab-ce/tree/hash"]) end - it 'detects http' do - stub_url('http://github.com/gitlab-org/gitlab-ce.git') - expect(submodule_links(submodule_item)).to eq(['https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash']) + it "detects http" do + stub_url("http://github.com/gitlab-org/gitlab-ce.git") + expect(submodule_links(submodule_item)).to eq(["https://github.com/gitlab-org/gitlab-ce", "https://github.com/gitlab-org/gitlab-ce/tree/hash"]) end - it 'detects https' do - stub_url('https://github.com/gitlab-org/gitlab-ce.git') - expect(submodule_links(submodule_item)).to eq(['https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash']) + it "detects https" do + stub_url("https://github.com/gitlab-org/gitlab-ce.git") + expect(submodule_links(submodule_item)).to eq(["https://github.com/gitlab-org/gitlab-ce", "https://github.com/gitlab-org/gitlab-ce/tree/hash"]) end - it 'handles urls with no .git on the end' do - stub_url('http://github.com/gitlab-org/gitlab-ce') - expect(submodule_links(submodule_item)).to eq(['https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash']) + it "handles urls with no .git on the end" do + stub_url("http://github.com/gitlab-org/gitlab-ce") + expect(submodule_links(submodule_item)).to eq(["https://github.com/gitlab-org/gitlab-ce", "https://github.com/gitlab-org/gitlab-ce/tree/hash"]) end - it 'returns original with non-standard url' do - stub_url('http://github.com/another/gitlab-org/gitlab-ce.git') + it "returns original with non-standard url" do + stub_url("http://github.com/another/gitlab-org/gitlab-ce.git") expect(submodule_links(submodule_item)).to eq([repo.submodule_url_for, nil]) end end - context 'in-repository submodule' do + context "in-repository submodule" do let(:group) { create(:group, name: "Master Project", path: "master-project") } let(:project) { create(:project, group: group) } - it 'in-repository' do + it "in-repository" do allow(repo).to receive(:project).and_return(project) - stub_url('./') + stub_url("./") expect(submodule_links(submodule_item)).to eq(["/master-project/#{project.path}", "/master-project/#{project.path}/tree/hash"]) end end - context 'submodule on gitlab.com' do - it 'detects ssh' do - stub_url('git@gitlab.com:gitlab-org/gitlab-ce.git') - expect(submodule_links(submodule_item)).to eq(['https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash']) + context "submodule on gitlab.com" do + it "detects ssh" do + stub_url("git@gitlab.com:gitlab-org/gitlab-ce.git") + expect(submodule_links(submodule_item)).to eq(["https://gitlab.com/gitlab-org/gitlab-ce", "https://gitlab.com/gitlab-org/gitlab-ce/tree/hash"]) end - it 'detects http' do - stub_url('http://gitlab.com/gitlab-org/gitlab-ce.git') - expect(submodule_links(submodule_item)).to eq(['https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash']) + it "detects http" do + stub_url("http://gitlab.com/gitlab-org/gitlab-ce.git") + expect(submodule_links(submodule_item)).to eq(["https://gitlab.com/gitlab-org/gitlab-ce", "https://gitlab.com/gitlab-org/gitlab-ce/tree/hash"]) end - it 'detects https' do - stub_url('https://gitlab.com/gitlab-org/gitlab-ce.git') - expect(submodule_links(submodule_item)).to eq(['https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash']) + it "detects https" do + stub_url("https://gitlab.com/gitlab-org/gitlab-ce.git") + expect(submodule_links(submodule_item)).to eq(["https://gitlab.com/gitlab-org/gitlab-ce", "https://gitlab.com/gitlab-org/gitlab-ce/tree/hash"]) end - it 'handles urls with no .git on the end' do - stub_url('http://gitlab.com/gitlab-org/gitlab-ce') - expect(submodule_links(submodule_item)).to eq(['https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash']) + it "handles urls with no .git on the end" do + stub_url("http://gitlab.com/gitlab-org/gitlab-ce") + expect(submodule_links(submodule_item)).to eq(["https://gitlab.com/gitlab-org/gitlab-ce", "https://gitlab.com/gitlab-org/gitlab-ce/tree/hash"]) end - it 'handles urls with trailing whitespace' do - stub_url('http://gitlab.com/gitlab-org/gitlab-ce.git ') - expect(submodule_links(submodule_item)).to eq(['https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash']) + it "handles urls with trailing whitespace" do + stub_url("http://gitlab.com/gitlab-org/gitlab-ce.git ") + expect(submodule_links(submodule_item)).to eq(["https://gitlab.com/gitlab-org/gitlab-ce", "https://gitlab.com/gitlab-org/gitlab-ce/tree/hash"]) end - it 'returns original with non-standard url' do - stub_url('http://gitlab.com/another/gitlab-org/gitlab-ce.git') + it "returns original with non-standard url" do + stub_url("http://gitlab.com/another/gitlab-org/gitlab-ce.git") expect(submodule_links(submodule_item)).to eq([repo.submodule_url_for, nil]) end end - context 'submodule on unsupported' do - it 'sanitizes unsupported protocols' do + context "submodule on unsupported" do + it "sanitizes unsupported protocols" do stub_url('javascript:alert("XSS");') expect(helper.submodule_links(submodule_item)).to eq([nil, nil]) end - it 'sanitizes unsupported protocols disguised as a repository URL' do + it "sanitizes unsupported protocols disguised as a repository URL" do stub_url('javascript:alert("XSS");foo/bar.git') expect(helper.submodule_links(submodule_item)).to eq([nil, nil]) end - it 'sanitizes invalid URL with extended ASCII' do - stub_url('é') + it "sanitizes invalid URL with extended ASCII" do + stub_url("é") expect(helper.submodule_links(submodule_item)).to eq([nil, nil]) end - it 'returns original' do - stub_url('http://mygitserver.com/gitlab-org/gitlab-ce') + it "returns original" do + stub_url("http://mygitserver.com/gitlab-org/gitlab-ce") expect(submodule_links(submodule_item)).to eq([repo.submodule_url_for, nil]) - stub_url('http://mygitserver.com/gitlab-org/gitlab-ce.git') + stub_url("http://mygitserver.com/gitlab-org/gitlab-ce.git") expect(submodule_links(submodule_item)).to eq([repo.submodule_url_for, nil]) end end - context 'submodules with relative links' do + context "submodules with relative links" do let(:group) { create(:group, name: "top group", path: "top-group") } let(:project) { create(:project, group: group) } let(:repo) { double(:repo, project: project) } @@ -174,21 +174,21 @@ describe SubmoduleHelper do expect(result).to eq([expected_path, "#{expected_path}/tree/#{submodule_item.id}"]) end - it 'handles project under same group' do - expect_relative_link_to_resolve_to('../test.git', "/#{group.path}/test") + it "handles project under same group" do + expect_relative_link_to_resolve_to("../test.git", "/#{group.path}/test") end - it 'handles trailing whitespace' do - expect_relative_link_to_resolve_to('../test.git ', "/#{group.path}/test") + it "handles trailing whitespace" do + expect_relative_link_to_resolve_to("../test.git ", "/#{group.path}/test") end - it 'handles project under another top group' do - expect_relative_link_to_resolve_to('../../baz/test.git ', "/baz/test") + it "handles project under another top group" do + expect_relative_link_to_resolve_to("../../baz/test.git ", "/baz/test") end - context 'repo path resolves to be located at root (namespace absent)' do - it 'returns nil' do - allow(repo).to receive(:submodule_url_for).and_return('../../test.git') + context "repo path resolves to be located at root (namespace absent)" do + it "returns nil" do + allow(repo).to receive(:submodule_url_for).and_return("../../test.git") result = submodule_links(submodule_item) @@ -196,9 +196,9 @@ describe SubmoduleHelper do end end - context 'repo path resolves to be located underneath current project path' do - it 'returns nil because it is not possible to have repo nested under another repo' do - allow(repo).to receive(:submodule_url_for).and_return('./test.git') + context "repo path resolves to be located underneath current project path" do + it "returns nil because it is not possible to have repo nested under another repo" do + allow(repo).to receive(:submodule_url_for).and_return("./test.git") result = submodule_links(submodule_item) @@ -206,33 +206,33 @@ describe SubmoduleHelper do end end - context 'subgroup' do + context "subgroup" do let(:sub_group) { create(:group, parent: group, name: "sub group", path: "sub-group") } let(:sub_project) { create(:project, group: sub_group) } - context 'project in sub group' do + context "project in sub group" do let(:project) { sub_project } it "handles referencing ancestor group's project" do - expect_relative_link_to_resolve_to('../../../top-group/test.git', "/#{group.path}/test") + expect_relative_link_to_resolve_to("../../../top-group/test.git", "/#{group.path}/test") end end it "handles referencing descendent group's project" do - expect_relative_link_to_resolve_to('../sub-group/test.git', "/top-group/sub-group/test") + expect_relative_link_to_resolve_to("../sub-group/test.git", "/top-group/sub-group/test") end it "handles referencing another top group's project" do - expect_relative_link_to_resolve_to('../../frontend/css/test.git', "/frontend/css/test") + expect_relative_link_to_resolve_to("../../frontend/css/test.git", "/frontend/css/test") end end - context 'personal project' do + context "personal project" do let(:user) { create(:user) } let(:project) { create(:project, namespace: user.namespace) } - it 'handles referencing another personal project' do - expect_relative_link_to_resolve_to('../test.git', "/#{user.username}/test") + it "handles referencing another personal project" do + expect_relative_link_to_resolve_to("../test.git", "/#{user.username}/test") end end end diff --git a/spec/helpers/tab_helper_spec.rb b/spec/helpers/tab_helper_spec.rb index 9abf63d4bd4..c33c51dcd6e 100644 --- a/spec/helpers/tab_helper_spec.rb +++ b/spec/helpers/tab_helper_spec.rb @@ -1,28 +1,28 @@ -require 'spec_helper' +require "spec_helper" describe TabHelper do include ApplicationHelper - describe 'nav_link' do + describe "nav_link" do before do - allow(controller).to receive(:controller_name).and_return('foo') - allow(self).to receive(:action_name).and_return('foo') + allow(controller).to receive(:controller_name).and_return("foo") + allow(self).to receive(:action_name).and_return("foo") end - context 'with the content of the li' do + context "with the content of the li" do it "captures block output" do expect(nav_link { "Testing Blocks" }).to match(/Testing Blocks/) end end - context 'with controller param' do + context "with controller param" do it "performs checks on the current controller" do expect(nav_link(controller: :foo)).to match(/
  • /) expect(nav_link(controller: :bar)).not_to match(/active/) expect(nav_link(controller: [:foo, :bar])).to match(/active/) end - context 'with action param' do + context "with action param" do it "performs checks on both controller and action when both are present" do expect(nav_link(controller: :bar, action: :foo)).not_to match(/active/) expect(nav_link(controller: :foo, action: :bar)).not_to match(/active/) @@ -30,27 +30,27 @@ describe TabHelper do end end - context 'with namespace in path notation' do + context "with namespace in path notation" do before do - allow(controller).to receive(:controller_path).and_return('bar/foo') + allow(controller).to receive(:controller_path).and_return("bar/foo") end - it 'performs checks on both controller and namespace' do - expect(nav_link(controller: 'foo/foo')).not_to match(/active/) - expect(nav_link(controller: 'bar/foo')).to match(/active/) + it "performs checks on both controller and namespace" do + expect(nav_link(controller: "foo/foo")).not_to match(/active/) + expect(nav_link(controller: "bar/foo")).to match(/active/) end - context 'with action param' do + context "with action param" do it "performs checks on both namespace, controller and action when they are all present" do - expect(nav_link(controller: 'foo/foo', action: :foo)).not_to match(/active/) - expect(nav_link(controller: 'bar/foo', action: :bar)).not_to match(/active/) - expect(nav_link(controller: 'bar/foo', action: :foo)).to match(/active/) + expect(nav_link(controller: "foo/foo", action: :foo)).not_to match(/active/) + expect(nav_link(controller: "bar/foo", action: :bar)).not_to match(/active/) + expect(nav_link(controller: "bar/foo", action: :foo)).to match(/active/) end end end end - context 'with action param' do + context "with action param" do it "performs checks on the current action" do expect(nav_link(action: :foo)).to match(/
  • /) expect(nav_link(action: :bar)).not_to match(/active/) @@ -58,27 +58,27 @@ describe TabHelper do end end - context 'with path param' do + context "with path param" do it "accepts a path shorthand" do - expect(nav_link(path: 'foo#bar')).not_to match(/active/) - expect(nav_link(path: 'foo#foo')).to match(/active/) + expect(nav_link(path: "foo#bar")).not_to match(/active/) + expect(nav_link(path: "foo#foo")).to match(/active/) end - context 'with namespace' do + context "with namespace" do before do - allow(controller).to receive(:controller_path).and_return('bar/foo') + allow(controller).to receive(:controller_path).and_return("bar/foo") end - it 'accepts a path shorthand with namespace' do - expect(nav_link(path: 'bar/foo#foo')).to match(/active/) - expect(nav_link(path: 'foo/foo#foo')).not_to match(/active/) + it "accepts a path shorthand with namespace" do + expect(nav_link(path: "bar/foo#foo")).to match(/active/) + expect(nav_link(path: "foo/foo#foo")).not_to match(/active/) end end end it "passes extra html options to the list element" do - expect(nav_link(action: :foo, html_options: { class: 'home' })).to match(/
  • /) - expect(nav_link(html_options: { class: 'active' })).to match(/
  • /) + expect(nav_link(action: :foo, html_options: {class: "home"})).to match(/
  • /) + expect(nav_link(html_options: {class: "active"})).to match(/
  • /) end end end diff --git a/spec/helpers/time_helper_spec.rb b/spec/helpers/time_helper_spec.rb index 8bf378549fe..af1e7476532 100644 --- a/spec/helpers/time_helper_spec.rb +++ b/spec/helpers/time_helper_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe TimeHelper do describe "#time_interval_in_words" do @@ -10,7 +10,7 @@ describe TimeHelper do 120 => "2 minutes", 121 => "2 minutes and 1 second", 3721 => "62 minutes and 1 second", - 0 => "0 seconds" + 0 => "0 seconds", } intervals_in_words.each do |interval, expectation| diff --git a/spec/helpers/todos_helper_spec.rb b/spec/helpers/todos_helper_spec.rb index 63806ef91f3..0a6e7af2d91 100644 --- a/spec/helpers/todos_helper_spec.rb +++ b/spec/helpers/todos_helper_spec.rb @@ -1,33 +1,33 @@ require "spec_helper" describe TodosHelper do - describe '#todos_count_format' do - it 'shows fuzzy count for 100 or more items' do - expect(helper.todos_count_format(100)).to eq '99+' - expect(helper.todos_count_format(1000)).to eq '99+' + describe "#todos_count_format" do + it "shows fuzzy count for 100 or more items" do + expect(helper.todos_count_format(100)).to eq "99+" + expect(helper.todos_count_format(1000)).to eq "99+" end - it 'shows exact count for 99 or fewer items' do - expect(helper.todos_count_format(99)).to eq '99' - expect(helper.todos_count_format(50)).to eq '50' - expect(helper.todos_count_format(1)).to eq '1' + it "shows exact count for 99 or fewer items" do + expect(helper.todos_count_format(99)).to eq "99" + expect(helper.todos_count_format(50)).to eq "50" + expect(helper.todos_count_format(1)).to eq "1" end end - describe '#todo_projects_options' do + describe "#todo_projects_options" do let(:projects) { create_list(:project, 3) } let(:user) { create(:user) } - it 'returns users authorised projects in json format' do + it "returns users authorised projects in json format" do projects.first.add_developer(user) projects.second.add_developer(user) allow(helper).to receive(:current_user).and_return(user) expected_results = [ - { 'id' => '', 'text' => 'Any Project' }, - { 'id' => projects.second.id, 'text' => projects.second.full_name }, - { 'id' => projects.first.id, 'text' => projects.first.full_name } + {"id" => "", "text" => "Any Project"}, + {"id" => projects.second.id, "text" => projects.second.full_name}, + {"id" => projects.first.id, "text" => projects.first.full_name}, ] expect(JSON.parse(helper.todo_projects_options)).to match_array(expected_results) diff --git a/spec/helpers/tree_helper_spec.rb b/spec/helpers/tree_helper_spec.rb index 4a62e696cd9..7d1d6b3c895 100644 --- a/spec/helpers/tree_helper_spec.rb +++ b/spec/helpers/tree_helper_spec.rb @@ -1,21 +1,21 @@ -require 'spec_helper' +require "spec_helper" describe TreeHelper do let(:project) { create(:project, :repository) } let(:repository) { project.repository } - let(:sha) { 'c1c67abbaf91f624347bb3ae96eabe3a1b742478' } + let(:sha) { "c1c67abbaf91f624347bb3ae96eabe3a1b742478" } def create_file(filename) project.repository.create_file( project.creator, filename, - 'test this', + "test this", message: "Automatically created file #{filename}", - branch_name: 'master' + branch_name: "master" ) end - describe '.render_tree' do + describe ".render_tree" do before do @id = sha @path = "" @@ -23,131 +23,131 @@ describe TreeHelper do @lfs_blob_ids = [] end - it 'displays all entries without a warning' do - tree = repository.tree(sha, 'files') + it "displays all entries without a warning" do + tree = repository.tree(sha, "files") html = render_tree(tree) - expect(html).not_to have_selector('.tree-truncated-warning') + expect(html).not_to have_selector(".tree-truncated-warning") end - it 'truncates entries and adds a warning' do - stub_const('TreeHelper::FILE_LIMIT', 1) - tree = repository.tree(sha, 'files') + it "truncates entries and adds a warning" do + stub_const("TreeHelper::FILE_LIMIT", 1) + tree = repository.tree(sha, "files") html = render_tree(tree) - expect(html).to have_selector('.tree-truncated-warning', count: 1) - expect(html).to have_selector('.tree-item-file-name', count: 1) + expect(html).to have_selector(".tree-truncated-warning", count: 1) + expect(html).to have_selector(".tree-item-file-name", count: 1) end end - describe '.fast_project_blob_path' do - it 'generates the same path as project_blob_path' do - blob_path = repository.tree(sha, 'with space').entries.first.path + describe ".fast_project_blob_path" do + it "generates the same path as project_blob_path" do + blob_path = repository.tree(sha, "with space").entries.first.path fast_path = fast_project_blob_path(project, blob_path) std_path = project_blob_path(project, blob_path) expect(fast_path).to eq(std_path) end - it 'generates the same path with encoded file names' do - tree = repository.tree(sha, 'encoding') - blob_path = tree.entries.find { |entry| entry.path == 'encoding/テスト.txt' }.path + it "generates the same path with encoded file names" do + tree = repository.tree(sha, "encoding") + blob_path = tree.entries.find { |entry| entry.path == "encoding/テスト.txt" }.path fast_path = fast_project_blob_path(project, blob_path) std_path = project_blob_path(project, blob_path) expect(fast_path).to eq(std_path) end - it 'respects a configured relative URL' do - allow(Gitlab.config.gitlab).to receive(:relative_url_root).and_return('/gitlab/root') - blob_path = repository.tree(sha, '').entries.first.path + it "respects a configured relative URL" do + allow(Gitlab.config.gitlab).to receive(:relative_url_root).and_return("/gitlab/root") + blob_path = repository.tree(sha, "").entries.first.path fast_path = fast_project_blob_path(project, blob_path) - expect(fast_path).to start_with('/gitlab/root') + expect(fast_path).to start_with("/gitlab/root") end - it 'encodes files starting with #' do - filename = '#test-file' + it "encodes files starting with #" do + filename = "#test-file" create_file(filename) fast_path = fast_project_blob_path(project, filename) - expect(fast_path).to end_with('%23test-file') + expect(fast_path).to end_with("%23test-file") end end - describe '.fast_project_tree_path' do - let(:tree_path) { repository.tree(sha, 'with space').path } + describe ".fast_project_tree_path" do + let(:tree_path) { repository.tree(sha, "with space").path } let(:fast_path) { fast_project_tree_path(project, tree_path) } let(:std_path) { project_tree_path(project, tree_path) } - it 'generates the same path as project_tree_path' do + it "generates the same path as project_tree_path" do expect(fast_path).to eq(std_path) end - it 'respects a configured relative URL' do - allow(Gitlab.config.gitlab).to receive(:relative_url_root).and_return('/gitlab/root') + it "respects a configured relative URL" do + allow(Gitlab.config.gitlab).to receive(:relative_url_root).and_return("/gitlab/root") - expect(fast_path).to start_with('/gitlab/root') + expect(fast_path).to start_with("/gitlab/root") end - it 'encodes files starting with #' do - filename = '#test-file' + it "encodes files starting with #" do + filename = "#test-file" create_file(filename) fast_path = fast_project_tree_path(project, filename) - expect(fast_path).to end_with('%23test-file') + expect(fast_path).to end_with("%23test-file") end end - describe 'flatten_tree' do - let(:tree) { repository.tree(sha, 'files') } - let(:root_path) { 'files' } + describe "flatten_tree" do + let(:tree) { repository.tree(sha, "files") } + let(:root_path) { "files" } let(:tree_item) { tree.entries.find { |entry| entry.path == path } } subject { flatten_tree(root_path, tree_item) } context "on a directory containing more than one file/directory" do - let(:path) { 'files/html' } + let(:path) { "files/html" } it "returns the directory name" do - expect(subject).to match('html') + expect(subject).to match("html") end end context "on a directory containing only one directory" do - let(:path) { 'files/flat' } + let(:path) { "files/flat" } it "returns the flattened path" do - expect(subject).to match('flat/path/correct') + expect(subject).to match("flat/path/correct") end context "with a nested root path" do - let(:root_path) { 'files/flat' } + let(:root_path) { "files/flat" } it "returns the flattened path with the root path suffix removed" do - expect(subject).to match('path/correct') + expect(subject).to match("path/correct") end end end - context 'when the root path contains a plus character' do - let(:root_path) { 'gtk/C++' } - let(:tree_item) { double(flat_path: 'gtk/C++/glade') } + context "when the root path contains a plus character" do + let(:root_path) { "gtk/C++" } + let(:tree_item) { double(flat_path: "gtk/C++/glade") } - it 'returns the flattened path' do - expect(subject).to eq('glade') + it "returns the flattened path" do + expect(subject).to eq("glade") end end end - describe '#commit_in_single_accessible_branch' do - it 'escapes HTML from the branch name' do + describe "#commit_in_single_accessible_branch" do + it "escapes HTML from the branch name" do helper.instance_variable_set(:@branch_name, "") - escaped_branch_name = '<script>alert('escape me!');</script>' + escaped_branch_name = "<script>alert('escape me!');</script>" expect(helper.commit_in_single_accessible_branch).to include(escaped_branch_name) end diff --git a/spec/helpers/user_callouts_helper_spec.rb b/spec/helpers/user_callouts_helper_spec.rb index 8fa479a4474..f24005ed7af 100644 --- a/spec/helpers/user_callouts_helper_spec.rb +++ b/spec/helpers/user_callouts_helper_spec.rb @@ -7,18 +7,18 @@ describe UserCalloutsHelper do allow(helper).to receive(:current_user).and_return(user) end - describe '.show_gke_cluster_integration_callout?' do + describe ".show_gke_cluster_integration_callout?" do let(:project) { create(:project) } subject { helper.show_gke_cluster_integration_callout?(project) } - context 'when user can create a cluster' do + context "when user can create a cluster" do before do allow(helper).to receive(:can?).with(anything, :create_cluster, anything) .and_return(true) end - context 'when user has not dismissed' do + context "when user has not dismissed" do before do allow(helper).to receive(:user_dismissed?).and_return(false) end @@ -26,7 +26,7 @@ describe UserCalloutsHelper do it { is_expected.to be true } end - context 'when user dismissed' do + context "when user dismissed" do before do allow(helper).to receive(:user_dismissed?).and_return(true) end @@ -35,7 +35,7 @@ describe UserCalloutsHelper do end end - context 'when user can not create a cluster' do + context "when user can not create a cluster" do before do allow(helper).to receive(:can?).with(anything, :create_cluster, anything) .and_return(false) @@ -45,12 +45,12 @@ describe UserCalloutsHelper do end end - describe '.render_flash_user_callout' do - it 'renders the flash_user_callout partial' do + describe ".render_flash_user_callout" do + it "renders the flash_user_callout partial" do expect(helper).to receive(:render) - .with(/flash_user_callout/, flash_type: :warning, message: 'foo', feature_name: 'bar') + .with(/flash_user_callout/, flash_type: :warning, message: "foo", feature_name: "bar") - helper.render_flash_user_callout(:warning, 'foo', 'bar') + helper.render_flash_user_callout(:warning, "foo", "bar") end end end diff --git a/spec/helpers/users_helper_spec.rb b/spec/helpers/users_helper_spec.rb index f3649495493..201ce20d5c1 100644 --- a/spec/helpers/users_helper_spec.rb +++ b/spec/helpers/users_helper_spec.rb @@ -1,11 +1,11 @@ -require 'rails_helper' +require "rails_helper" describe UsersHelper do include TermsHelper let(:user) { create(:user) } - describe '#user_link' do + describe "#user_link" do subject { helper.user_link(user) } it "links to the user's profile" do @@ -17,7 +17,7 @@ describe UsersHelper do end end - describe '#profile_tabs' do + describe "#profile_tabs" do subject(:tabs) { helper.profile_tabs } before do @@ -25,33 +25,33 @@ describe UsersHelper do allow(helper).to receive(:can?).and_return(true) end - context 'with public profile' do - it 'includes all the expected tabs' do + context "with public profile" do + it "includes all the expected tabs" do expect(tabs).to include(:activity, :groups, :contributed, :projects, :snippets) end end - context 'with private profile' do + context "with private profile" do before do allow(helper).to receive(:can?).with(user, :read_user_profile, nil).and_return(false) end - it 'is empty' do + it "is empty" do expect(tabs).to be_empty end end end - describe '#user_internal_regex_data' do + describe "#user_internal_regex_data" do using RSpec::Parameterized::TableSyntax where(:user_default_external, :user_default_internal_regex, :result) do - false | nil | { user_internal_regex_pattern: nil, user_internal_regex_options: nil } - false | '' | { user_internal_regex_pattern: nil, user_internal_regex_options: nil } - false | 'mockRegexPattern' | { user_internal_regex_pattern: nil, user_internal_regex_options: nil } - true | nil | { user_internal_regex_pattern: nil, user_internal_regex_options: nil } - true | '' | { user_internal_regex_pattern: nil, user_internal_regex_options: nil } - true | 'mockRegexPattern' | { user_internal_regex_pattern: 'mockRegexPattern', user_internal_regex_options: 'i' } + false | nil | {user_internal_regex_pattern: nil, user_internal_regex_options: nil} + false | "" | {user_internal_regex_pattern: nil, user_internal_regex_options: nil} + false | "mockRegexPattern" | {user_internal_regex_pattern: nil, user_internal_regex_options: nil} + true | nil | {user_internal_regex_pattern: nil, user_internal_regex_options: nil} + true | "" | {user_internal_regex_pattern: nil, user_internal_regex_options: nil} + true | "mockRegexPattern" | {user_internal_regex_pattern: "mockRegexPattern", user_internal_regex_options: "i"} end with_them do @@ -66,7 +66,7 @@ describe UsersHelper do end end - describe '#current_user_menu_items' do + describe "#current_user_menu_items" do subject(:items) { helper.current_user_menu_items } before do @@ -74,41 +74,41 @@ describe UsersHelper do allow(helper).to receive(:can?).and_return(false) end - it 'includes all default items' do + it "includes all default items" do expect(items).to include(:help, :sign_out) end - it 'includes the profile tab if the user can read themself' do + it "includes the profile tab if the user can read themself" do expect(helper).to receive(:can?).with(user, :read_user, user) { true } expect(items).to include(:profile) end - it 'includes the settings tab if the user can update themself' do + it "includes the settings tab if the user can update themself" do expect(helper).to receive(:can?).with(user, :read_user, user) { true } expect(items).to include(:profile) end - context 'when terms are enforced' do + context "when terms are enforced" do before do enforce_terms end - it 'hides the profile and the settings tab' do + it "hides the profile and the settings tab" do expect(items).not_to include(:settings, :profile, :help) end end end - describe '#user_badges_in_admin_section' do + describe "#user_badges_in_admin_section" do before do allow(helper).to receive(:current_user).and_return(user) end - context 'with a blocked user' do + context "with a blocked user" do it "returns the blocked badge" do - blocked_user = create(:user, state: 'blocked') + blocked_user = create(:user, state: "blocked") badges = helper.user_badges_in_admin_section(blocked_user) @@ -116,7 +116,7 @@ describe UsersHelper do end end - context 'with an admin user' do + context "with an admin user" do it "returns the admin badge" do admin_user = create(:admin) @@ -126,8 +126,8 @@ describe UsersHelper do end end - context 'with an external user' do - it 'returns the external badge' do + context "with an external user" do + it "returns the external badge" do external_user = create(:user, external: true) badges = helper.user_badges_in_admin_section(external_user) @@ -136,7 +136,7 @@ describe UsersHelper do end end - context 'with the current user' do + context "with the current user" do it 'returns the "It\'s You" badge' do badges = helper.user_badges_in_admin_section(user) @@ -144,22 +144,22 @@ describe UsersHelper do end end - context 'with an external blocked admin' do - it 'returns the blocked, admin and external badges' do - user = create(:admin, state: 'blocked', external: true) + context "with an external blocked admin" do + it "returns the blocked, admin and external badges" do + user = create(:admin, state: "blocked", external: true) badges = helper.user_badges_in_admin_section(user) expect(badges).to eq([ - { text: "Blocked", variant: "danger" }, - { text: "Admin", variant: "success" }, - { text: "External", variant: "secondary" } + {text: "Blocked", variant: "danger"}, + {text: "Admin", variant: "success"}, + {text: "External", variant: "secondary"}, ]) end end - context 'get badges for normal user' do - it 'returns no badges' do + context "get badges for normal user" do + it "returns no badges" do user = create(:user) badges = helper.user_badges_in_admin_section(user) diff --git a/spec/helpers/version_check_helper_spec.rb b/spec/helpers/version_check_helper_spec.rb index bfec7ad4bba..7f75da80cc0 100644 --- a/spec/helpers/version_check_helper_spec.rb +++ b/spec/helpers/version_check_helper_spec.rb @@ -1,33 +1,33 @@ -require 'spec_helper' +require "spec_helper" describe VersionCheckHelper do - describe '#version_status_badge' do - it 'should return nil if not dev environment and not enabled' do + describe "#version_status_badge" do + it "should return nil if not dev environment and not enabled" do allow(Rails.env).to receive(:production?) { false } allow(Gitlab::CurrentSettings.current_application_settings).to receive(:version_check_enabled) { false } expect(helper.version_status_badge).to be(nil) end - context 'when production and enabled' do + context "when production and enabled" do before do allow(Rails.env).to receive(:production?) { true } allow(Gitlab::CurrentSettings.current_application_settings).to receive(:version_check_enabled) { true } - allow(VersionCheck).to receive(:url) { 'https://version.host.com/check.svg?gitlab_info=xxx' } + allow(VersionCheck).to receive(:url) { "https://version.host.com/check.svg?gitlab_info=xxx" } end - it 'should return an image tag' do - expect(helper.version_status_badge).to start_with('