Sha256: 9998a6e55efe03ddc23a843edb6f9f4da745c9cc10b64fcf20493fc46f3d2750

Contents?: true

Size: 693 Bytes

Versions: 5

Compression:

Stored size: 693 Bytes

Contents

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

describe 'before_validation callback' do
  before(:each) do
    @tree = Tree.new(:leaf_count => 1, :root_count => 1)
  end

  class Tree
    include CouchPotato::Persistence

    before_validation :water!, lambda {|tree| tree.root_count += 1 }

    property :leaf_count
    property :root_count

    def water!
      self.leaf_count += 1
    end
  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

5 entries across 5 versions & 1 rubygems

Version Path
couch_potato-0.2.27 spec/unit/callbacks_spec.rb
couch_potato-0.2.26 spec/unit/callbacks_spec.rb
couch_potato-0.2.25 spec/unit/callbacks_spec.rb
couch_potato-0.2.24 spec/unit/callbacks_spec.rb
couch_potato-0.2.23 spec/unit/callbacks_spec.rb