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 'net/http' | |
class FeedDetector | |
# return the feed url for a url | |
# for example: http://blog.dominiek.com/ => http://blog.dominiek.com/feed/atom.xml | |
# only_detect can force detection of :rss or :atom | |
def self.fetch_feed_url(page_url, only_detect=:any) | |
url = URI.parse(page_url) | |
host_with_port = url.host | |
host_with_port << ":#{url.port}" unless url.port == 80 |
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 :datarm do | |
desc "Run Trip Wires" | |
task :run_trip_wires => :environment do |rake_task| | |
proceed(rake_task) do | |
TripWireEngine.proceed_all_active | |
end | |
end | |
desc 'Empty action for report. Requirements: REPORT_ID' | |
task :empty_report => :environment do |rake_task| |
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
<head> | |
<meta http-equiv="content-type" content="text/html;charset=UTF-8" /> | |
<title><%= yield :title || "Philtro" %></title> | |
<%= yield :head -%> | |
</head> | |
<body> |
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
describe FooController do | |
describe "route generation" do | |
it "should map { :controller => 'foo', :action => 'index' } to /foo" do | |
route_for(:controller => "foo", :action => "index").should == "/foo" | |
end | |
end | |
describe "route recognition" do | |
it "should generate params { :controller => 'foo', action => 'index' } from GET /foo" do | |
params_from(:get, "/foo").should == {:controller => "foo", :action => "index"} |
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
if Rails.env.development? | |
ActiveRecord::Base.class_eval do | |
def log_protected_attribute_removal(*attributes) | |
raise "Can't mass-assign these protected attributes: #{attributes.join(', ')}" | |
end | |
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
class ActionController::Base | |
private | |
def rescue_action_in_public(exception) | |
respond_to do |want| | |
want.html { | |
super(exception) | |
} | |
want.js { | |
render :update do |page| |
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 ActionController::Base | |
private | |
def rescue_action_in_public(exception) | |
respond_to do |want| | |
want.html { | |
super(exception) | |
} | |
want.js { | |
render :update do |page| |
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 Errors | |
# Redefine the ActiveRecord::Errors::full_messages method: | |
# E.g. validates_acceptance_of :accepted_terms, :message => 'Please accept the terms of service' | |
def full_messages | |
full_messages = [] | |
@errors.each_key do |attr| | |
@errors[attr].each do |msg| |
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 Array | |
# does a kind of ZIP compression for integer arrays | |
# examples: | |
# [0,1,2,3].compress! => [[0, 4]] | |
# [1,2,3,8,9,10,11].compress! => [[1, 3], [8, 4]] | |
# [1,3,5].compress! => [1, 3, 5] | |
# [1,3,5,6].compress! => [1, 3, [5, 2]] | |
def compress! | |
compact! | |
return [] if empty? |
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
# rake app:test:file file=sample_test,other_test,third_test,etc_test | |
# rake app:test:file file=sample name=method_to_test | |
# rake app:test:monitor | |
namespace :app do | |
namespace :test do | |
# accepts ARGV[1] as parameter for test file patterns. Format: | |
# ARGV[1] = "file=[pattern]" (pattern can be a comma list of multiple files) | |
# ARGV[2] = "name=[method]" name of method to run in test file | |
desc "Run a single test without preparing database first. Smart about finding the test file.\n Syntax: rake app:test file=[basename] where basename matches (globbed) test(s).\n Will accept multiple comma delimted file patterns. " |
OlderNewer