Posted: March 31st, 2009 | Author: Brad | Filed under: Rails, Testing, ruby | Tags: cucumber, Rails, rspec, ruby, webrat | 1 Comment »
If you’ve read the new PragProg beta e-book on RSpec, you may have read that you can set HTTP headers for your Webrat request like so:
Given /^I am browsing the site using Safari$/ do
header "User-Agent" , "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us)"
end
Like me, you may have found out the hard way that this doesn’t work. Webrat does not automagically apply these new HTTP headers to your request – they certainly don’t make it to my controller. What worked for me:
Given /^I am browsing the site using Safari$/ do
headers["User-Agent"] = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us)"
end
When /^I visit my precious site$/ do
get '/my/precious/path', my_query_string, headers
end
In the code above, headers is a method call that returns all the HTTP headers for your request. Just tack headers on as the third argument of your request, and you’re good to go.
Posted: March 23rd, 2009 | Author: abel | Filed under: Programming, Quick Hits, Rails | Tags: fastercsv, noob | No Comments »
Here are two things I discovered this weekend:
Thing 1: FasterCSV is really cool! It’s easy to use and does exactly what it should. Here’s Scott Becker’s exporting tutorial. For importing, i’ve hacked together bits from Peter Larkmund’s travels and the FasterCSV documentation. Thanks to these tutorials, AMB will give users the ability to upload and export CSVs.
Thing 2: Default values for the win! If you have a table that has a column for an amount, feel free to set the default value to 0.00. Otherwise you won’t be able to do the following:
a = Account.new
a.amount += 20
…because a.amount will be nil. You’ll throw an error and if you just updated a bunch of code, you might waste an hour trying to figure out why you’re throwing an exception. However, if you declare a default value, you’ll be able to avoid any issues.
If you want me to go into further detail on either thing, just leave a comment.
Thanks for reading and happy hacking.
Posted: March 15th, 2009 | Author: abel | Filed under: Programming, Rails | Tags: ambudget | No Comments »
I’m not new to software development, but unlike Gabe and Brad I’m new to hacking rails. I’ve created simple tutorial apps in rails (an online store, a blog, etc.) and I now feel comfortable enough to create something for the world to see. At the same time, I realized that I would need to care about the project in order to keep coding it. I decided to turn the spreadsheet that I use for budgeting into a rails app. AM-Budget (which I like to call AMB) is my first rails app and I’ve learned a lot leading up to its deployment. I’d like to share the following with you in the hopes that I can encourage other ruby-newbies to release a v1.
Read the rest of this entry »
Posted: March 8th, 2009 | Author: Brad | Filed under: Events, hadoop, ruby | Comments Off
A note for interested parties: I (Brad) will be giving a short (10-15 minute) talk on using Ruby with Hadoop for distributed computing. The plan is to give an ultra-brief description of the MapReduce algorithm and Hadoop, show 2 examples of working code (including one with Wukong, Flip Kromers Hadoop Streaming wrapper), and closing notes on my attempts to use JRuby to create Hadoop jobs.
The talk will be on Tuesday at the NYC.rb meeting, 7:00 at Bway.net’s offices. Get there early for a seat, the last one was packed.
Posted: March 1st, 2009 | Author: gabe | Filed under: Rails, Testing | Tags: assert_select, invalid selector | Comments Off
Problem: assert_select 'input[name=model_name[field_name]]' gives ArgumentError: Invalid selector: ]
Solution: assert_select 'input[name=?]', 'model_name[field_name]'
Thanks to the Boston Ruby Group thread for the answer.
Bonus: Here’s a helpful assert_select cheat sheet.
Posted: March 1st, 2009 | Author: gabe | Filed under: HTML, Rails | Tags: forms, invalidauthenticitytoken, tables | 3 Comments »
Recently, while pairing with Abel as we hacked on some code for his budget tracking app, we came across an interesting problem while trying to acomplish what seems like a pretty straightforward task.
Read the rest of this entry »