I am using site prism to create an page object that has a possible 2 urls. Site_prism uses Addressable::Template, and this uses the URI template RFC 6570.
The required page contains a list of elements, but can have none as well, and from this logic 2 possible URLs are defined.
If the page has no elements the URL is example.com/foo
If the page has elements, it redirects selecting the first to example.com/foo/1/bar
I am trying to create a url template for the page so that I can have one of two possible outputs.
case 1 : Page.new.load
=> example.com/foo
case 2 : Page.new.load(id: 1)
=> example.com/foo/1/bar
The solutions I have got so far are:
set_url '/foo{/id,path}'
Page.new.load(id: 1, path: 'bar')
This works for case 1 but not case 2 as it requires 2 variables.
set_url '/foo{/path*}'
Page.new.load(path: [1, 'path'])
Again this works for case 1 but not case 2.
What I need is a uri template that has a path appended to it but only if the variable is present.
something like: /foo{/id,path("bar")}
A variable with a default value, or a path that is only present with a defined variable.
Thanks in advance.
SitePrism has had a lot of updated regarding the addressable templates, however you're posting after all of those have gone in.
Have you tried with the later versions of site_prism and addressable (Something after 2.12 for site_prism and 2.5 for addressable).
If not could you open a defect / feature request on Github, as this sounds like something we "should" support. https://github.com/natritmeyer/site_prism/issues