Skip to content

Commit

Permalink
Removing default value of device in Vif
Browse files Browse the repository at this point in the history
  • Loading branch information
plribeiro3000 committed Sep 9, 2014
1 parent 36f0c60 commit 79257c3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 34 deletions.
9 changes: 2 additions & 7 deletions lib/fog/compute/xen_server/models/vif.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Vif < Fog::Model
attribute :allowed_operations
attribute :current_operations
attribute :currently_attached
attribute :device, :default => -1
attribute :device
attribute :ipv4_allowed
attribute :ipv6_allowed
attribute :locking_mode
Expand All @@ -34,15 +34,10 @@ class Vif < Fog::Model
has_one_identity :network, :networks
has_one_identity :vm, :servers, :aliases => :VM, :as => :VM

require_before_save :server, :network
require_before_save :server, :network, :device

alias_method :server, :vm

def save
set_device_number
super
end

def set_device_number
return device unless device == -1
devices = vm.vifs.map(&:device)
Expand Down
30 changes: 3 additions & 27 deletions spec/fog/compute/xen_server/models/vif_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,41 +85,17 @@ def self.read_identity
:VM => :vm)
end

it 'should have 7 default values' do
it 'should have 6 default values' do
vif_class.default_values.must_equal(:mac => '',
:mac_autogenerated => 'True',
:device => -1,
:mtu => '0',
:other_config => {},
:qos_algorithm_params => {},
:qos_algorithm_type => 'ratelimit')
end

it 'should require 2 attributes before save' do
vif_class.require_before_save.must_equal([ :server, :network ])
end

describe '#save' do
before :each do
def vif.set_device_number; @device = 23 end
def vif.require_creation_attributes; @required = true end
def service.create_vif(attributes); @created = true end
vif.stub(:service, service) do
vif.save
end
end

it 'should set the device number' do
vif.instance_variable_get(:@device).must_equal(23)
end

it 'should check for the required attributes' do
vif.instance_variable_get(:@required).must_equal(true)
end

it 'should create the vif' do
service.instance_variable_get(:@created).must_equal(true)
end
it 'should require 3 attributes before save' do
vif_class.require_before_save.must_equal([ :server, :network, :device ])
end

describe '#set_device_number' do
Expand Down

0 comments on commit 79257c3

Please sign in to comment.