Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
I think I'm figuring out how use Sequel::Model....
require "sequel"
# Use the module to avoid naming collisions with other specs.
module LearnSequelModelSpec
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
end
context "round-trip" do
example "happy path" do
Person = Sequel::Model(db[:persons])
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
context "mix in non-database behavior" do
module PersonBehavior
def length_of_name
name.length
end
end
example "happy path" do
Person = Class.new(Sequel::Model(db[:persons])) do
include PersonBehavior
end
Person.create(name: "J. B. Rainsberger")
found = Person.find(name: "J. B. Rainsberger")
expect(found.length_of_name).to eq(17)
end
end
end
end
@jbrains

This comment has been minimized.

Copy link
Owner Author

jbrains commented May 17, 2014

I really, really, really hate the name PersonBehavior here. I don't know what else to call it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.