Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/tooling/danger/database_spec.rb')
-rw-r--r--spec/tooling/danger/database_spec.rb90
1 files changed, 89 insertions, 1 deletions
diff --git a/spec/tooling/danger/database_spec.rb b/spec/tooling/danger/database_spec.rb
index ddcfa279dc3..a342014cf6b 100644
--- a/spec/tooling/danger/database_spec.rb
+++ b/spec/tooling/danger/database_spec.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
+require 'rspec-parameterized'
require 'gitlab-dangerfiles'
require 'danger'
require 'danger/plugins/internal/helper'
@@ -41,11 +42,98 @@ RSpec.describe Tooling::Danger::Database, feature_category: :tooling do
let(:cutoff) { Date.parse('2022-10-01') - 21 }
- subject(:database) { fake_danger.new }
+ subject(:database) { fake_danger.new(helper: fake_helper) }
describe '#find_migration_files_before' do
it 'returns migrations that are before the cutoff' do
expect(database.find_migration_files_before(migration_files, cutoff).length).to eq(8)
end
end
+
+ describe '#changes' do
+ using RSpec::Parameterized::TableSyntax
+
+ where do
+ {
+ 'with database changes to a migration file' => {
+ modified_files: %w[
+ db/migrate/20230720114001_test_migration.rb
+ db/schema_migrations/20230720114001
+ db/structure.sql
+ app/models/test.rb
+ ],
+ changed_lines: [],
+ changes_by_category: {
+ database: %w[
+ db/migrate/20230720114001_test_migration.rb
+ db/schema_migrations/20230720114001
+ db/structure.sql
+ ]
+ },
+ impacted_files: %w[
+ db/migrate/20230720114001_test_migration.rb
+ db/schema_migrations/20230720114001
+ db/structure.sql
+ ]
+ },
+ 'with non-database changes' => {
+ modified_files: %w[
+ app/models/test.rb
+ ],
+ changed_lines: %w[
+ +# Comment explaining scope :blah
+ ],
+ changes_by_category: {
+ database: []
+ },
+ impacted_files: []
+ },
+ 'with database changes in a doc' => {
+ modified_files: %w[doc/development/database/test.md],
+ changed_lines: [
+ '+scope :blah, ->() { where(hidden: false) }'
+ ],
+ changes_by_category: {
+ database: []
+ },
+ impacted_files: []
+ },
+ 'with database changes in a model' => {
+ modified_files: %w[app/models/test.rb],
+ changed_lines: [
+ '+# Comment explaining scope :blah',
+ '+scope :blah, ->() { where(hidden: false) }'
+ ],
+ changes_by_category: {
+ database: []
+ },
+ impacted_files: %w[app/models/test.rb]
+ },
+ 'with database changes in a concern' => {
+ modified_files: %w[app/models/concerns/test.rb],
+ changed_lines: [
+ '- .where(hidden: false)',
+ '+ .where(hidden: true)'
+ ],
+ changes_by_category: {
+ database: []
+ },
+ impacted_files: %w[app/models/concerns/test.rb]
+ }
+ }
+ end
+
+ with_them do
+ before do
+ allow(fake_helper).to receive(:modified_files).and_return(modified_files)
+ allow(fake_helper).to receive(:all_changed_files).and_return(modified_files)
+ allow(fake_helper).to receive(:changed_lines).and_return(changed_lines)
+ allow(fake_helper).to receive(:changes_by_category).and_return(changes_by_category)
+ end
+
+ it 'returns database changes' do
+ expect(database.changes).to match impacted_files
+ end
+ end
+ end
end