Skip to content

Instantly share code, notes, and snippets.

View lightscalar's full-sized avatar

Matthew J. Lewis lightscalar

View GitHub Profile
So, this helps a lot when testing applications using RSPEC that use the authlogic gem for authentication.
Just require and include the following module in your rspec file. Then you can simply write things like:
before(:each) do
login_as_user
end
at the top of your specs, and you should be good to go...
module ControllerHelpers
class Book < ActiveRecord::Base
has_one :author
has_many :pages
accepts_nested_attributes_for :author, :pages
end
accepts_nested_attributes_for :author,
:reject_if => proc { |attributes| attributes['name'].blank? }
Just discovered this: an easy way to humanize the attributes of a model. Allows you to rename the database column name to something more reasonable. Makes for nicer, more understandable error messages back to the user.
class User < ActiveRecord::Base
HUMANIZED_ATTRIBUTES = {
:user_email => "E-mail address"
}
def self.human_attribute_name(attr)
HUMANIZED_ATTRIBUTES[attr.to_sym] || super
document.observe("widget:frobbed", function(event) {
console.log("Element with ID (" + event.target.id +
") frobbed widget #" + event.memo.widgetNumber + ".");
});
var someNode = $('foo');
someNode.fire("widget:frobbed", { widgetNumber: 19 });
//-> "Element with ID (foo) frobbed widget #19."
This is my first test of gist.github.