I made a filter before this, it seems to work well, for the test I did this:
at authentication_pages_spec.rb
describe "signin" do describe "authorization" do describe "for signed in users" do let(:user) { FactoryGirl.create(:user) } let(:new_user) { FactoryGirl.attributes_for(:user) } before { sign_in user } describe "using a 'new' action" do before { get new_user_path } specify { response.should redirect_to(root_path) } end describe "using a 'create' action" do before { post users_path new_user } specify { response.should redirect_to(root_path) } end end end end
Like @WillJones, some people can add no_capybara: true to the previous block
and on my user controller:
before_filter :signed_in_user_filter, only: [:new, :create] def signed_in_user_filter redirect_to root_path, notice: "Already logged in" if signed_in? end
For the difference between new and created actions, this is due to the REST architectural style, but basically new is an action from a user controller that responds to a GET request, and one that is responsible for returning the view it responds to (in this case, a new user form ) create , on the other hand, is an action that responds to a POST request, it does not display anything (it can respond with javascript, but this is an extended topic), and it is responsible for creating new users, for example, the name of the action implies.
rkrdo
source share