-
-
Save myronmarston/76ac701e39c53a73a5fd 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 "sequel" | |
# Connect to the DB to make sequel happy. It expects a DB connection when you subclass Sequel::Model | |
DB = Sequel.sqlite | |
# Use the module to avoid naming collisions with other specs. | |
module LearnSequelModelSpec | |
# Where can I safely declare this class without specifying | |
# the database for it?! | |
class Person < Sequel::Model | |
end | |
describe "Person Model" do | |
let(:db) { Sequel.sqlite } | |
before(:each) do | |
db.create_table :persons do | |
primary_key :id | |
String :name, null: false, unique: true | |
end | |
Person.dataset = db[:persons] | |
end | |
context "round-trip" do | |
example "happy path" do | |
Person.create(name: "J. B. Rainsberger") | |
found = Person.find(name: "J. B. Rainsberger") | |
expect(found.id).not_to be_nil | |
expect(found.name).to eq("J. B. Rainsberger") | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This makes me sad. A textbook example of programming by coincidence.