diff options
Diffstat (limited to 'spec/lib/api')
-rw-r--r-- | spec/lib/api/api_spec.rb | 16 | ||||
-rw-r--r-- | spec/lib/api/helpers/custom_validators_spec.rb | 40 | ||||
-rw-r--r-- | spec/lib/api/helpers/pagination_spec.rb | 252 | ||||
-rw-r--r-- | spec/lib/api/helpers/related_resources_helpers_spec.rb | 38 | ||||
-rw-r--r-- | spec/lib/api/helpers/version_spec.rb | 26 | ||||
-rw-r--r-- | spec/lib/api/helpers_spec.rb | 102 |
6 files changed, 237 insertions, 237 deletions
diff --git a/spec/lib/api/api_spec.rb b/spec/lib/api/api_spec.rb index ceef0b41e59..62686fb9792 100644 --- a/spec/lib/api/api_spec.rb +++ b/spec/lib/api/api_spec.rb @@ -1,20 +1,20 @@ -require 'spec_helper' +require "spec_helper" describe API::API do - describe '.prefix' do - it 'has a prefix defined' do + describe ".prefix" do + it "has a prefix defined" do expect(described_class.prefix).to eq :api end end - describe '.version' do - it 'uses most recent version of the API' do - expect(described_class.version).to eq 'v4' + describe ".version" do + it "uses most recent version of the API" do + expect(described_class.version).to eq "v4" end end - describe '.versions' do - it 'returns all available versions' do + describe ".versions" do + it "returns all available versions" do expect(described_class.versions).to eq %w[v3 v4] end end diff --git a/spec/lib/api/helpers/custom_validators_spec.rb b/spec/lib/api/helpers/custom_validators_spec.rb index 41e6fb47b11..efda9748aa5 100644 --- a/spec/lib/api/helpers/custom_validators_spec.rb +++ b/spec/lib/api/helpers/custom_validators_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe API::Helpers::CustomValidators do let(:scope) do @@ -11,41 +11,41 @@ describe API::Helpers::CustomValidators do describe API::Helpers::CustomValidators::Absence do subject do - described_class.new(['test'], {}, false, scope.new) + described_class.new(["test"], {}, false, scope.new) end - context 'empty param' do - it 'does not raise a validation error' do + context "empty param" do + it "does not raise a validation error" do expect_no_validation_error({}) end end - context 'invalid parameters' do - it 'should raise a validation error' do - expect_validation_error({ 'test' => 'some_value' }) + context "invalid parameters" do + it "should raise a validation error" do + expect_validation_error({"test" => "some_value"}) end end end describe API::Helpers::CustomValidators::IntegerNoneAny do subject do - described_class.new(['test'], {}, false, scope.new) + described_class.new(["test"], {}, false, scope.new) end - context 'valid parameters' do - it 'does not raise a validation error' do - expect_no_validation_error({ 'test' => 2 }) - expect_no_validation_error({ 'test' => 100 }) - expect_no_validation_error({ 'test' => 'None' }) - expect_no_validation_error({ 'test' => 'Any' }) - expect_no_validation_error({ 'test' => 'none' }) - expect_no_validation_error({ 'test' => 'any' }) + context "valid parameters" do + it "does not raise a validation error" do + expect_no_validation_error({"test" => 2}) + expect_no_validation_error({"test" => 100}) + expect_no_validation_error({"test" => "None"}) + expect_no_validation_error({"test" => "Any"}) + expect_no_validation_error({"test" => "none"}) + expect_no_validation_error({"test" => "any"}) end end - context 'invalid parameters' do - it 'should raise a validation error' do - expect_validation_error({ 'test' => 'some_other_string' }) + context "invalid parameters" do + it "should raise a validation error" do + expect_validation_error({"test" => "some_other_string"}) end end end @@ -59,6 +59,6 @@ describe API::Helpers::CustomValidators do end def validate_test_param!(params) - subject.validate_param!('test', params) + subject.validate_param!("test", params) end end diff --git a/spec/lib/api/helpers/pagination_spec.rb b/spec/lib/api/helpers/pagination_spec.rb index 6e215ea1561..ca7650aaf34 100644 --- a/spec/lib/api/helpers/pagination_spec.rb +++ b/spec/lib/api/helpers/pagination_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe API::Helpers::Pagination do let(:resource) { Project.all } @@ -9,13 +9,13 @@ describe API::Helpers::Pagination do Class.new.include(described_class).new end - describe '#paginate (keyset pagination)' do - let(:value) { spy('return value') } + describe "#paginate (keyset pagination)" do + let(:value) { spy("return value") } let(:base_query) do { - pagination: 'keyset', - foo: 'bar', - bar: 'baz' + pagination: "keyset", + foo: "bar", + bar: "baz", } end let(:query) { base_query } @@ -26,31 +26,31 @@ describe API::Helpers::Pagination do allow(subject).to receive(:request).and_return(double(url: "#{incoming_api_projects_url}?#{query.to_query}")) end - context 'when resource can be paginated' do + context "when resource can be paginated" do let!(:projects) do [ - create(:project, name: 'One'), - create(:project, name: 'Two'), - create(:project, name: 'Three') + create(:project, name: "One"), + create(:project, name: "Two"), + create(:project, name: "Three"), ].sort_by { |e| -e.id } # sort by id desc (this is the default sort order for the API) end - describe 'first page' do + describe "first page" do let(:query) { base_query.merge(per_page: 2) } - it 'returns appropriate amount of resources' do + it "returns appropriate amount of resources" do expect(subject.paginate(resource).count).to eq 2 end - it 'returns the first two records (by id desc)' do + it "returns the first two records (by id desc)" do expect(subject.paginate(resource)).to eq(projects[0..1]) end - it 'adds appropriate headers' do - expect_header('X-Per-Page', '2') - expect_header('X-Next-Page', "#{canonical_api_projects_url}?#{query.merge(ks_prev_id: projects[1].id).to_query}") + it "adds appropriate headers" do + expect_header("X-Per-Page", "2") + expect_header("X-Next-Page", "#{canonical_api_projects_url}?#{query.merge(ks_prev_id: projects[1].id).to_query}") - expect_header('Link', anything) do |_key, val| + expect_header("Link", anything) do |_key, val| expect(val).to include('rel="next"') end @@ -58,22 +58,22 @@ describe API::Helpers::Pagination do end end - describe 'second page' do + describe "second page" do let(:query) { base_query.merge(per_page: 2, ks_prev_id: projects[1].id) } - it 'returns appropriate amount of resources' do + it "returns appropriate amount of resources" do expect(subject.paginate(resource).count).to eq 1 end - it 'returns the third record' do + it "returns the third record" do expect(subject.paginate(resource)).to eq(projects[2..2]) end - it 'adds appropriate headers' do - expect_header('X-Per-Page', '2') - expect_header('X-Next-Page', "#{canonical_api_projects_url}?#{query.merge(ks_prev_id: projects[2].id).to_query}") + it "adds appropriate headers" do + expect_header("X-Per-Page", "2") + expect_header("X-Next-Page", "#{canonical_api_projects_url}?#{query.merge(ks_prev_id: projects[2].id).to_query}") - expect_header('Link', anything) do |_key, val| + expect_header("Link", anything) do |_key, val| expect(val).to include('rel="next"') end @@ -81,27 +81,27 @@ describe API::Helpers::Pagination do end end - describe 'third page' do + describe "third page" do let(:query) { base_query.merge(per_page: 2, ks_prev_id: projects[2].id) } - it 'returns appropriate amount of resources' do + it "returns appropriate amount of resources" do expect(subject.paginate(resource).count).to eq 0 end - it 'adds appropriate headers' do - expect_header('X-Per-Page', '2') - expect_no_header('X-Next-Page') - expect(subject).not_to receive(:header).with('Link') + it "adds appropriate headers" do + expect_header("X-Per-Page", "2") + expect_no_header("X-Next-Page") + expect(subject).not_to receive(:header).with("Link") subject.paginate(resource) end end - context 'if order' do - context 'is not present' do + context "if order" do + context "is not present" do let(:query) { base_query.merge(per_page: 2) } - it 'is not present it adds default order(:id) desc' do + it "is not present it adds default order(:id) desc" do resource.order_values = [] paginated_relation = subject.paginate(resource) @@ -114,17 +114,17 @@ describe API::Helpers::Pagination do end end - context 'is present' do + context "is present" do let(:resource) { Project.all.order(name: :desc) } let!(:projects) do [ - create(:project, name: 'One'), - create(:project, name: 'Two'), - create(:project, name: 'Three'), - create(:project, name: 'Three'), # Note the duplicate name - create(:project, name: 'Four'), - create(:project, name: 'Five'), - create(:project, name: 'Six') + create(:project, name: "One"), + create(:project, name: "Two"), + create(:project, name: "Three"), + create(:project, name: "Three"), # Note the duplicate name + create(:project, name: "Four"), + create(:project, name: "Five"), + create(:project, name: "Six"), ] # if we sort this by name descending, id descending, this yields: @@ -141,7 +141,7 @@ describe API::Helpers::Pagination do # (key is the id) end - it 'also orders by primary key' do + it "also orders by primary key" do paginated_relation = subject.paginate(resource) expect(paginated_relation.order_values).to be_present @@ -152,27 +152,27 @@ describe API::Helpers::Pagination do expect(paginated_relation.order_values.second.expr.name).to eq :id end - it 'returns the right records (first page)' do + it "returns the right records (first page)" do result = subject.paginate(resource) expect(result.first).to eq(projects[1]) expect(result.second).to eq(projects[3]) end - describe 'second page' do + describe "second page" do let(:query) { base_query.merge(ks_prev_id: projects[3].id, ks_prev_name: projects[3].name, per_page: 2) } - it 'returns the right records (second page)' do + it "returns the right records (second page)" do result = subject.paginate(resource) expect(result.first).to eq(projects[2]) expect(result.second).to eq(projects[6]) end - it 'returns the right link to the next page' do - expect_header('X-Per-Page', '2') - expect_header('X-Next-Page', "#{canonical_api_projects_url}?#{query.merge(ks_prev_id: projects[6].id, ks_prev_name: projects[6].name).to_query}") - expect_header('Link', anything) do |_key, val| + it "returns the right link to the next page" do + expect_header("X-Per-Page", "2") + expect_header("X-Next-Page", "#{canonical_api_projects_url}?#{query.merge(ks_prev_id: projects[6].id, ks_prev_name: projects[6].name).to_query}") + expect_header("Link", anything) do |_key, val| expect(val).to include('rel="next"') end @@ -180,10 +180,10 @@ describe API::Helpers::Pagination do end end - describe 'third page' do + describe "third page" do let(:query) { base_query.merge(ks_prev_id: projects[6].id, ks_prev_name: projects[6].name, per_page: 5) } - it 'returns the right records (third page), note increased per_page' do + it "returns the right records (third page), note increased per_page" do result = subject.paginate(resource) expect(result.size).to eq(3) @@ -197,9 +197,9 @@ describe API::Helpers::Pagination do end end - describe '#paginate (default offset-based pagination)' do - let(:value) { spy('return value') } - let(:base_query) { { foo: 'bar', bar: 'baz' } } + describe "#paginate (default offset-based pagination)" do + let(:value) { spy("return value") } + let(:base_query) { {foo: "bar", bar: "baz"} } let(:query) { base_query } before do @@ -208,25 +208,25 @@ describe API::Helpers::Pagination do allow(subject).to receive(:request).and_return(double(url: "#{incoming_api_projects_url}?#{query.to_query}")) end - context 'when resource can be paginated' do + context "when resource can be paginated" do before do create_list(:project, 3) end - describe 'first page' do - shared_examples 'response with pagination headers' do - it 'adds appropriate headers' do - expect_header('X-Total', '3') - expect_header('X-Total-Pages', '2') - expect_header('X-Per-Page', '2') - expect_header('X-Page', '1') - expect_header('X-Next-Page', '2') - expect_header('X-Prev-Page', '') - - expect_header('Link', anything) do |_key, val| - expect(val).to include(%Q(<#{canonical_api_projects_url}?#{query.merge(page: 1).to_query}>; rel="first")) - expect(val).to include(%Q(<#{canonical_api_projects_url}?#{query.merge(page: 2).to_query}>; rel="last")) - expect(val).to include(%Q(<#{canonical_api_projects_url}?#{query.merge(page: 2).to_query}>; rel="next")) + describe "first page" do + shared_examples "response with pagination headers" do + it "adds appropriate headers" do + expect_header("X-Total", "3") + expect_header("X-Total-Pages", "2") + expect_header("X-Per-Page", "2") + expect_header("X-Page", "1") + expect_header("X-Next-Page", "2") + expect_header("X-Prev-Page", "") + + expect_header("Link", anything) do |_key, val| + expect(val).to include(%(<#{canonical_api_projects_url}?#{query.merge(page: 1).to_query}>; rel="first")) + expect(val).to include(%(<#{canonical_api_projects_url}?#{query.merge(page: 2).to_query}>; rel="last")) + expect(val).to include(%(<#{canonical_api_projects_url}?#{query.merge(page: 2).to_query}>; rel="next")) expect(val).not_to include('rel="prev"') end @@ -234,64 +234,64 @@ describe API::Helpers::Pagination do end end - shared_examples 'paginated response' do - it 'returns appropriate amount of resources' do + shared_examples "paginated response" do + it "returns appropriate amount of resources" do expect(subject.paginate(resource).count).to eq 2 end - it 'executes only one SELECT COUNT query' do + it "executes only one SELECT COUNT query" do expect { subject.paginate(resource) }.to make_queries_matching(/SELECT COUNT/, 1) end end let(:query) { base_query.merge(page: 1, per_page: 2) } - context 'when the api_kaminari_count_with_limit feature flag is unset' do - it_behaves_like 'paginated response' - it_behaves_like 'response with pagination headers' + context "when the api_kaminari_count_with_limit feature flag is unset" do + it_behaves_like "paginated response" + it_behaves_like "response with pagination headers" end - context 'when the api_kaminari_count_with_limit feature flag is disabled' do + context "when the api_kaminari_count_with_limit feature flag is disabled" do before do stub_feature_flags(api_kaminari_count_with_limit: false) end - it_behaves_like 'paginated response' - it_behaves_like 'response with pagination headers' + it_behaves_like "paginated response" + it_behaves_like "response with pagination headers" end - context 'when the api_kaminari_count_with_limit feature flag is enabled' do + context "when the api_kaminari_count_with_limit feature flag is enabled" do before do stub_feature_flags(api_kaminari_count_with_limit: true) end - context 'when resources count is less than MAX_COUNT_LIMIT' do + context "when resources count is less than MAX_COUNT_LIMIT" do before do stub_const("::Kaminari::ActiveRecordRelationMethods::MAX_COUNT_LIMIT", 4) end - it_behaves_like 'paginated response' - it_behaves_like 'response with pagination headers' + it_behaves_like "paginated response" + it_behaves_like "response with pagination headers" end - context 'when resources count is more than MAX_COUNT_LIMIT' do + context "when resources count is more than MAX_COUNT_LIMIT" do before do stub_const("::Kaminari::ActiveRecordRelationMethods::MAX_COUNT_LIMIT", 2) end - it_behaves_like 'paginated response' + it_behaves_like "paginated response" - it 'does not return the X-Total and X-Total-Pages headers' do - expect_no_header('X-Total') - expect_no_header('X-Total-Pages') - expect_header('X-Per-Page', '2') - expect_header('X-Page', '1') - expect_header('X-Next-Page', '2') - expect_header('X-Prev-Page', '') + it "does not return the X-Total and X-Total-Pages headers" do + expect_no_header("X-Total") + expect_no_header("X-Total-Pages") + expect_header("X-Per-Page", "2") + expect_header("X-Page", "1") + expect_header("X-Next-Page", "2") + expect_header("X-Prev-Page", "") - expect_header('Link', anything) do |_key, val| - expect(val).to include(%Q(<#{canonical_api_projects_url}?#{query.merge(page: 1).to_query}>; rel="first")) - expect(val).to include(%Q(<#{canonical_api_projects_url}?#{query.merge(page: 2).to_query}>; rel="next")) + expect_header("Link", anything) do |_key, val| + expect(val).to include(%(<#{canonical_api_projects_url}?#{query.merge(page: 1).to_query}>; rel="first")) + expect(val).to include(%(<#{canonical_api_projects_url}?#{query.merge(page: 2).to_query}>; rel="next")) expect(val).not_to include('rel="last"') expect(val).not_to include('rel="prev"') end @@ -302,25 +302,25 @@ describe API::Helpers::Pagination do end end - describe 'second page' do + describe "second page" do let(:query) { base_query.merge(page: 2, per_page: 2) } - it 'returns appropriate amount of resources' do + it "returns appropriate amount of resources" do expect(subject.paginate(resource).count).to eq 1 end - it 'adds appropriate headers' do - expect_header('X-Total', '3') - expect_header('X-Total-Pages', '2') - expect_header('X-Per-Page', '2') - expect_header('X-Page', '2') - expect_header('X-Next-Page', '') - expect_header('X-Prev-Page', '1') - - expect_header('Link', anything) do |_key, val| - expect(val).to include(%Q(<#{canonical_api_projects_url}?#{query.merge(page: 1).to_query}>; rel="first")) - expect(val).to include(%Q(<#{canonical_api_projects_url}?#{query.merge(page: 2).to_query}>; rel="last")) - expect(val).to include(%Q(<#{canonical_api_projects_url}?#{query.merge(page: 1).to_query}>; rel="prev")) + it "adds appropriate headers" do + expect_header("X-Total", "3") + expect_header("X-Total-Pages", "2") + expect_header("X-Per-Page", "2") + expect_header("X-Page", "2") + expect_header("X-Next-Page", "") + expect_header("X-Prev-Page", "1") + + expect_header("Link", anything) do |_key, val| + expect(val).to include(%(<#{canonical_api_projects_url}?#{query.merge(page: 1).to_query}>; rel="first")) + expect(val).to include(%(<#{canonical_api_projects_url}?#{query.merge(page: 2).to_query}>; rel="last")) + expect(val).to include(%(<#{canonical_api_projects_url}?#{query.merge(page: 1).to_query}>; rel="prev")) expect(val).not_to include('rel="next"') end @@ -328,8 +328,8 @@ describe API::Helpers::Pagination do end end - context 'if order' do - it 'is not present it adds default order(:id) if no order is present' do + context "if order" do + it "is not present it adds default order(:id) if no order is present" do resource.order_values = [] paginated_relation = subject.paginate(resource) @@ -340,7 +340,7 @@ describe API::Helpers::Pagination do expect(paginated_relation.order_values.first.expr.name).to eq :id end - it 'is present it does not add anything' do + it "is present it does not add anything" do paginated_relation = subject.paginate(resource.order(created_at: :desc)) expect(paginated_relation.order_values).to be_present @@ -350,28 +350,28 @@ describe API::Helpers::Pagination do end end - context 'when resource empty' do - describe 'first page' do + context "when resource empty" do + describe "first page" do let(:query) { base_query.merge(page: 1, per_page: 2) } - it 'returns appropriate amount of resources' do + it "returns appropriate amount of resources" do expect(subject.paginate(resource).count).to eq 0 end - it 'adds appropriate headers' do - expect_header('X-Total', '0') - expect_header('X-Total-Pages', '1') - expect_header('X-Per-Page', '2') - expect_header('X-Page', '1') - expect_header('X-Next-Page', '') - expect_header('X-Prev-Page', '') - - expect_header('Link', anything) do |_key, val| - expect(val).to include(%Q(<#{canonical_api_projects_url}?#{query.merge(page: 1).to_query}>; rel="first")) - expect(val).to include(%Q(<#{canonical_api_projects_url}?#{query.merge(page: 1).to_query}>; rel="last")) + it "adds appropriate headers" do + expect_header("X-Total", "0") + expect_header("X-Total-Pages", "1") + expect_header("X-Per-Page", "2") + expect_header("X-Page", "1") + expect_header("X-Next-Page", "") + expect_header("X-Prev-Page", "") + + expect_header("Link", anything) do |_key, val| + expect(val).to include(%(<#{canonical_api_projects_url}?#{query.merge(page: 1).to_query}>; rel="first")) + expect(val).to include(%(<#{canonical_api_projects_url}?#{query.merge(page: 1).to_query}>; rel="last")) expect(val).not_to include('rel="prev"') expect(val).not_to include('rel="next"') - expect(val).not_to include('page=0') + expect(val).not_to include("page=0") end subject.paginate(resource) diff --git a/spec/lib/api/helpers/related_resources_helpers_spec.rb b/spec/lib/api/helpers/related_resources_helpers_spec.rb index 66af7f81535..085d0819bd0 100644 --- a/spec/lib/api/helpers/related_resources_helpers_spec.rb +++ b/spec/lib/api/helpers/related_resources_helpers_spec.rb @@ -1,53 +1,53 @@ -require 'spec_helper' +require "spec_helper" describe API::Helpers::RelatedResourcesHelpers do subject(:helpers) do Class.new.include(described_class).new end - describe '#expose_url' do - let(:path) { '/api/v4/awesome_endpoint' } + describe "#expose_url" do + let(:path) { "/api/v4/awesome_endpoint" } subject(:url) { helpers.expose_url(path) } - def stub_default_url_options(protocol: 'http', host: 'example.com', port: nil, script_name: '') + def stub_default_url_options(protocol: "http", host: "example.com", port: nil, script_name: "") expect(Gitlab::Application.routes).to receive(:default_url_options) .and_return(protocol: protocol, host: host, port: port, script_name: script_name) end - it 'respects the protocol if it is HTTP' do - stub_default_url_options(protocol: 'http') + it "respects the protocol if it is HTTP" do + stub_default_url_options(protocol: "http") - is_expected.to start_with('http://') + is_expected.to start_with("http://") end - it 'respects the protocol if it is HTTPS' do - stub_default_url_options(protocol: 'https') + it "respects the protocol if it is HTTPS" do + stub_default_url_options(protocol: "https") - is_expected.to start_with('https://') + is_expected.to start_with("https://") end - it 'accepts port to be nil' do + it "accepts port to be nil" do stub_default_url_options(port: nil) - is_expected.to start_with('http://example.com/') + is_expected.to start_with("http://example.com/") end - it 'includes port if provided' do + it "includes port if provided" do stub_default_url_options(port: 8080) - is_expected.to start_with('http://example.com:8080/') + is_expected.to start_with("http://example.com:8080/") end - it 'includes the relative_url before the path if it is set' do - stub_default_url_options(script_name: '/gitlab') + it "includes the relative_url before the path if it is set" do + stub_default_url_options(script_name: "/gitlab") - is_expected.to start_with('http://example.com/gitlab/api/v4') + is_expected.to start_with("http://example.com/gitlab/api/v4") end - it 'includes the path after the host' do + it "includes the path after the host" do stub_default_url_options - is_expected.to start_with('http://example.com/api/v4') + is_expected.to start_with("http://example.com/api/v4") end end end diff --git a/spec/lib/api/helpers/version_spec.rb b/spec/lib/api/helpers/version_spec.rb index 34006e0930b..d69dcf6a9d0 100644 --- a/spec/lib/api/helpers/version_spec.rb +++ b/spec/lib/api/helpers/version_spec.rb @@ -1,26 +1,26 @@ -require 'spec_helper' +require "spec_helper" describe API::Helpers::Version do - describe '.new' do - it 'is possible to initialize it with existing API version' do - expect(described_class.new('v4').to_s).to eq 'v4' + describe ".new" do + it "is possible to initialize it with existing API version" do + expect(described_class.new("v4").to_s).to eq "v4" end - it 'raises an error when unsupported API version is provided' do - expect { described_class.new('v111') }.to raise_error ArgumentError + it "raises an error when unsupported API version is provided" do + expect { described_class.new("v111") }.to raise_error ArgumentError end end - describe '#root_path' do - it 'returns a root path of the API version' do - expect(described_class.new('v4').root_path).to eq '/api/v4' + describe "#root_path" do + it "returns a root path of the API version" do + expect(described_class.new("v4").root_path).to eq "/api/v4" end end - describe '#root_url' do - it 'returns an URL for a root path for the API version' do - expect(described_class.new('v4').root_url) - .to eq 'http://localhost/api/v4' + describe "#root_url" do + it "returns an URL for a root path for the API version" do + expect(described_class.new("v4").root_url) + .to eq "http://localhost/api/v4" end end end diff --git a/spec/lib/api/helpers_spec.rb b/spec/lib/api/helpers_spec.rb index 08165f147bb..e677b3910ee 100644 --- a/spec/lib/api/helpers_spec.rb +++ b/spec/lib/api/helpers_spec.rb @@ -1,42 +1,42 @@ -require 'spec_helper' +require "spec_helper" describe API::Helpers do subject { Class.new.include(described_class).new } - describe '#find_project' do + describe "#find_project" do let(:project) { create(:project) } - shared_examples 'project finder' do - context 'when project exists' do - it 'returns requested project' do + shared_examples "project finder" do + context "when project exists" do + it "returns requested project" do expect(subject.find_project(existing_id)).to eq(project) end - it 'returns nil' do + it "returns nil" do expect(subject.find_project(non_existing_id)).to be_nil end end end - context 'when ID is used as an argument' do + context "when ID is used as an argument" do let(:existing_id) { project.id } let(:non_existing_id) { (Project.maximum(:id) || 0) + 1 } - it_behaves_like 'project finder' + it_behaves_like "project finder" end - context 'when PATH is used as an argument' do + context "when PATH is used as an argument" do let(:existing_id) { project.full_path } - let(:non_existing_id) { 'something/else' } + let(:non_existing_id) { "something/else" } - it_behaves_like 'project finder' + it_behaves_like "project finder" - context 'with an invalid PATH' do - let(:non_existing_id) { 'undefined' } # path without slash + context "with an invalid PATH" do + let(:non_existing_id) { "undefined" } # path without slash - it_behaves_like 'project finder' + it_behaves_like "project finder" - it 'does not hit the database' do + it "does not hit the database" do expect(Project).not_to receive(:find_by_full_path) subject.find_project(non_existing_id) @@ -45,64 +45,64 @@ describe API::Helpers do end end - describe '#find_namespace' do + describe "#find_namespace" do let(:namespace) { create(:namespace) } - shared_examples 'namespace finder' do - context 'when namespace exists' do - it 'returns requested namespace' do + shared_examples "namespace finder" do + context "when namespace exists" do + it "returns requested namespace" do expect(subject.find_namespace(existing_id)).to eq(namespace) end end context "when namespace doesn't exists" do - it 'returns nil' do + it "returns nil" do expect(subject.find_namespace(non_existing_id)).to be_nil end end end - context 'when ID is used as an argument' do + context "when ID is used as an argument" do let(:existing_id) { namespace.id } let(:non_existing_id) { 9999 } - it_behaves_like 'namespace finder' + it_behaves_like "namespace finder" end - context 'when PATH is used as an argument' do + context "when PATH is used as an argument" do let(:existing_id) { namespace.path } - let(:non_existing_id) { 'non-existing-path' } + let(:non_existing_id) { "non-existing-path" } - it_behaves_like 'namespace finder' + it_behaves_like "namespace finder" end end - shared_examples 'user namespace finder' do + shared_examples "user namespace finder" do let(:user1) { create(:user) } before do allow(subject).to receive(:current_user).and_return(user1) allow(subject).to receive(:header).and_return(nil) - allow(subject).to receive(:not_found!).and_raise('404 Namespace not found') + allow(subject).to receive(:not_found!).and_raise("404 Namespace not found") end - context 'when namespace is group' do + context "when namespace is group" do let(:namespace) { create(:group) } - context 'when user has access to group' do + context "when user has access to group" do before do namespace.add_guest(user1) namespace.save! end - it 'returns requested namespace' do + it "returns requested namespace" do expect(namespace_finder).to eq(namespace) end end context "when user doesn't have access to group" do - it 'raises not found error' do - expect { namespace_finder }.to raise_error(RuntimeError, '404 Namespace not found') + it "raises not found error" do + expect { namespace_finder }.to raise_error(RuntimeError, "404 Namespace not found") end end end @@ -110,48 +110,48 @@ describe API::Helpers do context "when namespace is user's personal namespace" do let(:namespace) { create(:namespace) } - context 'when user owns the namespace' do + context "when user owns the namespace" do before do namespace.owner = user1 namespace.save! end - it 'returns requested namespace' do + it "returns requested namespace" do expect(namespace_finder).to eq(namespace) end end context "when user doesn't own the namespace" do - it 'raises not found error' do - expect { namespace_finder }.to raise_error(RuntimeError, '404 Namespace not found') + it "raises not found error" do + expect { namespace_finder }.to raise_error(RuntimeError, "404 Namespace not found") end end end end - describe '#find_namespace!' do + describe "#find_namespace!" do let(:namespace_finder) do subject.find_namespace!(namespace.id) end - it_behaves_like 'user namespace finder' + it_behaves_like "user namespace finder" end - describe '#user_namespace' do + describe "#user_namespace" do let(:namespace_finder) do subject.user_namespace end before do - allow(subject).to receive(:params).and_return({ id: namespace.id }) + allow(subject).to receive(:params).and_return({id: namespace.id}) end - it_behaves_like 'user namespace finder' + it_behaves_like "user namespace finder" end - describe '#send_git_blob' do + describe "#send_git_blob" do let(:repository) { double } - let(:blob) { double(name: 'foobar') } + let(:blob) { double(name: "foobar") } let(:send_git_blob) do subject.send(:send_git_blob, repository, blob) @@ -164,22 +164,22 @@ describe API::Helpers do allow(Gitlab::Workhorse).to receive(:send_git_blob) end - it 'sets Gitlab::Workhorse::DETECT_HEADER header' do + it "sets Gitlab::Workhorse::DETECT_HEADER header" do expect(send_git_blob[Gitlab::Workhorse::DETECT_HEADER]).to eq "true" end - context 'content disposition' do - context 'when blob name is null' do + context "content disposition" do + context "when blob name is null" do let(:blob) { double(name: nil) } - it 'returns only the disposition' do - expect(send_git_blob['Content-Disposition']).to eq 'inline' + it "returns only the disposition" do + expect(send_git_blob["Content-Disposition"]).to eq "inline" end end - context 'when blob name is not null' do - it 'returns disposition with the blob name' do - expect(send_git_blob['Content-Disposition']).to eq %q(inline; filename="foobar"; filename*=UTF-8''foobar) + context "when blob name is not null" do + it "returns disposition with the blob name" do + expect(send_git_blob["Content-Disposition"]).to eq %q(inline; filename="foobar"; filename*=UTF-8''foobar) end end end |