Skip to content

Instantly share code, notes, and snippets.

def to_headers
kookie = ""
self.each do |name, value|
options = @_cookie_defaults.merge(@_options_lookup[name] || {})
secure = options.delete(:secure)
kookie << "#{name}=#{Merb::Request.escape(value)}; "
options.each {|k, v| kookie << "#{k}=#{v}; " }
kookie << 'secure' if secure
end
{ 'Set-Cookie' => [kookie] }
it "should allow you to use cookie-based sessions" do
with_cookies(@controller_class) do
controller = dispatch_to(@controller_class, :store_in_cookie)
controller.request.session(:cookie)[:foo].should == "cookie-bar"
controller.request.session[:foo].should == "cookie-bar" # defaults to the first registered store
end
end
it "should allow you to use cookie-based sessions" do
with_cookies(@controller_class) do
it "should render a collection of nested value/content arrays" do
form_for @obj do
content = select(:foo, :collection => [["small", "Small"], ["medium", "Medium"], ["large", "Large"]])
content.should match_tag(:select, :id => "fake_model_foo", :name => "fake_model[foo]")
content.should match_tag(:option, :value => "small", :content => "Small")
content.should match_tag(:option, :value => "medium", :content => "Medium")
content.should match_tag(:option, :value => "large", :content => "Large")
end
end
def update_unbound_check_box(attrs)
boolean = attrs[:boolean] || (attrs[:on] && attrs[:off]) ? true : false
case
when attrs.key?(:on) ^ attrs.key?(:off)
raise ArgumentError, ":on and :off must be specified together"
when (attrs[:boolean] == false) && (attrs.key?(:on))
raise ArgumentError, ":boolean => false cannot be used with :on and :off"
when boolean && attrs.key?(:value)
raise ArgumentError, ":value can't be used with a boolean checkbox"
>> def awesome
>> x = 7
>> proc { self * x }
>> end
=> nil
>> awesome
=> #<Proc:0x00368b84@(irb):3>
>> awesome[]
NoMethodError: undefined method `*' for main:Object
from (irb):3:in `awesome'
# t = Containers::Trie.new
# t.push("Hello", "World")
# t.push("Hilly", "World")
# t.push("Hello, bob", "World")
# t.wildcard("H*ll.") #=> ["Hello", "Hilly"]
# t.wildcard("Hel") #=> []
Merb::Router.prepare do
resources :donors do
resources :pledges do
resources :donations
end
end
resources :campaigns do
The pundits like to slice-and-dice our country into Red States and Blue States; Red States for Republicans, Blue States for Democrats. But I've got news for them, too. We worship an awesome God in the Blue States, and we don't like federal agents poking around our libraries in the Red States. We coach Little League in the Blue States and have gay friends in the Red States. There are patriots who opposed the war in Iraq and patriots who supported it. We are one people, all of us pledging allegiance to the stars and stripes, all of us defending the United States of America.
@wycats
wycats / gist:8093
Created August 30, 2008 06:18 — forked from carllerche/gist:8091
it "should only use the second namespace" do
Merb::Router.prepare do |r|
r.namespace(:foo) do |f|
end
r.namespace(:bar) do |b|
b.match("/login").to(:controller => "home").name(:login)
end
end
url(:bar_login).should == "/bar/login"
it 'should typecast Hash for a Date property' do
Zoo.class_eval { property :date, Date }
zoo = Zoo.new
zoo.date = {:year => 2002, "month" => 1, :day => 1}
zoo.date.should == Date.new(2002, 1, 1)
end