Maintenance: Improve handling of config updates.
This commit is contained in:
parent
1cfd323845
commit
a7f312bec7
2 changed files with 34 additions and 2 deletions
|
@ -183,7 +183,7 @@ reload config settings
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
# notify clients about public config changes
|
# Notify clients about config changes.
|
||||||
def check_broadcast
|
def check_broadcast
|
||||||
return true if frontend != true
|
return true if frontend != true
|
||||||
|
|
||||||
|
@ -196,7 +196,7 @@ reload config settings
|
||||||
event: 'config_update',
|
event: 'config_update',
|
||||||
data: { name: name, value: value }
|
data: { name: name, value: value }
|
||||||
},
|
},
|
||||||
'public'
|
preferences[:authentication] ? 'authenticated' : 'public'
|
||||||
)
|
)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
|
@ -56,4 +56,36 @@ RSpec.describe Setting, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'check_broadcast' do
|
||||||
|
context 'when setting is non-frontend' do
|
||||||
|
subject(:setting) { build(:setting, name: 'broadcast_test', state: 'foo', frontend: false) }
|
||||||
|
|
||||||
|
it 'does not broadcast' do
|
||||||
|
allow(Sessions).to receive(:broadcast)
|
||||||
|
setting.save
|
||||||
|
expect(Sessions).not_to have_received(:broadcast)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when setting is public' do
|
||||||
|
subject(:setting) { build(:setting, name: 'broadcast_test', state: 'foo', frontend: true) }
|
||||||
|
|
||||||
|
it 'broadcasts to public' do
|
||||||
|
allow(Sessions).to receive(:broadcast)
|
||||||
|
setting.save
|
||||||
|
expect(Sessions).to have_received(:broadcast).with({ data: { name: 'broadcast_test', value: 'foo' }, event: 'config_update' }, 'public')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when setting requires authentication' do
|
||||||
|
subject(:setting) { build(:setting, name: 'broadcast_test', state: 'foo', frontend: true, preferences: { authentication: true }) }
|
||||||
|
|
||||||
|
it 'broadcasts to authenticated only' do
|
||||||
|
allow(Sessions).to receive(:broadcast)
|
||||||
|
setting.save
|
||||||
|
expect(Sessions).to have_received(:broadcast).with({ data: { name: 'broadcast_test', value: 'foo' }, event: 'config_update' }, 'authenticated')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue