Add the following gems to your gem file:
group :development, :test do
gem 'jasmine'
gem 'jasminerice'
gem 'database_cleaner'
gem 'capybara'
gem 'rspec', ">= 2.5.0"
gem "rspec-rails", ">= 2.5.0"
This is my first test of gist.github. |
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." |
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 |
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? } |
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 |
time.strftime( string ) => string | |
Formats time according to the directives in the given format string. Any text not listed as a directive will be passed through to the output string. | |
Format meaning: | |
%a - The abbreviated weekday name (``Sun'') | |
%A - The full weekday name (``Sunday'') | |
%b - The abbreviated month name (``Jan'') | |
%B - The full month name (``January'') | |
%c - The preferred local date and time representation |
We're working in a Rails 3 App with devise attached to the user model | |
In routes.rb, if we write: | |
devise_for :users, :path => 'u' | |
Then we can obviate all the problems with nested resources. Now users will be directed to /u/sign_in and so forth. |
rails g controller sample_controller new --no-test-framework |
Add the following gems to your gem file:
group :development, :test do
gem 'jasmine'
gem 'jasminerice'
gem 'database_cleaner'
gem 'capybara'
gem 'rspec', ">= 2.5.0"
gem "rspec-rails", ">= 2.5.0"
<html> | |
<link rel="stylesheet" href="styles.css" type="text/css"> | |
<body> | |
<p>Hello</p> | |
</body> | |
</html> |