Sha256: 734e996c5003bc6fab6c0bab3525235ec7675d57870280428d2701e5be813032

Contents?: true

Size: 1.58 KB

Versions: 6

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true

RSpec.describe RuboCop::Cop::Discourse::NoAddReferenceOrAliasesActiveRecordMigration, :config do
  subject(:cop) { described_class.new(config) }

  let(:config) { RuboCop::Config.new }

  it "raises an offense if add_reference is used, with or without arguments" do
    offenses = inspect_source(<<~RUBY)
      add_reference :posts, :users, foreign_key: true, null: false
    RUBY
    expect(offenses.first.message).to match(described_class::MSG)
  end

  it "raises an offense if add_belongs_to is used, with or without arguments" do
    offenses = inspect_source(<<~RUBY)
      add_belongs_to :posts, :users, foreign_key: true, null: false
    RUBY
    expect(offenses.first.message).to match(described_class::MSG)
  end

  it "raises an offense if t.references, or any variable.references is used, with or without arguments" do
    offenses = inspect_source(<<~RUBY)
      create_table do |t|
        t.references :topic, null: false
      end
      create_table do |mytable|
        mytable.references :topic, null: false
      end
    RUBY
    expect(offenses.count).to eq(2)
    expect(offenses.first.message).to match(described_class::MSG)
  end

  it "raises an offense if t.belongs_to, or any variable.belongs_to is used, with or without arguments" do
    offenses = inspect_source(<<~RUBY)
      create_table do |t|
        t.belongs_to :topic, null: false
      end
      create_table do |mytable|
        mytable.belongs_to :topic, null: false
      end
    RUBY
    expect(offenses.count).to eq(2)
    expect(offenses.first.message).to match(described_class::MSG)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rubocop-discourse-3.12.1 spec/lib/rubocop/cop/no_add_reference_active_record_migrations_spec.rb
rubocop-discourse-3.12.0 spec/lib/rubocop/cop/no_add_reference_active_record_migrations_spec.rb
rubocop-discourse-3.11.0 spec/lib/rubocop/cop/no_add_reference_active_record_migrations_spec.rb
rubocop-discourse-3.10.0 spec/lib/rubocop/cop/no_add_reference_active_record_migrations_spec.rb
rubocop-discourse-3.9.3 spec/lib/rubocop/cop/no_add_reference_active_record_migrations_spec.rb
rubocop-discourse-3.9.2 spec/lib/rubocop/cop/no_add_reference_active_record_migrations_spec.rb