diff options
author | Seb Bacon <seb.bacon@gmail.com> | 2012-07-12 13:04:27 +0100 |
---|---|---|
committer | Seb Bacon <seb.bacon@gmail.com> | 2012-07-13 08:21:15 +0100 |
commit | 088bc961328f4d876971994102cde52c1ad49246 (patch) | |
tree | 26ded6a4940a23f898a688ea0b6041a21f455a53 /spec/models/censor_rule_spec.rb | |
parent | 39fdae7de23244b47581c197e1d78506aebf5af1 (diff) |
Support regular expressions in CensorRules; also support 'global' CensorRules that aren't attached to a User or Request or Public Body (but don't expose this in the admin UI). Fixes #33
Diffstat (limited to 'spec/models/censor_rule_spec.rb')
-rw-r--r-- | spec/models/censor_rule_spec.rb | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/spec/models/censor_rule_spec.rb b/spec/models/censor_rule_spec.rb index 44087c5a6..d5797ec74 100644 --- a/spec/models/censor_rule_spec.rb +++ b/spec/models/censor_rule_spec.rb @@ -21,5 +21,45 @@ describe CensorRule, "substituting things" do body.should == "I don't know why you say xxxxxxx" body.should_not == orig_body # be sure duplicated as expected end + + context "when regexp type" do + before do + CensorRule.delete_all + CensorRule.create(:last_edit_editor => 1, + :last_edit_comment => 'comment') + @censor_rule = CensorRule.new(:last_edit_editor => 1, + :last_edit_comment => 'comment') + @censor_rule.text = "--PRIVATE.*--PRIVATE" + @censor_rule.replacement = "--REMOVED\nHidden private info\n--REMOVED" + @censor_rule.regexp = true + end + + it "replaces with the regexp" do + body = +<<BODY +Some public information +--PRIVATE +Some private information +--PRIVATE +BODY + @censor_rule.apply_to_text!(body) + body.should == +<<BODY +Some public information +--REMOVED +Hidden private info +--REMOVED +BODY + end + + it "validates without info_request, user or public body set" do + @censor_rule.save.should be_true + end + + it "has scope for regexps" do + @censor_rule.save + CensorRule.regexps.all.should == [@censor_rule] + end + end end - + |