Skip to content

Commit

Permalink
Added some new features and tests for identifying devices from an active
Browse files Browse the repository at this point in the history
connection.
  • Loading branch information
Steven Steffen authored and Steven Steffen committed Jan 9, 2012
1 parent 7b8a09e commit 1bc0d67
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
5 changes: 5 additions & 0 deletions lib/network_manager/dbus/active_connection.rb
Expand Up @@ -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
23 changes: 17 additions & 6 deletions lib/network_manager/dbus/root.rb
Expand Up @@ -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 ||=
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions spec/lib/network_manager/dbus/active_connection_spec.rb
Expand Up @@ -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
10 changes: 10 additions & 0 deletions 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.