Skip to content
Browse files

Added some new features and tests for identifying devices from an active

connection.
  • Loading branch information...
1 parent 7b8a09e commit 1bc0d67ebe13e78ae4490073508665e95d02e0ff Steven Steffen committed Jan 9, 2012
View
5 lib/network_manager/dbus/active_connection.rb
@@ -14,4 +14,9 @@ def access_point
end
end
+ def devices
+ if self["Devices"].empty? then nil end
+ self["Devices"].map{|device_path| NetworkManager::DBus::Device.new(device_path)}
+ end
+
end
View
23 lib/network_manager/dbus/root.rb
@@ -35,12 +35,16 @@ class NetworkManager::DBus::Root
# SetLogging
# @return [Array<NetworkManager::DBus::Device>]] devices
- def self.devices
- instance.call('GetDevices').flatten.map do |object_path|
+ def devices
+ self.call('GetDevices').flatten.map do |object_path|
new_device(object_path)
end
end
+ def self.devices
+ instance.devices
+ end
+
# @return [NetworkManager::DBus::ActiveConnection] con
def active_connection
@active_connection ||=
@@ -69,17 +73,24 @@ def self.internet_connection?
state == NM_STATE_CONNECTED_GLOBAL || state == NM_OLD_STATE_CONNECTED
end
+ def state
+ self.call('state')
+ end
+
def self.state
- instance.call('state')
+ NetworkManager.new.state
end
- def self.version
- version = instance['Version']
+ def version
+ version = self['Version']
if version.nil?
return "0.7"
end
return version
-
+ end
+
+ def self.version
+ NetworkManager.new.version
end
private
View
7 spec/lib/network_manager/dbus/active_connection_spec.rb
@@ -16,4 +16,11 @@
con = NetworkManager::DBus::ActiveConnection.new @object_paths.first
con.properties.should == @data.first.last['properties']
end
+
+ it "should list devices" do
+ network_manager_dbus_mock
+ con = NetworkManager::DBus::ActiveConnection.new @object_paths.first
+ con.devices.size.should_not eql(0)
+ con.devices.first.class.should eql(NetworkManager::DBus::Device)
+ end
end
View
10 spec/mocks/dbus/active_connection_mock.rb
@@ -1,3 +1,13 @@
module ActiveConnectionMock
+ def all_properties
+ data['properties']
+ end
+
+ def devices
+ self['Devices'].map do |x|
+ NetworkManager::DBus::Device.new x
+ end
+ end
+
end

0 comments on commit 1bc0d67

Please sign in to comment.
Something went wrong with that request. Please try again.