From 4a17553c25da15a94e178e9b3a27f684d2c4e07f Mon Sep 17 00:00:00 2001 From: Chaoyue Zhao Date: Wed, 5 Nov 2025 20:08:15 -0500 Subject: [PATCH 1/8] Support view on environment for commits and compare pages in rapid diffs --- .../rapid_diffs/app_component.html.haml | 2 +- app/components/rapid_diffs/app_component.rb | 2 +- .../rapid_diffs/diff_file_component.rb | 8 +- .../rapid_diffs/diff_file_header_component.rb | 30 +++- .../concerns/rapid_diffs/resource.rb | 6 +- .../rapid_diffs/streaming_resource.rb | 14 +- app/controllers/projects/commit_controller.rb | 7 +- .../projects/compare_controller.rb | 3 +- app/helpers/commits_helper.rb | 2 +- app/presenters/rapid_diffs/base_presenter.rb | 5 +- .../rapid_diffs/commit_presenter.rb | 4 +- locale/gitlab.pot | 3 + .../rapid_diffs/diff_file_component_spec.rb | 22 ++- .../diff_file_header_component_spec.rb | 91 +++++++++++ .../concerns/rapid_diffs/resource_spec.rb | 37 +++++ .../rapid_diffs/streaming_resource_spec.rb | 144 ++++++++++++++++++ spec/features/projects/view_on_env_spec.rb | 69 +++++++-- .../rapid_diffs/base_presenter_spec.rb | 42 +++++ 18 files changed, 459 insertions(+), 32 deletions(-) diff --git a/app/components/rapid_diffs/app_component.html.haml b/app/components/rapid_diffs/app_component.html.haml index 622ceb854db4d8..ff5f84fa98a96b 100644 --- a/app/components/rapid_diffs/app_component.html.haml +++ b/app/components/rapid_diffs/app_component.html.haml @@ -40,7 +40,7 @@ - if diffs_list? = diffs_list - else - = render RapidDiffs::DiffFileComponent.with_collection(diffs_slice, parallel_view: parallel_view?) + = render RapidDiffs::DiffFileComponent.with_collection(diffs_slice, parallel_view: parallel_view?, environment: environment) - if diffs_stream_url %div{ data: { stream_remaining_diffs: true } } - else diff --git a/app/components/rapid_diffs/app_component.rb b/app/components/rapid_diffs/app_component.rb index 9bf74b59e2132a..3c745bd9af176d 100644 --- a/app/components/rapid_diffs/app_component.rb +++ b/app/components/rapid_diffs/app_component.rb @@ -8,7 +8,7 @@ class AppComponent < ViewComponent::Base attr_reader :presenter delegate :diffs_stream_url, :reload_stream_url, :diffs_stats_endpoint, :diff_files_endpoint, :diff_file_endpoint, - :should_sort_metadata_files?, :diffs_slice, :lazy?, to: :presenter + :should_sort_metadata_files?, :diffs_slice, :lazy?, :environment, to: :presenter delegate :diff_view, :current_user, to: :helpers diff --git a/app/components/rapid_diffs/diff_file_component.rb b/app/components/rapid_diffs/diff_file_component.rb index 6735be9229a6d9..00b7420524f7e3 100644 --- a/app/components/rapid_diffs/diff_file_component.rb +++ b/app/components/rapid_diffs/diff_file_component.rb @@ -7,9 +7,10 @@ class DiffFileComponent < ViewComponent::Base renders_one :header - def initialize(diff_file:, parallel_view: false) + def initialize(diff_file:, parallel_view: false, environment: nil) @diff_file = diff_file @parallel_view = parallel_view + @environment = environment end def id @@ -46,7 +47,10 @@ def viewer_component_instance end def default_header - render RapidDiffs::DiffFileHeaderComponent.new(diff_file: @diff_file) + render RapidDiffs::DiffFileHeaderComponent.new( + diff_file: @diff_file, + environment: @environment + ) end # enables virtual rendering through content-visibility: auto, significantly boosts client performance diff --git a/app/components/rapid_diffs/diff_file_header_component.rb b/app/components/rapid_diffs/diff_file_header_component.rb index 97092301a70bc4..ed95f050b23688 100644 --- a/app/components/rapid_diffs/diff_file_header_component.rb +++ b/app/components/rapid_diffs/diff_file_header_component.rb @@ -5,9 +5,10 @@ class DiffFileHeaderComponent < ViewComponent::Base include ButtonHelper include DiffHelper - def initialize(diff_file:, additional_menu_items: []) + def initialize(diff_file:, additional_menu_items: [], environment: nil) @diff_file = diff_file @additional_menu_items = additional_menu_items + @environment = environment end def file_title_chunks @@ -36,12 +37,13 @@ def copy_path_button end def menu_items - [ + @menu_items ||= [ view_file_menu_item, + view_on_environment_menu_item, *@additional_menu_items ] - .filter_map { |item| item unless item.nil? } - .sort_by { |item| item[:position] || Float::INFINITY } + .compact + .sort_by { |item| item[:position] || Float::INFINITY } end def heading_id @@ -92,5 +94,25 @@ def view_file_menu_item position: 1 } end + + def view_on_environment_menu_item + return unless @environment + + file_path = @diff_file.new_path || @diff_file.old_path + commit_sha = @diff_file.content_sha + + environment_path = @environment.external_url_for(file_path, commit_sha) + return unless environment_path + + { + text: helpers.safe_format( + s_('RapidDiffs|View on %{environment}'), + environment: @environment.formatted_external_url + ), + href: environment_path, + extraAttrs: { target: '_blank', rel: 'noopener noreferrer' }, + position: 2 + } + end end end diff --git a/app/controllers/concerns/rapid_diffs/resource.rb b/app/controllers/concerns/rapid_diffs/resource.rb index afa0accfa219d1..4430146c46092e 100644 --- a/app/controllers/concerns/rapid_diffs/resource.rb +++ b/app/controllers/concerns/rapid_diffs/resource.rb @@ -53,8 +53,12 @@ def diffs_resource(options = {}) raise NotImplementedError end + def environment + @environment + end + def diff_file_component(base_args) - ::RapidDiffs::DiffFileComponent.new(**base_args) + ::RapidDiffs::DiffFileComponent.new(**base_args, environment: environment) end def find_diff_file(extra_options, old_path, new_path) diff --git a/app/controllers/concerns/rapid_diffs/streaming_resource.rb b/app/controllers/concerns/rapid_diffs/streaming_resource.rb index cfc4f0545124aa..8abd471a3f237f 100644 --- a/app/controllers/concerns/rapid_diffs/streaming_resource.rb +++ b/app/controllers/concerns/rapid_diffs/streaming_resource.rb @@ -85,12 +85,22 @@ def stream_diff_collection(options, view_context) response.stream.write(diff_files_collection(skipped).render_in(view_context)) unless skipped.empty? end + def environment + @environment + end + def diff_file_component(diff_file) - ::RapidDiffs::DiffFileComponent.new(diff_file: diff_file, parallel_view: view == :parallel) + ::RapidDiffs::DiffFileComponent.new( + diff_file: diff_file, + parallel_view: view == :parallel, + environment: environment) end def diff_files_collection(diff_files) - ::RapidDiffs::DiffFileComponent.with_collection(diff_files, parallel_view: view == :parallel) + ::RapidDiffs::DiffFileComponent.with_collection( + diff_files, + parallel_view: view == :parallel, + environment: environment) end def stream_diff_blobs(options, view_context) diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb index 84d52244b2ff63..9cfa9dafe86cc1 100644 --- a/app/controllers/projects/commit_controller.rb +++ b/app/controllers/projects/commit_controller.rb @@ -16,7 +16,9 @@ class Projects::CommitController < Projects::ApplicationController before_action :authorize_read_code! before_action :authorize_read_pipeline!, only: [:pipelines] before_action :commit - before_action :define_commit_vars, only: [:show, :diff_for_path, :diff_files, :pipelines, :merge_requests] + before_action :define_commit_vars, only: [ + :show, :diff_for_path, :diff_files, :pipelines, :merge_requests, :rapid_diffs + ] before_action :define_commit_box_vars, only: [:show, :pipelines, :rapid_diffs] before_action :define_note_vars, only: [:show, :diff_for_path, :diff_files, :discussions] before_action :authorize_edit_tree!, only: [:revert, :cherry_pick] @@ -172,7 +174,8 @@ def rapid_diffs diff_view, commit_diff_options, nil, - current_user + current_user, + @environment ) show diff --git a/app/controllers/projects/compare_controller.rb b/app/controllers/projects/compare_controller.rb index 289844bbb5147e..4f601cd466d210 100644 --- a/app/controllers/projects/compare_controller.rb +++ b/app/controllers/projects/compare_controller.rb @@ -42,7 +42,8 @@ def show compare, diff_view, diff_options, - compare_params + compare_params, + @environment ) return render action: :rapid_diffs end diff --git a/app/helpers/commits_helper.rb b/app/helpers/commits_helper.rb index 43695d948ff26b..692df57cb20138 100644 --- a/app/helpers/commits_helper.rb +++ b/app/helpers/commits_helper.rb @@ -279,7 +279,7 @@ def view_on_environment_button(commit_sha, diff_new_path, environment) button_options: { rel: 'noopener noreferrer', title: "View on #{environment.formatted_external_url}", - class: 'has-tooltip', + class: 'has-tooltip gl-ml-3', data: { container: 'body' } } ) diff --git a/app/presenters/rapid_diffs/base_presenter.rb b/app/presenters/rapid_diffs/base_presenter.rb index e41a63fb02bf31..7dc6fc6a82ecc6 100644 --- a/app/presenters/rapid_diffs/base_presenter.rb +++ b/app/presenters/rapid_diffs/base_presenter.rb @@ -2,13 +2,16 @@ module RapidDiffs class BasePresenter < Gitlab::View::Presenter::Delegated - def initialize(subject, diff_view, diff_options, request_params = nil) + def initialize(subject, diff_view, diff_options, request_params = nil, environment = nil) super(subject) @diff_view = diff_view @diff_options = diff_options @request_params = request_params + @environment = environment end + attr_reader :environment + def diffs_stream_url return reload_stream_url(diff_view: @diff_view) if offset == 0 return if offset.nil? || offset >= diffs_count diff --git a/app/presenters/rapid_diffs/commit_presenter.rb b/app/presenters/rapid_diffs/commit_presenter.rb index 24fef6988dd945..ec9be55bd768e2 100644 --- a/app/presenters/rapid_diffs/commit_presenter.rb +++ b/app/presenters/rapid_diffs/commit_presenter.rb @@ -6,8 +6,8 @@ class CommitPresenter < BasePresenter presents ::Commit, as: :resource - def initialize(subject, diff_view, diff_options, request_params = nil, current_user = nil) - super(subject, diff_view, diff_options, request_params) + def initialize(subject, diff_view, diff_options, request_params = nil, current_user = nil, environment = nil) + super(subject, diff_view, diff_options, request_params, environment) @current_user = current_user end diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 9053489adbb0e4..e19356f41f80fb 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -54707,6 +54707,9 @@ msgstr "" msgid "RapidDiffs|View file at %{codeStart}%{commit}%{codeEnd}" msgstr "" +msgid "RapidDiffs|View on %{environment}" +msgstr "" + msgid "Rate Limits" msgstr "" diff --git a/spec/components/rapid_diffs/diff_file_component_spec.rb b/spec/components/rapid_diffs/diff_file_component_spec.rb index e693c821bfe346..655383e49276de 100644 --- a/spec/components/rapid_diffs/diff_file_component_spec.rb +++ b/spec/components/rapid_diffs/diff_file_component_spec.rb @@ -13,7 +13,8 @@ it 'renders the default header when no custom header is provided' do allow_next_instance_of( RapidDiffs::DiffFileHeaderComponent, - diff_file: diff_file + diff_file: diff_file, + environment: nil ) do |instance| allow(instance).to receive(:render_in).and_return('diff-file-header') end @@ -32,6 +33,25 @@ expect(result.css('.custom-header').text).to eq('Custom Header') end + + context 'with environment' do + let_it_be(:project) { build_stubbed(:project, :repository) } + let_it_be(:environment) { build_stubbed(:environment, project: project) } + + it 'renders the default header with environment when no custom header is provided' do + allow_next_instance_of( + RapidDiffs::DiffFileHeaderComponent, + diff_file: diff_file, + environment: environment + ) do |instance| + allow(instance).to receive(:render_in).and_return('diff-file-header-with-env') + end + + result = render_component(environment: environment) + + expect(result.to_html).to include('diff-file-header-with-env') + end + end end def render_component(**args, &block) diff --git a/spec/components/rapid_diffs/diff_file_header_component_spec.rb b/spec/components/rapid_diffs/diff_file_header_component_spec.rb index 0491f88a77fde3..fa166a5b885c39 100644 --- a/spec/components/rapid_diffs/diff_file_header_component_spec.rb +++ b/spec/components/rapid_diffs/diff_file_header_component_spec.rb @@ -190,6 +190,97 @@ expect(item).not_to have_key('position') end end + + context 'with environment' do + let(:project) { diff_file.repository.project } + let(:environment) { build(:environment, project: project, external_url: 'https://test.example.com') } + let(:environment_path) { "https://test.example.com/#{diff_file.new_path}" } + + before do + allow(environment).to receive(:formatted_external_url).and_return('test.example.com') + allow(environment).to receive(:external_url_for) + .with(diff_file.new_path, content_sha) + .and_return(environment_path) + end + + it 'renders "View on environment" menu item' do + render_component(environment: environment) + + options_menu_items = Gitlab::Json.parse(page.find('script', visible: false).text) + + view_on_env_item = options_menu_items.find { |item| item['text']&.include?('View on') } + + expect(view_on_env_item).not_to be_nil + expect(view_on_env_item['text']).to include('test.example.com') + expect(view_on_env_item['href']).to eq(environment_path) + expect(view_on_env_item['extraAttrs']['target']).to eq('_blank') + expect(view_on_env_item['extraAttrs']['rel']).to eq('noopener noreferrer') + end + + it 'uses correct file path and SHA when calling external_url_for' do + expect(environment).to receive(:external_url_for) + .with(diff_file.new_path, content_sha) + .and_return(environment_path) + + render_component(environment: environment) + end + + context 'when file is renamed' do + before do + allow(diff_file).to receive(:new_path).and_return('new/file/path.rb') + allow(diff_file).to receive(:old_path).and_return('old/file/path.rb') + end + + it 'uses new_path for environment URL generation' do + expect(environment).to receive(:external_url_for) + .with(diff_file.new_path, content_sha) + .once + .and_return(environment_path) + + render_component(environment: environment) + end + end + + context 'when environment has no route map for the file' do + before do + allow(environment).to receive(:external_url_for) + .with(diff_file.new_path, content_sha) + .and_return(nil) + end + + it 'does not render "View on environment" menu item' do + render_component(environment: environment) + + options_menu_items = Gitlab::Json.parse(page.find('script', visible: false).text) + + view_on_env_item = options_menu_items.find { |item| item['text']&.include?('View on') } + + expect(view_on_env_item).to be_nil + end + end + end + + context 'without environment' do + it 'does not render "View on environment" menu item when environment is nil' do + render_component(environment: nil) + + options_menu_items = Gitlab::Json.parse(page.find('script', visible: false).text) + + view_on_env_item = options_menu_items.find { |item| item['text']&.include?('View on') } + + expect(view_on_env_item).to be_nil + end + + it 'does not render "View on environment" menu item when environment is not provided' do + render_component + + options_menu_items = Gitlab::Json.parse(page.find('script', visible: false).text) + + view_on_env_item = options_menu_items.find { |item| item['text']&.include?('View on') } + + expect(view_on_env_item).to be_nil + end + end end def create_instance(**args) diff --git a/spec/controllers/concerns/rapid_diffs/resource_spec.rb b/spec/controllers/concerns/rapid_diffs/resource_spec.rb index 0b025499769518..e49bb100a332f7 100644 --- a/spec/controllers/concerns/rapid_diffs/resource_spec.rb +++ b/spec/controllers/concerns/rapid_diffs/resource_spec.rb @@ -67,6 +67,27 @@ def with_custom_diff_options controller.new.call_diff_file_component(args) end + + context 'when environment is nil' do + let(:environment) { nil } + + it 'creates a DiffFileComponent with nil environment' do + expect(::RapidDiffs::DiffFileComponent).to receive(:new) + .with(**base_args, environment: nil) + + controller.diff_file_component(base_args) + end + + it 'passes through all base_args to the component' do + additional_args = { parallel_view: true, some_option: 'value' } + full_args = base_args.merge(additional_args) + + expect(::RapidDiffs::DiffFileComponent).to receive(:new) + .with(**full_args, environment: environment) + + controller.diff_file_component(full_args) + end + end end describe '#find_diff_file' do @@ -88,4 +109,20 @@ def with_custom_diff_options expect(controller_instance.call_find_diff_file(extra_options, old_path, new_path)).to eq(diff_file) end end + + describe '#environment' do + context 'when environment is set' do + it 'returns the environment' do + expect(controller.environment).to eq(environment) + end + end + + context 'when environment is not set' do + let(:environment) { nil } + + it 'returns nil' do + expect(controller.environment).to be_nil + end + end + end end diff --git a/spec/controllers/concerns/rapid_diffs/streaming_resource_spec.rb b/spec/controllers/concerns/rapid_diffs/streaming_resource_spec.rb index f1db1e84dcee1b..38cf553a5d0d20 100644 --- a/spec/controllers/concerns/rapid_diffs/streaming_resource_spec.rb +++ b/spec/controllers/concerns/rapid_diffs/streaming_resource_spec.rb @@ -49,6 +49,150 @@ def diff_options end end + describe '#environment' do + let(:controller_instance) { controller.new } + + context 'when environment is set' do + let(:environment) { build(:environment) } + + before do + controller_instance.instance_variable_set(:@environment, environment) + end + + it 'returns the environment' do + expect(controller_instance.send(:environment)).to eq(environment) + end + end + + context 'when environment is not set' do + it 'returns nil' do + expect(controller_instance.send(:environment)).to be_nil + end + end + end + + describe '#diff_file_component' do + let(:controller_instance) { controller.new } + let(:diff_file) { build(:diff_file) } + + before do + allow(controller_instance).to receive_message_chain(:helpers, :diff_view).and_return(:inline) + end + + context 'when environment is nil' do + it 'creates a DiffFileComponent with nil environment' do + expect(::RapidDiffs::DiffFileComponent).to receive(:new) + .with( + diff_file: diff_file, + parallel_view: false, + environment: nil + ) + + controller_instance.send(:diff_file_component, diff_file) + end + end + + context 'when environment is set' do + let(:environment) { build(:environment) } + + before do + controller_instance.instance_variable_set(:@environment, environment) + end + + it 'creates a DiffFileComponent with the environment' do + expect(::RapidDiffs::DiffFileComponent).to receive(:new) + .with( + diff_file: diff_file, + parallel_view: false, + environment: environment + ) + + controller_instance.send(:diff_file_component, diff_file) + end + end + + context 'when view is parallel' do + let(:environment) { build(:environment) } + + before do + allow(controller_instance).to receive_message_chain(:helpers, :diff_view).and_return(:parallel) + controller_instance.instance_variable_set(:@environment, environment) + end + + it 'creates a DiffFileComponent with parallel_view: true' do + expect(::RapidDiffs::DiffFileComponent).to receive(:new) + .with( + diff_file: diff_file, + parallel_view: true, + environment: environment + ) + + controller_instance.send(:diff_file_component, diff_file) + end + end + end + + describe '#diff_files_collection' do + let(:controller_instance) { controller.new } + let(:diff_files) { [build(:diff_file), build(:diff_file)] } + + before do + allow(controller_instance).to receive_message_chain(:helpers, :diff_view).and_return(:inline) + end + + context 'when environment is nil' do + it 'creates a DiffFileComponent collection with nil environment' do + expect(::RapidDiffs::DiffFileComponent).to receive(:with_collection) + .with( + diff_files, + parallel_view: false, + environment: nil + ) + + controller_instance.send(:diff_files_collection, diff_files) + end + end + + context 'when environment is set' do + let(:environment) { build(:environment) } + + before do + controller_instance.instance_variable_set(:@environment, environment) + end + + it 'creates a DiffFileComponent collection with the environment' do + expect(::RapidDiffs::DiffFileComponent).to receive(:with_collection) + .with( + diff_files, + parallel_view: false, + environment: environment + ) + + controller_instance.send(:diff_files_collection, diff_files) + end + end + + context 'when view is parallel' do + let(:environment) { build(:environment) } + + before do + allow(controller_instance).to receive_message_chain(:helpers, :diff_view).and_return(:parallel) + controller_instance.instance_variable_set(:@environment, environment) + end + + it 'creates a DiffFileComponent collection with parallel_view: true' do + expect(::RapidDiffs::DiffFileComponent).to receive(:with_collection) + .with( + diff_files, + parallel_view: true, + environment: environment + ) + + controller_instance.send(:diff_files_collection, diff_files) + end + end + end + describe '#diffs' do let(:controller_instance) { controller.new } let(:mock_resource) { instance_double(::Commit) } diff --git a/spec/features/projects/view_on_env_spec.rb b/spec/features/projects/view_on_env_spec.rb index a790a64ee8c5e8..cb262c6e8b9a3c 100644 --- a/spec/features/projects/view_on_env_spec.rb +++ b/spec/features/projects/view_on_env_spec.rb @@ -67,11 +67,11 @@ end end - context 'when visiting a comparison for the commit' do + context 'when visiting the commit' do before do sign_in(user) - visit project_compare_path(project, from: 'master', to: sha) + visit project_commit_path(project, sha) wait_for_requests end @@ -82,26 +82,68 @@ end end - context 'when visiting a blob on the branch' do + context 'with rapid diffs' do before do - sign_in(user) + stub_feature_flags(rapid_diffs_on_compare_show: true) + end - visit project_blob_path(project, File.join(branch_name, file_path)) + context 'when visiting a comparison for the branch' do + before do + sign_in(user) - wait_for_requests + visit project_compare_path(project, from: 'master', to: branch_name) + + wait_for_requests + end + + it 'has a "View on env" button in the file header menu' do + diff_file = all_by_testid('rd-diff-file').find do |file| + file.has_text?(file_path) + end + diff_file.find('button[data-click="toggleOptionsMenu"]').click + + expect(page).to have_link( + 'View on feature.review.example.com', + href: 'http://feature.review.example.com/ruby/feature' + ) + end end - it 'has a "View on env" button' do - click_button 'File actions' - expect(page).to have_link('View on feature.review.example.com', href: 'http://feature.review.example.com/ruby/feature') + context 'when visiting the commit' do + before do + sign_in(user) + + visit project_commit_path(project, sha, rapid_diffs: true) + + wait_for_requests + end + + it 'has a "View on env" button' do + first_file = find_by_testid('rd-diff-file') + first_file.find('button[data-click="toggleOptionsMenu"]').click + + expect(page).to have_link( + 'View on feature.review.example.com', + href: 'http://feature.review.example.com/ruby/feature' + ) + end + + it 'opens the environment URL in a new tab' do + first_file = find_by_testid('rd-diff-file') + first_file.find('button[data-click="toggleOptionsMenu"]').click + + link = page.find_link('View on feature.review.example.com') + expect(link[:target]).to eq('_blank') + expect(link[:rel]).to include('noopener') + end end end - context 'when visiting a blob on the commit' do + context 'when visiting a blob on the branch' do before do sign_in(user) - visit project_blob_path(project, File.join(sha, file_path)) + visit project_blob_path(project, File.join(branch_name, file_path)) wait_for_requests end @@ -112,16 +154,17 @@ end end - context 'when visiting the commit' do + context 'when visiting a blob on the commit' do before do sign_in(user) - visit project_commit_path(project, sha) + visit project_blob_path(project, File.join(sha, file_path)) wait_for_requests end it 'has a "View on env" button' do + click_button 'File actions' expect(page).to have_link('View on feature.review.example.com', href: 'http://feature.review.example.com/ruby/feature') end end diff --git a/spec/presenters/rapid_diffs/base_presenter_spec.rb b/spec/presenters/rapid_diffs/base_presenter_spec.rb index 2b0fc202fa44bf..0a8c02b6026671 100644 --- a/spec/presenters/rapid_diffs/base_presenter_spec.rb +++ b/spec/presenters/rapid_diffs/base_presenter_spec.rb @@ -5,6 +5,48 @@ RSpec.describe RapidDiffs::BasePresenter, feature_category: :source_code_management do subject(:presenter) { described_class.new(Class.new, :inline, {}) } + describe '#initialize' do + context 'when environment is provided' do + let(:environment) { build(:environment) } + let(:presenter_with_env) { described_class.new(Class.new, :inline, {}, nil, environment) } + + it 'sets the environment' do + expect(presenter_with_env.environment).to eq(environment) + end + end + + context 'when environment is not provided' do + it 'sets environment to nil' do + expect(presenter.environment).to be_nil + end + end + + context 'when environment is explicitly nil' do + let(:presenter_with_nil_env) { described_class.new(Class.new, :inline, {}, nil, nil) } + + it 'sets environment to nil' do + expect(presenter_with_nil_env.environment).to be_nil + end + end + end + + describe '#environment' do + context 'when environment is set' do + let(:environment) { build(:environment) } + let(:presenter_with_env) { described_class.new(Class.new, :inline, {}, nil, environment) } + + it 'returns the environment' do + expect(presenter_with_env.environment).to eq(environment) + end + end + + context 'when environment is not set' do + it 'returns nil' do + expect(presenter.environment).to be_nil + end + end + end + describe 'abstract methods' do it 'raises a NotImplementedError for #diffs_stats_endpoint' do expect { presenter.diffs_stats_endpoint }.to raise_error(NotImplementedError) -- GitLab From 80763b7e698dc22c79296cfd36e65228f99b421c Mon Sep 17 00:00:00 2001 From: Chaoyue Zhao Date: Wed, 12 Nov 2025 23:23:21 -0500 Subject: [PATCH 2/8] Fix view environment in compare page --- app/controllers/projects/compare_diffs_stream_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/projects/compare_diffs_stream_controller.rb b/app/controllers/projects/compare_diffs_stream_controller.rb index f73e9b91c5059f..ccfa120ebcfe27 100644 --- a/app/controllers/projects/compare_diffs_stream_controller.rb +++ b/app/controllers/projects/compare_diffs_stream_controller.rb @@ -4,6 +4,8 @@ module Projects class CompareDiffsStreamController < Projects::CompareController include RapidDiffs::StreamingResource + before_action :define_environment + private def resource -- GitLab From c06f0ca3e8b5fd6fc91891fcae68c76ae566309c Mon Sep 17 00:00:00 2001 From: Chaoyue Zhao Date: Thu, 13 Nov 2025 15:47:56 -0500 Subject: [PATCH 3/8] Fix test failures # Conflicts: # spec/components/rapid_diffs/commit_app_component_spec.rb --- .../rapid_diffs/app_component_spec.rb | 1 + .../rapid_diffs/commit_app_component_spec.rb | 4 ++- .../concerns/rapid_diffs/resource_spec.rb | 33 ++++++++++--------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/spec/components/rapid_diffs/app_component_spec.rb b/spec/components/rapid_diffs/app_component_spec.rb index 354296e7f53f5b..5607b8a9b8cca8 100644 --- a/spec/components/rapid_diffs/app_component_spec.rb +++ b/spec/components/rapid_diffs/app_component_spec.rb @@ -27,6 +27,7 @@ diff_files_endpoint: diff_files_endpoint, diff_file_endpoint: diff_file_endpoint, should_sort_metadata_files?: should_sort_metadata_files, + environment: nil, lazy?: lazy ) end diff --git a/spec/components/rapid_diffs/commit_app_component_spec.rb b/spec/components/rapid_diffs/commit_app_component_spec.rb index 969298d6d35028..589897997ba1a1 100644 --- a/spec/components/rapid_diffs/commit_app_component_spec.rb +++ b/spec/components/rapid_diffs/commit_app_component_spec.rb @@ -23,7 +23,9 @@ register_path: register_path, sign_in_path: sign_in_path, report_abuse_path: report_abuse_path, - markdown_docs_path: markdown_docs_path + markdown_docs_path: markdown_docs_path, + environment: nil, + lazy?: lazy ) end diff --git a/spec/controllers/concerns/rapid_diffs/resource_spec.rb b/spec/controllers/concerns/rapid_diffs/resource_spec.rb index e49bb100a332f7..023226e966f2e8 100644 --- a/spec/controllers/concerns/rapid_diffs/resource_spec.rb +++ b/spec/controllers/concerns/rapid_diffs/resource_spec.rb @@ -61,31 +61,32 @@ def with_custom_diff_options describe '#diff_file_component' do it 'initializes a DiffFileComponent with the given arguments' do - args = { parallel_view: :parallel } + args = { diff_file: instance_double(Gitlab::Git::Diff), parallel_view: :parallel } - expect(RapidDiffs::DiffFileComponent).to receive(:new).with(**args) + expect(RapidDiffs::DiffFileComponent).to receive(:new).with(**args, environment: nil) controller.new.call_diff_file_component(args) end context 'when environment is nil' do - let(:environment) { nil } - it 'creates a DiffFileComponent with nil environment' do + base_args = { diff_file: instance_double(Gitlab::Git::Diff) } + expect(::RapidDiffs::DiffFileComponent).to receive(:new) .with(**base_args, environment: nil) - controller.diff_file_component(base_args) + controller.new.call_diff_file_component(base_args) end it 'passes through all base_args to the component' do + base_args = { diff_file: instance_double(Gitlab::Git::Diff) } additional_args = { parallel_view: true, some_option: 'value' } full_args = base_args.merge(additional_args) expect(::RapidDiffs::DiffFileComponent).to receive(:new) - .with(**full_args, environment: environment) + .with(**full_args, environment: nil) - controller.diff_file_component(full_args) + controller.new.call_diff_file_component(full_args) end end end @@ -111,17 +112,19 @@ def with_custom_diff_options end describe '#environment' do - context 'when environment is set' do - it 'returns the environment' do - expect(controller.environment).to eq(environment) - end + it 'returns nil by default' do + controller_instance = controller.new + + expect(controller_instance.send(:environment)).to be_nil end - context 'when environment is not set' do - let(:environment) { nil } + context 'when environment instance variable is set' do + it 'returns the environment' do + controller_instance = controller.new + environment = instance_double(Environment) + controller_instance.instance_variable_set(:@environment, environment) - it 'returns nil' do - expect(controller.environment).to be_nil + expect(controller_instance.send(:environment)).to eq(environment) end end end -- GitLab From f3fbad6b3be82fbbedbca07120b02e56c72f2ee2 Mon Sep 17 00:00:00 2001 From: Chaoyue Zhao Date: Mon, 24 Nov 2025 15:27:12 -0500 Subject: [PATCH 4/8] Address test comments --- .../rapid_diffs/diff_file_header_component.rb | 2 +- .../diff_file_header_component_spec.rb | 19 +++----- .../concerns/rapid_diffs/resource_spec.rb | 11 ----- spec/features/projects/view_on_env_spec.rb | 38 ++++++---------- .../rapid_diffs/base_presenter_spec.rb | 44 ++++--------------- 5 files changed, 29 insertions(+), 85 deletions(-) diff --git a/app/components/rapid_diffs/diff_file_header_component.rb b/app/components/rapid_diffs/diff_file_header_component.rb index ed95f050b23688..4406e3da777f8e 100644 --- a/app/components/rapid_diffs/diff_file_header_component.rb +++ b/app/components/rapid_diffs/diff_file_header_component.rb @@ -37,7 +37,7 @@ def copy_path_button end def menu_items - @menu_items ||= [ + [ view_file_menu_item, view_on_environment_menu_item, *@additional_menu_items diff --git a/spec/components/rapid_diffs/diff_file_header_component_spec.rb b/spec/components/rapid_diffs/diff_file_header_component_spec.rb index fa166a5b885c39..a1fbc4e6ad1647 100644 --- a/spec/components/rapid_diffs/diff_file_header_component_spec.rb +++ b/spec/components/rapid_diffs/diff_file_header_component_spec.rb @@ -217,27 +217,20 @@ expect(view_on_env_item['extraAttrs']['rel']).to eq('noopener noreferrer') end - it 'uses correct file path and SHA when calling external_url_for' do - expect(environment).to receive(:external_url_for) - .with(diff_file.new_path, content_sha) - .and_return(environment_path) - - render_component(environment: environment) - end - context 'when file is renamed' do before do allow(diff_file).to receive(:new_path).and_return('new/file/path.rb') allow(diff_file).to receive(:old_path).and_return('old/file/path.rb') + allow(environment).to receive(:external_url_for) do |path, _sha| + path == diff_file.new_path ? environment_path : nil + end end it 'uses new_path for environment URL generation' do - expect(environment).to receive(:external_url_for) - .with(diff_file.new_path, content_sha) - .once - .and_return(environment_path) - render_component(environment: environment) + + expect(page).to have_content('View on test.example.com') + expect(page).to have_content(environment_path) end end diff --git a/spec/controllers/concerns/rapid_diffs/resource_spec.rb b/spec/controllers/concerns/rapid_diffs/resource_spec.rb index 023226e966f2e8..775d0d8a587b6b 100644 --- a/spec/controllers/concerns/rapid_diffs/resource_spec.rb +++ b/spec/controllers/concerns/rapid_diffs/resource_spec.rb @@ -77,17 +77,6 @@ def with_custom_diff_options controller.new.call_diff_file_component(base_args) end - - it 'passes through all base_args to the component' do - base_args = { diff_file: instance_double(Gitlab::Git::Diff) } - additional_args = { parallel_view: true, some_option: 'value' } - full_args = base_args.merge(additional_args) - - expect(::RapidDiffs::DiffFileComponent).to receive(:new) - .with(**full_args, environment: nil) - - controller.new.call_diff_file_component(full_args) - end end end diff --git a/spec/features/projects/view_on_env_spec.rb b/spec/features/projects/view_on_env_spec.rb index cb262c6e8b9a3c..0064b9052dcf13 100644 --- a/spec/features/projects/view_on_env_spec.rb +++ b/spec/features/projects/view_on_env_spec.rb @@ -51,31 +51,19 @@ context 'with legacy diffs' do before do stub_feature_flags(rapid_diffs_on_compare_show: false) + sign_in(user) + visit page_path + wait_for_requests end - context 'when visiting a comparison for the branch' do - before do - sign_in(user) - - visit project_compare_path(project, from: 'master', to: branch_name) - - wait_for_requests - 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 + where(:page_path) do + [ + lazy { project_compare_path(project, from: 'master', to: branch_name) }, + lazy { project_commit_path(project, sha) } + ] end - context 'when visiting the commit' do - before do - sign_in(user) - - visit project_commit_path(project, sha) - - wait_for_requests - end - + with_them do 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 @@ -100,7 +88,7 @@ diff_file = all_by_testid('rd-diff-file').find do |file| file.has_text?(file_path) end - diff_file.find('button[data-click="toggleOptionsMenu"]').click + diff_file.find('button:has([data-testid="ellipsis_v-icon"])').click expect(page).to have_link( 'View on feature.review.example.com', @@ -118,9 +106,9 @@ wait_for_requests end - it 'has a "View on env" button' do + it 'has a "View on env" button in the file header menu' do first_file = find_by_testid('rd-diff-file') - first_file.find('button[data-click="toggleOptionsMenu"]').click + first_file.find('button:has([data-testid="ellipsis_v-icon"])').click expect(page).to have_link( 'View on feature.review.example.com', @@ -130,7 +118,7 @@ it 'opens the environment URL in a new tab' do first_file = find_by_testid('rd-diff-file') - first_file.find('button[data-click="toggleOptionsMenu"]').click + first_file.find('button:has([data-testid="ellipsis_v-icon"])').click link = page.find_link('View on feature.review.example.com') expect(link[:target]).to eq('_blank') diff --git a/spec/presenters/rapid_diffs/base_presenter_spec.rb b/spec/presenters/rapid_diffs/base_presenter_spec.rb index 0a8c02b6026671..604e4a84e4bfcd 100644 --- a/spec/presenters/rapid_diffs/base_presenter_spec.rb +++ b/spec/presenters/rapid_diffs/base_presenter_spec.rb @@ -3,47 +3,21 @@ require 'spec_helper' RSpec.describe RapidDiffs::BasePresenter, feature_category: :source_code_management do - subject(:presenter) { described_class.new(Class.new, :inline, {}) } + let(:diff_view) { :inline } + let(:diff_options) { {} } + let(:environment) { nil } - describe '#initialize' do - context 'when environment is provided' do - let(:environment) { build(:environment) } - let(:presenter_with_env) { described_class.new(Class.new, :inline, {}, nil, environment) } - - it 'sets the environment' do - expect(presenter_with_env.environment).to eq(environment) - end - end + subject(:presenter) { described_class.new(Class.new, diff_view, diff_options, nil, environment) } - context 'when environment is not provided' do - it 'sets environment to nil' do - expect(presenter.environment).to be_nil - end - end + describe '#environment' do + subject(:method) { presenter.environment } - context 'when environment is explicitly nil' do - let(:presenter_with_nil_env) { described_class.new(Class.new, :inline, {}, nil, nil) } + it { is_expected.to be_nil } - it 'sets environment to nil' do - expect(presenter_with_nil_env.environment).to be_nil - end - end - end - - describe '#environment' do - context 'when environment is set' do + context 'when environment is provided' do let(:environment) { build(:environment) } - let(:presenter_with_env) { described_class.new(Class.new, :inline, {}, nil, environment) } - - it 'returns the environment' do - expect(presenter_with_env.environment).to eq(environment) - end - end - context 'when environment is not set' do - it 'returns nil' do - expect(presenter.environment).to be_nil - end + it { is_expected.to eq(environment) } end end -- GitLab From 34a1b36deb2c4473f938febe64c9f7c0692e5c6d Mon Sep 17 00:00:00 2001 From: Chaoyue Zhao Date: Mon, 24 Nov 2025 15:46:05 -0500 Subject: [PATCH 5/8] Remove `rapid_diffs` from `before_action` --- app/controllers/projects/commit_controller.rb | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb index 9cfa9dafe86cc1..4feeb4d6ab488b 100644 --- a/app/controllers/projects/commit_controller.rb +++ b/app/controllers/projects/commit_controller.rb @@ -16,9 +16,9 @@ class Projects::CommitController < Projects::ApplicationController before_action :authorize_read_code! before_action :authorize_read_pipeline!, only: [:pipelines] before_action :commit - before_action :define_commit_vars, only: [ - :show, :diff_for_path, :diff_files, :pipelines, :merge_requests, :rapid_diffs - ] + before_action :define_commit_vars, only: [:show, :diff_for_path, :diff_files, :pipelines, :merge_requests] + before_action :define_environment, + only: [:show, :rapid_diffs, :diff_for_path, :diff_files, :pipelines, :merge_requests] before_action :define_commit_box_vars, only: [:show, :pipelines, :rapid_diffs] before_action :define_note_vars, only: [:show, :diff_for_path, :diff_files, :discussions] before_action :authorize_edit_tree!, only: [:revert, :cherry_pick] @@ -165,6 +165,15 @@ def cherry_pick ) end + def define_environment + @environment ||= ::Environments::EnvironmentsByDeploymentsFinder.new( + @project, + current_user, + commit: @commit, + find_latest: true + ).execute.last + end + def rapid_diffs return render_404 unless ::Feature.enabled?(:rapid_diffs_on_commit_show, current_user, type: :wip) @@ -175,7 +184,7 @@ def rapid_diffs commit_diff_options, nil, current_user, - @environment + define_environment ) show @@ -227,12 +236,6 @@ def define_commit_vars return git_not_found! unless commit @diffs = commit.diffs(commit_diff_options) - @environment = ::Environments::EnvironmentsByDeploymentsFinder.new( - @project, - current_user, - commit: @commit, - find_latest: true - ).execute.last end # rubocop: disable CodeReuse/ActiveRecord -- GitLab From d590ecd19882c1b4d3abf7ab4e5c2da7a8128bc2 Mon Sep 17 00:00:00 2001 From: Chaoyue Zhao Date: Fri, 28 Nov 2025 11:36:26 -0500 Subject: [PATCH 6/8] Address Gavin's comments - Add `:define_environment` to `CommitDiffsStreamController` - Add request tests for `CommitDiffsStreamController` and `CompareDiffsStreamController` --- .../commit_diffs_stream_controller.rb | 2 + .../diff_file_header_component_spec.rb | 10 ----- .../commit_diffs_stream_controller_spec.rb | 42 +++++++++++++++++++ .../compare_diffs_stream_controller_spec.rb | 38 +++++++++++++++++ 4 files changed, 82 insertions(+), 10 deletions(-) diff --git a/app/controllers/projects/commit_diffs_stream_controller.rb b/app/controllers/projects/commit_diffs_stream_controller.rb index 387511885a3515..7c584150547bdf 100644 --- a/app/controllers/projects/commit_diffs_stream_controller.rb +++ b/app/controllers/projects/commit_diffs_stream_controller.rb @@ -4,6 +4,8 @@ module Projects class CommitDiffsStreamController < Projects::CommitController include RapidDiffs::StreamingResource + before_action :define_environment + private def resource diff --git a/spec/components/rapid_diffs/diff_file_header_component_spec.rb b/spec/components/rapid_diffs/diff_file_header_component_spec.rb index a1fbc4e6ad1647..1c07e2309feefa 100644 --- a/spec/components/rapid_diffs/diff_file_header_component_spec.rb +++ b/spec/components/rapid_diffs/diff_file_header_component_spec.rb @@ -263,16 +263,6 @@ expect(view_on_env_item).to be_nil end - - it 'does not render "View on environment" menu item when environment is not provided' do - render_component - - options_menu_items = Gitlab::Json.parse(page.find('script', visible: false).text) - - view_on_env_item = options_menu_items.find { |item| item['text']&.include?('View on') } - - expect(view_on_env_item).to be_nil - end end end diff --git a/spec/requests/projects/commit_diffs_stream_controller_spec.rb b/spec/requests/projects/commit_diffs_stream_controller_spec.rb index e636f7b34b9d80..79a561c3abd5f2 100644 --- a/spec/requests/projects/commit_diffs_stream_controller_spec.rb +++ b/spec/requests/projects/commit_diffs_stream_controller_spec.rb @@ -5,6 +5,7 @@ RSpec.describe 'Commit diffs stream', feature_category: :source_code_management do let_it_be(:project) { create(:project, :public, :repository) } let_it_be(:user) { create(:user, maintainer_of: project) } + let(:commit_with_two_diffs) { project.commit("874797c3a73b60d2187ed6e2fcabd289ff75171e") } let(:offset) { 0 } let(:diff_files) { commit_with_two_diffs.diffs.diff_files } @@ -38,5 +39,46 @@ def go(**extra_params) include_examples 'diffs stream tests' include_examples 'with diffs_blobs param' + + context 'with environment' do + let(:environment) { create(:environment, project: project, external_url: 'https://example.com') } + + before do + create( + :deployment, :success, environment: environment, + project: project, sha: commit_with_two_diffs.sha + ) + + allow_next_instance_of(Environments::EnvironmentsByDeploymentsFinder) do |finder| + allow(finder).to receive(:execute).and_return([environment]) + end + + allow(project).to receive(:public_path_for_source_path).and_return('public/file.html') + end + + it 'includes environment link in response' do + go + + expect(response.body).to include('View on') + expect(response.body).to include(environment.formatted_external_url) + end + end + + context 'without environment' do + before do + create(:deployment, :success, environment: + create(:environment, project: project), project: project, sha: commit_with_two_diffs.sha) + + allow_next_instance_of(Environments::EnvironmentsByDeploymentsFinder) do |finder| + allow(finder).to receive(:execute).and_return([]) + end + end + + it 'does not include environment link in response' do + go + + expect(response.body).not_to include('View on') + end + end end end diff --git a/spec/requests/projects/compare_diffs_stream_controller_spec.rb b/spec/requests/projects/compare_diffs_stream_controller_spec.rb index c12b2e859acd72..a64c4968b814e5 100644 --- a/spec/requests/projects/compare_diffs_stream_controller_spec.rb +++ b/spec/requests/projects/compare_diffs_stream_controller_spec.rb @@ -53,5 +53,43 @@ def go(**extra_params) include_examples 'diffs stream tests' include_examples 'with diffs_blobs param' + + context 'with environment' do + let(:environment) { create(:environment, project: project, external_url: 'https://example.com') } + + before do + create(:deployment, :success, environment: environment, project: project, sha: compare.head_commit_sha) + + allow_next_instance_of(Environments::EnvironmentsByDeploymentsFinder) do |finder| + allow(finder).to receive(:execute).and_return([environment]) + end + + allow(project).to receive(:public_path_for_source_path).and_return('public/file.html') + end + + it 'includes environment link in response' do + go + + expect(response.body).to include('View on') + expect(response.body).to include(environment.formatted_external_url) + end + end + + context 'without environment' do + before do + create(:deployment, :success, environment: create(:environment, project: project), + project: project, sha: compare.head_commit_sha) + + allow_next_instance_of(Environments::EnvironmentsByDeploymentsFinder) do |finder| + allow(finder).to receive(:execute).and_return([]) + end + end + + it 'does not include environment link in response' do + go + + expect(response.body).not_to include('View on') + end + end end end -- GitLab From 778f4ba8a65679575cbfacaa717accdf961497f8 Mon Sep 17 00:00:00 2001 From: Chaoyue Zhao Date: Fri, 28 Nov 2025 11:44:10 -0500 Subject: [PATCH 7/8] Move `define_environment` into private section --- app/controllers/projects/commit_controller.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb index 4feeb4d6ab488b..42b0e94fef767c 100644 --- a/app/controllers/projects/commit_controller.rb +++ b/app/controllers/projects/commit_controller.rb @@ -165,15 +165,6 @@ def cherry_pick ) end - def define_environment - @environment ||= ::Environments::EnvironmentsByDeploymentsFinder.new( - @project, - current_user, - commit: @commit, - find_latest: true - ).execute.last - end - def rapid_diffs return render_404 unless ::Feature.enabled?(:rapid_diffs_on_commit_show, current_user, type: :wip) @@ -324,6 +315,15 @@ def complete_diff_path def email_format_path project_commit_path(project, commit, format: :patch) end + + def define_environment + @environment ||= ::Environments::EnvironmentsByDeploymentsFinder.new( + @project, + current_user, + commit: @commit, + find_latest: true + ).execute.last + end end Projects::CommitController.prepend_mod_with('Projects::CommitController') -- GitLab From 35575d9fd103295fd92d089e028558cabef0250b Mon Sep 17 00:00:00 2001 From: Chaoyue Zhao Date: Mon, 1 Dec 2025 14:12:06 -0500 Subject: [PATCH 8/8] A few more comments!! - Use `attr_reader` - Clean up tests --- app/controllers/concerns/rapid_diffs/resource.rb | 4 +--- .../concerns/rapid_diffs/streaming_resource.rb | 4 +--- app/controllers/projects/compare_controller.rb | 3 +-- .../rapid_diffs/commit_app_component_spec.rb | 3 +-- .../commit_diffs_stream_controller_spec.rb | 16 ---------------- 5 files changed, 4 insertions(+), 26 deletions(-) diff --git a/app/controllers/concerns/rapid_diffs/resource.rb b/app/controllers/concerns/rapid_diffs/resource.rb index 4430146c46092e..f2f6964be8b85c 100644 --- a/app/controllers/concerns/rapid_diffs/resource.rb +++ b/app/controllers/concerns/rapid_diffs/resource.rb @@ -53,9 +53,7 @@ def diffs_resource(options = {}) raise NotImplementedError end - def environment - @environment - end + attr_reader :environment def diff_file_component(base_args) ::RapidDiffs::DiffFileComponent.new(**base_args, environment: environment) diff --git a/app/controllers/concerns/rapid_diffs/streaming_resource.rb b/app/controllers/concerns/rapid_diffs/streaming_resource.rb index 8abd471a3f237f..0f2f059bee9829 100644 --- a/app/controllers/concerns/rapid_diffs/streaming_resource.rb +++ b/app/controllers/concerns/rapid_diffs/streaming_resource.rb @@ -85,9 +85,7 @@ def stream_diff_collection(options, view_context) response.stream.write(diff_files_collection(skipped).render_in(view_context)) unless skipped.empty? end - def environment - @environment - end + attr_reader :environment def diff_file_component(diff_file) ::RapidDiffs::DiffFileComponent.new( diff --git a/app/controllers/projects/compare_controller.rb b/app/controllers/projects/compare_controller.rb index 4f601cd466d210..289844bbb5147e 100644 --- a/app/controllers/projects/compare_controller.rb +++ b/app/controllers/projects/compare_controller.rb @@ -42,8 +42,7 @@ def show compare, diff_view, diff_options, - compare_params, - @environment + compare_params ) return render action: :rapid_diffs end diff --git a/spec/components/rapid_diffs/commit_app_component_spec.rb b/spec/components/rapid_diffs/commit_app_component_spec.rb index 589897997ba1a1..90d4882332171e 100644 --- a/spec/components/rapid_diffs/commit_app_component_spec.rb +++ b/spec/components/rapid_diffs/commit_app_component_spec.rb @@ -24,8 +24,7 @@ sign_in_path: sign_in_path, report_abuse_path: report_abuse_path, markdown_docs_path: markdown_docs_path, - environment: nil, - lazy?: lazy + environment: nil ) end diff --git a/spec/requests/projects/commit_diffs_stream_controller_spec.rb b/spec/requests/projects/commit_diffs_stream_controller_spec.rb index 79a561c3abd5f2..3a505a3a465a08 100644 --- a/spec/requests/projects/commit_diffs_stream_controller_spec.rb +++ b/spec/requests/projects/commit_diffs_stream_controller_spec.rb @@ -5,7 +5,6 @@ RSpec.describe 'Commit diffs stream', feature_category: :source_code_management do let_it_be(:project) { create(:project, :public, :repository) } let_it_be(:user) { create(:user, maintainer_of: project) } - let(:commit_with_two_diffs) { project.commit("874797c3a73b60d2187ed6e2fcabd289ff75171e") } let(:offset) { 0 } let(:diff_files) { commit_with_two_diffs.diffs.diff_files } @@ -44,11 +43,6 @@ def go(**extra_params) let(:environment) { create(:environment, project: project, external_url: 'https://example.com') } before do - create( - :deployment, :success, environment: environment, - project: project, sha: commit_with_two_diffs.sha - ) - allow_next_instance_of(Environments::EnvironmentsByDeploymentsFinder) do |finder| allow(finder).to receive(:execute).and_return([environment]) end @@ -59,21 +53,11 @@ def go(**extra_params) it 'includes environment link in response' do go - expect(response.body).to include('View on') expect(response.body).to include(environment.formatted_external_url) end end context 'without environment' do - before do - create(:deployment, :success, environment: - create(:environment, project: project), project: project, sha: commit_with_two_diffs.sha) - - allow_next_instance_of(Environments::EnvironmentsByDeploymentsFinder) do |finder| - allow(finder).to receive(:execute).and_return([]) - end - end - it 'does not include environment link in response' do go -- GitLab