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 NilObject | |
def true?; false end | |
def false?; true end | |
def nil?; true end | |
def blank?; true end | |
def present?; false end | |
def empty?; true end | |
def to_s; "" end | |
def !; true end |
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
gem 'activerecord', '4.0.0.beta' | |
require 'active_record' | |
require 'logger' | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Base.logger.level = Logger::INFO | |
ActiveRecord::Base.establish_connection( :adapter => 'sqlite3', | |
:database => ':memory:' ) | |
ActiveRecord::Schema.define do |
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
describe Rate do | |
it "can do arithmetic" do | |
total = Rate.new(amount: 100.00) + Rate.new(amount: 200.00) | |
total.should == 300.00 | |
end | |
end | |
class Rate < ActiveRecord::Base | |
attr_accessible :amount |
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 Army < AR:B | |
has_many :robots | |
has_many :weapons | |
end | |
class Robot < AR:B | |
belongs_to: :army | |
has_one :weapon | |
end |
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 MyMailer < ActionMailer::Base | |
def notice(user) | |
# ... | |
mail(to: @to, from: @from, subject: @subject) do |format| | |
format.html { render text: @html_content } | |
format.text { render text: @text_content } | |
end | |
end | |
end |
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
# Goal: split responsibilities of count and grouped_count so they are responsible for returning | |
# count => Fixnum and grouped_count => Hash in all cases | |
# | |
# This option removes original calculation options for count(:group => x) | |
# in favour of grouped_count(:group => x) | |
# | |
# (I'm showing count and average as examples of optional & required column_name params, | |
# but this would apply to all calculation methods.) | |
relation = Post.group("author_id").order("created_at") |
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 SomethingsController < ActionController::Base | |
def create | |
Time.zone = current_user.time_zone | |
@another_user = current_user.friends.find(params[:friend_id]) | |
FriendMailer.message(@another_user).deliver | |
# Wouldn't Time.zone be reset by the mailer before rendering the page here? | |
end | |
end |
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 combination of inputs will throw Rack --> | |
<input name="event[dates][]" type="date" /> | |
<input id="event_dates__destroy" name="event[dates][_destroy]" type="hidden" /> |
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
Oct 16 19:56:48 localhost mysqld_safe[27557]: ERROR: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ALTER TABLE user ADD column Show_view_priv enum('N','Y') CHARACTER SET utf8 NOT ' at line 1 | |
Oct 16 19:56:48 localhost mysqld_safe[27557]: 121016 19:56:48 [ERROR] Aborting |
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 Foo < ActiveRecord::Base | |
serialize :check_in, TimeOfDayAttribute # dump/load for valid, empty, nil values tested independently | |
# Setter will handle both String & TimeOfDay input | |
# I want to test the getter before defining (and depending on) this method | |
def check_in=(param) | |
# ... | |
end | |
end |