Skip to content

Instantly share code, notes, and snippets.

@ashmoran
Created October 19, 2009 12:39
Show Gist options
  • Save ashmoran/213331 to your computer and use it in GitHub Desktop.
Save ashmoran/213331 to your computer and use it in GitHub Desktop.
require 'rubygems'
require "data_objects"
require "dm-core"
require "dm-types"
require "dm-validations"
require 'spec'
SQLITE_FILE = File.join(`pwd`.chomp, "test.db")
DataMapper.setup(:default, "sqlite3:#{SQLITE_FILE}")
class Employee
include DataMapper::Resource
property :id, Serial
belongs_to :job_role, :default => lambda { |r, p| JobRole.first(:name => "Boss" ) }
end
class JobRole
include DataMapper::Resource
property :id, Serial
property :name, String
has 1, :employee
end
DataMapper.auto_migrate!
describe "default" do
before(:each) do
@job_role = JobRole.create(:name => "Boss")
@employee = Employee.new
end
it "works with resources" do
@employee.job_role.should == @job_role
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment