#440 √ resolved
Kostia

Before-Filter are executed twice

Reported by Kostia | June 19th, 2008 @ 11:39 AM | in 1.1.5

Before-Filter in application.rb are exected twice.

$> cd /tmp
$> rails test
$> cd test
$> ./script/plugin install git://github.com/dchelimsky/rspec.git
$> ./script/plugin install git://github.com/dchelimsky/rspec-rails.git
$> ./script/generate rspec
$> ./script/generate rspec_scaffold User name:string
$> rake db:migrate

"app/controllers/aplication.rb":

class ApplicationController < ActionController::Base
  helper :all # include all helpers, all the time
  protect_from_forgery # :secret => 'c4dfc3d116d130ee911ec43dbbe448c3'
  before_filter :foo
  def foo; end
end

"spec/controllers/user_controller_spec.rb":

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe UsersController do
  describe "handling GET /users" do

    before(:each) do
      @user = mock_model(User)
      User.stub!(:find).and_return([@user])
    end
 
    def do_get
      get :index
    end
 
    it "should be successful" do
      do_get
      response.should be_success
    end

    it 'should call before filter foo only once' do
      controller.should_receive :foo
      do_get
    end

  (...)
$> rake spec

Will fail, because foo will be called twice.

Example in attachment.

Comments and changes to this ticket

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)