Category Archives: rails

Monitoring Rails with statsd and graphite

Assuming you’ve googled this topic at all, you are bound to have come across this article from 37signals, pssst-your-rails-application-has-a-secret-to-tell-you. You can basically build an initializer doing all the things in that post to get started sending data to statsd. Statsd … Continue reading

Posted in rails | Tagged , , , | Leave a comment

Ruby’s Singleton and Custom Rails Application Configuration

A relatively simple way to load some configuration once and safely, is through the use of the Singleton module provided with Ruby. Accessing the instance is easy, call FooConfig.instance. This method is also thread-safe so no two threads are going … Continue reading

Posted in rails | Tagged , , , | 1 Comment

Rails + Kaminari with RSpec

The default rspec view specs don’t work so well for index pages if you have added Kaminari pagination. The reason is the assigned variable in the controller is not an array, but is instead expected to respond to additional methods: … Continue reading

Posted in rails | Tagged , | Leave a comment

Rails + Devise and Rspec

So I tried using Devise on a project and ran into an issue with the default generated controller specs. PlansController POST create with invalid params re-renders the ‘new’ template Failure/Error: response.should render_template(“new”) expecting <“new”> but rendering with <“”> # ./plans_controller_spec.rb:73:in … Continue reading

Posted in rails | Tagged , | 1 Comment

Test a gem with the Rails 3 stack

My previous post covers testing a gem that makes some change to how ActiveRecord works. But what if you want to test a gem that supplies some new behavior to another part of rails, like say ActionController. How do you … Continue reading

Posted in rails | Tagged , | 1 Comment

How to test a gem that changes ActiveRecord

The code given here comes from my gem, safe_attributes, which can be retrieved from https://github.com/bjones/safe_attributes. Some of the code for setting up this testing environment originally came from or was inspired by octopus, which is also available on github. The … Continue reading

Posted in rails | Tagged , , | 2 Comments

Better legacy database support for Rails

Have you seen these errors? NoMethodError: undefined method `columns_hash’ for “”:String NoMethodError: undefined method `private_method_defined?’ for “”:String If you’ve tried using Rails 3 with a legacy database, it is possible you’ve run across issues with some of your columns having … Continue reading

Posted in rails | Tagged | 2 Comments