Check to see that you’re not trying to do a synchronous call cross-site. And if you’re doing PhoneGap chances are the majority of calls you’re doing are cross-site.

"async": false,

..probably needs to be changed to “true” or removed altogether. If you really need cross-site async JS you may look in to <a href=””>Google JSONP</a>.

At my day job we have reports that are emailed out at 3AM every day, and the people who get them need them by, like, 9AM. Usually they work but for a number of reasons they occasionally will belch and I wouldn’t know until after the fact.

When that happened I would “hear about it”, and I generally just sucked it up and promised to fix whatever problem it was. One day, about 9 months ago, I had the brainwave that “I wish there was a site that would tell me when email didn’t get sent.” It was an awesome idea that was so cool I promptly forgot about it for almost a whole year..

A few weeks ago after having no problems, I once again “heard about” an email not going out decided to be proactive and build the system I had thought of 3 quarters before, and that system is Mailping.

So what is it? In a basic sense it is a incoming mailbox with filters and rules and if those filters/rules are or are not satisfied you will receive a notification.

So in my case it’s like this: I set it up to watch for an email with the subject line “X” between the hours of “Y” and “Z”. If that email comes through then great, but if not I have the system alert me that something is not right. It could also work the other way, where it can send you an email if if DOES receive a certain email. Whatever you want.

It can also ping a web site with a webhook sort of thing. Bitches love webhooks.

You can start using it now on your own project, anywhere you want to check if email is being sent. I’m already using it daily to make sure the automated email at my day job is working.

Plus, if you wanted to “think out of box” you could use the webhook functionality to trigger actions via an email.

Update, August 2013: The ideas here have been turned in to a gem!

For the last few days I’ve been use Rails’ built in JSON facilities to build API capabilities in to an existing app. Rails makes this easy so kudos, etc, blah blah. Seeing as how I need to test these features I was following a Test First approach and since a JSON API is basically a web-request in drag I decided to use Cucumber and Rack::Test. I wrote a lot of tests like:

Continue reading

Are you having an issue where ActiveRecord is insisting a column in an integer even when MySQL says it is a decimal?

Check the definition of the table in Mysql, chances are you have a decimal column with no decimal “scale” set.

By default, if you don’t tell Mysql ho many decimal places to use it will have none, and ActiveRecord will then simply interpret that as an Integer.

Update you column with a migration like this:

change_column('table_name', 'colun_name', :decimal, { :scale => 2, :precision => 10 } )

When /^I reload the page$/ do
# puts "DEBUG - The page for #{current_path}"
case Capybara::current_driver
when :selenium
visit page.driver.browser.current_url
when :racktest
visit [ current_path, page.driver.last_request.env['QUERY_STRING'] ].reject(&:blank?).join('?')
when :culerity
raise "unsupported driver, use rack::test or selenium/webdriver"

By default, when using celerity and celerity, there is no handler for file downloads. If your action in your scenario results in being served a file with a mime type you don’t understand it will end up being unceremoniously lost.

You can’t read “page.body” because that will return the page you are on, not the file you want to download.

You have a link to the action that will result in the file getting served to you:

When /^I press "([^"]*)" and download the file$/ do |element_id|

@file = page.find_by_id(element_id)


That will read the results of your click in to the @file variable that you can then parse in later steps.

Today I put out the first preliminary version of a gem I call ‘validate_block’. It comes from a discussion I had with @jakemallory yesterday where I said I wish I could logically scope the ‘validates_*’ commands in an ActiveRecord object.

It didn’t seem too hard and so last night I threw something together and it’s up on now.

The main idea is that this gem will let you take a block with a lot of duplication like this:

validates_presence_of :hair, :unless => :bald?
validates_length_of :hair, :within => 3..15, :unless => :bald?
validates_inclusion_of :hair_color, :in => HAIR_COLORS, :unless => bald?

..and convert it in to this:

validate_block :unless => :bald? do
  presence_of :hair
  length_of :hair, :within => 3..15
  inclusion_of :hair_color, :in => HAIR_COLORS

As you can see, it eliminates the need to prefix each item with ‘validate_’ and adds the :unless condition to the whole group (you can put any AR Validation options in there).

Check it out at github. That is all.

You may have a point when you’re writing specs that are meant to anticipate a 404 Not Found from a resource. You have a rescue like this:


rescue ActiveResource::ResourceNotFound
return nil

..and now you need a test for it. In Rspec it’s not obvious, but easy. First, you need to stub your actions in your spec:


That sounds good, but it won’t work because it will fail with:

ArgumentError: wrong number of arguments (0 for 1)

Arguments? I need to pass arguments to an error? I guess I do. Maybe the status code?

But no:

NoMethodError: undefined method `code’ for 404:Fixnum

Ah ha! It needs some kind of object passed in to new()! But, what is it? We have no way of knowing off hand what object should be there. Wait, though, we’re INSIDE an environment that exists for making throw-away objects!

Something.stub!(:some_method).and_raise('err', :code => '404'))

Try that, you’ll get your exception!