fire callbacks only when setting was stored sucessfully

pull/1081/head
Martin Linkhorst 11 years ago
parent 48abe7d64c
commit dda5226dff
  1. 9
      app/models/setting.rb
  2. 6
      spec/models/setting_spec.rb

@ -155,9 +155,12 @@ class Setting < ActiveRecord::Base
old_value = setting.value
setting.value = (v ? v : "")
Rails.cache.delete(cache_key(name))
setting.save
fire_callbacks(name, setting.value, old_value)
setting.value
if setting.save
fire_callbacks(name, setting.value, old_value)
setting.value
else
old_value
end
end
# Check whether a setting was defined

@ -108,6 +108,12 @@ describe Setting do
expect(collector).to_not be_empty
end
it "calls no callback on invalid setting" do
Setting.any_instance.stub(:valid?).and_return(false)
Setting.notified_events = 'invalid'
expect(collector).to be_empty
end
it "calls multiple callbacks when a setting is set" do
Setting.notified_events = [:some_event]
Setting.notified_events = [:some_event]

Loading…
Cancel
Save