Sha256: f852ac800caadd772bcffc759061817ecef3a7c3263da889e99293902106f863

Contents?: true

Size: 827 Bytes

Versions: 16

Compression:

Stored size: 827 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?
      expect(tree.leaf_count).to eq(2)
    end

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

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
couch_potato-1.17.0 spec/unit/callbacks_spec.rb
couch_potato-1.16.0 spec/unit/callbacks_spec.rb
couch_potato-1.15.0 spec/unit/callbacks_spec.rb
couch_potato-1.14.0 spec/unit/callbacks_spec.rb
couch_potato-1.13.0 spec/unit/callbacks_spec.rb
couch_potato-1.12.1 spec/unit/callbacks_spec.rb
couch_potato-1.12.0 spec/unit/callbacks_spec.rb
couch_potato-1.11.0 spec/unit/callbacks_spec.rb
couch_potato-1.10.1 spec/unit/callbacks_spec.rb
couch_potato-1.10.0 spec/unit/callbacks_spec.rb
couch_potato-1.9.0 spec/unit/callbacks_spec.rb
couch_potato-1.7.1 spec/unit/callbacks_spec.rb
couch_potato-1.7.0 spec/unit/callbacks_spec.rb
couch_potato-1.6.5 spec/unit/callbacks_spec.rb
couch_potato-1.6.4 spec/unit/callbacks_spec.rb
couch_potato-1.6.3 spec/unit/callbacks_spec.rb