Destroy associated rules when a channel is destroyed
This commit is contained in:
parent
bdb81191d7
commit
2275b048f9
|
@ -10,6 +10,11 @@ class DiscourseChat::Channel < DiscourseChat::PluginModel
|
|||
self.data = {} if self.data.nil?
|
||||
end
|
||||
|
||||
after_destroy :destroy_rules
|
||||
def destroy_rules
|
||||
rules.destroy_all()
|
||||
end
|
||||
|
||||
validate :provider_valid?, :data_valid?
|
||||
|
||||
def provider_valid?
|
||||
|
|
|
@ -52,6 +52,17 @@ RSpec.describe DiscourseChat::Channel do
|
|||
expect(channel.rules.size).to eq(2)
|
||||
end
|
||||
|
||||
it 'destroys its rules on destroy' do
|
||||
channel = DiscourseChat::Channel.create({provider:'dummy'})
|
||||
expect(channel.rules.size).to eq(0)
|
||||
rule1 = DiscourseChat::Rule.create(channel: channel)
|
||||
rule2 = DiscourseChat::Rule.create(channel: channel)
|
||||
|
||||
expect(DiscourseChat::Rule.with_channel(channel).exists?).to eq(true)
|
||||
channel.destroy()
|
||||
expect(DiscourseChat::Rule.with_channel(channel).exists?).to eq(false)
|
||||
end
|
||||
|
||||
describe 'validations' do
|
||||
let(:channel) { }
|
||||
|
||||
|
|
Loading…
Reference in New Issue