Sha256: b99993f24019adaa707683e70ff5a5a476e9dbb7395ad57ca37eaa1b1a3d54e2

Contents?: true

Size: 1.43 KB

Versions: 23

Compression:

Stored size: 1.43 KB

Contents

require 'volt/models'

describe ReactiveGenerator do
  before do
    @object = {
      name: ReactiveValue.new('bob'),
      location: {
        town: ReactiveValue.new('Bozeman'),
        places: [
          ReactiveValue.new('The Garage'),
          ReactiveValue.new('Ale Works')
        ]
      }
    }
  end

  it "should find all reactive values in any object" do
    values = ReactiveGenerator.find_reactives(@object)

    expect(values.map(&:cur)).to eq(['bob', 'Bozeman', 'The Garage', 'Ale Works'])
  end

  it "should return a reactive value that changes whenever a child reactive value changes" do
    values = ReactiveGenerator.from_hash(@object)

    count = 0
    values.on('changed') { count += 1 }
    expect(count).to eq(0)

    @object[:name].cur = 'jim'

    expect(count).to eq(1)

    @object[:location][:places].last.cur = 'Starkies'
    expect(count).to eq(2)

    expect(values.to_h).to eq({
      name: 'jim',
      location: {
        town: 'Bozeman',
        places: [
          'The Garage',
          'Starkies'
        ]
      }
    })
  end

  it "should optionally return a normal hash if there are no child reactive values" do
    values = ReactiveGenerator.from_hash({name: 'bob'})
    expect(values.reactive?).to eq(true)
    expect(values.is_a?(Hash)).to eq(false)

    values = ReactiveGenerator.from_hash({name: 'bob'}, true)
    expect(values.reactive?).to eq(false)
    expect(values.is_a?(Hash)).to eq(true)
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
volt-0.7.23 spec/models/reactive_generator_spec.rb
volt-0.7.22 spec/models/reactive_generator_spec.rb
volt-0.7.21 spec/models/reactive_generator_spec.rb
volt-0.7.20 spec/models/reactive_generator_spec.rb
volt-0.7.19 spec/models/reactive_generator_spec.rb
volt-0.7.18 spec/models/reactive_generator_spec.rb
volt-0.7.17 spec/models/reactive_generator_spec.rb
volt-0.7.16 spec/models/reactive_generator_spec.rb
volt-0.7.15 spec/models/reactive_generator_spec.rb
volt-0.7.14 spec/models/reactive_generator_spec.rb
volt-0.7.13 spec/models/reactive_generator_spec.rb
volt-0.7.12 spec/models/reactive_generator_spec.rb
volt-0.7.10 spec/models/reactive_generator_spec.rb
volt-0.7.9 spec/models/reactive_generator_spec.rb
volt-0.7.8 spec/models/reactive_generator_spec.rb
volt-0.7.7 spec/models/reactive_generator_spec.rb
volt-0.7.6 spec/models/reactive_generator_spec.rb
volt-0.7.5 spec/models/reactive_generator_spec.rb
volt-0.7.4 spec/models/reactive_generator_spec.rb
volt-0.7.3 spec/models/reactive_generator_spec.rb