We are having a strange problem. In the application controller we have a before_filter
set that requires authentication using devise
and redirects if needed to the login page.
In our library controller we skip this before_filter
.
skip_before_filter :authenticate_user!, :only => :show
When we run a simple functional test with capybara
and rspec
the test fails.
it "should get only english articles within the category 'computers'" do
visit '/en/library/computers'
page.should have_content('computers')
end
It looks like it doesn't skip this filter. The page content is of the login page.
When we run this with rails server
it works fine.
Any ideas why it behaves this way or what to look for to resolve this?
UPDATE:
It might be worth adding that this only happens using Linux. Under MacOS 10.7 with the "same" setup it works fine.
Controller Code:
class Library::CategoriesController < ApplicationController
skip_before_filter :authenticate_user!, :only => [:show]
# GET /categories/1
# GET /categories/1.json
def show
@categories = Category.all
@category = Category.find(params[:id])
@articles = @category.articles.where(:locale => I18n.locale)
respond_to do |format|
format.html # show.html.erb
end
end
end
The application_controller looks like (without the set_i18n_locale_from_url):
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :set_i18n_locale_from_url, :authenticate_user!
end
Routes:
namespace :library do
get '/' => 'library#index', :as => 'library'
resources :categories, :path => '', :only => [:show]
resources :categories, :path => '', :only => [] do
resources :articles, :path => '', :only => [:show]
end
end
I guess the first thing you can do is to see whether or not "visit '/en/library/computers'" is actually calling the show action in your controller. If you are using a restful path that accesses the show action, use that in place of your current url path so it looks something like:
visit library_path('computers')
Next throw some debugger text (puts 'blah') inside of your show method that you are testing against and make sure it is coming up. Maybe by calling a strict path does something weird with bypassing before_filters.
UPDATE:
Looks like your controller might be no be interpreting 'computers' as an id. Inside your routes, what if you add a member route to your libraries resource:
resources :libraries do
member do
get :computers
end
end
And in your controller your add:
def computers
@categories = Category.all
end
And change you skip_before_filter to use :computers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With