static_model 0.1.4 → 0.1.5

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.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ == 0.1.5 2008-09-18
2
+
3
+ * 1 minor enhancement
4
+
5
+ * better handling of empty YAML files (ienders)
6
+
1
7
  == 0.1.0 2008-08-27
2
8
 
3
9
  * 1 minor enchancement
@@ -74,7 +74,7 @@ module StaticModel
74
74
  return if loaded? && !reload
75
75
  raise(StaticModel::DataFileNotFound, "You must set a data file to load from") unless File.readable?(data_file)
76
76
  records = YAML::load_file(data_file)
77
- @records = records.dup.collect {|r| new(r) }
77
+ @records = records ? records.dup.collect {|r| new(r) } : []
78
78
  @loaded = true
79
79
  end
80
80
 
@@ -141,4 +141,4 @@ module StaticModel
141
141
  end
142
142
 
143
143
  end
144
- end
144
+ end
@@ -2,7 +2,7 @@ module StaticModel #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 4
5
+ TINY = 5
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -40,17 +40,17 @@ class TestStaticModel < Test::Unit::TestCase
40
40
  assert_equal @book.inspect, @book.to_s
41
41
  end
42
42
  end
43
-
43
+
44
44
  context "comparing" do
45
-
45
+
46
46
  should "be equal to an instance of the same class with same id" do
47
47
  assert_equal @book, Book.new(book_params)
48
48
  end
49
-
49
+
50
50
  should "not be equal to an instance with the same class with different ids" do
51
51
  assert_not_equal Book[1], @book
52
52
  end
53
-
53
+
54
54
  should "not be equal to an instance with different classes and the same ids" do
55
55
  assert_not_equal Book[1], Author[1]
56
56
  end
@@ -61,7 +61,7 @@ class TestStaticModel < Test::Unit::TestCase
61
61
  context "on the class" do
62
62
  context "set data file" do
63
63
  context "After the class is defined" do
64
-
64
+
65
65
  setup do
66
66
  @book = Book.find(1)
67
67
  @author = Author.find(1)
@@ -70,21 +70,21 @@ class TestStaticModel < Test::Unit::TestCase
70
70
  Book.set_data_file @data_file
71
71
  @new_book = Book.find(1)
72
72
  end
73
-
73
+
74
74
  should "set the @data_file" do
75
75
  assert_equal @data_file, Book.data_file
76
76
  end
77
-
77
+
78
78
  should "reload with next find" do
79
79
  assert @author.attributes, @new_book.attributes
80
80
  end
81
-
81
+
82
82
  teardown do
83
83
  Book.set_data_file @original_data_file
84
84
  end
85
85
  end
86
86
  end
87
-
87
+
88
88
  context "find" do
89
89
 
90
90
  context "with an integer" do
@@ -172,6 +172,23 @@ class TestStaticModel < Test::Unit::TestCase
172
172
  assert book.is_a?(Book)
173
173
  end
174
174
  end
175
+
176
+ context "with an empty data file" do
177
+ setup do
178
+ @original_data_file = Book.data_file
179
+ @data_file = File.join(File.dirname(__FILE__), 'empty.yml')
180
+ Book.set_data_file @data_file
181
+ end
182
+
183
+ should "return an empty array" do
184
+ assert_equal [], Book.find_all
185
+ end
186
+
187
+ teardown do
188
+ Book.set_data_file @original_data_file
189
+ end
190
+
191
+ end
175
192
  end
176
193
 
177
194
  context "find_first_by" do
@@ -194,7 +211,7 @@ class TestStaticModel < Test::Unit::TestCase
194
211
  end
195
212
  end
196
213
  end
197
-
214
+
198
215
  context "find_by" do
199
216
  setup do
200
217
  @author = 'Michael Pollan'
@@ -214,7 +231,7 @@ class TestStaticModel < Test::Unit::TestCase
214
231
  assert_nil Book.find_by(:author,'Aaron Quint')
215
232
  end
216
233
  end
217
-
234
+
218
235
  end
219
236
 
220
237
  context "find_all_by" do
@@ -247,21 +264,29 @@ class TestStaticModel < Test::Unit::TestCase
247
264
  end
248
265
  end
249
266
 
250
- context "find_by_*attribute*" do
251
- should "be equivalent to find_first_by(attribute,)" do
252
- assert_equal Book.find_by(:genre, 'Non-Fiction'), Book.find_first_by_genre('Non-Fiction')
267
+ context "dynamic finders" do
268
+ setup do
269
+ @book = Book.first
253
270
  end
254
- end
255
271
 
256
- context "find_first_by_*attribute*" do
257
- should "be equivalent to find_first_by(attribute,)" do
258
- assert_equal Book.find_first_by(:genre, 'Non-Fiction'), Book.find_first_by_genre('Non-Fiction')
272
+ context "find_by_*attribute*" do
273
+ should "be equivalent to find_first_by(attribute,)" do
274
+ assert_equal @book, Book.find_first_by(:genre, 'Non-Fiction')
275
+ assert_equal Book.find_first_by(:genre, 'Non-Fiction'), Book.find_by_genre('Non-Fiction')
276
+ end
277
+ end
278
+
279
+ context "find_first_by_*attribute*" do
280
+ should "be equivalent to find_first_by(attribute,)" do
281
+ assert_equal @book, Book.find_first_by(:genre, 'Non-Fiction')
282
+ assert_equal Book.find_first_by(:genre, 'Non-Fiction'), Book.find_first_by_genre('Non-Fiction')
283
+ end
259
284
  end
260
- end
261
285
 
262
- context "find_all_by_*attribute*" do
263
- should "be equivalent to find_all_by(attribute,)" do
264
- assert_equal Book.find_all_by(:genre, 'Non-Fiction'), Book.find_all_by_genre('Non-Fiction')
286
+ context "find_all_by_*attribute*" do
287
+ should "be equivalent to find_all_by(attribute,)" do
288
+ assert_equal Book.find_all_by(:genre, 'Non-Fiction'), Book.find_all_by_genre('Non-Fiction')
289
+ end
265
290
  end
266
291
  end
267
292
 
@@ -279,6 +304,6 @@ class TestStaticModel < Test::Unit::TestCase
279
304
  def book_params
280
305
  {:id => 15, :title => 'Lord of the Rings', :author => 'J.R. Tolkien', :genre => 'Fantasy'}
281
306
  end
282
-
283
307
 
284
- end
308
+
309
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: static_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Quint
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-27 00:00:00 -04:00
12
+ date: 2008-09-18 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency