Skip to content

Instantly share code, notes, and snippets.

@kitop

kitop/repro.rb

Last active Oct 17, 2020
Embed
What would you like to do?
Mongo relationship issue
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'mongoid', '~> 7.1.4'
gem 'minitest', '~> 5.14.1', require: ['minitest', 'minitest/autorun']
end
class Parent
include Mongoid::Document
belongs_to :child
end
class Child
include Mongoid::Document
has_one :parent
def a_public_method
'public'
end
private
def a_private_method
'private'
end
end
class TestRelationships < Minitest::Test
def test_child_private_methods_stay_private
parent = Parent.new
child = Child.new
parent.child = child
assert_raises NoMethodError do
child.a_private_method
end
assert_raises NoMethodError do
parent.child.a_private_method
end
end
def test_child_methods_are_defined
parent = Parent.new
child = Child.new
parent.child = child
assert_equal 'method', defined?(child.a_public_method)
assert_equal 'method', defined?(parent.child.a_public_method)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.