Verify that content does not exist. Iterating over content templates

24 views
Skip to first unread message

Samuel Rossinovic

unread,
Sep 27, 2017, 2:19:04 AM9/27/17
to Geb User Mailing List
Hi.
An index page has a navbar with refs to the various pages of the site:

class Index extends Page {
 
static content = {
 pageA
{ //..}
 pageB
{ //..}
 pageC
{ //..}
 pageD
{ //..}
 
}
}


The site implements roles. A role allows access to one (or more) pages: 
  • a priviledged user has access to the entire set of pages (A-D)
  • Other users get access to a subset of the pages. E.G a user may only have a link to pageB when he signs-in.
  • How can I assert that content DOES NOT appear in the page, using existing content templates?
           So far, I've tried:
try { pageA } catch (Throwable t) { assert t instanceof RequiredPageContentNotPresent }


, but was hoping there's a more streamlined solution.

  • can I somehow iterate over content? something like:
  page.content.findAll { it.name ~== /page[A-D]/}.each {
     assert page."$it" == null 
  }

Eventually, I'm looking to incorporate the above into a data-driven spec.

Thanks!

P.S: I was setting `required:false` on the content definitions, to see whether that does away with the exception. The above 'pageX' reference in-fact relies on another template, which then references yet-another template. In order to avoid an exception, I had to mark all the templates in the inheritance chain as non-required. I expected that once I've marked the base template as not-required, that content using it shall inherit that property.

Message has been deleted

Marcin Erdmann

unread,
Sep 29, 2017, 2:53:57 AM9/29/17
to geb-...@googlegroups.com
There are multiple questions in your email, hopefully I will be able to adress them all.

First of all, I'd suggest you indeed use required: false in your content definitions. And if your "nested" definitions might return an empty navigator, I'd mark them as not required. I understand that this feels cumbersome but I found that being explicit about what is required and what not will let you catch problems with elements missing from pages quicker.

I'm personally against catching all RequiredContentNotPresent exceptions from nested content acesses when required: false is used but I'm open to discussion. We could also consider making value of required for all content configurable (there's even an issue for that, as far as I remember) but that feels like shooting birds with a cannon in this particular usecase.

With regards to iterating over content, it will only become possible when this issue is implemented: https://github.com/geb/issues/issues/369

Hope that helps,
Marcin

--
You received this message because you are subscribed to the Google Groups "Geb User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geb-user+u...@googlegroups.com.
To post to this group, send email to geb-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/geb-user/68013fe3-8b91-48d6-a348-4ecbb4ff5799%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages