require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe CensorRule, "substituting things" do describe 'when using a text rule' do before do @censor_rule = CensorRule.new @censor_rule.text = "goodbye" @censor_rule.replacement = "hello" end it 'should do basic text substitution' do body = "I don't know why you say goodbye" @censor_rule.apply_to_text!(body) body.should == "I don't know why you say hello" end it 'should keep size same for binary substitution' do body = "I don't know why you say goodbye" orig_body = body.dup @censor_rule.apply_to_binary!(body) body.size.should == orig_body.size body.should == "I don't know why you say xxxxxxx" body.should_not == orig_body # be sure duplicated as expected end end describe "when using a regular expression rule" do before do @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 @body = < true, :text => 'hide me', :replacement => 'nothing to see here', :last_edit_editor => 1, :last_edit_comment => 'comment') @user_rule = CensorRule.create!(:user_id => 1, :text => 'hide me', :replacement => 'nothing to see here', :last_edit_editor => 1, :last_edit_comment => 'comment') end it 'should include an instance without user_id, request_id or public_body_id' do CensorRule.global.all.include?(@global_rule).should == true end it 'should not include a request with user_id' do CensorRule.global.all.include?(@user_rule).should == false end after do @global_rule.destroy if @global_rule @user_rule.destroy if @user_rule end end end