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 37 assert_nil(model.id)
38 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 50 def test_all_and_each
41 51 model = ModelStub.new
42 52
... ... @@ -44,36 +54,35 @@ class ModelTest < Test::Unit::TestCase
44 54
45 55 storage_mock = mock(:config => storage_config_mock)
46 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 61 DsAdmin::Model.storage = storage_mock
50 62 all = model.all
51 63
  64 + assert_nil(model.id)
  65 + assert_nil(model.data)
52 66 assert_instance_of(Array, all)
53 67 assert_instance_of(ModelStub, all[0])
54 68 assert_instance_of(ModelStub, all[1])
  69 + assert_equal(1, all[0].id)
55 70 assert_equal('data1', all[0].data)
  71 + assert_equal(2, all[1].id)
56 72 assert_equal('data2', all[1].data)
57 73
58 74 found = Array.new
  75 + ids = Array.new
59 76 all.each do |a|
60 77 assert_instance_of(ModelStub, a)
61 78 found << a.data
  79 + ids << a.id
62 80 end
63 81
  82 + assert_equal([1, 2], ids)
64 83 assert_equal(['data1', 'data2'], found)
65 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 86 def test_load
78 87 model = ModelStub.new
79 88
... ...
Please register or login to post a comment