Module: AuthorizedRailsScaffolds::Macros::RouteExampleMacros

Included in:
RSpecIntegrationHelper, RSpecScaffoldControllerHelper, RSpecScaffoldRoutingHelper, RailsScaffoldControllerHelper
Defined in:
lib/authorized_rails_scaffolds/macros/route_example_macros.rb

Instance Method Summary collapse

Instance Method Details

#example_index_pathObject

Example index route: i.e. /awesome/users/2/foo_bars



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/authorized_rails_scaffolds/macros/route_example_macros.rb', line 4

def example_index_path
  unless @example_index_path
    example_index_path_parts = []

    parent_model_names.each do |parent_model|
      # users, 2
      parent_value = example_parent_values["#{parent_model}_id"]
      example_index_path_parts << parent_model.pluralize
      example_index_path_parts << parent_value
    end

    # Example index route: i.e. /awesome/users/2/foo_bars
    @example_index_path = [parent_module_groups + example_index_path_parts + [resource_array_name]].join("/")
  end
  "/#{@example_index_path}"
end

#example_index_path_extra_paramsObject

Extra params for an example controller path: i.e. ‘, :user_id => 2’



40
41
42
# File 'lib/authorized_rails_scaffolds/macros/route_example_macros.rb', line 40

def example_index_path_extra_params
  @example_index_path_extra_params ||= example_parent_values.map{ |parent_model_id, parent_value| ", :#{parent_model_id} => \"#{parent_value}\"" }.join('')
end

#example_route_extra_params(use_shallow_route = false) ⇒ Object



48
49
50
51
# File 'lib/authorized_rails_scaffolds/macros/route_example_macros.rb', line 48

def example_route_extra_params(use_shallow_route=false)
  @example_route_extra_params ||= parent_model_names.collect{ |parent_table| ":#{parent_table}_id => #{references_test_name(parent_table)}.to_param" }
  use_shallow_route ? @example_route_extra_params[0..-2] : @example_route_extra_params
end

#example_show_pathObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/authorized_rails_scaffolds/macros/route_example_macros.rb', line 21

def example_show_path
  unless @example_show_path
    example_show_path_parts = []

    parent_names = shallow_routes? ? parent_model_names[0..-2] : parent_model_names
    parent_names.each do |parent_model|
      # users, 2
      parent_value = example_parent_values["#{parent_model}_id"]
      example_show_path_parts << parent_model.pluralize
      example_show_path_parts << parent_value
    end

    # Example index route: i.e. /awesome/users/2/foo_bars
    @example_show_path = [parent_module_groups + example_show_path_parts + [resource_array_name]].join("/")
  end
  "/#{@example_show_path}/1"
end

#example_show_path_extra_paramsObject



44
45
46
# File 'lib/authorized_rails_scaffolds/macros/route_example_macros.rb', line 44

def example_show_path_extra_params
  @example_show_path_extra_params ||= example_parent_values(shallow_routes?).map{ |parent_model_id, parent_value| ", :#{parent_model_id} => \"#{parent_value}\"" }.join('')
end