aboutsummaryrefslogtreecommitdiff
blob: d35fb6276a2bc47cc7fca8c42d01a9b1e2c89365 (plain)
1
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
module NavigationHelpers
  # Maps a name to a path. Used by the
  #
  #   When /^I go to (.+)$/ do |page_name|
  #
  # step definition in web_steps.rb
  #
  def path_to(page_name)
    case page_name

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

    when /login page/
      user_login_path

    when /edit "([^\"]*)" user page/
      edit_user_path(User.find_by_name($1))

    when /"([^\"]*)" user page/
      user_path(User.find_by_name($1))

    when /unanswered questions page/
      unanswered_questions_questions_path

    when /answer of "([^\"]*)" for question "([^\"]*)" page/
      answer_path(Question.find_by_title($2).answer_of(User.find_by_name($1)))

    when /new comment for answer of "([^\"]*)" for question "([^\"]*)"/
      new_comment_for_answer_path(Question.find_by_title($2).answer_of(User.find_by_name($1)))

    when /newest comment page/
      comment_path(Comment.last)

    when /recruits waiting for your acceptance page/
      pending_acceptances_project_acceptances_path

    when /project acceptance of "([^\"]*)" by "([^\"]*)" edit page/
      edit_project_acceptance_path(ProjectAcceptance.find_by_user_name_and_accepting_nick($1, $2))

    when /my answered questions page/
      answered_questions_questions_path

    when /my unanswered questions page/
      unanswered_questions_questions_path

    when /questions index page/
      questions_path

    when /question groups index page/
      category_question_groups_path

    when /show "([^\"]*)" question page/
      question_path(Question.find_by_title($1))
    # Add more mappings here.
    # Here is an example that pulls values out of the Regexp:
    #
    #   when /^(.*)'s profile page$/i
    #     user_profile_path(User.find_by_login($1))
    when /ready recruits/
      ready_recruits_users_path

    else
      begin
        page_name =~ /the (.*) page/
        path_components = $1.split(/\s+/)
        self.send(path_components.push('path').join('_').to_sym)
      rescue Object => e
        raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
          "Now, go and add a mapping in #{__FILE__}"
      end
    end
  end
end

World(NavigationHelpers)