Module: Remarkable::Mongoid::Matchers

Defined in:
lib/remarkable/mongoid/fields.rb,
lib/remarkable/mongoid/relations.rb,
lib/remarkable/mongoid/validate_association.rb,
lib/remarkable/mongoid/validate_uniqueness_of.rb

Defined Under Namespace

Classes: HasFieldMatcher, RelationMatcher, ValidateAssociationMatcher, ValidateUniquenessOfMatcher

Instance Method Summary collapse

Instance Method Details

#be_embedded_in(attr) ⇒ Remarkable::Mongoid::Matchers::RelationMatcher

Specify the document is embedded in another document

examples:

it { should be_embedded_in :dog }

Parameters:

  • (Symbol)

Returns:



84
85
86
# File 'lib/remarkable/mongoid/relations.rb', line 84

def be_embedded_in(attr)
  RelationMatcher.new(attr, ::Mongoid::Relations::Embedded::In)
end

#be_referenced_in(attr) ⇒ Remarkable::Mongoid::Matchers::RelationMatcher

Specify the document is referenced in another document

examples:

it { should be_referenced_in :dog }

Parameters:

  • (Symbol)

Returns:



48
49
50
# File 'lib/remarkable/mongoid/relations.rb', line 48

def be_referenced_in(attr)
  RelationMatcher.new(attr, ::Mongoid::Relations::Referenced::In)
end

#embed_many(attr) ⇒ Remarkable::Mongoid::Matchers::RelationMatcher

Specify the document embeds many documents

examples:

it { should embed_many :dog }

Parameters:

  • (Symbol)

Returns:



72
73
74
# File 'lib/remarkable/mongoid/relations.rb', line 72

def embed_many(attr)
  RelationMatcher.new(attr, ::Mongoid::Relations::Embedded::Many)
end

#embed_one(attr) ⇒ Remarkable::Mongoid::Matchers::RelationMatcher

Specify the document embeds another document

examples:

it { should embed_one :dog }

Parameters:

  • (Symbol)

Returns:



60
61
62
# File 'lib/remarkable/mongoid/relations.rb', line 60

def embed_one(attr)
  RelationMatcher.new(attr, ::Mongoid::Relations::Embedded::One)
end

#have_field(field, options = {}) ⇒ Remarkable::Mongoid::Matchers::HasFieldMatcher

Specify the document should have a field

examples:

it { should have_field :name }
it { should have_field :age, :type => Integer, :default => 0 }

Parameters:

  • options (Symbol, Hash) (defaults to: {})

Options Hash (options):

  • :type (Class)

    The data type

  • :default (Object)

    The default value for this field

Returns:



15
16
17
# File 'lib/remarkable/mongoid/fields.rb', line 15

def have_field(field, options = {})
  HasFieldMatcher.new(field, options)
end

#reference_many(attr) ⇒ Remarkable::Mongoid::Matchers::RelationMatcher

Specify the document references many documents

examples:

it { should reference_many :dogs }

Parameters:

  • (Symbol)

Returns:



24
25
26
# File 'lib/remarkable/mongoid/relations.rb', line 24

def reference_many(attr)
  RelationMatcher.new(attr, ::Mongoid::Relations::Referenced::Many)
end

#reference_many_and_be_referenced_in(attr) ⇒ Remarkable::Mongoid::Matchers::RelationMatcher

Specify the document references many documents and is referenced in many documents

examples:

it { should reference_many_and_be_referenced_in :dog }

Parameters:

  • (Symbol)

Returns:



36
37
38
# File 'lib/remarkable/mongoid/relations.rb', line 36

def reference_many_and_be_referenced_in(attr)
  RelationMatcher.new(attr, ::Mongoid::Relations::Referenced::ManyToMany)
end

#reference_one(attr) ⇒ Remarkable::Mongoid::Matchers::RelationMatcher

Specify the document references another document

examples:

it { should reference_one :dog }

Parameters:

  • (Symbol)

Returns:



12
13
14
# File 'lib/remarkable/mongoid/relations.rb', line 12

def reference_one(attr)
  RelationMatcher.new(attr, ::Mongoid::Relations::Referenced::One)
end

#validate_association(attr) ⇒ Remarkable::Mongoid::Matchers::ValidateAssociationMatcher

Specify the document validates the association

examples:

it { should validate_association :dog }


12
13
14
# File 'lib/remarkable/mongoid/validate_association.rb', line 12

def validate_association(attr)
  ValidateAssociationMatcher.new(attr)
end

#validate_uniqueness_of(attr) ⇒ Remarkable::Mongoid::Matchers::ValidateUniquenessOfMatcher

Specify the document validates the uniqueness of the field’s data

examples:

it { should validate_uniqueness_of :dog }


12
13
14
# File 'lib/remarkable/mongoid/validate_uniqueness_of.rb', line 12

def validate_uniqueness_of(attr)
  ValidateUniquenessOfMatcher.new(attr)
end