Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Routing incorrectly matches documents #63

Closed
dtognazzini opened this issue Jun 23, 2014 · 4 comments
Closed

Routing incorrectly matches documents #63

dtognazzini opened this issue Jun 23, 2014 · 4 comments
Labels
Milestone

Comments

@dtognazzini
Copy link
Contributor

Consider the following code:

def save!
  node.find("input[type=submit]").click
  window.change_to(Books::ShowPage, Books::NewPage)
end

window.change_to needs to load one of the documents above instead of using an on-demand load with a document proxy to ensure that the window.change_to call fails if the window has a document not in the expected set. If this check is deferred until later, the calling code may never access the returned reference and thus the check would never be made.

However, Rails routes is a precedence-order matching list and the first thing that matches, wins. So, in the above case, if the url is /books/new and we try to load a Books::ShowPage, it'll work because the show route will match the URL and use "new" as the :id parameter for the show named route.

So we have 2 options:

  1. Keep the current load-now behavior and figure out how to match better such that loading ShowPage will fail for /books/new. This would involve running through the normal Rails route matching and somehow comparing the resulting match with whatever would match the ShowPage. A first try might be to run the route matching with the path defined for ShowPage. Unfortunately, generating the path is difficult, 'cause the ShowPage route has a required parameter which would have to be faked in order to get Rails' routes matching to work; this would have to be done for any arbitrary route.

    Another idea, is to run all of the expected document types through the route matching and from the matching ones select whichever has the highest precedence. This would require changes to the Router and/or AePageObjects to support the idea of precedence. This support is a coupling between AePageObjects and the underlying router, in this case Rails'. Of course, the document loading could be further generalized to support this concept.

  2. Keep the current load-now behavior to get the immediate failure when there are no matches, but run the route matching later again from the DocumentProxy when the page is accessed. This works great for explicit casts because it doesn't care about the previous loading that happened with the window.change_to call. Implicit casts works as well, as with implicit casts the contract is that the first specified expected page is used for implicit casts.

    The downside of this method is that it only works when you call window.change_to with multiple pages. It doesn't work with single-arg window.change_to calls:

    new_page  = PageObjects::Books::NewPage.visit
    show_page = new_page.window.change_to(PageObjects::Books::ShowPage)

    This code does not raise an error because Books::ShowPage can recognize Books::NewPage's routes.

Then again, it's not really clear how either solution can handle the single-arg case.

@dtognazzini dtognazzini added this to the 1.1 milestone Oct 4, 2014
dtognazzini added a commit that referenced this issue Oct 4, 2014
fix Routing incorrectly matches documents issue and fix for #63
@dtognazzini dtognazzini modified the milestones: 1.2, 1.1 Oct 4, 2014
@dtognazzini
Copy link
Contributor Author

Released in 1.2.0

@dtognazzini
Copy link
Contributor Author

This fix doesn't support handling mounted Rails engines. Reopening.

@dtognazzini dtognazzini reopened this Oct 4, 2014
@dtognazzini dtognazzini modified the milestones: 1.X, 1.2 Oct 4, 2014
@ipmsteven
Copy link
Contributor

@dtognazzini can we add engine test case in page_object_integration_test after revert #73

@dtognazzini
Copy link
Contributor Author

Yes, we should.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants