dm-types 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/Gemfile +18 -19
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/dm-types.gemspec +16 -11
- data/lib/dm-types/enum.rb +2 -13
- data/lib/dm-types/flag.rb +2 -13
- data/lib/dm-types/json.rb +1 -1
- data/lib/dm-types/paranoid_boolean.rb +1 -1
- data/lib/dm-types/paranoid_datetime.rb +1 -1
- data/lib/dm-types/support/flags.rb +41 -0
- data/lib/dm-types/uri.rb +2 -3
- data/lib/dm-types/uuid.rb +4 -0
- data/spec/fixtures/article.rb +23 -25
- data/spec/fixtures/bookmark.rb +15 -17
- data/spec/fixtures/invention.rb +2 -4
- data/spec/fixtures/network_node.rb +34 -36
- data/spec/fixtures/person.rb +15 -18
- data/spec/fixtures/software_package.rb +23 -25
- data/spec/fixtures/ticket.rb +15 -17
- data/spec/fixtures/tshirt.rb +2 -4
- data/spec/integration/bcrypt_hash_spec.rb +4 -4
- data/spec/integration/comma_separated_list_spec.rb +2 -2
- data/spec/integration/enum_spec.rb +7 -7
- data/spec/integration/file_path_spec.rb +7 -7
- data/spec/integration/flag_spec.rb +3 -3
- data/spec/integration/ip_address_spec.rb +2 -2
- data/spec/integration/json_spec.rb +2 -2
- data/spec/integration/slug_spec.rb +5 -5
- data/spec/integration/uri_spec.rb +9 -9
- data/spec/integration/uuid_spec.rb +6 -6
- data/spec/integration/yaml_spec.rb +3 -3
- data/spec/shared/flags_shared_spec.rb +37 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/unit/bcrypt_hash_spec.rb +2 -2
- data/spec/unit/csv_spec.rb +1 -1
- data/spec/unit/enum_spec.rb +4 -0
- data/spec/unit/epoch_time_spec.rb +1 -1
- data/spec/unit/file_path_spec.rb +1 -1
- data/spec/unit/flag_spec.rb +6 -2
- data/spec/unit/ip_address_spec.rb +1 -1
- data/spec/unit/json_spec.rb +2 -2
- data/spec/unit/regexp_spec.rb +1 -1
- data/spec/unit/uri_spec.rb +1 -1
- data/spec/unit/uuid_spec.rb +25 -0
- data/spec/unit/yaml_spec.rb +2 -2
- data/tasks/local_gemfile.rake +5 -7
- metadata +13 -19
data/spec/fixtures/invention.rb
CHANGED
@@ -1,38 +1,36 @@
|
|
1
1
|
module DataMapper
|
2
|
-
module
|
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
|
-
end # Fixtures
|
37
|
-
end # Types
|
2
|
+
module TypesFixtures
|
3
|
+
|
4
|
+
class NetworkNode
|
5
|
+
#
|
6
|
+
# Behaviors
|
7
|
+
#
|
8
|
+
|
9
|
+
include ::DataMapper::Resource
|
10
|
+
|
11
|
+
#
|
12
|
+
# Properties
|
13
|
+
#
|
14
|
+
|
15
|
+
property :id, Serial
|
16
|
+
property :ip_address, IPAddress
|
17
|
+
property :cidr_subnet_bits, Integer
|
18
|
+
property :node_uuid, UUID
|
19
|
+
|
20
|
+
#
|
21
|
+
# API
|
22
|
+
#
|
23
|
+
|
24
|
+
alias uuid node_uuid
|
25
|
+
alias uuid= node_uuid=
|
26
|
+
|
27
|
+
def runs_ipv6?
|
28
|
+
self.ip_address.ipv6?
|
29
|
+
end
|
30
|
+
|
31
|
+
def runs_ipv4?
|
32
|
+
self.ip_address.ipv4?
|
33
|
+
end
|
34
|
+
end # NetworkNode
|
35
|
+
end # TypesFixtures
|
38
36
|
end # DataMapper
|
data/spec/fixtures/person.rb
CHANGED
@@ -1,27 +1,24 @@
|
|
1
1
|
module DataMapper
|
2
|
-
module
|
3
|
-
|
2
|
+
module TypesFixtures
|
3
|
+
class Person
|
4
|
+
#
|
5
|
+
# Behaviors
|
6
|
+
#
|
4
7
|
|
5
|
-
|
6
|
-
#
|
7
|
-
# Behaviors
|
8
|
-
#
|
8
|
+
include DataMapper::Resource
|
9
9
|
|
10
|
-
|
10
|
+
#
|
11
|
+
# Properties
|
12
|
+
#
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
14
|
+
property :id, Serial
|
15
|
+
property :name, String
|
16
|
+
property :positions, Json
|
17
|
+
property :inventions, Yaml
|
15
18
|
|
16
|
-
|
17
|
-
property :name, String
|
18
|
-
property :positions, Json
|
19
|
-
property :inventions, Yaml
|
19
|
+
property :interests, CommaSeparatedList
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
property :password, BCryptHash
|
24
|
-
end
|
21
|
+
property :password, BCryptHash
|
25
22
|
end
|
26
23
|
end
|
27
24
|
end
|
@@ -1,35 +1,33 @@
|
|
1
1
|
module DataMapper
|
2
|
-
module
|
3
|
-
module Fixtures
|
2
|
+
module TypesFixtures
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
class SoftwarePackage
|
5
|
+
#
|
6
|
+
# Behaviors
|
7
|
+
#
|
9
8
|
|
10
|
-
|
9
|
+
include ::DataMapper::Resource
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
#
|
12
|
+
# Properties
|
13
|
+
#
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
property :id, Serial
|
16
|
+
without_auto_validations do
|
17
|
+
property :node_number, Integer, :index => true
|
19
18
|
|
20
|
-
|
21
|
-
|
19
|
+
property :source_path, FilePath
|
20
|
+
property :destination_path, FilePath
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
property :product, String
|
23
|
+
property :version, String
|
24
|
+
property :released_at, DateTime
|
26
25
|
|
27
|
-
|
26
|
+
property :security_update, Boolean
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end # Types
|
28
|
+
property :installed_at, DateTime
|
29
|
+
property :installed_by, String
|
30
|
+
end
|
31
|
+
end # SoftwarePackage
|
32
|
+
end # TypesFixtures
|
35
33
|
end # DataMapper
|
data/spec/fixtures/ticket.rb
CHANGED
@@ -1,23 +1,21 @@
|
|
1
1
|
module DataMapper
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
#
|
2
|
+
module TypesFixtures
|
3
|
+
class Ticket
|
4
|
+
#
|
5
|
+
# Behaviors
|
6
|
+
#
|
8
7
|
|
9
|
-
|
10
|
-
|
8
|
+
include DataMapper::Resource
|
9
|
+
include DataMapper::Validations
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
#
|
12
|
+
# Properties
|
13
|
+
#
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
15
|
+
property :id, Serial
|
16
|
+
property :title, String, :length => 255
|
17
|
+
property :body, Text
|
18
|
+
property :status, Enum[:unconfirmed, :confirmed, :assigned, :resolved, :not_applicable]
|
19
|
+
end # Ticket
|
22
20
|
end
|
23
21
|
end
|
data/spec/fixtures/tshirt.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module DataMapper
|
2
|
-
module
|
3
|
-
module Fixtures
|
2
|
+
module TypesFixtures
|
4
3
|
|
5
4
|
class TShirt
|
6
5
|
#
|
@@ -21,6 +20,5 @@ module DataMapper
|
|
21
20
|
property :color, Enum[:white, :black, :red, :orange, :yellow, :green, :cyan, :blue, :purple]
|
22
21
|
property :size, Flag[:xs, :small, :medium, :large, :xl, :xxl], :default => :xs
|
23
22
|
end # Shirt
|
24
|
-
end #
|
25
|
-
end # Types
|
23
|
+
end # TypesFixtures
|
26
24
|
end # DataMapper
|
@@ -4,13 +4,13 @@ try_spec do
|
|
4
4
|
|
5
5
|
require './spec/fixtures/person'
|
6
6
|
|
7
|
-
describe DataMapper::
|
7
|
+
describe DataMapper::TypesFixtures::Person do
|
8
8
|
supported_by :all do
|
9
9
|
before :all do
|
10
|
-
@resource = DataMapper::
|
11
|
-
DataMapper::
|
10
|
+
@resource = DataMapper::TypesFixtures::Person.create(:password => 'DataMapper R0cks!')
|
11
|
+
DataMapper::TypesFixtures::Person.create(:password => 'password1')
|
12
12
|
|
13
|
-
@people = DataMapper::
|
13
|
+
@people = DataMapper::TypesFixtures::Person.all
|
14
14
|
@resource.reload
|
15
15
|
end
|
16
16
|
|
@@ -4,10 +4,10 @@ try_spec do
|
|
4
4
|
|
5
5
|
require './spec/fixtures/person'
|
6
6
|
|
7
|
-
describe DataMapper::
|
7
|
+
describe DataMapper::TypesFixtures::Person do
|
8
8
|
supported_by :all do
|
9
9
|
before :all do
|
10
|
-
@resource = DataMapper::
|
10
|
+
@resource = DataMapper::TypesFixtures::Person.new(:name => '')
|
11
11
|
end
|
12
12
|
|
13
13
|
describe 'with no interests information' do
|
@@ -4,11 +4,11 @@ try_spec do
|
|
4
4
|
|
5
5
|
require './spec/fixtures/ticket'
|
6
6
|
|
7
|
-
describe DataMapper::
|
7
|
+
describe DataMapper::TypesFixtures::Ticket do
|
8
8
|
supported_by :all do
|
9
9
|
describe 'that is dumped and then loaded' do
|
10
10
|
before :all do
|
11
|
-
@resource = DataMapper::
|
11
|
+
@resource = DataMapper::TypesFixtures::Ticket.new(
|
12
12
|
:title => "Can't order by aggregated fields",
|
13
13
|
:id => 789,
|
14
14
|
:body => "I'm trying to use the aggregate method and sort the results by a summed field, but it doesn't work.",
|
@@ -26,7 +26,7 @@ try_spec do
|
|
26
26
|
|
27
27
|
describe 'that is supplied a matching enumeration value' do
|
28
28
|
before :all do
|
29
|
-
@resource = DataMapper::
|
29
|
+
@resource = DataMapper::TypesFixtures::Ticket.new(:status => :assigned)
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'typecasts it for outside reader' do
|
@@ -36,7 +36,7 @@ try_spec do
|
|
36
36
|
|
37
37
|
describe '#get' do
|
38
38
|
before :all do
|
39
|
-
@resource = DataMapper::
|
39
|
+
@resource = DataMapper::TypesFixtures::Ticket.new(
|
40
40
|
:title => '"sudo make install" of drizzle fails because it tries to chown mysql',
|
41
41
|
:id => 257497,
|
42
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.",
|
@@ -46,19 +46,19 @@ try_spec do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'supports queries with equality operator on enumeration property' do
|
49
|
-
DataMapper::
|
49
|
+
DataMapper::TypesFixtures::Ticket.all(:status => :confirmed).
|
50
50
|
should include(@resource)
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'supports queries with inequality operator on enumeration property' do
|
54
|
-
DataMapper::
|
54
|
+
DataMapper::TypesFixtures::Ticket.all(:status.not => :confirmed).
|
55
55
|
should_not include(@resource)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
describe 'with value unknown to enumeration property' do
|
60
60
|
before :all do
|
61
|
-
@resource = DataMapper::
|
61
|
+
@resource = DataMapper::TypesFixtures::Ticket.new(:status => :undecided)
|
62
62
|
end
|
63
63
|
|
64
64
|
# TODO: consider sharing shared spec exampels with dm-validations,
|
@@ -4,12 +4,12 @@ try_spec do
|
|
4
4
|
|
5
5
|
require './spec/fixtures/software_package'
|
6
6
|
|
7
|
-
describe DataMapper::
|
7
|
+
describe DataMapper::TypesFixtures::SoftwarePackage do
|
8
8
|
supported_by :all do
|
9
9
|
describe 'with source path at /var/cache/apt/archives/linux-libc-dev_2.6.28-11.40_i386.deb' do
|
10
10
|
before :all do
|
11
11
|
@source_path = '/var/cache/apt/archives/linux-libc-dev_2.6.28-11.40_i386.deb'
|
12
|
-
@resource = DataMapper::
|
12
|
+
@resource = DataMapper::TypesFixtures::SoftwarePackage.new(:source_path => @source_path)
|
13
13
|
end
|
14
14
|
|
15
15
|
describe 'when is a new record' do
|
@@ -49,7 +49,7 @@ try_spec do
|
|
49
49
|
describe 'with destination path at /usr/local' do
|
50
50
|
before :all do
|
51
51
|
@destination_path = '/usr/local'
|
52
|
-
@resource = DataMapper::
|
52
|
+
@resource = DataMapper::TypesFixtures::SoftwarePackage.new(:destination_path => @destination_path)
|
53
53
|
end
|
54
54
|
|
55
55
|
describe 'when saved and reloaded' do
|
@@ -91,7 +91,7 @@ try_spec do
|
|
91
91
|
describe 'with no (nil) source path' do
|
92
92
|
before :all do
|
93
93
|
@source_path = nil
|
94
|
-
@resource = DataMapper::
|
94
|
+
@resource = DataMapper::TypesFixtures::SoftwarePackage.new(:source_path => @source_path)
|
95
95
|
end
|
96
96
|
|
97
97
|
describe 'when saved and reloaded' do
|
@@ -109,7 +109,7 @@ try_spec do
|
|
109
109
|
describe 'with a blank source path' do
|
110
110
|
before :all do
|
111
111
|
@source_path = ''
|
112
|
-
@resource = DataMapper::
|
112
|
+
@resource = DataMapper::TypesFixtures::SoftwarePackage.new(:source_path => @source_path)
|
113
113
|
end
|
114
114
|
|
115
115
|
describe 'when saved and reloaded' do
|
@@ -127,7 +127,7 @@ try_spec do
|
|
127
127
|
describe 'with a source path assigned to an empty array' do
|
128
128
|
before :all do
|
129
129
|
@source_path = []
|
130
|
-
@resource = DataMapper::
|
130
|
+
@resource = DataMapper::TypesFixtures::SoftwarePackage.new(:source_path => @source_path)
|
131
131
|
end
|
132
132
|
|
133
133
|
describe 'when saved and reloaded' do
|
@@ -150,7 +150,7 @@ try_spec do
|
|
150
150
|
describe 'when instantiated' do
|
151
151
|
it 'raises an exception' do
|
152
152
|
lambda do
|
153
|
-
DataMapper::
|
153
|
+
DataMapper::TypesFixtures::SoftwarePackage.new(:source_path => @source_path)
|
154
154
|
end.should raise_error(TypeError)
|
155
155
|
end
|
156
156
|
end
|
@@ -4,10 +4,10 @@ try_spec do
|
|
4
4
|
|
5
5
|
require './spec/fixtures/tshirt'
|
6
6
|
|
7
|
-
describe DataMapper::
|
7
|
+
describe DataMapper::TypesFixtures::TShirt do
|
8
8
|
supported_by :all do
|
9
9
|
before do
|
10
|
-
@resource = DataMapper::
|
10
|
+
@resource = DataMapper::TypesFixtures::TShirt.new(
|
11
11
|
:writing => 'Fork you',
|
12
12
|
:has_picture => true,
|
13
13
|
:picture => :octocat,
|
@@ -17,7 +17,7 @@ try_spec do
|
|
17
17
|
|
18
18
|
describe 'with the default value' do
|
19
19
|
it 'returns it as an array' do
|
20
|
-
@resource.size.should eql([DataMapper::
|
20
|
+
@resource.size.should eql([DataMapper::TypesFixtures::TShirt.properties[:size].default])
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -14,10 +14,10 @@ try_spec do
|
|
14
14
|
|
15
15
|
require './spec/fixtures/network_node'
|
16
16
|
|
17
|
-
describe DataMapper::
|
17
|
+
describe DataMapper::TypesFixtures::NetworkNode do
|
18
18
|
supported_by :all do
|
19
19
|
before :all do
|
20
|
-
@resource = DataMapper::
|
20
|
+
@resource = DataMapper::TypesFixtures::NetworkNode.new(
|
21
21
|
:node_uuid => '25a44800-21c9-11de-8c30-0800200c9a66',
|
22
22
|
:ip_address => nil,
|
23
23
|
:cidr_subnet_bits => nil
|
@@ -4,10 +4,10 @@ try_spec do
|
|
4
4
|
|
5
5
|
require './spec/fixtures/person'
|
6
6
|
|
7
|
-
describe DataMapper::
|
7
|
+
describe DataMapper::TypesFixtures::Person do
|
8
8
|
supported_by :all do
|
9
9
|
before :all do
|
10
|
-
@resource = DataMapper::
|
10
|
+
@resource = DataMapper::TypesFixtures::Person.new(:name => 'Thomas Edison')
|
11
11
|
end
|
12
12
|
|
13
13
|
describe 'with no positions information' do
|
@@ -6,12 +6,12 @@ try_spec do
|
|
6
6
|
|
7
7
|
require './spec/fixtures/article'
|
8
8
|
|
9
|
-
describe DataMapper::
|
9
|
+
describe DataMapper::TypesFixtures::Article do
|
10
10
|
supported_by :all do
|
11
11
|
describe "persisted with title and slug set to 'New DataMapper Type'" do
|
12
12
|
before :all do
|
13
13
|
@input = 'New DataMapper Type'
|
14
|
-
@resource = DataMapper::
|
14
|
+
@resource = DataMapper::TypesFixtures::Article.create(:title => @input, :slug => @input)
|
15
15
|
|
16
16
|
@resource.reload
|
17
17
|
end
|
@@ -21,7 +21,7 @@ try_spec do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'can be found by slug' do
|
24
|
-
DataMapper::
|
24
|
+
DataMapper::TypesFixtures::Article.first(:slug => 'new-datamapper-type').should == @resource
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -38,7 +38,7 @@ try_spec do
|
|
38
38
|
].each do |title, slug|
|
39
39
|
describe "set with title '#{title}'" do
|
40
40
|
before :all do
|
41
|
-
@resource = DataMapper::
|
41
|
+
@resource = DataMapper::TypesFixtures::Article.new(:title => title)
|
42
42
|
@resource.valid?.should be(true)
|
43
43
|
end
|
44
44
|
|
@@ -53,7 +53,7 @@ try_spec do
|
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'can be found by slug' do
|
56
|
-
DataMapper::
|
56
|
+
DataMapper::TypesFixtures::Article.first(:slug => slug).should == @resource
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|