Skip to content

Instantly share code, notes, and snippets.

# before
Factory.define :base_post, :class => Post do |h|
h.name "Demo"
...
end
#after
Factory.define :base_post, :class => "Post" do |h|
h.name "Demo"
...
class Capybara::Server
def self.manual_host=(value)
@manual_host = value
end
def self.manual_host
@manual_host ||= 'localhost'
end
def url(path)
if path =~ /^http/
Before ('@subdomain') do
Capybara::Server.manual_host = "subdomain.myapp.local"
Capybara.default_host = "subdomain.example.org"
end
After ('@subdomain') do
Capybara.default_host = "example.org"
Capybara::Server.manual_host = "myapp.local"
end
Night Load (2.5ms) SELECT * FROM `nights` WHERE (`nights`.room_type_id = 1) ORDER BY date ASC
app/helpers/admin/nights_helper.rb:68:in `nights_form_helper'
app/views/admin/nights/edit.html.haml:13
haml (3.0.10) rails/./lib/haml/helpers/action_view_mods.rb:225:in `call'
haml (3.0.10) rails/./lib/haml/helpers/action_view_mods.rb:225:in `form_for_without_live_validations'
haml (3.0.10) lib/haml/helpers.rb:588:in `call'
haml (3.0.10) lib/haml/helpers.rb:588:in `haml_bind_proc'
....
dragonfly (0.6.1) lib/dragonfly/middleware.rb:13:in `call'
script/plugin install git://github.com/ntalbott/query_trace.git
@jamesalmond
jamesalmond / asynchronous_sinatra.rb
Created November 8, 2010 11:37
Using the test helpers in the async_sinatra library to drive cucumber tests
ENV["RACK_ENV"] = 'test'
require 'rspec'
require 'test/unit'
require 'rack/test'
require "sinatra/async/test"
module AppRunner
def app
My::App.new
end
@jamesalmond
jamesalmond / async_sinatra_rspec.rb
Created November 8, 2010 12:11
A way of integrating async_sinatra tests into RSpec
require "spec_helper"
require "sinatra/async/test"
require 'test/unit'
module My
describe App do
include Sinatra::Async::Test::Methods
include Test::Unit::Assertions
def app
App
#some_object_controller.rb
class SomeObjectController < ApplicationController
def search
@search_results = SomeClass.find(params[:search_term])
end
end
# search.html.haml
- if @search_results.count > 0
- @search_results.each do |result|
#some_object_controller.rb
class SomeObjectController < ApplicationController
def search
@search_results = SomeClass.find(params[:search_term])
if @search_results.count > 0
render :search_results
else
render :no_search_results
end
class SomeObjectController < ApplicationController
def show
@object = SomeObject.find(params[:id])
render @object.status
end
end