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
# Why even the simple validations for ActiveRecord must also be tested. | |
# Can you spot the error? | |
validates_numericality_of :discount, :allow_nil => false, | |
:greater_than_or_equal => 0, | |
:less_than_or_equal_to => 100, | |
:if => :published? |
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 'rubygems' | |
require 'sinatra' | |
require 'activerecord' | |
#db settings | |
ActiveRecord::Base.establish_connection( | |
:adapter => '', | |
:encoding => '', | |
:database => '', | |
:username => '', |
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
# In my test_helper | |
def self.should_have_valid_test_data | |
klass = self.name[/^(.*)Test$/, 1].constantize | |
test "#{klass.name} should have valid fixtures" do | |
invalids = klass.all.reject{|m|m.valid?} | |
message = "Expected all #{klass.name} fixtures to be valid.\nInvalids:\n#{ | |
invalids.map{|m| [m.errors.full_messages, m]}.pretty_inspect}" | |
assert_block(message) { invalids.empty? } |
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
Rails CMS alternatives | |
====================== | |
Active projects: | |
--------------- | |
adva-cms | |
repo: http://github.com/svenfuchs/adva_cms/ | |
site: http://adva-cms.org/ | |
Last update: 11/24/09 | |
"the cutting edge Rails CMS platform" |
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
# Neater Github gem dependencies for Rails | |
module GithubGem | |
def github_gem(gem_name, opts={}) | |
lib_name = gem_name.split('-', 2)[1] | |
self.gem gem_name, {:lib => lib_name, :source => 'http://gems.github.com'}.merge(opts) | |
end | |
end | |
Rails::Initializer.run do |config| |
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
# In .irbrc | |
# then when you want to play with generating urls from the console, | |
# just call make_urls and you're set. | |
def make_urls | |
self.class.class_eval do | |
include ActionController::UrlWriter | |
mattr_accessor :default_url_options | |
end | |
self.class.default_url_options = { |
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
# Our deployment tags are s or p followed by YYmmdd-HHMMSS | |
namespace :deploy do | |
namespace :pending do | |
desc "Show the list of new migrations since the last deployments to staging and production" | |
task :migrations do | |
tags = run_locally("git tag").split | |
staging = tags.grep(/\As\d{6}-\d{6}\Z/).sort.last | |
production = tags.grep(/\Ap\d{6}-\d{6}\Z/).sort.last | |
%w(staging production).each do |stage| | |
puts '', stage |
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 String | |
# Return everything after the given string | |
# or nil if the substring can't be found | |
def after(prefix) | |
match = self.match Regexp.new(Regexp.escape(prefix) + "(.*)") | |
match && match[1] | |
end | |
end | |
dir = "/Users/mat/Desktop/wordpress-1" |
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
# Rubygems 1.3.1 incompatible with rbx. Missing constant EACCESS | |
# Either with the dev's bin/ in the path or rbx symlinked in the path, | |
# I get the following error: | |
$ rbx gem install rack --no-rdoc --no-ri | |
ERROR: While executing gem ... (NameError) | |
Missing or uninitialized constant: EACCESS | |
# Note: Yeah, I should SUDO |
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
# IRB prompt that looks like code samples | |
IRB.conf[:USE_READLINE] = true | |
IRB.conf[:AUTO_INDENT] = false | |
my_conf = IRB.conf[:PROMPT][:COPY] = {} | |
my_conf[:PROMPT_N] = "" | |
my_conf[:PROMPT_S] = "" | |
my_conf[:PROMPT_I] = "" | |
my_conf[:PROMPT_C] = "" | |
my_conf[:RETURN] = "#=> %s\n\n" |