-
-
Save jonstorer/1567196 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module NavigationHelpers | |
def path_to(page_name) | |
case page_name | |
#services | |
when /the list of services/ | |
services_path | |
when /a new service/ | |
new_service_path | |
when /edit the service named "([^"]*)"/ | |
edit_service_path(fetch_service(name: $1)) | |
#subscriptions | |
when /a new subscription for user "([^"]*)"/ | |
new_user_subscription_path(fetch_user(username: $1)) | |
end | |
end | |
end | |
World(NavigationHelpers) | |
module FetchHelpers | |
def method_missing(name, *args, &block) | |
clazz_name = name.to_s.sub("fetch_","").capitalize | |
fetch(Kernel.const_get(clazz_name), args.first) | |
end | |
private | |
def fetch(clazz, options) | |
clazz.where(options).first or | |
raise "No #{clazz} found for #{options.inspect}" | |
end | |
end | |
World(FetchHelpers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment