This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is my first test of gist.github. |
NewerOlder