Skip to content

Instantly share code, notes, and snippets.

View brookr's full-sized avatar
💭
🚀

Brook Riggio brookr

💭
🚀
View GitHub Profile
Rails 2.2.2, Shoulda 2.9.1, Factory Girl 1.2.0
The default test:
context 'PUT to update for existing survey' do
setup do
@survey = Factory(:survey)
put :update, :id => @survey.to_param,
:survey => Factory.attributes_for(:survey)
context 'PUT to update for existing survey' do
setup do
@survey = Factory(:survey)
put :update, :id => @survey.to_param,
:survey => Factory.attributes_for(:survey)
end
should_set_the_flash_to /updated/i
should_redirect_to 'surveys_path(@survey)'
end
survey_controller_test.rb:
context 'PUT to update for existing survey' do
setup do
@survey = Factory(:survey)
put :update, :id => @survey.to_param,
:survey => Factory.attributes_for(:survey)
end
class SurveysController < ApplicationController
# GET /surveys
# GET /surveys.xml
def index
@surveys = Survey.find(:all, :limit => 50)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @surveys }
end
require File.dirname(__FILE__) + '/../test_helper'
class SurveysControllerTest < ActionController::TestCase
context 'GET to index' do
setup do
@staff = Factory(:staff)
session['staff'] = @staff.id
get :index
end
gem 'faker'
require 'faker'
# Clean out what is there
# Makes a bunch of different types of events per day at a random time during work hours
account_id ||= 1
(30.days.ago.to_date..90.days.from_now.to_date).each do |date|
rand(5).times do
start = date.beginning_of_day + 8.hours + (rand(32) * 15).minutes
require 'rubygems'
require 'utility_belt'
require 'wirble'
class Object
def local_methods
(methods - Object.instance_methods).sort
end
end
def load_sql_file(file)
config = ActiveRecord::Base.configurations[RAILS_ENV]
database = config['database']
user = config['username']
puts `psql -U #{user} -f #{file} #{database}`
end
desc 'Load an SQL file'
task :load_sql => [ENV['FILE'], :environment] do |t|
file = ENV['FILE']
@brookr
brookr / FakerCalData.rb
Created November 15, 2009 06:41 — forked from carlosdavis/gist:225567
Fake CalHawk Data
gem 'faker'
require 'faker'
I18n.reload!
account_id = 4
# Makes a bunch of different types of events per day at a random time during work hours
(30.days.ago.to_date..90.days.from_now.to_date).each do |date|
rand(3).times do
start = date.beginning_of_day + 8.hours + (rand(32) * 15).minutes
class NilClass
def method_missing(method, *args, &block)
nil
end
end