Spaces:
Paused
Paused
File size: 1,799 Bytes
874ae95 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | require 'rails_helper'
describe ApplicationController do
describe '#current_school' do
let!(:first_school) { create :school }
let!(:second_school) { create :school }
let!(:third_school) { create :school }
let!(:second_school_domain) { create :domain, :primary, fqdn: 'www.second.localhost', school: second_school }
let!(:third_school_domain) { create :domain, :primary, fqdn: 'www.third.localhost', school: third_school }
context 'when multitenancy is turned on' do
around(:each) do |example|
begin
current = Settings.multitenancy
Settings.multitenancy = true
example.run
ensure
Settings.multitenancy = current
end
end
context 'when the current domain belongs to second school' do
controller do
def current_domain
Domain.find_by(fqdn: 'www.second.localhost')
end
end
it 'returns the second school' do
expect(subject.current_school).to eq(second_school)
end
end
context 'when the current domain belongs to the third school' do
controller do
def current_domain
Domain.find_by(fqdn: 'www.third.localhost')
end
end
it 'returns the third school' do
expect(subject.current_school).to eq(third_school)
end
end
end
context 'when multitenancy is turned off' do
around(:each) do |example|
begin
current = Settings.multitenancy
Settings.multitenancy = false
example.run
ensure
Settings.multitenancy = current
end
end
it 'returns the first school' do
expect(subject.current_school).to eq(first_school)
end
end
end
end
|