sanitize_email 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.8.7
4
3
  - 1.9.2
5
4
  - 1.9.3
6
5
  - 2.0.0
@@ -1,3 +1,13 @@
1
+ Version 1.1.1 - DEC.30.2013
2
+ * Cribbed have_body_text from email_spec gem by Peter Boling
3
+ * Cribbed have_header from email_spec gem by Peter Boling
4
+ * Cribbed MailExt from email_spec gem by Peter Boling
5
+ * All Rspec Matchers now working by Peter Boling
6
+ * All Test Helpers now working by Peter Boling
7
+ * All internal tests now use the matchers and helpers of sanitize_email by Peter Boling
8
+ * Development dependency on email_spec gem removed by Peter Boling
9
+ * Travis is getting barfy on my 1.8.7 build (passes locally) by Peter Boling
10
+
1
11
  Version 1.1.0 - DEC.30.2013
2
12
  * Add documentation for non-Rails setup by Peter Boling
3
13
  * Add documentation for using sanitize_email's bundled Rspec Matchers by Peter Boling
@@ -0,0 +1,12 @@
1
+ # Cribbed from email_spec gem
2
+ module SanitizeEmail::MailExt
3
+ def default_part
4
+ @default_part ||= html_part || text_part || self
5
+ end
6
+
7
+ def default_part_body
8
+ default_part.body
9
+ end
10
+ end
11
+
12
+ Mail::Message.send(:include, SanitizeEmail::MailExt)
@@ -1,11 +1,12 @@
1
1
  # Copyright (c) 2008-13 Peter H. Boling of RailsBling.com
2
2
  # Released under the MIT license
3
3
  require 'sanitize_email/test_helpers'
4
+ require 'sanitize_email/mail_ext'
4
5
 
5
6
  module SanitizeEmail
6
7
  module RspecMatchers
7
8
  include SanitizeEmail::TestHelpers
8
- [:from, :to, :cc, :bcc, :subject, :reply_to].each do |attribute|
9
+ [:from, :to, :cc, :bcc, :reply_to].each do |attribute|
9
10
  RSpec::Matchers.define "have_#{attribute}" do |matcher|
10
11
  match do |actual|
11
12
  email_matching(matcher, attribute, actual)
@@ -13,6 +14,14 @@ module SanitizeEmail
13
14
  end
14
15
  end
15
16
 
17
+ [:subject].each do |attribute|
18
+ RSpec::Matchers.define "have_#{attribute}" do |matcher|
19
+ match do |actual|
20
+ string_matching_attribute(matcher, attribute, actual)
21
+ end
22
+ end
23
+ end
24
+
16
25
  [:from, :to, :cc, :bcc, :subject, :reply_to].each do |attribute|
17
26
  RSpec::Matchers.define "be_#{attribute}" do |matcher|
18
27
  match do |actual|
@@ -29,5 +38,35 @@ module SanitizeEmail
29
38
  string_matching(matcher, :to_username, get_username(actual))
30
39
  end
31
40
  end
41
+
42
+ # Cribbed from email_spec gem
43
+ RSpec::Matchers.define "have_body_text" do |matcher|
44
+ match do |actual|
45
+ # Normalize all the whitespace, to improve match fuzz
46
+ if matcher.is_a?(String)
47
+ actual_text = actual.default_part_body.to_s.gsub(/\s+/, " ")
48
+ matcher_text = matcher.gsub(/\s+/, " ")
49
+ raise SanitizeEmail::TestHelpers::UnexpectedMailType, "Cannot find #{matcher} in body" unless actual_text.respond_to?(:include?)
50
+ actual_text.include?(matcher_text)
51
+ else
52
+ actual_text = actual.default_part_body.to_s
53
+ raise SanitizeEmail::TestHelpers::UnexpectedMailType, "Cannot find #{matcher} in body" unless actual_text.respond_to?(:=~)
54
+ !!(actual_text =~ matcher)
55
+ end
56
+ end
57
+ end
58
+
59
+ # Cribbed from email_spec gem
60
+ RSpec::Matchers.define "have_header" do |name, matcher|
61
+ match do |actual|
62
+ header = actual.header
63
+ if matcher.is_a?(String)
64
+ header[name].to_s == matcher
65
+ else
66
+ header[name].to_s =~ matcher
67
+ end
68
+ end
69
+ end
70
+
32
71
  end
33
72
  end
@@ -4,9 +4,17 @@ module SanitizeEmail
4
4
  module TestHelpers
5
5
  class UnexpectedMailType < StandardError; end
6
6
 
7
+ def string_matching_attribute(matcher, part, mail_or_part)
8
+ string_matching(matcher, part, mail_or_part.send(part))
9
+ end
10
+
7
11
  def string_matching(matcher, part, mail_or_part)
8
12
  if mail_or_part.respond_to?(:=~) # Can we match a regex against it?
9
- mail_or_part =~ Regexp.new(Regexp.escape(matcher))
13
+ if matcher.is_a?(Regexp)
14
+ mail_or_part =~ matcher
15
+ else
16
+ mail_or_part =~ Regexp.new(Regexp.escape(matcher))
17
+ end
10
18
  else
11
19
  raise UnexpectedMailType, "Cannot match #{matcher} for #{part}"
12
20
  end
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2008-13 Peter H. Boling of RailsBling.com
2
2
  # Released under the MIT license
3
3
  module SanitizeEmail
4
- VERSION = '1.1.0'
4
+ VERSION = '1.1.1'
5
5
  end
@@ -40,7 +40,6 @@ Gem::Specification.new do |s|
40
40
  s.add_development_dependency(%q<reek>, [">= 1.2.8"])
41
41
  s.add_development_dependency(%q<roodi>, [">= 2.1.0"])
42
42
  s.add_development_dependency(%q<rake>, [">= 0"])
43
- s.add_development_dependency(%q<email_spec>, [">= 0"])
44
43
  s.add_development_dependency "coveralls"
45
44
  end
46
45
 
@@ -98,6 +98,7 @@ describe SanitizeEmail do
98
98
  bcc 'same@example.org'
99
99
  reply_to 'same@example.org'
100
100
  subject 'original subject'
101
+ body 'funky fresh'
101
102
  end
102
103
  end
103
104
 
@@ -109,6 +110,7 @@ describe SanitizeEmail do
109
110
  bcc 'bcc@example.org'
110
111
  reply_to 'reply_to@example.org'
111
112
  subject 'original subject'
113
+ body 'funky fresh'
112
114
  end
113
115
  end
114
116
 
@@ -120,6 +122,7 @@ describe SanitizeEmail do
120
122
  bcc %w( bcc1@example.org bcc2@example.org bcc3@example.org )
121
123
  reply_to 'reply_to@example.org'
122
124
  subject 'original subject'
125
+ body 'funky fresh'
123
126
  end
124
127
  end
125
128
 
@@ -136,6 +139,7 @@ describe SanitizeEmail do
136
139
  it "should not alter non-sanitized attributes" do
137
140
  @email_message.should have_from('from@example.org')
138
141
  @email_message.should have_reply_to('reply_to@example.org')
142
+ @email_message.should have_body_text('funky fresh')
139
143
  end
140
144
  it "should not prepend overrides" do
141
145
  @email_message.should_not have_to_username("to at sanitize_email.org")
@@ -150,6 +154,7 @@ describe SanitizeEmail do
150
154
  @email_message.should have_cc("cc@example.org")
151
155
  @email_message.should have_bcc("bcc@example.org")
152
156
  @email_message.should have_subject("original subject")
157
+ @email_message.should have_body_text('funky fresh')
153
158
  end
154
159
  end
155
160
 
@@ -161,6 +166,7 @@ describe SanitizeEmail do
161
166
  it "should not alter non-sanitized attributes" do
162
167
  @email_message.should have_from('from@example.org')
163
168
  @email_message.should have_reply_to('reply_to@example.org')
169
+ @email_message.should have_body_text('funky fresh')
164
170
  end
165
171
  it "should not prepend overrides" do
166
172
  @email_message.should_not have_to_username("to at sanitize_email.org")
@@ -190,6 +196,7 @@ describe SanitizeEmail do
190
196
  it "should not alter non-sanitized attributes" do
191
197
  @email_message.should have_from('from@example.org')
192
198
  @email_message.should have_reply_to('reply_to@example.org')
199
+ @email_message.should have_body_text('funky fresh')
193
200
  end
194
201
  it "should not prepend overrides" do
195
202
  @email_message.should_not have_to_username("to at sanitize_email.org")
@@ -242,6 +249,7 @@ describe SanitizeEmail do
242
249
  it "should not alter non-sanitized attributes" do
243
250
  @email_message.should have_from('from@example.org')
244
251
  @email_message.should have_reply_to('reply_to@example.org')
252
+ @email_message.should have_body_text('funky fresh')
245
253
  end
246
254
  it "should not prepend overrides" do
247
255
  @email_message.should_not have_to_username("to at sanitize_email.org")
@@ -288,6 +296,7 @@ describe SanitizeEmail do
288
296
  it "should not alter non-sanitized attributes" do
289
297
  @email_message.should have_from('same@example.org')
290
298
  @email_message.should have_reply_to('same@example.org')
299
+ @email_message.should have_body_text('funky fresh')
291
300
  end
292
301
  it "should not prepend overrides" do
293
302
  @email_message.should_not have_to_username("same at example.org")
@@ -327,6 +336,7 @@ describe SanitizeEmail do
327
336
  it "should not alter non-sanitized attributes" do
328
337
  @email_message.should have_from('from@example.org')
329
338
  @email_message.should have_reply_to('reply_to@example.org')
339
+ @email_message.should have_body_text('funky fresh')
330
340
  end
331
341
  it "should override" do
332
342
  @email_message.should have_to("to@sanitize_email.org")
@@ -349,6 +359,7 @@ describe SanitizeEmail do
349
359
  it "should not alter non-sanitized attributes" do
350
360
  @email_message.should have_from('from@example.org')
351
361
  @email_message.should have_reply_to('reply_to@example.org')
362
+ @email_message.should have_body_text('funky fresh')
352
363
  end
353
364
  it "should not alter normally sanitized attributes" do
354
365
  @email_message.should have_to("to@example.org")
@@ -371,6 +382,7 @@ describe SanitizeEmail do
371
382
  it "should not alter non-sanitized attributes" do
372
383
  @email_message.should have_from('from@example.org')
373
384
  @email_message.should have_reply_to('reply_to@example.org')
385
+ @email_message.should have_body_text('funky fresh')
374
386
  end
375
387
  it "should override" do
376
388
  @email_message.should have_to("to@sanitize_email.org")
@@ -392,6 +404,7 @@ describe SanitizeEmail do
392
404
  it "should not alter non-sanitized attributes" do
393
405
  @email_message.should have_from('from@example.org')
394
406
  @email_message.should have_reply_to('reply_to@example.org')
407
+ @email_message.should have_body_text('funky fresh')
395
408
  end
396
409
  it "should not alter normally sanitized attributes" do
397
410
  @email_message.should have_to("to@example.org")
@@ -420,6 +433,7 @@ describe SanitizeEmail do
420
433
  it "should not alter non-sanitized attributes" do
421
434
  @email_message.should have_from('from@example.org')
422
435
  @email_message.should have_reply_to('reply_to@example.org')
436
+ @email_message.should have_body_text('funky fresh')
423
437
  end
424
438
  it "should not prepend overrides" do
425
439
  @email_message.should_not have_to_username("to at sanitize_email.org")
@@ -438,6 +452,7 @@ describe SanitizeEmail do
438
452
  it "should not alter non-sanitized attributes" do
439
453
  @email_message.should have_from('from@example.org')
440
454
  @email_message.should have_reply_to('reply_to@example.org')
455
+ @email_message.should have_body_text('funky fresh')
441
456
  end
442
457
  it "should not prepend overrides" do
443
458
  @email_message.should_not have_to_username("to at sanitize_email.org")
@@ -459,6 +474,7 @@ describe SanitizeEmail do
459
474
  it "should not alter non-sanitized attributes" do
460
475
  @email_message.should have_from('from@example.org')
461
476
  @email_message.should have_reply_to('reply_to@example.org')
477
+ @email_message.should have_body_text('funky fresh')
462
478
  end
463
479
  it "should not prepend overrides" do
464
480
  @email_message.should_not have_to_username("to at sanitize_email.org")
@@ -477,6 +493,7 @@ describe SanitizeEmail do
477
493
  it "should not alter non-sanitized attributes" do
478
494
  @email_message.should have_from('from@example.org')
479
495
  @email_message.should have_reply_to('reply_to@example.org')
496
+ @email_message.should have_body_text('funky fresh')
480
497
  end
481
498
  it "should not prepend overrides" do
482
499
  @email_message.should_not have_to_username("to at sanitize_email.org")
@@ -498,6 +515,7 @@ describe SanitizeEmail do
498
515
  it "should not alter non-sanitized attributes" do
499
516
  @email_message.should have_from('from@example.org')
500
517
  @email_message.should have_reply_to('reply_to@example.org')
518
+ @email_message.should have_body_text('funky fresh')
501
519
  end
502
520
  it "should not prepend overrides" do
503
521
  @email_message.should_not have_to_username("to at sanitize_email.org")
@@ -516,6 +534,7 @@ describe SanitizeEmail do
516
534
  it "should not alter non-sanitized attributes" do
517
535
  @email_message.should have_from('from@example.org')
518
536
  @email_message.should have_reply_to('reply_to@example.org')
537
+ @email_message.should have_body_text('funky fresh')
519
538
  end
520
539
  it "should not prepend overrides" do
521
540
  @email_message.should_not have_to_username("to at sanitize_email.org")
@@ -539,6 +558,7 @@ describe SanitizeEmail do
539
558
  it "should not alter non-sanitized attributes" do
540
559
  @email_message.should have_from('from@example.org')
541
560
  @email_message.should have_reply_to('reply_to@example.org')
561
+ @email_message.should have_body_text('funky fresh')
542
562
  end
543
563
  it "should use activation_proc for matching environment" do
544
564
  @email_message.should have_to("to@sanitize_email.org")
@@ -556,6 +576,7 @@ describe SanitizeEmail do
556
576
  it "should not alter non-sanitized attributes" do
557
577
  @email_message.should have_from('from@example.org')
558
578
  @email_message.should have_reply_to('reply_to@example.org')
579
+ @email_message.should have_body_text('funky fresh')
559
580
  end
560
581
  it "should use activation_proc for non-matching environment" do
561
582
  @email_message.should have_to("to@example.org")
@@ -574,6 +595,7 @@ describe SanitizeEmail do
574
595
  it "should not alter non-sanitized attributes" do
575
596
  @email_message.should have_from('from@example.org')
576
597
  @email_message.should have_reply_to('reply_to@example.org')
598
+ @email_message.should have_body_text('funky fresh')
577
599
  end
578
600
  it "used as sanitized_to" do
579
601
  @email_message.should have_to("barney@sanitize_email.org")
@@ -590,6 +612,7 @@ describe SanitizeEmail do
590
612
  it "should not alter non-sanitized attributes" do
591
613
  @email_message.should have_from('from@example.org')
592
614
  @email_message.should have_reply_to('reply_to@example.org')
615
+ @email_message.should have_body_text('funky fresh')
593
616
  end
594
617
  it "should not alter normally sanitized attributes" do
595
618
  @email_message.should have_to("to@example.org")
@@ -5,7 +5,6 @@ require 'mail'
5
5
  require 'rails'
6
6
  require 'letter_opener'
7
7
  require 'action_mailer'
8
- require 'email_spec'
9
8
 
10
9
  # For code coverage, must be required before all application / gem / library code.
11
10
  require 'coveralls'
@@ -20,9 +19,6 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
20
19
 
21
20
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
22
21
  RSpec.configure do |config|
23
- config.include(EmailSpec::Helpers)
24
- config.include(EmailSpec::Matchers)
25
-
26
22
  config.treat_symbols_as_metadata_keys_with_true_values = true
27
23
  config.run_all_when_everything_filtered = true
28
24
  config.filter_run :focus
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sanitize_email
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -173,22 +173,6 @@ dependencies:
173
173
  - - ! '>='
174
174
  - !ruby/object:Gem::Version
175
175
  version: '0'
176
- - !ruby/object:Gem::Dependency
177
- name: email_spec
178
- requirement: !ruby/object:Gem::Requirement
179
- none: false
180
- requirements:
181
- - - ! '>='
182
- - !ruby/object:Gem::Version
183
- version: '0'
184
- type: :development
185
- prerelease: false
186
- version_requirements: !ruby/object:Gem::Requirement
187
- none: false
188
- requirements:
189
- - - ! '>='
190
- - !ruby/object:Gem::Version
191
- version: '0'
192
176
  - !ruby/object:Gem::Dependency
193
177
  name: coveralls
194
178
  requirement: !ruby/object:Gem::Requirement
@@ -238,6 +222,7 @@ files:
238
222
  - lib/sanitize_email/config.rb
239
223
  - lib/sanitize_email/deprecation.rb
240
224
  - lib/sanitize_email/engine.rb
225
+ - lib/sanitize_email/mail_ext.rb
241
226
  - lib/sanitize_email/mail_header_tools.rb
242
227
  - lib/sanitize_email/overridden_addresses.rb
243
228
  - lib/sanitize_email/railtie.rb