Install the Paperclip gem on Ubuntu servers
Paperclip gem builds on Ubuntu only after ImageMagick and RMagick Ruby packages are installed.
Pay attention to the order of your submit buttons
If you have several submit elements (inputs or buttons with type="submit") that each cause different things to happen (e.g. you might have a button that sends an extra attribute) you might run into trouble when submitting the form by pressing the return key in a field.
When nothing fancy like a tabindex is defined it seems as if the first submit element inside a form is chosen (and has its attributes submitted) when pressing return.\
So, if possible, put your "default" (aka least harmful) submit element before others.
NB: If you s...
Using state_machine events within a resource_controller
If you need to call a state_machine event and do not want to re-define resource_controller's create method, try this:
create.before do
object.state_event = :launch_spaceship
end
Kill a dead SSH shell
If a SSH shell dies (from timeout for example), you cannot kill it with the usual CTRL-C or CTRL-Z. Instead, press
[ENTER]~.
(That is ENTER TILDE PERIOD).
Sun Java JVM/JRE on Ubuntu Linux
Install Oracle or Sun Java on Ubuntu, remove OpenJDK for better RubyMine performance, and switch the default java version when multiple JVMs are installed.
Reload the page in your Cucumber features
Reloading a GET page in Cucumber can preserve query parameters during feature tests. Capybara and Webrat variants use the current request data to revisit the same URL.
Replace substrings in Cucumber step argument transforms
Substring transforms in Cucumber must return the full matched string, or surrounding characters get lost and steps may match incorrectly.
The WordCount Simulation
So this is the simulation that I use in my Agile Testing class, as well as in other contexts where I want to teach lessons about increasing Agility. The mechanics of the simulation itself are very general: the simulation models the organization of a software company. It just happens to work really well for making Agile concepts very visible, and visceral.
RSpec's context method is broken
RSpec's context name can collide with application methods and trigger missing description errors. Renaming the method or using describe avoids the conflict.
Places where cron jobs can hide
Cron tasks may be stored in system files or in each user's personal schedule, so hidden automation can be hard to spot when investigating background activity.
Delete from joined MySQL tables
MySQL deletion with joined tables requires naming the target table explicitly, such as deleting posts via a join to authors.
Fixing Web Fonts, A Case Study
Some web fonts with bad hinting can be fixed by applying auto-hinting with Font Squirrel.
Save ActiveRecord models without callbacks or validations (in Rails 2 and Rails 3)
Persist ActiveRecord records directly when callbacks and validations are unnecessary; Rails 2 has create_without_callbacks and update_without_callbacks, while Rails 3 needs sneaky-save.
Fix permissions of temporary RTeX files (which are group and world-readable)
We use RTeX for PDF exports.
While converting LaTeX to PDF, RTeX opens a temporary file which has problematic permissions: Both group and world can read those files.
Although the temp files should go away they sometimes live longer than one would expect.
We patched RTeX to fix this (and have more secure permissions). Place the code below into config/initializers/rtex.rb
Use Sass without Rails
Generate CSS from Sass on a static site without Rails by watching source files and rewriting stylesheets automatically.
Recent RSpec features you might not know about
Less-known RSpec features simplify expectation style, chained stubs, and restoring stubbed methods while using double as the preferred mock object.
A quick guide to pull requests
It’s pretty common for projects hosted on GitHub to receive “pull requests”: requests from people who have cloned your project, made a modification to it and then asking you to merge their changes back into the main project.
There are a lot of ways you can handle these pull requests, here are some of them.
Adding Stroke to Web Text
Because they are vector, it would make sense if we could do things that other vector programs (e.g. Adobe Illustrator) can do with vector text, like draw a stroke around the individual characters. Well, we can! At least in WebKit
Check that a text field is empty with Cucumber
Empty-field checks can pass unexpectedly in Cucumber because "" becomes a regular expression that matches any string. Use ^$ in Capybara or be_blank in Webrat.
Define an array condition that selects on dynamic columns
Safely build dynamic SQL conditions from user-supplied column names and values; sanitize_sql_array works where placeholder syntax fails in MySQL.
Run a rake task in all environments
Use like this:
power-rake db:migrate VERSION=20100913132321
By default the environments development, test, cucumber and performance are considered. The script will not run rake on a production or staging environment.
This script is part of our geordi gem on github.
Run a single example group in RSpec
Run one RSpec example group or a single it example by line number in a long spec without executing the whole file.
Ruby: How to collect a Hash from an Array
Map an array or enumerable to a hash in Ruby using to_h, index_by, group_by, index_with, or a custom collect_hash helper.
Find files modified since a given timestamp
Find files changed after a specific time or within the last day using find age tests and a reference timestamp file.