Module: Workarea::Factories::Search

Defined in:
lib/workarea/testing/factories/search.rb

Instance Method Summary collapse

Instance Method Details

#create_admin_search(options = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/workarea/testing/factories/search.rb', line 35

def create_admin_search(options = {})
  result = Workarea::Search::AdminSearch.new
  options.reverse_merge!(factory_defaults(:admin_search))

  options[:results] = PagedArray.from(
    options[:results],
    options[:page],
    options[:per_page],
    options[:total]
  )

  allow(result).to receive_messages(options)

  result
end

#create_category_browse_search(options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/workarea/testing/factories/search.rb', line 25

def create_category_browse_search(options = {})
  result = Workarea::Search::CategoryBrowse.new

  allow(result).to receive_messages(
    create_product_browse_search_options(options)
  )

  result
end

#create_product_browse_search_options(options = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/workarea/testing/factories/search.rb', line 56

def create_product_browse_search_options(options = {})
  options.reverse_merge!(factory_defaults(:product_browse_search_options))

  options[:results] = options[:products].map do |product|
    { catalog_id: product.id, model: product, option: nil }
  end

  options.except(:products)
end

#create_product_search(options = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/workarea/testing/factories/search.rb', line 15

def create_product_search(options = {})
  result = Workarea::Search::ProductSearch.new

  allow(result).to receive_messages(
    create_product_browse_search_options(options)
  )

  result
end

#create_search_customization(overrides = {}) ⇒ Object



10
11
12
13
# File 'lib/workarea/testing/factories/search.rb', line 10

def create_search_customization(overrides = {})
  attributes = factory_defaults(:search_customization).merge(overrides)
  Workarea::Search::Customization.create!(attributes)
end

#create_search_settings(overrides = {}) ⇒ Object



6
7
8
# File 'lib/workarea/testing/factories/search.rb', line 6

def create_search_settings(overrides = {})
  Workarea::Search::Settings.create!(overrides)
end

#elasticsearch_responseObject



51
52
53
54
# File 'lib/workarea/testing/factories/search.rb', line 51

def elasticsearch_response
  file = "#{File.dirname(__FILE__)}/../elasticsearch_response.json"
  JSON.parse(IO.read(file))
end

#update_search_settings(overrides = {}) ⇒ Object



66
67
68
69
# File 'lib/workarea/testing/factories/search.rb', line 66

def update_search_settings(overrides = {})
  attributes = factory_defaults(:search_settings).merge(overrides)
  Workarea::Search::Settings.current.update_attributes!(attributes)
end