Cucumber: Detect if the current Capybara driver supports Javascript

Copy the attached file to features/support. This gets you a convenience method:

Capybara.javascript_test?

Is true for Selenium, capybara-webkit, Poltergeist and a custom driver called :chrome (which we sometimes like to use for Selenium+Chrome).

Similar sounding but completely different card: Detect if a Javascript is running under Selenium WebDriver (with Rails)

RailsPanel chrome extension

Chrome extension that shows all info from your rails log (like parameters, response times, view rendering times, DB requests) inside a chrome panel.

Rails 3/4: How to add routes for specs only

If you want to have routes that are only available in tests (e.g. for testing obscure redirects), you can use the with_routing helper -- but that one destroys existing routes which may break a specs that require them to work.

To keep both "regular" and test routes, do this:

class MyApplicationController < ActionController::Base
  def show
    render text: 'Welcome to my application'
  end
end

test_routes = Proc.new do
  get '/my_application' => 'my_application#show'
end
Rails.application.routes.ev...

PostgreSQL vs. Rails migration: How to change columns from string to integer

When writing Rails migrations to convert a string column to an integer you'd usually say:

change_column :table_name, :column_name, :integer

However, PostgreSQL will complain:

PG::DatatypeMismatch: ERROR:  column "column_name" cannot be cast automatically to type integer
HINT:  Specify a USING expression to perform the conversion.

The "hint" basically tells you that you need to confirm you want this to happen, and how data shall be converted. Just say this in your migration:

change_column :table_name, :column_name, 'i...

ActiveRecord::StatementInvalid: Mysql2::Error: closed MySQL connection

I recently experienced the error ActiveRecord::StatementInvalid: Mysql2::Error: closed MySQL connection. Apparently this happens when there is a timeout during query execution. In order to fix this you can reconnect to your db.

Therefore either add reconnect: true to your database.yml for automatic reconnection when the error occurs or catch the error and manually and reconnect explicitly via ActiveRecord::Base.connection.reconnect!

Be aware that reconnecting will have the following impact on your current connection:

  • Any active tr...

How to change the locale of a PostgreSQL cluster

There may be reasons to change the locale of your Postgres cluster. A popular one is your development system's locale being used by default (which may be annoying). Here is how to do that.

Beware: By following the steps below, you will drop and recreate your cluster. You will lose all data (including roles). Instructions below include a procedure for dumping and restoring all cluster data (including roles). While it worked at the time of writing, you should have extra backup strategies for a production database.

  1. Find the cluster you...

xfce - How do I finetune subpixel font anti-aliasing?

If your XFCE renders text with overly hard, thin lines instead of smooth anti-aliased lines, you might need to disable the LCD Filter as discribed in the linked article.

The Future of AngularJS

Presentation about awesome changes we can look forward to.

PostgreSQL cheat sheet for MySQL lamers

So you're switching to PostgreSQL from MySQL? Here is some help...

General hints on PostgreSQL

  • \? opens the command overview
  • \d lists things: \du lists users, \dt lists tables etc

Command comparison

Description MySQL command PostgreSQL equivalent
Connect to the database mysql -u $USERNAME -p sudo -u postgres psql
Show databases SHOW DATABASES; \l[ist]
Use/Connect to a database named 'some_database' USE some_database; \c some_dat...

Open browser console with keyboard shortcut

| Chrome | CTRL+Shift+J |
| Firefox / Firebug | CTRL+Shift+L |

mysql2 and older ruby versions

The mysql2 gem in version 0.3.13 might break while compiling on older patch releases of Ruby 1.9.3 within rvm:

*** [err :: server] ruby: symbol lookup error: /path/to/deployment/shared/bundle/ruby/1.9.1/gems/mysql2-0.3.13/lib/mysql2/mysql2.so: undefined symbol: rb_wait_for_single_fd
*** [err :: server] ruby: symbol lookup error: /path/to/deployment/shared/bundle/ruby/1.9.1/gems/mysql2-0.3.13/lib/mysql2/mysql2.so: undefined symbol: rb_wait_for_single_fd

Fixating mysql2 to version 0.3.11 helped.

Disable text-transforms in Selenium tests

Using text-transform: uppercase - especially on form labels - can cause you serious headaches in Selenium tests. Sometimes the web driver will see the uppercase text, sometimes it won't, and umlauts will be a problem as well.

Simply disable it in tests, by

  • adding a body class for tests

    %body{'data-environment' => Rails.env}
    
  • overriding the transforms

    [data-environment="test"] *
      text-transform: none !important
    

List of Compass Mixins

Since we are migrating from our homegrown mixins.sass and helpers.sass to Compass, here is a list of all the mixins provided by Compass.

Responsive Elements - Helps you build better responsive websites

Responsive elements makes it possible for any element to adapt and respond to the area they occupy.

This is different from media queries which always refer to the screen width, not the element's width.

dusen and edge_rider gems no longer depend on Rails

dusen 0.4.8 and edge_rider 0.2.3 no longer depend on Rails (they still depend on ActiveRecord). That means you can use them e.g. with Sinatra.

Building Custom Text Strikethroughs with CSS

Did you know you can color your line-throughs or underline, or make them wavy like spell-checkers do?

Normalising Designs For Better Quality CSS

Awesome slide deck about taking liberties with design requirements in order to keep the CSS simple.

Concerned about Concerns?

With Rails 4, Concerns have become the “official” solution to the big-models problem. However, there’s a fair amount of controversy about this topic in the community. Not everyone is convinced that Concerns are the “right“ solution to the problem of AR models becoming too big.

In this talk we will see what Rails Concerns are and how can we use them to keep our models fit. More interestingly, we’ll discuss the trade-offs of this technique, the different views in the community and a couple of alternatives.

What are the best programming fonts?

Long list of fonts suitable for coding. With screenshots.

4 Lessons Learned Doing Angular on Rails

We’ve been working on one of our first Angular projects with a Rails backend. It’s been a great experience. I wanted to share a few things we learned that we hope are helpful to others building Angular on Rails apps.

.rvmrc deprecated in favor of .ruby-version and .ruby-gemset

Do not use .rvmrc files to specify Ruby version and gemset configuration any longer, it's deprecated and not considered by other Ruby version managers such as rbenv.

If you want to migrate an existing .rvmrc you can use rvm rvmrc to .ruby-version.
Put gemset specification into .ruby-gemset.

Creating the .ruby-version file on your own, just make a file containing e.g.

1.8.7

Attention: Don't clutter other developers rvms with several unecessary ruby patch levels

When you use the rvm command

rvm --ruby-version use 1....

redshift

For all late night coders:

The program "redshift" changes your monitors' white balance according to your position on the planet and your local time. This is supposed to put less strain on your eyeballs than staring at a "daylight white" screen all day and night.
The program is in the Ubuntu repositories, so a simple "sudo apt-get install gtk-redshift" transfers it onto your hard drive.

I find the effect rather pleasing and so I have set the following alias on my computer:

alias rdshft='gtk-redshift -l 48.3714407:10.8982552 -t 6500:4200 &'...