Browse Source

added some more tests for module Model

master
Georg Hopp 15 years ago
committed by Georg Hopp
parent
commit
39cac09889
  1. 31
      tests/test_model.rb

31
tests/test_model.rb

@ -37,6 +37,16 @@ class ModelTest < Test::Unit::TestCase
assert_nil(model.id)
end
def test_config_key
assert_equal(:ModelStub, ModelStub.new.config_key)
end
def test_to_h
model_hash = ModelStub.new({:data => 'data'}).to_h
assert_instance_of(Hash, model_hash)
assert_equal('data', model_hash[:data])
end
def test_all_and_each
model = ModelStub.new
@ -44,36 +54,35 @@ class ModelTest < Test::Unit::TestCase
storage_mock = mock(:config => storage_config_mock)
storage_mock.extend(Enumerable).
expects(:each).multiple_yields([{:data => 'data1'}], [{:data => 'data2'}])
expects(:each).multiple_yields(
[{:id => 1, :data => 'data1'}],
[{:id => 2, :data => 'data2'}])
DsAdmin::Model.storage = storage_mock
all = model.all
assert_nil(model.id)
assert_nil(model.data)
assert_instance_of(Array, all)
assert_instance_of(ModelStub, all[0])
assert_instance_of(ModelStub, all[1])
assert_equal(1, all[0].id)
assert_equal('data1', all[0].data)
assert_equal(2, all[1].id)
assert_equal('data2', all[1].data)
found = Array.new
ids = Array.new
all.each do |a|
assert_instance_of(ModelStub, a)
found << a.data
ids << a.id
end
assert_equal([1, 2], ids)
assert_equal(['data1', 'data2'], found)
end
def test_config_key
assert_equal(:ModelStub, ModelStub.new.config_key)
end
def test_to_h
model_hash = ModelStub.new({:data => 'data'}).to_h
assert_instance_of(Hash, model_hash)
assert_equal('data', model_hash[:data])
end
def test_load
model = ModelStub.new

Loading…
Cancel
Save