Skip to content

Instantly share code, notes, and snippets.

@dreamr
dreamr / gist:722201
Created November 30, 2010 19:14
array.rb
class Array
def to_hash
begin
raise ArgumentError if self.collect {|x| x.flatten.size > 2}.reject {|x| x == false}.size > 0
Hash[*self.flatten]
rescue NoMethodError
raise ArgumentError
end
end
end
@dreamr
dreamr / gist:735541
Created December 9, 2010 23:57
Spec Failures
WorkOrder
adding cost codes
should not have a cost code (FAILED - 1)
should allow you to add a cost code (FAILED - 2)
should have one field cost code (FAILED - 3)
should have one engineering cost code (FAILED - 4)
has 100 hours of Field labor (FAILED - 5)
has 100 hours of Engineering labor (FAILED - 6)
will update the total field labor on save (FAILED - 7)
will update the total engineering labor on save (FAILED - 8)
@dreamr
dreamr / gist:735545
Created December 10, 2010 00:01
Failing specs
1)
'AccountController AccountController should be able to upload avatar' FAILED
expected: 1,
got: 0 (using ==)
./spec/controllers/account_controller_spec.rb:144:
2)
'Pic pic should be valid when files are png or gif' FAILED
expected valid_on_create? to return true, got false
./spec/models/pic_spec.rb:18:
rake spec:models
(in /Users/james/development/clients/blanee)
./spec/models/../../config/../vendor/rails/railties/lib/rails/gem_dependency.rb:119:Warning: Gem::Dependency#version_requirements is deprecated and will be removed on or after August 2010. Use #requirement
WARNING: Nokogiri was built against LibXML version 2.7.7, but has dynamically loaded 2.7.3
loading categories and citis
load finished
Mocha deprecation warning: Mocha::Standalone has been renamed to Mocha::API
......................................Ftrue
true
# mine
@user_questions = UserQuestion.by_clinic_id(@clinic.id).by_user_id(current_user.id).
ordered
# yours
@user_questions = UserQuestion.where("question_id IN (?)", question_ids)
@dreamr
dreamr / auth_spec_helper.pb
Created June 1, 2011 21:29
Basic Auth helpers
module AuthenticationSpecHelper
def current_user(user=nil)
@current_user ||= Factory(:user)
end
def user_session(stubs = {}, user=nil)
@current_user_session ||= mock_model(UserSession, {:user => current_user(user)})
end
def login(session_stubs = {}, user=nil)
@dreamr
dreamr / spec_helper.rb
Created June 1, 2011 21:36
my spec helper
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'authlogic/test_case'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
@dreamr
dreamr / tasks_spec.rb
Created June 1, 2011 21:37
request spec for tasks
require 'spec_helper'
describe "Tasks" do
before(:each) do
login_as(:developer)
end
describe "GET /tasks" do
it "renders" do
visit tasks_path
class UserSession < Authlogic::Session::Base
extend ActiveModel::Naming
end
require 'faker'
require "#{Rails.root}/app/lib/railstar_lib/data/masked_field"
require "#{Rails.root}/spec/support/factory_sequences"
include RailstarLib::Data
Factory.define :user do |u|
u.name { Faker::Name.name }
u.email { Factory.next(:email) }
u.password "password"