Module: Wallaby::TestUtils

Defined in:
lib/utils/wallaby/test_utils.rb

Overview

Utils for test

Class Method Summary collapse

Class Method Details

.around_crud(context, controller_class = nil) ⇒ Object

Parameters:

  • context
  • controller_class (Class) (defaults to: nil)


7
8
9
10
11
12
13
14
15
# File 'lib/utils/wallaby/test_utils.rb', line 7

def around_crud(context, controller_class = nil)
  context.before do
    controller_class ||= described_class
    controller_path = controller_class.controller_path
    Wallaby::TestUtils.draw(routes, controller_path)
  end

  context.after { Rails.application.reload_routes! }
end

.draw(routes, controller_path) ⇒ Object

Parameters:

  • routes
  • controller_path (String)


19
20
21
22
23
24
25
26
27
28
29
# File 'lib/utils/wallaby/test_utils.rb', line 19

def draw(routes, controller_path)
  routes.draw do
    get ':resources', to: "#{controller_path}#index", as: :resources
    get ':resources/:id', to: "#{controller_path}#show", as: :resource
    get ':resources/new', to: "#{controller_path}#new"
    get ':resources/:id/edit', to: "#{controller_path}#edit"
    post ':resources', to: "#{controller_path}#create"
    patch ':resources/:id', to: "#{controller_path}#update"
    delete ':resources/:id', to: "#{controller_path}#destroy"
  end
end