Cast an ActiveRecord to a subclass or superclass

becomes casts an ActiveRecord record to a different STI class so Rails can treat it as another type, while both instances share the same attributes.

wycats/artifice

Artifice allows you to replace the Net::HTTP subsystem of Ruby with an equivalent that routes all requests to a Rack application.

You can use Sinatra, raw Rack, or even Rails as your application, allowing you to build up an equivalent to the remote service you are mocking out using familiar and convenient tools to route requests and build up responses.

mitmproxy

mitmproxy is an SSL-capable, intercepting HTTP proxy. It provides a console interface that allows traffic flows to be inspected and edited on the fly.

Safely chain scopes with hash conditions

Rails 2 and some Rails 3.x versions let chained scopes overwrite hash conditions on the same attribute, creating authorization leaks. chain_safely avoids that overwrite.

Weird margin at top of page

Unexplained whitespace at the top of a page can come from a BOM in one of the rendered views; saving the file without a BOM removes it.

Imperative vs Declarative Scenarios in User Stories

Imperative and declarative user-story scenarios suit different situations; declarative phrasing offers advantages in RSpec Story Runner and Cucumber testing.

Making IE 9 happy

Internet Explorer 9 compatibility can require a jQuery update to 1.5.1, and box shadows may render lighter and slightly offset.

Download all Google Web Fonts as a single tarball

Google’s Font Directory and API for web fonts could have a transformative effect on how we read the web. The only problem is, Google has made it very difficult to download all of the actual font files.

Web designers must be free to experiment with these new fonts, to sketch, comp and get to know these typefaces in browser and non-browser applications. This is why I’m providing this archive.

Where to put custom RSpec matchers

Custom RSpec matchers fit well in spec/support/matchers, one file per matcher, and can be loaded from spec_helper.rb or Cucumber features/support/env.rb.

Test that a hash contains a partial hash with RSpec

Use hash_including in RSpec to verify a hash or method call contains only the expected key-value pairs without matching the full structure.

Different CSS for IE using Sass

Different styling for Internet Explorer can be generated with Sass variables and conditional imports without relying on CSS hacks.

Do not deliver mails when there are no recipients set

ActionMailer can send empty messages when recipient arrays are generated dynamically; overriding deliver! prevents delivery when to, cc, and bcc are all blank.

Install LaTeX on Ubuntu 10.10

tetex is no longer supported on Ubuntu 10.10; texlive provides a supported LaTeX installation via apt-get.

Fixing "undefined local variable or method `version_requirements' for #<Rails::GemDependency:0x...> (NameError)"

Rails startup can fail with a NameError when version_requirements is missing on Rails::GemDependency; a small environment.rb patch restores compatibility with newer RubyGems.

Acceptance testing using Capybara's new RSpec DSL

Capybara now includes an RSpec acceptance-testing DSL, replacing much of Steak’s earlier role and making end-to-end testing in RSpec more seamless.

Liquid Canvas

Liquid Canvas is a JavaScript library which allows you to draw inside an HTML canvas element with an easy yet powerful description language.

It can be used to add graphics to your web page without ever touching an image creation tool such as The Gimp, Inkscape or Photoshop.

Check out the Demo and the basic example and then download version 0.3.

Fix "couldn't parse YAML" error after upgrading Bundler

Rails can fail to boot after a Bundler upgrade when the new YAML engine cannot handle symbol values in localization files.

Upgrade from Ruby 1.8.7 to Ruby 1.9.2 on Ubuntu

Upgrading Ubuntu from Ruby 1.8.7 to 1.9.2 can break Rails 2 apps using RSpec and removes installed gems, but Bundler can restore dependencies.

PhantomJS: Headless WebKit with JavaScript API

PhantomJS is a minimalistic headless WebKit.

It has fast and native support for various web standards:

DOM handling, CSS selector, JSON, Canvas, and SVG.

PhantomJS can be fully scripted using JavaScript. It is an optimal solution for headless testing of web-based applications, site scraping, pages capture, SVG renderer, PDF converter and many other usages.

Prevent an ActiveRecord attribute from being changed after creation

Changing a persisted association can leave cached counts inconsistent; freezing an ActiveRecord foreign key prevents updates that would otherwise require extra bookkeeping.

Touch records without running callbacks

ActiveRecord#touch updates updated_at but also triggers callbacks and validations, making frequent timestamp updates expensive. touch_gently and touch_all_gently refresh timestamps without callbacks.

Generate Puppet or Chef recipes from a Ubuntu system state

Blueprint inspects installed packages, changed config files, and locally built software to generate Puppet, Chef, or shell code from an Ubuntu system state.

Global variables in Ruby

List of global variables available to a Ruby script.

Upgrading Cucumber and Capybara to the latest versions available for Rails 2

Rails 2-compatible versions of Cucumber, Capybara, and related gems avoid breakage from newer dependencies and Capybara API changes.