Class: Spec::Example::ExampleGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/spec/rails/matchers/associations.rb

Instance Method Summary collapse

Instance Method Details

#belong_to(association) ⇒ Object



7
8
9
10
11
12
# File 'lib/spec/rails/matchers/associations.rb', line 7

def belong_to(association)
  return simple_matcher("model to belong to #{association}") do |model|
    model = model.class if model.is_a? ActiveRecord::Base
    model.reflect_on_all_associations(:belongs_to).find { |a| a.name == association }
  end
end

#have_and_belong_to_many(association) ⇒ Object



28
29
30
31
32
33
# File 'lib/spec/rails/matchers/associations.rb', line 28

def have_and_belong_to_many(association)
  return simple_matcher("model to have and belong to many #{association}") do |model|
    model = model.class if model.is_a? ActiveRecord::Base
    model.reflect_on_all_associations(:has_and_belongs_to_many).find { |a| a.name == association }
  end
end

#have_many(association) ⇒ Object



14
15
16
17
18
19
# File 'lib/spec/rails/matchers/associations.rb', line 14

def have_many(association)
  return simple_matcher("model to have many #{association}") do |model|
    model = model.class if model.is_a? ActiveRecord::Base
    model.reflect_on_all_associations(:has_many).find { |a| a.name == association }
  end
end

#have_one(association) ⇒ Object



21
22
23
24
25
26
# File 'lib/spec/rails/matchers/associations.rb', line 21

def have_one(association)
  return simple_matcher("model to have one #{association}") do |model|
    model = model.class if model.is_a? ActiveRecord::Base
    model.reflect_on_all_associations(:has_one).find { |a| a.name == association }
  end
end