Sha256: df6d94876bd076b59b9c0bdcaf6ec2e7083392c6f33742e4aedf6e4114bde887

Contents?: true

Size: 624 Bytes

Versions: 21

Compression:

Stored size: 624 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

21 entries across 21 versions & 1 rubygems

Version Path
ohm-1.4.0 test/association.rb
ohm-2.0.0.rc1 test/association.rb
ohm-2.0.0.alpha5 test/association.rb
ohm-2.0.0.alpha4 test/association.rb
ohm-2.0.0.alpha3 test/association.rb
ohm-2.0.0.alpha2 test/association.rb
ohm-2.0.0.alpha1 test/association.rb
ohm-1.3.2 test/association.rb
ohm-1.3.1 test/association.rb
ohm-1.3.0 test/association.rb
ohm-1.2.0 test/association.rb
ohm-1.1.2 test/association.rb
ohm-1.1.1 test/association.rb
ohm-1.1.0 test/association.rb
ohm-1.1.0.rc1 test/association.rb
ohm-1.0.2 test/association.rb
ohm-1.0.1 test/association.rb
ohm-1.0.0 test/association.rb
ohm-1.0.0.rc4 test/association.rb
ohm-1.0.0.rc3 test/association.rb