Skip to content

Instantly share code, notes, and snippets.

View tanelsuurhans's full-sized avatar

Tanel Suurhans tanelsuurhans

  • ID.me
  • United States
View GitHub Profile
class ImportController << ApplicationController
require 'net/http'
require 'net/https'
require 'uri'
#THIS METHOD TO SEND USER TO THE GOOGLE AUTHENTICATION PAGE.
def authenticate
# initiate authentication w/ gmail
# create url with url-encoded params to initiate connection with contacts api
require 'spec_helper'
describe Purchase do
before :all do
@city = Factory.create(:city)
@user = Factory.create(:user, :cities => [@city])
@ticket = Factory.create(:ticket)
end
describe Foo do
let(:bar) { Factory.create(:bar) }
subject { Factory.create(:foo, :bar => bar) }
context "something" do
let(:bar) { Factory.create(:different_bar) }
@tanelsuurhans
tanelsuurhans / gist:969400
Created May 12, 2011 20:43
Date and time inconsistencies
ruby-1.9.2-p180 :005 > Date.today.to_time
=> 2011-05-12 00:00:00 +0300
ruby-1.9.2-p180 :006 > Date.today.to_datetime
=> Thu, 12 May 2011 00:00:00 +0000
ruby-1.9.2-p180 :007 > Date.today.to_time_in_current_zone
=> Thu, 12 May 2011 00:00:00 EDT -04:00
ruby-1.9.2-p180 :008 > Time.zone
=> (GMT-05:00) Eastern Time (US & Canada)
ruby-1.9.2-p180 :009 > Time.now
=> 2011-05-12 23:43:28 +0300
def set_cache_buster
response.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "#{10.year.ago}"
end
RSpec.configure do |config|
config.include Paperclip::Shoulda::Matchers
config.mock_with :mocha
config.use_transactional_fixtures = true
config.before(:all) do
geocode_payload = GeoKit::GeoLoc.new(:lat => 123.456, :lng => 123.456)
geocode_payload.success = true
GeoKit::Geocoders::MultiGeocoder.stubs(:geocode => nil)
end
# TODO - add dependent option support
def delete_records(records)
case @reflection.through_reflection.options[:dependent]
when :destroy
records.each do |associate|
@reflection.through_reflection.klass.destroy_all(construct_join_attributes(associate))
end
when :delete_all
@reflection.through_reflection.klass.delete(records.map { |record| record.id })
else
auth = Twitter::OAuth.new(TWITTER_TOKEN, TWITTER_SECRET)
auth.authorize_from_access(TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_SECRET)
base = Twitter::Base.new(auth)
base.update("#{title} - #{url}")
class UserPassword
include ActiveModel::Validations
include ActiveModel::Validations::Callbacks
include ActiveModel::Conversion
extend ActiveModel::Naming
extend ActiveModel::Translation
attr_accessor :email
def value=(value)
write_attribute(:value, value.gsub(/<your regexp>/, ''))
end