I'm integrating capybara to a project. At first instance, I just wanted to check what is displaying the login page, so I made this code:
require 'acceptance/acceptance_helper'
feature 'Login' do
scenario 'sign in with right credentials' do
visit '/'
save_and_open_page
end
end
But when I run the test, it shows me:
Failure/Error: visit '/'
ActionController::RoutingError:
No route matches "/login"
# ./spec/acceptance/login_spec.rb:6
If I enter to the application without a valid session, it redirects me (code 302) to a rubycas server to log me in (which has the /login context at start) and after that it redirects me again to my server.
What should I do to just view the login page or how to maintain the redirection references in capybara?
I usually do this:
Inside my test.rb :
require 'casclient'
require 'casclient/frameworks/rails/filter'
CASClient::Frameworks::Rails::Filter.configure(
:cas_base_url => cas_base_url
)
Modify your spec like this:
CASClient::Frameworks::Rails::Filter.fake(username)
visit '/'
Let me know if this works for you.
==================================================================================
Without using "CASClient::Frameworks::Rails::Filter.fake(username)" I too get the same error.
The reason is that cas redirects you to its base url with "/login?service=http%3A%2d%2Fwww.example.com%aF" a parameter like this.
And hence it complaints about missing route.
Check your test log
Make sure you have added the proper matching routes. it seems that you are missing routes.
I hope this helps you.
For writing routes you can get help from http://railscasts.com/episodes/79-generate-named-routes
Related
I have a question regarding the logout route. When you look at the Demo Page when the user is logged out, a 404 error is shown in the console, because the CMSPageGuard tries to fetch the non-existing Logout page from the Backend. This is a minor problem but doesn't seem intentional?
More so since the logic in the Logout guard redirects to either 'home' or 'login' in case the logout path doesn't exist.
Is the only workaround to not get the 404 error to add a logout page in the Backend, even though it is never shown?
In short, this is intentional. It is part of a feature that makes it easy for storefronts that do require the optional logout page to add it in the CMS and it will be picked up out of the box by the Spartacus logout logic.
You are right about what happens under the hood. If you look at the description of the LogoutGuard in the doc, the overall logic its described like so:
Takes care of routing the user to a logout page (if available) or redirects to the homepage. If the homepage is protected, the user is redirected to the login route instead.
To verify if a logout page is available, the LogoutGuard makes a request for it. If a logout page is not available, that request returns a 404 and this is what shows up in the browser dev tools.
As for preventing that these errors show in the log, there is for now no configuration that will turn this feature off. You might explore using a custom LogoutGuard and override the canActivate function, but I'm not 100% sure this is possible.
I have been trying to do this for days now and cant seem to find any help on how to do is. I want the user after login to be redirected to a different page instead of the members landing page.
Try checking the code in User/AuthController after this comment Run post login hook. There are several ways to do a custom redirect here.
specify a return_url parameter in the link to login page. You can also 64-bit encode the redirect url so that it is compact.
Keep a session variable, namely Zend_Session_Namespace('Redirect')->uri
Write a post login hook onUserLoginAfter and pass a redirect parameter in its response.
If all else fails, hard-code the next line of code which redirects to home :P
I have a login form that send the login info with Ajax.
If the login is wrong, I send a .js that shows some alert and shakes the form.
If the login is successfull, I simply want to redirect the full page.
The Rails controller expect always a .js call, and actually in both cases I send a .js reply, because the redirect in rails will go into some .js reply that the browser expect.
login wrong:
$("#login").effect("shake", { times:2 , distance:10},20);
login successfull:
window.location.replace("<%=root_url(:only_path => false)%>enterprises/");
The question is if this is a good approach (personally I don't like it but it works) or are better ways to handle this.
thanks,
I think it is a good solution. Mayby I would fix the url in case of a successful to depend on a helper, instead of a hardcoded path, but it is a minor thing.
Maybe it can be good to have an additional .html view on both actions in case of the user disabled the javascript in the browser.
i'm having troubles with the bhLDAPAuthPlugin for symfony when the user session expires. It redirects to the signin form as expected but once the user is authenticated, instead of redirect him to the requested page (the one witch first requested the user), it redirects him to the requested page adding exra information to the URL.
Let me show it to you with an example:
The user is in this URL and the session expires
myapp/editSomething/id/231
And then is redirected by the bhLDAPAuthPlugin to the signin form. Once the user had entered the username & password is redirected here
myapp/editSomething/images/loadingAnimation.gif
I dont know what loadingAnimation.gif is (is not in my /images/ directory nor in anywhere else of my app), nor where is this additional information added :S
Could you please help me to find the place where i must change this behaviour?
Thank you! :D
Every thing is done in the action. The redirect url is build here:
// always redirect to a URL set in app.yml
// or to the referer
// or to the homepage
$signinUrl = sfConfig::get('app_sf_guard_plugin_success_signin_url', $user->getReferer('#homepage'));
Did you define something in your app.yml for app_sf_guard_plugin_success_signin_url ?
all:
sf_guard_plugin:
success_signin_url: #my_route?param=value # the plugin uses the referer as default
So it seems that your referer is bad. Try to define an url in the app.yml to see if the behavior is different.
I followed the basic steps to add authentication to Rails using Devise from their page, but every time I try to visit a default page (such as the Sign In or Sign Up pages), I get:
Routing Error
No route matches {:controller=>"devise/Home"}
This happens whether I link to the page in a view using
link_to('Register', new_user_registration_path)
or just visit "/users/sign_up".
This is a different error from when I visit a page with no route defined (No route matches [GET] "/users/bad_example"), and
devise_for :users
is already present in my routes.rb. I have even tried generating views (rails g devise:views) to no avail. It looks like Devise isn't generating/using a controller or some such. How do I go about fixing this?
Here are some files that may help:
routes.rb
rake routes output
It turns out the problem was not with Devise, but with my routes file. I have fixed my routes file as seen at http://guides.rubyonrails.org/routing.html and now this works properly.