Module: SchemaExpectations::RSpecMatchers

Defined in:
lib/schema_expectations/rspec_matchers/validate_schema_nullable.rb,
lib/schema_expectations/rspec_matchers/validate_schema_uniqueness.rb

Defined Under Namespace

Classes: ValidateSchemaNullableMatcher, ValidateSchemaUniquenessMatcher

Instance Method Summary collapse

Instance Method Details

#validate_schema_nullableValidateSchemaNullableMatcher

class Record < ActiveRecord::Base

  validates :name, presence: true
end

# RSpec
describe Record do
  it { should validate_schema_nullable }
end

You can restrict the columns tested:

# RSpec
describe Record do
  it { should validate_schema_nullable.only(:name) }
  it { should validate_schema_nullable.except(:name) }
end

The primary key and timestamp columns are automatically skipped.


38
39
40
# File 'lib/schema_expectations/rspec_matchers/validate_schema_nullable.rb', line 38

def validate_schema_nullable
  ValidateSchemaNullableMatcher.new
end

#validate_schema_uniquenessValidateSchemaUniquenessMatcher

class Record < ActiveRecord::Base

  validates :record_type, uniqueness: { scope: :record_id }
end

# RSpec
describe Record do
  it { should validate_schema_uniqueness }
end

You can restrict the columns tested:

# RSpec
describe Record do
  it { should validate_schema_uniqueness.only(:record_id, :record_type) }
  it { should validate_schema_uniqueness.except(:record_id, :record_type) }
end

note: if you exclude a column, then every unique scope which includes it will be completely ignored, regardless of whether that scope includes other non-excluded columns. Only works similarly, in that it will ignore any scope which contains columns not in the list


42
43
44
# File 'lib/schema_expectations/rspec_matchers/validate_schema_uniqueness.rb', line 42

def validate_schema_uniqueness
  ValidateSchemaUniquenessMatcher.new
end