Module: Adva::Core::Paths

Defined in:
lib/testing/paths.rb

Instance Method Summary collapse

Instance Method Details

#path_to(page) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/testing/paths.rb', line 2

def path_to(page)
  case page

  when /^\//
    page

  when /^the home\s?page$/
    '/'

  when /^the site installation page$/
    new_installation_path

  when /^the site installation confirmation page$/
    installation_path(Site.last)

  when /^the "([^"]*)" section page$/
    section = Section.where(:name => $1).first || raise("could not find section named #{$1}")
    polymorphic_path(section)

  # the "Catalog" section page, ordered by "most viewed"
  when /,? ordered by "([^\"]*)"$/
    order = $1
    path_to(page.gsub(/,? ordered by "[^\"]*"$/, '')) + "?order=#{order.gsub(' ', '_')}"

  when /^the admin sites page$/
    polymorphic_path([:admin, :sites])

  when /^the admin dashboard page$/
    site = Site.first || raise("no site found")
    polymorphic_path([:admin, site])

  when /^the admin dashboard page for the site on "([^"]*)"$/
    site = Site.find_by_host($1) || raise("could not find site with host #{$1}")
    polymorphic_path([:admin, site])

  when /^the admin sections page$/
    site = Site.first || raise("no site found")
    polymorphic_path([:admin, site, :sections])

  when /^the admin "([^"]*)" section page$/
    site = Site.first || raise("no site found")
    section = Section.where(:name => $1).first || raise("could not find section named #{$1}")
    polymorphic_path([:admin, site, section])

  when /^the admin "([^"]*)" section settings page$/
    site = Site.first || raise("no site found")
    section = Section.where(:name => $1).first || raise("could not find section named #{$1}")
    polymorphic_path([:edit, :admin, site, section])

  else
    named_route_helper = page.gsub(/(\Athe )|( page\Z)/, '').gsub(/ +/, '_').downcase + '_path'
    raise "Can't find mapping from \"#{page}\" to a path.\nNow, go and add a mapping in #{__FILE__}" unless respond_to?(named_route_helper)
    send named_route_helper
  end
end