Sha256: f91a0c0205a07077df1e94d442b08e849d1b0615ef00bd939a0878e13f3b3fab

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

describe 'MotionBindable::StrategyHelpers' do
  class TestObject
    attr_accessor :prop
  end

  class TestModel
    include MotionModel::Model
    include MotionModel::ArrayModelAdapter
    columns :prop
  end

  class TestStrategy < MotionBindable::Strategy
    include MotionBindable::StrategyHelpers

    def observe(&block)
      observe_object(&block)
    end
  end

  describe '#observe_object' do
    describe 'normal object' do
      before do
        @object = TestObject.new
        @response = nil
        @strategy = TestStrategy.new(@object, :prop)
      end

      it 'should call the cb for changes' do
        @strategy.observe { |old, new| @response = new }
        @object.prop = 'updated'
        wait(0.5) do
          @response.should.equal 'updated'
        end
      end
    end

    describe 'MotionModel' do
      before do
        @object = TestModel.new
        @response = nil
        @strategy = TestStrategy.new(@object, :prop)
      end

      it 'should call the cb for changes' do
        @strategy.observe { |old, new| @response = new }
        @object.prop = 'updated'
        @object.save
        wait(0.5) { @response.should.equal 'updated' }
      end

      it 'should not turn the model.class into a KVO thingy' do
        @strategy.observe { |old, new| @response = new }
        @object.is_a?(MotionModel::Model).should.equal true
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
motion_bindable-0.3.0 spec/strategy_helpers_spec.rb