ardm-types 1.2.2
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.
- checksums.yaml +7 -0
- data/.gitignore +36 -0
- data/.travis.yml +11 -0
- data/Gemfile +51 -0
- data/LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +4 -0
- data/ardm-types.gemspec +29 -0
- data/lib/ardm-types.rb +1 -0
- data/lib/dm-types/api_key.rb +30 -0
- data/lib/dm-types/bcrypt_hash.rb +34 -0
- data/lib/dm-types/comma_separated_list.rb +29 -0
- data/lib/dm-types/csv.rb +38 -0
- data/lib/dm-types/enum.rb +51 -0
- data/lib/dm-types/epoch_time.rb +41 -0
- data/lib/dm-types/file_path.rb +32 -0
- data/lib/dm-types/flag.rb +63 -0
- data/lib/dm-types/ip_address.rb +42 -0
- data/lib/dm-types/json.rb +50 -0
- data/lib/dm-types/paranoid/base.rb +55 -0
- data/lib/dm-types/paranoid_boolean.rb +23 -0
- data/lib/dm-types/paranoid_datetime.rb +22 -0
- data/lib/dm-types/regexp.rb +21 -0
- data/lib/dm-types/slug.rb +29 -0
- data/lib/dm-types/support/dirty_minder.rb +166 -0
- data/lib/dm-types/support/flags.rb +41 -0
- data/lib/dm-types/uri.rb +38 -0
- data/lib/dm-types/uuid.rb +74 -0
- data/lib/dm-types/version.rb +5 -0
- data/lib/dm-types/yaml.rb +41 -0
- data/lib/dm-types.rb +23 -0
- data/spec/fixtures/api_user.rb +14 -0
- data/spec/fixtures/article.rb +35 -0
- data/spec/fixtures/bookmark.rb +23 -0
- data/spec/fixtures/invention.rb +7 -0
- data/spec/fixtures/network_node.rb +36 -0
- data/spec/fixtures/person.rb +25 -0
- data/spec/fixtures/software_package.rb +33 -0
- data/spec/fixtures/ticket.rb +21 -0
- data/spec/fixtures/tshirt.rb +24 -0
- data/spec/integration/api_key_spec.rb +27 -0
- data/spec/integration/bcrypt_hash_spec.rb +47 -0
- data/spec/integration/comma_separated_list_spec.rb +87 -0
- data/spec/integration/dirty_minder_spec.rb +197 -0
- data/spec/integration/enum_spec.rb +80 -0
- data/spec/integration/epoch_time_spec.rb +61 -0
- data/spec/integration/file_path_spec.rb +160 -0
- data/spec/integration/flag_spec.rb +72 -0
- data/spec/integration/ip_address_spec.rb +153 -0
- data/spec/integration/json_spec.rb +72 -0
- data/spec/integration/slug_spec.rb +67 -0
- data/spec/integration/uri_spec.rb +139 -0
- data/spec/integration/uuid_spec.rb +102 -0
- data/spec/integration/yaml_spec.rb +69 -0
- data/spec/rcov.opts +6 -0
- data/spec/shared/flags_shared_spec.rb +37 -0
- data/spec/shared/identity_function_group.rb +5 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +30 -0
- data/spec/unit/bcrypt_hash_spec.rb +155 -0
- data/spec/unit/csv_spec.rb +142 -0
- data/spec/unit/enum_spec.rb +126 -0
- data/spec/unit/epoch_time_spec.rb +74 -0
- data/spec/unit/file_path_spec.rb +87 -0
- data/spec/unit/flag_spec.rb +114 -0
- data/spec/unit/ip_address_spec.rb +121 -0
- data/spec/unit/json_spec.rb +144 -0
- data/spec/unit/paranoid_boolean_spec.rb +150 -0
- data/spec/unit/paranoid_datetime_spec.rb +154 -0
- data/spec/unit/regexp_spec.rb +63 -0
- data/spec/unit/uri_spec.rb +64 -0
- data/spec/unit/uuid_spec.rb +25 -0
- data/spec/unit/yaml_spec.rb +111 -0
- data/tasks/spec.rake +38 -0
- data/tasks/yard.rake +9 -0
- data/tasks/yardstick.rake +19 -0
- metadata +236 -0
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
try_spec do
|
4
|
+
|
5
|
+
require './spec/fixtures/tshirt'
|
6
|
+
|
7
|
+
describe DataMapper::TypesFixtures::TShirt do
|
8
|
+
supported_by :all do
|
9
|
+
before do
|
10
|
+
@resource = DataMapper::TypesFixtures::TShirt.new(
|
11
|
+
:writing => 'Fork you',
|
12
|
+
:has_picture => true,
|
13
|
+
:picture => :octocat,
|
14
|
+
:color => :white
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'with the default value' do
|
19
|
+
it 'returns it as an array' do
|
20
|
+
@resource.size.should eql([DataMapper::TypesFixtures::TShirt.properties[:size].default])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'with multiple sizes' do
|
25
|
+
describe 'dumped and loaded' do
|
26
|
+
before do
|
27
|
+
@resource.size = [ :xs, :medium ]
|
28
|
+
@resource.save.should be(true)
|
29
|
+
@resource.reload
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'returns size as array' do
|
33
|
+
@resource.size.should == [ :xs, :medium ]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'with a single size' do
|
39
|
+
before do
|
40
|
+
@resource.size = :large
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'dumped and loaded' do
|
44
|
+
before do
|
45
|
+
@resource.save.should be(true)
|
46
|
+
@resource.reload
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'returns size as array with a single value' do
|
50
|
+
@resource.size.should == [:large]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Flag does not add any auto validations
|
56
|
+
describe 'without size' do
|
57
|
+
before do
|
58
|
+
@resource.should be_valid
|
59
|
+
@resource.size = nil
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'is valid' do
|
63
|
+
@resource.should be_valid
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'has no errors' do
|
67
|
+
@resource.errors.should be_empty
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
Spec::Matchers.define :run_ipv4 do
|
4
|
+
match { |model| model.runs_ipv4? }
|
5
|
+
end
|
6
|
+
|
7
|
+
Spec::Matchers.define :run_ipv6 do
|
8
|
+
match { |model| model.runs_ipv6? }
|
9
|
+
end
|
10
|
+
|
11
|
+
try_spec do
|
12
|
+
|
13
|
+
require './spec/fixtures/network_node'
|
14
|
+
|
15
|
+
describe DataMapper::TypesFixtures::NetworkNode do
|
16
|
+
supported_by :all do
|
17
|
+
before :all do
|
18
|
+
@resource = DataMapper::TypesFixtures::NetworkNode.new(
|
19
|
+
:node_uuid => '25a44800-21c9-11de-8c30-0800200c9a66',
|
20
|
+
:ip_address => nil,
|
21
|
+
:cidr_subnet_bits => nil
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'with IP address fe80::ab8:e8ff:fed7:f8c9' do
|
26
|
+
before :all do
|
27
|
+
@resource.ip_address = 'fe80::ab8:e8ff:fed7:f8c9'
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'when dumped and loaded' do
|
31
|
+
before :all do
|
32
|
+
@resource.save.should be(true)
|
33
|
+
@resource.reload
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'is an IPv6 node' do
|
37
|
+
@resource.should run_ipv6
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'with IP address 127.0.0.1' do
|
43
|
+
before :all do
|
44
|
+
@resource.ip_address = '127.0.0.1'
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'when dumped and loaded' do
|
48
|
+
before :all do
|
49
|
+
@resource.save.should be(true)
|
50
|
+
@resource.reload
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'is an IPv4 node' do
|
54
|
+
@resource.should run_ipv4
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'with IP address 218.43.243.136' do
|
60
|
+
before :all do
|
61
|
+
@resource.ip_address = '218.43.243.136'
|
62
|
+
end
|
63
|
+
|
64
|
+
describe 'when dumped and loaded' do
|
65
|
+
before :all do
|
66
|
+
@resource.save.should be(true)
|
67
|
+
@resource.reload
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'is an IPv4 node' do
|
71
|
+
@resource.should run_ipv4
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'with IP address 221.186.184.68' do
|
77
|
+
before :all do
|
78
|
+
@resource.ip_address = '221.186.184.68'
|
79
|
+
end
|
80
|
+
|
81
|
+
describe 'when dumped and loaded' do
|
82
|
+
before :all do
|
83
|
+
@resource.save.should be(true)
|
84
|
+
@resource.reload
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'is an IPv4 node' do
|
88
|
+
@resource.should run_ipv4
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe 'with IP address given as CIDR' do
|
94
|
+
before :all do
|
95
|
+
@resource.ip_address = '218.43.243.0/24'
|
96
|
+
end
|
97
|
+
|
98
|
+
describe 'when dumped and loaded' do
|
99
|
+
before :all do
|
100
|
+
@resource.save.should be(true)
|
101
|
+
@resource.reload
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'is an IPv4 node' do
|
105
|
+
@resource.should run_ipv4
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'includes IP address 218.43.243.2 in subnet hosts' do
|
109
|
+
@resource.ip_address.include?('218.43.243.2')
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe 'with a blank string used as IP address' do
|
115
|
+
before :all do
|
116
|
+
@resource.ip_address = ''
|
117
|
+
end
|
118
|
+
|
119
|
+
describe 'when dumped and loaded' do
|
120
|
+
before :all do
|
121
|
+
@resource.save.should be(true)
|
122
|
+
@resource.reload
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'is an IPv4 node' do
|
126
|
+
@resource.should run_ipv4
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'should be the expected value' do
|
130
|
+
@resource.ip_address.should == IPAddr.new('0.0.0.0')
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe 'with NO IP address' do
|
136
|
+
before :all do
|
137
|
+
@resource.ip_address = nil
|
138
|
+
end
|
139
|
+
|
140
|
+
describe 'when dumped and loaded' do
|
141
|
+
before :all do
|
142
|
+
@resource.save.should be(true)
|
143
|
+
@resource.reload
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'has no IP address assigned' do
|
147
|
+
@resource.ip_address.should be_nil
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
try_spec do
|
4
|
+
|
5
|
+
require './spec/fixtures/person'
|
6
|
+
|
7
|
+
describe DataMapper::TypesFixtures::Person do
|
8
|
+
supported_by :all do
|
9
|
+
before :all do
|
10
|
+
@resource = DataMapper::TypesFixtures::Person.new(:name => 'Thomas Edison')
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'with no positions information' do
|
14
|
+
before :all do
|
15
|
+
@resource.positions = nil
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'when dumped and loaded again' do
|
19
|
+
before :all do
|
20
|
+
@resource.save.should be(true)
|
21
|
+
@resource.reload
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'has nil positions list' do
|
25
|
+
@resource.positions.should be_nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'with a few items on the positions list' do
|
31
|
+
before :all do
|
32
|
+
@resource.positions = [
|
33
|
+
{ :company => 'The Death Star, Inc', :title => 'Light sabre engineer' },
|
34
|
+
{ :company => 'Sane Little Company', :title => 'Chief Curiosity Officer' },
|
35
|
+
]
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'when dumped and loaded again' do
|
39
|
+
before :all do
|
40
|
+
@resource.save.should be(true)
|
41
|
+
@resource.reload
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'loads positions list to the state when it was dumped/persisted with keys being strings' do
|
45
|
+
@resource.positions.should == [
|
46
|
+
{ 'company' => 'The Death Star, Inc', 'title' => 'Light sabre engineer' },
|
47
|
+
{ 'company' => 'Sane Little Company', 'title' => 'Chief Curiosity Officer' },
|
48
|
+
]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe 'with positions information given as empty list' do
|
54
|
+
before :all do
|
55
|
+
@resource.positions = []
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'when dumped and loaded again' do
|
59
|
+
before :all do
|
60
|
+
@resource.save.should be(true)
|
61
|
+
@resource.reload
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'has empty positions list' do
|
65
|
+
@resource.positions.should == []
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
try_spec do
|
6
|
+
|
7
|
+
require './spec/fixtures/article'
|
8
|
+
|
9
|
+
describe DataMapper::TypesFixtures::Article do
|
10
|
+
supported_by :all do
|
11
|
+
describe "persisted with title and slug set to 'New DataMapper Type'" do
|
12
|
+
before :all do
|
13
|
+
@input = 'New DataMapper Type'
|
14
|
+
@resource = DataMapper::TypesFixtures::Article.create(:title => @input, :slug => @input)
|
15
|
+
|
16
|
+
@resource.reload
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'has slug equal to "new-datamapper-type"' do
|
20
|
+
@resource.slug.should == 'new-datamapper-type'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'can be found by slug' do
|
24
|
+
DataMapper::TypesFixtures::Article.first(:slug => 'new-datamapper-type').should == @resource
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# FIXME: when stringex fixes the problems it has with it's YAML
|
29
|
+
# files not being parsable by psych remove this conditional.
|
30
|
+
unless RUBY_PLATFORM =~ /java/ && JRUBY_VERSION >= '1.6' && RUBY_VERSION >= '1.9.2'
|
31
|
+
[
|
32
|
+
[ 'Iñtërnâtiônàlizætiøn', 'internationalizaetion' ],
|
33
|
+
[ "This is Dan's Blog", 'this-is-dans-blog' ],
|
34
|
+
[ 'This is My Site, and Blog', 'this-is-my-site-and-blog' ],
|
35
|
+
[ 'Google searches for holy grail of Python performance', 'google-searches-for-holy-grail-of-python-performance' ],
|
36
|
+
[ 'iPhone dev: Creating length-controlled data sources', 'iphone-dev-creating-length-controlled-data-sources' ],
|
37
|
+
[ "Review: Nintendo's New DSi -- A Quantum Leap Forward", 'review-nintendos-new-dsi-a-quantum-leap-forward' ],
|
38
|
+
[ "Arriva BraiVe, è l'auto-robot che si 'guida' da sola'", 'arriva-braive-e-lauto-robot-che-si-guida-da-sola' ],
|
39
|
+
[ "La ley antipiratería reduce un 33% el tráfico online en Suecia", 'la-ley-antipirateria-reduce-un-33-percent-el-trafico-online-en-suecia' ],
|
40
|
+
[ "L'Etat américain du Texas s'apprête à interdire Windows Vista", 'letat-americain-du-texas-sapprete-a-interdire-windows-vista' ],
|
41
|
+
].each do |title, slug|
|
42
|
+
describe "set with title '#{title}'" do
|
43
|
+
before :all do
|
44
|
+
@resource = DataMapper::TypesFixtures::Article.new(:title => title)
|
45
|
+
@resource.valid?.should be(true)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "has slug equal to '#{slug}'" do
|
49
|
+
@resource.slug.should == slug
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "and persisted" do
|
53
|
+
before :all do
|
54
|
+
@resource.save.should be(true)
|
55
|
+
@resource.reload
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'can be found by slug' do
|
59
|
+
DataMapper::TypesFixtures::Article.first(:slug => slug).should == @resource
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
try_spec do
|
4
|
+
|
5
|
+
require './spec/fixtures/bookmark'
|
6
|
+
|
7
|
+
describe DataMapper::TypesFixtures::Bookmark do
|
8
|
+
supported_by :all do
|
9
|
+
describe 'without URI' do
|
10
|
+
before :all do
|
11
|
+
@uri = nil
|
12
|
+
@resource = DataMapper::TypesFixtures::Bookmark.new(
|
13
|
+
:title => 'Check this out',
|
14
|
+
:uri => @uri,
|
15
|
+
:shared => false,
|
16
|
+
:tags => %w[ misc ]
|
17
|
+
)
|
18
|
+
|
19
|
+
@resource.save.should be(true)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'can be found by uri' do
|
23
|
+
DataMapper::TypesFixtures::Bookmark.first(:uri => @uri).should == @resource
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'when reloaded' do
|
27
|
+
before :all do
|
28
|
+
@resource.reload
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'has no uri' do
|
32
|
+
@resource.uri.should be_nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'with a blank URI' do
|
38
|
+
before :all do
|
39
|
+
@uri = ''
|
40
|
+
DataMapper::TypesFixtures::Bookmark.auto_migrate!
|
41
|
+
@resource = DataMapper::TypesFixtures::Bookmark.new(
|
42
|
+
:title => 'Check this out',
|
43
|
+
:uri => @uri,
|
44
|
+
:shared => false,
|
45
|
+
:tags => %w[ misc ]
|
46
|
+
)
|
47
|
+
|
48
|
+
@resource.save.should be(true)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'can be found by uri' do
|
52
|
+
DataMapper::TypesFixtures::Bookmark.first(:uri => @uri).should == @resource
|
53
|
+
end
|
54
|
+
|
55
|
+
describe 'when reloaded' do
|
56
|
+
before :all do
|
57
|
+
@resource.reload
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'is loaded as URI object' do
|
61
|
+
@resource.uri.should be_an_instance_of(Addressable::URI)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'has the same original URI' do
|
65
|
+
@resource.uri.to_s.should == @uri
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe 'with invalid URI' do
|
71
|
+
before :all do
|
72
|
+
@uri = 'this is def. not URI'
|
73
|
+
@resource = DataMapper::TypesFixtures::Bookmark.new(
|
74
|
+
:title => 'Check this out',
|
75
|
+
:uri => @uri,
|
76
|
+
:shared => false,
|
77
|
+
:tags => %w[ misc ]
|
78
|
+
)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'is perfectly valid (URI type does not provide auto validations)' do
|
82
|
+
@resource.save.should be(true)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
%w[
|
87
|
+
http://apple.com
|
88
|
+
http://www.apple.com
|
89
|
+
http://apple.com/
|
90
|
+
http://apple.com/iphone
|
91
|
+
http://www.google.com/search?client=safari&rls=en-us&q=LED&ie=UTF-8&oe=UTF-8
|
92
|
+
http://books.google.com
|
93
|
+
http://books.google.com/
|
94
|
+
http://db2.clouds.megacorp.net:8080
|
95
|
+
https://github.com
|
96
|
+
https://github.com/
|
97
|
+
http://www.example.com:8088/never/ending/path/segments/
|
98
|
+
http://db2.clouds.megacorp.net:8080/resources/10
|
99
|
+
http://www.example.com:8088/never/ending/path/segments
|
100
|
+
http://books.google.com/books?id=uSUJ3VhH4BsC&printsec=frontcover&dq=subject:%22+Linguistics+%22&as_brr=3&ei=DAHPSbGQE5rEzATk1sShAQ&rview=1
|
101
|
+
http://books.google.com:80/books?uid=14472359158468915761&rview=1
|
102
|
+
http://books.google.com/books?id=Ar3-TXCYXUkC&printsec=frontcover&rview=1
|
103
|
+
http://books.google.com/books/vp6ae081e454d30f89b6bca94e0f96fc14.js
|
104
|
+
http://www.google.com/images/cleardot.gif
|
105
|
+
http://books.google.com:80/books?id=Ar3-TXCYXUkC&printsec=frontcover&rview=1#PPA5,M1
|
106
|
+
http://www.hulu.com/watch/64923/terminator-the-sarah-connor-chronicles-to-the-lighthouse
|
107
|
+
http://hulu.com:80/browse/popular/tv
|
108
|
+
http://www.hulu.com/watch/62475/the-simpsons-gone-maggie-gone#s-p1-so-i0
|
109
|
+
].each do |uri|
|
110
|
+
describe "with URI set to '#{uri}'" do
|
111
|
+
before :all do
|
112
|
+
@resource = DataMapper::TypesFixtures::Bookmark.new(
|
113
|
+
:title => 'Check this out',
|
114
|
+
:uri => uri,
|
115
|
+
:shared => false,
|
116
|
+
:tags => %w[ misc ]
|
117
|
+
)
|
118
|
+
|
119
|
+
@resource.save.should be(true)
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'can be found by uri' do
|
123
|
+
DataMapper::TypesFixtures::Bookmark.first(:uri => uri).should_not be_nil
|
124
|
+
end
|
125
|
+
|
126
|
+
describe 'when reloaded' do
|
127
|
+
before :all do
|
128
|
+
@resource.reload
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'has the same original URI' do
|
132
|
+
@resource.uri.to_s.should eql(uri)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
try_spec do
|
4
|
+
|
5
|
+
require './spec/fixtures/network_node'
|
6
|
+
|
7
|
+
describe DataMapper::TypesFixtures::NetworkNode do
|
8
|
+
supported_by :all do
|
9
|
+
describe 'with UUID set as UUID object' do
|
10
|
+
before :all do
|
11
|
+
@uuid_string = 'b0fc632e-d744-4821-afe3-4ea0701859ee'
|
12
|
+
@uuid = UUIDTools::UUID.parse(@uuid_string)
|
13
|
+
@resource = DataMapper::TypesFixtures::NetworkNode.new(:uuid => @uuid)
|
14
|
+
|
15
|
+
@resource.save.should be(true)
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'when reloaded' do
|
19
|
+
before :all do
|
20
|
+
@resource.reload
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'has the same UUID string' do
|
24
|
+
@resource.uuid.to_s.should == @uuid_string
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'returns UUID as an object' do
|
28
|
+
@resource.uuid.should be_an_instance_of(UUIDTools::UUID)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'with UUID set as a valid UUID string' do
|
34
|
+
before :all do
|
35
|
+
@uuid = 'b0fc632e-d744-4821-afe3-4ea0701859ee'
|
36
|
+
@resource = DataMapper::TypesFixtures::NetworkNode.new(:uuid => @uuid)
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'when reloaded' do
|
40
|
+
before :all do
|
41
|
+
@resource.reload
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'has the same UUID string' do
|
45
|
+
@resource.uuid.to_s.should == @uuid
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'returns UUID as an object' do
|
49
|
+
@resource.uuid.should be_an_instance_of(UUIDTools::UUID)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'with UUID set as invalid UUID string' do
|
55
|
+
before :all do
|
56
|
+
@uuid = 'meh'
|
57
|
+
@operation = lambda do
|
58
|
+
DataMapper::TypesFixtures::NetworkNode.new(:uuid => @uuid)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe 'when assigned UUID' do
|
63
|
+
it 'raises ArgumentError' do
|
64
|
+
@operation.should raise_error(ArgumentError, /Invalid UUID format/)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe 'with UUID set as a blank string' do
|
70
|
+
before :all do
|
71
|
+
@uuid = ''
|
72
|
+
@operation = lambda do
|
73
|
+
DataMapper::TypesFixtures::NetworkNode.new(:uuid => @uuid)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe 'when assigned UUID' do
|
78
|
+
it 'raises ArgumentError' do
|
79
|
+
@operation.should raise_error(ArgumentError, /Invalid UUID format/)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe 'with missing UUID' do
|
85
|
+
before :all do
|
86
|
+
@uuid = nil
|
87
|
+
@resource = DataMapper::TypesFixtures::NetworkNode.new(:uuid => @uuid)
|
88
|
+
end
|
89
|
+
|
90
|
+
describe 'when reloaded' do
|
91
|
+
before :all do
|
92
|
+
@resource.reload
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'has no UUID' do
|
96
|
+
@resource.uuid.should be_nil
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
try_spec do
|
4
|
+
|
5
|
+
require './spec/fixtures/person'
|
6
|
+
require './spec/fixtures/invention'
|
7
|
+
|
8
|
+
describe DataMapper::TypesFixtures::Person do
|
9
|
+
supported_by :all do
|
10
|
+
before :all do
|
11
|
+
@resource = DataMapper::TypesFixtures::Person.new(:name => '')
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'with no inventions information' do
|
15
|
+
before :all do
|
16
|
+
@resource.inventions = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'when dumped and loaded again' do
|
20
|
+
before :all do
|
21
|
+
@resource.save.should be(true)
|
22
|
+
@resource.reload
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'has nil inventions list' do
|
26
|
+
@resource.inventions.should be_nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'with a few items on the inventions list' do
|
32
|
+
before :all do
|
33
|
+
@input = [ 'carbon telephone transmitter', 'light bulb', 'electric grid' ].map do |name|
|
34
|
+
DataMapper::TypesFixtures::Invention.new(name)
|
35
|
+
end
|
36
|
+
@resource.inventions = @input
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'when dumped and loaded again' do
|
40
|
+
before :all do
|
41
|
+
@resource.save.should be(true)
|
42
|
+
@resource.reload
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'loads inventions list to the state when it was dumped/persisted with keys being strings' do
|
46
|
+
@resource.inventions.should == @input
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'with inventions information given as empty list' do
|
52
|
+
before :all do
|
53
|
+
@resource.inventions = []
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'when dumped and loaded again' do
|
57
|
+
before :all do
|
58
|
+
@resource.save.should be(true)
|
59
|
+
@resource.reload
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'has empty inventions list' do
|
63
|
+
@resource.inventions.should == []
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|