diff options
Diffstat (limited to 'spec/controllers/concerns')
4 files changed, 92 insertions, 5 deletions
diff --git a/spec/controllers/concerns/issuable_actions_spec.rb b/spec/controllers/concerns/issuable_actions_spec.rb index c3fef591b91..37d9dc080e1 100644 --- a/spec/controllers/concerns/issuable_actions_spec.rb +++ b/spec/controllers/concerns/issuable_actions_spec.rb @@ -6,8 +6,8 @@ RSpec.describe IssuableActions do let(:project) { double('project') } let(:user) { double('user') } let(:issuable) { double('issuable') } - let(:finder_params_for_issuable) { {} } - let(:notes_result) { double('notes_result') } + let(:finder_params_for_issuable) { { project: project, target: issuable } } + let(:notes_result) { [] } let(:discussion_serializer) { double('discussion_serializer') } let(:controller) do @@ -55,13 +55,20 @@ RSpec.describe IssuableActions do end it 'instantiates and calls NotesFinder as expected' do + expect(issuable).to receive(:to_ability_name).and_return('issue') + expect(issuable).to receive(:project).and_return(project) + expect(Ability).to receive(:allowed?).at_least(1).and_return(true) expect(Discussion).to receive(:build_collection).and_return([]) expect(DiscussionSerializer).to receive(:new).and_return(discussion_serializer) expect(NotesFinder).to receive(:new).with(user, finder_params_for_issuable).and_call_original expect_any_instance_of(NotesFinder).to receive(:execute).and_return(notes_result) - expect(notes_result).to receive_messages(inc_relations_for_view: notes_result, includes: notes_result, fresh: notes_result) + expect(notes_result).to receive_messages( + with_web_entity_associations: notes_result, + inc_relations_for_view: notes_result, + fresh: notes_result + ) controller.discussions end diff --git a/spec/controllers/concerns/preferred_language_switcher_spec.rb b/spec/controllers/concerns/preferred_language_switcher_spec.rb new file mode 100644 index 00000000000..40d6ac10c37 --- /dev/null +++ b/spec/controllers/concerns/preferred_language_switcher_spec.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe PreferredLanguageSwitcher, type: :controller do + controller(ActionController::Base) do + include PreferredLanguageSwitcher # rubocop:disable RSpec/DescribedClass + + before_action :init_preferred_language, only: :new + + def new + render html: 'new page' + end + end + + context 'when first visit' do + before do + get :new + end + + it 'sets preferred_language to default' do + expect(cookies[:preferred_language]).to eq Gitlab::CurrentSettings.default_preferred_language + end + end + + context 'when preferred language in cookies has been modified' do + let(:user_preferred_language) { nil } + + before do + cookies[:preferred_language] = user_preferred_language + + get :new + end + + context 'with a valid value' do + let(:user_preferred_language) { 'zh_CN' } + + it 'keeps preferred language unchanged' do + expect(cookies[:preferred_language]).to eq user_preferred_language + end + end + + context 'with an invalid value' do + let(:user_preferred_language) { 'xxx' } + + it 'sets preferred_language to default' do + expect(cookies[:preferred_language]).to eq Gitlab::CurrentSettings.default_preferred_language + end + end + end +end diff --git a/spec/controllers/concerns/renders_commits_spec.rb b/spec/controllers/concerns/renders_commits_spec.rb index acdeb98bb16..6a504681527 100644 --- a/spec/controllers/concerns/renders_commits_spec.rb +++ b/spec/controllers/concerns/renders_commits_spec.rb @@ -43,7 +43,7 @@ RSpec.describe RendersCommits do context 'rendering commits' do render_views - it 'avoids N + 1' do + it 'avoids N + 1', :request_store do stub_const("MergeRequestDiff::COMMITS_SAFE_SIZE", 5) control_count = ActiveRecord::QueryRecorder.new do @@ -59,7 +59,7 @@ RSpec.describe RendersCommits do end describe '.prepare_commits_for_rendering' do - it 'avoids N+1' do + it 'avoids N+1', :request_store do control = ActiveRecord::QueryRecorder.new do subject.prepare_commits_for_rendering(merge_request.commits.take(1)) end diff --git a/spec/controllers/concerns/send_file_upload_spec.rb b/spec/controllers/concerns/send_file_upload_spec.rb index 32304815bbb..0b24387483b 100644 --- a/spec/controllers/concerns/send_file_upload_spec.rb +++ b/spec/controllers/concerns/send_file_upload_spec.rb @@ -18,6 +18,12 @@ RSpec.describe SendFileUpload do end end + let(:cdn_uploader_class) do + Class.new(uploader_class) do + include ObjectStorage::CDN::Concern + end + end + let(:controller_class) do Class.new do include SendFileUpload @@ -269,5 +275,28 @@ RSpec.describe SendFileUpload do it_behaves_like 'handles image resize requests' end + + context 'when CDN-enabled remote file is used' do + let(:uploader) { cdn_uploader_class.new(object, :file) } + let(:request) { instance_double('ActionDispatch::Request', remote_ip: '18.245.0.42') } + let(:signed_url) { 'https://cdn.example.org.test' } + let(:cdn_provider) { instance_double('ObjectStorage::CDN::GoogleCDN', signed_url: signed_url) } + + before do + stub_uploads_object_storage(uploader: cdn_uploader_class) + uploader.object_store = ObjectStorage::Store::REMOTE + uploader.store!(temp_file) + allow(Gitlab.config.uploads.object_store).to receive(:proxy_download) { false } + end + + it 'sends a file when CDN URL' do + expect(uploader).to receive(:use_cdn?).and_return(true) + expect(uploader).to receive(:cdn_provider).and_return(cdn_provider) + expect(controller).to receive(:request).and_return(request) + expect(controller).to receive(:redirect_to).with(signed_url) + + subject + end + end end end |