ardm 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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,197 @@
1
+ require 'spec_helper'
2
+
3
+ try_spec do
4
+
5
+ # FIXME: DirtyMinder is currently unsupported on RBX, because unlike the other
6
+ # supported Rubies, RBX core class (e.g. Array, Hash) methods use #send(). In
7
+ # other words, the other Rubies don't use #send() (they map directly to their
8
+ # C functions).
9
+ #
10
+ # The current methodology takes advantage of this by using #send() to forward
11
+ # method invocations we've hooked. Supporting RBX will require finding
12
+ # another way, possibly for all Rubies. In the meantime, something is better
13
+ # than nothing.
14
+ next if defined?(RUBY_ENGINE) and RUBY_ENGINE == 'rbx'
15
+
16
+ require './spec/fixtures/person'
17
+
18
+ describe Ardm::Fixtures::Person do
19
+ before :each do
20
+ @resource = Ardm::Fixtures::Person.new(:name => 'Thomas Edison')
21
+ end
22
+
23
+ describe 'with positions indirectly mutated as a hash' do
24
+ before :each do
25
+ @resource.positions = {
26
+ 'company' => "Soon To Be Dirty, LLC",
27
+ 'title' => "Layperson",
28
+ 'details' => { 'awesome' => true },
29
+ }
30
+ @resource.save!
31
+ @resource.reload
32
+ @resource.positions['title'].should == 'Layperson'
33
+ end
34
+
35
+ describe "when I change positions" do
36
+ before :each do
37
+ @resource.changed?.should == false
38
+ @resource.positions['title'] = 'Chief Layer of People'
39
+ @resource.save!
40
+ @resource.reload
41
+ end
42
+
43
+ it "should remember the new position" do
44
+ @resource.positions['title'].should == 'Chief Layer of People'
45
+ end
46
+ end
47
+
48
+ describe "when I add a new attribute of the position" do
49
+ before :each do
50
+ @resource.changed?.should == false
51
+ @resource.positions['pays_buttloads_of_money'] = true
52
+ @resource.save!
53
+ @resource.reload
54
+ end
55
+
56
+ it "should remember the new attribute" do
57
+ @resource.positions['pays_buttloads_of_money'].should be_true
58
+ end
59
+ end
60
+
61
+ describe "when I change the details of the position" do
62
+ before :each do
63
+ @resource.changed?.should == false
64
+ @resource.positions['details'].merge!('awesome' => "VERY TRUE")
65
+ @resource.save!
66
+ @resource.reload
67
+ end
68
+
69
+ it "should remember the changed detail" do
70
+ # Works in active record (unless something is fooling me)
71
+ #pending "not supported (YET)" do
72
+ # TODO: Not supported (yet?) -- this is a much harder problem to
73
+ # solve: using mutating accessors of nested objects. We could
74
+ # detect it from #dirty? (using the #hash method), but #dirty?
75
+ # only returns the status of known-mutated properties (not full,
76
+ # on-demand scan of object dirty-ness).
77
+ @resource.positions['details']['awesome'].should == 'VERY TRUE'
78
+ #end
79
+ end
80
+ end
81
+
82
+ describe "when I reload the resource while the property is dirty" do
83
+ before :each do
84
+ @resource.positions['title'] = 'Chief Layer of People'
85
+ @resource.reload
86
+ end
87
+
88
+ it "should reflect the previously set/persisted value" do
89
+ @resource.positions.should_not be_nil
90
+ @resource.positions['title'].should == 'Layperson'
91
+ end
92
+ end
93
+
94
+ end # positions indirectly mutated as a hash
95
+
96
+ describe 'with positions indirectly mutated as an array' do
97
+ before :each do
98
+ @resource.positions = [
99
+ { 'company' => "Soon To Be Dirty, LLC",
100
+ 'title' => "Layperson",
101
+ 'details' => { 'awesome' => true },
102
+ },
103
+ ]
104
+ @resource.save!
105
+ @resource.reload
106
+ @resource.positions.first['title'].should == 'Layperson'
107
+ end
108
+
109
+ describe "when I remove the position" do
110
+ before :each do
111
+ @resource.changed?.should == false
112
+ @resource.positions.pop
113
+ @resource.save!
114
+ @resource.reload
115
+ end
116
+
117
+ it "should know there aren't any positions" do
118
+ @resource.positions.should == []
119
+ end
120
+ end
121
+
122
+ describe "when I add a new position" do
123
+ before :each do
124
+ @resource.changed?.should == false
125
+ @resource.positions << {
126
+ 'company' => "Down and Dirty, LP",
127
+ 'title' => "Porn Star",
128
+ 'details' => { 'awesome' => "also true" },
129
+ }
130
+ @resource.save!
131
+ @resource.reload
132
+ end
133
+
134
+ it "should know there's two positions" do
135
+ @resource.positions.length.should == 2
136
+ end
137
+
138
+ it "should know which position is which" do
139
+ @resource.positions.first['title'].should == "Layperson"
140
+ @resource.positions.last['title'].should == "Porn Star"
141
+ end
142
+
143
+ describe "when I change the details of one of the positions" do
144
+ before :each do
145
+ @resource.positions.last['details'].merge!('high_risk' => true)
146
+ @resource.save!
147
+ @resource.reload
148
+ end
149
+
150
+ it "should remember the changed detail" do
151
+ # Works in active record (unless something is fooling me)
152
+ #pending "not supported (YET)" do
153
+ # TODO: Not supported (yet?) -- this is a much harder problem to
154
+ # solve: using mutating accessors of nested objects. We could
155
+ # detect it from #dirty? (using the #hash method), but #dirty?
156
+ # only returns the status of known-mutated properties (not full,
157
+ # on-demand scan of object dirty-ness).
158
+ @resource.positions.last['details']['high_risk'].should == true
159
+ #end
160
+ end
161
+ end
162
+ end # when I add a new position
163
+
164
+ describe "when I remove the position with a block-based mutator" do
165
+ before :each do
166
+ @resource.changed?.should == false
167
+ @resource.positions.reject! { |_| true }
168
+ @resource.save!
169
+ @resource.reload
170
+ end
171
+
172
+ it "should know there aren't any positions" do
173
+ @resource.positions.should == []
174
+ end
175
+ end
176
+
177
+ describe "when I mutate positions through a reference" do
178
+ before :each do
179
+ @resource.changed?.should == false
180
+ @positions = @resource.positions
181
+ @positions << {
182
+ 'company' => "Ooga Booga, Inc",
183
+ 'title' => "Rocker",
184
+ }
185
+ end
186
+
187
+ it "should reflect the change in both the property and the reference" do
188
+ @resource.positions.length.should == 2
189
+ @resource.positions.last['title'].should == 'Rocker'
190
+ @positions.last['title'].should == 'Rocker'
191
+ end
192
+ end
193
+
194
+ end # positions indirectly mutated as an array
195
+
196
+ end
197
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ try_spec do
4
+
5
+ require './spec/fixtures/ticket'
6
+
7
+ describe Ardm::Fixtures::Ticket do
8
+ describe 'that is dumped and then loaded' do
9
+ before do
10
+ @resource = Ardm::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
+ )
16
+
17
+ @resource.save.should be_true
18
+ @resource.reload
19
+ end
20
+
21
+ it 'preserves property value' do
22
+ @resource.status.should == :confirmed
23
+ end
24
+ end
25
+
26
+ describe 'that is supplied a matching enumeration value' do
27
+ before do
28
+ @resource = Ardm::Fixtures::Ticket.new(:status => :assigned)
29
+ end
30
+
31
+ it 'typecasts it for outside reader' do
32
+ @resource.status.should == :assigned
33
+ end
34
+ end
35
+
36
+ describe '#get' do
37
+ before do
38
+ @resource = Ardm::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
46
+
47
+ it 'supports queries with equality operator on enumeration property' do
48
+ Ardm::Fixtures::Ticket.where(:status => :confirmed).
49
+ should include(@resource)
50
+ end
51
+
52
+ it 'supports queries with inequality operator on enumeration property' do
53
+ Ardm::Fixtures::Ticket.where.not(:status => :confirmed).
54
+ should_not include(@resource)
55
+ end
56
+ end
57
+
58
+ describe 'with value unknown to enumeration property' do
59
+ before do
60
+ @resource = Ardm::Fixtures::Ticket.new(:status => :undecided)
61
+ @resource.valid?
62
+ end
63
+
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
69
+
70
+ it 'has errors' do
71
+ @resource.errors.should_not be_empty
72
+ end
73
+
74
+ it 'has a meaningful error message on invalid property' do
75
+ @resource.errors[:status].should include('must be one of unconfirmed, confirmed, assigned, resolved, not_applicable')
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,59 @@
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 => '')
10
+ end
11
+
12
+ describe 'with a birthday' do
13
+ before do
14
+ @resource.birthday = '1983-05-03'
15
+ end
16
+
17
+ describe 'after typecasting string input' do
18
+ it 'has a valid birthday' do
19
+ @resource.birthday.should == ::Time.parse('1983-05-03')
20
+ end
21
+ end
22
+
23
+ describe 'when dumped and loaded again' do
24
+ before do
25
+ @resource.save.should be_true
26
+ @resource.reload
27
+ end
28
+
29
+ it 'has a valid birthday' do
30
+ @resource.birthday.should == ::Time.parse('1983-05-03')
31
+ end
32
+ end
33
+ end
34
+
35
+ describe 'without a birthday' do
36
+ before do
37
+ @resource.birthday = nil
38
+ end
39
+
40
+ describe 'after typecasting nil' do
41
+ it 'has a nil value for birthday' do
42
+ @resource.birthday.should be_nil
43
+ end
44
+ end
45
+
46
+ describe 'when dumped and loaded again' do
47
+ before do
48
+ @resource.save.should be_true
49
+ @resource.reload
50
+ end
51
+
52
+ it 'has a nil value for birthday' do
53
+ @resource.birthday.should be_nil
54
+ end
55
+ end
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,158 @@
1
+ require 'spec_helper'
2
+
3
+ try_spec do
4
+
5
+ require './spec/fixtures/software_package'
6
+
7
+ describe Ardm::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 do
10
+ @source_path = '/var/cache/apt/archives/linux-libc-dev_2.6.28-11.40_i386.deb'
11
+ @resource = Ardm::Fixtures::SoftwarePackage.new(:source_path => @source_path)
12
+ end
13
+
14
+ describe 'when is a new record' do
15
+ before do
16
+ end
17
+
18
+ it 'points to original path' do
19
+ @resource.source_path.to_s.should == @source_path
20
+ end
21
+
22
+ it 'responds to :directory?' do
23
+ @resource.source_path.should respond_to(:directory?)
24
+ end
25
+
26
+ it 'responds to :file?' do
27
+ @resource.source_path.should respond_to(:file?)
28
+ end
29
+
30
+ it 'responds to :dirname' do
31
+ @resource.source_path.should respond_to(:dirname)
32
+ end
33
+
34
+ it 'responds to :absolute?' do
35
+ @resource.source_path.should respond_to(:absolute?)
36
+ end
37
+
38
+ it 'responds to :readable?' do
39
+ @resource.source_path.should respond_to(:readable?)
40
+ end
41
+
42
+ it 'responds to :size' do
43
+ @resource.source_path.should respond_to(:size)
44
+ end
45
+ end
46
+ end
47
+
48
+ describe 'with destination path at /usr/local' do
49
+ before do
50
+ @destination_path = '/usr/local'
51
+ @resource = Ardm::Fixtures::SoftwarePackage.new(:destination_path => @destination_path)
52
+ end
53
+
54
+ describe 'when saved and reloaded' do
55
+ before do
56
+ @resource.save.should be_true
57
+ @resource.reload
58
+ end
59
+
60
+ it 'points to original path' do
61
+ @resource.destination_path.to_s.should == @destination_path
62
+ end
63
+
64
+ it 'responds to :directory?' do
65
+ @resource.destination_path.should respond_to(:directory?)
66
+ end
67
+
68
+ it 'responds to :file?' do
69
+ @resource.destination_path.should respond_to(:file?)
70
+ end
71
+
72
+ it 'responds to :dirname' do
73
+ @resource.destination_path.should respond_to(:dirname)
74
+ end
75
+
76
+ it 'responds to :absolute?' do
77
+ @resource.destination_path.should respond_to(:absolute?)
78
+ end
79
+
80
+ it 'responds to :readable?' do
81
+ @resource.destination_path.should respond_to(:readable?)
82
+ end
83
+
84
+ it 'responds to :size' do
85
+ @resource.destination_path.should respond_to(:size)
86
+ end
87
+ end
88
+ end
89
+
90
+ describe 'with no (nil) source path' do
91
+ before do
92
+ @source_path = nil
93
+ @resource = Ardm::Fixtures::SoftwarePackage.new(:source_path => @source_path)
94
+ end
95
+
96
+ describe 'when saved and reloaded' do
97
+ before do
98
+ @resource.save.should be_true
99
+ @resource.reload
100
+ end
101
+
102
+ it 'has nil source path' do
103
+ @resource.source_path.should be_nil
104
+ end
105
+ end
106
+ end
107
+
108
+ describe 'with a blank source path' do
109
+ before do
110
+ @source_path = ''
111
+ @resource = Ardm::Fixtures::SoftwarePackage.new(:source_path => @source_path)
112
+ end
113
+
114
+ describe 'when saved and reloaded' do
115
+ before do
116
+ @resource.save.should be_true
117
+ @resource.reload
118
+ end
119
+
120
+ it 'has nil source path' do
121
+ @resource.source_path.should be_nil
122
+ end
123
+ end
124
+ end
125
+
126
+ describe 'with a source path assigned to an empty array' do
127
+ before do
128
+ @source_path = []
129
+ @resource = Ardm::Fixtures::SoftwarePackage.new(:source_path => @source_path)
130
+ end
131
+
132
+ describe 'when saved and reloaded' do
133
+ before do
134
+ @resource.save.should be_true
135
+ @resource.reload
136
+ end
137
+
138
+ it 'has nil source path' do
139
+ @resource.source_path.should be_nil
140
+ end
141
+ end
142
+ end
143
+
144
+ describe 'with a source path assigned to a Hash' do
145
+ before do
146
+ @source_path = { :guitar => 'Joe Satriani' }
147
+ end
148
+
149
+ describe 'when instantiated' do
150
+ it 'raises an exception' do
151
+ lambda do
152
+ Ardm::Fixtures::SoftwarePackage.new(:source_path => @source_path)
153
+ end.should raise_error(TypeError)
154
+ end
155
+ end
156
+ end
157
+ end
158
+ end
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ try_spec do
4
+
5
+ require './spec/fixtures/tshirt'
6
+
7
+ describe Ardm::Fixtures::TShirt do
8
+ before do
9
+ @resource = Ardm::Fixtures::TShirt.new(
10
+ :writing => 'Fork you',
11
+ :has_picture => true,
12
+ :picture => :octocat,
13
+ :color => :white
14
+ )
15
+ end
16
+
17
+ describe 'with the default value' do
18
+ it 'returns it as an array' do
19
+ pending "FIXME: This probably should pass" do
20
+ @resource.size.should eq([Ardm::Fixtures::TShirt.properties[:size].default])
21
+ end
22
+ end
23
+ end
24
+
25
+ describe 'with multiple sizes' do
26
+ describe 'dumped and loaded' do
27
+ before do
28
+ @resource.size = [ :xs, :medium ]
29
+ @resource.save.should be_true
30
+ @resource.reload
31
+ end
32
+
33
+ it 'returns size as array' do
34
+ @resource.size.should == [ :xs, :medium ]
35
+ end
36
+ end
37
+ end
38
+
39
+ describe 'with a single size' do
40
+ before do
41
+ @resource.size = :large
42
+ end
43
+
44
+ describe 'dumped and loaded' do
45
+ before do
46
+ @resource.save.should be_true
47
+ @resource.reload
48
+ end
49
+
50
+ it 'returns size as array with a single value' do
51
+ @resource.size.should == [:large]
52
+ end
53
+ end
54
+ end
55
+
56
+ # Flag does not add any auto validations
57
+ describe 'without size' do
58
+ before do
59
+ @resource.should be_valid
60
+ @resource.size = nil
61
+ end
62
+
63
+ it 'is valid' do
64
+ @resource.should be_valid
65
+ end
66
+
67
+ it 'has no errors' do
68
+ @resource.errors.should be_empty
69
+ end
70
+ end
71
+ end
72
+ end