- Unit tests are very narrowly focused on testing a single model
- Functional tests are very narrowly focused on testing a single controller and the interactions between the models it employs
- Integration tests are broad story-level tests that verify the interactions between the various actions supported by the application, across all controllers
My notes from the Meet Chef course at http://pluralsight.com/training/Courses/TableOfContents/meet-chef
Chef is a Ruby framework for automating, reusing and documenting server configuration. It's like Unit tests for your servers.
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 'benchmark' | |
def validate_by_request(value) | |
uri = URI.parse(value) | |
http = Net::HTTP.new(uri.host, uri.port) | |
if uri.scheme == "https" | |
http.use_ssl = true | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
end | |
request = Net::HTTP::Get.new(uri.request_uri) | |
http.request(request) |
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 'uri_validator' | |
class SomeModel < ActiveRecord::Base | |
validates :url, :presence => true, :uri => { :format => /(^$)|(^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?([\/].*)?$)/ix } | |
end |
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
# config/initializers/acts_as_list_skip_validation.rb | |
module ActiveRecord | |
module Acts | |
module List | |
module InstanceMethods | |
# Move the item within scope, but skips validation | |
def move_within_scope(scope_id) | |
send("#{scope_name}=", scope_id) | |
save(false) | |
end |
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 Object | |
def is_integer? | |
!!(check = Integer(self) rescue false) && check.try(:to_s) == self.try(:to_s) | |
end | |
end |
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
var q = {}; window.location.search.replace(/^\?/, '').split('&').map(function(e){ | |
var a = e.split('='); | |
q[a[0]] = a[1]; | |
}); | |
for (a in q) { console.log(a, q[a]); } |
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
<html> | |
<body> | |
<section class="left"> | |
<article id="customers"> | |
<h2>New Customers</h2> | |
<table class="data"> | |
<thead> | |
<tr> | |
<th>ID</th> | |
<th>First Name</th> |
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
namespace :db do | |
desc "Completely tears down the database, rebuilds it from scratch using your migrations (i.e. ignoring the current schema file), re-seeds the database based on the current environment, and finally prepares the test database" | |
task :bootstrap => ["db:drop", "db:create", "db:migrate", "db:seed", "db:test:prepare"] | |
end |
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
# Create a git branch based off of an arbitrary string. Call the function from | |
# the command line inside a git project and pass in the description (quoted or | |
# not) as the argument. Your description will be converted to slug format and | |
# used to checkout a new branch. Useful for quickly creating branches named | |
# after a ticket # and description. | |
# Example: | |
$ git-mb 123 Add a new feature \(Don't forget the tests\!\) | |
Switched to a new branch '123-add-a-new-feature-don-t-forget-the-tests' |