Sha256: 92c2a921de3778c8c4b0b4db89a96ce8c3f42522b93140677ee22cc945cac2ad

Contents?: true

Size: 964 Bytes

Versions: 3

Compression:

Stored size: 964 Bytes

Contents

# -*- encoding : utf-8 -*-
require 'guacamole'
require 'acceptance/spec_helper'

require 'fabricators/book'
require 'fabricators/author'

class AuthorsCollection
  include Guacamole::Collection

  map do
    referenced_by :books
  end
end

class BooksCollection
  include Guacamole::Collection

  map do
    references :author
  end
end

describe 'Associations' do
  let(:author) { Fabricate(:author_with_three_books) }

  it 'should load referenced models from the database' do
    the_author        = AuthorsCollection.by_key author.key
    books_from_author = BooksCollection.by_example(author_id: author.key).to_a

    expect(books_from_author).to eq the_author.books.to_a
  end

  it 'should load the referenced model from the database' do
    the_author           = AuthorsCollection.by_key author.key
    a_book_by_the_author = BooksCollection.by_example(author_id: author.key).to_a.first

    expect(a_book_by_the_author.author).to eq the_author
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
guacamole-0.3.0 spec/acceptance/association_spec.rb
guacamole-0.2.0 spec/acceptance/association_spec.rb
guacamole-0.1.0 spec/acceptance/association_spec.rb