Sha256: ba9441214cee5902c3b488e00da65e84d3328109d4a3320d055c8d5ca020a39a

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

require_relative './spec_helper'

describe Groovy::Model do

  before :all do
    Groovy.open('tmp/vector', 'vector_spec')
    load_schema! 'vector_spec'
  end

  after :all do
    Groovy.close('vector_spec')
  end

  def load_vector_schema!
    klass = Class.new
    Object.const_set("Comment", klass)
    Comment.class_eval do
      include Groovy::Model
      schema(context: 'vector_spec') do |t|
        t.string :content
        t.timestamps
      end
    end

    klass = Class.new;
    Object.const_set("User", klass)
    User.class_eval do
      include Groovy::Model
      schema(context: 'vector_spec') do |t|
        t.string :name
        t.timestamps
      end
    end

    Comment.add_reference :author, "Users"
    User.add_reference :comments, "Comments", type: :vector
  end

  describe 'relations' do

    before do
      load_vector_schema!
    end

    it 'loads records and keeps relations' do
      user = User.new(name: 'John')
      expect(user.save).to eq(true)
      comment = Comment.new(author: user, content: 'Hello there!')
      expect(comment.save).to eq(true)
      user.comments << comment
      expect(user.reload.comments).to eq([comment])
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
groovy-0.6.1 spec/vector_spec.rb