Skip to content

Instantly share code, notes, and snippets.

View rafaellima's full-sized avatar

Rafael Lima rafaellima

View GitHub Profile
@rafaellima
rafaellima / modules_constants
Created July 13, 2012 03:37
name spacing applies to the constants
module A
module B
end
end
p A::B
module A
C = 10
end
@rafaellima
rafaellima / rspe_in_test_unit
Created September 12, 2012 01:28
just an example about how rspec works inside
require 'test/unit'
class TestDescribe < Test::Unit::TestCase
def test_that_it_can_pass
describe "something" do
end
end
@rafaellima
rafaellima / gist:5288299
Created April 1, 2013 22:26
Some thoughts about the law of Demeter
BAD SMELL
class Invoice < ActiveRecord::Base
belongs_to :user
end
<%= @invoice.user.name %>
<%= @invoice.user.email %>
@rafaellima
rafaellima / gist:5391441
Created April 15, 2013 21:32
Avoiding switch - case statements
rules = Rules.find :all
#Calling a method based on it's rule
rules.each do |rule|
case rule
when "foo"
foo()
when "bar"
bar()

Capybara Actions

# Anchor
click_link 'Save'

# Button
click_button 'awesome'

# Both above
require 'active_record'
require 'database_cleaner'
connection_info = YAML.load_file("config/database.yml")["test"]
ActiveRecord::Base.establish_connection(connection_info)
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
@rafaellima
rafaellima / gist:8411524
Created January 14, 2014 01:32
Refactoring a user model that sends a e-mail.
def expire
Email.to self.email_address, :expiration
destroy
end
module Email
def self.to(email_address, template_name)
case template_name
when :expiration
require 'minitest/autorun'
class TestDescribe < Minitest::Test
def test_that_it_can_pass
whatever "that it describes" do
another_block "lol" do
end
end
end
require 'active_record'
connection_info = YAML.load_file("config/database.yml")["test"]
ActiveRecord::Base.establish_connection(connection_info)
RSpec.configure do |config|
config.around do |example|
ActiveRecord::Base.transaction do
example.run
raise ActiveRecord::Rollback
Status Code Status Message Symbol
1xx Informational
100 Continue :continue
101 Switching Protocols :switching_protocols
102 Processing :processing
2xx Success
200 OK :ok
201 Created :created
202 Accepted :accepted