Last active
August 29, 2015 14:01
-
-
Save jbrains/73dc5c82cc1dd5073210 to your computer and use it in GitHub Desktop.
I think I'm figuring out how use Sequel::Model....
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" | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I really, really, really hate the name
PersonBehavior
here. I don't know what else to call it.