Skip to content

Instantly share code, notes, and snippets.

@kirs
Last active September 29, 2016 14:43
Show Gist options
  • Select an option

  • Save kirs/1d18128f0bf46b7728af80704da11d1e to your computer and use it in GitHub Desktop.

Select an option

Save kirs/1d18128f0bf46b7728af80704da11d1e to your computer and use it in GitHub Desktop.
require "bundler/setup"
require 'active_record'
require 'sqlite3'
require 'minitest/autorun'
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Schema.define do
create_table :gift_cards, force: true do |t|
t.references :checkout
end
create_table :checkouts, force: true do |t|
end
end
class Checkout < ActiveRecord::Base
has_many :gift_cards
end
class GiftCard < ActiveRecord::Base
belongs_to :checkout, required: true
end
checkout = Checkout.create!
g = GiftCard.new
g.valid?
puts g.errors.messages.inspect
# 4.2: {:checkout=>["can't be blank"]}
# 5.0: {:checkout=>["must exist"]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment