spec/spec_helper.rb in dm-rspec-0.1.0 vs spec/spec_helper.rb in dm-rspec-0.1.1
- old
+ new
@@ -1,13 +1,18 @@
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'rspec'
require 'dm-core'
require 'dm-validations'
+require 'dm-migrations'
+require 'dm-sqlite-adapter'
require 'dm-rspec'
+
+DataMapper.setup(:default, "sqlite3::memory:")
+
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
@@ -32,10 +37,12 @@
lambda { self.call }.should_not raise_error
end
end
+
+
# Models for testing
#
class Book
include DataMapper::Resource
property :id, Serial
@@ -43,33 +50,46 @@
belongs_to :author
has n, :genres, :through => Resource
has n, :taggings
has n, :tags, :through => :taggings
validates_presence_of :name
+ validates_uniqueness_of :name, :message => 'Book name must be unique!'
validates_length_of :name, :min => 10
end
class Author
include DataMapper::Resource
property :id, Serial
+ property :first_name, String
+ property :last_name, String
has n, :books
+ validates_uniqueness_of :last_name
end
class Genre
include DataMapper::Resource
property :id, Serial
property :name, String
has n, :books, :through => Resource
+ validates_uniqueness_of :name, :message => 'Genre name must be unique!'
+ validates_format_of :name, :with => /\w+/, :message => "Bad format of genre"
end
class Tag
include DataMapper::Resource
property :id, Serial
has n, :taggings
has n, :books, :through => :taggings
+ property :name, String
+ validates_format_of :name, :with => /\w+/
end
class Tagging
include DataMapper::Resource
+ property :id, Serial
belongs_to :tag
belongs_to :book
end
+
+
+DataMapper.finalize
+DataMapper.auto_migrate!