Last active
September 29, 2016 14:43
-
-
Save kirs/1d18128f0bf46b7728af80704da11d1e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 "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