Skip to content

Instantly share code, notes, and snippets.

View josevalim's full-sized avatar

José Valim josevalim

View GitHub Profile
class MessagesBuilder
def initialize
@description = nil
@failure = nil
end
def description(arg = nil, &block)
@description = arg || block
end
# Current way of overwriting your create behaviour when the task can't be saved with success:
class TasksController < InheritedResources::Base
# Project.find_by_title!(params[:project_title]).tasks
belongs_to :project, :finder => :find_by_title!, :param => :project_title
def create
# create! == super
create! do |format|
unless @task.errors.empty?
format.html { redirect_to project_url(@project) }
# TasksController
describe TasksController do
describe "responding to GET show" do
receive :find, :on => Task, :with => '37', :and_return => :mock_task
get :show, :id => '37'
it { should match_expectations }
it { should ensure_assign(:project, :task).equal(mock_project, mock_task) }
end
end
class GroupsController < InheritedResources::Base
protected
def begin_of_association_chain
@current_user # or a method that returns the @current_user
end
end
# Vamos supor que você quer fazer algo quando em special ("something_special!")
# antes de criar seus projetos. Você deve fazer isso:
#
class ProjectsController < InheritedResources::Base
def create
@project = Project.new(params[:project])
@project.something_special!
create!
end
end
describe User do
valid_attributes :name => 'José Valim', :email => 'myemail@josevalim.com', :password => '12345'
it{ should validates_presence_of(:email) }
end
require 'rubygems'
require 'active_support'
class Father
cattr_accessor :name
end
class Son < Father
end
#!/bin/sh
mkdir -p /usr/local/src && cd /usr/local/src
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p0.tar.bz2
tar -xjvf ruby-1.9.1-p0.tar.bz2
cd ruby-1.9.1-p0
./configure --prefix=/usr --program-suffix=19 --enable-shared
make && make install
class Fixtures < (RUBY_VERSION < '1.9' ? YAML::Omap : Hash)
cattr_accessor :current_fixtures
def self.destroy_fixtures(table_names)
NestedScenarios.delete_tables(table_names)
end
end
module ActiveRecord #:nodoc:
module TestFixtures #:nodoc:
module Spec
module Rails
module Example
# Controller Examples live in $RAILS_ROOT/spec/controllers/.
#
# Controller Examples use Spec::Rails::Example::ControllerExampleGroup, which supports running specs for
# Controllers in two modes, which represent the tension between the more granular
# testing common in TDD and the more high level testing built into
# rails. BDD sits somewhere in between: we want to a balance between
# specs that are close enough to the code to enable quick fault