Created
July 24, 2008 19:29
-
-
Save benburkert/2263 to your computer and use it in GitHub Desktop.
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 'pathname' | |
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper' | |
if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES | |
describe "STI Resources" do | |
before do | |
class Product | |
include DataMapper::Resource | |
property :id, Integer, :serial => true | |
property :type, Discriminator | |
property :code, String, :length => 20, :nullable => false | |
property :name, String, :length => 100, :nullable => false | |
property :description, Text | |
property :unit_price, Integer, :default => 0, :nullable => false | |
property :available_on, Date, :nullable => false | |
property :is_discontinued, Boolean | |
property :slug, String | |
property :vote_mean, Integer | |
end | |
class Shirt < Product | |
property :sizes, String | |
belongs_to :designer | |
end | |
class Variation < Product | |
property :product_id, Integer | |
belongs_to :product | |
end | |
class User | |
include DataMapper::Resource | |
attr_accessor :password, :password_confirmation | |
property :id, Integer, :serial => true | |
property :login, String, :length => 50, :nullable => false, :unique => true | |
property :email, String, :length => 3..100, :nullable => false, :unique => true | |
property :crypted_password, String | |
property :salt, String | |
property :activation_code, String | |
property :activated_at, DateTime | |
property :remember_token_expires_at, DateTime | |
property :remember_token, String | |
property :password_reset_code, String | |
property :created_at, DateTime | |
property :updated_at, DateTime | |
property :type, Discriminator | |
property :slug, String | |
property :name, String | |
end | |
class Designer < User | |
has n, :shirts | |
end | |
DataMapper.auto_migrate! | |
end | |
describe "description" do | |
it "should create a valid designer" do | |
designer = Designer.create(:login => 'designer', | |
:email => "[email protected]", | |
:name => 'Dee Ziner', | |
:password => 'qwerty', | |
:password_confirmation => 'qwerty') | |
shirt = Shirt.new(:sizes => "small", | |
:name => "trihs", | |
:available_on => Time.now, | |
:unit_price => Kernel.rand(2_500), | |
:code => '123', | |
:designer => designer) | |
shirt.should be_valid | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment