diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-02-01 15:49:20 -0600 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-02-06 16:12:24 -0600 |
commit | 6edc8d50dcec3252fd5afa244f9ade2e062f920d (patch) | |
tree | a837f220409adda5c7482396b2f78a53da2acdd8 | |
parent | 3dfb6a309442b181f179e854fdfe13f80f493616 (diff) | |
download | gitlab-ce-6edc8d50dcec3252fd5afa244f9ade2e062f920d.tar.gz |
Add feature specs
-rw-r--r-- | app/controllers/projects/blob_controller.rb | 4 | ||||
-rw-r--r-- | app/controllers/projects/compare_controller.rb | 4 | ||||
-rw-r--r-- | app/models/repository.rb | 4 | ||||
-rw-r--r-- | spec/features/projects/blobs/view_on_env_spec.rb | 7 | ||||
-rw-r--r-- | spec/features/projects/commit/view_on_env_spec.rb | 9 | ||||
-rw-r--r-- | spec/features/projects/compare/view_on_env_spec.rb | 9 | ||||
-rw-r--r-- | spec/features/projects/merge_requests/view_on_env_spec.rb | 9 | ||||
-rw-r--r-- | spec/features/projects/view_on_env_spec.rb | 140 |
8 files changed, 147 insertions, 39 deletions
diff --git a/app/controllers/projects/blob_controller.rb b/app/controllers/projects/blob_controller.rb index c88095abb3a..e7d61510624 100644 --- a/app/controllers/projects/blob_controller.rb +++ b/app/controllers/projects/blob_controller.rb @@ -30,8 +30,8 @@ class Projects::BlobController < Projects::ApplicationController end def show - branch_name = @ref if @repository.branch_exists?(@ref) - @environment = @project.environments_for(commit: @commit, ref: branch_name).last + environment_args = @repository.branch_exists?(@ref) ? { ref: @ref } : { commit: @commit } + @environment = @project.environments_for(**environment_args).last @environment = nil unless can?(current_user, :read_environment, @environment) end diff --git a/app/controllers/projects/compare_controller.rb b/app/controllers/projects/compare_controller.rb index 142df1ba4e9..d5cca827e9f 100644 --- a/app/controllers/projects/compare_controller.rb +++ b/app/controllers/projects/compare_controller.rb @@ -57,8 +57,8 @@ class Projects::CompareController < Projects::ApplicationController @diffs = @compare.diffs(diff_options) - branch_name = @head_ref if @repository.branch_exists?(@head_ref) - @environment = @project.environments_for(commit: @commit, ref: branch_name).last + environment_args = @repository.branch_exists?(@head_ref) ? { ref: @head_ref } : { commit: @commit } + @environment = @project.environments_for(**environment_args).last @environment = nil unless can?(current_user, :read_environment, @environment) @diff_notes_disabled = true diff --git a/app/models/repository.rb b/app/models/repository.rb index c043753507e..3e52841e802 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -467,6 +467,8 @@ class Repository unless Gitlab::Git.blank_ref?(sha) Blob.decorate(Gitlab::Git::Blob.find(self, sha, path)) end + rescue Gitlab::Git::Repository::NoRepository + nil end def blob_by_oid(oid) @@ -1190,7 +1192,7 @@ class Repository def route_map_for(sha) blob = blob_at(sha, ROUTE_MAP_PATH) return unless blob - + blob.load_all_data!(self) blob.data end diff --git a/spec/features/projects/blobs/view_on_env_spec.rb b/spec/features/projects/blobs/view_on_env_spec.rb deleted file mode 100644 index 360f9d66609..00000000000 --- a/spec/features/projects/blobs/view_on_env_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'spec_helper' - -feature 'Blob' do - describe 'View on environment' do - # TODO: Test - end -end diff --git a/spec/features/projects/commit/view_on_env_spec.rb b/spec/features/projects/commit/view_on_env_spec.rb deleted file mode 100644 index eee2814089a..00000000000 --- a/spec/features/projects/commit/view_on_env_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'spec_helper' - -feature 'Commit' do - describe 'Diff' do - describe 'View on environment' do - # TODO: Test - end - end -end diff --git a/spec/features/projects/compare/view_on_env_spec.rb b/spec/features/projects/compare/view_on_env_spec.rb deleted file mode 100644 index 0a4ec03b17f..00000000000 --- a/spec/features/projects/compare/view_on_env_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'spec_helper' - -feature 'Compare' do - describe 'Diff' do - describe 'View on environment' do - # TODO: Test - end - end -end diff --git a/spec/features/projects/merge_requests/view_on_env_spec.rb b/spec/features/projects/merge_requests/view_on_env_spec.rb deleted file mode 100644 index b25e499acd6..00000000000 --- a/spec/features/projects/merge_requests/view_on_env_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'spec_helper' - -feature 'Merge Request' do - describe 'Diff' do - describe 'View on environment' do - # TODO: Test - end - end -end diff --git a/spec/features/projects/view_on_env_spec.rb b/spec/features/projects/view_on_env_spec.rb new file mode 100644 index 00000000000..552705661a9 --- /dev/null +++ b/spec/features/projects/view_on_env_spec.rb @@ -0,0 +1,140 @@ +require 'spec_helper' + +describe 'View on environment', js: true do + include WaitForAjax + + let(:branch_name) { 'feature' } + let(:file_path) { 'files/ruby/feature.rb' } + let(:project) { create(:project) } + let(:user) { project.creator } + + before do + project.team << [user, :master] + end + + context 'when the branch has a route map' do + let(:route_map) do + <<-MAP.strip_heredoc + - source: /files/(.*)\\..*/ + public: '\\1' + MAP + end + + before do + Files::CreateService.new( + project, + user, + source_branch: branch_name, + target_branch: branch_name, + commit_message: "Add .gitlab/route-map.yml", + file_path: '.gitlab/route-map.yml', + file_content: route_map + ).execute + + # Update the file so that we still have a commit that will have a file on the environment + Files::UpdateService.new( + project, + user, + source_branch: branch_name, + target_branch: branch_name, + commit_message: "Update feature", + file_path: file_path, + file_content: "# Noop" + ).execute + end + + context 'and an active deployment' do + let(:sha) { project.commit(branch_name).sha } + let(:environment) { create(:environment, project: project, name: 'review/feature', external_url: 'http://feature.review.example.com') } + let!(:deployment) { create(:deployment, environment: environment, ref: branch_name, sha: sha) } + + context 'when visiting the diff of a merge request for the branch' do + let(:merge_request) { create(:merge_request, :simple, source_project: project, source_branch: branch_name) } + + before do + login_as(user) + + visit diffs_namespace_project_merge_request_path(project.namespace, project, merge_request) + + wait_for_ajax + end + + it 'has a "View on env" button' do + within '.diffs' do + expect(page).to have_link('View on feature.review.example.com', href: 'http://feature.review.example.com/ruby/feature') + end + end + end + + context 'when visiting a comparison for the branch' do + before do + login_as(user) + + visit namespace_project_compare_path(project.namespace, project, from: 'master', to: branch_name) + + wait_for_ajax + end + + it 'has a "View on env" button' do + expect(page).to have_link('View on feature.review.example.com', href: 'http://feature.review.example.com/ruby/feature') + end + end + + context 'when visiting a comparison for the commit' do + before do + login_as(user) + + visit namespace_project_compare_path(project.namespace, project, from: 'master', to: sha) + + wait_for_ajax + end + + it 'has a "View on env" button' do + expect(page).to have_link('View on feature.review.example.com', href: 'http://feature.review.example.com/ruby/feature') + end + end + + context 'when visiting a blob on the branch' do + before do + login_as(user) + + visit namespace_project_blob_path(project.namespace, project, File.join(branch_name, file_path)) + + wait_for_ajax + end + + it 'has a "View on env" button' do + expect(page).to have_link('View on feature.review.example.com', href: 'http://feature.review.example.com/ruby/feature') + end + end + + context 'when visiting a blob on the commit' do + before do + login_as(user) + + visit namespace_project_blob_path(project.namespace, project, File.join(sha, file_path)) + + wait_for_ajax + end + + it 'has a "View on env" button' do + expect(page).to have_link('View on feature.review.example.com', href: 'http://feature.review.example.com/ruby/feature') + end + end + + context 'when visiting the commit' do + before do + login_as(user) + + visit namespace_project_commit_path(project.namespace, project, sha) + + wait_for_ajax + end + + it 'has a "View on env" button' do + expect(page).to have_link('View on feature.review.example.com', href: 'http://feature.review.example.com/ruby/feature') + end + end + end + end +end |