ardm 0.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.
Files changed (179) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +35 -0
  3. data/Gemfile +13 -0
  4. data/LICENSE +21 -0
  5. data/README.md +70 -0
  6. data/Rakefile +4 -0
  7. data/ardm.gemspec +29 -0
  8. data/db/.gitignore +1 -0
  9. data/lib/ardm/active_record/associations.rb +80 -0
  10. data/lib/ardm/active_record/base.rb +49 -0
  11. data/lib/ardm/active_record/dirty.rb +25 -0
  12. data/lib/ardm/active_record/hooks.rb +31 -0
  13. data/lib/ardm/active_record/inheritance.rb +37 -0
  14. data/lib/ardm/active_record/is/state_machine.rb +21 -0
  15. data/lib/ardm/active_record/is.rb +22 -0
  16. data/lib/ardm/active_record/not_found.rb +7 -0
  17. data/lib/ardm/active_record/predicate_builder/array_handler.rb +31 -0
  18. data/lib/ardm/active_record/predicate_builder/rails3.rb +147 -0
  19. data/lib/ardm/active_record/predicate_builder/rails4.rb +139 -0
  20. data/lib/ardm/active_record/predicate_builder/relation_handler.rb +15 -0
  21. data/lib/ardm/active_record/predicate_builder.rb +19 -0
  22. data/lib/ardm/active_record/property.rb +357 -0
  23. data/lib/ardm/active_record/query.rb +108 -0
  24. data/lib/ardm/active_record/record.rb +70 -0
  25. data/lib/ardm/active_record/relation.rb +83 -0
  26. data/lib/ardm/active_record/repository.rb +38 -0
  27. data/lib/ardm/active_record/serialization.rb +164 -0
  28. data/lib/ardm/active_record/storage_names.rb +28 -0
  29. data/lib/ardm/active_record/validations.rb +111 -0
  30. data/lib/ardm/active_record.rb +43 -0
  31. data/lib/ardm/data_mapper/not_found.rb +5 -0
  32. data/lib/ardm/data_mapper/record.rb +41 -0
  33. data/lib/ardm/data_mapper.rb +5 -0
  34. data/lib/ardm/env.rb +5 -0
  35. data/lib/ardm/property/api_key.rb +30 -0
  36. data/lib/ardm/property/bcrypt_hash.rb +31 -0
  37. data/lib/ardm/property/binary.rb +23 -0
  38. data/lib/ardm/property/boolean.rb +29 -0
  39. data/lib/ardm/property/class.rb +19 -0
  40. data/lib/ardm/property/comma_separated_list.rb +28 -0
  41. data/lib/ardm/property/csv.rb +35 -0
  42. data/lib/ardm/property/date.rb +12 -0
  43. data/lib/ardm/property/datetime.rb +12 -0
  44. data/lib/ardm/property/decimal.rb +38 -0
  45. data/lib/ardm/property/discriminator.rb +65 -0
  46. data/lib/ardm/property/enum.rb +51 -0
  47. data/lib/ardm/property/epoch_time.rb +38 -0
  48. data/lib/ardm/property/file_path.rb +25 -0
  49. data/lib/ardm/property/flag.rb +65 -0
  50. data/lib/ardm/property/float.rb +18 -0
  51. data/lib/ardm/property/integer.rb +24 -0
  52. data/lib/ardm/property/invalid_value_error.rb +22 -0
  53. data/lib/ardm/property/ip_address.rb +35 -0
  54. data/lib/ardm/property/json.rb +49 -0
  55. data/lib/ardm/property/lookup.rb +29 -0
  56. data/lib/ardm/property/numeric.rb +40 -0
  57. data/lib/ardm/property/object.rb +36 -0
  58. data/lib/ardm/property/paranoid_boolean.rb +18 -0
  59. data/lib/ardm/property/paranoid_datetime.rb +17 -0
  60. data/lib/ardm/property/regexp.rb +22 -0
  61. data/lib/ardm/property/serial.rb +16 -0
  62. data/lib/ardm/property/slug.rb +29 -0
  63. data/lib/ardm/property/string.rb +40 -0
  64. data/lib/ardm/property/support/dirty_minder.rb +169 -0
  65. data/lib/ardm/property/support/flags.rb +41 -0
  66. data/lib/ardm/property/support/paranoid_base.rb +78 -0
  67. data/lib/ardm/property/text.rb +11 -0
  68. data/lib/ardm/property/time.rb +12 -0
  69. data/lib/ardm/property/uri.rb +27 -0
  70. data/lib/ardm/property/uuid.rb +65 -0
  71. data/lib/ardm/property/validation.rb +208 -0
  72. data/lib/ardm/property/yaml.rb +38 -0
  73. data/lib/ardm/property.rb +891 -0
  74. data/lib/ardm/property_set.rb +152 -0
  75. data/lib/ardm/query/expression.rb +85 -0
  76. data/lib/ardm/query/ext/symbol.rb +37 -0
  77. data/lib/ardm/query/operator.rb +64 -0
  78. data/lib/ardm/record.rb +1 -0
  79. data/lib/ardm/support/assertions.rb +8 -0
  80. data/lib/ardm/support/deprecate.rb +12 -0
  81. data/lib/ardm/support/descendant_set.rb +89 -0
  82. data/lib/ardm/support/equalizer.rb +48 -0
  83. data/lib/ardm/support/ext/array.rb +22 -0
  84. data/lib/ardm/support/ext/blank.rb +25 -0
  85. data/lib/ardm/support/ext/hash.rb +67 -0
  86. data/lib/ardm/support/ext/module.rb +47 -0
  87. data/lib/ardm/support/ext/object.rb +57 -0
  88. data/lib/ardm/support/ext/string.rb +24 -0
  89. data/lib/ardm/support/ext/try_dup.rb +12 -0
  90. data/lib/ardm/support/hook.rb +405 -0
  91. data/lib/ardm/support/lazy_array.rb +451 -0
  92. data/lib/ardm/support/local_object_space.rb +13 -0
  93. data/lib/ardm/support/logger.rb +201 -0
  94. data/lib/ardm/support/mash.rb +176 -0
  95. data/lib/ardm/support/naming_conventions.rb +90 -0
  96. data/lib/ardm/support/ordered_set.rb +380 -0
  97. data/lib/ardm/support/subject.rb +33 -0
  98. data/lib/ardm/support/subject_set.rb +250 -0
  99. data/lib/ardm/version.rb +3 -0
  100. data/lib/ardm.rb +56 -0
  101. data/spec/fixtures/api_user.rb +11 -0
  102. data/spec/fixtures/article.rb +22 -0
  103. data/spec/fixtures/bookmark.rb +14 -0
  104. data/spec/fixtures/invention.rb +5 -0
  105. data/spec/fixtures/network_node.rb +23 -0
  106. data/spec/fixtures/person.rb +17 -0
  107. data/spec/fixtures/software_package.rb +22 -0
  108. data/spec/fixtures/ticket.rb +12 -0
  109. data/spec/fixtures/tshirt.rb +15 -0
  110. data/spec/integration/api_key_spec.rb +25 -0
  111. data/spec/integration/bcrypt_hash_spec.rb +45 -0
  112. data/spec/integration/comma_separated_list_spec.rb +85 -0
  113. data/spec/integration/dirty_minder_spec.rb +197 -0
  114. data/spec/integration/enum_spec.rb +79 -0
  115. data/spec/integration/epoch_time_spec.rb +59 -0
  116. data/spec/integration/file_path_spec.rb +158 -0
  117. data/spec/integration/flag_spec.rb +72 -0
  118. data/spec/integration/ip_address_spec.rb +151 -0
  119. data/spec/integration/json_spec.rb +70 -0
  120. data/spec/integration/slug_spec.rb +65 -0
  121. data/spec/integration/uri_spec.rb +136 -0
  122. data/spec/integration/uuid_spec.rb +102 -0
  123. data/spec/integration/yaml_spec.rb +85 -0
  124. data/spec/public/property/binary_spec.rb +41 -0
  125. data/spec/public/property/boolean_spec.rb +30 -0
  126. data/spec/public/property/class_spec.rb +28 -0
  127. data/spec/public/property/date_spec.rb +22 -0
  128. data/spec/public/property/date_time_spec.rb +22 -0
  129. data/spec/public/property/decimal_spec.rb +23 -0
  130. data/spec/public/property/discriminator_spec.rb +133 -0
  131. data/spec/public/property/float_spec.rb +22 -0
  132. data/spec/public/property/integer_spec.rb +22 -0
  133. data/spec/public/property/object_spec.rb +103 -0
  134. data/spec/public/property/serial_spec.rb +22 -0
  135. data/spec/public/property/string_spec.rb +22 -0
  136. data/spec/public/property/text_spec.rb +23 -0
  137. data/spec/public/property/time_spec.rb +22 -0
  138. data/spec/public/property_spec.rb +316 -0
  139. data/spec/rcov.opts +6 -0
  140. data/spec/schema.rb +86 -0
  141. data/spec/semipublic/property/binary_spec.rb +14 -0
  142. data/spec/semipublic/property/boolean_spec.rb +48 -0
  143. data/spec/semipublic/property/class_spec.rb +36 -0
  144. data/spec/semipublic/property/date_spec.rb +44 -0
  145. data/spec/semipublic/property/date_time_spec.rb +47 -0
  146. data/spec/semipublic/property/decimal_spec.rb +83 -0
  147. data/spec/semipublic/property/discriminator_spec.rb +22 -0
  148. data/spec/semipublic/property/float_spec.rb +83 -0
  149. data/spec/semipublic/property/integer_spec.rb +83 -0
  150. data/spec/semipublic/property/lookup_spec.rb +27 -0
  151. data/spec/semipublic/property/serial_spec.rb +14 -0
  152. data/spec/semipublic/property/string_spec.rb +14 -0
  153. data/spec/semipublic/property/text_spec.rb +30 -0
  154. data/spec/semipublic/property/time_spec.rb +49 -0
  155. data/spec/semipublic/property_spec.rb +51 -0
  156. data/spec/shared/flags_shared_spec.rb +36 -0
  157. data/spec/shared/identity_function_group.rb +5 -0
  158. data/spec/shared/public_property_spec.rb +229 -0
  159. data/spec/shared/semipublic_property_spec.rb +159 -0
  160. data/spec/spec.opts +4 -0
  161. data/spec/spec_helper.rb +58 -0
  162. data/spec/unit/bcrypt_hash_spec.rb +154 -0
  163. data/spec/unit/csv_spec.rb +139 -0
  164. data/spec/unit/dirty_minder_spec.rb +64 -0
  165. data/spec/unit/enum_spec.rb +125 -0
  166. data/spec/unit/epoch_time_spec.rb +72 -0
  167. data/spec/unit/file_path_spec.rb +75 -0
  168. data/spec/unit/flag_spec.rb +114 -0
  169. data/spec/unit/ip_address_spec.rb +109 -0
  170. data/spec/unit/json_spec.rb +127 -0
  171. data/spec/unit/paranoid_boolean_spec.rb +142 -0
  172. data/spec/unit/paranoid_datetime_spec.rb +149 -0
  173. data/spec/unit/regexp_spec.rb +62 -0
  174. data/spec/unit/uri_spec.rb +64 -0
  175. data/spec/unit/yaml_spec.rb +111 -0
  176. data/tasks/spec.rake +40 -0
  177. data/tasks/yard.rake +9 -0
  178. data/tasks/yardstick.rake +19 -0
  179. metadata +350 -0
@@ -0,0 +1,151 @@
1
+ require 'spec_helper'
2
+
3
+ try_spec do
4
+
5
+ require './spec/fixtures/network_node'
6
+
7
+ describe Ardm::Fixtures::NetworkNode do
8
+ def run_ipv4
9
+ be_runs_ipv4
10
+ end
11
+
12
+ def run_ipv6
13
+ be_runs_ipv6
14
+ end
15
+
16
+ before do
17
+ @resource = Ardm::Fixtures::NetworkNode.new(
18
+ :node_uuid => '25a44800-21c9-11de-8c30-0800200c9a66',
19
+ :ip_address => nil,
20
+ :cidr_subnet_bits => nil
21
+ )
22
+ end
23
+
24
+ describe 'with IP address fe80::ab8:e8ff:fed7:f8c9' do
25
+ before do
26
+ @resource.ip_address = 'fe80::ab8:e8ff:fed7:f8c9'
27
+ end
28
+
29
+ describe 'when dumped and loaded' do
30
+ before do
31
+ @resource.save.should be(true)
32
+ @resource.reload
33
+ end
34
+
35
+ it 'is an IPv6 node' do
36
+ @resource.should run_ipv6
37
+ end
38
+ end
39
+ end
40
+
41
+ describe 'with IP address 127.0.0.1' do
42
+ before do
43
+ @resource.ip_address = '127.0.0.1'
44
+ end
45
+
46
+ describe 'when dumped and loaded' do
47
+ before do
48
+ @resource.save.should be(true)
49
+ @resource.reload
50
+ end
51
+
52
+ it 'is an IPv4 node' do
53
+ @resource.should run_ipv4
54
+ end
55
+ end
56
+ end
57
+
58
+ describe 'with IP address 218.43.243.136' do
59
+ before do
60
+ @resource.ip_address = '218.43.243.136'
61
+ end
62
+
63
+ describe 'when dumped and loaded' do
64
+ before do
65
+ @resource.save.should be(true)
66
+ @resource.reload
67
+ end
68
+
69
+ it 'is an IPv4 node' do
70
+ @resource.should run_ipv4
71
+ end
72
+ end
73
+ end
74
+
75
+ describe 'with IP address 221.186.184.68' do
76
+ before do
77
+ @resource.ip_address = '221.186.184.68'
78
+ end
79
+
80
+ describe 'when dumped and loaded' do
81
+ before do
82
+ @resource.save.should be(true)
83
+ @resource.reload
84
+ end
85
+
86
+ it 'is an IPv4 node' do
87
+ @resource.should run_ipv4
88
+ end
89
+ end
90
+ end
91
+
92
+ describe 'with IP address given as CIDR' do
93
+ before do
94
+ @resource.ip_address = '218.43.243.0/24'
95
+ end
96
+
97
+ describe 'when dumped and loaded' do
98
+ before do
99
+ @resource.save.should be(true)
100
+ @resource.reload
101
+ end
102
+
103
+ it 'is an IPv4 node' do
104
+ @resource.should run_ipv4
105
+ end
106
+
107
+ it 'includes IP address 218.43.243.2 in subnet hosts' do
108
+ @resource.ip_address.include?('218.43.243.2')
109
+ end
110
+ end
111
+ end
112
+
113
+ describe 'with a blank string used as IP address' do
114
+ before do
115
+ @resource.ip_address = ''
116
+ end
117
+
118
+ describe 'when dumped and loaded' do
119
+ before do
120
+ @resource.save.should be(true)
121
+ @resource.reload
122
+ end
123
+
124
+ it 'is an IPv4 node' do
125
+ @resource.should run_ipv4
126
+ end
127
+
128
+ it 'should be the expected value' do
129
+ @resource.ip_address.should == IPAddr.new('0.0.0.0')
130
+ end
131
+ end
132
+ end
133
+
134
+ describe 'with NO IP address' do
135
+ before do
136
+ @resource.ip_address = nil
137
+ end
138
+
139
+ describe 'when dumped and loaded' do
140
+ before do
141
+ @resource.save.should be(true)
142
+ @resource.reload
143
+ end
144
+
145
+ it 'has no IP address assigned' do
146
+ @resource.ip_address.should be_nil
147
+ end
148
+ end
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ try_spec do
4
+
5
+ require './spec/fixtures/person'
6
+
7
+ describe Ardm::Fixtures::Person do
8
+ before do
9
+ @resource = Ardm::Fixtures::Person.new(:name => 'Thomas Edison')
10
+ end
11
+
12
+ describe 'with no positions information' do
13
+ before do
14
+ @resource.positions = nil
15
+ end
16
+
17
+ describe 'when dumped and loaded again' do
18
+ before do
19
+ @resource.save.should be_true
20
+ @resource.reload
21
+ end
22
+
23
+ it 'has nil positions list' do
24
+ @resource.positions.should be_nil
25
+ end
26
+ end
27
+ end
28
+
29
+ describe 'with a few items on the positions list' do
30
+ before do
31
+ @resource.positions = [
32
+ { :company => 'The Death Star, Inc', :title => 'Light sabre engineer' },
33
+ { :company => 'Sane Little Company', :title => 'Chief Curiosity Officer' },
34
+ ]
35
+ end
36
+
37
+ describe 'when dumped and loaded again' do
38
+ before do
39
+ @resource.save.should be_true
40
+ @resource.reload
41
+ end
42
+
43
+ it 'loads positions list to the state when it was dumped/persisted with keys being strings' do
44
+ @resource.positions.should == [
45
+ { 'company' => 'The Death Star, Inc', 'title' => 'Light sabre engineer' },
46
+ { 'company' => 'Sane Little Company', 'title' => 'Chief Curiosity Officer' },
47
+ ]
48
+ end
49
+ end
50
+ end
51
+
52
+ describe 'with positions information given as empty list' do
53
+ before do
54
+ @resource.positions = []
55
+ end
56
+
57
+ describe 'when dumped and loaded again' do
58
+ before do
59
+ @resource.save.should be_true
60
+ @resource.reload
61
+ end
62
+
63
+ it 'has empty positions list' do
64
+ @resource.positions.should == []
65
+ end
66
+ end
67
+ end
68
+
69
+ end
70
+ end
@@ -0,0 +1,65 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ try_spec do
6
+
7
+ require './spec/fixtures/article'
8
+
9
+ describe Ardm::Fixtures::Article do
10
+ describe "persisted with title and slug set to 'New Ardm Type'" do
11
+ before do
12
+ @input = 'New Ardm Type'
13
+ @resource = Ardm::Fixtures::Article.create(:title => @input, :slug => @input)
14
+
15
+ @resource.reload
16
+ end
17
+
18
+ it 'has slug equal to "new-datamapper-type"' do
19
+ @resource.slug.should == 'new-ardm-type'
20
+ end
21
+
22
+ it 'can be found by slug' do
23
+ Ardm::Fixtures::Article.where(:slug => 'new-ardm-type').first.should == @resource
24
+ end
25
+ end
26
+
27
+ # FIXME: when stringex fixes the problems it has with it's YAML
28
+ # files not being parsable by psych remove this conditional.
29
+ unless RUBY_PLATFORM =~ /java/ && JRUBY_VERSION >= '1.6' && RUBY_VERSION >= '1.9.2'
30
+ [
31
+ [ 'Iñtërnâtiônàlizætiøn', 'internationalizaetion' ],
32
+ [ "This is Dan's Blog", 'this-is-dans-blog' ],
33
+ [ 'This is My Site, and Blog', 'this-is-my-site-and-blog' ],
34
+ [ 'Google searches for holy grail of Python performance', 'google-searches-for-holy-grail-of-python-performance' ],
35
+ [ 'iPhone dev: Creating length-controlled data sources', 'iphone-dev-creating-length-controlled-data-sources' ],
36
+ [ "Review: Nintendo's New DSi -- A Quantum Leap Forward", 'review-nintendos-new-dsi-a-quantum-leap-forward' ],
37
+ [ "Arriva BraiVe, è l'auto-robot che si 'guida' da sola'", 'arriva-braive-e-lauto-robot-che-si-guida-da-sola' ],
38
+ [ "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' ],
39
+ [ "L'Etat américain du Texas s'apprête à interdire Windows Vista", 'letat-americain-du-texas-sapprete-a-interdire-windows-vista' ],
40
+ ].each do |title, slug|
41
+ describe "set with title '#{title}'" do
42
+ before do
43
+ @resource = Ardm::Fixtures::Article.new(:title => title)
44
+ @resource.valid?.should be(true)
45
+ end
46
+
47
+ it "has slug equal to '#{slug}'" do
48
+ @resource.slug.should == slug
49
+ end
50
+
51
+ describe "and persisted" do
52
+ before do
53
+ @resource.save.should be(true)
54
+ @resource.reload
55
+ end
56
+
57
+ it 'can be found by slug' do
58
+ Ardm::Fixtures::Article.where(:slug => slug).first.should == @resource
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,136 @@
1
+ require 'spec_helper'
2
+
3
+ try_spec do
4
+
5
+ require './spec/fixtures/bookmark'
6
+
7
+ describe Ardm::Fixtures::Bookmark do
8
+ describe 'without URI' do
9
+ before do
10
+ @uri = nil
11
+ @resource = Ardm::Fixtures::Bookmark.new(
12
+ :title => 'Check this out',
13
+ :uri => @uri,
14
+ :shared => false,
15
+ :tags => %w[ misc ]
16
+ )
17
+
18
+ @resource.save.should be(true)
19
+ end
20
+
21
+ it 'can be found by uri' do
22
+ Ardm::Fixtures::Bookmark.where(:uri => @uri).first.should == @resource
23
+ end
24
+
25
+ describe 'when reloaded' do
26
+ before do
27
+ @resource.reload
28
+ end
29
+
30
+ it 'has no uri' do
31
+ @resource.uri.should be_nil
32
+ end
33
+ end
34
+ end
35
+
36
+ describe 'with a blank URI' do
37
+ before do
38
+ @uri = ''
39
+ @resource = Ardm::Fixtures::Bookmark.new(
40
+ :title => 'Check this out',
41
+ :uri => @uri,
42
+ :shared => false,
43
+ :tags => %w[ misc ]
44
+ )
45
+
46
+ @resource.save.should be(true)
47
+ end
48
+
49
+ it 'can be found by uri' do
50
+ Ardm::Fixtures::Bookmark.where(:uri => @uri).first.should == @resource
51
+ end
52
+
53
+ describe 'when reloaded' do
54
+ before do
55
+ @resource.reload
56
+ end
57
+
58
+ it 'is loaded as URI object' do
59
+ @resource.uri.should be_an_instance_of(Addressable::URI)
60
+ end
61
+
62
+ it 'has the same original URI' do
63
+ @resource.uri.to_s.should == @uri
64
+ end
65
+ end
66
+ end
67
+
68
+ describe 'with invalid URI' do
69
+ before do
70
+ @uri = 'this is def. not URI'
71
+ @resource = Ardm::Fixtures::Bookmark.new(
72
+ :title => 'Check this out',
73
+ :uri => @uri,
74
+ :shared => false,
75
+ :tags => %w[ misc ]
76
+ )
77
+ end
78
+
79
+ it 'is perfectly valid (URI type does not provide auto validations)' do
80
+ @resource.save.should be(true)
81
+ end
82
+ end
83
+
84
+ %w[
85
+ http://apple.com
86
+ http://www.apple.com
87
+ http://apple.com/
88
+ http://apple.com/iphone
89
+ http://www.google.com/search?client=safari&rls=en-us&q=LED&ie=UTF-8&oe=UTF-8
90
+ http://books.google.com
91
+ http://books.google.com/
92
+ http://db2.clouds.megacorp.net:8080
93
+ https://github.com
94
+ https://github.com/
95
+ http://www.example.com:8088/never/ending/path/segments/
96
+ http://db2.clouds.megacorp.net:8080/resources/10
97
+ http://www.example.com:8088/never/ending/path/segments
98
+ http://books.google.com/books?id=uSUJ3VhH4BsC&printsec=frontcover&dq=subject:%22+Linguistics+%22&as_brr=3&ei=DAHPSbGQE5rEzATk1sShAQ&rview=1
99
+ http://books.google.com:80/books?uid=14472359158468915761&rview=1
100
+ http://books.google.com/books?id=Ar3-TXCYXUkC&printsec=frontcover&rview=1
101
+ http://books.google.com/books/vp6ae081e454d30f89b6bca94e0f96fc14.js
102
+ http://www.google.com/images/cleardot.gif
103
+ http://books.google.com:80/books?id=Ar3-TXCYXUkC&printsec=frontcover&rview=1#PPA5,M1
104
+ http://www.hulu.com/watch/64923/terminator-the-sarah-connor-chronicles-to-the-lighthouse
105
+ http://hulu.com:80/browse/popular/tv
106
+ http://www.hulu.com/watch/62475/the-simpsons-gone-maggie-gone#s-p1-so-i0
107
+ ].each do |uri|
108
+ describe "with URI set to '#{uri}'" do
109
+ before do
110
+ @resource = Ardm::Fixtures::Bookmark.new(
111
+ :title => 'Check this out',
112
+ :uri => uri,
113
+ :shared => false,
114
+ :tags => %w[ misc ]
115
+ )
116
+
117
+ @resource.save.should be(true)
118
+ end
119
+
120
+ it 'can be found by uri' do
121
+ Ardm::Fixtures::Bookmark.where(:uri => uri).first.should_not be_nil
122
+ end
123
+
124
+ describe 'when reloaded' do
125
+ before do
126
+ @resource.reload
127
+ end
128
+
129
+ it 'has the same original URI' do
130
+ @resource.uri.to_s.should eql(uri)
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+
3
+ try_spec do
4
+
5
+ require './spec/fixtures/network_node'
6
+
7
+ describe Ardm::Fixtures::NetworkNode do
8
+ describe 'with UUID set as UUID object' do
9
+ before :each do
10
+ @uuid_string = 'b0fc632e-d744-4821-afe3-4ea0701859ee'
11
+ @uuid = UUIDTools::UUID.parse(@uuid_string)
12
+ @resource = Ardm::Fixtures::NetworkNode.new(:uuid => @uuid)
13
+
14
+ @resource.save.should be(true)
15
+ end
16
+
17
+ describe 'when reloaded' do
18
+ before :each do
19
+ @resource.reload
20
+ end
21
+
22
+ it 'has the same UUID string' do
23
+ @resource.uuid.to_s.should == @uuid_string
24
+ end
25
+
26
+ it 'returns UUID as an object' do
27
+ @resource.uuid.should be_an_instance_of(UUIDTools::UUID)
28
+ end
29
+ end
30
+ end
31
+
32
+ describe 'with UUID set as a valid UUID string' do
33
+ before :each do
34
+ @uuid = 'b0fc632e-d744-4821-afe3-4ea0701859ee'
35
+ @resource = Ardm::Fixtures::NetworkNode.new(:uuid => @uuid)
36
+ @resource.save.should be(true)
37
+ end
38
+
39
+ describe 'when reloaded' do
40
+ before :each 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 :each do
56
+ @uuid = 'meh'
57
+ @operation = lambda do
58
+ Ardm::Fixtures::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 :each do
71
+ @uuid = ''
72
+ @operation = lambda do
73
+ Ardm::Fixtures::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 :each do
86
+ @uuid = nil
87
+ @resource = Ardm::Fixtures::NetworkNode.new(:uuid => @uuid)
88
+ @resource.save.should be(true)
89
+ end
90
+
91
+ describe 'when reloaded' do
92
+ before :each do
93
+ @resource.reload
94
+ end
95
+
96
+ it 'has no UUID' do
97
+ @resource.uuid.should be_nil
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ try_spec do
4
+
5
+ require './spec/fixtures/person'
6
+ require './spec/fixtures/invention'
7
+
8
+ describe Ardm::Fixtures::Person do
9
+ before do
10
+ @resource = Ardm::Fixtures::Person.new(:name => '')
11
+ end
12
+
13
+ describe 'with no inventions information' do
14
+ before do
15
+ @resource.inventions = nil
16
+ end
17
+
18
+ describe 'when dumped and loaded again' do
19
+ before do
20
+ @resource.save.should be(true)
21
+ @resource.reload
22
+ end
23
+
24
+ it 'has nil inventions list' do
25
+ @resource.inventions.should be_nil
26
+ end
27
+ end
28
+ end
29
+
30
+ describe 'with a few items on the inventions list' do
31
+ before do
32
+ @input = [ 'carbon telephone transmitter', 'light bulb', 'electric grid' ].map do |name|
33
+ Ardm::Fixtures::Invention.new(name)
34
+ end
35
+ @resource.inventions = @input
36
+ end
37
+
38
+ describe 'when dumped and loaded again' do
39
+ before do
40
+ @resource.save.should be(true)
41
+ @resource.reload
42
+ end
43
+
44
+ it 'loads inventions list to the state when it was dumped/persisted with keys being strings' do
45
+ @resource.inventions.should == @input
46
+ end
47
+ end
48
+ end
49
+
50
+ describe 'with inventions information given as empty list' do
51
+ before do
52
+ @resource.inventions = []
53
+ end
54
+
55
+ describe 'when dumped and loaded again' do
56
+ before do
57
+ @resource.save.should be(true)
58
+ @resource.reload
59
+ end
60
+
61
+ it 'has empty inventions list' do
62
+ @resource.inventions.should == []
63
+ end
64
+ end
65
+ end
66
+
67
+ describe 'with inventions as a string' do
68
+ before do
69
+ object = "Foo and Bar" #.freeze
70
+ @resource.inventions = object
71
+ end
72
+
73
+ describe 'when dumped and loaded again' do
74
+ before do
75
+ @resource.save.should be(true)
76
+ @resource.reload
77
+ end
78
+
79
+ it 'has correct inventions' do
80
+ @resource.inventions.should == 'Foo and Bar'
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ardm::Property::Binary do
4
+ before do
5
+ @name = :title
6
+ @type = described_class
7
+ @load_as = String
8
+ @value = 'value'
9
+ @other_value = 'return value'
10
+ @invalid_value = 1
11
+ end
12
+
13
+ it_should_behave_like 'A public Property'
14
+
15
+ describe '.options' do
16
+ subject { described_class.options }
17
+
18
+ it { should be_kind_of(Hash) }
19
+
20
+ it { should eql(:load_as => @load_as, :dump_as => @load_as, :coercion_method => :to_string, :length => 50) }
21
+ end
22
+
23
+ if RUBY_VERSION >= "1.9"
24
+ describe 'encoding' do
25
+ let(:model) do
26
+ Class.new(::Ardm::Record) do
27
+ self.table_name = "articles" # co-opt the articles table
28
+ property :bin_data, ::Ardm::Property::Binary, :field => 'body'
29
+ end
30
+ end
31
+
32
+ it 'should always dump with BINARY' do
33
+ model.properties[:bin_data].dump("foo".freeze).encoding.names.should include("BINARY")
34
+ end
35
+
36
+ it 'should always load with BINARY' do
37
+ model.properties[:bin_data].load("foo".freeze).encoding.names.should include("BINARY")
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+ require './spec/fixtures/tshirt'
3
+
4
+ describe Ardm::Property::Boolean do
5
+ before do
6
+ @name = :active
7
+ @type = described_class
8
+ @load_as = TrueClass
9
+ @value = true
10
+ @other_value = false
11
+ @invalid_value = 1
12
+ end
13
+
14
+ it_should_behave_like 'A public Property'
15
+
16
+ describe '.options' do
17
+ subject { described_class.options }
18
+
19
+ it { should be_kind_of(Hash) }
20
+
21
+ it { should eql(:load_as => @load_as, :dump_as => @load_as, :coercion_method => :to_boolean) }
22
+ end
23
+
24
+ describe "default" do
25
+ it "should set has_picture to the default (booleans are specifically weird in rails because presence validation fails for false)" do
26
+ tshirt = Ardm::Fixtures::TShirt.create!
27
+ tshirt.should_not have_picture
28
+ end
29
+ end
30
+ end