From 088bc961328f4d876971994102cde52c1ad49246 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Thu, 12 Jul 2012 13:04:27 +0100 Subject: 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 --- spec/models/censor_rule_spec.rb | 42 +++++++++++++++++++++++++++++++++++++++- spec/models/info_request_spec.rb | 21 +++++++++++++++++++- 2 files changed, 61 insertions(+), 2 deletions(-) (limited to 'spec/models') 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 = +< 'normal', + :awaiting_description => true, + :title => 'title', + :public_body => public_bodies(:geraldine_public_body), + :user_id => 1) + @censor_rule = CensorRule.create(:last_edit_editor => 1, + :last_edit_comment => 'comment', + :text => 'text', + :replacement => 'replacement', + :regexp => true) + end + it "applies regexp censor rule" do + body = 'text' + @info_request.apply_censor_rules_to_text!(body) + body.should == 'replacement' + end end - + end -- cgit v1.2.3 From 2ba82022c6f7d509d2b3a5972615340db5a8097a Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Fri, 13 Jul 2012 11:19:38 +0100 Subject: Misc fixes to get tests to pass - notably a MonkeyPatch to work around problem testing template results --- spec/models/info_request_spec.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'spec/models') diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb index 21b26f067..230884c38 100644 --- a/spec/models/info_request_spec.rb +++ b/spec/models/info_request_spec.rb @@ -398,6 +398,7 @@ describe InfoRequest do it 'should return true if it is awaiting description, isn\'t the holding pen and hasn\'t had an event in 21 days' do @info_request.is_old_unclassified?.should be_true end + end context "with regexp censor rule" do before do -- cgit v1.2.3