Skip to content

Instantly share code, notes, and snippets.

View cassiomarques's full-sized avatar
💭
I have no idea what I'm doing

Cássio Marques cassiomarques

💭
I have no idea what I'm doing
View GitHub Profile
class ContactType < EnumerateIt::Base
associate_values(
:email => 1,
:sms => 2,
:phone => 3,
:smoke_signal => 4
)
end
person = Person.new
@cassiomarques
cassiomarques / gist:674824
Created November 12, 2010 22:37
New features for EnumerateIt
# Feature1: Change enumeration value based on bang methods (available only
# when passing true to the :create_helpers option)
class RelationshipStatus < EnumerateIt::Base
associate_values(
:single => 1,
:married => 2,
:widow => 3
)
end
@cassiomarques
cassiomarques / gist:663500
Created November 5, 2010 01:14
How to read constraints direct from postgresql databases
# == Schema Information
#
# Table name: information_schema.table_constraints
#
# constraint_catalog :
# constraint_schema :
# constraint_name :
# table_catalog :
# table_schema :
# table_name :
@cassiomarques
cassiomarques / gist:658634
Created November 1, 2010 18:13
Como fazer o webdriver aceitar os diálogos de confirmação JavaScript do browser (testei apenas no Chrome)
# MacGyver mode ON
Quando /^sigo "([^"]*)" aceitando a confirmação$/ do |link|
page.execute_script("window.confirm = function() { return true; }")
click_link link
end
class SectionType < EnumerateIt::Base
asociate_values(
:type_a => 1,
:type_b => 2
)
end
class Section < ActiveRecord::Base
# não precisa passar a opcao :with pois o nome do atributo coincide
# com o nome da enumeration
# is it risky to trust on updated_at ?
# Summary: all products with no price on API should be disabled.
# adding a new 'updated_by_api_at' timestamp field to the products table...
start_time = Time.now
Product.transaction do
ProductApi.each do |e|
Product.find(e.code).update_attributes :price => e.price, :updated_by_api_at = Time.now
end
charset_table: "0..9, a..z, _, A..Z->a..z, U+2E->., U+00C0->a, U+00C1->a,U+00C2->a, U+00C3->a, U+00C4->a, U+00C5->a, U+00C7->c, U+00C8->e,U+00C9->e, U+00CA->e, U+00CB->e, U+00CC->i, U+00CD->i, U+00CE->i,U+00CF->i, U+00D1->n, U+00D2->o, U+00D3->o, U+00D4->o, U+00D5->o,U+00D6->o, U+00D9->u, U+00DA->u, U+00DB->u, U+00DC->u, U+00DD->y,U+00E0->a, U+00E1->a, U+00E2->a, U+00E3->a, U+00E4->a, U+00E5->a,U+00E7->c, U+00E8->e, U+00E9->e, U+00EA->e, U+00EB->e, U+00EC->i,U+00ED->i, U+00EE->i, U+00EF->i, U+00F1->n, U+00F2->o, U+00F3->o,U+00F4->o, U+00F5->o, U+00F6->o, U+00F9->u, U+00FA->u, U+00FB->u,U+00FC->u, U+00FD->y, U+00FF->y, U+0100->a, U+0101->a, U+0102->a,U+0103->a, U+0104->a, U+0105->a, U+0106->c, U+0107->c, U+0108->c,U+0109->c, U+010A->c, U+010B->c, U+010C->c, U+010D->c, U+010E->d,U+010F->d, U+0112->e, U+0113->e, U+0114->e, U+0115->e, U+0116->e,U+0117->e, U+0118->e, U+0119->e, U+011A->e, U+011B->e, U+011C->g,U+011D->g, U+011E->g, U+011F->g, U+0120->g, U+0121->g, U+0122->g,U+0123->g, U+0124->h, U+0125->h, U+0128
class Hash
def hash_from(*keys)
self.delete_if { |k, v| !keys.include? k }
end
end
describe ".estado" do
before :each do
@estado1 = "SP"
@estado2 = "RJ"
@anuncio1 = Anuncio.make :estado => @estado1
@anuncio2 = Anuncio.make :estado => @estado1
@anuncio3 = Anuncio.make :estado => @estado2
@anuncio4 = Anuncio.make :estado => @estado2
end
class Gato < Animal; end
class Cachorro < Animal; end
describe Animal do
before(:each) do
@animal = Animal.new
end
it "ao criar um Animal, o contador dos filhoes deve permanecer 0" do
lambda { a = Animal.new }.should_not change(Gato, :total)
end