Skip to content

Instantly share code, notes, and snippets.

@fivetwentysix
Created September 6, 2011 08:12
Show Gist options
  • Select an option

  • Save fivetwentysix/1196919 to your computer and use it in GitHub Desktop.

Select an option

Save fivetwentysix/1196919 to your computer and use it in GitHub Desktop.
ruby-1.9.2-p290 :027 > Factory.build(:payment_object, company: Company.first, applicant: Company.first.employees.first).valid?
Company Load (0.4ms) SELECT "companies".* FROM "companies" ORDER BY name ASC LIMIT 1
Company Load (0.3ms) SELECT "companies".* FROM "companies" ORDER BY name ASC LIMIT 1
User Load (0.7ms) SELECT "users".* FROM "users" INNER JOIN "employment_data" ON "users"."id" = "employment_data"."user_id" WHERE "employment_data"."company_id" = 1 ORDER BY name ASC LIMIT 1
=> true
ruby-1.9.2-p290 :028 > Factory.build(:payment_object, company: Company.first, applicant: Company.first.employees.first).save!
Company Load (0.5ms) SELECT "companies".* FROM "companies" ORDER BY name ASC LIMIT 1
Company Load (0.3ms) SELECT "companies".* FROM "companies" ORDER BY name ASC LIMIT 1
User Load (0.7ms) SELECT "users".* FROM "users" INNER JOIN "employment_data" ON "users"."id" = "employment_data"."user_id" WHERE "employment_data"."company_id" = 1 ORDER BY name ASC LIMIT 1
(0.1ms) BEGIN
(0.8ms) SELECT COUNT(*) FROM "receiving_records" INNER JOIN "payment_object_items" ON "receiving_records"."payment_object_item_id" = "payment_object_items"."id" WHERE "payment_object_items"."payment_object_id" IS NULL
PaymentObject Load (0.5ms) SELECT "payment_objects".* FROM "payment_objects" WHERE "payment_objects"."company_id" = 1 AND "payment_objects"."company_specific_id" IS NOT NULL ORDER BY id DESC LIMIT 1
(0.1ms) ROLLBACK
ActiveRecord::RecordNotSaved: ActiveRecord::RecordNotSaved
from /Users/pma/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/persistence.rb:57:in `save!'
from /Users/pma/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/validations.rb:56:in `save!'
from /Users/pma/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/attribute_methods/dirty.rb:33:in `save!'
from /Users/pma/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/transactions.rb:246:in `block in save!'
from /Users/pma/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status'
from /Users/pma/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
from /Users/pma/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/transactions.rb:208:in `transaction'
from /Users/pma/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
from /Users/pma/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/transactions.rb:246:in `save!'
from (irb):28
from /Users/pma/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0/lib/rails/commands/console.rb:45:in `start'
from /Users/pma/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0/lib/rails/commands/console.rb:8:in `start'
from /Users/pma/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
ruby-1.9.2-p290 :029 >
ruby-1.9.2-p290 :030 > o =Factory.build(:payment_object, company: Company.first, applicant: Company.first.employees.first)
Company Load (0.5ms) SELECT "companies".* FROM "companies" ORDER BY name ASC LIMIT 1
Company Load (0.3ms) SELECT "companies".* FROM "companies" ORDER BY name ASC LIMIT 1
User Load (0.7ms) SELECT "users".* FROM "users" INNER JOIN "employment_data" ON "users"."id" = "employment_data"."user_id" WHERE "employment_data"."company_id" = 1 ORDER BY name ASC LIMIT 1
=> #<PaymentObject id: nil, company_id: 1, delivery_date: "2011-09-06", payment_terms: "Cash", vendor: "Apple", applicant_id: 1, approved_id: nil, declined: false, amount: nil, last_sent: nil, payment_date: nil, created_at: nil, updated_at: nil, cancelled: false, currency: "HKD", paid: false, paid_by_id: nil, paid_at: nil, received: nil, payment_status: nil, company_specific_id: nil, stage: nil, approved_at: nil, declined_at: nil, cancelled_reason: nil>
ruby-1.9.2-p290 :031 > o.save
(0.1ms) BEGIN
(0.5ms) SELECT COUNT(*) FROM "receiving_records" INNER JOIN "payment_object_items" ON "receiving_records"."payment_object_item_id" = "payment_object_items"."id" WHERE "payment_object_items"."payment_object_id" IS NULL
PaymentObject Load (2.1ms) SELECT "payment_objects".* FROM "payment_objects" WHERE "payment_objects"."company_id" = 1 AND "payment_objects"."company_specific_id" IS NOT NULL ORDER BY id DESC LIMIT 1
(0.2ms) ROLLBACK
=> false
ruby-1.9.2-p290 :032 > o.errors
=> #<ActiveModel::Errors:0x007fdaa36f8aa8 @base=#<PaymentObject id: nil, company_id: 1, delivery_date: "2011-09-06", payment_terms: "Cash", vendor: "Apple", applicant_id: 1, approved_id: nil, declined: false, amount: #<BigDecimal:7fdaa36499e0,'0.0',9(18)>, last_sent: nil, payment_date: "2011-09-06", created_at: nil, updated_at: nil, cancelled: false, currency: "HKD", paid: false, paid_by_id: nil, paid_at: nil, received: "None", payment_status: "Pending", company_specific_id: 1, stage: "Requisition", approved_at: nil, declined_at: nil, cancelled_reason: nil>, @messages={}>
ruby-1.9.2-p290 :033 > o.errors.inspect
=> "#<ActiveModel::Errors:0x007fdaa36f8aa8 @base=#<PaymentObject id: nil, company_id: 1, delivery_date: \"2011-09-06\", payment_terms: \"Cash\", vendor: \"Apple\", applicant_id: 1, approved_id: nil, declined: false, amount: #<BigDecimal:7fdaa361b220,'0.0',9(18)>, last_sent: nil, payment_date: \"2011-09-06\", created_at: nil, updated_at: nil, cancelled: false, currency: \"HKD\", paid: false, paid_by_id: nil, paid_at: nil, received: \"None\", payment_status: \"Pending\", company_specific_id: 1, stage: \"Requisition\", approved_at: nil, declined_at: nil, cancelled_reason: nil>, @messages={}>"
ruby-1.9.2-p290 :034 >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment