rails/rails — pull request #7072 by beerlington (2012-07-17 00:45:51+00:00)
Title: Use database value for uniqueness validation scope

Fixes issue an with overrding ActiveRecord reader methods with a composed object and using that attribute as the scope of a validates_uniqueness_of validation. This changes the validation to use the attribute's database value as opposed to the return value of the method call.

From the [original discussion](https://groups.google.com/forum/?fromgroups#!topic/rubyonrails-core/Z-k4zyW7XvI):

The following code will raise "TypeError: Cannot visit CatBreed" when trying to create a new Cat:

```ruby
class Cat < ActiveRecord::Base
validates :name, :uniqueness => { :scope => [:breed] }

def breed
CatBreed.new(super)
end
end

class CatBreed
def initialize(breed)
@breed = breed
end

def to_s
@breed
end
end
```