Skip to content

Commit e3c1eae

Browse files
fr3nch13thde
authored andcommitted
Adds Parent/Child relationship to Contact Groups.
1 parent 5a9d0bb commit e3c1eae

6 files changed

Lines changed: 63 additions & 17 deletions

File tree

lib/netbox_client_ruby/api/tenancy/contact_group.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class ContactGroup
99
deletable true
1010
path 'tenancy/contact-groups/:id/'
1111
creation_path 'tenancy/contact-groups/'
12+
object_fields parent: proc { |raw_data| ContactGroup.new raw_data['id'] }
1213
end
1314
end
1415
end
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"id": 1,
3-
"display": "Customer",
4-
"name": "Customer",
5-
"slug": "customer",
6-
"description": "Customer contact group",
7-
"parent": null
3+
"display": "Parent Customers",
4+
"name": "Parent Customers",
5+
"slug": "parent-customers",
6+
"description": "Parent Contact contact group"
87
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"id": 2,
3+
"display": "Child Customers",
4+
"name": "Child Customers",
5+
"slug": "child-customers",
6+
"description": "Child contact group",
7+
"parent": {
8+
"id": 1,
9+
"url": "http://localhost/api/tenancy/contact_groups/1/",
10+
"display": "Parent Customers",
11+
"name": "Parent Customers",
12+
"slug": "parent-customers",
13+
"description": "Parent Contact contact group"
14+
}
15+
}
Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
{
2-
"count": 1,
2+
"count": 2,
33
"next": null,
44
"previous": null,
55
"results": [
66
{
77
"id": 1,
8-
"display": "Customer",
9-
"name": "Customer",
10-
"slug": "customer",
11-
"description": "Customer contact group",
8+
"display": "Customers",
9+
"name": "Customers",
10+
"slug": "customers",
11+
"description": "Parent Contact contact group",
1212
"parent": null
13+
},
14+
{
15+
"id": 2,
16+
"display": "East Coast Customers",
17+
"name": "East Coast Customers",
18+
"slug": "east-coast-customers",
19+
"description": "Child contact group",
20+
"parent": {
21+
"id": 1,
22+
"url": "http://localhost/api/tenancy/contact_groups/1/",
23+
"display": "Customers",
24+
"name": "Customers",
25+
"slug": "customers",
26+
"description": "Parent Contact contact group"
27+
}
1328
}
1429
]
1530
}

spec/netbox_client_ruby/api/tenancy/contact_group_spec.rb

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,23 @@
2424
end
2525

2626
it 'shall be the expected name' do
27-
expect(subject.name).to eq('Customer')
27+
expect(subject.name).to eq('Parent Customers')
28+
end
29+
end
30+
31+
describe '.parent' do
32+
it 'should be nil' do
33+
expect(subject.parent).to be_nil
34+
end
35+
36+
context 'Child Contact Group' do
37+
let(:contact_group_id) { 2 }
38+
39+
it 'should be a Contact Group object' do
40+
parent_contact_group = subject.parent
41+
expect(parent_contact_group).to be_a NetboxClientRuby::Tenancy::ContactGroup
42+
expect(parent_contact_group.id).to eq(1)
43+
end
2844
end
2945
end
3046

@@ -45,7 +61,7 @@
4561

4662
it 'should update the object' do
4763
expect(faraday).to receive(request_method).and_call_original
48-
expect(subject.update(name: 'noob').name).to eq('Customer')
64+
expect(subject.update(name: 'noob').name).to eq('Parent Customers')
4965
end
5066
end
5167

@@ -91,8 +107,8 @@
91107
expect(faraday).to receive(request_method).and_call_original
92108

93109
subject.save
94-
expect(subject.name).to eq('Customer')
95-
expect(subject.slug).to eq('customer')
110+
expect(subject.name).to eq('Parent Customers')
111+
expect(subject.slug).to eq('parent-customers')
96112
end
97113
end
98114

@@ -127,8 +143,8 @@
127143
subject.save
128144

129145
expect(subject.id).to be(1)
130-
expect(subject.name).to eq('Customer')
131-
expect(subject.slug).to eq('customer')
146+
expect(subject.name).to eq('Parent Customers')
147+
expect(subject.slug).to eq('parent-customers')
132148
end
133149
end
134150
end

spec/netbox_client_ruby/api/tenancy/contacts_groups_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'spec_helper'
44

55
RSpec.describe NetboxClientRuby::Tenancy::ContactGroups, faraday_stub: true do
6-
let(:expected_number_of_items) { 1 }
6+
let(:expected_number_of_items) { 2 }
77
let(:expected_singular_type) { NetboxClientRuby::Tenancy::ContactGroup }
88

99
let(:response) { File.read('spec/fixtures/tenancy/contact-groups.json') }

0 commit comments

Comments
 (0)