Plugins (and gems) are typically tested using a complete sample rails application that lives in the spec
folder of the plugin. If your gem is supposed to work with multiple versions of Rails, you might want to use to separate apps - one for each rails version.
For best practice examples that give you full coverage with minimal repitition of code, check out our gems has_defaults and assignable_values. In particular, take a look at:
To install webmock 1.5.0:
sudo gem install webmock --version "=1.5.0"
or
sudo gem install webmock -v "=1.5.0"
As a user of Bundler you have spent significant time looking at this message:
Fetching source index for http://rubygems.org/
To make Bundler skip this index update and only use installed gems, you can use the --local
option:
bundle install --local
Unfortunately this does not work with bundle update
.
It is said that Bundler 1.1 will use a feature of Rubygems.org that allows partial index updates. Hopefully the wh...
Given this class:
class Foo
class Bar
end
end
If you want to clean up this code with the modularity gem, you might try something like this:
class Foo
does 'bar'
end
module BarTrait
as_trait do
class Bar
end
end
end
Note that this changes Bar
's full class name from Foo::Bar
to BarTrait::Bar
. If you have methods inside Foo
(or other classes), you would have to change all references accordingly, which is quite unpleasant.
You can solve it like that:
`...
This is a bash script for those of you who need to install all gems for all projects (e.g. to get started quickly on a newly installed system).
Put it into your ~/bin/
and run it from the directory that holds your projects.
Note that, like the vanilla bundle install
, this will fail whenever a new gem compiles native components and requires a missing system dependency.
After switching to Rails 3 you may get a LoadError
with the following message when trying to use your application via passenger:
no such file to load -- dispatcher
Your Passenger version is most likely out of date.
Update the gem, then install the apache module again:
sudo gem install passenger
sudo passenger-install-apache2-module
Follow any instructions. Update your /etc/apache2/httpd.conf
with the lines given at the end of the installation process to use the version you just installed.
You will need to upgrade to RSpec >= 2 and rspec-rails >= 2 for Rails 3. Here are some hints to get started:
rspec
, not spec
.Spec::Something
to RSpec::Something
. This also means that every require 'spec/something'
must now be require 'rspec/something'
.spec_helper.rb
, Spec::Runner.configure
becomes RSpec.configure
I prefer the application that I'm currently working on to be reachable at http://localhost/
.
So when I switch to another project, I use this handy shell script to set one site as the current one. Call it just like this:
apache-site makandra-com
Note that it disables all other sites in your Apache configuration so you would not want to use this on production machines.
Furthermore it will also enable the default
site if that was available.
When you call apache-site
with no arguments, it will list all available sites.
...
Be careful when memoizing a method that returns a scope, e.g.:
def variants
scoped(:conditions => { :name => name })
end
memoize :variants
Because of the way memoize
is implemented, that method now no longer returns a scope but its loaded target array.
The best solution is to use the Memoizer gem instead.
A workaround is to roll your own memoization:
def variants
@va...
The ancestry gem allows you to easily use tree structures in your Rails application.
There is one somewhat unobvious pitfall to it: its way of applying the orphan_strategy
which defines how it handles children of an object going to be destroyed.
In many cases you might want to disallow destruction if there are any child nodes present. The restrict
strategy does the trick but raises an exception when destroy
is called:
has_ancestry :orphan_st...
You need to install the following packages before you can build the Nokogiri gem:
sudo apt-get install libxml2-dev libxslt1-dev
Even when you're using bundler, it might be significant in which order your gems are listed in your Gemfile
. This can happen when gems are running around calling require
or require_dependency
on other gems or application classes when loaded (don't do that!).
A known culprit of this is the (otherwise wonderful) resource_controller gem, which requires ApplicationController
when loaded. When your ApplicationController
requires later-loaded gems when loaded, Rails will not boot.
He...
Ruby gem that provides an AR-style interface for the Pivotal Tracker API.
You need to install the following packages before you can build the Paperclip gem:
sudo apt-get install imagemagick librmagick-ruby
You can use
record.send(:update_without_callbacks)
or
record.send(:create_without_callbacks)
This can be used as a lightweight alternative to machinist's make
or FactoryGirl's create
, when you just need objects in the database but don't care about any callbacks or validations. Note that create_without_callbacks
does not return the object, so you might want to do
record = Record.new.tap(&:create_without_callbacks)
Rails 3 no longer comes with update_without_callbacks
or `crea...
You don't need a Rails application to use Sass. Even when you're working on a static site you can generate your CSS through Sass.
sudo gem install haml
sass
in the folder, that stores your stylesheets, e.g. mkdir css/sass
sass --watch css/sass:css
. This will watch your sass files for changes and rewrite stylesheets as required.This even works on Windows.
You might want to change our [typical .gitignor...
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.
First of all: You could just use RVM which would make the pain go away. If for some reason you can't, proceed.
Do not use rubygems from the apt repository.
tar xvfz rubygems-1.3.7.tgz
sudo apt-get remove rubygems
cd rubygems-1.3.7 && sudo ruby setup.rb
gem
to gem1.8
:\You can use the whatlanguage gem to detect the language of a Ruby string.
Note that it also has not been updated in quite a while and that there might be alternatives. However, it still works.
It has problems with short strings, but works quite well on longer texts.
Use it like this:
>> WhatLanguage.new(:all).language('Half the price of a hotel for twice the space')
=> :english
There is also a convenience method on Strings (you may need to require 'whatlanguage/string'
).
>> 'Wir ent...
This gem is designed to provide CSS views to Rails, and a process to concatenate and minify these files to one file for production.
Capistrano task for Bundler.
Call with the server's hostname (and user if you have no SSH agent), e.g.
install-gems-remotely my.server.com
# or without agent:
install-gems-remotely me@my.server.com
When you call it from a rails directory, it uploads your Gemfile
, Gemfile.lock
as well as the gemspecs of all vendored gems in to a temporary folder on the server and does a bundle install
there.
If you need to install gems from anothere Gemfile, just do it like this:
BUNDLE_GEMFILE=Gemfile.something; install-gems-remotely my.server.com
This scri...
This is an awesome gadget in your toolbox, even if your test coverage is great.
gem install ruby-debug
(Ruby 1.8) or gem install debugger
(Ruby 1.9)script/server --debugger
debugger
anywhere in your codeOur gem Mail Magnet allows you to override e-mail recipients in ActionMailer so all mails go to a given address.
This is useful for staging environments where you want to test production-like mail delivery without sending e-mails to real users.