appfolio / ae_page_objects

Page Objects for Capybara
MIT License
28 stars 9 forks source link

Issues using Paths with parameters in Rails 3 app with minitest #129

Closed mark-ellul closed 9 years ago

mark-ellul commented 9 years ago

Hi, I am having an issue with paths with parameters in my Rails 3.2 app testing with minitest.

I am using integration tests, with capybara, spork, poltergeist, and ae_page_objects. To complicate things our app is subdomain based and I am calling host! after creating the subdomain necessary.

Below is a snippet of the page I am trying to use.

require "pages/shared/network_menu"
require "pages/pathway_sets_page"
require "pages/base_signed_in_page"
require "test_helper"
module Pages
class EditPathwaySetPage < BaseSignedInPage
   path  :edit_pathway_set #"/pathway_sets/:id/edit"
   element :name, locator: "#name"
end

This is the code I use to initialise the site...

@@site =   FactoryGirl.create(:site, :has_col)
host! "#{@@site.subdomain}.lvh.me"
Capybara.app_host = "http://#{@@site.subdomain}.lvh.me:7787"
Pages::Site.initialize!

I won't give you all the cruft of the test but the line below fails with the error below that....

ps = PathwaySet.last
within(".pathway_set_#{ps.id}") do
    page.click_link("Edit")
end
Pages::EditPathwaySetPage.visit(id: ps.id)

The error thrown is....

#<NoMethodError: undefined method `host_with_port' for nil:NilClass>

Is there something I have to do so that the paths in the visitable concern generates the full_url correctly?

I have not set the router to anything specific, so I am sure I am missing something simple.

Any suggestions?

Thanks in advance

mark-ellul commented 9 years ago

After investigating I found that there were two issues occurring, #1 the route was not being found, and if it was found there was the error thrown above.

1 is an issue with the Rails router having problem recognising routes that have constraints.

https://github.com/rails/rails/issues/4260

2 when it comes to use named paths it needed a host passed into the args when converting a named_route in the generate_path

In my app I have a subdomain constraint so I created the below router to pass in a subdomain and host, even though I don't use those exact subdomains it was enough for the router to recognise the correct route and with the generate pathway host arg it stopped the recorded path

https://gist.github.com/mark-ellul/b530ea8fa31bc8afe408

Please feel free to add this to the project if and where you think its appropriate.

Regards

Mark

dtognazzini commented 9 years ago

Hi @mark-ellul. I'm glad you found a workaround. If this is something you'd like AePageObjects to support, feel free to open a pull request and we can make it happen.

Thanks!

mark-ellul commented 9 years ago

@dtognazzini I would need some time to clean up a few things to make it more flexible before I think its in the main code base. Once I get that time to do that I will create a pull request, but for now the gist should help anyone else with this constraints issues.

Regards Mark