diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-26 06:07:03 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-26 06:07:03 +0300 |
commit | d7bf02e916cdc8ec926a35ced9cf6ab118e0f5cc (patch) | |
tree | 51ceaeda80a43b34806239834e1fb6c4b9336d22 /spec | |
parent | b8fcf7c3d6c3b48e59e6aae5b1a6b536bba8ac40 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/banzai/filter/issuable_reference_expansion_filter_spec.rb | 42 | ||||
-rw-r--r-- | spec/tooling/danger/model_validations_spec.rb | 106 |
2 files changed, 148 insertions, 0 deletions
diff --git a/spec/lib/banzai/filter/issuable_reference_expansion_filter_spec.rb b/spec/lib/banzai/filter/issuable_reference_expansion_filter_spec.rb index e14b1362687..06bb0edc92c 100644 --- a/spec/lib/banzai/filter/issuable_reference_expansion_filter_spec.rb +++ b/spec/lib/banzai/filter/issuable_reference_expansion_filter_spec.rb @@ -173,6 +173,48 @@ RSpec.describe Banzai::Filter::IssuableReferenceExpansionFilter, feature_categor expect(doc.css('a').last.text).to eq("#{issuable.title} (#{issuable.to_reference} - closed)") end + context 'for references with fenced emoji' do + def issuable_link(issuable) + create_link( + issuable.to_reference, + "#{issuable_type}": issuable.id, + reference_type: issuable_type, + reference_format: '+' + ) + end + + it 'expands emoji for references with +' do + issuable = create_item(issuable_type, :opened, title: 'Some issue :eagle:') + doc = filter(issuable_link(issuable), context) + + expect(/\p{Emoji_Presentation}/ =~ doc.css('a').last.text).not_to be_nil + expect(doc.css('a').last.text.scan(/\p{Emoji_Presentation}/)).to eq(["🦅"]) + end + + it 'expands when emoji is embedded at the beginning of a string' do + issuable = create_item(issuable_type, :opened, title: ':eagle: Some issue') + doc = filter(issuable_link(issuable), context) + + expect(/\p{Emoji_Presentation}/ =~ doc.css('a').last.text).not_to be_nil + expect(doc.css('a').last.text.scan(/\p{Emoji_Presentation}/)).to eq(["🦅"]) + end + + it 'expands when emoji appears multiple times' do + issuable = create_item(issuable_type, :opened, title: ':eagle: Some issue :dog:') + doc = filter(issuable_link(issuable), context) + + expect(/\p{Emoji_Presentation}/ =~ doc.css('a').last.text).not_to be_nil + expect(doc.css('a').last.text.scan(/\p{Emoji_Presentation}/)).to eq(["🦅", "🐶"]) + end + + it 'does not expand when emoji is embedded mid-string' do + issuable = create_item(issuable_type, :opened, title: 'Some:eagle:issue') + doc = filter(issuable_link(issuable), context) + + expect(/\p{Emoji_Presentation}/ =~ doc.css('a').last.text).to be_nil + end + end + it 'shows title for references with +s' do issuable = create_item(issuable_type, :opened, title: 'Some issue') link = create_link(issuable.to_reference, "#{issuable_type}": issuable.id, reference_type: issuable_type, diff --git a/spec/tooling/danger/model_validations_spec.rb b/spec/tooling/danger/model_validations_spec.rb new file mode 100644 index 00000000000..bfd63f71656 --- /dev/null +++ b/spec/tooling/danger/model_validations_spec.rb @@ -0,0 +1,106 @@ +# frozen_string_literal: true + +require 'gitlab-dangerfiles' +require 'danger' +require 'danger/plugins/internal/helper' +require 'gitlab/dangerfiles/spec_helper' + +require_relative '../../../tooling/danger/model_validations' +require_relative '../../../tooling/danger/project_helper' + +RSpec.describe Tooling::Danger::ModelValidations, feature_category: :tooling do + include_context "with dangerfile" + + let(:fake_danger) { DangerSpecHelper.fake_danger.include(described_class) } + let(:fake_project_helper) { instance_double(Tooling::Danger::ProjectHelper) } + + subject(:model_validations) { fake_danger.new(helper: fake_helper) } + + before do + allow(model_validations).to receive(:project_helper).and_return(fake_project_helper) + end + + describe '#add_comment_for_added_validations' do + let(:file_lines) { file_diff.map { |line| line.delete_prefix('+').delete_prefix('-') } } + let(:filename) { 'app/models/user.rb' } + + before do + allow(model_validations.project_helper).to receive(:file_lines).and_return(file_lines) + allow(model_validations.helper).to receive(:all_changed_files).and_return([filename]) + allow(model_validations.helper).to receive(:changed_lines).with(filename).and_return(file_diff) + end + + context 'when model has a newly added validation' do + let(:file_diff) do + [ + "+ scope :admins, -> { where(admin: true) }", + "+ validates :name, presence: true, length: { maximum: 255 }", + "+ validates_with UserValidator", + "+ validate :check_password_weakness", + "+ validates_each :restricted_visibility_levels do |record, attr, value|", + "+ validates_associated :members", + "+ with_options if: :is_admin? do |admin|", + "+ admin.validates :password, length: { minimum: 10 }", + "+ admin.validates :email, presence: true", + "+ end", + "+ with_options if: :is_admin? { |admin| admin.validates :email, presence: true }", + "- validates :first_name, length: { maximum: 127 }" + ] + end + + it 'adds suggestions at the correct line' do + suggested_line = "\n#{described_class::SUGGEST_MR_COMMENT.chomp}" + + matching_line_numbers = [*2..6, 8, 9, 11] + matching_line_numbers.each do |line_number| + expect(model_validations).to receive(:markdown).with(suggested_line, file: filename, line: line_number) + end + + model_validations.add_comment_for_added_validations + end + end + + context 'when model does not have a newly added validation' do + let(:file_diff) do + [ + "+ scope :admins, -> { where(admin: true) }", + "- validates :first_name, length: { maximum: 127 }" + ] + end + + it 'does not add suggestion' do + expect(model_validations).not_to receive(:markdown) + + model_validations.add_comment_for_added_validations + end + end + end + + describe '#changed_model_files' do + let(:expected_files) do + %w[ + app/models/user.rb + app/models/users/user_follow_user.rb + ee/app/models/ee/user.rb + ee/app/models/sca/license_policy.rb + ] + end + + before do + all_new_files = %w[ + app/models/user.rb + app/models/users/user_follow_user.rb + ee/app/models/ee/user.rb + ee/app/models/sca/license_policy.rb + config/metrics/count_7d/new_metric.yml + app/assets/index.js + ] + + allow(model_validations.helper).to receive(:all_changed_files).and_return(all_new_files) + end + + it 'returns added and modified files' do + expect(model_validations.changed_model_files).to match_array(expected_files) + end + end +end |