Module: Itsf::Backend::SpecHelpers

Defined in:
lib/itsf/backend/spec_helpers.rb

Instance Method Summary collapse

Instance Method Details

#backend_pathObject



8
9
10
# File 'lib/itsf/backend/spec_helpers.rb', line 8

def backend_path
  "#{itsf_backend_path}/"
end

#create_resource_instance_for_controller(controller_class) ⇒ Object



24
25
26
# File 'lib/itsf/backend/spec_helpers.rb', line 24

def create_resource_instance_for_controller(controller_class)
  create(controller_class.resource_class.name.underscore.tr('/', '_'))
end

#engine_path(engine_class) ⇒ Object



12
13
14
# File 'lib/itsf/backend/spec_helpers.rb', line 12

def engine_path(engine_class)
  send("#{engine_class.engine_name}_path")
end

#ensure_backend_engine_homepage(engine_class) ⇒ Object



4
5
6
# File 'lib/itsf/backend/spec_helpers.rb', line 4

def ensure_backend_engine_homepage(engine_class)
  expect(current_path).to eq(engine_path(engine_class))
end

#ensure_current_action(_engine_class, controller_class, action_name, instance = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/itsf/backend/spec_helpers.rb', line 28

def ensure_current_action(_engine_class, controller_class, action_name, instance = nil)
  case action_name
  when :index
    expect(page).to have_content(controller_class.resource_class.model_name.human(count: :other))
  when :new
    expect(page).to have_content(I18n.t('itsf.backend.base.new.title', resource_name: controller_class.resource_class.model_name.human))
  when :show
    expect(page).to have_content(instance.try_all(*Itsf::Backend::Configuration.resource_title_methods))
  when :edit
    expect(page).to have_content(I18n.t('itsf.backend.base.edit.title', resource_name: instance.class.model_name.human))
  when :destroy
    expect(page).to have_content(instance.class.model_name.human(count: :other))
  end

  # Can't use this because of bug: undefined method `segment_keys' for nil:NilClass
  # expect(current_path).to eq(engine_class.routes.url_for(controller: controller_class.controller_name, action: action_name))
end


16
17
18
19
20
21
22
# File 'lib/itsf/backend/spec_helpers.rb', line 16

def link_to_controller_action(controller_class, action_name, instance = nil)
  if instance
    "link-to-#{controller_class.name.underscore.gsub('_controller', '').gsub(/[\/_]/, '-')}-#{instance.to_param}-#{action_name}"
  else
    "link-to-#{controller_class.name.underscore.gsub('_controller', '').gsub(/[\/_]/, '-')}-#{action_name}"
  end
end