ref: refs/heads/master commit 5036a1eded45eae1a2480fa057eb9bf69f309d7a Author: Martin Vidner <mvidner@suse.cz> Date: Fri Sep 4 16:07:24 2009 +0200 Implemented (and tested) Route.find(:all). @id is optionally settable separately --- plugins/network/app/models/route.rb | 15 ++++++++++++--- plugins/network/test/unit/route_test.rb | 8 ++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/plugins/network/app/models/route.rb b/plugins/network/app/models/route.rb index b3c34ac..af1dab6 100644 --- a/plugins/network/app/models/route.rb +++ b/plugins/network/app/models/route.rb @@ -12,8 +12,9 @@ class Route public - def initialize(kwargs) + def initialize(kwargs, id = nil) @via = kwargs["via"] + @id = kwargs["id"] || id end # fills route instance with data from YaPI. @@ -21,8 +22,15 @@ class Route # +warn+: YaPI implements default only. def Route.find( which ) response = YastService.Call("YaPI::NETWORK::Read") - ret = Route.new(response["routes"][which]) - ret.id = which + routes_h = response["routes"] + if which == :all + ret = Hash.new + routes_h.each do |id, route_h| + ret[id] = Route.new(route_h, id) + end + else + ret = Route.new(routes_h[which], which) + end return ret end @@ -41,6 +49,7 @@ class Route xml.instruct! unless options[:skip_instruct] xml.route do + xml.id @id xml.via @via end end diff --git a/plugins/network/test/unit/route_test.rb b/plugins/network/test/unit/route_test.rb index 0a9cd7d..b52d11d 100644 --- a/plugins/network/test/unit/route_test.rb +++ b/plugins/network/test/unit/route_test.rb @@ -18,6 +18,14 @@ class RouteTest < ActiveSupport::TestCase def test_getter route=Route.find('default') assert_equal '10.20.7.254', route.via + assert_equal 'default', route.id + end + + def test_index + routes = Route.find(:all) + assert_instance_of Hash, routes + route = routes["default"] + assert_equal 'default', route.id end end -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org