Sha256: e36156f23f09f2a33edea7c40ba9a0d5db2eaed6b419d64e043dc1ce84564ed2

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

require 'spec_helper'

class ::Person < Volt::Model
  has_many :addresses
end

class ::Address < Volt::Model
  belongs_to :person
end

describe Volt::Associations do
  if RUBY_PLATFORM != 'opal'
    before do
      store._people! << { name: 'Jimmy' }
      @person = store._people[0]
      @person._addresses! << { city: 'Bozeman' }
      @person._addresses << { city: 'Portland' }
    end

    it 'should associate via belongs_to' do
      address = store._addresses!.fetch_first.sync

      expect(address.person.sync.id).to eq(@person.id)
    end

    it 'should associate via has_many' do
      person = store._people!.fetch_first.sync

      addresses = person.addresses.fetch.sync
      expect(addresses.size).to eq(2)
      expect(addresses[0]._city).to eq('Bozeman')
    end

    it 'warns users if persistor is not a ModelStore' do
      store = Volt::Model.new({}, persistor: Volt::Persistors::Flash)
      expect do
        store.send(:association_with_root_model, :blah)
      end.to raise_error("blah currently only works on the store and page collection "\
                         "(support for other collections coming soon)")
    end

    # it 'should assign the reference_id for has_many' do
    #   bob = Person.new
    #   bob.addresses << {:street => '1234 awesome street'}
    #   puts "Bob: #{bob.inspect} - #{bob.addresses.size}"
    #   expect(bob.addresses[0].person_id).to eq(bob.id)
    #   expect(bob.id).to_not eq(nil)
    # end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
volt-0.9.3.pre2 spec/models/associations_spec.rb