Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myronmarston/76ac701e39c53a73a5fd to your computer and use it in GitHub Desktop.
Save myronmarston/76ac701e39c53a73a5fd to your computer and use it in GitHub Desktop.
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
@jbrains
Copy link

jbrains commented May 17, 2014

This makes me sad. A textbook example of programming by coincidence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment