Commit 39cac09889c7d35516412e722d07622b6107e1be

Authored by Georg GH. Hopp
Committed by Georg Hopp
1 parent 19324908

added some more tests for module Model

Showing 1 changed file with 20 additions and 11 deletions
@@ -37,6 +37,16 @@ class ModelTest < Test::Unit::TestCase @@ -37,6 +37,16 @@ class ModelTest < Test::Unit::TestCase
37 assert_nil(model.id) 37 assert_nil(model.id)
38 end 38 end
39 39
  40 + def test_config_key
  41 + assert_equal(:ModelStub, ModelStub.new.config_key)
  42 + end
  43 +
  44 + def test_to_h
  45 + model_hash = ModelStub.new({:data => 'data'}).to_h
  46 + assert_instance_of(Hash, model_hash)
  47 + assert_equal('data', model_hash[:data])
  48 + end
  49 +
40 def test_all_and_each 50 def test_all_and_each
41 model = ModelStub.new 51 model = ModelStub.new
42 52
@@ -44,36 +54,35 @@ class ModelTest < Test::Unit::TestCase @@ -44,36 +54,35 @@ class ModelTest < Test::Unit::TestCase
44 54
45 storage_mock = mock(:config => storage_config_mock) 55 storage_mock = mock(:config => storage_config_mock)
46 storage_mock.extend(Enumerable). 56 storage_mock.extend(Enumerable).
47 - expects(:each).multiple_yields([{:data => 'data1'}], [{:data => 'data2'}]) 57 + expects(:each).multiple_yields(
  58 + [{:id => 1, :data => 'data1'}],
  59 + [{:id => 2, :data => 'data2'}])
48 60
49 DsAdmin::Model.storage = storage_mock 61 DsAdmin::Model.storage = storage_mock
50 all = model.all 62 all = model.all
51 63
  64 + assert_nil(model.id)
  65 + assert_nil(model.data)
52 assert_instance_of(Array, all) 66 assert_instance_of(Array, all)
53 assert_instance_of(ModelStub, all[0]) 67 assert_instance_of(ModelStub, all[0])
54 assert_instance_of(ModelStub, all[1]) 68 assert_instance_of(ModelStub, all[1])
  69 + assert_equal(1, all[0].id)
55 assert_equal('data1', all[0].data) 70 assert_equal('data1', all[0].data)
  71 + assert_equal(2, all[1].id)
56 assert_equal('data2', all[1].data) 72 assert_equal('data2', all[1].data)
57 73
58 found = Array.new 74 found = Array.new
  75 + ids = Array.new
59 all.each do |a| 76 all.each do |a|
60 assert_instance_of(ModelStub, a) 77 assert_instance_of(ModelStub, a)
61 found << a.data 78 found << a.data
  79 + ids << a.id
62 end 80 end
63 81
  82 + assert_equal([1, 2], ids)
64 assert_equal(['data1', 'data2'], found) 83 assert_equal(['data1', 'data2'], found)
65 end 84 end
66 85
67 - def test_config_key  
68 - assert_equal(:ModelStub, ModelStub.new.config_key)  
69 - end  
70 -  
71 - def test_to_h  
72 - model_hash = ModelStub.new({:data => 'data'}).to_h  
73 - assert_instance_of(Hash, model_hash)  
74 - assert_equal('data', model_hash[:data])  
75 - end  
76 -  
77 def test_load 86 def test_load
78 model = ModelStub.new 87 model = ModelStub.new
79 88
Please register or login to post a comment