Class: RspecSequel::Association

Inherits:
Base
  • Object
show all
Defined in:
lib/rspec_sequel/association.rb

Instance Method Summary collapse

Methods inherited from Base

#failure_message, #hash_to_nice_string, #initialize, #matches?, #negative_failure_message

Constructor Details

This class inherits a constructor from RspecSequel::Base

Instance Method Details

#descriptionObject



5
6
7
8
9
# File 'lib/rspec_sequel/association.rb', line 5

def description
  desc = "have a #{association_type} association #{@attribute.inspect}"
  desc << " with option(s) #{hash_to_nice_string @options}" unless @options.empty?
  desc
end

#valid?(db, i, c, attribute, options) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rspec_sequel/association.rb', line 11

def valid?(db, i, c, attribute, options)
  @association = c.association_reflection(attribute) || {}
  if @association.empty?
    @suffix << "(no association #{@attribute.inspect} found)"
    false
  else
    matching = @association[:type] == association_type
    options.each{|key, value|
      if @association[key]!=value
        @suffix << "expected #{key.inspect} == #{value.inspect} but found #{@association[key].inspect} instead"
        matching = false
      end
    }
    matching
  end
end