Sha256: 1d1a0a8c393791fa90945f052151a91f3fd0386f1fbd818d0ff9ac03c910955c

Contents?: true

Size: 664 Bytes

Versions: 3

Compression:

Stored size: 664 Bytes

Contents

require '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

3 entries across 3 versions & 1 rubygems

Version Path
couch_potato-0.2.30 spec/unit/callbacks_spec.rb
couch_potato-0.2.29 spec/unit/callbacks_spec.rb
couch_potato-0.2.28 spec/unit/callbacks_spec.rb