aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/censor_rule.rb6
-rw-r--r--doc/CHANGES.md11
-rw-r--r--spec/models/censor_rule_spec.rb18
3 files changed, 31 insertions, 4 deletions
diff --git a/app/models/censor_rule.rb b/app/models/censor_rule.rb
index 3c5c77563..62cf8112f 100644
--- a/app/models/censor_rule.rb
+++ b/app/models/censor_rule.rb
@@ -30,7 +30,11 @@ class CensorRule < ActiveRecord::Base
attr_accessor :allow_global
validate :require_user_request_or_public_body, :unless => proc{ |rule| rule.allow_global == true }
validate :require_valid_regexp, :if => proc{ |rule| rule.regexp? == true }
- validates_presence_of :text
+
+ validates_presence_of :text,
+ :replacement,
+ :last_edit_comment,
+ :last_edit_editor
scope :global, {:conditions => {:info_request_id => nil,
:user_id => nil,
diff --git a/doc/CHANGES.md b/doc/CHANGES.md
index 237355c1d..748b37665 100644
--- a/doc/CHANGES.md
+++ b/doc/CHANGES.md
@@ -1,3 +1,14 @@
+# rails-3-develop
+
+## Highlighted Features
+
+## Upgrade Notes
+
+* `CensorRule` now validates the presence of all attributes at the model layer,
+ rather than only as a database constraint. If you have added a `CensorRule` in
+ your theme, you will now have to satisfy the additional validations on the
+ `:replacement`, `:last_edit_comment` and `:last_edit_editor` attributes.
+
# Version 0.19
## Highlighted Features
diff --git a/spec/models/censor_rule_spec.rb b/spec/models/censor_rule_spec.rb
index 5b41cc0d4..089f0648c 100644
--- a/spec/models/censor_rule_spec.rb
+++ b/spec/models/censor_rule_spec.rb
@@ -90,10 +90,22 @@ end
describe 'when validating rules' do
- it 'should be invalid without text' do
+ it 'must have the text to redact' do
censor_rule = CensorRule.new
- censor_rule.valid?.should == false
- censor_rule.errors[:text].should == ["can't be blank"]
+ expect(censor_rule).to have(1).error_on(:text)
+ expect(censor_rule.errors[:text]).to eql(["can't be blank"])
+ end
+
+ it 'must have a replacement' do
+ expect(CensorRule.new).to have(1).error_on(:replacement)
+ end
+
+ it 'must have a last_edit_editor' do
+ expect(CensorRule.new).to have(1).error_on(:last_edit_editor)
+ end
+
+ it 'must have a last_edit_comment' do
+ expect(CensorRule.new).to have(1).error_on(:last_edit_comment)
end
describe 'when validating a regexp rule' do