This file contains 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
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com | |
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below) | |
module Player | |
describe MovieList, "with optional description" do | |
it "is pending example, so that you can write ones quickly" | |
it "is already working example that we want to suspend from failing temporarily" do | |
pending("working on another feature that temporarily breaks this one") |
This file contains 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
# Probably the proper way to check a hash for options | |
def my_method(options = {}) | |
if options.has_key?(:key) && !options[:key].nil? | |
# do something using the option here | |
end | |
end |
This file contains 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
# The way I basically always check | |
def my_method(options = {}) | |
if options[:key] | |
# do something using the option here | |
end | |
end |
This file contains 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
# What I really wanted my logic to be | |
def my_method(options = {}) | |
if options.has_key?(:key) && !options[:key].nil? | |
if options[:key] | |
# do something using the option here | |
else | |
# do something else | |
end | |
end | |
end |
This file contains 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 DayMap | |
day_array = [] | |
Date::DAYNAMES.each_with_index{|d, i| day_array << [d, i]} | |
reverse_day_array = [] | |
Date::DAYNAMES.each_with_index{|d, i| reverse_day_array << [i, d]} | |
DAY_MAP = Hash[day_array] | |
REVERSE_MAP = Hash[reverse_day_array] | |
class << self |
This file contains 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
# before | |
describe "<=>" do | |
it "first compares days" do | |
l = TimePeriod.create(:start_day => 1, :start_time => 10.hours.to_i, :duration => 1.hours.to_i) | |
r = TimePeriod.create(:start_day => 2, :start_time => 10.hours.to_i, :duration => 1.hours.to_i) | |
(l <=> r).should == -1 | |
(r <=> l).should == 1 | |
end | |
end |
This file contains 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
# before | |
let (:user) { Factory(:user) } | |
# after | |
before :all do | |
@user = Factory(:user) | |
end | |
after :all do | |
@user.destroy |
This file contains 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
Factory.define :user do |user| | |
user.sequence(:email) {|n| "1test#{n}@sample.com"} | |
user.password 'secret' | |
user.password_confirmation 'secret' | |
end | |
This file contains 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
<html> | |
<body> | |
<script type="text/javascript"> | |
var lat = 40.733722; | |
var lon = -73.990683; | |
var id = "1234567890"; | |
var api_endpoint = "api-sandbox.thinknear.com"; | |
var link_endpoint = "m2-s.thinknear.com"; | |
var api_key = "YOUR API KEY"; | |
var app_id = "YOUR APP ID"; |
This file contains 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 'irb' | |
module IRB | |
class << self | |
alias :orig_init_config :init_config | |
def init_config(ap_path) | |
begin | |
puts "loading init config: #{Rails.env}" | |
# Set up the prompt to be slightly more informative |