# Create multiple orgs # Create an item in each # Make sure you can only see one org's item in one org describe RailsMultitenant::GlobalContextRegistry::Current do class Parent include RailsMultitenant::GlobalContextRegistry::Current attr_accessor :id def initialize(id: 0) @id = id end end class Dependent include RailsMultitenant::GlobalContextRegistry::Current global_context_dependent_on Parent end class StepParent < Parent end it 'current' do expect(Parent.current.id).to eq(0) expect(Parent.current).to eq(Parent.current) end it 'current=' do Parent.current = Parent.new(id: 42) expect(Parent.current.id).to eq(42) end it 'clear_current!' do Parent.clear_current! expect(Parent.current.id).to eq(0) end it 'current?' do Parent.clear_current! expect(Parent.current?).to be_falsey Parent.current = Parent.new(id: 42) expect(Parent.current?).to be_truthy end context 'with dependencies' do it 'dependent is cleared' do Parent.current = Parent.new(id: 78) Dependent.current = Dependent.new Parent.current = Parent.new(id: 78) expect(Dependent.current?).to be_falsey end it 'dependent subclass is cleared' do Parent.current = Parent.new(id: 78) Dependent.current = Dependent.new Parent.current = StepParent.new(id: 78) expect(Dependent.current?).to be_falsey end #let(dependent_id) { Organization.current.id } it 'dependent model subclass is cleared' do #Organization.current = Organization.create! DependsOnOrganization.current = DependsOnOrganization.create! dependent_id = DependsOnOrganization.current.object_id SubOrganization.current = SubOrganization.create! expect(DependsOnOrganization.current.object_id).not_to eq(dependent_id) end end end