Skip to content

Instantly share code, notes, and snippets.

@knewter
knewter / foo
Created December 6, 2011 16:43
--($:~/projects/user-auth/user-auth)(rails-3-0)ruby-1.8.7-p352@user-auth--
$ bundle exec rspec spec
....................................../home/jadams/projects/user-auth/user-auth/spec/models/user_spec.rb:103
true
(rdb:1) irb
1.8.7 :001 > user.increment_login_failures!
=> #<User _id: 4ede462bee85702b02000021, locked_until: nil, last_request_at: nil, created_at: Tue Dec 06 16:43:23 UTC 2011, updated_at: Tue Dec 06 16:43:23 UTC 2011, admin: nil, _id: BSON::ObjectId('4ede462bee85702b02000021'), _type: nil, admin_locked: nil, full_name: nil, disabled: nil, locked_at: nil, password_reset_at: nil, login_failure_count: 1, email: "[email protected]">
1.8.7 :002 > user.increment_login_failures!
NoMethodError: undefined method `name' for nil:NilClass
from /home/jadams/.rvm/gems/ruby-1.8.7-p352@user-auth/gems/activesupport-3.0.11/lib/active_support/whiny_nil.rb:48:in `method_missing'
@knewter
knewter / foo
Created December 6, 2011 17:12
1.8.7 :001 > user.save!
=> true
1.8.7 :002 > user.save!
NoMethodError: undefined method `name' for nil:NilClass
from /home/jadams/.rvm/gems/ruby-1.8.7-p352@user-auth/gems/activesupport-3.0.11/lib/active_support/whiny_nil.rb:48:in `method_missing'
from /home/jadams/.rvm/gems/ruby-1.8.7-p352@user-auth/gems/mongoid-2.0.1/lib/mongoid/paths.rb:38:in `_position'
from /home/jadams/.rvm/gems/ruby-1.8.7-p352@user-auth/gems/mongoid-2.0.1/lib/mongoid/dirty.rb:124:in `setters'
from (irb):2:in `inject'
from /home/jadams/.rvm/gems/ruby-1.8.7-p352@user-auth/gems/mongoid-2.0.1/lib/mongoid/dirty.rb:123:in `each'
from /home/jadams/.rvm/gems/ruby-1.8.7-p352@user-auth/gems/mongoid-2.0.1/lib/mongoid/dirty.rb:123:in `inject'
Scenario: After cloning, I should receive notifications when the document is updated
Given there are global documents:
| title | slug |
| homepage | / |
| Newsroom | /newsroom |
And there are global documents:
| title | slug |
| eClipboard | eclipboard |
And I have cloned documents:
| title | global title | slug |
tester.rb:114:in `validate_output_from': Command does not match output! (RuntimeError)
Expected content contained within ch01/tests/ch01_3 to match this:
/home/jadams/.rvm/gems/ruby-1.9.2-p290@saas_book/gems/bundler-1.0.21/lib/bundler/resolver.rb:280:in `resolve': Could not find gem 'turn (= 0.8.2) ruby' in any of the gem sources listed in your Gemfile. (Bundler::GemNotFound)
from /home/jadams/.rvm/gems/ruby-1.9.2-p290@saas_book/gems/bundler-1.0.21/lib/bundler/resolver.rb:160:in `start'
from /home/jadams/.rvm/gems/ruby-1.9.2-p290@saas_book/gems/bundler-1.0.21/lib/bundler/resolver.rb:128:in `block in resolve'
from /home/jadams/.rvm/gems/ruby-1.9.2-p290@saas_book/gems/bundler-1.0.21/lib/bundler/resolver.rb:127:in `catch'
from /home/jadams/.rvm/gems/ruby-1.9.2-p290@saas_book/gems/bundler-1.0.21/lib/bundler/resolver.rb:127:in `resolve'
from /home/jadams/.rvm/gems/ruby-1.9.2-p290@saas_book/gems/bundler-1.0.21/lib/bundler/definition.rb:151:in `resolve'
from /home/jadams/.rvm/gems/ruby-1.9.2-p290@saas
class Foo < ActiveRecord::Base
scope :bar, lambda{|a| where(a: a) }
scope :baz, lambda{|b| where(b: b) }
end
# Foo.bar(a).baz(b) works fine.
class Foo < ActiveRecord::Base
class << self
def bar(a)
@knewter
knewter / order.rb
Created December 22, 2011 21:05 — forked from rthbound/order.rb
def self.statuses
Order.all.collect{|x| x.status}.uniq
end
# Currently : STATUSES = ["SHIPPED", "PROCESSING", "RECEIVED", "INCOMPLETE", "VOIDED", "REFUNDED", "FRAUDULENT", "ON HOLD"]
validates_inclusion_of :status, :in => statuses
statuses.map{|x| x.downcase.gsub(" ", "_")}.each { |s| named_scope s, :conditions => { :status => s } }
### JOSH PREFERS
named_scope :with_status, lambda{|s| { :conditions => { :status => s } } }
@knewter
knewter / work.rb
Created January 12, 2012 17:24 — forked from rthbound/work.rb
Hot products
PartNumber.ordered_between(7.days.ago, Time.zone.now)
class PartNumber
named_scope :ordered_between, lambda{|start_time, end_time| { :conditions => ["orders.created_at BETWEEN ? AND ?", start_time, end_time], :include => [:order] }
end
class WorkUnit
scope :on_estimated_ticket, lambda{ include(:ticket).where("tickets.estimated_hours IS NOT NULL AND tickets.estimated_hours > 0") }
end
def project_completion_metric(project)
work_unit_hours_array = Array.new # Empty array to work with
# Take the summation of estimated_hours on a ticket from the project
estimated_hours = Ticket.for_project(project).sum(:estimated_hours)
require 'fnordmetric'
require 'fnordmetric/logger'
# This is a quickie ruby script to set up some base data for the dashboard
income_billing_keys = [:weekly_billing_external, :weekly_income_quickbooks, :weekly_break_even]
bank_account_keys = [:bank_account_checking, :bank_account_money_market, :bank_account_bonus_employee, :bank_account_bonus_boardmembers, :quickbooks_receivables, :quickbooks_payables]
website_traffic_keys = [:visitors_daily]
jenkins_keys = [:jenkins_build_success_daily, :jenkins_build_failure_daily]
demo_data = {
# First, set up a customer_create method.  This tells us how to create the
# customer in your persistence layer.
IsotopeSubscriptions.customer_create = lambda do |hash|
  customer = Customer.new(hash)
  if customer.save
    customer
  else
    false
  end

end