- 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
This file contains hidden or 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/active_record.rb | |
module ActiveRecord | |
class Base | |
# Find by array of IDs, preserving order of IDs | |
# See http://stackoverflow.com/a/25248122/83743 | |
def self.find_with_relevance(array_of_ids) | |
array_of_ids = Array(array_of_ids) unless array_of_ids.is_a?(Array) | |
self.find(array_of_ids).index_by(&:id).slice(*array_of_ids).values | |
end |
This file contains hidden or 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_indexed.rb | |
ActsAsIndexed.configure do |config| | |
# Disable acts_as_indexed auto indexing in test by default | |
config.disable_auto_indexing = Rails.env.test? | |
end |
This file contains hidden or 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
# Gemfile | |
gem 'paypal-sdk-merchant' | |
group :test do | |
gem 'fakeweb', '1.2.6' | |
end |
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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]); } |