diff options
-rw-r--r-- | app/models/censor_rule.rb | 6 | ||||
-rw-r--r-- | doc/CHANGES.md | 11 | ||||
-rw-r--r-- | spec/models/censor_rule_spec.rb | 33 |
3 files changed, 43 insertions, 7 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..4ecd2d3e1 100644 --- a/spec/models/censor_rule_spec.rb +++ b/spec/models/censor_rule_spec.rb @@ -90,17 +90,32 @@ 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 before do @censor_rule = CensorRule.new(:regexp => true, - :text => '*') + :text => '*', + :replacement => '---', + :last_edit_comment => 'test', + :last_edit_editor => 'rspec') end it 'should try to create a regexp from the text' do @@ -133,7 +148,10 @@ describe 'when validating rules' do describe 'when the allow_global flag has been set' do before do - @censor_rule = CensorRule.new(:text => 'some text') + @censor_rule = CensorRule.new(:text => 'some text', + :replacement => '---', + :last_edit_comment => 'test', + :last_edit_editor => 'rspec') @censor_rule.allow_global = true end @@ -146,7 +164,10 @@ describe 'when validating rules' do describe 'when the allow_global flag has not been set' do before do - @censor_rule = CensorRule.new(:text => '/./') + @censor_rule = CensorRule.new(:text => '/./', + :replacement => '---', + :last_edit_comment => 'test', + :last_edit_editor => 'rspec') end it 'should not allow a global text censor rule (without user_id, request_id or public_body_id)' do |