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.

This file can be required on its own

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



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

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

Instance Method Details

#and(count) ⇒ Object

Changes the number of generated children



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

def and(count)
  @count = count
  self
end

#attributes(options = {}) ⇒ Object

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



65
66
67
68
69
70
# File 'lib/storexplore/testing/dummy_store_generator.rb', line 65

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



50
51
52
# File 'lib/storexplore/testing/dummy_store_generator.rb', line 50

def categories
  dispatch(:category)
end

#itemsObject Also known as: item

Generates @count items with attributes on all @pages



57
58
59
# File 'lib/storexplore/testing/dummy_store_generator.rb', line 57

def items
  dispatch(:item).attributes
end