ridley 4.2.0 → 4.3.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile +1 -1
- data/README.md +4 -4
- data/lib/ridley/connection.rb +1 -2
- data/lib/ridley/errors.rb +1 -0
- data/lib/ridley/mixin/params_validate.rb +4 -0
- data/lib/ridley/version.rb +1 -1
- data/ridley.gemspec +2 -2
- data/spec/acceptance/client_resource_spec.rb +12 -12
- data/spec/acceptance/cookbook_resource_spec.rb +15 -15
- data/spec/acceptance/data_bag_item_resource_spec.rb +14 -14
- data/spec/acceptance/data_bag_resource_spec.rb +4 -4
- data/spec/acceptance/environment_resource_spec.rb +14 -14
- data/spec/acceptance/node_resource_spec.rb +15 -15
- data/spec/acceptance/role_resource_spec.rb +14 -14
- data/spec/acceptance/sandbox_resource_spec.rb +3 -3
- data/spec/acceptance/search_resource_spec.rb +6 -6
- data/spec/acceptance/user_resource_spec.rb +21 -21
- data/spec/support/each_matcher.rb +2 -2
- data/spec/support/filepath_matchers.rb +2 -2
- data/spec/support/shared_examples/ridley_resource.rb +39 -39
- data/spec/unit/ridley/chef/cookbook/metadata_spec.rb +8 -8
- data/spec/unit/ridley/chef/cookbook/syntax_check_spec.rb +15 -15
- data/spec/unit/ridley/chef/cookbook_spec.rb +124 -118
- data/spec/unit/ridley/chef/digester_spec.rb +2 -2
- data/spec/unit/ridley/chef_object_spec.rb +35 -35
- data/spec/unit/ridley/chef_objects/client_object_spec.rb +2 -2
- data/spec/unit/ridley/chef_objects/cookbook_object_spec.rb +12 -12
- data/spec/unit/ridley/chef_objects/data_bag_item_object_spec.rb +7 -7
- data/spec/unit/ridley/chef_objects/data_bag_object_spec.rb +4 -1
- data/spec/unit/ridley/chef_objects/environment_object_spec.rb +10 -10
- data/spec/unit/ridley/chef_objects/node_object_spec.rb +28 -28
- data/spec/unit/ridley/chef_objects/role_object_spec.rb +10 -10
- data/spec/unit/ridley/chef_objects/sandbox_object_spec.rb +6 -6
- data/spec/unit/ridley/client_spec.rb +59 -21
- data/spec/unit/ridley/connection_spec.rb +7 -7
- data/spec/unit/ridley/errors_spec.rb +3 -3
- data/spec/unit/ridley/middleware/chef_auth_spec.rb +2 -2
- data/spec/unit/ridley/middleware/chef_response_spec.rb +29 -29
- data/spec/unit/ridley/middleware/parse_json_spec.rb +14 -14
- data/spec/unit/ridley/mixins/from_file_spec.rb +3 -3
- data/spec/unit/ridley/resource_spec.rb +5 -5
- data/spec/unit/ridley/resources/cookbook_resource_spec.rb +10 -10
- data/spec/unit/ridley/resources/data_bag_item_resource_spec.rb +1 -1
- data/spec/unit/ridley/resources/data_bag_resource_spec.rb +6 -3
- data/spec/unit/ridley/resources/environment_resource_spec.rb +4 -4
- data/spec/unit/ridley/resources/role_resource_spec.rb +1 -1
- data/spec/unit/ridley/resources/sandbox_resource_spec.rb +7 -7
- data/spec/unit/ridley/resources/search_resource_spec.rb +22 -22
- data/spec/unit/ridley/sandbox_uploader_spec.rb +3 -3
- data/spec/unit/ridley_spec.rb +6 -6
- metadata +15 -18
- data/lib/ridley/middleware/gzip.rb +0 -18
- data/spec/unit/ridley/middleware/gzip_spec.rb +0 -59
@@ -11,7 +11,7 @@ describe "Node API operations", type: "acceptance" do
|
|
11
11
|
before { chef_node(node_name) }
|
12
12
|
|
13
13
|
it "returns a Ridley::NodeObject" do
|
14
|
-
connection.node.find(node_name).
|
14
|
+
expect(connection.node.find(node_name)).to be_a(Ridley::NodeObject)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -19,13 +19,13 @@ describe "Node API operations", type: "acceptance" do
|
|
19
19
|
let(:node_name) { "ridley.localhost" }
|
20
20
|
|
21
21
|
it "returns a new Ridley::NodeObject object" do
|
22
|
-
connection.node.create(name: node_name).
|
22
|
+
expect(connection.node.create(name: node_name)).to be_a(Ridley::NodeObject)
|
23
23
|
end
|
24
24
|
|
25
25
|
it "adds a new node to the server" do
|
26
26
|
connection.node.create(name: node_name)
|
27
27
|
|
28
|
-
connection.node.all.
|
28
|
+
expect(connection.node.all.size).to eq(1)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -34,13 +34,13 @@ describe "Node API operations", type: "acceptance" do
|
|
34
34
|
before { chef_node(node_name) }
|
35
35
|
|
36
36
|
it "returns a Ridley::NodeObject" do
|
37
|
-
connection.node.delete(node_name).
|
37
|
+
expect(connection.node.delete(node_name)).to be_a(Ridley::NodeObject)
|
38
38
|
end
|
39
39
|
|
40
40
|
it "removes the node from the server" do
|
41
41
|
connection.node.delete(node_name)
|
42
42
|
|
43
|
-
connection.node.find(node_name).
|
43
|
+
expect(connection.node.find(node_name)).to be_nil
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -53,7 +53,7 @@ describe "Node API operations", type: "acceptance" do
|
|
53
53
|
it "deletes all nodes from the remote server" do
|
54
54
|
connection.node.delete_all
|
55
55
|
|
56
|
-
connection.node.all.
|
56
|
+
expect(connection.node.all.size).to eq(0)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -66,8 +66,8 @@ describe "Node API operations", type: "acceptance" do
|
|
66
66
|
it "returns an array of Ridley::NodeObject" do
|
67
67
|
obj = connection.node.all
|
68
68
|
|
69
|
-
obj.
|
70
|
-
obj.
|
69
|
+
expect(obj).to each be_a(Ridley::NodeObject)
|
70
|
+
expect(obj.size).to eq(2)
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -77,7 +77,7 @@ describe "Node API operations", type: "acceptance" do
|
|
77
77
|
let(:target) { connection.node.find(node_name) }
|
78
78
|
|
79
79
|
it "returns the updated node" do
|
80
|
-
connection.node.update(target).
|
80
|
+
expect(connection.node.update(target)).to eql(target)
|
81
81
|
end
|
82
82
|
|
83
83
|
it "saves a new set of 'normal' attributes" do
|
@@ -91,7 +91,7 @@ describe "Node API operations", type: "acceptance" do
|
|
91
91
|
connection.node.update(target)
|
92
92
|
obj = connection.node.find(target)
|
93
93
|
|
94
|
-
obj.normal.
|
94
|
+
expect(obj.normal).to eql(normal)
|
95
95
|
end
|
96
96
|
|
97
97
|
it "saves a new set of 'default' attributes" do
|
@@ -105,7 +105,7 @@ describe "Node API operations", type: "acceptance" do
|
|
105
105
|
connection.node.update(target)
|
106
106
|
obj = connection.node.find(target)
|
107
107
|
|
108
|
-
obj.default.
|
108
|
+
expect(obj.default).to eql(defaults)
|
109
109
|
end
|
110
110
|
|
111
111
|
it "saves a new set of 'automatic' attributes" do
|
@@ -119,7 +119,7 @@ describe "Node API operations", type: "acceptance" do
|
|
119
119
|
connection.node.update(target)
|
120
120
|
obj = connection.node.find(target)
|
121
121
|
|
122
|
-
obj.automatic.
|
122
|
+
expect(obj.automatic).to eql(automatics)
|
123
123
|
end
|
124
124
|
|
125
125
|
it "saves a new set of 'override' attributes" do
|
@@ -133,7 +133,7 @@ describe "Node API operations", type: "acceptance" do
|
|
133
133
|
connection.node.update(target)
|
134
134
|
obj = connection.node.find(target)
|
135
135
|
|
136
|
-
obj.override.
|
136
|
+
expect(obj.override).to eql(overrides)
|
137
137
|
end
|
138
138
|
|
139
139
|
it "places a node in a new 'chef_environment'" do
|
@@ -142,7 +142,7 @@ describe "Node API operations", type: "acceptance" do
|
|
142
142
|
connection.node.update(target)
|
143
143
|
obj = connection.node.find(target)
|
144
144
|
|
145
|
-
obj.chef_environment.
|
145
|
+
expect(obj.chef_environment).to eql(environment)
|
146
146
|
end
|
147
147
|
|
148
148
|
it "saves a new 'run_list' for the node" do
|
@@ -151,7 +151,7 @@ describe "Node API operations", type: "acceptance" do
|
|
151
151
|
connection.node.update(target)
|
152
152
|
obj = connection.node.find(target)
|
153
153
|
|
154
|
-
obj.run_list.
|
154
|
+
expect(obj.run_list).to eql(run_list)
|
155
155
|
end
|
156
156
|
end
|
157
157
|
end
|
@@ -11,7 +11,7 @@ describe "Role API operations", type: "acceptance" do
|
|
11
11
|
before { chef_role(role_name) }
|
12
12
|
|
13
13
|
it "returns a Ridley::RoleObject" do
|
14
|
-
connection.role.find(role_name).
|
14
|
+
expect(connection.role.find(role_name)).to be_a(Ridley::RoleObject)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -19,12 +19,12 @@ describe "Role API operations", type: "acceptance" do
|
|
19
19
|
let(:role_name) { "ridley-role" }
|
20
20
|
|
21
21
|
it "returns a new Ridley::RoleObject" do
|
22
|
-
connection.role.create(name: role_name).
|
22
|
+
expect(connection.role.create(name: role_name)).to be_a(Ridley::RoleObject)
|
23
23
|
end
|
24
24
|
|
25
25
|
it "adds a new role to the server" do
|
26
26
|
connection.role.create(name: role_name)
|
27
|
-
connection.role.all.
|
27
|
+
expect(connection.role.all.size).to eq(1)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -33,13 +33,13 @@ describe "Role API operations", type: "acceptance" do
|
|
33
33
|
before { chef_role(role_name) }
|
34
34
|
|
35
35
|
it "returns the deleted Ridley::RoleObject resource" do
|
36
|
-
connection.role.delete(role_name).
|
36
|
+
expect(connection.role.delete(role_name)).to be_a(Ridley::RoleObject)
|
37
37
|
end
|
38
38
|
|
39
39
|
it "removes the role from the server" do
|
40
40
|
connection.role.delete(role_name)
|
41
41
|
|
42
|
-
connection.role.find(role_name).
|
42
|
+
expect(connection.role.find(role_name)).to be_nil
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -52,7 +52,7 @@ describe "Role API operations", type: "acceptance" do
|
|
52
52
|
it "deletes all nodes from the remote server" do
|
53
53
|
connection.role.delete_all
|
54
54
|
|
55
|
-
connection.role.all.
|
55
|
+
expect(connection.role.all.size).to eq(0)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -65,8 +65,8 @@ describe "Role API operations", type: "acceptance" do
|
|
65
65
|
it "should return an array of Ridley::RoleObject" do
|
66
66
|
obj = connection.role.all
|
67
67
|
|
68
|
-
obj.
|
69
|
-
obj.
|
68
|
+
expect(obj.size).to eq(2)
|
69
|
+
expect(obj).to each be_a(Ridley::RoleObject)
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -76,7 +76,7 @@ describe "Role API operations", type: "acceptance" do
|
|
76
76
|
let(:target) { connection.role.find(role_name) }
|
77
77
|
|
78
78
|
it "returns an updated Ridley::RoleObject object" do
|
79
|
-
connection.role.update(target).
|
79
|
+
expect(connection.role.update(target)).to eql(target)
|
80
80
|
end
|
81
81
|
|
82
82
|
it "saves a new run_list" do
|
@@ -85,7 +85,7 @@ describe "Role API operations", type: "acceptance" do
|
|
85
85
|
connection.role.update(target)
|
86
86
|
obj = connection.role.find(target)
|
87
87
|
|
88
|
-
obj.run_list.
|
88
|
+
expect(obj.run_list).to eql(run_list)
|
89
89
|
end
|
90
90
|
|
91
91
|
it "saves a new env_run_lists" do
|
@@ -97,7 +97,7 @@ describe "Role API operations", type: "acceptance" do
|
|
97
97
|
connection.role.update(target)
|
98
98
|
obj = connection.role.find(target)
|
99
99
|
|
100
|
-
obj.env_run_lists.
|
100
|
+
expect(obj.env_run_lists).to eql(env_run_lists)
|
101
101
|
end
|
102
102
|
|
103
103
|
it "saves a new description" do
|
@@ -106,7 +106,7 @@ describe "Role API operations", type: "acceptance" do
|
|
106
106
|
connection.role.update(target)
|
107
107
|
obj = connection.role.find(target)
|
108
108
|
|
109
|
-
obj.description.
|
109
|
+
expect(obj.description).to eql(description)
|
110
110
|
end
|
111
111
|
|
112
112
|
it "saves a new default_attributes" do
|
@@ -120,7 +120,7 @@ describe "Role API operations", type: "acceptance" do
|
|
120
120
|
connection.role.update(target)
|
121
121
|
obj = connection.role.find(target)
|
122
122
|
|
123
|
-
obj.default_attributes.
|
123
|
+
expect(obj.default_attributes).to eql(defaults)
|
124
124
|
end
|
125
125
|
|
126
126
|
it "saves a new override_attributes" do
|
@@ -134,7 +134,7 @@ describe "Role API operations", type: "acceptance" do
|
|
134
134
|
connection.role.update(target)
|
135
135
|
obj = connection.role.find(target)
|
136
136
|
|
137
|
-
obj.override_attributes.
|
137
|
+
expect(obj.override_attributes).to eql(overrides)
|
138
138
|
end
|
139
139
|
end
|
140
140
|
end
|
@@ -15,15 +15,15 @@ describe "Sandbox API operations", type: "acceptance" do
|
|
15
15
|
|
16
16
|
describe "creating a new sandbox" do
|
17
17
|
it "returns an instance of Ridley::SandboxObject" do
|
18
|
-
connection.sandbox.create(checksums).
|
18
|
+
expect(connection.sandbox.create(checksums)).to be_a(Ridley::SandboxObject)
|
19
19
|
end
|
20
20
|
|
21
21
|
it "contains a value for sandbox_id" do
|
22
|
-
connection.sandbox.create(checksums).sandbox_id.
|
22
|
+
expect(connection.sandbox.create(checksums).sandbox_id).not_to be_nil
|
23
23
|
end
|
24
24
|
|
25
25
|
it "returns an instance with the same amount of checksums given to create" do
|
26
|
-
connection.sandbox.create(checksums).checksums.
|
26
|
+
expect(connection.sandbox.create(checksums).checksums.size).to eq(2)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -10,18 +10,18 @@ describe "Search API operations", type: "acceptance" do
|
|
10
10
|
it "returns an array of indexes" do
|
11
11
|
indexes = connection.search_indexes
|
12
12
|
|
13
|
-
indexes.
|
14
|
-
indexes.
|
15
|
-
indexes.
|
16
|
-
indexes.
|
13
|
+
expect(indexes).to include("role")
|
14
|
+
expect(indexes).to include("node")
|
15
|
+
expect(indexes).to include("client")
|
16
|
+
expect(indexes).to include("environment")
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
describe "searching an index that doesn't exist" do
|
21
21
|
it "it raises a Ridley::Errors::HTTPNotFound error" do
|
22
|
-
|
22
|
+
expect {
|
23
23
|
connection.search(:notthere)
|
24
|
-
}.
|
24
|
+
}.to raise_error(Ridley::Errors::HTTPNotFound)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -11,30 +11,30 @@ describe "User API operations", type: "wip" do
|
|
11
11
|
before { chef_user("reset", admin: false) }
|
12
12
|
|
13
13
|
it "returns a UserObject" do
|
14
|
-
connection.user.find("reset").
|
14
|
+
expect(connection.user.find("reset")).to be_a(Ridley::UserObject)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
context "when the server does not have the user" do
|
19
19
|
it "returns a nil value" do
|
20
|
-
connection.user.find("not_there").
|
20
|
+
expect(connection.user.find("not_there")).to be_nil
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
describe "creating a user" do
|
26
26
|
it "returns a Ridley::UserObject" do
|
27
|
-
connection.user.create(name: "reset").
|
27
|
+
expect(connection.user.create(name: "reset")).to be_a(Ridley::UserObject)
|
28
28
|
end
|
29
29
|
|
30
30
|
it "adds a user to the chef server" do
|
31
31
|
old = connection.user.all.length
|
32
32
|
connection.user.create(name: "reset")
|
33
|
-
connection.user.all.
|
33
|
+
expect(connection.user.all.size).to eq(old + 1)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "has a value for #private_key" do
|
37
|
-
connection.user.create(name: "reset").private_key.
|
37
|
+
expect(connection.user.create(name: "reset").private_key).not_to be_nil
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -42,13 +42,13 @@ describe "User API operations", type: "wip" do
|
|
42
42
|
before { chef_user("reset", admin: false) }
|
43
43
|
|
44
44
|
it "returns a Ridley::UserObject object" do
|
45
|
-
connection.user.delete("reset").
|
45
|
+
expect(connection.user.delete("reset")).to be_a(Ridley::UserObject)
|
46
46
|
end
|
47
47
|
|
48
48
|
it "removes the user from the server" do
|
49
49
|
connection.user.delete("reset")
|
50
50
|
|
51
|
-
connection.user.find("reset").
|
51
|
+
expect(connection.user.find("reset")).to be_nil
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
@@ -59,12 +59,12 @@ describe "User API operations", type: "wip" do
|
|
59
59
|
end
|
60
60
|
|
61
61
|
it "returns an array of Ridley::UserObject objects" do
|
62
|
-
connection.user.delete_all.
|
62
|
+
expect(connection.user.delete_all).to each be_a(Ridley::UserObject)
|
63
63
|
end
|
64
64
|
|
65
65
|
it "deletes all users from the remote" do
|
66
66
|
connection.user.delete_all
|
67
|
-
connection.user.all.
|
67
|
+
expect(connection.user.all.size).to eq(0)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -75,11 +75,11 @@ describe "User API operations", type: "wip" do
|
|
75
75
|
end
|
76
76
|
|
77
77
|
it "returns an array of Ridley::UserObject objects" do
|
78
|
-
connection.user.all.
|
78
|
+
expect(connection.user.all).to each be_a(Ridley::UserObject)
|
79
79
|
end
|
80
80
|
|
81
81
|
it "returns all of the users on the server" do
|
82
|
-
connection.user.all.
|
82
|
+
expect(connection.user.all.size).to eq(3)
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
@@ -87,7 +87,7 @@ describe "User API operations", type: "wip" do
|
|
87
87
|
before { chef_user("reset", admin: false) }
|
88
88
|
|
89
89
|
it "returns a Ridley::UserObject object with a value for #private_key" do
|
90
|
-
connection.user.regenerate_key("reset").private_key.
|
90
|
+
expect(connection.user.regenerate_key("reset").private_key).to match(/^-----BEGIN RSA PRIVATE KEY-----/)
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
@@ -95,20 +95,20 @@ describe "User API operations", type: "wip" do
|
|
95
95
|
before { chef_user('reset', password: 'swordfish') }
|
96
96
|
|
97
97
|
it "returns true when given valid username & password" do
|
98
|
-
expect(connection.user.authenticate('reset', 'swordfish')).to
|
98
|
+
expect(connection.user.authenticate('reset', 'swordfish')).to be_truthy
|
99
99
|
end
|
100
100
|
|
101
101
|
it "returns false when given valid username & invalid password" do
|
102
|
-
expect(connection.user.authenticate('reset', "not a swordfish")).to
|
102
|
+
expect(connection.user.authenticate('reset', "not a swordfish")).to be_falsey
|
103
103
|
end
|
104
104
|
|
105
105
|
it "returns false when given invalid username & valid password" do
|
106
|
-
expect(connection.user.authenticate("someone-else", 'swordfish')).to
|
106
|
+
expect(connection.user.authenticate("someone-else", 'swordfish')).to be_falsey
|
107
107
|
end
|
108
108
|
|
109
109
|
it "works also on a User object level" do
|
110
|
-
expect(connection.user.find('reset').authenticate('swordfish')).to
|
111
|
-
expect(connection.user.find('reset').authenticate('not a swordfish')).to
|
110
|
+
expect(connection.user.find('reset').authenticate('swordfish')).to be_truthy
|
111
|
+
expect(connection.user.find('reset').authenticate('not a swordfish')).to be_falsey
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
@@ -117,14 +117,14 @@ describe "User API operations", type: "wip" do
|
|
117
117
|
subject { connection.user.find('reset') }
|
118
118
|
|
119
119
|
it "changes the password with which user can authenticate" do
|
120
|
-
expect(subject.authenticate('swordfish')).to
|
121
|
-
expect(subject.authenticate('salmon')).to
|
120
|
+
expect(subject.authenticate('swordfish')).to be_truthy
|
121
|
+
expect(subject.authenticate('salmon')).to be_falsey
|
122
122
|
|
123
123
|
subject.password = 'salmon'
|
124
124
|
subject.save
|
125
125
|
|
126
|
-
expect(subject.authenticate('swordfish')).to
|
127
|
-
expect(subject.authenticate('salmon')).to
|
126
|
+
expect(subject.authenticate('swordfish')).to be_falsey
|
127
|
+
expect(subject.authenticate('salmon')).to be_truthy
|
128
128
|
end
|
129
129
|
end
|
130
130
|
end
|
@@ -2,11 +2,11 @@ RSpec::Matchers.define :each do |check|
|
|
2
2
|
match do |actual|
|
3
3
|
actual.each_with_index do |index, o|
|
4
4
|
@object = o
|
5
|
-
index.
|
5
|
+
expect(index).to check
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
-
|
9
|
+
failure_message do |actual|
|
10
10
|
"at[#{@object}] #{check.failure_message_for_should}"
|
11
11
|
end
|
12
12
|
end
|
@@ -9,11 +9,11 @@ RSpec::Matchers.define :be_relative_path do
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
|
12
|
+
failure_message do |given|
|
13
13
|
"Expected '#{given}' to be a relative path but got an absolute path."
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
failure_message_when_negated do |given|
|
17
17
|
"Expected '#{given}' to not be a relative path but got an absolute path."
|
18
18
|
end
|
19
19
|
end
|
@@ -9,8 +9,8 @@ shared_examples_for "a Ridley Resource" do |resource_klass|
|
|
9
9
|
|
10
10
|
describe "::all" do
|
11
11
|
it "sends a get request for the class' resource_path using the given client" do
|
12
|
-
response.
|
13
|
-
client.connection.
|
12
|
+
allow(response).to receive(:body) { Hash.new }
|
13
|
+
expect(client.connection).to receive(:get).with(subject.resource_path).and_return(response)
|
14
14
|
|
15
15
|
subject.all(client)
|
16
16
|
end
|
@@ -19,8 +19,8 @@ shared_examples_for "a Ridley Resource" do |resource_klass|
|
|
19
19
|
describe "::find" do
|
20
20
|
it "sends a get request to the given client to the resource_path of the class for the given chef_id" do
|
21
21
|
chef_id = "ridley_test"
|
22
|
-
response.
|
23
|
-
client.connection.
|
22
|
+
allow(response).to receive(:body) { Hash.new }
|
23
|
+
expect(client.connection).to receive(:get).with("#{subject.resource_path}/#{chef_id}").and_return(response)
|
24
24
|
|
25
25
|
subject.find(client, chef_id)
|
26
26
|
end
|
@@ -33,8 +33,8 @@ shared_examples_for "a Ridley Resource" do |resource_klass|
|
|
33
33
|
last_name: "winsor"
|
34
34
|
}
|
35
35
|
|
36
|
-
response.
|
37
|
-
client.connection.
|
36
|
+
allow(response).to receive(:body) { attrs }
|
37
|
+
expect(client.connection).to receive(:post).with(subject.resource_path, duck_type(:to_json)).and_return(response)
|
38
38
|
|
39
39
|
subject.create(client, attrs)
|
40
40
|
end
|
@@ -42,17 +42,17 @@ shared_examples_for "a Ridley Resource" do |resource_klass|
|
|
42
42
|
|
43
43
|
describe "::delete" do
|
44
44
|
it "sends a delete request to the given client using the includer's resource_path for the given string" do
|
45
|
-
response.
|
46
|
-
client.connection.
|
45
|
+
allow(response).to receive(:body) { Hash.new }
|
46
|
+
expect(client.connection).to receive(:delete).with("#{subject.resource_path}/ridley-test").and_return(response)
|
47
47
|
|
48
48
|
subject.delete(client, "ridley-test")
|
49
49
|
end
|
50
50
|
|
51
51
|
it "accepts an object that responds to 'chef_id'" do
|
52
52
|
object = double("obj")
|
53
|
-
object.
|
54
|
-
response.
|
55
|
-
client.connection.
|
53
|
+
allow(object).to receive(:chef_id) { "hello" }
|
54
|
+
allow(response).to receive(:body) { Hash.new }
|
55
|
+
expect(client.connection).to receive(:delete).with("#{subject.resource_path}/#{object.chef_id}").and_return(response)
|
56
56
|
|
57
57
|
subject.delete(client, object)
|
58
58
|
end
|
@@ -60,17 +60,17 @@ shared_examples_for "a Ridley Resource" do |resource_klass|
|
|
60
60
|
|
61
61
|
describe "::delete_all" do
|
62
62
|
it "sends a delete request for every object in the collection" do
|
63
|
-
|
63
|
+
skip
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
67
|
describe "::update" do
|
68
68
|
it "sends a put request to the given client using the includer's resource_path with the given object" do
|
69
|
-
subject.
|
69
|
+
allow(subject).to receive(:chef_id) { :name }
|
70
70
|
subject.attribute(:name)
|
71
71
|
object = subject.new(name: "hello")
|
72
|
-
response.
|
73
|
-
client.connection.
|
72
|
+
allow(response).to receive(:body) { Hash.new }
|
73
|
+
expect(client.connection).to receive(:put).with("#{subject.resource_path}/#{object.chef_id}", duck_type(:to_json)).and_return(response)
|
74
74
|
|
75
75
|
subject.update(client, object)
|
76
76
|
end
|
@@ -81,12 +81,12 @@ shared_examples_for "a Ridley Resource" do |resource_klass|
|
|
81
81
|
|
82
82
|
describe "#save" do
|
83
83
|
context "when the object is valid" do
|
84
|
-
before(:each) { subject.
|
84
|
+
before(:each) { allow(subject).to receive(:valid?).and_return(true) }
|
85
85
|
|
86
86
|
it "sends a create message to the implementing class" do
|
87
87
|
updated = double('updated')
|
88
|
-
updated.
|
89
|
-
subject.class.
|
88
|
+
allow(updated).to receive(:_attributes_).and_return(Hash.new)
|
89
|
+
expect(subject.class).to receive(:create).with(client, subject).and_return(updated)
|
90
90
|
|
91
91
|
subject.save
|
92
92
|
end
|
@@ -94,10 +94,10 @@ shared_examples_for "a Ridley Resource" do |resource_klass|
|
|
94
94
|
context "when there is an HTTPConflict" do
|
95
95
|
it "sends the update message to self" do
|
96
96
|
updated = double('updated')
|
97
|
-
updated.
|
98
|
-
updated.
|
99
|
-
subject.class.
|
100
|
-
subject.
|
97
|
+
allow(updated).to receive(:[]).and_return(Hash.new)
|
98
|
+
allow(updated).to receive(:_attributes_).and_return(Hash.new)
|
99
|
+
expect(subject.class).to receive(:create).and_raise(Ridley::Errors::HTTPConflict.new(updated))
|
100
|
+
expect(subject).to receive(:update).and_return(updated)
|
101
101
|
|
102
102
|
subject.save
|
103
103
|
end
|
@@ -105,12 +105,12 @@ shared_examples_for "a Ridley Resource" do |resource_klass|
|
|
105
105
|
end
|
106
106
|
|
107
107
|
context "when the object is invalid" do
|
108
|
-
before(:each) { subject.
|
108
|
+
before(:each) { allow(subject).to receive(:valid?).and_return(false) }
|
109
109
|
|
110
110
|
it "raises an InvalidResource error" do
|
111
|
-
|
111
|
+
expect {
|
112
112
|
subject.save
|
113
|
-
}.
|
113
|
+
}.to raise_error(Ridley::Errors::InvalidResource)
|
114
114
|
end
|
115
115
|
end
|
116
116
|
end
|
@@ -119,31 +119,31 @@ shared_examples_for "a Ridley Resource" do |resource_klass|
|
|
119
119
|
context "when the object is valid" do
|
120
120
|
let(:updated) do
|
121
121
|
updated = double('updated')
|
122
|
-
updated.
|
123
|
-
updated.
|
122
|
+
allow(updated).to receive(:[]).and_return(Hash.new)
|
123
|
+
allow(updated).to receive(:_attributes_).and_return(Hash.new)
|
124
124
|
updated
|
125
125
|
end
|
126
126
|
|
127
|
-
before(:each) { subject.
|
127
|
+
before(:each) { allow(subject).to receive(:valid?).and_return(true) }
|
128
128
|
|
129
129
|
it "sends an update message to the implementing class" do
|
130
|
-
subject.class.
|
130
|
+
expect(subject.class).to receive(:update).with(anything, subject).and_return(updated)
|
131
131
|
subject.update
|
132
132
|
end
|
133
133
|
|
134
134
|
it "returns true" do
|
135
|
-
subject.class.
|
136
|
-
subject.update.
|
135
|
+
expect(subject.class).to receive(:update).with(anything, subject).and_return(updated)
|
136
|
+
expect(subject.update).to eql(true)
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
140
|
context "when the object is invalid" do
|
141
|
-
before(:each) { subject.
|
141
|
+
before(:each) { allow(subject).to receive(:valid?).and_return(false) }
|
142
142
|
|
143
143
|
it "raises an InvalidResource error" do
|
144
|
-
|
144
|
+
expect {
|
145
145
|
subject.update
|
146
|
-
}.
|
146
|
+
}.to raise_error(Ridley::Errors::InvalidResource)
|
147
147
|
end
|
148
148
|
end
|
149
149
|
end
|
@@ -151,10 +151,10 @@ shared_examples_for "a Ridley Resource" do |resource_klass|
|
|
151
151
|
describe "#chef_id" do
|
152
152
|
it "returns the value of the chef_id attribute" do
|
153
153
|
subject.class.attribute(:name)
|
154
|
-
subject.class.
|
154
|
+
allow(subject.class).to receive(:chef_id) { :name }
|
155
155
|
subject.mass_assign(name: "reset")
|
156
156
|
|
157
|
-
subject.chef_id.
|
157
|
+
expect(subject.chef_id).to eql("reset")
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|
@@ -163,17 +163,17 @@ shared_examples_for "a Ridley Resource" do |resource_klass|
|
|
163
163
|
|
164
164
|
before(:each) do
|
165
165
|
subject.class.attribute(:fake_attribute)
|
166
|
-
subject.class.
|
166
|
+
allow(subject.class).to receive(:find).with(client, subject).and_return(updated_subject)
|
167
167
|
end
|
168
168
|
|
169
169
|
it "returns itself" do
|
170
|
-
subject.reload.
|
170
|
+
expect(subject.reload).to eql(subject)
|
171
171
|
end
|
172
172
|
|
173
173
|
it "sets the attributes of self to include those of the reloaded object" do
|
174
174
|
subject.reload
|
175
175
|
|
176
|
-
subject.get_attribute(:fake_attribute).
|
176
|
+
expect(subject.get_attribute(:fake_attribute)).to eql("some_value")
|
177
177
|
end
|
178
178
|
end
|
179
179
|
end
|