gapinc-cobbler 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/COPYING +510 -0
- data/ChangeLog +40 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +41 -0
- data/NEWS +5 -0
- data/README.rdoc +87 -0
- data/Rakefile +75 -0
- data/TODO +6 -0
- data/config/cobbler.yml +5 -0
- data/examples/example_distros.rb +119 -0
- data/examples/example_version.rb +31 -0
- data/examples/utils.rb +44 -0
- data/lib/cobbler.rb +35 -0
- data/lib/cobbler/base.rb +128 -0
- data/lib/cobbler/common/debug.rb +59 -0
- data/lib/cobbler/common/finders.rb +55 -0
- data/lib/cobbler/common/lifecycle.rb +163 -0
- data/lib/cobbler/connection/common.rb +79 -0
- data/lib/cobbler/connection/handling.rb +108 -0
- data/lib/cobbler/distro.rb +32 -0
- data/lib/cobbler/image.rb +31 -0
- data/lib/cobbler/profile.rb +34 -0
- data/lib/cobbler/repo.rb +33 -0
- data/lib/cobbler/system.rb +45 -0
- data/rubygem-cobbler.spec +100 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/unit/cobbler/base_spec.rb +194 -0
- data/spec/unit/cobbler/common/debug_spec.rb +44 -0
- data/spec/unit/cobbler/common/finders_spec.rb +101 -0
- data/spec/unit/cobbler/common/lifecycle_spec.rb +192 -0
- data/spec/unit/cobbler/connection/common_spec.rb +59 -0
- data/spec/unit/cobbler/connection/handling_spec.rb +119 -0
- data/spec/unit/cobbler/system_spec.rb +27 -0
- metadata +181 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + '/../../../spec_helper'
|
3
|
+
|
4
|
+
class TestDebug
|
5
|
+
include Cobbler::Common::Debug
|
6
|
+
end
|
7
|
+
|
8
|
+
describe Cobbler::Common::Debug do
|
9
|
+
|
10
|
+
it "should provide a way to set and query a debug flag" do
|
11
|
+
TestDebug.should respond_to(:debug_enabled)
|
12
|
+
TestDebug.should respond_to(:debug_enabled=)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should provide a way to set and query an output engine" do
|
16
|
+
TestDebug.should respond_to(:output)
|
17
|
+
TestDebug.should respond_to(:output=)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should provide a method to print debug messages on class and instance level" do
|
21
|
+
TestDebug.should respond_to(:debug)
|
22
|
+
TestDebug.new.should respond_to(:debug)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should not have debugging enabled by default" do
|
26
|
+
TestDebug.debug_enabled.should == false
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should not print out a debug message if the debug flag is not set" do
|
30
|
+
output = Object.new
|
31
|
+
output.expects(:puts).with('foo').never
|
32
|
+
TestDebug.output = output
|
33
|
+
TestDebug.debug('foo')
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should print out a debug message if the debug flag is set" do
|
37
|
+
TestDebug.debug_enabled = true
|
38
|
+
output = Object.new
|
39
|
+
output.expects(:puts).with('foo').once
|
40
|
+
TestDebug.output = output
|
41
|
+
TestDebug.debug('foo')
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + '/../../../spec_helper'
|
3
|
+
|
4
|
+
class TestFinder
|
5
|
+
|
6
|
+
def initialize(a,b)
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
include Cobbler::Common::Debug
|
11
|
+
include Cobbler::Connection::Handling
|
12
|
+
include Cobbler::Common::Lifecycle
|
13
|
+
include Cobbler::Common::Finders
|
14
|
+
end
|
15
|
+
|
16
|
+
describe Cobbler::Common::Finders do
|
17
|
+
it "should provide a way to find all" do
|
18
|
+
TestFinder.should respond_to(:find)
|
19
|
+
end
|
20
|
+
it "should provide a way to find one" do
|
21
|
+
TestFinder.should respond_to(:find_one)
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "lookup" do
|
25
|
+
it "should raise an exception if we don't know how to lookup all" do
|
26
|
+
api_methods = Object.new
|
27
|
+
api_methods.stubs(:[]).with(:find_all).returns(nil)
|
28
|
+
TestFinder.stubs(:api_methods).returns(api_methods)
|
29
|
+
lambda{ TestFinder.find_all }.should raise_error(Exception)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should raise an exception if we don't know how to lookup an item" do
|
33
|
+
api_methods = Object.new
|
34
|
+
api_methods.stubs(:[]).with(:find_one).returns(nil)
|
35
|
+
TestFinder.stubs(:api_methods).returns(api_methods)
|
36
|
+
lambda{ TestFinder.find_one('foo') }.should raise_error(Exception)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should use the :find_one api_method to lookup an item" do
|
40
|
+
TestFinder.api_methods[:find_one] = 'find_one'
|
41
|
+
connection = Object.new
|
42
|
+
TestFinder.expects(:connect).returns(connection)
|
43
|
+
TestFinder.stubs(:make_call).with('find_one','foo').returns({})
|
44
|
+
item = TestFinder.find_one('foo')
|
45
|
+
item.should be_nil
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return nil if api returns '~'" do
|
49
|
+
TestFinder.api_methods[:find_one] = 'find_one'
|
50
|
+
connection = Object.new
|
51
|
+
TestFinder.expects(:connect).returns(connection)
|
52
|
+
TestFinder.stubs(:make_call).with('find_one','foo').returns('~')
|
53
|
+
item = TestFinder.find_one('foo')
|
54
|
+
item.should be_nil
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "is unsuccessful" do
|
58
|
+
it "should return an empty array if nothing is found" do
|
59
|
+
TestFinder.stubs(:in_transaction).returns([])
|
60
|
+
TestFinder.find.should be_empty
|
61
|
+
end
|
62
|
+
it "should return nil if nothing is found" do
|
63
|
+
TestFinder.stubs(:in_transaction).returns({})
|
64
|
+
TestFinder.find_one('foo').should be_nil
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "successfully all items" do
|
69
|
+
before(:each) do
|
70
|
+
TestFinder.stubs(:in_transaction).returns([1,2])
|
71
|
+
end
|
72
|
+
it "should return an array of Objects of itself if something is found" do
|
73
|
+
items = TestFinder.find
|
74
|
+
items.should have(2).items
|
75
|
+
items.first.should be_a(TestFinder)
|
76
|
+
items.last.should be_a(TestFinder)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should pass each found item to the passed block but return the found items" do
|
80
|
+
items = TestFinder.find do |item|
|
81
|
+
item.should be_a(TestFinder)
|
82
|
+
end
|
83
|
+
items.should have(2).items
|
84
|
+
items.first.should be_a(TestFinder)
|
85
|
+
items.last.should be_a(TestFinder)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "successfully one item" do
|
90
|
+
it "should return an item" do
|
91
|
+
TestFinder.stubs(:in_transaction).returns({:a => 1})
|
92
|
+
TestFinder.find_one('foo').should be_a(TestFinder)
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should return nil if nothing is found" do
|
96
|
+
TestFinder.stubs(:in_transaction).returns({})
|
97
|
+
TestFinder.find_one('foo').should be_nil
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../spec_helper'
|
2
|
+
|
3
|
+
class TestLifecycle
|
4
|
+
|
5
|
+
def initialize(a=nil,b=nil)
|
6
|
+
@definitions = Hash.new(a)
|
7
|
+
end
|
8
|
+
|
9
|
+
include Cobbler::Common::Debug
|
10
|
+
include Cobbler::Connection::Handling
|
11
|
+
include Cobbler::Common::Lifecycle
|
12
|
+
|
13
|
+
cobbler_field :name
|
14
|
+
cobbler_field :foo, :locked => true
|
15
|
+
cobbler_field :findme, :findable => 'find_me'
|
16
|
+
cobbler_field :super_field, :locked => true, :findable => 'find_super'
|
17
|
+
|
18
|
+
cobbler_fields :foo1, :foo2
|
19
|
+
|
20
|
+
cobbler_collection :coll1
|
21
|
+
cobbler_collection :coll2, :packing => Hash
|
22
|
+
cobbler_collection :coll3, :store => :foobar
|
23
|
+
end
|
24
|
+
|
25
|
+
class TestLifecycle2
|
26
|
+
def initialize(a,b); end
|
27
|
+
include Cobbler::Common::Debug
|
28
|
+
include Cobbler::Connection::Handling
|
29
|
+
include Cobbler::Common::Lifecycle
|
30
|
+
cobbler_field :name, :locked => false, :findable => false
|
31
|
+
cobbler_lifecycle :find_all => 'foobar', :find_one => false
|
32
|
+
end
|
33
|
+
|
34
|
+
describe Cobbler::Common::Lifecycle do
|
35
|
+
|
36
|
+
it "should provide a bunch of api_methods for that object" do
|
37
|
+
TestLifecycle.api_methods.keys.should_not be_empty
|
38
|
+
end
|
39
|
+
|
40
|
+
[ :find_all, :find_one, :handle, :remove, :save, :new, :modify].each do |method|
|
41
|
+
it "should provide an api_method for #{method} and be derived from the classname" do
|
42
|
+
TestLifecycle.api_methods[method].should_not be_nil
|
43
|
+
TestLifecycle.api_methods[method].should =~ /test_lifecycle/
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "defining lifecycle" do
|
48
|
+
it "should provide a way to define a lifecycle" do
|
49
|
+
TestLifecycle.should respond_to(:cobbler_lifecycle)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should set the api_method according to the one we defined" do
|
53
|
+
TestLifecycle2.api_methods[:find_all].should == 'foobar'
|
54
|
+
TestLifecycle2.api_methods[:find_one].should be_false
|
55
|
+
end
|
56
|
+
|
57
|
+
[ :handle, :remove, :save, :new, :modify].each do |method|
|
58
|
+
it "should define method #{method}" do
|
59
|
+
TestLifecycle2.api_methods[method].should_not be_nil
|
60
|
+
TestLifecycle2.api_methods[method].should =~ /test_lifecycle/
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "define a cobbler field" do
|
67
|
+
it "should provide a way to define a cobbler field" do
|
68
|
+
TestLifecycle.should respond_to(:cobbler_field)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should provide a way to define multiple cobbler fields" do
|
72
|
+
TestLifecycle.should respond_to(:cobbler_fields)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should add this field to the record fields" do
|
76
|
+
TestLifecycle.cobbler_record_fields.should include(:name)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should add the name field as findable" do
|
80
|
+
TestLifecycle.should respond_to(:find_by_name)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should lock the name field" do
|
84
|
+
TestLifecycle.locked_fields.should include(:name)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should not add the name field as findable if we mark it" do
|
88
|
+
TestLifecycle2.should_not respond_to(:find_by_name)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should lock the name field" do
|
92
|
+
TestLifecycle2.locked_fields.should_not include(:name)
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should be available as getter and setter on an instance" do
|
96
|
+
test = TestLifecycle.new
|
97
|
+
test.should respond_to(:name)
|
98
|
+
test.should respond_to(:name=)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should handle cobbler_fields over to cobbler_field" do
|
102
|
+
test = TestLifecycle.new
|
103
|
+
[:foo1,:foo2].each do |field|
|
104
|
+
test.should respond_to(field)
|
105
|
+
test.should respond_to(:"#{field}=")
|
106
|
+
TestLifecycle.cobbler_record_fields.should include(field)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should be possible to mark that field as locked" do
|
111
|
+
TestLifecycle.locked_fields.should include(:foo)
|
112
|
+
TestLifecycle.locked_fields.should include(:super_field)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should be possible to mark a field as findable" do
|
116
|
+
TestLifecycle.should respond_to(:find_by_findme)
|
117
|
+
TestLifecycle.should respond_to(:find_by_super_field)
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "which is findable" do
|
121
|
+
before(:each) do
|
122
|
+
connection = Object.new
|
123
|
+
TestLifecycle.expects(:connect).returns(connection)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should lookup that field" do
|
127
|
+
TestLifecycle.expects(:make_call).with('get_test_lifecycle','foo').returns('a')
|
128
|
+
item = TestLifecycle.find_by_name('foo')
|
129
|
+
item.should be_a(TestLifecycle)
|
130
|
+
end
|
131
|
+
it "should lookup the field with the appropriate api method" do
|
132
|
+
TestLifecycle.expects(:make_call).with('find_super','foo').returns('a')
|
133
|
+
item = TestLifecycle.find_by_super_field('foo')
|
134
|
+
item.should be_a(TestLifecycle)
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should return nil if nothing is found" do
|
138
|
+
TestLifecycle.expects(:make_call).with('get_test_lifecycle','foo').returns(nil)
|
139
|
+
TestLifecycle.find_by_name('foo').should be_nil
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
describe "define a cobbler collection" do
|
144
|
+
it "should provide a way to define a cobbler collection" do
|
145
|
+
TestLifecycle.should respond_to(:cobbler_collection)
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should provide accessor and setter for a collection" do
|
149
|
+
TestLifecycle.new.should respond_to(:coll1)
|
150
|
+
TestLifecycle.new.should respond_to(:coll1=)
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should add the collection to the fields" do
|
154
|
+
TestLifecycle.cobbler_record_fields.should include(:coll1)
|
155
|
+
TestLifecycle.cobbler_record_fields.should include(:coll2)
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should set a default type to be an array" do
|
159
|
+
TestLifecycle.new.coll1.should be_a(Array)
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should be possible to set packing as Hash" do
|
163
|
+
TestLifecycle.new.coll2.should be_a(Hash)
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should be possible to define a special store callback" do
|
167
|
+
TestLifecycle.cobbler_record_fields.should_not include(:coll3)
|
168
|
+
TestLifecycle.cobbler_collections_store_callbacks.should include(:foobar)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
describe "assigning new values" do
|
173
|
+
it "should not be added to the original definitions" do
|
174
|
+
test = TestLifecycle.new
|
175
|
+
test.name = 'foo'
|
176
|
+
test.name.should == 'foo'
|
177
|
+
test.definitions['name'].should_not == 'foo'
|
178
|
+
test.user_definitions['name'].should == 'foo'
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should always be added to the user_definitions if it as collection" do
|
182
|
+
test = TestLifecycle.new
|
183
|
+
test.coll1.should == []
|
184
|
+
test.coll1 = [1,2]
|
185
|
+
test.coll1.should == [1,2]
|
186
|
+
test.user_definitions['coll1'].should == [1,2]
|
187
|
+
test.coll1 << 3
|
188
|
+
test.coll1 == [1,2,3]
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + '/../../../spec_helper'
|
3
|
+
|
4
|
+
class TestConnection
|
5
|
+
include Cobbler::Common::Debug
|
6
|
+
include Cobbler::Connection::Handling
|
7
|
+
include Cobbler::Connection::Common
|
8
|
+
end
|
9
|
+
|
10
|
+
describe Cobbler::Connection::Common do
|
11
|
+
it "should provide a method to test a connection" do
|
12
|
+
TestConnection.should respond_to(:test_connection)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should provide a method to start a sync" do
|
16
|
+
TestConnection.should respond_to(:sync)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "testing a connection" do
|
20
|
+
|
21
|
+
before(:each) do
|
22
|
+
connection = Object.new
|
23
|
+
TestConnection.expects(:connect).returns(connection)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return false if login fails" do
|
27
|
+
TestConnection.expects(:login).returns(nil)
|
28
|
+
TestConnection.test_connection.should be_false
|
29
|
+
end
|
30
|
+
it "should return true if login succeeds and logout" do
|
31
|
+
TestConnection.expects(:login).returns("true")
|
32
|
+
TestConnection.expects(:logout)
|
33
|
+
TestConnection.test_connection.should be_true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
with_real_cobbler(TestConnection) do |cobbler_yml|
|
38
|
+
describe "testing a real connection" do
|
39
|
+
before(:each) do
|
40
|
+
TestConnection.hostname = yml['hostname']
|
41
|
+
TestConnection.username = yml['username']
|
42
|
+
TestConnection.password = yml['password']
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should "
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "syncing a cobbler" do
|
50
|
+
it "should send the sync command" do
|
51
|
+
connection =
|
52
|
+
TestConnection.expects(:connect).returns(Object.new)
|
53
|
+
TestConnection.expects(:login).returns('foobar')
|
54
|
+
TestConnection.expects(:logout)
|
55
|
+
TestConnection.expects(:make_call).with('sync','foobar')
|
56
|
+
TestConnection.sync
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + '/../../../spec_helper'
|
3
|
+
|
4
|
+
class TestConnection
|
5
|
+
include Cobbler::Common::Debug
|
6
|
+
include Cobbler::Connection::Handling
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Cobbler::Connection::Handling do
|
10
|
+
[:hostname, :username, :password].each do |field|
|
11
|
+
it "should provide getters and setters for #{field}" do
|
12
|
+
TestConnection.should respond_to(field)
|
13
|
+
TestConnection.should respond_to("#{field}=".to_sym)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should provide a way to query the version of the cobbler server" do
|
18
|
+
TestConnection.should respond_to(:remote_version)
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "querying remote version" do
|
22
|
+
before(:each) do
|
23
|
+
connection = Object.new
|
24
|
+
TestConnection.expects(:connect).returns(connection)
|
25
|
+
TestConnection.expects(:connection).returns(nil)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return the version" do
|
29
|
+
TestConnection.expects(:make_call).with('version').returns("2.0")
|
30
|
+
TestConnection.remote_version.should == "2.0"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should provide a way to login to the cobbler server" do
|
35
|
+
TestConnection.should respond_to(:login)
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "logging into cobbler server" do
|
39
|
+
|
40
|
+
it "should call the login server" do
|
41
|
+
TestConnection.username = 'foobar'
|
42
|
+
TestConnection.password = 'password'
|
43
|
+
TestConnection.expects(:make_call).with('login','foobar','password')
|
44
|
+
TestConnection.login
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should not relogin if we are still logged in" do
|
48
|
+
TestConnection.username = 'foobar'
|
49
|
+
TestConnection.password = 'password'
|
50
|
+
TestConnection.expects(:make_call).with('login','foobar','password').returns("token")
|
51
|
+
TestConnection.login
|
52
|
+
|
53
|
+
TestConnection.username = 'foobar2'
|
54
|
+
TestConnection.password = 'password2'
|
55
|
+
TestConnection.expects(:make_call).with('login','foobar2','password2').never
|
56
|
+
TestConnection.login
|
57
|
+
end
|
58
|
+
end
|
59
|
+
it "should provide a way to connect to the cobbler server" do
|
60
|
+
TestConnection.should respond_to(:connect)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should connect to the cobbler server" do
|
64
|
+
TestConnection.hostname = 'localhost'
|
65
|
+
@connection = Object.new
|
66
|
+
XMLRPC::Client.expects(:new2).with('http://localhost/cobbler_api').returns(@connection)
|
67
|
+
TestConnection.send(:connect)
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "making a call" do
|
71
|
+
it "should raise an exception if no connection have been established so far" do
|
72
|
+
TestConnection.expects(:connection).returns(nil)
|
73
|
+
lambda { TestConnection.make_call('foobar') }.should raise_error(Exception)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should pass all arguments to the connection and return the resul" do
|
77
|
+
connection = Object.new
|
78
|
+
connection.expects(:call).with('foo','bar').returns('juhu')
|
79
|
+
TestConnection.expects(:connection).twice.returns(connection)
|
80
|
+
TestConnection.make_call('foo','bar')
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "handling transactions" do
|
85
|
+
it "should initialze and end a connection" do
|
86
|
+
TestConnection.expects(:begin_transaction)
|
87
|
+
TestConnection.expects(:end_transaction)
|
88
|
+
TestConnection.send(:in_transaction) do
|
89
|
+
#
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should cleanup the connection" do
|
94
|
+
TestConnection.expects(:connect).returns('foobar')
|
95
|
+
TestConnection.in_transaction do
|
96
|
+
#
|
97
|
+
end
|
98
|
+
TestConnection.send(:connection).should be_nil
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should login if you want a login and pass the token into the transaction and logout" do
|
102
|
+
connection = Object.new
|
103
|
+
TestConnection.expects(:login).returns('token')
|
104
|
+
TestConnection.expects(:logout)
|
105
|
+
TestConnection.expects(:connect).returns('foobar')
|
106
|
+
TestConnection.in_transaction(true) do |token|
|
107
|
+
token.should == 'token'
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should ensure that the connection is cleaned up" do
|
112
|
+
TestConnection.expects(:connect).returns('foobar')
|
113
|
+
lambda { TestConnection.in_transaction do
|
114
|
+
raise "foobar"
|
115
|
+
end }.should raise_error(Exception)
|
116
|
+
TestConnection.send(:connection).should be_nil
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|