virtualbox 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. data/Readme.md +9 -9
  2. data/VERSION +1 -1
  3. data/docs/GettingStarted.md +11 -11
  4. data/docs/WhatsNew.md +1 -1
  5. data/lib/virtualbox.rb +10 -1
  6. data/lib/virtualbox/abstract_model.rb +47 -29
  7. data/lib/virtualbox/abstract_model/attributable.rb +16 -16
  8. data/lib/virtualbox/abstract_model/dirty.rb +10 -10
  9. data/lib/virtualbox/abstract_model/relatable.rb +22 -22
  10. data/lib/virtualbox/abstract_model/validatable.rb +4 -4
  11. data/lib/virtualbox/attached_device.rb +23 -23
  12. data/lib/virtualbox/command.rb +9 -9
  13. data/lib/virtualbox/dvd.rb +7 -7
  14. data/lib/virtualbox/ext/subclass_listing.rb +1 -1
  15. data/lib/virtualbox/extra_data.rb +17 -17
  16. data/lib/virtualbox/forwarded_port.rb +23 -23
  17. data/lib/virtualbox/hard_drive.rb +27 -27
  18. data/lib/virtualbox/image.rb +25 -18
  19. data/lib/virtualbox/nic.rb +22 -22
  20. data/lib/virtualbox/proxies/collection.rb +4 -4
  21. data/lib/virtualbox/shared_folder.rb +25 -25
  22. data/lib/virtualbox/storage_controller.rb +16 -16
  23. data/lib/virtualbox/vm.rb +95 -42
  24. data/test/virtualbox/abstract_model/attributable_test.rb +28 -28
  25. data/test/virtualbox/abstract_model/dirty_test.rb +13 -13
  26. data/test/virtualbox/abstract_model/relatable_test.rb +36 -36
  27. data/test/virtualbox/abstract_model/validatable_test.rb +22 -22
  28. data/test/virtualbox/abstract_model_test.rb +46 -36
  29. data/test/virtualbox/attached_device_test.rb +47 -47
  30. data/test/virtualbox/command_test.rb +12 -12
  31. data/test/virtualbox/dvd_test.rb +15 -19
  32. data/test/virtualbox/ext/subclass_listing_test.rb +2 -2
  33. data/test/virtualbox/extra_data_test.rb +37 -37
  34. data/test/virtualbox/forwarded_port_test.rb +31 -31
  35. data/test/virtualbox/hard_drive_test.rb +40 -48
  36. data/test/virtualbox/image_test.rb +36 -33
  37. data/test/virtualbox/nic_test.rb +22 -22
  38. data/test/virtualbox/proxies/collection_test.rb +6 -6
  39. data/test/virtualbox/shared_folder_test.rb +36 -36
  40. data/test/virtualbox/storage_controller_test.rb +14 -14
  41. data/test/virtualbox/vm_test.rb +121 -70
  42. data/test/virtualbox_test.rb +19 -0
  43. data/virtualbox.gemspec +5 -3
  44. metadata +4 -2
@@ -3,38 +3,38 @@ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
3
3
  class DirtyTest < Test::Unit::TestCase
4
4
  class DirtyModel
5
5
  include VirtualBox::AbstractModel::Dirty
6
-
6
+
7
7
  def initialize
8
8
  @foo = "foo"
9
9
  @bar = "bar"
10
10
  end
11
-
11
+
12
12
  def foo=(value)
13
13
  set_dirty!(:foo, @foo, value)
14
14
  @foo = value
15
15
  end
16
-
16
+
17
17
  def bar=(value)
18
18
  set_dirty!(:bar, @bar, value)
19
19
  @bar = value
20
20
  end
21
21
  end
22
-
22
+
23
23
  context "dirty attributes" do
24
24
  setup do
25
25
  @model = DirtyModel.new
26
26
  end
27
-
27
+
28
28
  should "not be dirty initially" do
29
29
  assert !@model.changed?
30
30
  end
31
-
31
+
32
32
  should "be dirty after changing an attribute" do
33
33
  assert !@model.changed? # sanity
34
34
  @model.foo = "my value"
35
35
  assert @model.changed?
36
36
  end
37
-
37
+
38
38
  should "be able to clear dirty state" do
39
39
  assert !@model.changed?
40
40
  @model.foo = "my value"
@@ -42,7 +42,7 @@ class DirtyTest < Test::Unit::TestCase
42
42
  @model.clear_dirty!(:foo)
43
43
  assert !@model.changed?
44
44
  end
45
-
45
+
46
46
  should "be able to clear dirty state on entire model" do
47
47
  @model.foo = "changed"
48
48
  @model.bar = "changed"
@@ -50,7 +50,7 @@ class DirtyTest < Test::Unit::TestCase
50
50
  @model.clear_dirty!
51
51
  assert !@model.changed?
52
52
  end
53
-
53
+
54
54
  should "show changes on specific field" do
55
55
  assert !@model.changed?
56
56
  @model.foo = "my value"
@@ -58,24 +58,24 @@ class DirtyTest < Test::Unit::TestCase
58
58
  assert_equal ["foo", "my value"], @model.foo_change
59
59
  assert_equal "foo", @model.foo_was
60
60
  end
61
-
61
+
62
62
  should "return nil for field_was if its not changed" do
63
63
  assert !@model.foo_changed?
64
64
  assert_nil @model.foo_was
65
65
  end
66
-
66
+
67
67
  should "show changes for the whole model" do
68
68
  assert !@model.changed?
69
69
  @model.foo = "foo2"
70
70
  @model.bar = "bar2"
71
-
71
+
72
72
  assert @model.changed?
73
73
  changes = @model.changes
74
74
  assert_equal 2, changes.length
75
75
  assert_equal ["foo", "foo2"], changes[:foo]
76
76
  assert_equal ["bar", "bar2"], changes[:bar]
77
77
  end
78
-
78
+
79
79
  should "still forward non-dirty magic methods up method_missing" do
80
80
  assert_raises(NoMethodError) { @model.foobarbaz }
81
81
  end
@@ -10,120 +10,120 @@ class RelatableTest < Test::Unit::TestCase
10
10
  def self.set_relationship(caller, old_value, new_value)
11
11
  end
12
12
  end
13
-
13
+
14
14
  class RelatableModel
15
15
  include VirtualBox::AbstractModel::Relatable
16
-
16
+
17
17
  relationship :foos, Relatee
18
18
  relationship :bars, BarRelatee
19
19
  end
20
-
20
+
21
21
  setup do
22
22
  @data = {}
23
23
  end
24
-
24
+
25
25
  context "class methods" do
26
26
  should "read back relationships in order added" do
27
27
  order = mock("order")
28
28
  order_seq = sequence("order_seq")
29
29
  order.expects(:foos).in_sequence(order_seq)
30
30
  order.expects(:bars).in_sequence(order_seq)
31
-
31
+
32
32
  RelatableModel.relationships.each do |name, options|
33
33
  order.send(name)
34
34
  end
35
35
  end
36
36
  end
37
-
37
+
38
38
  context "setting a relationship" do
39
39
  setup do
40
40
  @model = RelatableModel.new
41
41
  end
42
-
42
+
43
43
  should "have a magic method relationship= which calls set_relationship" do
44
44
  @model.expects(:set_relationship).with(:foos, "FOOS!")
45
45
  @model.foos = "FOOS!"
46
46
  end
47
-
47
+
48
48
  should "raise a NonSettableRelationshipException if relationship can't be set" do
49
49
  assert_raises(VirtualBox::Exceptions::NonSettableRelationshipException) {
50
50
  @model.foos = "FOOS!"
51
51
  }
52
52
  end
53
-
53
+
54
54
  should "call set_relationship on the relationship class" do
55
55
  BarRelatee.expects(:populate_relationship).returns("foo")
56
56
  @model.populate_relationships({})
57
-
57
+
58
58
  BarRelatee.expects(:set_relationship).with(@model, "foo", "bars")
59
59
  assert_nothing_raised { @model.bars = "bars" }
60
60
  end
61
-
61
+
62
62
  should "set the result of set_relationship as the new relationship data" do
63
63
  BarRelatee.stubs(:set_relationship).returns("hello")
64
64
  @model.bars = "zoo"
65
65
  assert_equal "hello", @model.bars
66
66
  end
67
67
  end
68
-
68
+
69
69
  context "subclasses" do
70
70
  class SubRelatableModel < RelatableModel
71
71
  relationship :bars, RelatableTest::Relatee
72
72
  end
73
-
73
+
74
74
  setup do
75
75
  @relationships = SubRelatableModel.relationships
76
76
  end
77
-
77
+
78
78
  should "inherit relationships of parent" do
79
79
  assert SubRelatableModel.has_relationship?(:foos)
80
80
  assert SubRelatableModel.has_relationship?(:bars)
81
81
  end
82
-
82
+
83
83
  should "inherit options of relationships" do
84
84
  assert_equal Relatee, SubRelatableModel.relationships_hash[:foos][:klass]
85
85
  end
86
86
  end
87
-
87
+
88
88
  context "default callbacks" do
89
89
  setup do
90
90
  @model = RelatableModel.new
91
91
  end
92
-
92
+
93
93
  should "not raise an error if populate_relationship doesn't exist" do
94
94
  assert !BarRelatee.respond_to?(:populate_relationship)
95
95
  assert_nothing_raised { @model.populate_relationships(nil) }
96
96
  end
97
-
97
+
98
98
  should "not raise an error when saving relationships if the callback doesn't exist" do
99
99
  assert !Relatee.respond_to?(:save_relationship)
100
100
  assert_nothing_raised { @model.save_relationships }
101
101
  end
102
-
102
+
103
103
  should "not raise an error in destroying relationships if the callback doesn't exist" do
104
104
  assert !Relatee.respond_to?(:destroy_relationship)
105
105
  assert_nothing_raised { @model.destroy_relationships }
106
106
  end
107
107
  end
108
-
108
+
109
109
  context "destroying" do
110
110
  setup do
111
111
  @model = RelatableModel.new
112
112
  @model.populate_relationships({})
113
113
  end
114
-
114
+
115
115
  context "a single relationship" do
116
116
  should "call destroy_relationship only for the given relationship" do
117
117
  Relatee.expects(:destroy_relationship).once
118
118
  BarRelatee.expects(:destroy_relationship).never
119
119
  @model.destroy_relationship(:foos)
120
120
  end
121
-
121
+
122
122
  should "forward any args passed into destroy_relationship" do
123
123
  Relatee.expects(:destroy_relationship).with(@model, anything, "HELLO").once
124
124
  @model.destroy_relationship(:foos, "HELLO")
125
125
  end
126
-
126
+
127
127
  should "pass the data into destroy_relationship" do
128
128
  Relatee.expects(:destroy_relationship).with(@model, "FOO").once
129
129
  @model.destroy_relationship(:foos)
@@ -135,69 +135,69 @@ class RelatableTest < Test::Unit::TestCase
135
135
  Relatee.expects(:destroy_relationship).with(@model, anything).once
136
136
  @model.destroy_relationships
137
137
  end
138
-
138
+
139
139
  should "forward any args passed into destroy relationships" do
140
140
  Relatee.expects(:destroy_relationship).with(@model, anything, "HELLO").once
141
141
  @model.destroy_relationships("HELLO")
142
142
  end
143
143
  end
144
144
  end
145
-
145
+
146
146
  context "saving relationships" do
147
147
  setup do
148
148
  @model = RelatableModel.new
149
149
  end
150
-
150
+
151
151
  should "call save_relationship on the related class" do
152
152
  Relatee.expects(:save_relationship).with(@model, @model.foos).once
153
153
  @model.save_relationships
154
154
  end
155
-
155
+
156
156
  should "forward parameters through" do
157
157
  Relatee.expects(:save_relationship).with(@model, @model.foos, "YES").once
158
158
  @model.save_relationships("YES")
159
159
  end
160
160
  end
161
-
161
+
162
162
  context "reading relationships" do
163
163
  setup do
164
164
  @model = RelatableModel.new
165
165
  end
166
-
166
+
167
167
  should "provide a read method for relationships" do
168
168
  assert_nothing_raised { @model.foos }
169
169
  end
170
170
  end
171
-
171
+
172
172
  context "checking for relationships" do
173
173
  setup do
174
174
  @model = RelatableModel.new
175
175
  end
176
-
176
+
177
177
  should "have a class method as well" do
178
178
  assert RelatableModel.has_relationship?(:foos)
179
179
  assert !RelatableModel.has_relationship?(:bazs)
180
180
  end
181
-
181
+
182
182
  should "return true for existing relationships" do
183
183
  assert @model.has_relationship?(:foos)
184
184
  end
185
-
185
+
186
186
  should "return false for nonexistent relationships" do
187
187
  assert !@model.has_relationship?(:bazs)
188
188
  end
189
189
  end
190
-
190
+
191
191
  context "populating relationships" do
192
192
  setup do
193
193
  @model = RelatableModel.new
194
194
  end
195
-
195
+
196
196
  should "call populate_relationship on the related class" do
197
197
  Relatee.expects(:populate_relationship).with(@model, @data).once
198
198
  @model.populate_relationships(@data)
199
199
  end
200
-
200
+
201
201
  should "properly save returned value as the value for the relationship" do
202
202
  Relatee.expects(:populate_relationship).once.returns("HEY")
203
203
  @model.populate_relationships(@data)
@@ -3,27 +3,27 @@ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
3
3
  class ValidatableTest < Test::Unit::TestCase
4
4
  class ValidatableModel
5
5
  include VirtualBox::AbstractModel::Validatable
6
-
6
+
7
7
  attr_accessor :foos
8
8
  attr_accessor :bars
9
9
  end
10
-
10
+
11
11
  context "errors" do
12
12
  setup do
13
13
  @model = ValidatableModel.new
14
14
  end
15
-
15
+
16
16
  should "have no errors by default" do
17
17
  assert @model.errors.empty?
18
18
  end
19
-
19
+
20
20
  should "be able to add errors" do
21
21
  @model.add_error(:foo, "is blank")
22
22
  assert !@model.errors.empty?
23
23
  assert !@model.errors[:foo].nil?
24
24
  assert_equal "is blank", @model.errors[:foo].first
25
25
  end
26
-
26
+
27
27
  should "be able to add multiple errors" do
28
28
  @model.add_error(:foo, "foo")
29
29
  @model.add_error(:foo, "bar")
@@ -31,7 +31,7 @@ class ValidatableTest < Test::Unit::TestCase
31
31
  assert !@model.errors[:foo].nil?
32
32
  assert_equal 2, @model.errors[:foo].length
33
33
  end
34
-
34
+
35
35
  should "be able to clear errors" do
36
36
  @model.add_error(:foo, "foo")
37
37
  assert !@model.errors.empty?
@@ -39,82 +39,82 @@ class ValidatableTest < Test::Unit::TestCase
39
39
  assert @model.errors.empty?
40
40
  end
41
41
  end
42
-
42
+
43
43
  context "validity" do
44
44
  setup do
45
45
  @model = ValidatableModel.new
46
46
  end
47
-
47
+
48
48
  should "call validate on valid?" do
49
49
  @model.expects(:validate)
50
50
  assert @model.valid?
51
51
  end
52
-
52
+
53
53
  should "be valid if there are no errors" do
54
54
  assert @model.valid?
55
55
  end
56
-
56
+
57
57
  should "be invalid if there are any errors" do
58
58
  @model.add_error(:foo, "foo")
59
59
  assert !@model.valid?
60
60
  end
61
-
61
+
62
62
  should "have a validate method by default which returns true" do
63
63
  assert @model.validate
64
64
  end
65
65
  end
66
-
66
+
67
67
  context "specific validations" do
68
68
  setup do
69
69
  @model = ValidatableModel.new
70
70
  end
71
-
71
+
72
72
  context "validates_presence_of" do
73
73
  setup do
74
74
  @model.foos = "foo"
75
75
  @model.bars = "bar"
76
76
  end
77
-
77
+
78
78
  should "not add an error if not blank" do
79
79
  @model.validates_presence_of(:foos)
80
80
  assert @model.valid?
81
81
  end
82
-
82
+
83
83
  should "add an error if blank field" do
84
84
  @model.foos = ""
85
85
  @model.validates_presence_of(:foos)
86
86
  assert !@model.valid?
87
87
  end
88
-
88
+
89
89
  should "add an error for a nil field" do
90
90
  @model.foos = nil
91
91
  @model.validates_presence_of(:foos)
92
92
  assert !@model.valid?
93
93
  end
94
-
94
+
95
95
  should "validate multiple fields" do
96
96
  @model.bars = nil
97
97
  @model.validates_presence_of([:foos, :bars])
98
-
98
+
99
99
  assert !@model.valid?
100
100
  assert @model.errors[:bars]
101
101
  end
102
-
102
+
103
103
  should "return false on invalid" do
104
104
  @model.bars = nil
105
105
  assert !@model.validates_presence_of(:bars)
106
106
  end
107
-
107
+
108
108
  should "return true on valid" do
109
109
  @model.bars = "foo"
110
110
  assert @model.validates_presence_of(:bars)
111
111
  end
112
-
112
+
113
113
  should "return false if any are invalid on multiple fields" do
114
114
  @model.bars = nil
115
115
  assert !@model.validates_presence_of([:foos, :bars])
116
116
  end
117
-
117
+
118
118
  should "return true if all fields are valid" do
119
119
  @model.foos = "foo"
120
120
  @model.bars = "bar"