Sha256: 52a6833a186e80ce70f2a16c0ee8208d4926f6bccae543fc530c0f22cf6412d4

Contents?: true

Size: 872 Bytes

Versions: 3

Compression:

Stored size: 872 Bytes

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
      # DataStore.new.drop_database
      # $page.instance_variable_set('@store', nil)

      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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
volt-0.8.27.beta6 spec/models/associations_spec.rb
volt-0.8.27.beta5 spec/models/associations_spec.rb
volt-0.8.27.beta4 spec/models/associations_spec.rb