This project is archived and is in readonly mode.

#4598 open
David Chelimsky

default_scope treats hashes and relations inconsistently when overwriting

Reported by David Chelimsky | May 14th, 2010 @ 10:41 PM | in 3.1

In working on #4583, Brian and I discovered some inconsistent behavior. Here are a couple of tests that should both behave the same way, but one passes and one fails:

http://github.com/dchelimsky/rails/commit/6180043572ff30a2e01690b86...

require "cases/helper"
require 'models/developer'

class ArelBugTest < ActiveRecord::TestCase
  fixtures :developers

  # We would expect both to pass or both to fail, but one passes and one fails.

  # fails
  def test_default_scope_called_twice_with_relations
    klass = Class.new(Developer)
    klass.class_eval do 
      default_scope where(:name => 'David')
      default_scope where(:name => 'Jamis')
    end
    assert_equal ["Jamis"], klass.all.map(&:name).uniq.sort
  end
  
  # passes
  def test_default_scope_called_twice_with_hashes
    klass = Class.new(Developer)
    klass.class_eval do 
      default_scope :conditions => { :name => 'David' }
      default_scope :conditions => { :name => 'Jamis' }
    end
    assert_equal ["Jamis"], klass.all.map(&:name).uniq.sort
  end
end

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages