Skip to content

Instantly share code, notes, and snippets.

View jhchabran's full-sized avatar
🧀

Jean-Hadrien Chabran jhchabran

🧀
View GitHub Profile
class IO
def readbytes(n)
str = read(n)
if str == nil
raise EOFError, "End of file reached"
end
if str.size < n
raise TruncatedDataError.new("data truncated", str)
end
str
class RestfulActions
include Singleton
Action = Struct.new(:name, :method, :args)
@@actions = []
[
[:index, :get],
[:new, :get],
[:show, :get, {:id => 1}],
# custom matchers to expect layouts
Spec::Matchers.define :use_layout do |layout|
match do |response|
response.layout == layout
end
failure_message_for_should do |employee|
"expected response to use layout named #{layout}"
end
failure_message_for_should_not do |employee|
"expected response to not use layout named #{layout}"
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe BabysittersController do
integrate_views
context "when not authenticated" do
RestfulActions.for(BabysittersController) do |action|
it "should redirect to root path when accessing ##{action.name}" do
send action.method, action.name, action.args
response.should redirect_to(root_path)
# When deploying for the first time, use vlad:install before vlad:deploy
# 1) vlad:install will copy all files matching .sample* in deploy_to/shared/config
# 2) edit those files and rename them to their final name
# 3) each time you deploy with vlad:deploy, your config files will be symlinked in your application config folder
namespace :vlad do
def shared_config_path
shared_path + '/' + 'config'
end
Rake::Task.define_task(:environment)
load RAILS_ROOT + '/lib/tasks/seed.rake'
Rake.application['db:seed:load'].invoke
module Keywordable
module ClassMethods
def keyword(symbol, proc)
write_inheritable_attribute :keywords, {} unless read_inheritable_attribute :keywords
read_inheritable_attribute(:keywords)[symbol] = proc
end
end
module InstanceMethods
def keywords
# Autocomplete handler for all core controllers.
#----------------------------------------------------------------------------
def auto_complete
@query = params[:auto_complete_query]
@auto_complete = hook(:auto_complete, self, :query => @query, :user => @current_user)
if @auto_complete.empty?
@auto_complete = self.controller_name.classify.constantize.my(:user => @current_user, :limit => 10).search(@query)
else
@auto_complete = @auto_complete.last
end
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe Snapshot do
before(:each) do
@observer = PretendObserver.new(@string_io = StringIO.new("","w"))
end
it "should create a snapshot ready to be applied" do
Snapshot.new(:size => "4G", :path => '/dev/vg00/pwet-disk', :name => 'pwet')
end
Usine := Object clone do (
DummyObject := Object clone do (
Suite := Object clone do (
variantName := nil
bodyBlock := nil
eval := method(x,
context := Object clone
context setSlot(variantName, x)