1
|
require 'rubygems'
|
2
|
require 'minitest/autorun'
|
3
|
|
4
|
module Resources
|
5
|
module TestUserBase
|
6
|
def setup
|
7
|
@username = 'integration_test_user'
|
8
|
@resource = TestRuncible.server.resources.user
|
9
|
end
|
10
|
end
|
11
|
|
12
|
class TestUserCreate < MiniTest::Unit::TestCase
|
13
|
include TestUserBase
|
14
|
|
15
|
def teardown
|
16
|
@resource.delete(@username)
|
17
|
ensure
|
18
|
super
|
19
|
end
|
20
|
|
21
|
def test_create
|
22
|
response = @resource.create(@username)
|
23
|
|
24
|
assert_equal 201, response.code
|
25
|
assert_equal @username, response['login']
|
26
|
end
|
27
|
|
28
|
def test_create_with_name_and_password
|
29
|
response = @resource.create(@username, :name => @username, :password => 'integration_test_password')
|
30
|
|
31
|
assert_equal 201, response.code
|
32
|
assert_equal @username, response['name']
|
33
|
end
|
34
|
end
|
35
|
|
36
|
class TestUser < MiniTest::Unit::TestCase
|
37
|
include TestUserBase
|
38
|
|
39
|
def setup
|
40
|
super
|
41
|
begin
|
42
|
@resource.retrieve(@username)
|
43
|
rescue RestClient::ResourceNotFound
|
44
|
@resource.create(@username)
|
45
|
end
|
46
|
end
|
47
|
|
48
|
def teardown
|
49
|
@resource.delete(@username)
|
50
|
rescue RestClient::ResourceNotFound => e
|
51
|
puts "Could not destroy user #{@username}. Exception \n #{e}"
|
52
|
ensure
|
53
|
super
|
54
|
end
|
55
|
|
56
|
def test_path
|
57
|
path = @resource.class.path
|
58
|
|
59
|
assert_match 'users/', path
|
60
|
end
|
61
|
|
62
|
def test_path_with_username
|
63
|
path = @resource.class.path(@username)
|
64
|
|
65
|
assert_match "users/#{@username}", path
|
66
|
end
|
67
|
|
68
|
def test_retrieve
|
69
|
response = @resource.retrieve(@username)
|
70
|
|
71
|
assert_equal 200, response.code
|
72
|
assert_equal @username, response['login']
|
73
|
end
|
74
|
|
75
|
def test_retrieve_all
|
76
|
response = @resource.retrieve_all
|
77
|
|
78
|
assert_equal 200, response.code
|
79
|
refute_empty response
|
80
|
end
|
81
|
|
82
|
def test_delete
|
83
|
response = @resource.delete(@username)
|
84
|
|
85
|
assert_equal 200, response.code
|
86
|
end
|
87
|
end
|
88
|
end
|