Skip to content

Instantly share code, notes, and snippets.

@jbrains
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jbrains/73dc5c82cc1dd5073210 to your computer and use it in GitHub Desktop.
Save jbrains/73dc5c82cc1dd5073210 to your computer and use it in GitHub Desktop.
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
Copy link
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