dirt-core 2.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. data/Gemfile +8 -0
  2. data/Gemfile.lock +46 -0
  3. data/MIT-LICENSE +23 -0
  4. data/README +14 -0
  5. data/doc/BlockValidator.html +272 -0
  6. data/doc/ClosureValidator.html +276 -0
  7. data/doc/Dirt.html +158 -0
  8. data/doc/Dirt/FooBar.html +167 -0
  9. data/doc/Dirt/HerpZerp.html +161 -0
  10. data/doc/Dirt/HerpZerp/DerpGerp.html +161 -0
  11. data/doc/Dirt/HerpZerp/DerpGerp/FooBar.html +167 -0
  12. data/doc/Dirt/MemoryPersister.html +453 -0
  13. data/doc/Dirt/MemoryRecord.html +157 -0
  14. data/doc/Dirt/MissingRecordError.html +157 -0
  15. data/doc/Dirt/Model.html +320 -0
  16. data/doc/Dirt/NoPersisterError.html +157 -0
  17. data/doc/Dirt/Relation.html +338 -0
  18. data/doc/Dirt/Role.html +345 -0
  19. data/doc/Dirt/TooManyRecordsError.html +157 -0
  20. data/doc/Dirt/TransactionError.html +157 -0
  21. data/doc/ExistenceValidator.html +316 -0
  22. data/doc/FooBar.html +153 -0
  23. data/doc/Gemfile.html +131 -0
  24. data/doc/HerpZerp.html +147 -0
  25. data/doc/HerpZerp/DerpGerp.html +147 -0
  26. data/doc/HerpZerp/DerpGerp/FooBar.html +153 -0
  27. data/doc/Persister.html +311 -0
  28. data/doc/Persisting.html +413 -0
  29. data/doc/PresenceValidator.html +281 -0
  30. data/doc/README.html +132 -0
  31. data/doc/Role.html +309 -0
  32. data/doc/Scheduler.html +147 -0
  33. data/doc/SelfExistenceValidator.html +278 -0
  34. data/doc/TestPersister.html +411 -0
  35. data/doc/Validating.html +293 -0
  36. data/doc/created.rid +18 -0
  37. data/doc/images/add.png +0 -0
  38. data/doc/images/brick.png +0 -0
  39. data/doc/images/brick_link.png +0 -0
  40. data/doc/images/bug.png +0 -0
  41. data/doc/images/bullet_black.png +0 -0
  42. data/doc/images/bullet_toggle_minus.png +0 -0
  43. data/doc/images/bullet_toggle_plus.png +0 -0
  44. data/doc/images/date.png +0 -0
  45. data/doc/images/delete.png +0 -0
  46. data/doc/images/find.png +0 -0
  47. data/doc/images/loadingAnimation.gif +0 -0
  48. data/doc/images/macFFBgHack.png +0 -0
  49. data/doc/images/package.png +0 -0
  50. data/doc/images/page_green.png +0 -0
  51. data/doc/images/page_white_text.png +0 -0
  52. data/doc/images/page_white_width.png +0 -0
  53. data/doc/images/plugin.png +0 -0
  54. data/doc/images/ruby.png +0 -0
  55. data/doc/images/tag_blue.png +0 -0
  56. data/doc/images/tag_green.png +0 -0
  57. data/doc/images/transparent.png +0 -0
  58. data/doc/images/wrench.png +0 -0
  59. data/doc/images/wrench_orange.png +0 -0
  60. data/doc/images/zoom.png +0 -0
  61. data/doc/index.html +110 -0
  62. data/doc/js/darkfish.js +155 -0
  63. data/doc/js/jquery.js +18 -0
  64. data/doc/js/navigation.js +142 -0
  65. data/doc/js/search.js +94 -0
  66. data/doc/js/search_index.js +1 -0
  67. data/doc/js/searcher.js +228 -0
  68. data/doc/rdoc.css +543 -0
  69. data/doc/table_of_contents.html +203 -0
  70. data/lib/dirt/bdd/matchers.rb +10 -0
  71. data/lib/dirt/bdd/persister_spec_helper.rb +213 -0
  72. data/lib/dirt/bdd/shared_examples.rb +29 -0
  73. data/lib/dirt/contexts/context.rb +15 -0
  74. data/lib/dirt/core.rb +36 -0
  75. data/lib/dirt/errors/missing_record_error.rb +4 -0
  76. data/lib/dirt/errors/no_persister_error.rb +4 -0
  77. data/lib/dirt/errors/too_many_records_error.rb +4 -0
  78. data/lib/dirt/errors/transaction_error.rb +4 -0
  79. data/lib/dirt/models/model_behaviour.rb +47 -0
  80. data/lib/dirt/persisters/memory_persister.rb +86 -0
  81. data/lib/dirt/persisters/persister.rb +54 -0
  82. data/lib/dirt/persisters/relation.rb +38 -0
  83. data/lib/dirt/roles/persisting.rb +73 -0
  84. data/lib/dirt/roles/role.rb +32 -0
  85. data/lib/dirt/roles/validating.rb +27 -0
  86. data/lib/dirt/roles/validation/closure_validator.rb +15 -0
  87. data/lib/dirt/roles/validation/existence_validator.rb +53 -0
  88. data/lib/dirt/roles/validation/presence_validator.rb +21 -0
  89. data/lib/dirt/roles/validation/self_existence_validator.rb +18 -0
  90. data/spec/isolations/closure_validator_spec.rb +57 -0
  91. data/spec/isolations/context_spec.rb +54 -0
  92. data/spec/isolations/existence_validator_spec.rb +151 -0
  93. data/spec/isolations/memory_persister_spec.rb +175 -0
  94. data/spec/isolations/model_spec.rb +91 -0
  95. data/spec/isolations/persister_spec.rb +113 -0
  96. data/spec/isolations/persisting_spec.rb +266 -0
  97. data/spec/isolations/presence_validator_spec.rb +63 -0
  98. data/spec/isolations/role_spec.rb +116 -0
  99. data/spec/isolations/self_existence_validator_spec.rb +64 -0
  100. data/spec/isolations/spec_helper.rb +26 -0
  101. data/spec/isolations/validating_spec.rb +88 -0
  102. metadata +161 -0
@@ -0,0 +1,203 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
6
+
7
+ <title>Table of Contents - RDoc Documentation</title>
8
+
9
+ <link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet">
10
+
11
+ <script type="text/javascript">
12
+ var rdoc_rel_prefix = "./";
13
+ </script>
14
+
15
+ <script type="text/javascript" charset="utf-8" src="./js/jquery.js"></script>
16
+ <script type="text/javascript" charset="utf-8" src="./js/navigation.js"></script>
17
+ <script type="text/javascript" charset="utf-8" src="./js/search_index.js"></script>
18
+ <script type="text/javascript" charset="utf-8" src="./js/search.js"></script>
19
+ <script type="text/javascript" charset="utf-8" src="./js/searcher.js"></script>
20
+ <script type="text/javascript" charset="utf-8" src="./js/darkfish.js"></script>
21
+
22
+
23
+ <body class="indexpage">
24
+ <h1>Table of Contents - RDoc Documentation</h1>
25
+
26
+ <h2>Pages</h2>
27
+ <ul>
28
+ <li class="file">
29
+ <a href="README.html">README</a>
30
+ </li>
31
+
32
+ </ul>
33
+
34
+ <h2 id="classes">Classes/Modules</h2>
35
+ <ul>
36
+ <li class="module">
37
+ <a href="Dirt.html">Dirt</a>
38
+ </li>
39
+ <li class="class">
40
+ <a href="Dirt/MemoryPersister.html">Dirt::MemoryPersister</a>
41
+ </li>
42
+ <li class="class">
43
+ <a href="Dirt/MemoryRecord.html">Dirt::MemoryRecord</a>
44
+ </li>
45
+ <li class="class">
46
+ <a href="Dirt/MissingRecordError.html">Dirt::MissingRecordError</a>
47
+ </li>
48
+ <li class="class">
49
+ <a href="Dirt/Model.html">Dirt::Model</a>
50
+ </li>
51
+ <li class="class">
52
+ <a href="Dirt/NoPersisterError.html">Dirt::NoPersisterError</a>
53
+ </li>
54
+ <li class="class">
55
+ <a href="Dirt/Relation.html">Dirt::Relation</a>
56
+ </li>
57
+ <li class="class">
58
+ <a href="Dirt/Role.html">Dirt::Role</a>
59
+ </li>
60
+ <li class="class">
61
+ <a href="Dirt/TooManyRecordsError.html">Dirt::TooManyRecordsError</a>
62
+ </li>
63
+ <li class="class">
64
+ <a href="Dirt/TransactionError.html">Dirt::TransactionError</a>
65
+ </li>
66
+ <li class="class">
67
+ <a href="ClosureValidator.html">ClosureValidator</a>
68
+ </li>
69
+ <li class="class">
70
+ <a href="ExistenceValidator.html">ExistenceValidator</a>
71
+ </li>
72
+ <li class="class">
73
+ <a href="Persister.html">Persister</a>
74
+
75
+ <img class="toc-toggle" src="images/transparent.png" alt="" title="toggle headings">
76
+ <ul class="initially-hidden">
77
+ <li><a href="Persister.html#label-Persisters">Persisters</a>
78
+ </ul>
79
+ </li>
80
+ <li class="class">
81
+ <a href="Persisting.html">Persisting</a>
82
+ </li>
83
+ <li class="class">
84
+ <a href="PresenceValidator.html">PresenceValidator</a>
85
+ </li>
86
+ <li class="class">
87
+ <a href="SelfExistenceValidator.html">SelfExistenceValidator</a>
88
+ </li>
89
+ <li class="class">
90
+ <a href="Validating.html">Validating</a>
91
+
92
+ <img class="toc-toggle" src="images/transparent.png" alt="" title="toggle headings">
93
+ <ul class="initially-hidden">
94
+ <li><a href="Validating.html#label-Validators">Validators</a>
95
+ </ul>
96
+ </li>
97
+
98
+ </ul>
99
+
100
+ <h2 id="methods">Methods</h2>
101
+ <ul>
102
+
103
+ <li class="method"><a href="Persister.html#method-c-clear">::clear &mdash; Persister</a>
104
+
105
+ <li class="method"><a href="Persister.html#method-c-for">::for &mdash; Persister</a>
106
+
107
+ <li class="method"><a href="Validating.html#method-c-new">::new &mdash; Validating</a>
108
+
109
+ <li class="method"><a href="Dirt/Relation.html#method-c-new">::new &mdash; Dirt::Relation</a>
110
+
111
+ <li class="method"><a href="Dirt/MemoryPersister.html#method-c-new">::new &mdash; Dirt::MemoryPersister</a>
112
+
113
+ <li class="method"><a href="Dirt/Model.html#method-c-new">::new &mdash; Dirt::Model</a>
114
+
115
+ <li class="method"><a href="Persisting.html#method-c-new">::new &mdash; Persisting</a>
116
+
117
+ <li class="method"><a href="SelfExistenceValidator.html#method-c-new">::new &mdash; SelfExistenceValidator</a>
118
+
119
+ <li class="method"><a href="Dirt/Role.html#method-c-new">::new &mdash; Dirt::Role</a>
120
+
121
+ <li class="method"><a href="ClosureValidator.html#method-c-new">::new &mdash; ClosureValidator</a>
122
+
123
+ <li class="method"><a href="PresenceValidator.html#method-c-new">::new &mdash; PresenceValidator</a>
124
+
125
+ <li class="method"><a href="ExistenceValidator.html#method-c-new">::new &mdash; ExistenceValidator</a>
126
+
127
+ <li class="method"><a href="Persister.html#method-c-transaction">::transaction &mdash; Persister</a>
128
+
129
+ <li class="method"><a href="Dirt/Model.html#method-i-3D-3D">#== &mdash; Dirt::Model</a>
130
+
131
+ <li class="method"><a href="Persisting.html#method-i-3D-3D">#== &mdash; Persisting</a>
132
+
133
+ <li class="method"><a href="Dirt/Role.html#method-i-3D-3D">#== &mdash; Dirt::Role</a>
134
+
135
+ <li class="method"><a href="Dirt/MemoryPersister.html#method-i-all">#all &mdash; Dirt::MemoryPersister</a>
136
+
137
+ <li class="method"><a href="Dirt/Role.html#method-i-class">#class &mdash; Dirt::Role</a>
138
+
139
+ <li class="method"><a href="Dirt/Relation.html#method-i-collect">#collect &mdash; Dirt::Relation</a>
140
+
141
+ <li class="method"><a href="Persisting.html#method-i-delete">#delete &mdash; Persisting</a>
142
+
143
+ <li class="method"><a href="Dirt/MemoryPersister.html#method-i-delete">#delete &mdash; Dirt::MemoryPersister</a>
144
+
145
+ <li class="method"><a href="Dirt/Relation.html#method-i-each">#each &mdash; Dirt::Relation</a>
146
+
147
+ <li class="method"><a href="Dirt/Relation.html#method-i-empty-3F">#empty? &mdash; Dirt::Relation</a>
148
+
149
+ <li class="method"><a href="SelfExistenceValidator.html#method-i-error_message">#error_message &mdash; SelfExistenceValidator</a>
150
+
151
+ <li class="method"><a href="PresenceValidator.html#method-i-error_message">#error_message &mdash; PresenceValidator</a>
152
+
153
+ <li class="method"><a href="ClosureValidator.html#method-i-error_message">#error_message &mdash; ClosureValidator</a>
154
+
155
+ <li class="method"><a href="ExistenceValidator.html#method-i-error_message">#error_message &mdash; ExistenceValidator</a>
156
+
157
+ <li class="method"><a href="Validating.html#method-i-errors">#errors &mdash; Validating</a>
158
+
159
+ <li class="method"><a href="Dirt/MemoryPersister.html#method-i-exists-3F">#exists? &mdash; Dirt::MemoryPersister</a>
160
+
161
+ <li class="method"><a href="Dirt/MemoryPersister.html#method-i-find">#find &mdash; Dirt::MemoryPersister</a>
162
+
163
+ <li class="method"><a href="Dirt/Relation.html#method-i-first">#first &mdash; Dirt::Relation</a>
164
+
165
+ <li class="method"><a href="Dirt/MemoryPersister.html#method-i-load">#load &mdash; Dirt::MemoryPersister</a>
166
+
167
+ <li class="method"><a href="Persisting.html#method-i-load">#load &mdash; Persisting</a>
168
+
169
+ <li class="method"><a href="Persisting.html#method-i-load_by">#load_by &mdash; Persisting</a>
170
+
171
+ <li class="method"><a href="Dirt/Role.html#method-i-method_missing">#method_missing &mdash; Dirt::Role</a>
172
+
173
+ <li class="method"><a href="Dirt/Role.html#method-i-respond_to-3F">#respond_to? &mdash; Dirt::Role</a>
174
+
175
+ <li class="method"><a href="Persisting.html#method-i-save">#save &mdash; Persisting</a>
176
+
177
+ <li class="method"><a href="Dirt/MemoryPersister.html#method-i-save">#save &mdash; Dirt::MemoryPersister</a>
178
+
179
+ <li class="method"><a href="Dirt/Model.html#method-i-to_hash">#to_hash &mdash; Dirt::Model</a>
180
+
181
+ <li class="method"><a href="Dirt/Model.html#method-i-update">#update &mdash; Dirt::Model</a>
182
+
183
+ <li class="method"><a href="ClosureValidator.html#method-i-valid-3F">#valid? &mdash; ClosureValidator</a>
184
+
185
+ <li class="method"><a href="SelfExistenceValidator.html#method-i-valid-3F">#valid? &mdash; SelfExistenceValidator</a>
186
+
187
+ <li class="method"><a href="ExistenceValidator.html#method-i-valid-3F">#valid? &mdash; ExistenceValidator</a>
188
+
189
+ <li class="method"><a href="PresenceValidator.html#method-i-valid-3F">#valid? &mdash; PresenceValidator</a>
190
+
191
+ <li class="method"><a href="Validating.html#method-i-valid-3F">#valid? &mdash; Validating</a>
192
+
193
+ <li class="method"><a href="Dirt/MemoryPersister.html#method-i-where">#where &mdash; Dirt::MemoryPersister</a>
194
+
195
+ </ul>
196
+
197
+
198
+ <footer id="validator-badges">
199
+ <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
200
+ <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.12.2.
201
+ <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
202
+ </footer>
203
+
@@ -0,0 +1,10 @@
1
+ RSpec::Matchers.define :data_matches do |expected|
2
+ match do |actual|
3
+ expected.keys.each do |key|
4
+ unless expected[key] == actual.send(key)
5
+ return false
6
+ end
7
+ end
8
+ true
9
+ end
10
+ end
@@ -0,0 +1,213 @@
1
+ # To use Persister shared examples, supply +it_behaves_like(:persister)+ with:
2
+ # * +:persisted+ - An instance to be saved to the persister that matches +where_params+
3
+ # * +:persisted2+ - An instance to be saved to the persister that matches +where_params+
4
+ # * +:different_persisted+ - An instance to be saved to the persister that does *not* match +where_params+
5
+ # * +:where_params+ - The parameter hash given to #where()
6
+ #
7
+ # using, for example, the block syntax
8
+ shared_examples_for(:persister) do
9
+ describe '#new' do
10
+ context 'no args' do
11
+ it 'should return a non-nil' do
12
+ subject.new.should_not be_nil
13
+ end
14
+ end
15
+
16
+ context 'some args' do
17
+ before(:each) do
18
+ @new_obj = subject.new(where_params)
19
+ end
20
+ it 'should populate each parameter' do
21
+ where_params.each do |key, val|
22
+ @new_obj.send(key).should == val
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ describe '#save' do
29
+ context 'one arg' do
30
+ it { should respond_to(:save).with(1).arguments }
31
+
32
+ it 'should return an object with an id' do
33
+ subject.save(persisted).should respond_to(:id)
34
+ end
35
+ end
36
+
37
+ context 'specific id' do
38
+ it { should respond_to(:save).with(2).arguments }
39
+
40
+ context 'it pre-exists' do
41
+ let(:id) { subject.save(persisted).id }
42
+
43
+ it 'should return an object with an id' do
44
+ subject.save(persisted, id).should respond_to(:id)
45
+ end
46
+
47
+ it 'should return an object that can to_hash' do
48
+ subject.save(persisted, id).should respond_to(:to_hash)
49
+ end
50
+ end
51
+
52
+ context 'it does not exist' do
53
+ let(:id) { 1 }
54
+
55
+ it 'should raise an error' do
56
+ expect { subject.save(persisted, id) }.to raise_error(Dirt::MissingRecordError, "That #{persisted.class.to_s.demodulize} (id: 1) does not exist.")
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ describe '#load' do
63
+ context 'it exists' do
64
+ let(:id) { subject.save(persisted).id }
65
+
66
+ it { should respond_to(:load).with(1).argument }
67
+
68
+ it 'should return an object with an id' do
69
+ subject.load(id).should respond_to(:id)
70
+ end
71
+
72
+ it 'should return an object that can to_hash' do
73
+ subject.load(id).should respond_to(:to_hash)
74
+ end
75
+ end
76
+
77
+ context 'it does not exist' do
78
+ let(:id) { 1 }
79
+
80
+ it 'should raise an error' do
81
+ expect { subject.load(id) }.to raise_error(Dirt::MissingRecordError, "That #{persisted.class.to_s.demodulize} (id: #{id}) does not exist.")
82
+ end
83
+ end
84
+ end
85
+
86
+ describe '#delete' do
87
+ it { should respond_to(:delete).with(1).argument }
88
+
89
+ context 'exists' do
90
+ let(:id) { subject.save(persisted).id }
91
+
92
+ it 'should return true' do
93
+ subject.delete(id).should == OpenStruct.new(persisted.to_hash.merge(id: id))
94
+ end
95
+ end
96
+
97
+ context 'does not exist' do
98
+ let(:id) { 1 }
99
+
100
+ it 'should return false' do
101
+ subject.delete(id).should be nil
102
+ end
103
+ end
104
+ end
105
+
106
+ describe '#exists?' do
107
+ it { should respond_to(:exists?) }
108
+
109
+ context 'it does' do
110
+ let(:id) { subject.save(persisted).id }
111
+
112
+ it 'should return true' do
113
+ subject.exists?(id).should == true
114
+ end
115
+ end
116
+
117
+ context 'it does not' do
118
+ let(:id) { 1 }
119
+
120
+ it 'should return true' do
121
+ subject.exists?(id).should == false
122
+ end
123
+ end
124
+ end
125
+
126
+ describe '#all' do
127
+ it { should respond_to(:all) }
128
+
129
+ before(:each) do
130
+ subject.save(persisted)
131
+ subject.save(persisted2)
132
+ end
133
+
134
+ it 'should return an array' do
135
+ subject.all.should be_a Array
136
+ end
137
+
138
+ it 'should return all objects' do
139
+ subject.all.size.should == 2
140
+ end
141
+
142
+ it 'should return an array of id-having objects' do
143
+ subject.all.each { |o| o.should respond_to(:id) }
144
+ end
145
+
146
+ it 'should return an array of to_hash-capable objects' do
147
+ subject.all.each { |o| o.should respond_to(:to_hash) }
148
+ end
149
+ end
150
+
151
+ describe '#where' do
152
+ before(:each) do
153
+ @id_match1 = subject.save(persisted).id
154
+ subject.save(different_persisted)
155
+ @id_match2 = subject.save(persisted2).id
156
+ end
157
+
158
+ it { should respond_to(:where).with(1).argument }
159
+
160
+ it 'should return only matching results' do
161
+ all = subject.where(where_params).all? do |data|
162
+ where_params.all? { |key, value| data.send(key) == value }
163
+ end
164
+
165
+ all.should be_true
166
+ end
167
+
168
+ it 'should the correct matching results' do
169
+ subject.where(where_params).collect do |record|
170
+ record.id
171
+ end.should == [@id_match1, @id_match2]
172
+ end
173
+
174
+ describe 'relation returned' do
175
+ let(:relation) { subject.where(where_params) }
176
+
177
+ # This is true of ActiveRecord relations, but not of DataMapper collections.
178
+ # it 'should respond to where' do
179
+ # relation.should respond_to(:where)
180
+ # end
181
+
182
+ it 'should respond to first' do
183
+ relation.should respond_to(:first)
184
+ end
185
+
186
+ it 'should respond to all?' do
187
+ relation.should respond_to(:all?)
188
+ end
189
+ end
190
+ end
191
+
192
+ describe '#find' do
193
+ before(:each) do
194
+ subject.save(different_persisted)
195
+ @id = subject.save(persisted).id
196
+ subject.save(persisted2)
197
+ end
198
+
199
+ it { should respond_to(:find).with(1).argument }
200
+
201
+ it 'should return an object with an id' do
202
+ subject.find(where_params).should respond_to(:id)
203
+ end
204
+
205
+ it 'should return an object that can to_hash' do
206
+ subject.find(where_params).should respond_to(:to_hash)
207
+ end
208
+
209
+ it 'should return the first matching result' do
210
+ subject.find(where_params).id.should == @id
211
+ end
212
+ end
213
+ end
@@ -0,0 +1,29 @@
1
+ shared_examples_for(:returning) do
2
+ it "should return the appropriate messages" do
3
+ actual_msgs = command[:messages]
4
+
5
+ if msgs.nil? || msgs.empty?
6
+ actual_msgs.should be_nil
7
+ else
8
+ actual_msgs.should_not be_nil
9
+
10
+ msgs.each do |msg|
11
+ actual_msgs.should include msg
12
+ end
13
+ end
14
+ end
15
+
16
+ it "should return the appropriate errors" do
17
+ actual_errors = command[:errors]
18
+
19
+ if errors.nil?
20
+ actual_errors.should be_nil
21
+ else
22
+ actual_errors.should_not be_nil
23
+
24
+ errors.each do |error|
25
+ actual_errors.should include error
26
+ end
27
+ end
28
+ end
29
+ end