diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-01-04 14:18:06 +0100 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-01-14 12:48:15 +0100 |
commit | cd3b8bbd2f8e7ad75a453441f83c46aeb1d37353 (patch) | |
tree | 4db42d36c99897ab1cfaf461ef1d9b5b03c9a218 | |
parent | a5e1905d28e490fb4734bff0e02a1ecff4c7c029 (diff) | |
download | gitlab-ce-cd3b8bbd2f8e7ad75a453441f83c46aeb1d37353.tar.gz |
Add method that checks if path exists in `StringPath`
-rw-r--r-- | app/controllers/projects/artifacts_controller.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/string_path.rb | 4 | ||||
-rw-r--r-- | spec/lib/gitlab/string_path_spec.rb | 13 |
3 files changed, 18 insertions, 1 deletions
diff --git a/app/controllers/projects/artifacts_controller.rb b/app/controllers/projects/artifacts_controller.rb index d11ae5bd52d..647bcc31de5 100644 --- a/app/controllers/projects/artifacts_controller.rb +++ b/app/controllers/projects/artifacts_controller.rb @@ -17,7 +17,7 @@ class Projects::ArtifactsController < Projects::ApplicationController def browse return render_404 unless build.artifacts? @path = build.artifacts_metadata_string_path(params[:path] || './') - return render_404 if @path.universe.empty? + return render_404 unless @path.exists? end private diff --git a/lib/gitlab/string_path.rb b/lib/gitlab/string_path.rb index 4d024b3ff73..a6234d34e7d 100644 --- a/lib/gitlab/string_path.rb +++ b/lib/gitlab/string_path.rb @@ -19,6 +19,10 @@ module Gitlab @path end + def exists? + @path == './' || @universe.include?(@path) + end + def absolute? @path.start_with?('/') end diff --git a/spec/lib/gitlab/string_path_spec.rb b/spec/lib/gitlab/string_path_spec.rb index a54bf109c80..861eb951236 100644 --- a/spec/lib/gitlab/string_path_spec.rb +++ b/spec/lib/gitlab/string_path_spec.rb @@ -32,6 +32,7 @@ describe Gitlab::StringPath do it { is_expected.to be_file } it { is_expected.to have_parent } it { is_expected.to_not have_descendants } + it { is_expected.to exist } describe '#basename' do subject { |example| path(example).basename } @@ -170,4 +171,16 @@ describe Gitlab::StringPath do it { is_expected.to eq '/path/file1' } end + + describe '#exists?', path: 'another_file' do + subject { |example| path(example).exists? } + it { is_expected.to be true } + end + + describe '#exists?', path: './non_existent/' do + let(:universe) { ['./something'] } + subject { |example| path(example).exists? } + + it { is_expected.to be false } + end end |