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
$count = 0 | |
describe "let" do | |
let(:count) { $count += 1 } | |
it "memoizes the value" do | |
count.should eq(1) | |
count.should eq(1) | |
end | |
it "is not cached across examples" 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
# Using before method | |
before do | |
@customer = Customer.new(:name => "Amazon") | |
end | |
it "should be valid" { @customer.should be_valid } | |
# Using let method | |
let(:customer) { Customer.new(:name => "Amazon") } | |
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 "rspec/expectations" | |
class Thing | |
def widgets | |
@widgets ||= [] | |
end | |
end | |
describe Thing do | |
before(:all) 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
# Renders the template located in [TEMPLATE_ROOT]/weblog/show.r(html|xml) (in Rails, app/views/weblog/show.erb) | |
render :template => "weblog/show" | |
# Renders the template with a local variable | |
render :template => "weblog/show", :locals => {:customer => Customer.new} |
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
Rails::Initializer.run do |config| | |
config.time_zone = "UTC" | |
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
function getTimezone(){ | |
var current_date_time = new Date(); | |
currentTimeZoneOffsetInHours = (-1) * current_date_time.getTimezoneOffset()/60; | |
return currentTimeZoneOffsetInHours; | |
} |
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
SELECT e.enumlabel | |
FROM pg_enum e | |
JOIN pg_type t ON e.enumtypid = t.oid | |
WHERE t.typname = 'yourenumname' |
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
1.9.3-p125 :007 > x=[["2010-01-10", 2], ["2010-01-09", 5], ["2009-12-11", 3], ["2009-12-12", 12], ["2009-12-13", 0]] | |
=> [["2010-01-10", 2], ["2010-01-09", 5], ["2009-12-11", 3], ["2009-12-12", 12], ["2009-12-13", 0]] | |
1.9.3-p125 :008 > x.sort_by{|k|k[1]} | |
=> [["2009-12-13", 0], ["2010-01-10", 2], ["2009-12-11", 3], ["2010-01-09", 5], ["2009-12-12", 12]] | |
1.9.3-p125 :009 > x.sort_by{|k|k[0]} | |
=> [["2009-12-11", 3], ["2009-12-12", 12], ["2009-12-13", 0], ["2010-01-09", 5], ["2010-01-10", 2]] |
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
1.9.3-p125 :002 > [1,2,3,4,5].delete_if{|i| i%2==0} | |
=> [1, 3, 5] |
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/controllers/users/omniauth_callbacks_controller.rb | |
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController | |
def twitter | |
# You need to implement the method below in your model | |
auth = env["omniauth.auth"] | |
@user = user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.new | |
if @user.persisted? | |
flash[:notice] = I18n.t "devise.omniauth_callbacks.success" | |
sign_in_and_redirect @user, :event => :authentication | |
else |
OlderNewer