Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8928177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:22:35+00:00 2026-06-15T08:22:35+00:00

I have an action create in UsersController which looks like this def create @user

  • 0

I have an action create in UsersController which looks like this

def create
  @user = User.new(params[:user])
  if @user.save
    sign_in_as(@user)
    Resque.enqueue(MailWorker, @user.email)
    redirect_to root_url, notice: "Thanks"
  else
    render "new"
  end
end

Before I added reqsue to this action, I’ve been testing email confrimation like this

it "creates a new user account" do
  # code for creating a new account...

  ActionMailer::Base.deliveries.size.should == 1
  mail = ActionMailer::Base.deliveries.last
  mail.to.should == [user[:email]]
  mail.body.encoded.should match(/Thank you for registration/)
end

But now, since I added resque worker to deliver the message, I guess it doesn’t deliver the message instantly and therefore I’m getting this test failed with the message

 Failure/Error: ActionMailer::Base.deliveries.size.should == 1
   expected: 1
        got: 0 (using ==)

How can I test such cases, when async workers are involved and the result depends on them?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:22:37+00:00Added an answer on June 15, 2026 at 8:22 am

    Now that you’ve decoupled the mail delivery from your controller, you will also be able to decouple the tests. What I’ve done in the past for this is use the resque_spec Gem which lets you add assertions for whether or not the jobs have been enqueued as expected.

    You will be adding something like this in your tests:

    MailWorker.should have_queued(user.email)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using RSpec and Cancan, I have this test which fails with: Failure/Error: User.should_receive(:new).and_return(@user) expected:
In my view I have: <?php echo $this->Form->create('User', array(controller => Users, action => login,
I have an action which create QMessageBox. In that dialog I want to print
I have an ASP.NET MVC 3 application which has a post action called Create
Okay, I have the following create action #posts_controller, nested resource under discussions def create
I have controller with action new , and I want it to create ActiveRecord::Base
I have managed to create a custom action in C# using MakeSfxCA which is
Possible Duplicate: Rails - AJAX to for new/create action I have a timeline that
I have a users_controller which has this function in it: def process_csv puts 'processing
I have a User model and a Company model linked like this: class User

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.