gist: 2263 Download_button fork
public
Public Clone URL: git://gist.github.com/2263.git
Text only
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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 => "designer@example.com",
          :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

Owner

benburkert

Revisions