Has anybody noticed validates_uniqueness_of missing in rails 3.0 rc2? I'm not 
sure if this is a bug or I'm just doing something wrong.

Here's what I'm doing.

Class 1:

class Title < ActiveRecord::Base
  validates_length_of     :language, :is => 3
  validates_uniqueness_of :language, :scope => :book_id
  validate                :language, :is_proper_language_code
  
  validates_presence_of   :value
  
  belongs_to              :book
  
  def is_proper_language_code
    errors.add(:base, "invalid language code") unless !ISO_639::ISO_639_2.find{ 
|lang| lang[0] == self.language }.nil?
  end
end

Class 2:

class Book < ActiveRecord::Base
  attr_accessible       :titles
  
  validates_presence_of :titles
  
  has_many              :titles
end

Spec:

before(:each) do
    @valid_title_attributes = {:book_id => 1, :language => "eng", :value => 
"..."}
    
    @book = Book.new
    @book.titles.push(Title.new(@valid_title_attributes))
end

it "should not have multiple titles with same language attribute" do
      @book.titles.clear
      @book.titles.push(Title.new(@valid_title_attributes))
      @book.titles.push(Title.new(@valid_title_attributes))
      @book.should_not be_valid
      
      @book.titles.clear
      @book.titles.push(Title.new(@valid_title_attributes))
      @book.should be_valid
end

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to