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
# Mock all calls through .find on an ActiveRecord model | |
# or its chained scopes | |
def expect_find(model) | |
@scope ||= model.scoped | |
model.stub!(:scoped).and_return @scope | |
@scope.should_receive(:find).ordered | |
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
std = Time.local(2013, 11, 3, 01, 00, 00) | |
# => 2013-11-03 01:00:00 -0800 | |
dst = std - 3600 | |
# => 2013-11-03 01:00:00 -0700 | |
## Challenge: | |
# Is it possible to instantiate a time in the last hour of DST (01:00 - 01:59) | |
# without first having to create a nearby time to subtract from? |
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
require 'bundler' | |
require 'barometer' | |
require 'fakeweb' | |
module TestStubs | |
module Barometer | |
def self.stub! | |
FakeWeb.register_uri( | |
:get, %r[^http://api\.wunderground\.com/auto/wui/geo/WXCurrentObXML/index\.xml\?query], | |
body: File.read(current_fixture_path) |
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
## app/models/project.rb | |
class Project | |
autoload :Report, 'project_report' | |
end | |
## app/models/project_report.rb | |
class Project::Report | |
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 NullObject | |
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
module BacktickAttributeSyntax | |
extend self | |
# WARNING: this is a dangerous hack. Don't use it. It'll bite you if you ever | |
# accidentally call backticks outside of a model. | |
# Override backtick syntax to return an Arel attribute for use with | |
# predications like `.gteq` in the model. To use the original shell | |
# behaviour, (which should be very uncommon in ActiveRecord models), you can |
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 |
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
<!-- 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
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 |