Skip to content

Commit 1e37311

Browse files
committed
Merge pull request #836 from planio-gmbh/808-pass_respond_to
fix: Mail::Field correctly responds_to? the methods of its instantiated field
2 parents 651de9e + ff0fc6b commit 1e37311

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

CHANGELOG.rdoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
== HEAD
22

3+
* #808 - Mail::Field correctly responds_to? the methods of its instantiated field (thegcat)
34
* #772 - normalize encoding matchers (grosser)
45
* #789 - Fix encoding collapsing not dealing with multiple encodings in 1 line (grosser)
56
* #775 - avoid failed encodings / stop bad charsets early (grosser)

lib/mail/field.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,16 @@ def method_missing(name, *args, &block)
189189
field.send(name, *args, &block)
190190
end
191191

192+
if RUBY_VERSION >= '1.9.2'
193+
def respond_to_missing?(method_name, include_private)
194+
field.respond_to?(method_name, include_private) || super
195+
end
196+
else
197+
def respond_to?(method_name, include_private = false)
198+
field.respond_to?(method_name, include_private) || super
199+
end
200+
end
201+
192202
FIELD_ORDER = %w[ return-path received
193203
resent-date resent-from resent-sender resent-to
194204
resent-cc resent-bcc resent-message-id

spec/mail/field_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@
9999
field.addresses
100100
end
101101

102+
it "should respond_to? its own methods and the same methods as its instantiated field class" do
103+
field = Mail::Field.new('To: Bob')
104+
expect(field.respond_to?(:field)).to be_truthy
105+
expect(field.field).to receive(:"respond_to?").once
106+
field.respond_to?(:addresses)
107+
end
108+
102109
it "should change its type if you change the name" do
103110
field = Mail::Field.new("To: [email protected]")
104111
expect(field.field.class).to eq Mail::ToField

0 commit comments

Comments
 (0)