Sha256: a66161cf4efc2962f96971816f017bfbe85a6dcfcfdcd98aab45a90fcc8ceb64

Contents?: true

Size: 1.84 KB

Versions: 2

Compression:

Stored size: 1.84 KB

Contents

# 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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rails_multitenant-0.9.0 spec/current_spec.rb.dis
rails_multitenant-0.7.2 spec/current_spec.rb.dis