dm-types 0.10.2 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/.gitignore +36 -0
  2. data/Gemfile +147 -0
  3. data/Rakefile +7 -8
  4. data/VERSION +1 -1
  5. data/dm-types.gemspec +61 -20
  6. data/lib/dm-types.rb +24 -19
  7. data/lib/dm-types/bcrypt_hash.rb +17 -13
  8. data/lib/dm-types/comma_separated_list.rb +11 -16
  9. data/lib/dm-types/csv.rb +11 -11
  10. data/lib/dm-types/enum.rb +33 -50
  11. data/lib/dm-types/epoch_time.rb +11 -11
  12. data/lib/dm-types/file_path.rb +13 -10
  13. data/lib/dm-types/flag.rb +17 -25
  14. data/lib/dm-types/ip_address.rb +15 -11
  15. data/lib/dm-types/json.rb +17 -14
  16. data/lib/dm-types/paranoid/base.rb +38 -0
  17. data/lib/dm-types/paranoid_boolean.rb +23 -0
  18. data/lib/dm-types/paranoid_datetime.rb +22 -0
  19. data/lib/dm-types/regexp.rb +8 -8
  20. data/lib/dm-types/slug.rb +7 -12
  21. data/lib/dm-types/uri.rb +21 -9
  22. data/lib/dm-types/uuid.rb +18 -11
  23. data/lib/dm-types/yaml.rb +12 -10
  24. data/spec/fixtures/article.rb +0 -2
  25. data/spec/fixtures/bookmark.rb +0 -2
  26. data/spec/fixtures/network_node.rb +0 -2
  27. data/spec/fixtures/person.rb +0 -2
  28. data/spec/fixtures/software_package.rb +0 -2
  29. data/spec/fixtures/ticket.rb +2 -4
  30. data/spec/fixtures/tshirt.rb +3 -5
  31. data/spec/integration/bcrypt_hash_spec.rb +33 -31
  32. data/spec/integration/comma_separated_list_spec.rb +55 -53
  33. data/spec/integration/enum_spec.rb +55 -53
  34. data/spec/integration/file_path_spec.rb +105 -103
  35. data/spec/integration/flag_spec.rb +42 -40
  36. data/spec/integration/ip_address_spec.rb +91 -89
  37. data/spec/integration/json_spec.rb +41 -39
  38. data/spec/integration/slug_spec.rb +36 -34
  39. data/spec/integration/uri_spec.rb +82 -79
  40. data/spec/integration/uuid_spec.rb +63 -61
  41. data/spec/integration/yaml_spec.rb +37 -35
  42. data/spec/spec_helper.rb +7 -36
  43. data/spec/unit/bcrypt_hash_spec.rb +18 -10
  44. data/spec/unit/csv_spec.rb +92 -80
  45. data/spec/unit/enum_spec.rb +27 -42
  46. data/spec/unit/epoch_time_spec.rb +18 -7
  47. data/spec/unit/file_path_spec.rb +15 -10
  48. data/spec/unit/flag_spec.rb +13 -36
  49. data/spec/unit/ip_address_spec.rb +13 -10
  50. data/spec/unit/json_spec.rb +21 -14
  51. data/spec/unit/paranoid_boolean_spec.rb +138 -0
  52. data/spec/unit/paranoid_datetime_spec.rb +143 -0
  53. data/spec/unit/regexp_spec.rb +15 -5
  54. data/spec/unit/uri_spec.rb +13 -9
  55. data/spec/unit/yaml_spec.rb +16 -9
  56. data/tasks/local_gemfile.rake +18 -0
  57. data/tasks/spec.rake +0 -3
  58. metadata +122 -52
@@ -5,73 +5,75 @@ try_spec do
5
5
  require './spec/fixtures/ticket'
6
6
 
7
7
  describe DataMapper::Types::Fixtures::Ticket do
8
- describe 'that is dumped and then loaded' do
9
- before :all do
10
- @resource = DataMapper::Types::Fixtures::Ticket.new(
11
- :title => "Can't order by aggregated fields",
12
- :id => 789,
13
- :body => "I'm trying to use the aggregate method and sort the results by a summed field, but it doesn't work.",
14
- :status => 'confirmed'
15
- )
8
+ supported_by :all do
9
+ describe 'that is dumped and then loaded' do
10
+ before :all do
11
+ @resource = DataMapper::Types::Fixtures::Ticket.new(
12
+ :title => "Can't order by aggregated fields",
13
+ :id => 789,
14
+ :body => "I'm trying to use the aggregate method and sort the results by a summed field, but it doesn't work.",
15
+ :status => 'confirmed'
16
+ )
16
17
 
17
- @resource.save.should be_true
18
- @resource.reload
19
- end
18
+ @resource.save.should be_true
19
+ @resource.reload
20
+ end
20
21
 
21
- it 'preserves property value' do
22
- @resource.status.should == :confirmed
22
+ it 'preserves property value' do
23
+ @resource.status.should == :confirmed
24
+ end
23
25
  end
24
- end
25
26
 
26
- describe 'that is supplied a matching enumeration value' do
27
- before :all do
28
- @resource = DataMapper::Types::Fixtures::Ticket.new(:status => :assigned)
29
- end
27
+ describe 'that is supplied a matching enumeration value' do
28
+ before :all do
29
+ @resource = DataMapper::Types::Fixtures::Ticket.new(:status => :assigned)
30
+ end
30
31
 
31
- it 'typecasts it for outside reader' do
32
- @resource.status.should == :assigned
32
+ it 'typecasts it for outside reader' do
33
+ @resource.status.should == :assigned
34
+ end
33
35
  end
34
- end
35
36
 
36
- describe '#get' do
37
- before :all do
38
- @resource = DataMapper::Types::Fixtures::Ticket.new(
39
- :title => '"sudo make install" of drizzle fails because it tries to chown mysql',
40
- :id => 257497,
41
- :body => "Note that at the very least, there should be a check to see whether or not the user is created before chown'ing a file to the user.",
42
- :status => 'confirmed'
43
- )
44
- @resource.save.should be_true
45
- end
37
+ describe '#get' do
38
+ before :all do
39
+ @resource = DataMapper::Types::Fixtures::Ticket.new(
40
+ :title => '"sudo make install" of drizzle fails because it tries to chown mysql',
41
+ :id => 257497,
42
+ :body => "Note that at the very least, there should be a check to see whether or not the user is created before chown'ing a file to the user.",
43
+ :status => 'confirmed'
44
+ )
45
+ @resource.save.should be_true
46
+ end
46
47
 
47
- it 'supports queries with equality operator on enumeration property' do
48
- DataMapper::Types::Fixtures::Ticket.all(:status => :confirmed).
49
- should include(@resource)
50
- end
48
+ it 'supports queries with equality operator on enumeration property' do
49
+ DataMapper::Types::Fixtures::Ticket.all(:status => :confirmed).
50
+ should include(@resource)
51
+ end
51
52
 
52
- it 'supports queries with inequality operator on enumeration property' do
53
- DataMapper::Types::Fixtures::Ticket.all(:status.not => :confirmed).
54
- should_not include(@resource)
53
+ it 'supports queries with inequality operator on enumeration property' do
54
+ DataMapper::Types::Fixtures::Ticket.all(:status.not => :confirmed).
55
+ should_not include(@resource)
56
+ end
55
57
  end
56
- end
57
58
 
58
- describe 'with value unknown to enumeration property' do
59
- before :all do
60
- @resource = DataMapper::Types::Fixtures::Ticket.new(:status => :undecided)
61
- end
59
+ describe 'with value unknown to enumeration property' do
60
+ before :all do
61
+ @resource = DataMapper::Types::Fixtures::Ticket.new(:status => :undecided)
62
+ end
62
63
 
63
- # TODO: consider sharing shared spec exampels with dm-validations,
64
- # which has 'invalid model' shared group
65
- it 'is invalid (auto validation for :within kicks in)' do
66
- @resource.should_not be_valid
67
- end
64
+ # TODO: consider sharing shared spec exampels with dm-validations,
65
+ # which has 'invalid model' shared group
66
+ it 'is invalid (auto validation for :within kicks in)' do
67
+ @resource.should_not be_valid
68
+ end
68
69
 
69
- it 'has errors' do
70
- @resource.errors.should_not be_empty
71
- end
70
+ it 'has errors' do
71
+ @resource.errors.should_not be_empty
72
+ end
72
73
 
73
- it 'has a meaningful error message on invalid property' do
74
- @resource.errors.on(:status).should include('Status must be one of unconfirmed, confirmed, assigned, resolved, not_applicable')
74
+ it 'has a meaningful error message on invalid property' do
75
+ @resource.errors.on(:status).should include('Status must be one of unconfirmed, confirmed, assigned, resolved, not_applicable')
76
+ end
75
77
  end
76
78
  end
77
79
  end
@@ -5,152 +5,154 @@ try_spec do
5
5
  require './spec/fixtures/software_package'
6
6
 
7
7
  describe DataMapper::Types::Fixtures::SoftwarePackage do
8
- describe 'with source path at /var/cache/apt/archives/linux-libc-dev_2.6.28-11.40_i386.deb' do
9
- before :all do
10
- @source_path = '/var/cache/apt/archives/linux-libc-dev_2.6.28-11.40_i386.deb'
11
- @resource = DataMapper::Types::Fixtures::SoftwarePackage.new(:source_path => @source_path)
12
- end
13
-
14
- describe 'when is a new record' do
8
+ supported_by :all do
9
+ describe 'with source path at /var/cache/apt/archives/linux-libc-dev_2.6.28-11.40_i386.deb' do
15
10
  before :all do
11
+ @source_path = '/var/cache/apt/archives/linux-libc-dev_2.6.28-11.40_i386.deb'
12
+ @resource = DataMapper::Types::Fixtures::SoftwarePackage.new(:source_path => @source_path)
16
13
  end
17
14
 
18
- it 'points to original path' do
19
- @resource.source_path.to_s.should == @source_path
20
- end
15
+ describe 'when is a new record' do
16
+ before :all do
17
+ end
21
18
 
22
- it 'responds to :directory?' do
23
- @resource.source_path.should respond_to(:directory?)
24
- end
19
+ it 'points to original path' do
20
+ @resource.source_path.to_s.should == @source_path
21
+ end
25
22
 
26
- it 'responds to :file?' do
27
- @resource.source_path.should respond_to(:file?)
28
- end
23
+ it 'responds to :directory?' do
24
+ @resource.source_path.should respond_to(:directory?)
25
+ end
29
26
 
30
- it 'responds to :dirname' do
31
- @resource.source_path.should respond_to(:dirname)
32
- end
27
+ it 'responds to :file?' do
28
+ @resource.source_path.should respond_to(:file?)
29
+ end
33
30
 
34
- it 'responds to :absolute?' do
35
- @resource.source_path.should respond_to(:absolute?)
36
- end
31
+ it 'responds to :dirname' do
32
+ @resource.source_path.should respond_to(:dirname)
33
+ end
37
34
 
38
- it 'responds to :readable?' do
39
- @resource.source_path.should respond_to(:readable?)
40
- end
35
+ it 'responds to :absolute?' do
36
+ @resource.source_path.should respond_to(:absolute?)
37
+ end
41
38
 
42
- it 'responds to :size' do
43
- @resource.source_path.should respond_to(:size)
44
- end
45
- end
46
- end
39
+ it 'responds to :readable?' do
40
+ @resource.source_path.should respond_to(:readable?)
41
+ end
47
42
 
48
- describe 'with destination path at /usr/local' do
49
- before :all do
50
- @destination_path = '/usr/local'
51
- @resource = DataMapper::Types::Fixtures::SoftwarePackage.new(:destination_path => @destination_path)
43
+ it 'responds to :size' do
44
+ @resource.source_path.should respond_to(:size)
45
+ end
46
+ end
52
47
  end
53
48
 
54
- describe 'when saved and reloaded' do
49
+ describe 'with destination path at /usr/local' do
55
50
  before :all do
56
- @resource.save.should be_true
57
- @resource.reload
51
+ @destination_path = '/usr/local'
52
+ @resource = DataMapper::Types::Fixtures::SoftwarePackage.new(:destination_path => @destination_path)
58
53
  end
59
54
 
60
- it 'points to original path' do
61
- @resource.destination_path.to_s.should == @destination_path
62
- end
55
+ describe 'when saved and reloaded' do
56
+ before :all do
57
+ @resource.save.should be_true
58
+ @resource.reload
59
+ end
63
60
 
64
- it 'responds to :directory?' do
65
- @resource.destination_path.should respond_to(:directory?)
66
- end
61
+ it 'points to original path' do
62
+ @resource.destination_path.to_s.should == @destination_path
63
+ end
67
64
 
68
- it 'responds to :file?' do
69
- @resource.destination_path.should respond_to(:file?)
70
- end
65
+ it 'responds to :directory?' do
66
+ @resource.destination_path.should respond_to(:directory?)
67
+ end
71
68
 
72
- it 'responds to :dirname' do
73
- @resource.destination_path.should respond_to(:dirname)
74
- end
69
+ it 'responds to :file?' do
70
+ @resource.destination_path.should respond_to(:file?)
71
+ end
75
72
 
76
- it 'responds to :absolute?' do
77
- @resource.destination_path.should respond_to(:absolute?)
78
- end
73
+ it 'responds to :dirname' do
74
+ @resource.destination_path.should respond_to(:dirname)
75
+ end
79
76
 
80
- it 'responds to :readable?' do
81
- @resource.destination_path.should respond_to(:readable?)
82
- end
77
+ it 'responds to :absolute?' do
78
+ @resource.destination_path.should respond_to(:absolute?)
79
+ end
83
80
 
84
- it 'responds to :size' do
85
- @resource.destination_path.should respond_to(:size)
86
- end
87
- end
88
- end
81
+ it 'responds to :readable?' do
82
+ @resource.destination_path.should respond_to(:readable?)
83
+ end
89
84
 
90
- describe 'with no (nil) source path' do
91
- before :all do
92
- @source_path = nil
93
- @resource = DataMapper::Types::Fixtures::SoftwarePackage.new(:source_path => @source_path)
85
+ it 'responds to :size' do
86
+ @resource.destination_path.should respond_to(:size)
87
+ end
88
+ end
94
89
  end
95
90
 
96
- describe 'when saved and reloaded' do
91
+ describe 'with no (nil) source path' do
97
92
  before :all do
98
- @resource.save.should be_true
99
- @resource.reload
93
+ @source_path = nil
94
+ @resource = DataMapper::Types::Fixtures::SoftwarePackage.new(:source_path => @source_path)
100
95
  end
101
96
 
102
- it 'has nil source path' do
103
- @resource.source_path.should be_nil
104
- end
105
- end
106
- end
97
+ describe 'when saved and reloaded' do
98
+ before :all do
99
+ @resource.save.should be_true
100
+ @resource.reload
101
+ end
107
102
 
108
- describe 'with a blank source path' do
109
- before :all do
110
- @source_path = ''
111
- @resource = DataMapper::Types::Fixtures::SoftwarePackage.new(:source_path => @source_path)
103
+ it 'has nil source path' do
104
+ @resource.source_path.should be_nil
105
+ end
106
+ end
112
107
  end
113
108
 
114
- describe 'when saved and reloaded' do
109
+ describe 'with a blank source path' do
115
110
  before :all do
116
- @resource.save.should be_true
117
- @resource.reload
111
+ @source_path = ''
112
+ @resource = DataMapper::Types::Fixtures::SoftwarePackage.new(:source_path => @source_path)
118
113
  end
119
114
 
120
- it 'has nil source path' do
121
- @resource.source_path.should be_nil
122
- end
123
- end
124
- end
115
+ describe 'when saved and reloaded' do
116
+ before :all do
117
+ @resource.save.should be_true
118
+ @resource.reload
119
+ end
125
120
 
126
- describe 'with a source path assigned to an empty array' do
127
- before :all do
128
- @source_path = []
129
- @resource = DataMapper::Types::Fixtures::SoftwarePackage.new(:source_path => @source_path)
121
+ it 'has nil source path' do
122
+ @resource.source_path.should be_nil
123
+ end
124
+ end
130
125
  end
131
126
 
132
- describe 'when saved and reloaded' do
127
+ describe 'with a source path assigned to an empty array' do
133
128
  before :all do
134
- @resource.save.should be_true
135
- @resource.reload
129
+ @source_path = []
130
+ @resource = DataMapper::Types::Fixtures::SoftwarePackage.new(:source_path => @source_path)
136
131
  end
137
132
 
138
- it 'has nil source path' do
139
- @resource.source_path.should be_nil
133
+ describe 'when saved and reloaded' do
134
+ before :all do
135
+ @resource.save.should be_true
136
+ @resource.reload
137
+ end
138
+
139
+ it 'has nil source path' do
140
+ @resource.source_path.should be_nil
141
+ end
140
142
  end
141
143
  end
142
- end
143
144
 
144
- describe 'with a source path assigned to a Hash' do
145
- before :all do
146
- @source_path = { :guitar => 'Joe Satriani' }
147
- end
145
+ describe 'with a source path assigned to a Hash' do
146
+ before :all do
147
+ @source_path = { :guitar => 'Joe Satriani' }
148
+ end
148
149
 
149
- describe 'when instantiated' do
150
- it 'raises an exception' do
151
- lambda do
152
- DataMapper::Types::Fixtures::SoftwarePackage.new(:source_path => @source_path)
153
- end.should raise_error(TypeError)
150
+ describe 'when instantiated' do
151
+ it 'raises an exception' do
152
+ lambda do
153
+ DataMapper::Types::Fixtures::SoftwarePackage.new(:source_path => @source_path)
154
+ end.should raise_error(TypeError)
155
+ end
154
156
  end
155
157
  end
156
158
  end
@@ -5,59 +5,61 @@ try_spec do
5
5
  require './spec/fixtures/tshirt'
6
6
 
7
7
  describe DataMapper::Types::Fixtures::TShirt do
8
- before do
9
- @resource = DataMapper::Types::Fixtures::TShirt.new(
10
- :writing => 'Fork you',
11
- :has_picture => true,
12
- :picture => :octocat,
13
- :color => :white,
14
- :size => [ :xs, :medium ]
15
- )
16
- end
8
+ supported_by :all do
9
+ before do
10
+ @resource = DataMapper::Types::Fixtures::TShirt.new(
11
+ :writing => 'Fork you',
12
+ :has_picture => true,
13
+ :picture => :octocat,
14
+ :color => :white,
15
+ :size => [ :xs, :medium ]
16
+ )
17
+ end
17
18
 
18
- describe 'with multiple sizes' do
19
- describe 'dumped and loaded' do
20
- before do
21
- @resource.save.should be_true
22
- @resource.reload
23
- end
19
+ describe 'with multiple sizes' do
20
+ describe 'dumped and loaded' do
21
+ before do
22
+ @resource.save.should be_true
23
+ @resource.reload
24
+ end
24
25
 
25
- it 'returns size as array' do
26
- @resource.size.should == [ :xs, :medium ]
26
+ it 'returns size as array' do
27
+ @resource.size.should == [ :xs, :medium ]
28
+ end
27
29
  end
28
30
  end
29
- end
30
-
31
- describe 'with a single size' do
32
- before do
33
- @resource.size = :large
34
- end
35
31
 
36
- describe 'dumped and loaded' do
32
+ describe 'with a single size' do
37
33
  before do
38
- @resource.save.should be_true
39
- @resource.reload
34
+ @resource.size = :large
40
35
  end
41
36
 
42
- it 'returns size as array with a single value' do
43
- @resource.size.should == [:large]
37
+ describe 'dumped and loaded' do
38
+ before do
39
+ @resource.save.should be_true
40
+ @resource.reload
41
+ end
42
+
43
+ it 'returns size as array with a single value' do
44
+ @resource.size.should == [:large]
45
+ end
44
46
  end
45
47
  end
46
- end
47
48
 
48
- # Flag does not add any auto validations
49
- describe 'without size' do
50
- before do
51
- @resource.should be_valid
52
- @resource.size = nil
53
- end
49
+ # Flag does not add any auto validations
50
+ describe 'without size' do
51
+ before do
52
+ @resource.should be_valid
53
+ @resource.size = nil
54
+ end
54
55
 
55
- it 'is valid' do
56
- @resource.should be_valid
57
- end
56
+ it 'is valid' do
57
+ @resource.should be_valid
58
+ end
58
59
 
59
- it 'has no errors' do
60
- @resource.errors.should be_blank
60
+ it 'has no errors' do
61
+ @resource.errors.should be_blank
62
+ end
61
63
  end
62
64
  end
63
65
  end