2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
RSpec.describe 'View on environment', :js, feature_category: :projects do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:branch_name) { 'feature' }
|
|
|
|
let(:file_path) { 'files/ruby/feature.rb' }
|
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:user) { project.creator }
|
|
|
|
|
|
|
|
before do
|
2018-11-18 11:00:15 +05:30
|
|
|
project.add_maintainer(user)
|
2017-08-17 22:00:37 +05:30
|
|
|
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,
|
|
|
|
start_branch: branch_name,
|
|
|
|
branch_name: branch_name,
|
2019-12-26 22:10:19 +05:30
|
|
|
commit_message: 'Add .gitlab/route-map.yml',
|
2017-08-17 22:00:37 +05:30
|
|
|
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,
|
|
|
|
start_branch: branch_name,
|
|
|
|
branch_name: branch_name,
|
2019-12-26 22:10:19 +05:30
|
|
|
commit_message: 'Update feature',
|
2017-08-17 22:00:37 +05:30
|
|
|
file_path: file_path,
|
2019-12-26 22:10:19 +05:30
|
|
|
file_content: '# Noop'
|
2017-08-17 22:00:37 +05:30
|
|
|
).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') }
|
2018-12-13 13:39:08 +05:30
|
|
|
let!(:deployment) { create(:deployment, :success, environment: environment, ref: branch_name, sha: sha) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
context 'when visiting a comparison for the branch' do
|
|
|
|
before do
|
2017-09-10 17:25:29 +05:30
|
|
|
sign_in(user)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
visit project_compare_path(project, from: 'master', to: branch_name)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
wait_for_requests
|
2017-08-17 22:00:37 +05:30
|
|
|
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
|
2017-09-10 17:25:29 +05:30
|
|
|
sign_in(user)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
visit project_compare_path(project, from: 'master', to: sha)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
wait_for_requests
|
2017-08-17 22:00:37 +05:30
|
|
|
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
|
2017-09-10 17:25:29 +05:30
|
|
|
sign_in(user)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
visit project_blob_path(project, File.join(branch_name, file_path))
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
wait_for_requests
|
2017-08-17 22:00:37 +05:30
|
|
|
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
|
2017-09-10 17:25:29 +05:30
|
|
|
sign_in(user)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
visit project_blob_path(project, File.join(sha, file_path))
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
wait_for_requests
|
2017-08-17 22:00:37 +05:30
|
|
|
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
|
2017-09-10 17:25:29 +05:30
|
|
|
sign_in(user)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
visit project_commit_path(project, sha)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
wait_for_requests
|
2017-08-17 22:00:37 +05:30
|
|
|
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
|