bakedweb logo

Design and Web Development from Downtown Miami.

Archive for the ‘ruby’ tag

Testing sending a delayed_job email with Cucumber

with 9 comments

I recently implemented delayed_job into one of our applications. It was done because the application was dropping emails at the expense of user experience. We had about 120+ “Net::SMTPServerBusy” notifications and something had to be done about that.

We had about six places in our application where the email-spec gem came into play with a nicely:

Then “thebaker@bakedweb.net” should receive 1 ?email

After implementing delayed_job they changed to:

Then “thebaker@bakedweb.net” should receive 1 delayed email

The question is: How would I go about implementing the step? I came up with the following:

Then /^"([^\"]*)” should receive 1 delayed email$/ do |arg1|
Delayed::Job.last.name[0..15].should == ‘Notifier.deliver’
end

I know my implementation is dirty and brakes if we are sending the email from somewhere else, but Notifier and it only takes into account 1 email. The real reason for this post is to pick you mind on how to better implement the step. How would you go about it?

Update: Kotrin from #cucumber came up with a neat regex for the step and tells us that we could probably expand on it to pick up on args.


Then /^"([^\"]*)” should receive 1 delayed email$/ do |arg1|
Delayed::Job.last.name.should match(/^Notifier\.deliver/)
end

Written by ivan

August 5th, 2009 at 8:18 am

Posted in ruby on rails

Tagged with , , ,

Deploying ruby on rails app in Media Temple

with 5 comments

We are about to deploid our newest project Yonopelo to Media Temple Grid Containers and we are going to share the experience with you. We wanted to make this process as smooth as posible so we decided to go with git, github and capistrano.

We are using Jobberrails as the codebase for Yonopelo, so we fork it from github.

git clone git://github.com/jcnetdev/jobberrails.git

After that we just created a new project on github to store Yonopelo’s code.

git config --global user.email ivan@bakedweb.net
git init
git add .
git commit -m "first commit"

We had to delete the origin and add ours.

git remote rm origin
git remote add origin git@github.com:bakedweb/yonopelo.git
git push origin master

Let’s move on to Capify our project. We need to install the gem:

gem install -y capistrano

This is where you have to decide a lot of stuff about you application. Just go to capistrano’s website for a better overview of this process.

capify .

Make sure you run the above code in your application’s root directory. It will create two file, but we are using config/deploy.rb to tell capistrano what’s up.

The recipe for deploying Capistrano to Media Temple can be found here. and I found the original media temple capistrano recipe here. You need to change the fallowing parameters for it to work:


set :site, ""
set :application, ""
set :webpath, ""
set :domain, ""
set :user, ""
set :password, ""
set :scm_password, ""

Notice how we tell capistrano to create the database.yml from the /config/database.yml.mt. You’ll need to create that file. We then go to

cap deploy:setup
cap deploy:check
cap deploy:update

The last comand gave me an error so I had to ssh into the grid and install the aplication manually fallowing Media Temple’s guide to ruby on rails

mtr add yonopelo $PWD yonopelo.com

I then created the databases and migrated the schema.

rake gems:install db:create db:schema:load db:migrate

Guala!

Some interesting article:
Getting Started with ruby on rails on Media Temple
Ruby on Rails application on Primary Domain (Media Temple)

Written by ivan

January 29th, 2009 at 3:13 pm