Sha256: 2af1b726e859a902febced8de04cd3260c17ee2a7ef17b70ef4e9a839a02b742

Contents?: true

Size: 702 Bytes

Versions: 19

Compression:

Stored size: 702 Bytes

Contents

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

class Tree
  include CouchPotato::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

19 entries across 19 versions & 3 rubygems

Version Path
andrewtimberlake-couch_potato-0.2.8.1 spec/unit/callbacks_spec.rb
andrewtimberlake-couch_potato-0.2.8.2 spec/unit/callbacks_spec.rb
andrewtimberlake-couch_potato-0.2.8.3 spec/unit/callbacks_spec.rb
andrewtimberlake-couch_potato-0.2.8.4 spec/unit/callbacks_spec.rb
langalex-couch_potato-0.2.11 spec/unit/callbacks_spec.rb
langalex-couch_potato-0.2.12 spec/unit/callbacks_spec.rb
langalex-couch_potato-0.2.8 spec/unit/callbacks_spec.rb
langalex-couch_potato-0.2.9 spec/unit/callbacks_spec.rb
couch_potato-0.2.22 spec/unit/callbacks_spec.rb
couch_potato-0.2.21 spec/unit/callbacks_spec.rb
couch_potato-0.2.20 spec/unit/callbacks_spec.rb
couch_potato-0.2.19 spec/unit/callbacks_spec.rb
couch_potato-0.2.18 spec/unit/callbacks_spec.rb
couch_potato-0.2.17 spec/unit/callbacks_spec.rb
couch_potato-0.2.16 spec/unit/callbacks_spec.rb
couch_potato-0.2.15 spec/unit/callbacks_spec.rb
couch_potato-0.2.14 spec/unit/callbacks_spec.rb
couch_potato-0.2.13 spec/unit/callbacks_spec.rb
couch_potato-0.2.12 spec/unit/callbacks_spec.rb