Module: Testable::Pages::Region

Defined in:
lib/testable/region.rb

Instance Method Summary collapse

Instance Method Details

#has_many(identifier, **context, &block) ⇒ Object

Allows for a “has_many” method to be declared on a model, like a poage object to specify that the model was a certain region associated with it, but where that region occurs more than once.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/testable/region.rb', line 19

def has_many(identifier, **context, &block)
  region_class = context[:class] || context[:region_class]
  collection_class = context[:through] || context[:collection_class]
  each = context[:each] || raise(ArgumentError, 'the "has_many" method requires an "each" param')
  within = context[:in] || context[:within]
  define_region_accessor(
    identifier,
    within: within,
    each: each,
    region_class: region_class,
    collection_class: collection_class,
    &block
  )
  define_finder_method(identifier)
end

#has_one(identifier, **context, &block) ⇒ Object

Allows for a “has_one” method to be declared on a model, like a page object to specify that the model has a region associated with it. In this case, that would be a single region that can be located by a reference to a specific class (which is also a model) and, relative to that model, is within some specific means of identification. rubocop:disable Naming/PredicateName



10
11
12
13
14
# File 'lib/testable/region.rb', line 10

def has_one(identifier, **context, &block)
  within = context[:in] || context[:within]
  region_class = context[:class] || context[:region_class]
  define_region_accessor(identifier, within: within, region_class: region_class, &block)
end