Skip to content

Instantly share code, notes, and snippets.

View carlosantoniodasilva's full-sized avatar
👨‍💻
Hacking beautiful code...

Carlos Antonio da Silva carlosantoniodasilva

👨‍💻
Hacking beautiful code...
View GitHub Profile
class Test
def self.public_method
"Hello from public"
end
protected
def self.protected_method
"Hello from 'supposted' protected method"
end
@carlosantoniodasilva
carlosantoniodasilva / config.rb
Created July 28, 2010 01:02
Simple config class
## Simple config class - testing purposes =)
FooConfig = Class.new do
def initialize(config_file, env)
@config = YAML.load_file(config_file)[env]
end
def method_missing(method, *args)
@config.send(:[], method.to_s, *args)
end
## Original
def reverse_sql_order(order_query)
order_query.join(', ').split(',').collect { |s|
if s.match(/\s(asc|ASC)$/)
s.gsub(/\s(asc|ASC)$/, ' DESC')
elsif s.match(/\s(desc|DESC)$/)
s.gsub(/\s(desc|DESC)$/, ' ASC')
else
s + ' DESC'
end
# Rack-test
p find("#lst-servicos-proximos li:eq(1)").text
"\n \n LINCES LINCES BLUMENAURUA MARECHAL DEODORO, , 397, BLUMENAU, SC(47) 3035-4455\n \n 63,28 km\n \n \n \n \n
p find("#lst-servicos-proximos li:eq(1)").native.class
Nokogiri::XML::Element
# Selenium
p find("#lst-servicos-proximos li:eq(1)").text
@carlosantoniodasilva
carlosantoniodasilva / gist:640361
Created October 22, 2010 11:08
Configure User Agent for selenium webdriver in Capybara
# Re-register selenium driver to be able to pass in the profile option, overriding the user agent.
Capybara.register_driver :selenium do |app|
require 'selenium/webdriver'
profile = Selenium::WebDriver::Firefox::Profile.new
profile['general.useragent.override'] = 'FooBar'
Capybara::Driver::Selenium.new(app, :profile => profile)
end
@carlosantoniodasilva
carlosantoniodasilva / gist:701163
Created November 15, 2010 23:21
Rails 3.0.2 "visit_Foo" Arel error
require 'rubygems'
require 'sqlite3'
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3', :database => ':memory:'
)
ActiveRecord::Schema.define(:version => 0) do
create_table :users, :force => true do |t|
@carlosantoniodasilva
carlosantoniodasilva / gist:709301
Created November 21, 2010 23:44
SimpleForm submit with cancel link example
module SimpleForm
class FormBuilder < ActionView::Helpers::FormBuilder
# You can just override the default submit button and add the functionality.
#
# Simple usage:
# f.button :submit 'Send!', :cancel_link => root_path
#
def submit(*args)
cancel_link = args.last.is_a?(Hash) && args.last.delete(:cancel_link)
submit_button = super
@carlosantoniodasilva
carlosantoniodasilva / post-receive
Created February 9, 2011 01:28
Basic git post-receive hook file to deploy a Rails app.
#!/bin/bash
APP_NAME="your-app-name-goes-here"
APP_PATH=/home/deploy/${APP_NAME}
# Production environment
export RAILS_ENV="production"
# This loads RVM into a shell session. Uncomment if you're using RVM system wide.
# [[ -s "/usr/local/lib/rvm" ]] && . "/usr/local/lib/rvm"
@carlosantoniodasilva
carlosantoniodasilva / gist:906129
Created April 6, 2011 17:49
Running Capybara + Webdriver with Xvfb in a CI server (linux)
## rake command
RAILS_ENV=test DISPLAY=:2.0 rake db:migrate spec:acceptance
## init.d
#!/bin/sh
### BEGIN INIT INFO
# Provides: xvfb
@carlosantoniodasilva
carlosantoniodasilva / rspec_before_after_blocks.rb
Created April 14, 2011 17:55
Example showing how RSpec before/after blocks work.
# Acceptance spec
require "acceptance_helper"
feature "Rspec before blocks" do
before(:suite) do
puts "I'll run just once, before suite"
end
before(:all) do
puts "I'll run 3 times, before all"