chmich
chmich

Reputation: 1176

Rails, Rspec, Devise: View Specs with routes within authenticated block

How do you work on this point?

On an application I wanted to put all my routes inside the authenticated block, for example:

devise_scope :user do

  unauthenticated do
    root 'sessions#new'
  end

  authenticated do
    ... routes here
  end

end

Resons:

On the controller/request specs, everything works fine. Because you log_in (Devise Helper) at the beginning of the test.

Problem

On view specs, this throws No route matches for every link_to because on view specs you cannot use the Devise log_in helper. You would have to mock the authenticated block.

From my point of view, I would like to use the authenticated block, but it seems that this is not possible in practice.

How do you work on that point?

How to mock the authenticated block?

Upvotes: 0

Views: 99

Answers (1)

chmich
chmich

Reputation: 1176

Found my answer

The Devise authenticated block is not useful in practice, because:

When an unauthenticated user wants to access a specific page of the application, you normally want to cache the request url, redirect him to the login page, and after successful login, redirect him to the original url.

But this is not possible if the route does not exist for unauthenticated.

Upvotes: 0

Related Questions