SmartLogic Logo (443) 451-3001

Blog

SmartLogic Wants to Clean Up Twitter, Introduces ShouldIRT.com

May 5th, 2009 by

Are you tired of a world that lacks retweeting etiquette? You know who I’m talking about, that dude who’s always retweeting @THE_REAL_SHAQ or @guykawasaki. Or those guys with multiple twitter accounts who need to ensure that every last contact gets the message, several duplicate followers be damned!

Well, we’re sick of it…..and we’re not the only ones!
Read the rest of this entry »

Integrity CI on Passenger 2.2.2 with Ruby Enterprise Edition on Ubuntu 8.04

April 26th, 2009 by

I just spent a few hours trying to get this configuration sorted out, so I thought I’d share my notes. My goal was to get Integrity running on Passenger with Ruby Enterprise Edition. However, I couldn’t get the user Integrity/Apache was running as to use the proper PATH.

Whenever Integrity would try to build my project, I’d get an error about rake not being able to be found: sh: rake: not found

Read the rest of this entry »

Reintroducing sanitize_email | Work with Production Email without Fear

April 25th, 2009 by

An issue I have to tackle on almost every project I encounter is developing, QA’ing, and troubleshooting email generated from my app. Rails provides a couple of options to help during the development and test phases (setting action_mailer.delivery_method = :test), but there aren’t any great mechanisms for performing QA with a client or troubleshooting production email issues (formatting, content, etc).

Not long ago I stumbled upon Peter Boling’s plugin implementation of sanitize_email. I’ve since forked it, turned it into a gem, and continued to apply maintenance commits to it as rails has marched forward through versions 2.2 and 2.3.

The primary value sanitize_email provides is that it allows you to reroute all email without having to alter any application code. It’s environment-specific and doesn’t introduce any production/deployment dependencies.

Read the rest of this entry »

environmentalist 0.2.3 released — supports rails 2.3.2

April 4th, 2009 by

Just a heads up that I’ve released environmentalist 0.2.3. You can update with:


  sudo gem install environmentalist

The only substantial change in this release is that we moved the loading of postboot.rb to the bottom of the boot.rb file as opposed to the top of config/environment.rb. This was necessary because common db rake tasks like db:create and db:drop stopped loading the environment in 2.3.2.

As a recap, environmentalist provides an executable that converts a rails app’s config structure. The basic idea is that environments themselves are now first-class citizens, allowing you to create several environments (e.g. staging, prodtest, demo, etc.) in a clean, organized fashion. Each environment is given its own folder where it can store its own set of configuration files (think mongrel configs, apache configs, etc.) without polluting the top-level config/ directory.

Recap of the First Baltimore Angels Meetup

March 5th, 2009 by

As many of you know, Baltimore Angels is a group of individual angel investors that have come together as a loose federation whose primary purpose is to spur continued and sustained economic and technological development in this region. (Obviously, they’d like to make a little coin too.) Last month, Baltimore Angels made a public call for business ideas and received 51 submissions in only a few weeks. How encouraging for Baltimore!

Yair and I submitted MyStudentGroups, a web application we built that is currently being used by Johns Hopkins to facilitate the administration of more than 300 student organizations at Hopkins. Among other group management features, it provides a budget management component that takes a lot of the paperwork out of allocating and utilizing a group’s budget. Most importantly, it serves as the official mechanism by which Hopkins recognizes their student groups.

I don’t intend to go into much detail about our specific idea. Rather, my intentions are to (a) document our experience for the benefit of interested entrepreneurs, and (b) provide an honest critique of the process. Read the rest of this entry »

Rails 2.3 Nested Object Forms: I’m not Crazy about Them

February 24th, 2009 by

I’m a couple of weeks late, but I just finished reviewing Rails 2.3 Nested Object Forms. While a very nice and “magical” feature, I’ve got to admit that I’m really not that crazy about how it works.

Let me be the first to admit that there’s no one right way to do things. In fact, I’m writing this post particularly because I have a few objections to how this functionality is ultimately exposed, and I’d like to hear arguments from those who disagree. In other words, let me acknowledge the possibility that I am the misguided one.

Read the rest of this entry »

TATFT: Test Private Methods in C++

February 16th, 2009 by

It’s very rare that I do any C++ programming these days. However, one of my oldest customers continues to utilize a C++-based optimization/statistics framework that we helped them build many years ago. The project has a wonderful purpose, and we owe quite a bit to some of the first people to trust us (thank you Sommer and Dorry!).

As a Ruby programmer, I’ve come to love test-driven programming. As such, I’ve made an effort recently to build a test-based workflow into this existing codebase (not always the easiest thing to do, applying a test-base to a large existing codebase). Today I found myself in dire need of being able to test private functions in C++. As a testament to the poor state of testing in other programming languages, many message boards/threads simply told me that I was testing the wrong thing (you should test the public API, not the private implementation). Well, needless to say, this left me a bit uncomfortable. The fact is, the majority of my code is tucked into private methods, and I’d be left with huge long-running end-to-end tests if I strictly followed this heuristic.

However, I came across one golden nugget, one of the most clever hacks I’ve seen in some time. By utilizing pre-processor directives, we can temporarily override the meaning of private and protected in C++ code, essentially aliasing it to public.

 #define protected public
 #define private   public
 #include "TheClassHeaderUnderTest.h"
 #undef protected
 #undef private

See what this is doing? We wrap the class that we’ll be testing in pre-processor directives to interpret protected and private as an alias for public, essentially loading that class (when including the header file) as entirely public. This allows me to access everything! Private methods, private variables, you name it. And now, just like in Ruby, it’s no holds barred, allowing me to poke and prod my objects without being wrapped on the wrist by the compiler.

Even better, these directives simply wrap your includes in your test files. In other words, I don’t have to change my implementation to achieve this.

A clever hack, no matter the language or technology, is a clever hack. And I absolutely love this hack.

Credit: I discovered this technique as a comment on this wiki.

AASM + interning empty string error

February 13th, 2009 by

Second time I’ve run into this in the past week, so I thought I’d share it with you guys. I fumbled for a short while with the extremely unhelpful error message “interning empty string error” after a re-deployment to my staging server. It seemed to be affecting all of my pages, and I couldn’t really load any page.

The Problem

This blog post is valid for rails 2.1.2 and rubyist-aasm 2.0.5. It may apply to other version combinations, but I make no guarantees.

First, let’s dive into the error itself. This error message occurs when you call to_sym on an empty string:

john-mbp:trunk john$ irb
>> "".to_sym
ArgumentError: interning empty string
	from (irb):1:in `to_sym'
	from (irb):1

Now that we know what’s up, let’s dig into my stack trace.

/opt/ruby-enterprise-1.8.6-20090113/lib/ruby/gems/1.8/gems/rubyist-aasm-2.0.5/lib/persistence/active_record_persistence.rb:233:in `to_sym’
/opt/ruby-enterprise-1.8.6-20090113/lib/ruby/gems/1.8/gems/rubyist-aasm-2.0.5/lib/persistence/active_record_persistence.rb:233:in `aasm_read_state’
/opt/ruby-enterprise-1.8.6-20090113/lib/ruby/gems/1.8/gems/rubyist-aasm-2.0.5/lib/persistence/active_record_persistence.rb:135:in `aasm_current_state’
/opt/ruby-enterprise-1.8.6-20090113/lib/ruby/gems/1.8/gems/rubyist-aasm-2.0.5/lib/aasm.rb:50:in `disabled?’
/var/vhosts/discovered/releases/20090213213806/app/helpers/base_admin_helper.rb:4:in `disable_link’
/var/vhosts/discovered/releases/20090213213806/app/views/schools/index.rhtml:16:in `_run_erb_47app47views47schools47index46rhtml’
/var/vhosts/discovered/releases/20090213213806/app/views/schools/index.rhtml:12:in `each’
/var/vhosts/discovered/releases/20090213213806/app/views/schools/index.rhtml:12:in `_run_erb_47app47views47schools47index46rhtml’


The cause of this bug is the fact that my newest build added an aasm_state column to the School model, but my migration did not properly default schools to a particular state. As such, when an instance of the model was asked for its state, the AASM codebase raised an error. And this occurred on every page because I was rendering a link to a school in a common layout.

The Solution

After the fact, in SQL:

UPDATE schools SET aasm_state = 'active';

Or better yet, before the fact, in my migration:

def self.up
  add_column :schools, :aasm_state, :string
  School.reset_column_information
  School.update_all("aasm_state", "active")
end

The Lesson

Don’t forget that there’s a difference between a migration for a yet-to-be-deployed application and a live running application. Live apps require you to take into account that data already exists.

Timecop 0.2.0 Released: Freeze and Rebase Time in Ruby

December 24th, 2008 by

I just released version 0.2.0 of Timecop this evening (morning).

The primary feature added was the distinction between “freezing” and “rebasing” time. In 0.1.0, Timecop.travel would actually freeze time. This is no longer the case. Rather, a time offset will be calculated, and a running clock is simulated by always offsetting the time returned by Time.now (and friends) by the original offset.

(Note that time can still be frozen with Timecop.freeze.)

Read the rest of this entry »

Timecop: Freeze Time in Ruby for Better Testing

November 19th, 2008 by
The API mentioned in this blog post is specific to v0.1.0. The latest version is v0.2.0. See the blog post announcement, the documentation, or the github home page.

This past weekend I released v0.1.0 of the Timecop gem. Timecop makes it dead simple to travel through or freeze time for the sake of creating a predictable and ultimately testable scenario.

The gem is derived from a plugin I wrote a while back to achieve more or less the same functionality for an extremely time-sensitive application. My goals for the gem included:

  1. Drop-in-ability: The primary goal is to allow your app to continue to use Time.now, Date.today and DateTime.now as normal within your application. No overloading of functions with optional arguments (a la today=Date.today) just so you can write test cases.
  2. Environment independence: I wanted the gem to work (a) w/ rails (ActiveSupport actually), (b) w/ plain ruby when the ‘date’ library has been loaded, and (c) w/ plain ruby when the ‘date’ library had not been loaded.
  3. Library independence: I could have utilized mocha to achieve the mocking functionality found under the hood, but because I wanted this to work with plain vanilla ruby, libraries like mocha are out.
  4. Short-term time travel: I wanted to expose the ability to temporarily change the concept of “now.” This is particularly helpful when writing tests where time needs to pass.
  5. Long-range time travel: I wanted to expose the ability to change the concept of “now” for an indeterminate period of time. This is particularly helpful when setting up a rails test environment along with the test data.
  6. Nested time travel: I wanted to provide the ability to nest traveling, allowing the state to be kept within each block (we’ll see an example later).

The gem is hosted on RubyForge and can be installed by simply running:

sudo gem install timecop

Read the rest of this entry »

John co-founded SmartLogic Solutions with Yair Flicker in May 2005. He is very actively involved with the Ruby and Rails communities, as well as the Baltimore/DC tech and business communities. Check out his GitHub Projects or follow @jtrupiano on twitter.