Sha256: 469e277eb007c55263e5ad4712affd64a01b4feb23b2b2c39da918544af2bf16

Contents?: true

Size: 702 Bytes

Versions: 7

Compression:

Stored size: 702 Bytes

Contents

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

class Tree
  include CouchTomato::Persistence
  before_validation :water!
  before_validation lambda {|tree| tree.root_count += 1 }
  
  property :leaf_count
  property :root_count
  
  def water!
    self.leaf_count += 1
  end
end


describe 'before_validation callback' do
  before :each do
    @tree = Tree.new(:leaf_count => 1, :root_count => 1)
  end
  
  it "should call water! when validated" do
    @tree.leaf_count.should == 1
    @tree.should be_valid
    @tree.leaf_count.should == 2
  end
  
  it "should call lambda when validated" do
    @tree.root_count.should == 1
    @tree.should be_valid
    @tree.root_count.should == 2
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
couch_tomato-0.2.0 spec/unit/callbacks_spec.rb
couch_tomato-0.1.5 spec/unit/callbacks_spec.rb
couch_tomato-0.1.4 spec/unit/callbacks_spec.rb
couch_tomato-0.1.3 spec/unit/callbacks_spec.rb
couch_tomato-0.1.2 spec/unit/callbacks_spec.rb
couch_tomato-0.1.1 spec/unit/callbacks_spec.rb
couch_tomato-0.1.0 spec/unit/callbacks_spec.rb