aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/censor_rule_spec.rb
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2015-06-23 10:01:49 +0100
committerLouise Crow <louise.crow@gmail.com>2015-06-23 10:01:49 +0100
commitac59a76cc380af792a09e5dd82b8402dc966af42 (patch)
tree8c0640c44a11ac6f9e42fdb7fc7e6618da2ed6fe /spec/models/censor_rule_spec.rb
parent994a13b08be94220512961b28de8fb95c8d181a5 (diff)
parent7983e37506f3fa16211255ef802bf50735adbdb8 (diff)
Merge branch 'binary-or-utf8-attachment-bodies' into develop
Diffstat (limited to 'spec/models/censor_rule_spec.rb')
-rw-r--r--spec/models/censor_rule_spec.rb58
1 files changed, 47 insertions, 11 deletions
diff --git a/spec/models/censor_rule_spec.rb b/spec/models/censor_rule_spec.rb
index 314b060d2..d308ac1b9 100644
--- a/spec/models/censor_rule_spec.rb
+++ b/spec/models/censor_rule_spec.rb
@@ -64,19 +64,35 @@ describe CensorRule, "substituting things" do
@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"
+ describe :apply_to_text do
+
+ 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
+
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
+ describe :apply_to_binary do
+
+ 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
+
+ it 'should handle a UTF-8 rule and ASCII-8BIT text' do
+ body = "I don't know why you say g‘oodbye"
+ body.force_encoding("ASCII-8BIT") if String.method_defined?(:encode)
+ @censor_rule.text = 'g‘oodbye'
+ @censor_rule.apply_to_binary!(body)
+ body.should == "I don't know why you say xxxxxxxxxx"
+ end
+
end
end
@@ -121,6 +137,26 @@ xxxxxxxxx
BODY
end
+ it "handles a UTF-8 rule with ASCII-8BIT text" do
+ @censor_rule.text = "--PRIVATE.*--P‘RIVATE"
+ @body =
+<<BODY
+Some public information
+--PRIVATE
+Some private information
+--P‘RIVATE
+BODY
+ @body.force_encoding('ASCII-8BIT') if String.method_defined?(:encode)
+ @censor_rule.apply_to_binary!(@body)
+ @body.should ==
+<<BODY
+Some public information
+xxxxxxxxx
+xxxxxxxxxxxxxxxxxxxxxxxx
+xxxxxxxxxxxx
+BODY
+ end
+
end
end