November 20th, 2007
This is part of an ongoing series of posts about how to get started writing tests for Ruby on Rails. The series begins with the introduction and overview of the ideas behind testing.
Testing the colors Method
Now that we have examined the thought process behind writing tests, I will move more quickly through test_colors and test_full_name. test_colors is simple: invoking colors on the class Car will return an array of colors. How much and what kind of testing this requires is up to you and really depends on your application’s usage. Here are some examples:
1 2 3 4 5 6 7 8 9
| def test_colors
assert(Car.colors.kind_of?(Array))
assert_equal(4, Car.colors.length)
assert_equal(['blue', 'black', 'red', 'green'], Car.colors)
assert(Car.colors.include?(@volvo.color))
assert(Car.colors.include?(@honda.color))
assert(!Car.colors.include?(@dodge.color))
assert(!Car.colors.include?(Car.new.color))
end |
Read the rest of this entry »
Posted in Ruby on Rails, Tutorials | 3 Comments »
November 17th, 2007

This is part of an ongoing series of posts about how to get started writing tests for Ruby on Rails. The series begins with the introduction and overview of the ideas behind testing.
Unit Testing Classes and Instances
Any Ruby code can be tested with TestUnit. Working with classes and instances of objects is no different. Let’s create definition for a Car class (keeping with the car theme from the last section). Then we can write tests that will test the Car class. We will also spend some time considering what we should test and how we can test it.
Read the rest of this entry »
Posted in Ruby on Rails, Tutorials | 2 Comments »
November 14th, 2007
This is part of an ongoing series of posts about how to get started writing tests for Ruby on Rails. The series begins with the introduction and overview of the ideas behind testing.
Unit Testing

I am going to cover several types of tests over the course of this tutorial: unit tests, functional tests, integration tests. I will start with unit tests. Unit tests are a good way to introduce the subject of testing and, if you already have a working Rails application, they are the first tests you should consider adding. Think of unit tests as our first testing layer, a foundation for the other layers.
Unit testing is a testing technique to validate that individual “units” of code are working properly. A “unit” refers to the smallest testable part of the code. When unit testing, we are not interested in how all the units fit together, just in make sure that each unit is functioning properly on its own.
Read the rest of this entry »
Posted in Ruby on Rails, Tutorials | 6 Comments »
November 10th, 2007

For some time, I’ve been wanting to teach how to get started writing tests for Ruby on Rails. Eventually I’d like to do a video training on the subject, but until then I’ve decided to write a series of blog posts as a tutorial.
Everyone agrees that testing is important, yet a small percentage of developers actually write tests. That’s understandable because there is a lot to learn when first starting with Ruby on Rails: installation, Ruby, the MVC framework, Rails, ActiveRecord, migrations, validations, routes, pagination, plug-ins, deployment… There’s more than enough to keep beginners busy during their first few projects. Testing requires learning yet another skill for something that seems like it can be put off until later. After all, you just want to get the site built, right?
Experienced developers often preach to beginners how important it is to test. I’ve even heard it said: “You are not a professional developer unless you write tests.” That is simply not true. You can write great applications, have lots of clients and make lots of money without writing tests. There are thousands of professional developers who don’t. But what I think they really mean by that statement is: Once you start writing tests, you’ll reap a lot of benefits (saving time and writing better code), take your programming to another level, and have a competitive edge over developers who don’t write tests. And who doesn’t want to save time and write better code???
But how do you get there? If you are a Ruby on Rails beginner, focus on the essentials first. Write an application or two. You can start writing tests from the beginning, but I think it’s best if you learn to program in Ruby and have a solid understanding of what Rails is doing first. After you have the fundamentals down, you’ll be ready to learn to write tests. Don’t worry, it’s not as difficult as it might seem. I’m going to walk you through the process step-by-step. (It’ll be an ongoing project spread out over many blog posts.)
Read the rest of this entry »
Posted in Ruby on Rails, Tutorials | 9 Comments »
October 30th, 2007
I ran into an issue with MySQL the other day. After upgrading to a newer version on my development server (a Mac), my databases, user privileges and root password were missing. This isn’t the first time I’ve felt that sinking feeling as I frantically searched for the missing files, and since the fix is easy I thought I should write it up to save you the panic if you ever find yourself in the same situation.
Read the rest of this entry »
Posted in MySQL | 1 Comment »
October 30th, 2007
A pair of interesting posts by Nick Halstead:
Posted in Culture | No Comments »
October 25th, 2007
Google is one of the biggest users of MySQL and they have added many enhancements to get MySQL to meet their needs, including better database replication and tools to monitor a high volume of database instances.
Now, thanks to an agreement between Google and MySQL, some of those features are going to be put back into MySQL so that everyone can take advantage of them. These new features should start showing up around MySQL 6.1 in 2009 and are just part of the improvements on the roadmap to MySQL 7.0 recently laid out by the MySQL group.
Some of the other improvements scheduled on the MySQL roadmap are better enterprise-level security features, a new storage engine (Falcon), table and index partioning, and row-based replication. Most web developers won’t notice a difference, but power-users and database admins will welcome these high-level additions that put MySQL on par with Oracle and IBM solutions.
From ComputerWorld
Posted in MySQL | No Comments »
October 18th, 2007

I’m happy to announce that my latest video training, Ruby on Rails Beyond the Basics, has been released on the lynda.com Online Training Library.
Ruby on Rails Beyond the Basics is the sequel to Ruby on Rails Essential Training and is 11.5 hours of video training for web developers who already feel comfortable with the fundamentals of Ruby and the Rails MVC framework. I teach more of the Ruby language and spend a lot of time on code blocks. Then, using the example of a blog as a project, I show you how to use migrations, demonstrate how to create CRUD that doesn’t simply mimic scaffold, and give you a better understanding of ActiveRecord and some of the pitfalls that often trip up developers. I also cover validations, callbacks, routes, pagination, performance improvements and more.
Ruby on Rails Beyond the Basics is available online as streaming video to subscribers of the lynda.com Online Training Library ($25/month, $250/year, $375/year with exercise files included). It is will also be available as a CD-ROM soon both through lynda.com and Amazon.com.
If you are a beginner, you will be better off if you first start with Ruby on Rails Essential Training which is available online to lynda.com OTL subscribers and on CD-ROM, both through lynda.com and Amazon.com, for $99.95.
If you try either of them and find that they are helpful, be sure to let me know!
Topics include:
- Updating Ruby, Rails and projects
- Using irb and the Rails console
- Intermediate Ruby language techniques
- Understanding code blocks
- Catching errors and raising exceptions
- Using migrations to manage database changes
- Understanding ActiveRecord and avoiding common pitfalls
- Creating flexible controllers and views
- Improving performance with eager loading and cache counters
- Working with form validations and model callbacks
- Using partials and helpers to organize views
- Salting passwords for increased security
- Choosing how to store session data
- Understanding and defining custom and named routes
- Pagination
- Using plug-ins
Posted in News, Ruby on Rails, Tutorials | 15 Comments »
October 17th, 2007

A List Apart has released their 2007 Web Design Survey results.
They received 33,000 reponses to their 37 question survey and massaged all that data into 80 pages of interesting findings. Not only do they share the summary of age, ethnicity, salary, and job field, but they also dive deeper to examine questions such as how many women felt their was a gender bias and is that bias reflected in their salaries. It is an impressive undertaking and worth a read.
Even though “Developers” seem to be well represented in the survey, keep in mind that the ALA audience skews toward designers, designer/developers and those interested in CSS, accessibility and usability, instead of hard-core code heads. If you surveyed enterprise Java developers or Oracle database administrators you might get different results.
Posted in Design, General | No Comments »
October 16th, 2007
Stuart Herbert has posted six ways to group and organise your web servers. He starts small with simple shared hosting and scales upward to web farms, clusters and n-Tier architectures. (Stuart is a PHP-guy but his server advice is platform and language agnostic.)
It’s a good overview for anyone who’s thinking that they are outgrowing their current server set up and wondering what options they should consider. If nothing else it should give you the language you need to go off and do more research on your own.
It’s also a good read if you aren’t outgrowing your server, but want to design applications smartly, so that they could scale if necessary.
Posted in General | No Comments »