Sha256: 3caf188db1b45e5c959dc2c8c5b2883a60f59c89ac0d723324dafb17709db827

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 KB

Contents

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

describe 'MotionBindable::Strategies::UITextField' do

  before do
    MotionBindable::Strategy.register_strategy(
      MotionBindable::Strategies::UITextField,
      UITextField
    )

    @app = UIApplication.sharedApplication
    @text_field = UITextField.alloc.initWithFrame [[110, 60], [100, 26]]
  end

  context 'nested model' do

    before do
      @object = FakeModel.new
      @object.nested = FakeModel.new
    end

    context 'text set and then bound' do

      before do
        @text_field.text = 'Just testing.'
        @object.bind_attributes({
          attribute: @text_field,
          nested: {
            attribute: @text_field
          }
        })
      end

      it 'should update the root attribute' do
        @object.attribute.should.equal 'Just testing.'
      end

      it 'should update the nested attribute' do
        @object.nested.attribute.should.equal 'Just testing.'
      end

      context 'text field is updated' do

        before do
          @text_field.text = 'Updated.'
          NSNotificationCenter.defaultCenter.postNotificationName(
            UITextFieldTextDidChangeNotification, 
            object: @text_field
          )
        end

        it 'should update the root attribute' do
          @object.attribute.should.equal 'Updated.'
        end

        it 'should update the nested attribute' do
          @object.nested.attribute.should.equal 'Updated.'
        end

      end

    end

  end


end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
motion_bindable-0.0.6 spec/ui_text_field_strategy_spec.rb
motion_bindable-0.0.5 spec/ui_text_field_strategy_spec.rb