Sha256: 945781301f8fbf8d1832b37714e3e71ee75170320015ab0ae7dc3de05ab87c97

Contents?: true

Size: 1.1 KB

Versions: 7

Compression:

Stored size: 1.1 KB

Contents

class FakeBound
  attr_accessor :attribute
end

class FakeModel
  include MotionBindable::Bindable
  attr_accessor :attribute
  attr_accessor :nested
end

describe 'MotionBindable::Strategies::Proc' do

  before do
    MotionBindable::Strategy.register_strategy(
      MotionBindable::Strategies::Proc,
      Proc
    )
  end

  context 'nested model' do

    before do
      @bound = FakeBound.new
      @bound.attribute = 'Testing.'
      @object = FakeModel.new
      @object.nested = FakeModel.new
    end

    context 'is bound' do

      before do
        @object.bind_attributes({
          attribute: proc { @bound.attribute },
          nested: {
            attribute: proc { @bound.attribute }
          }
        })
      end

      it 'should refresh upon bind' do
        @object.attribute.should.equal 'Testing.'
        @object.nested.attribute.should.equal 'Testing.'
      end

      it 'can refresh manually' do
        @bound.attribute = 'Updated.'
        @object.refresh.attribute.should.equal 'Updated.'
        @object.refresh.nested.attribute.should.equal 'Updated.'
      end

    end

  end


end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
motion_bindable-0.1.1 spec/proc_strategy_spec.rb
motion_bindable-0.1.0 spec/proc_strategy_spec.rb
motion_bindable-0.0.6 spec/proc_strategy_spec.rb
motion_bindable-0.0.5 spec/proc_strategy_spec.rb
motion_bindable-0.0.4 spec/proc_strategy_spec.rb
motion_bindable-0.0.3 spec/proc_strategy_spec.rb
motion_bindable-0.0.2 spec/proc_strategy_spec.rb