Sha256: 9d1370f00a8f22fe186b73cc6a42c2202e5566c29a5c00e25c876c44003bbcd6

Contents?: true

Size: 621 Bytes

Versions: 3

Compression:

Stored size: 621 Bytes

Contents

require File.expand_path("./helper", File.dirname(__FILE__))

class User < Ohm::Model
  collection :posts, :Post
end

class Post < Ohm::Model
  reference :user, :User
end

setup do
  u = User.create
  p = Post.create(user: u)

  [u, p]
end

test "basic shake and bake" do |u, p|
  assert u.posts.include?(p)

  p = Post[p.id]
  assert_equal u, p.user
end

test "memoization" do |u, p|
  # This will read the user instance once.
  p.user
  assert_equal p.user, p.instance_variable_get(:@_memo)[:user]

  # This will un-memoize the user instance
  p.user = u
  assert_equal nil, p.instance_variable_get(:@_memo)[:user]
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ohm-1.0.0.rc1 test/association.rb
ohm-1.0.0.alpha2 test/association.rb
ohm-1.0.0.alpha1 test/association.rb