Sha256: c1d068c0f626252944662bf231ca80a0fcdad6020fc2a01ef98d85854992b10f

Contents?: true

Size: 818 Bytes

Versions: 30

Compression:

Stored size: 818 Bytes

Contents

require 'spec_helper'

describe 'callbacks' do
  class Tree
    include CouchPotato::Persistence

    before_validation :grow_leaf

    property :leaf_count
    property :watered

    def grow_leaf
      self.leaf_count ||= 0
      self.leaf_count += 1
    end
  end
  
  class AppleTree < Tree
    attr_accessor :watered
    
    before_validation :water
    
    def water
      self.watered = true
    end
    
    def watered?
      watered
    end
  end

  context 'inheritance' do
    it "should call the callbacks of the super class" do
      tree = AppleTree.new :leaf_count => 1
      tree.valid?
      tree.leaf_count.should == 2
    end

    it "should call the callbacks of the child class" do
      tree = AppleTree.new :leaf_count => 1
      tree.valid?
      tree.should be_watered
    end
  end
  
end

Version data entries

30 entries across 30 versions & 3 rubygems

Version Path
couch_potato-1.4.0 spec/unit/callbacks_spec.rb
couch_potato-1.3.0 spec/unit/callbacks_spec.rb
couch_potato-1.2.0 spec/unit/callbacks_spec.rb
couch_potato-1.1.4 spec/unit/callbacks_spec.rb
couch_potato-1.1.2 spec/unit/callbacks_spec.rb
couch_potato-1.1.1 spec/unit/callbacks_spec.rb
couch_potato-1.1.0 spec/unit/callbacks_spec.rb
couch_potato-1.0.1 spec/unit/callbacks_spec.rb
couch_potato-1.0.0 spec/unit/callbacks_spec.rb
couch_potato-0.7.1 spec/unit/callbacks_spec.rb
couch_potato-0.7.0 spec/unit/callbacks_spec.rb
couch_potato-0.7.0.pre.1 spec/unit/callbacks_spec.rb
couch_potato-0.6.0 spec/unit/callbacks_spec.rb
couch_potato-0.5.7 spec/unit/callbacks_spec.rb
couch_potato-rails2-0.5.10 spec/unit/callbacks_spec.rb
couch_potato-rails2-0.5.9 spec/unit/callbacks_spec.rb
couch_potato-rails2-0.5.8 spec/unit/callbacks_spec.rb
couch_potato-rails2-0.5.7 spec/unit/callbacks_spec.rb
couch_potato-rails2-0.5.6 spec/unit/callbacks_spec.rb
couch_potato-0.5.6 spec/unit/callbacks_spec.rb