Brad
2009-Dec-10 00:48 UTC
[rspec-users] Need Help with Specs failing when using ActionMailer
No one was able to help me with the last post so I thought I would try
again with more details. I am having problems with specs that invoke
the mailer. My User model has a method that invokes a mailer as part
of the create_from_signup method.
First an example of the test that passes in my spec/models/user_spec
when run in isolation (i.e. spec spec/models/user_spec.rb).
before do
UserNotifier.deliveries = []
end
it "should signup a valid user and send an activation e-mail" do
u = User.create_from_signup(params)
u.state.should == ''pending''
UserNotifier.should have(1).deliveries
mail = UserNotifier.deliveries.first
mail.to.should eql( [u.email] )
mail.subject.should eql( "#{u.login}, Please activate your new
account" )
end
The spec passes with no problems [ all green :) ]
When I run this same spec within my entire suite (spec spec), it fails
with the following backtrace
ArgumentError in ''User Signup - should signup a valid user and send an
activation e-mail"
wrong number of arguments (0 for 1)
ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/
base.rb:551:in ''content_type''
ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/
base.rb:551:in ''render_message''
ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/
base.rb:493:in ''create!''
ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/
base.rb:452:in ''initialize''
ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/
base.rb:395:in ''new''
ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/
base.rb:395:in ''method_missing''
rails/app/models/user.rb:150:in ''create_from_signup''
I get this same error in my user controller tests, whether I run it
standalone or within the suite.
Does anyone have any idea what could be causing this?
Thanks in advance
Brad
David Chelimsky
2009-Dec-10 09:55 UTC
[rspec-users] Need Help with Specs failing when using ActionMailer
On Wed, Dec 9, 2009 at 7:48 PM, Brad <brad.forsyth at inspire2go.com> wrote:> No one was able to help me with the last post so I thought I would try > again with more details. ?I am having problems with specs that invoke > the mailer. ?My User model has a method that invokes a mailer as part > of the create_from_signup method. > > First an example of the test that passes in my spec/models/user_spec > when run in isolation (i.e. spec spec/models/user_spec.rb). > > ? ?before do > ? ? ?UserNotifier.deliveries = [] > ? ?end > > ? ?it "should signup a valid user and send an activation e-mail" do > ? ? ?u = User.create_from_signup(params) > ? ? ?u.state.should == ''pending'' > ? ? ?UserNotifier.should have(1).deliveries > ? ? ?mail = UserNotifier.deliveries.first > ? ? ?mail.to.should eql( [u.email] ) > ? ? ?mail.subject.should eql( "#{u.login}, Please activate your new > account" ) > ? ?end > > The spec passes with no problems [ all green :) ] > > When I run this same spec within my entire suite (spec spec), it fails > with the following backtrace > > ArgumentError in ''User Signup - should signup a valid user and send an > activation e-mail" > wrong number of arguments (0 for 1) > ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/ > base.rb:551:in ''content_type'' > ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/ > base.rb:551:in ''render_message'' > ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/ > base.rb:493:in ''create!'' > ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/ > base.rb:452:in ''initialize'' > ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/ > base.rb:395:in ''new'' > ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/ > base.rb:395:in ''method_missing'' > rails/app/models/user.rb:150:in ''create_from_signup''What''s on line 150 in user.rb? Please post the entire method surrounding that line.> I get this same error in my user controller tests, whether I run it > standalone or within the suite. > > Does anyone have any idea what could be causing this? > > Thanks in advance > > Brad
Brad
2009-Dec-10 14:20 UTC
[rspec-users] Need Help with Specs failing when using ActionMailer
Dave
Thanks for looking at this. I really appreciate it.
Here is the method being called:
144 # Sign up a new user with a default role of USER and with a state
of pending.
145 # The user must activate their account via e-mail before they can
login
146 def self.create_from_signup(params = {} )
147 user = new(params)
148 if user.valid?
149 user.register!
150 UserNotifier.deliver_signup_notification(user)
151 end
152 return user
153 end
Line 150 is calling UserNotifier
class UserNotifier < ActionMailer::Base
def signup_notification(user)
setup_email(user)
@subject += "#{user.login}, Please activate your new account"
@body[:url] = "http://#{SITE_HOST}/activate/#
{user.activation_code}"
end
def password_reset_notification(user, newpassword)
setup_email(user)
@subject += "#{user.login}, Account changes"
@body[:password] = newpassword
end
protected
def setup_email(user)
@recipients = "#{user.email}"
@from = SITE
@subject = "[CONFIRMATION] "
@sent_on = Time.now
@body[:user] = user
end
end
Everything works well in the standalone model spec. It''s when I
combine it with controller spec''s that the problem occurs.
Brad
On Dec 10, 4:55?am, David Chelimsky <dchelim... at gmail.com>
wrote:> On Wed, Dec 9, 2009 at 7:48 PM, Brad <brad.fors... at inspire2go.com>
wrote:
> > No one was able to help me with the last post so I thought I would try
> > again with more details. ?I am having problems with specs that invoke
> > the mailer. ?My User model has a method that invokes a mailer as part
> > of the create_from_signup method.
>
> > First an example of the test that passes in my spec/models/user_spec
> > when run in isolation (i.e. spec spec/models/user_spec.rb).
>
> > ? ?before do
> > ? ? ?UserNotifier.deliveries = []
> > ? ?end
>
> > ? ?it "should signup a valid user and send an activation
e-mail" do
> > ? ? ?u = User.create_from_signup(params)
> > ? ? ?u.state.should == ''pending''
> > ? ? ?UserNotifier.should have(1).deliveries
> > ? ? ?mail = UserNotifier.deliveries.first
> > ? ? ?mail.to.should eql( [u.email] )
> > ? ? ?mail.subject.should eql( "#{u.login}, Please activate your
new
> > account" )
> > ? ?end
>
> > The spec passes with no problems [ all green :) ]
>
> > When I run this same spec within my entire suite (spec spec), it fails
> > with the following backtrace
>
> > ArgumentError in ''User Signup - should signup a valid user
and send an
> > activation e-mail"
> > wrong number of arguments (0 for 1)
> > ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/
> > base.rb:551:in ''content_type''
> > ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/
> > base.rb:551:in ''render_message''
> > ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/
> > base.rb:493:in ''create!''
> > ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/
> > base.rb:452:in ''initialize''
> > ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/
> > base.rb:395:in ''new''
> > ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/
> > base.rb:395:in ''method_missing''
> > rails/app/models/user.rb:150:in ''create_from_signup''
>
> What''s on line 150 in user.rb? Please post the entire method
> surrounding that line.
>
> > I get this same error in my user controller tests, whether I run it
> > standalone or within the suite.
>
> > Does anyone have any idea what could be causing this?
>
> > Thanks in advance
>
> > Brad
>
> _______________________________________________
> rspec-users mailing list
> rspec-us... at
rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
Brad
2010-Jan-21 03:38 UTC
[rspec-users] Need Help with Specs failing when using ActionMailer
Finally solved the problem. Even though the application is Rails 2.3.5 it was started on a much earlier version and the view files were using the old rhtml extensions. The newer auto format detection uses html.erb, or in the case of the mailer, likes file_name.text.html.erb. All I had to do was rename the view files and the specifications passed. Not sure why the application ran fine with the old file name extensions whereas controller spec''s failed, but at least it is now working. On Dec 10 2009, 9:20?am, Brad <brad.fors... at inspire2go.com> wrote:> Dave > Thanks for looking at this. ?I really appreciate it. > > Here is the method being called: > > 144 ?# Sign up a new user with a default role of USER and with a state > of pending. > 145 ?# The user must activate their account via e-mail before they can > login > 146 ?def self.create_from_signup(params = {} ) > 147 ? ?user = new(params) > 148 ? ?if user.valid? > 149 ? ? ?user.register! > 150 ? ? ?UserNotifier.deliver_signup_notification(user) > 151 ? ?end > 152 ? ?return user > 153 ?end > > Line 150 is calling UserNotifier > > class UserNotifier <ActionMailer::Base > ? def signup_notification(user) > ? ? setup_email(user) > ? ? @subject ? ?+= "#{user.login}, Please activate your new account" > ? ? @body[:url] ?= "http://#{SITE_HOST}/activate/# > {user.activation_code}" > ? end > > ? def password_reset_notification(user, newpassword) > ? ? setup_email(user) > ? ? @subject ? ?+= "#{user.login}, Account changes" > ? ? @body[:password] ?= newpassword > ? end > > ? protected > ? def setup_email(user) > ? ? @recipients ?= "#{user.email}" > ? ? @from ? ? ? ?= ?SITE > ? ? @subject ? ? = "[CONFIRMATION] " > ? ? @sent_on ? ? = Time.now > ? ? @body[:user] = user > ? end > end > > Everything works well in the standalone model spec. ?It''s when I > combine it with controller spec''s that the problem occurs. > > Brad > > On Dec 10, 4:55?am, David Chelimsky <dchelim... at gmail.com> wrote: > > > > > On Wed, Dec 9, 2009 at 7:48 PM, Brad <brad.fors... at inspire2go.com> wrote: > > > No one was able to help me with the last post so I thought I would try > > > again with more details. ?I am having problems with specs that invoke > > > the mailer. ?My User model has a method that invokes a mailer as part > > > of the create_from_signup method. > > > > First an example of the test that passes in my spec/models/user_spec > > > when run in isolation (i.e. spec spec/models/user_spec.rb). > > > > ? ?before do > > > ? ? ?UserNotifier.deliveries = [] > > > ? ?end > > > > ? ?it "should signup a valid user and send an activation e-mail" do > > > ? ? ?u = User.create_from_signup(params) > > > ? ? ?u.state.should == ''pending'' > > > ? ? ?UserNotifier.should have(1).deliveries > > > ? ? ?mail = UserNotifier.deliveries.first > > > ? ? ?mail.to.should eql( [u.email] ) > > > ? ? ?mail.subject.should eql( "#{u.login}, Please activate your new > > > account" ) > > > ? ?end > > > > The spec passes with no problems [ all green :) ] > > > > When I run this same spec within my entire suite (spec spec), it fails > > > with the following backtrace > > > > ArgumentError in ''User Signup - should signup a valid user and send an > > > activation e-mail" > > > wrong number of arguments (0 for 1) > > > ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/ > > > base.rb:551:in ''content_type'' > > > ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/ > > > base.rb:551:in ''render_message'' > > > ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/ > > > base.rb:493:in ''create!'' > > > ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/ > > > base.rb:452:in ''initialize'' > > > ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/ > > > base.rb:395:in ''new'' > > > ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/ > > > base.rb:395:in ''method_missing'' > > > rails/app/models/user.rb:150:in ''create_from_signup'' > > > What''s on line 150 in user.rb? Please post the entire method > > surrounding that line. > > > > I get this same error in my user controller tests, whether I run it > > > standalone or within the suite. > > > > Does anyone have any idea what could be causing this? > > > > Thanks in advance > > > > Brad > > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users