diff options
author | Louise Crow <louise.crow@gmail.com> | 2012-08-14 16:31:03 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2012-08-14 16:31:03 +0100 |
commit | 21082cc55d3d61edce660ea7a73ec80380359e2f (patch) | |
tree | 61fa475667267db3c88088945adb70b39a4bc0bf /spec/models/censor_rule_spec.rb | |
parent | 2aa3d7bfd76e774555207a81cd5e39513f965bf1 (diff) |
Add basic validation for regexp censor rules that a valid regexp can be created with the text of the rule.
Diffstat (limited to 'spec/models/censor_rule_spec.rb')
-rw-r--r-- | spec/models/censor_rule_spec.rb | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/spec/models/censor_rule_spec.rb b/spec/models/censor_rule_spec.rb index 443bbe449..471a73fa2 100644 --- a/spec/models/censor_rule_spec.rb +++ b/spec/models/censor_rule_spec.rb @@ -73,6 +73,40 @@ end describe 'when validating rules' do + describe 'when validating a regexp rule' do + + before do + @censor_rule = CensorRule.new(:regexp => true, + :text => '*') + end + + it 'should try to create a regexp from the text' do + Regexp.should_receive(:new).with('*', Regexp::MULTILINE) + @censor_rule.valid? + end + + describe 'if a regexp error is produced' do + + it 'should add an error message to the text field with the regexp error message' do + Regexp.stub!(:new).and_raise(RegexpError.new("very bad regexp")) + @censor_rule.valid?.should == false + @censor_rule.errors.on(:text).should == "very bad regexp" + end + + end + + describe 'if no regexp error is produced' do + + it 'should not add any error message to the text field' do + Regexp.stub!(:new) + @censor_rule.valid? + @censor_rule.errors.on(:text).should == nil + end + + end + + end + describe 'when the allow_global flag has been set' do before do @@ -89,7 +123,7 @@ describe 'when validating rules' do describe 'when the allow_global flag has not been set' do before do - @censor_rule = CensorRule.new + @censor_rule = CensorRule.new(:text => '/./') end it 'should not allow a global text censor rule (without user_id, request_id or public_body_id)' do |