File tree Expand file tree Collapse file tree
lib/netbox_client_ruby/api/tenancy
netbox_client_ruby/api/tenancy Expand file tree Collapse file tree Original file line number Diff line number Diff 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
1415end
Original file line number Diff line number Diff line change 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}
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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}
Original file line number Diff line number Diff line change 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
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
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
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
Original file line number Diff line number Diff line change 33require 'spec_helper'
44
55RSpec . 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' ) }
You can’t perform that action at this time.
0 commit comments