- Many people say "I hate my tests"
- They kill your productivity when they're slow
- A little change can break your tests (even if they shouldn't)
- They're expensive
- They are misery incarnate
- Just delete some tests
- You may have too many tests testing the wrong tests
This file contains 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
record = Post.new(:title => 'Yay', :body => 'This is some insert SQL') | |
# easiest way to achieve this is by calling protected #arel_attributes_values (tested in | |
# rails 3.2.13). the alternative is to build the entire insert statement using arel >_> | |
record.class.arel_table.create_insert \ | |
.tap { |im| im.insert(record.send(:arel_attributes_values, false)) } \ | |
.to_sql |
This file contains 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/core/rake_task' | |
orm_setting = Rails.configuration.generators.options[:rails][:orm] | |
spec_prereq = if(orm_setting == :active_record) | |
Rails.configuration.active_record[:schema_format] == :sql ? "db:test:clone_structure" : "db:test:prepare" | |
else | |
:noop | |
end | |
namespace :spec do | |
[:requests, :models, :controllers, :views, :helpers, :mailers, :lib, :routing].each do |sub| | |
dn = "#{File.expand_path(::Rails.root.to_s)}/spec/#{sub}" |
This file contains 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
#!/bin/bash | |
## | |
## A simple little shell script that will return the current | |
## fingerprint on the SSL certificate. It's crude but works :D | |
## | |
## Author: Bob Saska (r35krag0th) <[email protected]> | |
openssl s_client -connect tuner.pandora.com:443 < /dev/null 2> /dev/null | \ | |
openssl x509 -noout -fingerprint | tr -d ':' | cut -d'=' -f2 |
This file contains 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
#!/usr/bin/env ruby | |
# coding: utf-8 | |
require 'digest/md5' | |
require 'net/http' | |
class LastFM | |
attr_reader :api_key, :secret, :session_key, :base_uri, :namespace |
This file contains 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
RSpec::Matchers.define(:redirect_to_ssl) do | |
description { 'redirect to same page using the HTTPS protocol' } | |
match { |status| | |
response.redirect_url == request.url.gsub(/^http:/, 'https:') | |
} | |
end | |
# in spec/requests or similar... | |
get('/admin/sign_in').should redirect_to_ssl |
This file contains 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
class Luhn | |
def self.checksum(number) | |
digits = number.to_s.reverse.scan(/\d/).map { |x| x.to_i } | |
digits = digits.each_with_index.map { |d, i| | |
d *= 2 if i.even? | |
d > 9 ? d - 9 : d | |
} | |
sum = digits.inject(0) { |m, x| m + x } | |
mod = 10 - sum % 10 | |
mod==10 ? 0 : mod |
This file contains 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
installing Firefox on headless Ubuntu: | |
http://notes.hemju.com/notes/rails-cucumber-install-headless-firefox-on-ubuntu | |
Running Firefox on headless Ubuntu with selenium: | |
http://markgandolfo.com/?p=47 | |
Switching from Webrat to Capybara: | |
http://cakebaker.42dh.com/2010/09/19/cucumber-switching-from-webrat-to-capybara/ |
This file contains 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
module ActiveRecord | |
class Base | |
def self.merge_conditions(*conditions) | |
segments = [] | |
conditions.each do |condition| | |
unless condition.blank? | |
sql = sanitize_sql(condition) | |
segments << sql unless sql.blank? | |
end |
NewerOlder