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
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) |
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
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 |
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
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 | |
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 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 |
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 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 |
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
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 |
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 'rubygems' | |
require 'utility_belt' | |
require 'wirble' | |
class Object | |
def local_methods | |
(methods - Object.instance_methods).sort | |
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
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'] |
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
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 |
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 NilClass | |
def method_missing(method, *args, &block) | |
nil | |
end | |
end |
OlderNewer