sbf-dm-types 1.3.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +45 -0
- data/.rspec +1 -0
- data/.rubocop.yml +468 -0
- data/.travis.yml +52 -0
- data/Gemfile +67 -0
- data/LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +4 -0
- data/dm-types.gemspec +26 -0
- data/lib/dm-types/api_key.rb +30 -0
- data/lib/dm-types/bcrypt_hash.rb +33 -0
- data/lib/dm-types/comma_separated_list.rb +28 -0
- data/lib/dm-types/csv.rb +34 -0
- data/lib/dm-types/enum.rb +55 -0
- data/lib/dm-types/epoch_time.rb +35 -0
- data/lib/dm-types/file_path.rb +24 -0
- data/lib/dm-types/flag.rb +64 -0
- data/lib/dm-types/ip_address.rb +34 -0
- data/lib/dm-types/json.rb +48 -0
- data/lib/dm-types/paranoid/base.rb +56 -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 +28 -0
- data/lib/dm-types/support/dirty_minder.rb +168 -0
- data/lib/dm-types/support/flags.rb +41 -0
- data/lib/dm-types/uri.rb +27 -0
- data/lib/dm-types/uuid.rb +64 -0
- data/lib/dm-types/version.rb +5 -0
- data/lib/dm-types/yaml.rb +39 -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 +78 -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 +117 -0
- data/spec/integration/uuid_spec.rb +102 -0
- data/spec/integration/yaml_spec.rb +87 -0
- data/spec/shared/flags_shared_spec.rb +37 -0
- data/spec/shared/identity_function_group.rb +5 -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/dirty_minder_spec.rb +65 -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 +75 -0
- data/spec/unit/flag_spec.rb +114 -0
- data/spec/unit/ip_address_spec.rb +109 -0
- data/spec/unit/json_spec.rb +126 -0
- data/spec/unit/paranoid_boolean_spec.rb +149 -0
- data/spec/unit/paranoid_datetime_spec.rb +153 -0
- data/spec/unit/regexp_spec.rb +63 -0
- data/spec/unit/uri_spec.rb +83 -0
- data/spec/unit/yaml_spec.rb +111 -0
- data/tasks/spec.rake +21 -0
- data/tasks/yard.rake +9 -0
- data/tasks/yardstick.rake +19 -0
- metadata +229 -0
@@ -0,0 +1,153 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
RSpec::Matchers.define :run_ipv4 do
|
4
|
+
match(&:runs_ipv4?)
|
5
|
+
end
|
6
|
+
|
7
|
+
RSpec::Matchers.define :run_ipv6 do
|
8
|
+
match(&:runs_ipv6?)
|
9
|
+
end
|
10
|
+
|
11
|
+
try_spec do
|
12
|
+
|
13
|
+
require_relative '../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
|
+
expect(@resource.save).to be(true)
|
33
|
+
@resource.reload
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'is an IPv6 node' do
|
37
|
+
expect(@resource).to 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
|
+
expect(@resource.save).to be(true)
|
50
|
+
@resource.reload
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'is an IPv4 node' do
|
54
|
+
expect(@resource).to 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
|
+
expect(@resource.save).to be(true)
|
67
|
+
@resource.reload
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'is an IPv4 node' do
|
71
|
+
expect(@resource).to 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
|
+
expect(@resource.save).to be(true)
|
84
|
+
@resource.reload
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'is an IPv4 node' do
|
88
|
+
expect(@resource).to 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
|
+
expect(@resource.save).to be(true)
|
101
|
+
@resource.reload
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'is an IPv4 node' do
|
105
|
+
expect(@resource).to 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
|
+
expect(@resource.save).to be(true)
|
122
|
+
@resource.reload
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'is an IPv4 node' do
|
126
|
+
expect(@resource).to run_ipv4
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'is the expected value' do
|
130
|
+
expect(@resource.ip_address).to eq 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
|
+
expect(@resource.save).to be(true)
|
143
|
+
@resource.reload
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'has no IP address assigned' do
|
147
|
+
expect(@resource.ip_address).to be_nil
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
try_spec do
|
4
|
+
|
5
|
+
require_relative '../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
|
+
expect(@resource.save).to be(true)
|
21
|
+
@resource.reload
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'has nil positions list' do
|
25
|
+
expect(@resource.positions).to 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
|
+
expect(@resource.save).to 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
|
+
expect(@resource.positions).to eq [
|
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
|
+
expect(@resource.save).to be(true)
|
61
|
+
@resource.reload
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'has empty positions list' do
|
65
|
+
expect(@resource.positions).to eq []
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative '../spec_helper'
|
4
|
+
|
5
|
+
try_spec do
|
6
|
+
|
7
|
+
require_relative '../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
|
+
expect(@resource.slug).to eq 'new-datamapper-type'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'can be found by slug' do
|
24
|
+
expect(DataMapper::TypesFixtures::Article.first(:slug => 'new-datamapper-type')).to eq @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
|
+
expect(@resource.valid?).to be(true)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "has slug equal to '#{slug}'" do
|
49
|
+
expect(@resource.slug).to eq slug
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "and persisted" do
|
53
|
+
before :all do
|
54
|
+
expect(@resource.save).to be(true)
|
55
|
+
@resource.reload
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'can be found by slug' do
|
59
|
+
expect(DataMapper::TypesFixtures::Article.first(:slug => slug)).to eq @resource
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
try_spec do
|
4
|
+
require_relative '../fixtures/bookmark'
|
5
|
+
|
6
|
+
describe DataMapper::TypesFixtures::Bookmark do
|
7
|
+
supported_by :all do
|
8
|
+
before :all do
|
9
|
+
DataMapper::TypesFixtures::Bookmark.auto_migrate!
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:resource) do
|
13
|
+
DataMapper::TypesFixtures::Bookmark.create(
|
14
|
+
:title => 'Check this out',
|
15
|
+
:uri => uri,
|
16
|
+
:shared => false,
|
17
|
+
:tags => %w[ misc ]
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
before do
|
22
|
+
expect(resource).to be_saved
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'without URI' do
|
26
|
+
let(:uri) { nil }
|
27
|
+
|
28
|
+
it 'can be found by uri' do
|
29
|
+
expect(DataMapper::TypesFixtures::Bookmark.first(:uri => uri)).to eql(resource)
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'when reloaded' do
|
33
|
+
before do
|
34
|
+
resource.reload
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'has no uri' do
|
38
|
+
expect(resource.uri).to be(nil)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'with a blank URI' do
|
44
|
+
let(:uri) { '' }
|
45
|
+
|
46
|
+
it 'can be found by uri' do
|
47
|
+
expect(DataMapper::TypesFixtures::Bookmark.first(:uri => uri)).to eql(resource)
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'when reloaded' do
|
51
|
+
before do
|
52
|
+
resource.reload
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'is loaded as URI object' do
|
56
|
+
expect(resource.uri).to be_an_instance_of(Addressable::URI)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'has the same original URI' do
|
60
|
+
expect(resource.uri.to_s).to eql(uri)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe 'with invalid URI' do
|
66
|
+
let(:uri) { 'this is def. not URI' }
|
67
|
+
|
68
|
+
it 'is perfectly valid (URI type does not provide auto validations)' do
|
69
|
+
expect(resource.save).to be(true)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
%w[
|
74
|
+
http://apple.com
|
75
|
+
http://www.apple.com
|
76
|
+
http://apple.com/
|
77
|
+
http://apple.com/iphone
|
78
|
+
http://www.google.com/search?client=safari&rls=en-us&q=LED&ie=UTF-8&oe=UTF-8
|
79
|
+
http://books.google.com
|
80
|
+
http://books.google.com/
|
81
|
+
http://db2.clouds.megacorp.net:8080
|
82
|
+
https://github.com
|
83
|
+
https://github.com/
|
84
|
+
http://www.example.com:8088/never/ending/path/segments/
|
85
|
+
http://db2.clouds.megacorp.net:8080/resources/10
|
86
|
+
http://www.example.com:8088/never/ending/path/segments
|
87
|
+
http://books.google.com/books?id=uSUJ3VhH4BsC&printsec=frontcover&dq=subject:%22+Linguistics+%22&as_brr=3&ei=DAHPSbGQE5rEzATk1sShAQ&rview=1
|
88
|
+
http://books.google.com:80/books?uid=14472359158468915761&rview=1
|
89
|
+
http://books.google.com/books?id=Ar3-TXCYXUkC&printsec=frontcover&rview=1
|
90
|
+
http://books.google.com/books/vp6ae081e454d30f89b6bca94e0f96fc14.js
|
91
|
+
http://www.google.com/images/cleardot.gif
|
92
|
+
http://books.google.com:80/books?id=Ar3-TXCYXUkC&printsec=frontcover&rview=1#PPA5,M1
|
93
|
+
http://www.hulu.com/watch/64923/terminator-the-sarah-connor-chronicles-to-the-lighthouse
|
94
|
+
http://hulu.com:80/browse/popular/tv
|
95
|
+
http://www.hulu.com/watch/62475/the-simpsons-gone-maggie-gone#s-p1-so-i0
|
96
|
+
].each do |uri|
|
97
|
+
describe "with URI set to '#{uri}'" do
|
98
|
+
let(:uri) { uri }
|
99
|
+
|
100
|
+
it 'can be found by uri' do
|
101
|
+
expect(DataMapper::TypesFixtures::Bookmark.first(:uri => uri)).not_to be(nil)
|
102
|
+
end
|
103
|
+
|
104
|
+
describe 'when reloaded' do
|
105
|
+
before do
|
106
|
+
resource.reload
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'matches a normalized form of the original URI' do
|
110
|
+
expect(resource.uri).to eql(Addressable::URI.parse(uri).normalize)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
try_spec do
|
4
|
+
|
5
|
+
require_relative '../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
|
+
expect(@resource.save).to 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
|
+
expect(@resource.uuid.to_s).to eq @uuid_string
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'returns UUID as an object' do
|
28
|
+
expect(@resource.uuid).to 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
|
+
expect(@resource.uuid.to_s).to eq @uuid
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'returns UUID as an object' do
|
49
|
+
expect(@resource.uuid).to 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
|
+
expect { @operation }.to 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
|
+
expect { @operation }.to 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
|
+
expect(@resource.uuid).to be_nil
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
try_spec do
|
4
|
+
|
5
|
+
require_relative '../fixtures/person'
|
6
|
+
require_relative '../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
|
+
expect(@resource.save).to be(true)
|
22
|
+
@resource.reload
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'has nil inventions list' do
|
26
|
+
expect(@resource.inventions).to 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
|
+
expect(@resource.save).to 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
|
+
expect(@resource.inventions).to eq [{ 'name' => 'carbon telephone transmitter' }, { 'name' => 'light bulb' }, { 'name' => 'electric grid' }]
|
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
|
+
expect(@resource.save).to be(true)
|
59
|
+
@resource.reload
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'has empty inventions list' do
|
63
|
+
expect(@resource.inventions).to eq []
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe 'with inventions as a string' do
|
69
|
+
before :all do
|
70
|
+
object = "Foo and Bar" #.freeze
|
71
|
+
@resource.inventions = object
|
72
|
+
end
|
73
|
+
|
74
|
+
describe 'when dumped and loaded again' do
|
75
|
+
before :all do
|
76
|
+
expect(@resource.save).to be(true)
|
77
|
+
@resource.reload
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'has correct inventions' do
|
81
|
+
expect(@resource.inventions).to eq 'Foo and Bar'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
shared_examples 'A property with flags' do
|
2
|
+
before :all do
|
3
|
+
%w(@property_klass).each do |ivar|
|
4
|
+
raise "+#{ivar}+ should be defined in before block" unless instance_variable_defined?(ivar)
|
5
|
+
end
|
6
|
+
|
7
|
+
@flags = %i(one two three)
|
8
|
+
|
9
|
+
class ::User
|
10
|
+
include DataMapper::Resource
|
11
|
+
end
|
12
|
+
|
13
|
+
@property = User.property :item, @property_klass[@flags], key: true
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '.generated_classes' do
|
17
|
+
it 'caches the generated class' do
|
18
|
+
expect(@property_klass.generated_classes[@flags]).not_to be_nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'includes :flags in accepted_options' do
|
23
|
+
expect(@property_klass.accepted_options).to include(:flags)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'responds to :generated_classes' do
|
27
|
+
expect(@property_klass).to respond_to(:generated_classes)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'responds to :flag_map' do
|
31
|
+
expect(@property).to respond_to(:flag_map)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'is custom' do
|
35
|
+
expect(@property.custom?).to be(true)
|
36
|
+
end
|
37
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'dm-core/spec/setup'
|
2
|
+
require 'dm-core/spec/lib/adapter_helpers'
|
3
|
+
|
4
|
+
require 'dm-types'
|
5
|
+
require 'dm-migrations'
|
6
|
+
require 'dm-validations'
|
7
|
+
|
8
|
+
Dir["#{Pathname(__FILE__).dirname.expand_path}/shared/*.rb"].sort.each { |file| require file }
|
9
|
+
|
10
|
+
DataMapper::Spec.setup
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.extend(DataMapper::Spec::Adapters::Helpers)
|
14
|
+
end
|
15
|
+
|
16
|
+
DEPENDENCIES = {
|
17
|
+
'bcrypt' => 'bcrypt-ruby'
|
18
|
+
}.freeze
|
19
|
+
|
20
|
+
def try_spec
|
21
|
+
begin
|
22
|
+
yield
|
23
|
+
rescue LoadError => error
|
24
|
+
raise error unless (lib = error.message.match(/\Ano such file to load -- (.+)\z/)[1])
|
25
|
+
|
26
|
+
gem_location = DEPENDENCIES[lib] || raise("Unknown lib #{lib}")
|
27
|
+
|
28
|
+
warn "[WARNING] Skipping specs using #{lib}, please do: gem install #{gem_location}"
|
29
|
+
end
|
30
|
+
end
|