Sha256: b33906883147b778740aa413ec3eac89e9c1d10949df18e9be4ee04df0b7c576

Contents?: true

Size: 1.4 KB

Versions: 49

Compression:

Stored size: 1.4 KB

Contents

module PathHelpers

  def path_to(page_name)
    case page_name

    when /^the list of (.*?)$/
      models_prose = $1
      route = "#{model_prose_to_route_segment(models_prose)}_path"
      send(route)

    when /^the (page|form) for the (.*?) above$/
      action_prose, model_prose = $1, $2
      route = "#{action_prose == 'form' ? 'edit_' : ''}#{model_prose_to_route_segment(model_prose)}_path"
      model = model_prose.classify.constantize
      send(route, model.last)

    when /^the (page|form) for the (.*?) "(.*?)"$/
      action_prose, model_prose, identifier = $1, $2, $3
      path_to_show_or_edit(action_prose, model_prose, identifier)

    when /^the (.*?) (page|form) for "(.*?)"$/
      model_prose, action_prose, identifier = $1, $2, $3
      path_to_show_or_edit(action_prose, model_prose, identifier)

    when /^the (.*?) form$/
      model_prose = $1
      route = "new_#{model_prose_to_route_segment(model_prose)}_path"
      send(route)

    when /^the screen selection$/
      root_path

    end

  end

  private

  def path_to_show_or_edit(action_prose, model_prose, identifier)
    model = model_prose.classify.constantize
    route = "#{action_prose == 'form' ? 'edit_' : ''}#{model_prose_to_route_segment(model_prose)}_path"
    send(route, model.find_by_anything!(identifier))
  end

  def model_prose_to_route_segment(model_prose)
    model_prose.gsub(/[\ \/]/, '_')
  end

end

World(PathHelpers)

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
upjs-rails-0.14.0 spec_app/features/support/paths.rb
upjs-rails-0.13.0 spec_app/features/support/paths.rb
upjs-rails-0.12.5 spec_app/features/support/paths.rb
upjs-rails-0.12.4 spec_app/features/support/paths.rb
upjs-rails-0.12.3 spec_app/features/support/paths.rb
upjs-rails-0.12.2 spec_app/features/support/paths.rb
upjs-rails-0.12.1 spec_app/features/support/paths.rb
upjs-rails-0.12.0 spec_app/features/support/paths.rb
upjs-rails-0.11.1 spec_app/features/support/paths.rb
upjs-rails-0.11.0 spec_app/features/support/paths.rb
upjs-rails-0.10.5 spec_app/features/support/paths.rb
upjs-rails-0.10.4 spec_app/features/support/paths.rb
upjs-rails-0.10.3 spec_app/features/support/paths.rb
upjs-rails-0.10.2 spec_app/features/support/paths.rb
upjs-rails-0.10.1 spec_app/features/support/paths.rb
upjs-rails-0.10.0 spec_app/features/support/paths.rb
upjs-rails-0.9.1 spec_app/features/support/paths.rb
upjs-rails-0.9.0 spec_app/features/support/paths.rb
upjs-rails-0.8.2 spec_app/features/support/paths.rb
upjs-rails-0.8.1 spec_app/features/support/paths.rb