Class: Storexplore::Testing::DummyStoreGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/storexplore/testing/dummy_store_generator.rb

Overview

Dummy store generation one liner. Forwards chains of method calls to a collections of Storexplore::Testing::DummyStore instances.

Instance Method Summary collapse

Constructor Details

#initialize(pages, count = 1) ⇒ DummyStoreGenerator

  • pages : collection of Storexplore::Testing::DummyStore instances to which calls will be forwarded

  • count : number of children (categories or items) that will be added with every generation call



33
34
35
36
# File 'lib/storexplore/testing/dummy_store_generator.rb', line 33

def initialize(pages, count = 1)
  @pages = pages
  @count = count
end

Instance Method Details

#and(count) ⇒ Object

Changes the number of generated children



39
40
41
42
# File 'lib/storexplore/testing/dummy_store_generator.rb', line 39

def and(count)
  @count = count
  self
end

#attributes(options = {}) ⇒ Object

generates attributes for all @pages. Explicit attributes can be specified



60
61
62
63
64
65
# File 'lib/storexplore/testing/dummy_store_generator.rb', line 60

def attributes(options = {})
  @pages.map do |page|
    attributes = DummyData.attributes(page.name, options)
    page.attributes(HashUtils.without(attributes, [:name]))
  end
end

#categoriesObject Also known as: category

Generates @count categories on all @pages



45
46
47
# File 'lib/storexplore/testing/dummy_store_generator.rb', line 45

def categories
  dispatch(:category)
end

#itemsObject Also known as: item

Generates @count items with attributes on all @pages



52
53
54
# File 'lib/storexplore/testing/dummy_store_generator.rb', line 52

def items
  dispatch(:item).attributes
end