Sha256: 76220a7e327bfdfa3b57a31ab9271d525a9a7de27d2479a55e36781d373da66d

Contents?: true

Size: 1.6 KB

Versions: 7

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

require "spec_helper"

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

7 entries across 7 versions & 1 rubygems

Version Path
rubocop-discourse-3.9.1 spec/lib/rubocop/cop/no_add_reference_active_record_migrations_spec.rb
rubocop-discourse-3.9.0 spec/lib/rubocop/cop/no_add_reference_active_record_migrations_spec.rb
rubocop-discourse-3.8.6 spec/lib/rubocop/cop/no_add_reference_active_record_migrations_spec.rb
rubocop-discourse-3.8.5 spec/lib/rubocop/cop/no_add_reference_active_record_migrations_spec.rb
rubocop-discourse-3.8.4 spec/lib/rubocop/cop/no_add_reference_active_record_migrations_spec.rb
rubocop-discourse-3.8.3 spec/lib/rubocop/cop/no_add_reference_active_record_migrations_spec.rb
rubocop-discourse-3.8.2 spec/lib/rubocop/cop/no_add_reference_active_record_migrations_spec.rb