Skip to content
Browse files

Resolved Issue #13 - replacing From field results in from field becom…

…ing optional field.
  • Loading branch information...
1 parent fa257d6 commit 001a868fb9cefddd5709e6690cbcd0fb7cba3ec3 @mikel committed
Showing with 45 additions and 1 deletion.
  1. +4 −0 CHANGELOG.rdoc
  2. +1 −1 lib/mail/field.rb
  3. +17 −0 spec/mail/header_spec.rb
  4. +23 −0 spec/mail/message_spec.rb
View
4 CHANGELOG.rdoc
@@ -1,3 +1,7 @@
+== Thu Dec 10 21:25:37 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
+
+* Resolved Issue #13 - replacing From field results in from field becoming optional field.
+
== Thu 3 Dec 2009 00:52:12 UTC Mikel Lindsaar <raasdnil@gmail.com>
* Added POP upgrades from Nicolas Fouché
View
2 lib/mail/field.rb
@@ -149,7 +149,7 @@ def create_field(name, value)
def new_field(name, value)
# Could do this with constantize and make it "as DRY as", but a simple case
# statement is, well, simpler...
- case name
+ case name.to_s
when /^to$/i
ToField.new(name, value)
when /^cc$/i
View
17 spec/mail/header_spec.rb
@@ -334,6 +334,23 @@
header['Bobs-Field'].should == nil
end
+ it "should allow you to replace a from field" do
+ header = Mail::Header.new
+ header['From'].should == nil
+ header['From'] = 'mikel@test.lindsaar.net'
+ header['From'].decoded.should == 'mikel@test.lindsaar.net'
+ header['From'] = 'bob@test.lindsaar.net'
+ header['From'].decoded.should == 'bob@test.lindsaar.net'
+ end
+
+ it "should maintain the class of the field" do
+ header = Mail::Header.new
+ header['From'] = 'mikel@test.lindsaar.net'
+ header['From'].field.class.should == Mail::FromField
+ header['From'] = 'bob@test.lindsaar.net'
+ header['From'].field.class.should == Mail::FromField
+ end
+
end
describe "folding and unfolding" do
View
23 spec/mail/message_spec.rb
@@ -185,6 +185,9 @@ def basic_email
@mail['foo'] = nil
@mail.header_fields.length.should == 0
end
+
+
+
end
describe "with :method=" do
@@ -262,6 +265,26 @@ def basic_email
end
end
+ describe "replacing header values" do
+
+ it "should allow you to replace a from field" do
+ mail = Mail.new
+ mail.from.should == nil
+ mail.from = 'mikel@test.lindsaar.net'
+ mail.from.decoded.should == 'mikel@test.lindsaar.net'
+ mail.from = 'bob@test.lindsaar.net'
+ mail.from.decoded.should == 'bob@test.lindsaar.net'
+ end
+
+ it "should maintain the class of the field" do
+ mail = Mail.new
+ mail.from = 'mikel@test.lindsaar.net'
+ mail.from.field.class.should == Mail::FromField
+ mail.from = 'bob@test.lindsaar.net'
+ mail.from.field.class.should == Mail::FromField
+ end
+ end
+
describe "setting headers" do
it "should accept them in block form" do

0 comments on commit 001a868

Please sign in to comment.
Something went wrong with that request. Please try again.