diff --git a/spec/netbox_client_ruby/api/circuits/circuit_spec.rb b/spec/netbox_client_ruby/api/circuits/circuit_spec.rb index 1b0723e..c038f54 100644 --- a/spec/netbox_client_ruby/api/circuits/circuit_spec.rb +++ b/spec/netbox_client_ruby/api/circuits/circuit_spec.rb @@ -1,153 +1,149 @@ require 'spec_helper' -module NetboxClientRuby - module Circuits - RSpec.describe Circuit, faraday_stub: true do - let(:id) { 1 } - let(:base_url) { '/api/circuits/circuits/' } - let(:request_url) { "#{base_url}#{id}.json" } - let(:response) { File.read("spec/fixtures/circuits/circuit_#{id}.json") } - - subject { described_class.new id } - - describe '#id' do - it 'shall be the expected id' do - expect(subject.id).to eq(id) - end - end +RSpec.describe NetboxClientRuby::Circuits::Circuit, faraday_stub: true do + let(:id) { 1 } + let(:base_url) { '/api/circuits/circuits/' } + let(:request_url) { "#{base_url}#{id}.json" } + let(:response) { File.read("spec/fixtures/circuits/circuit_#{id}.json") } - describe '#description' do - it 'should fetch the data' do - expect(faraday).to receive(:get).and_call_original + subject { described_class.new id } - subject.description - end + describe '#id' do + it 'shall be the expected id' do + expect(subject.id).to eq(id) + end + end - it 'shall be the expected description' do - expect(subject.description).to eq('Desc of Circuit 0') - end - end + describe '#description' do + it 'should fetch the data' do + expect(faraday).to receive(:get).and_call_original - describe '.tenant' do - it 'should be a Tenant object' do - tenant = subject.tenant - expect(tenant).to be_a Tenancy::Tenant - expect(tenant.id).to eq(1) - end - end + subject.description + end - describe '.provider' do - it 'should be a Provider object' do - provider = subject.provider - expect(provider).to be_a Provider - expect(provider.id).to eq(1) - end - end + it 'shall be the expected description' do + expect(subject.description).to eq('Desc of Circuit 0') + end + end - describe '.type' do - it 'should be a Type object' do - provider = subject.type - expect(provider).to be_a CircuitType - expect(provider.id).to eq(1) - end - end + describe '.tenant' do + it 'should be a Tenant object' do + tenant = subject.tenant + expect(tenant).to be_a NetboxClientRuby::Tenancy::Tenant + expect(tenant.id).to eq(1) + end + end - describe '.delete' do - let(:request_method) { :delete } - let(:response_status) { 204 } - let(:response) { nil } + describe '.provider' do + it 'should be a Provider object' do + provider = subject.provider + expect(provider).to be_a NetboxClientRuby::Circuits::Provider + expect(provider.id).to eq(1) + end + end - it 'should delete the object' do - expect(faraday).to receive(request_method).and_call_original - subject.delete - end - end + describe '.type' do + it 'should be a Type object' do + provider = subject.type + expect(provider).to be_a NetboxClientRuby::Circuits::CircuitType + expect(provider.id).to eq(1) + end + end - describe '.update' do - let(:request_method) { :patch } - let(:request_params) { { 'description' => 'noob' } } + describe '.delete' do + let(:request_method) { :delete } + let(:response_status) { 204 } + let(:response) { nil } - it 'should update the object' do - expect(faraday).to receive(request_method).and_call_original - expect(subject.update(description: 'noob').description).to eq('Desc of Circuit 0') - end - end + it 'should delete the object' do + expect(faraday).to receive(request_method).and_call_original + subject.delete + end + end - describe '.reload' do - it 'should reload the object' do - expect(faraday).to receive(request_method).twice.and_call_original + describe '.update' do + let(:request_method) { :patch } + let(:request_params) { { 'description' => 'noob' } } - subject.reload - subject.reload - end - end + it 'should update the object' do + expect(faraday).to receive(request_method).and_call_original + expect(subject.update(description: 'noob').description).to eq('Desc of Circuit 0') + end + end - describe '.save' do - let(:description) { 'foobar' } - let(:request_params) { { 'description' => description } } + describe '.reload' do + it 'should reload the object' do + expect(faraday).to receive(request_method).twice.and_call_original - context 'update' do - let(:request_method) { :patch } + subject.reload + subject.reload + end + end - subject do - entity = described_class.new id - entity.description = description - entity - end + describe '.save' do + let(:description) { 'foobar' } + let(:request_params) { { 'description' => description } } - it 'does not call PATCH until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + context 'update' do + let(:request_method) { :patch } - expect(subject.description).to eq(description) - end + subject do + entity = described_class.new id + entity.description = description + entity + end - it 'calls PATCH when save is called' do - expect(faraday).to receive(request_method).and_call_original + it 'does not call PATCH until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) - expect(subject.save).to be(subject) - end + expect(subject.description).to eq(description) + end - it 'Reads the answer from the PATCH answer' do - expect(faraday).to receive(request_method).and_call_original + it 'calls PATCH when save is called' do + expect(faraday).to receive(request_method).and_call_original - subject.save - expect(subject.description).to eq('Desc of Circuit 0') - end - end + expect(subject.save).to be(subject) + end + + it 'Reads the answer from the PATCH answer' do + expect(faraday).to receive(request_method).and_call_original + + subject.save + expect(subject.description).to eq('Desc of Circuit 0') + end + end - context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } + context 'create' do + let(:request_method) { :post } + let(:request_url) { base_url } - subject do - entity = described_class.new - entity.description = description - entity - end + subject do + entity = described_class.new + entity.description = description + entity + end - it 'does not POST until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + it 'does not POST until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) - expect(subject.description).to eq(description) - end + expect(subject.description).to eq(description) + end - it 'POSTs the data upon a call of save' do - expect(faraday).to receive(request_method).and_call_original + it 'POSTs the data upon a call of save' do + expect(faraday).to receive(request_method).and_call_original - expect(subject.save).to be(subject) - end + expect(subject.save).to be(subject) + end - it 'Reads the answer from the POST' do - expect(faraday).to receive(request_method).and_call_original + it 'Reads the answer from the POST' do + expect(faraday).to receive(request_method).and_call_original - subject.save + subject.save - expect(subject.id).to be(1) - expect(subject.description).to eq('Desc of Circuit 0') - end - end + expect(subject.id).to be(1) + expect(subject.description).to eq('Desc of Circuit 0') end end end diff --git a/spec/netbox_client_ruby/api/circuits/circuit_termination_spec.rb b/spec/netbox_client_ruby/api/circuits/circuit_termination_spec.rb index 0676cd0..e34b569 100644 --- a/spec/netbox_client_ruby/api/circuits/circuit_termination_spec.rb +++ b/spec/netbox_client_ruby/api/circuits/circuit_termination_spec.rb @@ -1,137 +1,133 @@ require 'spec_helper' -module NetboxClientRuby - module Circuits - RSpec.describe CircuitTermination, faraday_stub: true do - let(:id) { 1 } - let(:base_url) { '/api/circuits/circuit-terminations/' } - let(:request_url) { "#{base_url}#{id}.json" } - let(:response) { File.read("spec/fixtures/circuits/circuit-termination_#{id}.json") } - - subject { described_class.new id } - - describe '#id' do - it 'shall be the expected id' do - expect(subject.id).to eq(id) - end - end +RSpec.describe NetboxClientRuby::Circuits::CircuitTermination, faraday_stub: true do + let(:id) { 1 } + let(:base_url) { '/api/circuits/circuit-terminations/' } + let(:request_url) { "#{base_url}#{id}.json" } + let(:response) { File.read("spec/fixtures/circuits/circuit-termination_#{id}.json") } - describe '#term_side' do - it 'should fetch the data' do - expect(faraday).to receive(:get).and_call_original + subject { described_class.new id } - subject.term_side - end + describe '#id' do + it 'shall be the expected id' do + expect(subject.id).to eq(id) + end + end - it 'shall be the expected term_side' do - expect(subject.term_side).to eq('A') - end - end + describe '#term_side' do + it 'should fetch the data' do + expect(faraday).to receive(:get).and_call_original - describe '.site' do - it 'should be a Site object' do - site = subject.site - expect(site).to be_a DCIM::Site - expect(site.id).to eq(1) - end - end + subject.term_side + end - describe '.delete' do - let(:request_method) { :delete } - let(:response_status) { 204 } - let(:response) { nil } + it 'shall be the expected term_side' do + expect(subject.term_side).to eq('A') + end + end - it 'should delete the object' do - expect(faraday).to receive(request_method).and_call_original - subject.delete - end - end + describe '.site' do + it 'should be a Site object' do + site = subject.site + expect(site).to be_a NetboxClientRuby::DCIM::Site + expect(site.id).to eq(1) + end + end - describe '.update' do - let(:request_method) { :patch } - let(:request_params) { { 'term_side' => 'noob' } } + describe '.delete' do + let(:request_method) { :delete } + let(:response_status) { 204 } + let(:response) { nil } - it 'should update the object' do - expect(faraday).to receive(request_method).and_call_original - expect(subject.update(term_side: 'noob').term_side).to eq('A') - end - end + it 'should delete the object' do + expect(faraday).to receive(request_method).and_call_original + subject.delete + end + end - describe '.reload' do - it 'should reload the object' do - expect(faraday).to receive(request_method).twice.and_call_original + describe '.update' do + let(:request_method) { :patch } + let(:request_params) { { 'term_side' => 'noob' } } - subject.reload - subject.reload - end - end + it 'should update the object' do + expect(faraday).to receive(request_method).and_call_original + expect(subject.update(term_side: 'noob').term_side).to eq('A') + end + end - describe '.save' do - let(:term_side) { 'Z' } - let(:request_params) { { 'term_side' => term_side } } + describe '.reload' do + it 'should reload the object' do + expect(faraday).to receive(request_method).twice.and_call_original - context 'update' do - let(:request_method) { :patch } + subject.reload + subject.reload + end + end - subject do - entity = described_class.new id - entity.term_side = term_side - entity - end + describe '.save' do + let(:term_side) { 'Z' } + let(:request_params) { { 'term_side' => term_side } } + + context 'update' do + let(:request_method) { :patch } + + subject do + entity = described_class.new id + entity.term_side = term_side + entity + end - it 'does not call PATCH until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + it 'does not call PATCH until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) - expect(subject.term_side).to eq(term_side) - end + expect(subject.term_side).to eq(term_side) + end - it 'calls PATCH when save is called' do - expect(faraday).to receive(request_method).and_call_original + it 'calls PATCH when save is called' do + expect(faraday).to receive(request_method).and_call_original - expect(subject.save).to be(subject) - end + expect(subject.save).to be(subject) + end - it 'Reads the answer from the PATCH answer' do - expect(faraday).to receive(request_method).and_call_original + it 'Reads the answer from the PATCH answer' do + expect(faraday).to receive(request_method).and_call_original - subject.save - expect(subject.term_side).to eq('A') - end - end + subject.save + expect(subject.term_side).to eq('A') + end + end - context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } + context 'create' do + let(:request_method) { :post } + let(:request_url) { base_url } - subject do - entity = described_class.new - entity.term_side = term_side - entity - end + subject do + entity = described_class.new + entity.term_side = term_side + entity + end - it 'does not POST until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + it 'does not POST until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) - expect(subject.term_side).to eq(term_side) - end + expect(subject.term_side).to eq(term_side) + end - it 'POSTs the data upon a call of save' do - expect(faraday).to receive(request_method).and_call_original + it 'POSTs the data upon a call of save' do + expect(faraday).to receive(request_method).and_call_original - expect(subject.save).to be(subject) - end + expect(subject.save).to be(subject) + end - it 'Reads the answer from the POST' do - expect(faraday).to receive(request_method).and_call_original + it 'Reads the answer from the POST' do + expect(faraday).to receive(request_method).and_call_original - subject.save + subject.save - expect(subject.id).to be(1) - expect(subject.term_side).to eq('A') - end - end + expect(subject.id).to be(1) + expect(subject.term_side).to eq('A') end end end diff --git a/spec/netbox_client_ruby/api/circuits/circuit_terminations_spec.rb b/spec/netbox_client_ruby/api/circuits/circuit_terminations_spec.rb index d4ee821..992220e 100644 --- a/spec/netbox_client_ruby/api/circuits/circuit_terminations_spec.rb +++ b/spec/netbox_client_ruby/api/circuits/circuit_terminations_spec.rb @@ -1,59 +1,55 @@ require 'spec_helper' -module NetboxClientRuby - module Circuits - RSpec.describe CircuitTerminations, faraday_stub: true do - let(:response) { File.read('spec/fixtures/circuits/circuit-terminations.json') } - let(:request_url) { '/api/circuits/circuit-terminations.json' } - let(:single_type) { CircuitTermination } - let(:expected_number_of_items) { 1 } - let(:request_url_params) do - { limit: NetboxClientRuby.config.netbox.pagination.default_limit } - end +RSpec.describe NetboxClientRuby::Circuits::CircuitTerminations, faraday_stub: true do + let(:response) { File.read('spec/fixtures/circuits/circuit-terminations.json') } + let(:request_url) { '/api/circuits/circuit-terminations.json' } + let(:single_type) { NetboxClientRuby::Circuits::CircuitTermination } + let(:expected_number_of_items) { 1 } + let(:request_url_params) do + { limit: NetboxClientRuby.config.netbox.pagination.default_limit } + end - context 'unpaged fetch' do - describe '#length' do - it 'shall be the expected length' do - expect(subject.length).to be expected_number_of_items - end - end - - describe '#total' do - it 'shall be the expected total' do - expect(subject.total).to be expected_number_of_items - end - end + context 'unpaged fetch' do + describe '#length' do + it 'shall be the expected length' do + expect(subject.length).to be expected_number_of_items end + end - describe '#reload' do - it 'fetches the correct data' do - expect(faraday).to receive(:get).and_call_original - subject.reload - end - - it 'caches the data' do - expect(faraday).to receive(:get).and_call_original - subject.total - subject.total - end - - it 'reloads the data' do - expect(faraday).to receive(:get).twice.and_call_original - subject.reload - subject.reload - end + describe '#total' do + it 'shall be the expected total' do + expect(subject.total).to be expected_number_of_items end + end + end + + describe '#reload' do + it 'fetches the correct data' do + expect(faraday).to receive(:get).and_call_original + subject.reload + end - describe '#as_array' do - it 'return the correct amount' do - expect(subject.to_a.length).to be expected_number_of_items - end + it 'caches the data' do + expect(faraday).to receive(:get).and_call_original + subject.total + subject.total + end + + it 'reloads the data' do + expect(faraday).to receive(:get).twice.and_call_original + subject.reload + subject.reload + end + end + + describe '#as_array' do + it 'return the correct amount' do + expect(subject.to_a.length).to be expected_number_of_items + end - it 'returns single instances' do - subject.to_a.each do |element| - expect(element).to be_a single_type - end - end + it 'returns single instances' do + subject.to_a.each do |element| + expect(element).to be_a single_type end end end diff --git a/spec/netbox_client_ruby/api/circuits/circuit_type_spec.rb b/spec/netbox_client_ruby/api/circuits/circuit_type_spec.rb index 582b24f..fbbfd19 100644 --- a/spec/netbox_client_ruby/api/circuits/circuit_type_spec.rb +++ b/spec/netbox_client_ruby/api/circuits/circuit_type_spec.rb @@ -1,129 +1,125 @@ require 'spec_helper' -module NetboxClientRuby - module Circuits - RSpec.describe CircuitType, faraday_stub: true do - let(:id) { 1 } - let(:base_url) { '/api/circuits/circuit-types/' } - let(:request_url) { "#{base_url}#{id}.json" } - let(:response) { File.read("spec/fixtures/circuits/circuit-type_#{id}.json") } - - subject { described_class.new id } - - describe '#id' do - it 'shall be the expected id' do - expect(subject.id).to eq(id) - end - end +RSpec.describe NetboxClientRuby::Circuits::CircuitType, faraday_stub: true do + let(:id) { 1 } + let(:base_url) { '/api/circuits/circuit-types/' } + let(:request_url) { "#{base_url}#{id}.json" } + let(:response) { File.read("spec/fixtures/circuits/circuit-type_#{id}.json") } - describe '#name' do - it 'should fetch the data' do - expect(faraday).to receive(:get).and_call_original + subject { described_class.new id } - subject.name - end + describe '#id' do + it 'shall be the expected id' do + expect(subject.id).to eq(id) + end + end - it 'shall be the expected name' do - expect(subject.name).to eq('Circuit Type 0') - end - end + describe '#name' do + it 'should fetch the data' do + expect(faraday).to receive(:get).and_call_original - describe '.delete' do - let(:request_method) { :delete } - let(:response_status) { 204 } - let(:response) { nil } + subject.name + end - it 'should delete the object' do - expect(faraday).to receive(request_method).and_call_original - subject.delete - end - end + it 'shall be the expected name' do + expect(subject.name).to eq('Circuit Type 0') + end + end - describe '.update' do - let(:request_method) { :patch } - let(:request_params) { { 'name' => 'noob' } } + describe '.delete' do + let(:request_method) { :delete } + let(:response_status) { 204 } + let(:response) { nil } - it 'should update the object' do - expect(faraday).to receive(request_method).and_call_original - expect(subject.update(name: 'noob').name).to eq('Circuit Type 0') - end - end + it 'should delete the object' do + expect(faraday).to receive(request_method).and_call_original + subject.delete + end + end - describe '.reload' do - it 'should reload the object' do - expect(faraday).to receive(request_method).twice.and_call_original + describe '.update' do + let(:request_method) { :patch } + let(:request_params) { { 'name' => 'noob' } } - subject.reload - subject.reload - end - end + it 'should update the object' do + expect(faraday).to receive(request_method).and_call_original + expect(subject.update(name: 'noob').name).to eq('Circuit Type 0') + end + end - describe '.save' do - let(:name) { 'foobar' } - let(:request_params) { { 'name' => name } } + describe '.reload' do + it 'should reload the object' do + expect(faraday).to receive(request_method).twice.and_call_original - context 'update' do - let(:request_method) { :patch } + subject.reload + subject.reload + end + end - subject do - entity = described_class.new id - entity.name = name - entity - end + describe '.save' do + let(:name) { 'foobar' } + let(:request_params) { { 'name' => name } } - it 'does not call PATCH until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + context 'update' do + let(:request_method) { :patch } - expect(subject.name).to eq(name) - end + subject do + entity = described_class.new id + entity.name = name + entity + end - it 'calls PATCH when save is called' do - expect(faraday).to receive(request_method).and_call_original + it 'does not call PATCH until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) - expect(subject.save).to be(subject) - end + expect(subject.name).to eq(name) + end - it 'Reads the answer from the PATCH answer' do - expect(faraday).to receive(request_method).and_call_original + it 'calls PATCH when save is called' do + expect(faraday).to receive(request_method).and_call_original - subject.save - expect(subject.name).to eq('Circuit Type 0') - end - end + expect(subject.save).to be(subject) + end - context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } + it 'Reads the answer from the PATCH answer' do + expect(faraday).to receive(request_method).and_call_original - subject do - entity = described_class.new - entity.name = name - entity - end + subject.save + expect(subject.name).to eq('Circuit Type 0') + end + end + + context 'create' do + let(:request_method) { :post } + let(:request_url) { base_url } + + subject do + entity = described_class.new + entity.name = name + entity + end - it 'does not POST until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + it 'does not POST until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) - expect(subject.name).to eq(name) - end + expect(subject.name).to eq(name) + end - it 'POSTs the data upon a call of save' do - expect(faraday).to receive(request_method).and_call_original + it 'POSTs the data upon a call of save' do + expect(faraday).to receive(request_method).and_call_original - expect(subject.save).to be(subject) - end + expect(subject.save).to be(subject) + end - it 'Reads the answer from the POST' do - expect(faraday).to receive(request_method).and_call_original + it 'Reads the answer from the POST' do + expect(faraday).to receive(request_method).and_call_original - subject.save + subject.save - expect(subject.id).to be(1) - expect(subject.name).to eq('Circuit Type 0') - end - end + expect(subject.id).to be(1) + expect(subject.name).to eq('Circuit Type 0') end end end diff --git a/spec/netbox_client_ruby/api/circuits/circuit_types_spec.rb b/spec/netbox_client_ruby/api/circuits/circuit_types_spec.rb index 56a82be..27a743d 100644 --- a/spec/netbox_client_ruby/api/circuits/circuit_types_spec.rb +++ b/spec/netbox_client_ruby/api/circuits/circuit_types_spec.rb @@ -1,59 +1,55 @@ require 'spec_helper' -module NetboxClientRuby - module Circuits - RSpec.describe CircuitTypes, faraday_stub: true do - let(:response) { File.read('spec/fixtures/circuits/circuit-types.json') } - let(:request_url) { '/api/circuits/circuit-types.json' } - let(:single_type) { CircuitType } - let(:expected_number_of_items) { 1 } - let(:request_url_params) do - { limit: NetboxClientRuby.config.netbox.pagination.default_limit } - end +RSpec.describe NetboxClientRuby::Circuits::CircuitTypes, faraday_stub: true do + let(:response) { File.read('spec/fixtures/circuits/circuit-types.json') } + let(:request_url) { '/api/circuits/circuit-types.json' } + let(:single_type) { NetboxClientRuby::Circuits::CircuitType } + let(:expected_number_of_items) { 1 } + let(:request_url_params) do + { limit: NetboxClientRuby.config.netbox.pagination.default_limit } + end - context 'unpaged fetch' do - describe '#length' do - it 'shall be the expected length' do - expect(subject.length).to be expected_number_of_items - end - end - - describe '#total' do - it 'shall be the expected total' do - expect(subject.total).to be expected_number_of_items - end - end + context 'unpaged fetch' do + describe '#length' do + it 'shall be the expected length' do + expect(subject.length).to be expected_number_of_items end + end - describe '#reload' do - it 'fetches the correct data' do - expect(faraday).to receive(:get).and_call_original - subject.reload - end - - it 'caches the data' do - expect(faraday).to receive(:get).and_call_original - subject.total - subject.total - end - - it 'reloads the data' do - expect(faraday).to receive(:get).twice.and_call_original - subject.reload - subject.reload - end + describe '#total' do + it 'shall be the expected total' do + expect(subject.total).to be expected_number_of_items end + end + end + + describe '#reload' do + it 'fetches the correct data' do + expect(faraday).to receive(:get).and_call_original + subject.reload + end - describe '#as_array' do - it 'return the correct amount' do - expect(subject.to_a.length).to be expected_number_of_items - end + it 'caches the data' do + expect(faraday).to receive(:get).and_call_original + subject.total + subject.total + end + + it 'reloads the data' do + expect(faraday).to receive(:get).twice.and_call_original + subject.reload + subject.reload + end + end + + describe '#as_array' do + it 'return the correct amount' do + expect(subject.to_a.length).to be expected_number_of_items + end - it 'returns single instances' do - subject.to_a.each do |element| - expect(element).to be_a single_type - end - end + it 'returns single instances' do + subject.to_a.each do |element| + expect(element).to be_a single_type end end end diff --git a/spec/netbox_client_ruby/api/circuits/circuits_spec.rb b/spec/netbox_client_ruby/api/circuits/circuits_spec.rb index eff7619..99f8565 100644 --- a/spec/netbox_client_ruby/api/circuits/circuits_spec.rb +++ b/spec/netbox_client_ruby/api/circuits/circuits_spec.rb @@ -1,59 +1,55 @@ require 'spec_helper' -module NetboxClientRuby - module Circuits - RSpec.describe NetboxClientRuby::Circuits::Circuits, faraday_stub: true do - let(:response) { File.read('spec/fixtures/circuits/circuits.json') } - let(:request_url) { '/api/circuits/circuits.json' } - let(:single_type) { Circuit } - let(:expected_number_of_items) { 1 } - let(:request_url_params) do - { limit: NetboxClientRuby.config.netbox.pagination.default_limit } - end +RSpec.describe NetboxClientRuby::Circuits::Circuits, faraday_stub: true do + let(:response) { File.read('spec/fixtures/circuits/circuits.json') } + let(:request_url) { '/api/circuits/circuits.json' } + let(:single_type) { NetboxClientRuby::Circuits::Circuit } + let(:expected_number_of_items) { 1 } + let(:request_url_params) do + { limit: NetboxClientRuby.config.netbox.pagination.default_limit } + end - context 'unpaged fetch' do - describe '#length' do - it 'shall be the expected length' do - expect(subject.length).to be expected_number_of_items - end - end - - describe '#total' do - it 'shall be the expected total' do - expect(subject.total).to be expected_number_of_items - end - end + context 'unpaged fetch' do + describe '#length' do + it 'shall be the expected length' do + expect(subject.length).to be expected_number_of_items end + end - describe '#reload' do - it 'fetches the correct data' do - expect(faraday).to receive(:get).and_call_original - subject.reload - end - - it 'caches the data' do - expect(faraday).to receive(:get).and_call_original - subject.total - subject.total - end - - it 'reloads the data' do - expect(faraday).to receive(:get).twice.and_call_original - subject.reload - subject.reload - end + describe '#total' do + it 'shall be the expected total' do + expect(subject.total).to be expected_number_of_items end + end + end + + describe '#reload' do + it 'fetches the correct data' do + expect(faraday).to receive(:get).and_call_original + subject.reload + end - describe '#as_array' do - it 'return the correct amount' do - expect(subject.to_a.length).to be expected_number_of_items - end + it 'caches the data' do + expect(faraday).to receive(:get).and_call_original + subject.total + subject.total + end + + it 'reloads the data' do + expect(faraday).to receive(:get).twice.and_call_original + subject.reload + subject.reload + end + end + + describe '#as_array' do + it 'return the correct amount' do + expect(subject.to_a.length).to be expected_number_of_items + end - it 'returns single instances' do - subject.to_a.each do |element| - expect(element).to be_a single_type - end - end + it 'returns single instances' do + subject.to_a.each do |element| + expect(element).to be_a single_type end end end diff --git a/spec/netbox_client_ruby/api/circuits/provider_spec.rb b/spec/netbox_client_ruby/api/circuits/provider_spec.rb index 326c778..0aa1cdb 100644 --- a/spec/netbox_client_ruby/api/circuits/provider_spec.rb +++ b/spec/netbox_client_ruby/api/circuits/provider_spec.rb @@ -1,129 +1,125 @@ require 'spec_helper' -module NetboxClientRuby - module Circuits - RSpec.describe Provider, faraday_stub: true do - let(:id) { 1 } - let(:base_url) { '/api/circuits/providers/' } - let(:request_url) { "#{base_url}#{id}.json" } - let(:response) { File.read("spec/fixtures/circuits/provider_#{id}.json") } - - subject { described_class.new id } - - describe '#id' do - it 'shall be the expected id' do - expect(subject.id).to eq(id) - end - end +RSpec.describe NetboxClientRuby::Circuits::Provider, faraday_stub: true do + let(:id) { 1 } + let(:base_url) { '/api/circuits/providers/' } + let(:request_url) { "#{base_url}#{id}.json" } + let(:response) { File.read("spec/fixtures/circuits/provider_#{id}.json") } - describe '#name' do - it 'should fetch the data' do - expect(faraday).to receive(:get).and_call_original + subject { described_class.new id } - subject.name - end + describe '#id' do + it 'shall be the expected id' do + expect(subject.id).to eq(id) + end + end - it 'shall be the expected name' do - expect(subject.name).to eq('Circuit Provider 0') - end - end + describe '#name' do + it 'should fetch the data' do + expect(faraday).to receive(:get).and_call_original - describe '.delete' do - let(:request_method) { :delete } - let(:response_status) { 204 } - let(:response) { nil } + subject.name + end - it 'should delete the object' do - expect(faraday).to receive(request_method).and_call_original - subject.delete - end - end + it 'shall be the expected name' do + expect(subject.name).to eq('Circuit Provider 0') + end + end - describe '.update' do - let(:request_method) { :patch } - let(:request_params) { { 'name' => 'noob' } } + describe '.delete' do + let(:request_method) { :delete } + let(:response_status) { 204 } + let(:response) { nil } - it 'should update the object' do - expect(faraday).to receive(request_method).and_call_original - expect(subject.update(name: 'noob').name).to eq('Circuit Provider 0') - end - end + it 'should delete the object' do + expect(faraday).to receive(request_method).and_call_original + subject.delete + end + end - describe '.reload' do - it 'should reload the object' do - expect(faraday).to receive(request_method).twice.and_call_original + describe '.update' do + let(:request_method) { :patch } + let(:request_params) { { 'name' => 'noob' } } - subject.reload - subject.reload - end - end + it 'should update the object' do + expect(faraday).to receive(request_method).and_call_original + expect(subject.update(name: 'noob').name).to eq('Circuit Provider 0') + end + end - describe '.save' do - let(:name) { 'foobar' } - let(:request_params) { { 'name' => name } } + describe '.reload' do + it 'should reload the object' do + expect(faraday).to receive(request_method).twice.and_call_original - context 'update' do - let(:request_method) { :patch } + subject.reload + subject.reload + end + end - subject do - entity = described_class.new id - entity.name = name - entity - end + describe '.save' do + let(:name) { 'foobar' } + let(:request_params) { { 'name' => name } } - it 'does not call PATCH until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + context 'update' do + let(:request_method) { :patch } - expect(subject.name).to eq(name) - end + subject do + entity = described_class.new id + entity.name = name + entity + end - it 'calls PATCH when save is called' do - expect(faraday).to receive(request_method).and_call_original + it 'does not call PATCH until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) - expect(subject.save).to be(subject) - end + expect(subject.name).to eq(name) + end - it 'Reads the answer from the PATCH answer' do - expect(faraday).to receive(request_method).and_call_original + it 'calls PATCH when save is called' do + expect(faraday).to receive(request_method).and_call_original - subject.save - expect(subject.name).to eq('Circuit Provider 0') - end - end + expect(subject.save).to be(subject) + end - context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } + it 'Reads the answer from the PATCH answer' do + expect(faraday).to receive(request_method).and_call_original - subject do - entity = described_class.new - entity.name = name - entity - end + subject.save + expect(subject.name).to eq('Circuit Provider 0') + end + end + + context 'create' do + let(:request_method) { :post } + let(:request_url) { base_url } + + subject do + entity = described_class.new + entity.name = name + entity + end - it 'does not POST until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + it 'does not POST until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) - expect(subject.name).to eq(name) - end + expect(subject.name).to eq(name) + end - it 'POSTs the data upon a call of save' do - expect(faraday).to receive(request_method).and_call_original + it 'POSTs the data upon a call of save' do + expect(faraday).to receive(request_method).and_call_original - expect(subject.save).to be(subject) - end + expect(subject.save).to be(subject) + end - it 'Reads the answer from the POST' do - expect(faraday).to receive(request_method).and_call_original + it 'Reads the answer from the POST' do + expect(faraday).to receive(request_method).and_call_original - subject.save + subject.save - expect(subject.id).to be(1) - expect(subject.name).to eq('Circuit Provider 0') - end - end + expect(subject.id).to be(1) + expect(subject.name).to eq('Circuit Provider 0') end end end diff --git a/spec/netbox_client_ruby/api/circuits/providers_spec.rb b/spec/netbox_client_ruby/api/circuits/providers_spec.rb index 9589daf..87a2fbc 100644 --- a/spec/netbox_client_ruby/api/circuits/providers_spec.rb +++ b/spec/netbox_client_ruby/api/circuits/providers_spec.rb @@ -1,59 +1,55 @@ require 'spec_helper' -module NetboxClientRuby - module Circuits - RSpec.describe Providers, faraday_stub: true do - let(:response) { File.read('spec/fixtures/circuits/providers.json') } - let(:request_url) { '/api/circuits/providers.json' } - let(:single_type) { Provider } - let(:expected_number_of_items) { 1 } - let(:request_url_params) do - { limit: NetboxClientRuby.config.netbox.pagination.default_limit } - end +RSpec.describe NetboxClientRuby::Circuits::Providers, faraday_stub: true do + let(:response) { File.read('spec/fixtures/circuits/providers.json') } + let(:request_url) { '/api/circuits/providers.json' } + let(:single_type) { NetboxClientRuby::Circuits::Provider } + let(:expected_number_of_items) { 1 } + let(:request_url_params) do + { limit: NetboxClientRuby.config.netbox.pagination.default_limit } + end - context 'unpaged fetch' do - describe '#length' do - it 'shall be the expected length' do - expect(subject.length).to be expected_number_of_items - end - end - - describe '#total' do - it 'shall be the expected total' do - expect(subject.total).to be expected_number_of_items - end - end + context 'unpaged fetch' do + describe '#length' do + it 'shall be the expected length' do + expect(subject.length).to be expected_number_of_items end + end - describe '#reload' do - it 'fetches the correct data' do - expect(faraday).to receive(:get).and_call_original - subject.reload - end - - it 'caches the data' do - expect(faraday).to receive(:get).and_call_original - subject.total - subject.total - end - - it 'reloads the data' do - expect(faraday).to receive(:get).twice.and_call_original - subject.reload - subject.reload - end + describe '#total' do + it 'shall be the expected total' do + expect(subject.total).to be expected_number_of_items end + end + end + + describe '#reload' do + it 'fetches the correct data' do + expect(faraday).to receive(:get).and_call_original + subject.reload + end - describe '#as_array' do - it 'return the correct amount' do - expect(subject.to_a.length).to be expected_number_of_items - end + it 'caches the data' do + expect(faraday).to receive(:get).and_call_original + subject.total + subject.total + end + + it 'reloads the data' do + expect(faraday).to receive(:get).twice.and_call_original + subject.reload + subject.reload + end + end + + describe '#as_array' do + it 'return the correct amount' do + expect(subject.to_a.length).to be expected_number_of_items + end - it 'returns single instances' do - subject.to_a.each do |element| - expect(element).to be_a single_type - end - end + it 'returns single instances' do + subject.to_a.each do |element| + expect(element).to be_a single_type end end end diff --git a/spec/netbox_client_ruby/api/circuits_spec.rb b/spec/netbox_client_ruby/api/circuits_spec.rb index fae3a75..0bc657a 100644 --- a/spec/netbox_client_ruby/api/circuits_spec.rb +++ b/spec/netbox_client_ruby/api/circuits_spec.rb @@ -1,60 +1,56 @@ require 'spec_helper' -module NetboxClientRuby - module Circuits - RSpec.describe NetboxClientRuby::Circuits do - { - providers: Providers, - circuits: NetboxClientRuby::Circuits::Circuits, - circuit_terminations: CircuitTerminations, - circuit_types: CircuitTypes - }.each do |method, klass| - describe ".#{method}" do - subject { described_class.public_send(method) } - - context 'is of the correct type' do - it { is_expected.to be_a klass } - end - - context 'is a different instance each time' do - it do - is_expected - .to_not be described_class.public_send(method) - end - end - - context 'is an Entities object' do - it { is_expected.to respond_to(:get!) } - end +RSpec.describe NetboxClientRuby::Circuits do + { + providers: NetboxClientRuby::Circuits::Providers, + circuits: NetboxClientRuby::Circuits::Circuits, + circuit_terminations: NetboxClientRuby::Circuits::CircuitTerminations, + circuit_types: NetboxClientRuby::Circuits::CircuitTypes + }.each do |method, klass| + describe ".#{method}" do + subject { described_class.public_send(method) } + + context 'is of the correct type' do + it { is_expected.to be_a klass } + end + + context 'is a different instance each time' do + it do + is_expected + .to_not be described_class.public_send(method) end end - { - provider: Provider, - circuit: Circuit, - circuit_termination: CircuitTermination, - circuit_type: CircuitType - }.each do |method, expected_class| - describe ".#{method}" do - let(:id) { 1 } - subject { described_class.public_send(method, id) } - - context 'is of the expected type' do - it { is_expected.to be_a expected_class } - end - - context 'it is a new instance each time' do - it do - is_expected - .to_not be described_class.public_send(method, id) - end - end - - context 'is an Entity object' do - it { is_expected.to respond_to(:get!) } - end + context 'is an Entities object' do + it { is_expected.to respond_to(:get!) } + end + end + end + + { + provider: NetboxClientRuby::Circuits::Provider, + circuit: NetboxClientRuby::Circuits::Circuit, + circuit_termination: NetboxClientRuby::Circuits::CircuitTermination, + circuit_type: NetboxClientRuby::Circuits::CircuitType + }.each do |method, expected_class| + describe ".#{method}" do + let(:id) { 1 } + subject { described_class.public_send(method, id) } + + context 'is of the expected type' do + it { is_expected.to be_a expected_class } + end + + context 'it is a new instance each time' do + it do + is_expected + .to_not be described_class.public_send(method, id) end end + + context 'is an Entity object' do + it { is_expected.to respond_to(:get!) } + end end end end diff --git a/spec/netbox_client_ruby/api/dcim/console_connection_spec.rb b/spec/netbox_client_ruby/api/dcim/console_connection_spec.rb index 5870f12..dce4b28 100644 --- a/spec/netbox_client_ruby/api/dcim/console_connection_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/console_connection_spec.rb @@ -1,131 +1,127 @@ require 'spec_helper' -module NetboxClientRuby - module DCIM - RSpec.describe ConsoleConnection, faraday_stub: true do - let(:entity_id) { 1 } - let(:expected_name) { 'rj45' } - let(:base_url) { '/api/dcim/console-connections/' } - let(:response) { File.read("spec/fixtures/dcim/console-connection_#{entity_id}.json") } - - let(:request_url) { "#{base_url}#{entity_id}.json" } - - subject { described_class.new entity_id } - - describe '#id' do - it 'shall be the expected id' do - expect(subject.id).to eq(entity_id) - end - end +RSpec.describe NetboxClientRuby::DCIM::ConsoleConnection, faraday_stub: true do + let(:entity_id) { 1 } + let(:expected_name) { 'rj45' } + let(:base_url) { '/api/dcim/console-connections/' } + let(:response) { File.read("spec/fixtures/dcim/console-connection_#{entity_id}.json") } - describe '#name' do - it 'should fetch the data' do - expect(faraday).to receive(:get).and_call_original + let(:request_url) { "#{base_url}#{entity_id}.json" } - expect(subject.name).to_not be_nil - end + subject { described_class.new entity_id } - it 'shall be the expected name' do - expect(subject.name).to eq(expected_name) - end - end + describe '#id' do + it 'shall be the expected id' do + expect(subject.id).to eq(entity_id) + end + end - describe '.delete' do - let(:request_method) { :delete } - let(:response_status) { 204 } - let(:response) { nil } + describe '#name' do + it 'should fetch the data' do + expect(faraday).to receive(:get).and_call_original - it 'should delete the object' do - expect(faraday).to receive(request_method).and_call_original - subject.delete - end - end + expect(subject.name).to_not be_nil + end - describe '.update' do - let(:request_method) { :patch } - let(:request_params) { { 'name' => 'foobar' } } + it 'shall be the expected name' do + expect(subject.name).to eq(expected_name) + end + end - it 'should update the object' do - expect(faraday).to receive(request_method).and_call_original - expect(subject.update(name: 'foobar').name).to eq(expected_name) - end - end + describe '.delete' do + let(:request_method) { :delete } + let(:response_status) { 204 } + let(:response) { nil } - describe '.reload' do - it 'should reload the object' do - expect(faraday).to receive(request_method).twice.and_call_original + it 'should delete the object' do + expect(faraday).to receive(request_method).and_call_original + subject.delete + end + end - subject.reload - subject.reload - end - end + describe '.update' do + let(:request_method) { :patch } + let(:request_params) { { 'name' => 'foobar' } } - describe '.save' do - let(:name) { 'foobar' } - let(:request_params) { { 'name' => name } } + it 'should update the object' do + expect(faraday).to receive(request_method).and_call_original + expect(subject.update(name: 'foobar').name).to eq(expected_name) + end + end - context 'update' do - let(:request_method) { :patch } + describe '.reload' do + it 'should reload the object' do + expect(faraday).to receive(request_method).twice.and_call_original - subject do - entity = described_class.new entity_id - entity.name = name - entity - end + subject.reload + subject.reload + end + end - it 'does not call PATCH until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + describe '.save' do + let(:name) { 'foobar' } + let(:request_params) { { 'name' => name } } - expect(subject.name).to eq(name) - end + context 'update' do + let(:request_method) { :patch } - it 'calls PATCH when save is called' do - expect(faraday).to receive(request_method).and_call_original + subject do + entity = described_class.new entity_id + entity.name = name + entity + end - expect(subject.save).to be(subject) - end + it 'does not call PATCH until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) - it 'Reads the answer from the PATCH answer' do - expect(faraday).to receive(request_method).and_call_original + expect(subject.name).to eq(name) + end - subject.save - expect(subject.name).to eq(expected_name) - end - end + it 'calls PATCH when save is called' do + expect(faraday).to receive(request_method).and_call_original - context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } + expect(subject.save).to be(subject) + end - subject do - entity = described_class.new - entity.name = name - entity - end + it 'Reads the answer from the PATCH answer' do + expect(faraday).to receive(request_method).and_call_original - it 'does not POST until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + subject.save + expect(subject.name).to eq(expected_name) + end + end - expect(subject.name).to eq(name) - end + context 'create' do + let(:request_method) { :post } + let(:request_url) { base_url } - it 'POSTs the data upon a call of save' do - expect(faraday).to receive(request_method).and_call_original + subject do + entity = described_class.new + entity.name = name + entity + end + + it 'does not POST until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) + + expect(subject.name).to eq(name) + end + + it 'POSTs the data upon a call of save' do + expect(faraday).to receive(request_method).and_call_original - expect(subject.save).to be(subject) - end + expect(subject.save).to be(subject) + end - it 'Reads the answer from the POST' do - expect(faraday).to receive(request_method).and_call_original + it 'Reads the answer from the POST' do + expect(faraday).to receive(request_method).and_call_original - subject.save + subject.save - expect(subject.id).to be(entity_id) - expect(subject.name).to eq(expected_name) - end - end + expect(subject.id).to be(entity_id) + expect(subject.name).to eq(expected_name) end end end diff --git a/spec/netbox_client_ruby/api/dcim/console_connections_spec.rb b/spec/netbox_client_ruby/api/dcim/console_connections_spec.rb index d77329b..d268657 100644 --- a/spec/netbox_client_ruby/api/dcim/console_connections_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/console_connections_spec.rb @@ -1,60 +1,56 @@ require 'spec_helper' -module NetboxClientRuby - module DCIM - RSpec.describe ConsoleConnections, faraday_stub: true do - let(:expected_length) { 2 } - let(:singular_type) { ConsoleConnection } - - let(:response) { File.read('spec/fixtures/dcim/console-connections.json') } - let(:request_url) { '/api/dcim/console-connections.json' } - let(:request_url_params) do - { limit: NetboxClientRuby.config.netbox.pagination.default_limit } - end +RSpec.describe NetboxClientRuby::DCIM::ConsoleConnections, faraday_stub: true do + let(:expected_length) { 2 } + let(:singular_type) { NetboxClientRuby::DCIM::ConsoleConnection } + + let(:response) { File.read('spec/fixtures/dcim/console-connections.json') } + let(:request_url) { '/api/dcim/console-connections.json' } + let(:request_url_params) do + { limit: NetboxClientRuby.config.netbox.pagination.default_limit } + end - context 'unpaged fetch' do - describe '#length' do - it 'shall be the expected length' do - expect(subject.length).to be expected_length - end - end - - describe '#total' do - it 'shall be the expected total' do - expect(subject.total).to be expected_length - end - end + context 'unpaged fetch' do + describe '#length' do + it 'shall be the expected length' do + expect(subject.length).to be expected_length end + end - describe '#reload' do - it 'fetches the correct data' do - expect(faraday).to receive(:get).and_call_original - subject.reload - end - - it 'caches the data' do - expect(faraday).to receive(:get).and_call_original - subject.total - subject.total - end - - it 'reloads the data' do - expect(faraday).to receive(:get).twice.and_call_original - subject.reload - subject.reload - end + describe '#total' do + it 'shall be the expected total' do + expect(subject.total).to be expected_length end + end + end + + describe '#reload' do + it 'fetches the correct data' do + expect(faraday).to receive(:get).and_call_original + subject.reload + end - describe '#as_array' do - it 'return the correct amount' do - expect(subject.to_a.length).to be expected_length - end + it 'caches the data' do + expect(faraday).to receive(:get).and_call_original + subject.total + subject.total + end + + it 'reloads the data' do + expect(faraday).to receive(:get).twice.and_call_original + subject.reload + subject.reload + end + end + + describe '#as_array' do + it 'return the correct amount' do + expect(subject.to_a.length).to be expected_length + end - it 'returns Site instances' do - subject.to_a.each do |element| - expect(element).to be_a singular_type - end - end + it 'returns Site instances' do + subject.to_a.each do |element| + expect(element).to be_a singular_type end end end diff --git a/spec/netbox_client_ruby/api/dcim/console_port_spec.rb b/spec/netbox_client_ruby/api/dcim/console_port_spec.rb index 6b07e7c..95dfc14 100644 --- a/spec/netbox_client_ruby/api/dcim/console_port_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/console_port_spec.rb @@ -1,151 +1,147 @@ require 'spec_helper' -module NetboxClientRuby - module DCIM - RSpec.describe ConsolePort, faraday_stub: true do - let(:entity_id) { 1 } - let(:expected_name) { 'rj45' } - let(:base_url) { '/api/dcim/console-ports/' } - let(:response) { File.read("spec/fixtures/dcim/console-port_#{entity_id}.json") } - - let(:request_url) { "#{base_url}#{entity_id}.json" } - - subject { described_class.new entity_id } - - describe '#id' do - it 'shall be the expected id' do - expect(subject.id).to eq(entity_id) - end - end +RSpec.describe NetboxClientRuby::DCIM::ConsolePort, faraday_stub: true do + let(:entity_id) { 1 } + let(:expected_name) { 'rj45' } + let(:base_url) { '/api/dcim/console-ports/' } + let(:response) { File.read("spec/fixtures/dcim/console-port_#{entity_id}.json") } - describe '#name' do - it 'should fetch the data' do - expect(faraday).to receive(:get).and_call_original + let(:request_url) { "#{base_url}#{entity_id}.json" } - expect(subject.name).to_not be_nil - end + subject { described_class.new entity_id } - it 'shall be the expected name' do - expect(subject.name).to eq(expected_name) - end - end + describe '#id' do + it 'shall be the expected id' do + expect(subject.id).to eq(entity_id) + end + end - describe '#device' do - it 'should return a Device' do - expect(subject.device).to be_a(Device) - end - end + describe '#name' do + it 'should fetch the data' do + expect(faraday).to receive(:get).and_call_original - describe '#device' do - it 'should return a Device' do - expect(subject.cs_port).to be_a(ConsoleServerPort) - end + expect(subject.name).to_not be_nil + end - context 'unconnected port' do - let(:entity_id) { 3 } + it 'shall be the expected name' do + expect(subject.name).to eq(expected_name) + end + end - it 'should return nil' do - expect(subject.cs_port).to be_nil - end - end - end + describe '#device' do + it 'should return a Device' do + expect(subject.device).to be_a(NetboxClientRuby::DCIM::Device) + end + end + + describe '#device' do + it 'should return a Device' do + expect(subject.cs_port).to be_a(NetboxClientRuby::DCIM::ConsoleServerPort) + end - describe '.delete' do - let(:request_method) { :delete } - let(:response_status) { 204 } - let(:response) { nil } + context 'unconnected port' do + let(:entity_id) { 3 } - it 'should delete the object' do - expect(faraday).to receive(request_method).and_call_original - subject.delete - end + it 'should return nil' do + expect(subject.cs_port).to be_nil end + end + end - describe '.update' do - let(:request_method) { :patch } - let(:request_params) { { 'name' => 'noob' } } + describe '.delete' do + let(:request_method) { :delete } + let(:response_status) { 204 } + let(:response) { nil } - it 'should update the object' do - expect(faraday).to receive(request_method).and_call_original - expect(subject.update(name: 'noob').name).to eq(expected_name) - end - end + it 'should delete the object' do + expect(faraday).to receive(request_method).and_call_original + subject.delete + end + end - describe '.reload' do - it 'should reload the object' do - expect(faraday).to receive(request_method).twice.and_call_original + describe '.update' do + let(:request_method) { :patch } + let(:request_params) { { 'name' => 'noob' } } - subject.reload - subject.reload - end - end + it 'should update the object' do + expect(faraday).to receive(request_method).and_call_original + expect(subject.update(name: 'noob').name).to eq(expected_name) + end + end + + describe '.reload' do + it 'should reload the object' do + expect(faraday).to receive(request_method).twice.and_call_original + + subject.reload + subject.reload + end + end - describe '.save' do - let(:name) { 'foobar' } - let(:request_params) { { 'name' => name } } + describe '.save' do + let(:name) { 'foobar' } + let(:request_params) { { 'name' => name } } - context 'update' do - let(:request_method) { :patch } + context 'update' do + let(:request_method) { :patch } - subject do - entity = described_class.new entity_id - entity.name = name - entity - end + subject do + entity = described_class.new entity_id + entity.name = name + entity + end - it 'does not call PATCH until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + it 'does not call PATCH until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) - expect(subject.name).to eq(name) - end + expect(subject.name).to eq(name) + end - it 'calls PATCH when save is called' do - expect(faraday).to receive(request_method).and_call_original + it 'calls PATCH when save is called' do + expect(faraday).to receive(request_method).and_call_original - expect(subject.save).to be(subject) - end + expect(subject.save).to be(subject) + end - it 'Reads the answer from the PATCH answer' do - expect(faraday).to receive(request_method).and_call_original + it 'Reads the answer from the PATCH answer' do + expect(faraday).to receive(request_method).and_call_original - subject.save - expect(subject.name).to eq(expected_name) - end - end + subject.save + expect(subject.name).to eq(expected_name) + end + end - context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } + context 'create' do + let(:request_method) { :post } + let(:request_url) { base_url } - subject do - entity = described_class.new - entity.name = name - entity - end + subject do + entity = described_class.new + entity.name = name + entity + end - it 'does not POST until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + it 'does not POST until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) - expect(subject.name).to eq(name) - end + expect(subject.name).to eq(name) + end - it 'POSTs the data upon a call of save' do - expect(faraday).to receive(request_method).and_call_original + it 'POSTs the data upon a call of save' do + expect(faraday).to receive(request_method).and_call_original - expect(subject.save).to be(subject) - end + expect(subject.save).to be(subject) + end - it 'Reads the answer from the POST' do - expect(faraday).to receive(request_method).and_call_original + it 'Reads the answer from the POST' do + expect(faraday).to receive(request_method).and_call_original - subject.save + subject.save - expect(subject.id).to be(1) - expect(subject.name).to eq(expected_name) - end - end + expect(subject.id).to be(1) + expect(subject.name).to eq(expected_name) end end end diff --git a/spec/netbox_client_ruby/api/dcim/console_ports_spec.rb b/spec/netbox_client_ruby/api/dcim/console_ports_spec.rb index f2c7556..1f5cdd0 100644 --- a/spec/netbox_client_ruby/api/dcim/console_ports_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/console_ports_spec.rb @@ -1,60 +1,56 @@ require 'spec_helper' -module NetboxClientRuby - module DCIM - RSpec.describe ConsolePorts, faraday_stub: true do - let(:expected_length) { 6 } - let(:singular_type) { ConsolePort } - - let(:response) { File.read('spec/fixtures/dcim/console-ports.json') } - let(:request_url) { '/api/dcim/console-ports.json' } - let(:request_url_params) do - { limit: NetboxClientRuby.config.netbox.pagination.default_limit } - end +RSpec.describe NetboxClientRuby::DCIM::ConsolePorts, faraday_stub: true do + let(:expected_length) { 6 } + let(:singular_type) { NetboxClientRuby::DCIM::ConsolePort } + + let(:response) { File.read('spec/fixtures/dcim/console-ports.json') } + let(:request_url) { '/api/dcim/console-ports.json' } + let(:request_url_params) do + { limit: NetboxClientRuby.config.netbox.pagination.default_limit } + end - context 'unpaged fetch' do - describe '#length' do - it 'shall be the expected length' do - expect(subject.length).to be expected_length - end - end - - describe '#total' do - it 'shall be the expected total' do - expect(subject.total).to be expected_length - end - end + context 'unpaged fetch' do + describe '#length' do + it 'shall be the expected length' do + expect(subject.length).to be expected_length end + end - describe '#reload' do - it 'fetches the correct data' do - expect(faraday).to receive(:get).and_call_original - subject.reload - end - - it 'caches the data' do - expect(faraday).to receive(:get).and_call_original - subject.total - subject.total - end - - it 'reloads the data' do - expect(faraday).to receive(:get).twice.and_call_original - subject.reload - subject.reload - end + describe '#total' do + it 'shall be the expected total' do + expect(subject.total).to be expected_length end + end + end + + describe '#reload' do + it 'fetches the correct data' do + expect(faraday).to receive(:get).and_call_original + subject.reload + end - describe '#as_array' do - it 'return the correct amount' do - expect(subject.to_a.length).to be expected_length - end + it 'caches the data' do + expect(faraday).to receive(:get).and_call_original + subject.total + subject.total + end + + it 'reloads the data' do + expect(faraday).to receive(:get).twice.and_call_original + subject.reload + subject.reload + end + end + + describe '#as_array' do + it 'return the correct amount' do + expect(subject.to_a.length).to be expected_length + end - it 'returns Site instances' do - subject.to_a.each do |element| - expect(element).to be_a singular_type - end - end + it 'returns Site instances' do + subject.to_a.each do |element| + expect(element).to be_a singular_type end end end diff --git a/spec/netbox_client_ruby/api/dcim/console_server_port_spec.rb b/spec/netbox_client_ruby/api/dcim/console_server_port_spec.rb index 685fe0a..9257a83 100644 --- a/spec/netbox_client_ruby/api/dcim/console_server_port_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/console_server_port_spec.rb @@ -1,151 +1,147 @@ require 'spec_helper' -module NetboxClientRuby - module DCIM - RSpec.describe ConsoleServerPort, faraday_stub: true do - let(:entity_id) { 1 } - let(:expected_name) { 'Console Server Port 0' } - let(:base_url) { '/api/dcim/console-server-ports/' } - let(:response) { File.read("spec/fixtures/dcim/console-server-port_#{entity_id}.json") } - - let(:request_url) { "#{base_url}#{entity_id}.json" } - - subject { described_class.new entity_id } - - describe '#id' do - it 'shall be the expected id' do - expect(subject.id).to eq(entity_id) - end - end +RSpec.describe NetboxClientRuby::DCIM::ConsoleServerPort, faraday_stub: true do + let(:entity_id) { 1 } + let(:expected_name) { 'Console Server Port 0' } + let(:base_url) { '/api/dcim/console-server-ports/' } + let(:response) { File.read("spec/fixtures/dcim/console-server-port_#{entity_id}.json") } - describe '#name' do - it 'should fetch the data' do - expect(faraday).to receive(:get).and_call_original + let(:request_url) { "#{base_url}#{entity_id}.json" } - expect(subject.name).to_not be_nil - end + subject { described_class.new entity_id } - it 'shall be the expected name' do - expect(subject.name).to eq(expected_name) - end - end + describe '#id' do + it 'shall be the expected id' do + expect(subject.id).to eq(entity_id) + end + end - describe '#device' do - it 'should return a Device' do - expect(subject.device).to be_a(Device) - end - end + describe '#name' do + it 'should fetch the data' do + expect(faraday).to receive(:get).and_call_original - describe '#device' do - it 'should return a Device' do - expect(subject.connected_console).to be_a(ConsolePort) - end + expect(subject.name).to_not be_nil + end - context 'unconnected port' do - let(:entity_id) { 3 } + it 'shall be the expected name' do + expect(subject.name).to eq(expected_name) + end + end - it 'should return nil' do - expect(subject.connected_console).to be_nil - end - end - end + describe '#device' do + it 'should return a Device' do + expect(subject.device).to be_a(NetboxClientRuby::DCIM::Device) + end + end + + describe '#device' do + it 'should return a Device' do + expect(subject.connected_console).to be_a(NetboxClientRuby::DCIM::ConsolePort) + end - describe '.delete' do - let(:request_method) { :delete } - let(:response_status) { 204 } - let(:response) { nil } + context 'unconnected port' do + let(:entity_id) { 3 } - it 'should delete the object' do - expect(faraday).to receive(request_method).and_call_original - subject.delete - end + it 'should return nil' do + expect(subject.connected_console).to be_nil end + end + end - describe '.update' do - let(:request_method) { :patch } - let(:request_params) { { 'name' => 'noob' } } + describe '.delete' do + let(:request_method) { :delete } + let(:response_status) { 204 } + let(:response) { nil } - it 'should update the object' do - expect(faraday).to receive(request_method).and_call_original - expect(subject.update(name: 'noob').name).to eq(expected_name) - end - end + it 'should delete the object' do + expect(faraday).to receive(request_method).and_call_original + subject.delete + end + end - describe '.reload' do - it 'should reload the object' do - expect(faraday).to receive(request_method).twice.and_call_original + describe '.update' do + let(:request_method) { :patch } + let(:request_params) { { 'name' => 'noob' } } - subject.reload - subject.reload - end - end + it 'should update the object' do + expect(faraday).to receive(request_method).and_call_original + expect(subject.update(name: 'noob').name).to eq(expected_name) + end + end + + describe '.reload' do + it 'should reload the object' do + expect(faraday).to receive(request_method).twice.and_call_original + + subject.reload + subject.reload + end + end - describe '.save' do - let(:name) { 'foobar' } - let(:request_params) { { 'name' => name } } + describe '.save' do + let(:name) { 'foobar' } + let(:request_params) { { 'name' => name } } - context 'update' do - let(:request_method) { :patch } + context 'update' do + let(:request_method) { :patch } - subject do - entity = described_class.new entity_id - entity.name = name - entity - end + subject do + entity = described_class.new entity_id + entity.name = name + entity + end - it 'does not call PATCH until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + it 'does not call PATCH until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) - expect(subject.name).to eq(name) - end + expect(subject.name).to eq(name) + end - it 'calls PATCH when save is called' do - expect(faraday).to receive(request_method).and_call_original + it 'calls PATCH when save is called' do + expect(faraday).to receive(request_method).and_call_original - expect(subject.save).to be(subject) - end + expect(subject.save).to be(subject) + end - it 'Reads the answer from the PATCH answer' do - expect(faraday).to receive(request_method).and_call_original + it 'Reads the answer from the PATCH answer' do + expect(faraday).to receive(request_method).and_call_original - subject.save - expect(subject.name).to eq(expected_name) - end - end + subject.save + expect(subject.name).to eq(expected_name) + end + end - context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } + context 'create' do + let(:request_method) { :post } + let(:request_url) { base_url } - subject do - entity = described_class.new - entity.name = name - entity - end + subject do + entity = described_class.new + entity.name = name + entity + end - it 'does not POST until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + it 'does not POST until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) - expect(subject.name).to eq(name) - end + expect(subject.name).to eq(name) + end - it 'POSTs the data upon a call of save' do - expect(faraday).to receive(request_method).and_call_original + it 'POSTs the data upon a call of save' do + expect(faraday).to receive(request_method).and_call_original - expect(subject.save).to be(subject) - end + expect(subject.save).to be(subject) + end - it 'Reads the answer from the POST' do - expect(faraday).to receive(request_method).and_call_original + it 'Reads the answer from the POST' do + expect(faraday).to receive(request_method).and_call_original - subject.save + subject.save - expect(subject.id).to be(1) - expect(subject.name).to eq(expected_name) - end - end + expect(subject.id).to be(1) + expect(subject.name).to eq(expected_name) end end end diff --git a/spec/netbox_client_ruby/api/dcim/console_server_ports_spec.rb b/spec/netbox_client_ruby/api/dcim/console_server_ports_spec.rb index 7c4f991..dee2d94 100644 --- a/spec/netbox_client_ruby/api/dcim/console_server_ports_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/console_server_ports_spec.rb @@ -1,60 +1,56 @@ require 'spec_helper' -module NetboxClientRuby - module DCIM - RSpec.describe ConsoleServerPorts, faraday_stub: true do - let(:expected_length) { 4 } - let(:singular_type) { ConsoleServerPort } - - let(:response) { File.read('spec/fixtures/dcim/console-server-ports.json') } - let(:request_url) { '/api/dcim/console-server-ports.json' } - let(:request_url_params) do - { limit: NetboxClientRuby.config.netbox.pagination.default_limit } - end +RSpec.describe NetboxClientRuby::DCIM::ConsoleServerPorts, faraday_stub: true do + let(:expected_length) { 4 } + let(:singular_type) { NetboxClientRuby::DCIM::ConsoleServerPort } + + let(:response) { File.read('spec/fixtures/dcim/console-server-ports.json') } + let(:request_url) { '/api/dcim/console-server-ports.json' } + let(:request_url_params) do + { limit: NetboxClientRuby.config.netbox.pagination.default_limit } + end - context 'unpaged fetch' do - describe '#length' do - it 'shall be the expected length' do - expect(subject.length).to be expected_length - end - end - - describe '#total' do - it 'shall be the expected total' do - expect(subject.total).to be expected_length - end - end + context 'unpaged fetch' do + describe '#length' do + it 'shall be the expected length' do + expect(subject.length).to be expected_length end + end - describe '#reload' do - it 'fetches the correct data' do - expect(faraday).to receive(:get).and_call_original - subject.reload - end - - it 'caches the data' do - expect(faraday).to receive(:get).and_call_original - subject.total - subject.total - end - - it 'reloads the data' do - expect(faraday).to receive(:get).twice.and_call_original - subject.reload - subject.reload - end + describe '#total' do + it 'shall be the expected total' do + expect(subject.total).to be expected_length end + end + end + + describe '#reload' do + it 'fetches the correct data' do + expect(faraday).to receive(:get).and_call_original + subject.reload + end - describe '#as_array' do - it 'return the correct amount' do - expect(subject.to_a.length).to be expected_length - end + it 'caches the data' do + expect(faraday).to receive(:get).and_call_original + subject.total + subject.total + end + + it 'reloads the data' do + expect(faraday).to receive(:get).twice.and_call_original + subject.reload + subject.reload + end + end + + describe '#as_array' do + it 'return the correct amount' do + expect(subject.to_a.length).to be expected_length + end - it 'returns Site instances' do - subject.to_a.each do |element| - expect(element).to be_a singular_type - end - end + it 'returns Site instances' do + subject.to_a.each do |element| + expect(element).to be_a singular_type end end end diff --git a/spec/netbox_client_ruby/api/dcim/interface_connection_spec.rb b/spec/netbox_client_ruby/api/dcim/interface_connection_spec.rb index f144353..32333fa 100644 --- a/spec/netbox_client_ruby/api/dcim/interface_connection_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/interface_connection_spec.rb @@ -1,131 +1,127 @@ require 'spec_helper' -module NetboxClientRuby - module DCIM - RSpec.describe InterfaceConnection, faraday_stub: true do - let(:entity_id) { 9 } - let(:expected_connection_status) { true } - let(:base_url) { '/api/dcim/interface-connections/' } - let(:response) { File.read("spec/fixtures/dcim/interface-connection_#{entity_id}.json") } - - let(:request_url) { "#{base_url}#{entity_id}.json" } - - subject { described_class.new entity_id } - - describe '#id' do - it 'shall be the expected id' do - expect(subject.id).to eq(entity_id) - end - end +RSpec.describe NetboxClientRuby::DCIM::InterfaceConnection, faraday_stub: true do + let(:entity_id) { 9 } + let(:expected_connection_status) { true } + let(:base_url) { '/api/dcim/interface-connections/' } + let(:response) { File.read("spec/fixtures/dcim/interface-connection_#{entity_id}.json") } - describe '#connection_status' do - it 'should fetch the data' do - expect(faraday).to receive(:get).and_call_original + let(:request_url) { "#{base_url}#{entity_id}.json" } - expect(subject.connection_status['value']).to_not be_nil - end + subject { described_class.new entity_id } - it 'shall be the expected connection_status' do - expect(subject.connection_status['value']).to eq(expected_connection_status) - end - end + describe '#id' do + it 'shall be the expected id' do + expect(subject.id).to eq(entity_id) + end + end - describe '.delete' do - let(:request_method) { :delete } - let(:response_status) { 204 } - let(:response) { nil } + describe '#connection_status' do + it 'should fetch the data' do + expect(faraday).to receive(:get).and_call_original - it 'should delete the object' do - expect(faraday).to receive(request_method).and_call_original - subject.delete - end - end + expect(subject.connection_status['value']).to_not be_nil + end - describe '.update' do - let(:request_method) { :patch } - let(:request_params) { { 'connection_status' => false } } + it 'shall be the expected connection_status' do + expect(subject.connection_status['value']).to eq(expected_connection_status) + end + end - it 'should update the object' do - expect(faraday).to receive(request_method).and_call_original - expect(subject.update(connection_status: false).connection_status['value']).to eq(expected_connection_status) - end - end + describe '.delete' do + let(:request_method) { :delete } + let(:response_status) { 204 } + let(:response) { nil } - describe '.reload' do - it 'should reload the object' do - expect(faraday).to receive(request_method).twice.and_call_original + it 'should delete the object' do + expect(faraday).to receive(request_method).and_call_original + subject.delete + end + end - subject.reload - subject.reload - end - end + describe '.update' do + let(:request_method) { :patch } + let(:request_params) { { 'connection_status' => false } } - describe '.save' do - let(:connection_status) { true } - let(:request_params) { { 'connection_status' => connection_status } } + it 'should update the object' do + expect(faraday).to receive(request_method).and_call_original + expect(subject.update(connection_status: false).connection_status['value']).to eq(expected_connection_status) + end + end - context 'update' do - let(:request_method) { :patch } + describe '.reload' do + it 'should reload the object' do + expect(faraday).to receive(request_method).twice.and_call_original - subject do - entity = described_class.new entity_id - entity.connection_status = connection_status - entity - end + subject.reload + subject.reload + end + end - it 'does not call PATCH until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + describe '.save' do + let(:connection_status) { true } + let(:request_params) { { 'connection_status' => connection_status } } - expect(subject.connection_status).to eq(connection_status) - end + context 'update' do + let(:request_method) { :patch } - it 'calls PATCH when save is called' do - expect(faraday).to receive(request_method).and_call_original + subject do + entity = described_class.new entity_id + entity.connection_status = connection_status + entity + end - expect(subject.save).to be(subject) - end + it 'does not call PATCH until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) - it 'Reads the answer from the PATCH answer' do - expect(faraday).to receive(request_method).and_call_original + expect(subject.connection_status).to eq(connection_status) + end - subject.save - expect(subject.connection_status['value']).to eq(expected_connection_status) - end - end + it 'calls PATCH when save is called' do + expect(faraday).to receive(request_method).and_call_original - context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } + expect(subject.save).to be(subject) + end - subject do - entity = described_class.new - entity.connection_status = connection_status - entity - end + it 'Reads the answer from the PATCH answer' do + expect(faraday).to receive(request_method).and_call_original - it 'does not POST until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + subject.save + expect(subject.connection_status['value']).to eq(expected_connection_status) + end + end - expect(subject.connection_status).to eq(connection_status) - end + context 'create' do + let(:request_method) { :post } + let(:request_url) { base_url } - it 'POSTs the data upon a call of save' do - expect(faraday).to receive(request_method).and_call_original + subject do + entity = described_class.new + entity.connection_status = connection_status + entity + end + + it 'does not POST until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) + + expect(subject.connection_status).to eq(connection_status) + end + + it 'POSTs the data upon a call of save' do + expect(faraday).to receive(request_method).and_call_original - expect(subject.save).to be(subject) - end + expect(subject.save).to be(subject) + end - it 'Reads the answer from the POST' do - expect(faraday).to receive(request_method).and_call_original + it 'Reads the answer from the POST' do + expect(faraday).to receive(request_method).and_call_original - subject.save + subject.save - expect(subject.id).to be(entity_id) - expect(subject.connection_status['value']).to eq(expected_connection_status) - end - end + expect(subject.id).to be(entity_id) + expect(subject.connection_status['value']).to eq(expected_connection_status) end end end diff --git a/spec/netbox_client_ruby/api/dcim/interface_connections_spec.rb b/spec/netbox_client_ruby/api/dcim/interface_connections_spec.rb index 9aaee63..81c74cd 100644 --- a/spec/netbox_client_ruby/api/dcim/interface_connections_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/interface_connections_spec.rb @@ -1,60 +1,56 @@ require 'spec_helper' -module NetboxClientRuby - module DCIM - RSpec.describe InterfaceConnections, faraday_stub: true do - let(:expected_length) { 5 } - let(:singular_type) { InterfaceConnection } - - let(:response) { File.read('spec/fixtures/dcim/interface-connections.json') } - let(:request_url) { '/api/dcim/interface-connections.json' } - let(:request_url_params) do - { limit: NetboxClientRuby.config.netbox.pagination.default_limit } - end +RSpec.describe NetboxClientRuby::DCIM::InterfaceConnections, faraday_stub: true do + let(:expected_length) { 5 } + let(:singular_type) { NetboxClientRuby::DCIM::InterfaceConnection } + + let(:response) { File.read('spec/fixtures/dcim/interface-connections.json') } + let(:request_url) { '/api/dcim/interface-connections.json' } + let(:request_url_params) do + { limit: NetboxClientRuby.config.netbox.pagination.default_limit } + end - context 'unpaged fetch' do - describe '#length' do - it 'shall be the expected length' do - expect(subject.length).to be expected_length - end - end - - describe '#total' do - it 'shall be the expected total' do - expect(subject.total).to be expected_length - end - end + context 'unpaged fetch' do + describe '#length' do + it 'shall be the expected length' do + expect(subject.length).to be expected_length end + end - describe '#reload' do - it 'fetches the correct data' do - expect(faraday).to receive(:get).and_call_original - subject.reload - end - - it 'caches the data' do - expect(faraday).to receive(:get).and_call_original - subject.total - subject.total - end - - it 'reloads the data' do - expect(faraday).to receive(:get).twice.and_call_original - subject.reload - subject.reload - end + describe '#total' do + it 'shall be the expected total' do + expect(subject.total).to be expected_length end + end + end + + describe '#reload' do + it 'fetches the correct data' do + expect(faraday).to receive(:get).and_call_original + subject.reload + end - describe '#as_array' do - it 'return the correct amount' do - expect(subject.to_a.length).to be expected_length - end + it 'caches the data' do + expect(faraday).to receive(:get).and_call_original + subject.total + subject.total + end + + it 'reloads the data' do + expect(faraday).to receive(:get).twice.and_call_original + subject.reload + subject.reload + end + end + + describe '#as_array' do + it 'return the correct amount' do + expect(subject.to_a.length).to be expected_length + end - it 'returns Site instances' do - subject.to_a.each do |element| - expect(element).to be_a singular_type - end - end + it 'returns Site instances' do + subject.to_a.each do |element| + expect(element).to be_a singular_type end end end diff --git a/spec/netbox_client_ruby/api/dcim/power_connection_spec.rb b/spec/netbox_client_ruby/api/dcim/power_connection_spec.rb index d07df7e..a822d83 100644 --- a/spec/netbox_client_ruby/api/dcim/power_connection_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/power_connection_spec.rb @@ -1,131 +1,127 @@ require 'spec_helper' -module NetboxClientRuby - module DCIM - RSpec.describe PowerConnection, faraday_stub: true do - let(:entity_id) { 1 } - let(:expected_name) { 'power port 0' } - let(:base_url) { '/api/dcim/power-connections/' } - let(:response) { File.read("spec/fixtures/dcim/power-connection_#{entity_id}.json") } - - let(:request_url) { "#{base_url}#{entity_id}.json" } - - subject { described_class.new entity_id } - - describe '#id' do - it 'shall be the expected id' do - expect(subject.id).to eq(entity_id) - end - end +RSpec.describe NetboxClientRuby::DCIM::PowerConnection, faraday_stub: true do + let(:entity_id) { 1 } + let(:expected_name) { 'power port 0' } + let(:base_url) { '/api/dcim/power-connections/' } + let(:response) { File.read("spec/fixtures/dcim/power-connection_#{entity_id}.json") } - describe '#name' do - it 'should fetch the data' do - expect(faraday).to receive(:get).and_call_original + let(:request_url) { "#{base_url}#{entity_id}.json" } - expect(subject.name).to_not be_nil - end + subject { described_class.new entity_id } - it 'shall be the expected name' do - expect(subject.name).to eq(expected_name) - end - end + describe '#id' do + it 'shall be the expected id' do + expect(subject.id).to eq(entity_id) + end + end - describe '.delete' do - let(:request_method) { :delete } - let(:response_status) { 204 } - let(:response) { nil } + describe '#name' do + it 'should fetch the data' do + expect(faraday).to receive(:get).and_call_original - it 'should delete the object' do - expect(faraday).to receive(request_method).and_call_original - subject.delete - end - end + expect(subject.name).to_not be_nil + end - describe '.update' do - let(:request_method) { :patch } - let(:request_params) { { 'name' => 'foobar' } } + it 'shall be the expected name' do + expect(subject.name).to eq(expected_name) + end + end - it 'should update the object' do - expect(faraday).to receive(request_method).and_call_original - expect(subject.update(name: 'foobar').name).to eq(expected_name) - end - end + describe '.delete' do + let(:request_method) { :delete } + let(:response_status) { 204 } + let(:response) { nil } - describe '.reload' do - it 'should reload the object' do - expect(faraday).to receive(request_method).twice.and_call_original + it 'should delete the object' do + expect(faraday).to receive(request_method).and_call_original + subject.delete + end + end - subject.reload - subject.reload - end - end + describe '.update' do + let(:request_method) { :patch } + let(:request_params) { { 'name' => 'foobar' } } - describe '.save' do - let(:name) { 'foobar' } - let(:request_params) { { 'name' => name } } + it 'should update the object' do + expect(faraday).to receive(request_method).and_call_original + expect(subject.update(name: 'foobar').name).to eq(expected_name) + end + end - context 'update' do - let(:request_method) { :patch } + describe '.reload' do + it 'should reload the object' do + expect(faraday).to receive(request_method).twice.and_call_original - subject do - entity = described_class.new entity_id - entity.name = name - entity - end + subject.reload + subject.reload + end + end - it 'does not call PATCH until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + describe '.save' do + let(:name) { 'foobar' } + let(:request_params) { { 'name' => name } } - expect(subject.name).to eq(name) - end + context 'update' do + let(:request_method) { :patch } - it 'calls PATCH when save is called' do - expect(faraday).to receive(request_method).and_call_original + subject do + entity = described_class.new entity_id + entity.name = name + entity + end - expect(subject.save).to be(subject) - end + it 'does not call PATCH until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) - it 'Reads the answer from the PATCH answer' do - expect(faraday).to receive(request_method).and_call_original + expect(subject.name).to eq(name) + end - subject.save - expect(subject.name).to eq(expected_name) - end - end + it 'calls PATCH when save is called' do + expect(faraday).to receive(request_method).and_call_original - context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } + expect(subject.save).to be(subject) + end - subject do - entity = described_class.new - entity.name = name - entity - end + it 'Reads the answer from the PATCH answer' do + expect(faraday).to receive(request_method).and_call_original - it 'does not POST until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + subject.save + expect(subject.name).to eq(expected_name) + end + end - expect(subject.name).to eq(name) - end + context 'create' do + let(:request_method) { :post } + let(:request_url) { base_url } - it 'POSTs the data upon a call of save' do - expect(faraday).to receive(request_method).and_call_original + subject do + entity = described_class.new + entity.name = name + entity + end + + it 'does not POST until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) + + expect(subject.name).to eq(name) + end + + it 'POSTs the data upon a call of save' do + expect(faraday).to receive(request_method).and_call_original - expect(subject.save).to be(subject) - end + expect(subject.save).to be(subject) + end - it 'Reads the answer from the POST' do - expect(faraday).to receive(request_method).and_call_original + it 'Reads the answer from the POST' do + expect(faraday).to receive(request_method).and_call_original - subject.save + subject.save - expect(subject.id).to be(entity_id) - expect(subject.name).to eq(expected_name) - end - end + expect(subject.id).to be(entity_id) + expect(subject.name).to eq(expected_name) end end end diff --git a/spec/netbox_client_ruby/api/dcim/power_connections_spec.rb b/spec/netbox_client_ruby/api/dcim/power_connections_spec.rb index 6d8a5f4..b7112bf 100644 --- a/spec/netbox_client_ruby/api/dcim/power_connections_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/power_connections_spec.rb @@ -1,60 +1,56 @@ require 'spec_helper' -module NetboxClientRuby - module DCIM - RSpec.describe PowerConnections, faraday_stub: true do - let(:expected_length) { 2 } - let(:singular_type) { PowerConnection } - - let(:response) { File.read('spec/fixtures/dcim/power-connections.json') } - let(:request_url) { '/api/dcim/power-connections.json' } - let(:request_url_params) do - { limit: NetboxClientRuby.config.netbox.pagination.default_limit } - end +RSpec.describe NetboxClientRuby::DCIM::PowerConnections, faraday_stub: true do + let(:expected_length) { 2 } + let(:singular_type) { NetboxClientRuby::DCIM::PowerConnection } + + let(:response) { File.read('spec/fixtures/dcim/power-connections.json') } + let(:request_url) { '/api/dcim/power-connections.json' } + let(:request_url_params) do + { limit: NetboxClientRuby.config.netbox.pagination.default_limit } + end - context 'unpaged fetch' do - describe '#length' do - it 'shall be the expected length' do - expect(subject.length).to be expected_length - end - end - - describe '#total' do - it 'shall be the expected total' do - expect(subject.total).to be expected_length - end - end + context 'unpaged fetch' do + describe '#length' do + it 'shall be the expected length' do + expect(subject.length).to be expected_length end + end - describe '#reload' do - it 'fetches the correct data' do - expect(faraday).to receive(:get).and_call_original - subject.reload - end - - it 'caches the data' do - expect(faraday).to receive(:get).and_call_original - subject.total - subject.total - end - - it 'reloads the data' do - expect(faraday).to receive(:get).twice.and_call_original - subject.reload - subject.reload - end + describe '#total' do + it 'shall be the expected total' do + expect(subject.total).to be expected_length end + end + end + + describe '#reload' do + it 'fetches the correct data' do + expect(faraday).to receive(:get).and_call_original + subject.reload + end - describe '#as_array' do - it 'return the correct amount' do - expect(subject.to_a.length).to be expected_length - end + it 'caches the data' do + expect(faraday).to receive(:get).and_call_original + subject.total + subject.total + end + + it 'reloads the data' do + expect(faraday).to receive(:get).twice.and_call_original + subject.reload + subject.reload + end + end + + describe '#as_array' do + it 'return the correct amount' do + expect(subject.to_a.length).to be expected_length + end - it 'returns Site instances' do - subject.to_a.each do |element| - expect(element).to be_a singular_type - end - end + it 'returns Site instances' do + subject.to_a.each do |element| + expect(element).to be_a singular_type end end end diff --git a/spec/netbox_client_ruby/api/dcim/rack_reservation_spec.rb b/spec/netbox_client_ruby/api/dcim/rack_reservation_spec.rb index 6479c3c..6c4ef31 100644 --- a/spec/netbox_client_ruby/api/dcim/rack_reservation_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/rack_reservation_spec.rb @@ -1,131 +1,127 @@ require 'spec_helper' -module NetboxClientRuby - module DCIM - RSpec.describe RackReservation, faraday_stub: true do - let(:entity_id) { 1 } - let(:expected_description) { 'Reservation 0' } - let(:base_url) { '/api/dcim/rack-reservations/' } - let(:response) { File.read("spec/fixtures/dcim/rack-reservation_#{entity_id}.json") } - - let(:request_url) { "#{base_url}#{entity_id}.json" } - - subject { described_class.new entity_id } - - describe '#id' do - it 'shall be the expected id' do - expect(subject.id).to eq(entity_id) - end - end +RSpec.describe NetboxClientRuby::DCIM::RackReservation, faraday_stub: true do + let(:entity_id) { 1 } + let(:expected_description) { 'Reservation 0' } + let(:base_url) { '/api/dcim/rack-reservations/' } + let(:response) { File.read("spec/fixtures/dcim/rack-reservation_#{entity_id}.json") } - describe '#description' do - it 'should fetch the data' do - expect(faraday).to receive(:get).and_call_original + let(:request_url) { "#{base_url}#{entity_id}.json" } - expect(subject.description).to_not be_nil - end + subject { described_class.new entity_id } - it 'shall be the expected description' do - expect(subject.description).to eq(expected_description) - end - end + describe '#id' do + it 'shall be the expected id' do + expect(subject.id).to eq(entity_id) + end + end - describe '.delete' do - let(:request_method) { :delete } - let(:response_status) { 204 } - let(:response) { nil } + describe '#description' do + it 'should fetch the data' do + expect(faraday).to receive(:get).and_call_original - it 'should delete the object' do - expect(faraday).to receive(request_method).and_call_original - subject.delete - end - end + expect(subject.description).to_not be_nil + end - describe '.update' do - let(:request_method) { :patch } - let(:request_params) { { 'description' => 'noob' } } + it 'shall be the expected description' do + expect(subject.description).to eq(expected_description) + end + end - it 'should update the object' do - expect(faraday).to receive(request_method).and_call_original - expect(subject.update(description: 'noob').description).to eq(expected_description) - end - end + describe '.delete' do + let(:request_method) { :delete } + let(:response_status) { 204 } + let(:response) { nil } - describe '.reload' do - it 'should reload the object' do - expect(faraday).to receive(request_method).twice.and_call_original + it 'should delete the object' do + expect(faraday).to receive(request_method).and_call_original + subject.delete + end + end - subject.reload - subject.reload - end - end + describe '.update' do + let(:request_method) { :patch } + let(:request_params) { { 'description' => 'noob' } } - describe '.save' do - let(:description) { 'foobar' } - let(:request_params) { { 'description' => description } } + it 'should update the object' do + expect(faraday).to receive(request_method).and_call_original + expect(subject.update(description: 'noob').description).to eq(expected_description) + end + end - context 'update' do - let(:request_method) { :patch } + describe '.reload' do + it 'should reload the object' do + expect(faraday).to receive(request_method).twice.and_call_original - subject do - entity = described_class.new entity_id - entity.description = description - entity - end + subject.reload + subject.reload + end + end - it 'does not call PATCH until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + describe '.save' do + let(:description) { 'foobar' } + let(:request_params) { { 'description' => description } } - expect(subject.description).to eq(description) - end + context 'update' do + let(:request_method) { :patch } - it 'calls PATCH when save is called' do - expect(faraday).to receive(request_method).and_call_original + subject do + entity = described_class.new entity_id + entity.description = description + entity + end - expect(subject.save).to be(subject) - end + it 'does not call PATCH until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) - it 'Reads the answer from the PATCH answer' do - expect(faraday).to receive(request_method).and_call_original + expect(subject.description).to eq(description) + end - subject.save - expect(subject.description).to eq(expected_description) - end - end + it 'calls PATCH when save is called' do + expect(faraday).to receive(request_method).and_call_original - context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } + expect(subject.save).to be(subject) + end - subject do - entity = described_class.new - entity.description = description - entity - end + it 'Reads the answer from the PATCH answer' do + expect(faraday).to receive(request_method).and_call_original - it 'does not POST until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + subject.save + expect(subject.description).to eq(expected_description) + end + end - expect(subject.description).to eq(description) - end + context 'create' do + let(:request_method) { :post } + let(:request_url) { base_url } - it 'POSTs the data upon a call of save' do - expect(faraday).to receive(request_method).and_call_original + subject do + entity = described_class.new + entity.description = description + entity + end + + it 'does not POST until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) + + expect(subject.description).to eq(description) + end + + it 'POSTs the data upon a call of save' do + expect(faraday).to receive(request_method).and_call_original - expect(subject.save).to be(subject) - end + expect(subject.save).to be(subject) + end - it 'Reads the answer from the POST' do - expect(faraday).to receive(request_method).and_call_original + it 'Reads the answer from the POST' do + expect(faraday).to receive(request_method).and_call_original - subject.save + subject.save - expect(subject.id).to be(1) - expect(subject.description).to eq(expected_description) - end - end + expect(subject.id).to be(1) + expect(subject.description).to eq(expected_description) end end end diff --git a/spec/netbox_client_ruby/api/dcim/rack_reservations_spec.rb b/spec/netbox_client_ruby/api/dcim/rack_reservations_spec.rb index ecd0870..441b87e 100644 --- a/spec/netbox_client_ruby/api/dcim/rack_reservations_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/rack_reservations_spec.rb @@ -1,60 +1,56 @@ require 'spec_helper' -module NetboxClientRuby - module DCIM - RSpec.describe RackReservations, faraday_stub: true do - let(:expected_length) { 1 } - let(:singular_type) { RackReservation } - - let(:response) { File.read('spec/fixtures/dcim/rack-reservations.json') } - let(:request_url) { '/api/dcim/rack-reservations.json' } - let(:request_url_params) do - { limit: NetboxClientRuby.config.netbox.pagination.default_limit } - end +RSpec.describe NetboxClientRuby::DCIM::RackReservations, faraday_stub: true do + let(:expected_length) { 1 } + let(:singular_type) { NetboxClientRuby::DCIM::RackReservation } + + let(:response) { File.read('spec/fixtures/dcim/rack-reservations.json') } + let(:request_url) { '/api/dcim/rack-reservations.json' } + let(:request_url_params) do + { limit: NetboxClientRuby.config.netbox.pagination.default_limit } + end - context 'unpaged fetch' do - describe '#length' do - it 'shall be the expected length' do - expect(subject.length).to be expected_length - end - end - - describe '#total' do - it 'shall be the expected total' do - expect(subject.total).to be expected_length - end - end + context 'unpaged fetch' do + describe '#length' do + it 'shall be the expected length' do + expect(subject.length).to be expected_length end + end - describe '#reload' do - it 'fetches the correct data' do - expect(faraday).to receive(:get).and_call_original - subject.reload - end - - it 'caches the data' do - expect(faraday).to receive(:get).and_call_original - subject.total - subject.total - end - - it 'reloads the data' do - expect(faraday).to receive(:get).twice.and_call_original - subject.reload - subject.reload - end + describe '#total' do + it 'shall be the expected total' do + expect(subject.total).to be expected_length end + end + end + + describe '#reload' do + it 'fetches the correct data' do + expect(faraday).to receive(:get).and_call_original + subject.reload + end - describe '#as_array' do - it 'return the correct amount' do - expect(subject.to_a.length).to be expected_length - end + it 'caches the data' do + expect(faraday).to receive(:get).and_call_original + subject.total + subject.total + end + + it 'reloads the data' do + expect(faraday).to receive(:get).twice.and_call_original + subject.reload + subject.reload + end + end + + describe '#as_array' do + it 'return the correct amount' do + expect(subject.to_a.length).to be expected_length + end - it 'returns Site instances' do - subject.to_a.each do |element| - expect(element).to be_a singular_type - end - end + it 'returns Site instances' do + subject.to_a.each do |element| + expect(element).to be_a singular_type end end end diff --git a/spec/netbox_client_ruby/api/dcim/virtual_chassis_list_spec.rb b/spec/netbox_client_ruby/api/dcim/virtual_chassis_list_spec.rb index 3fb91c1..8635b3c 100644 --- a/spec/netbox_client_ruby/api/dcim/virtual_chassis_list_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/virtual_chassis_list_spec.rb @@ -1,60 +1,56 @@ require 'spec_helper' -module NetboxClientRuby - module DCIM - RSpec.describe VirtualChassisList, faraday_stub: true do - let(:expected_length) { 1 } - let(:singular_type) { VirtualChassis } - - let(:response) { File.read('spec/fixtures/dcim/virtual-chassis.json') } - let(:request_url) { '/api/dcim/virtual-chassis.json' } - let(:request_url_params) do - { limit: NetboxClientRuby.config.netbox.pagination.default_limit } - end +RSpec.describe NetboxClientRuby::DCIM::VirtualChassisList, faraday_stub: true do + let(:expected_length) { 1 } + let(:singular_type) { NetboxClientRuby::DCIM::VirtualChassis } + + let(:response) { File.read('spec/fixtures/dcim/virtual-chassis.json') } + let(:request_url) { '/api/dcim/virtual-chassis.json' } + let(:request_url_params) do + { limit: NetboxClientRuby.config.netbox.pagination.default_limit } + end - context 'unpaged fetch' do - describe '#length' do - it 'shall be the expected length' do - expect(subject.length).to be expected_length - end - end - - describe '#total' do - it 'shall be the expected total' do - expect(subject.total).to be expected_length - end - end + context 'unpaged fetch' do + describe '#length' do + it 'shall be the expected length' do + expect(subject.length).to be expected_length end + end - describe '#reload' do - it 'fetches the correct data' do - expect(faraday).to receive(:get).and_call_original - subject.reload - end - - it 'caches the data' do - expect(faraday).to receive(:get).and_call_original - subject.total - subject.total - end - - it 'reloads the data' do - expect(faraday).to receive(:get).twice.and_call_original - subject.reload - subject.reload - end + describe '#total' do + it 'shall be the expected total' do + expect(subject.total).to be expected_length end + end + end + + describe '#reload' do + it 'fetches the correct data' do + expect(faraday).to receive(:get).and_call_original + subject.reload + end - describe '#as_array' do - it 'return the correct amount' do - expect(subject.to_a.length).to be expected_length - end + it 'caches the data' do + expect(faraday).to receive(:get).and_call_original + subject.total + subject.total + end + + it 'reloads the data' do + expect(faraday).to receive(:get).twice.and_call_original + subject.reload + subject.reload + end + end + + describe '#as_array' do + it 'return the correct amount' do + expect(subject.to_a.length).to be expected_length + end - it 'returns Site instances' do - subject.to_a.each do |element| - expect(element).to be_a singular_type - end - end + it 'returns Site instances' do + subject.to_a.each do |element| + expect(element).to be_a singular_type end end end diff --git a/spec/netbox_client_ruby/api/dcim/virtual_chassis_spec.rb b/spec/netbox_client_ruby/api/dcim/virtual_chassis_spec.rb index dcb551d..26fd350 100644 --- a/spec/netbox_client_ruby/api/dcim/virtual_chassis_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/virtual_chassis_spec.rb @@ -1,131 +1,127 @@ require 'spec_helper' -module NetboxClientRuby - module DCIM - RSpec.describe VirtualChassis, faraday_stub: true do - let(:entity_id) { 1 } - let(:expected_domain) { 'Virtual Chassis 0' } - let(:base_url) { '/api/dcim/virtual-chassis/' } - let(:response) { File.read("spec/fixtures/dcim/virtual-chassis_#{entity_id}.json") } - - let(:request_url) { "#{base_url}#{entity_id}.json" } - - subject { described_class.new entity_id } - - describe '#id' do - it 'shall be the expected id' do - expect(subject.id).to eq(entity_id) - end - end +RSpec.describe NetboxClientRuby::DCIM::VirtualChassis, faraday_stub: true do + let(:entity_id) { 1 } + let(:expected_domain) { 'Virtual Chassis 0' } + let(:base_url) { '/api/dcim/virtual-chassis/' } + let(:response) { File.read("spec/fixtures/dcim/virtual-chassis_#{entity_id}.json") } - describe '#domain' do - it 'should fetch the data' do - expect(faraday).to receive(:get).and_call_original + let(:request_url) { "#{base_url}#{entity_id}.json" } - expect(subject.domain).to_not be_nil - end + subject { described_class.new entity_id } - it 'shall be the expected domain' do - expect(subject.domain).to eq(expected_domain) - end - end + describe '#id' do + it 'shall be the expected id' do + expect(subject.id).to eq(entity_id) + end + end - describe '.delete' do - let(:request_method) { :delete } - let(:response_status) { 204 } - let(:response) { nil } + describe '#domain' do + it 'should fetch the data' do + expect(faraday).to receive(:get).and_call_original - it 'should delete the object' do - expect(faraday).to receive(request_method).and_call_original - subject.delete - end - end + expect(subject.domain).to_not be_nil + end - describe '.update' do - let(:request_method) { :patch } - let(:request_params) { { 'domain' => 'noob' } } + it 'shall be the expected domain' do + expect(subject.domain).to eq(expected_domain) + end + end - it 'should update the object' do - expect(faraday).to receive(request_method).and_call_original - expect(subject.update(domain: 'noob').domain).to eq(expected_domain) - end - end + describe '.delete' do + let(:request_method) { :delete } + let(:response_status) { 204 } + let(:response) { nil } - describe '.reload' do - it 'should reload the object' do - expect(faraday).to receive(request_method).twice.and_call_original + it 'should delete the object' do + expect(faraday).to receive(request_method).and_call_original + subject.delete + end + end - subject.reload - subject.reload - end - end + describe '.update' do + let(:request_method) { :patch } + let(:request_params) { { 'domain' => 'noob' } } - describe '.save' do - let(:domain) { 'foobar' } - let(:request_params) { { 'domain' => domain } } + it 'should update the object' do + expect(faraday).to receive(request_method).and_call_original + expect(subject.update(domain: 'noob').domain).to eq(expected_domain) + end + end - context 'update' do - let(:request_method) { :patch } + describe '.reload' do + it 'should reload the object' do + expect(faraday).to receive(request_method).twice.and_call_original - subject do - entity = described_class.new entity_id - entity.domain = domain - entity - end + subject.reload + subject.reload + end + end - it 'does not call PATCH until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + describe '.save' do + let(:domain) { 'foobar' } + let(:request_params) { { 'domain' => domain } } - expect(subject.domain).to eq(domain) - end + context 'update' do + let(:request_method) { :patch } - it 'calls PATCH when save is called' do - expect(faraday).to receive(request_method).and_call_original + subject do + entity = described_class.new entity_id + entity.domain = domain + entity + end - expect(subject.save).to be(subject) - end + it 'does not call PATCH until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) - it 'Reads the answer from the PATCH answer' do - expect(faraday).to receive(request_method).and_call_original + expect(subject.domain).to eq(domain) + end - subject.save - expect(subject.domain).to eq(expected_domain) - end - end + it 'calls PATCH when save is called' do + expect(faraday).to receive(request_method).and_call_original - context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } + expect(subject.save).to be(subject) + end - subject do - entity = described_class.new - entity.domain = domain - entity - end + it 'Reads the answer from the PATCH answer' do + expect(faraday).to receive(request_method).and_call_original - it 'does not POST until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + subject.save + expect(subject.domain).to eq(expected_domain) + end + end - expect(subject.domain).to eq(domain) - end + context 'create' do + let(:request_method) { :post } + let(:request_url) { base_url } - it 'POSTs the data upon a call of save' do - expect(faraday).to receive(request_method).and_call_original + subject do + entity = described_class.new + entity.domain = domain + entity + end + + it 'does not POST until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) + + expect(subject.domain).to eq(domain) + end + + it 'POSTs the data upon a call of save' do + expect(faraday).to receive(request_method).and_call_original - expect(subject.save).to be(subject) - end + expect(subject.save).to be(subject) + end - it 'Reads the answer from the POST' do - expect(faraday).to receive(request_method).and_call_original + it 'Reads the answer from the POST' do + expect(faraday).to receive(request_method).and_call_original - subject.save + subject.save - expect(subject.id).to be(1) - expect(subject.domain).to eq(expected_domain) - end - end + expect(subject.id).to be(1) + expect(subject.domain).to eq(expected_domain) end end end diff --git a/spec/netbox_client_ruby/api/extras/config_context_spec.rb b/spec/netbox_client_ruby/api/extras/config_context_spec.rb index 0f9a61c..554c6d4 100644 --- a/spec/netbox_client_ruby/api/extras/config_context_spec.rb +++ b/spec/netbox_client_ruby/api/extras/config_context_spec.rb @@ -1,136 +1,132 @@ require 'spec_helper' -module NetboxClientRuby - module Extras - RSpec.describe ConfigContext, faraday_stub: true do - let(:entity_id) { 1 } - let(:base_url) { '/api/extras/config-contexts/' } - let(:request_url) { "#{base_url}#{entity_id}.json" } - let(:response) { File.read("spec/fixtures/extras/config_context_#{entity_id}.json") } - - subject { ConfigContext.new entity_id } - - describe '#id' do - it 'shall be the expected id' do - expect(subject.id).to eq(entity_id) - end - end +RSpec.describe NetboxClientRuby::Extras::ConfigContext, faraday_stub: true do + let(:entity_id) { 1 } + let(:base_url) { '/api/extras/config-contexts/' } + let(:request_url) { "#{base_url}#{entity_id}.json" } + let(:response) { File.read("spec/fixtures/extras/config_context_#{entity_id}.json") } - describe '#name' do - it 'should fetch the data' do - expect(faraday).to receive(:get).and_call_original + subject { NetboxClientRuby::Extras::ConfigContext.new entity_id } - subject.name - end + describe '#id' do + it 'shall be the expected id' do + expect(subject.id).to eq(entity_id) + end + end - it 'shall be the expected name' do - expect(subject.name).to eq('Production') - end - end + describe '#name' do + it 'should fetch the data' do + expect(faraday).to receive(:get).and_call_original - describe '.delete' do - let(:request_method) { :delete } - let(:response_status) { 204 } - let(:response) { nil } + subject.name + end - it 'should delete the object' do - expect(faraday).to receive(request_method).and_call_original - subject.delete - end - end + it 'shall be the expected name' do + expect(subject.name).to eq('Production') + end + end - describe '.update' do - let(:request_method) { :patch } - let(:request_params) { { 'name' => 'noob' } } + describe '.delete' do + let(:request_method) { :delete } + let(:response_status) { 204 } + let(:response) { nil } - it 'should update the object' do - expect(faraday).to receive(request_method).and_call_original - expect(subject.update(name: 'noob').name).to eq('Production') - end - end + it 'should delete the object' do + expect(faraday).to receive(request_method).and_call_original + subject.delete + end + end - describe '.reload' do - it 'should reload the object' do - expect(faraday).to receive(request_method).twice.and_call_original + describe '.update' do + let(:request_method) { :patch } + let(:request_params) { { 'name' => 'noob' } } - subject.reload - subject.reload - end - end + it 'should update the object' do + expect(faraday).to receive(request_method).and_call_original + expect(subject.update(name: 'noob').name).to eq('Production') + end + end - describe '.save' do - let(:name) { 'foobar' } - let(:weight) { 1000 } - let(:request_params) { { 'name' => name, 'weight' => weight } } + describe '.reload' do + it 'should reload the object' do + expect(faraday).to receive(request_method).twice.and_call_original - context 'update' do - let(:request_method) { :patch } + subject.reload + subject.reload + end + end - subject do - entity = ConfigContext.new entity_id - entity.name = name - entity.weight = weight - entity - end + describe '.save' do + let(:name) { 'foobar' } + let(:weight) { 1000 } + let(:request_params) { { 'name' => name, 'weight' => weight } } - it 'does not call PATCH until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + context 'update' do + let(:request_method) { :patch } - expect(subject.name).to eq(name) - expect(subject.weight).to eq(weight) - end + subject do + entity = NetboxClientRuby::Extras::ConfigContext.new entity_id + entity.name = name + entity.weight = weight + entity + end - it 'calls PATCH when save is called' do - expect(faraday).to receive(request_method).and_call_original + it 'does not call PATCH until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) - expect(subject.save).to be(subject) - end + expect(subject.name).to eq(name) + expect(subject.weight).to eq(weight) + end - it 'Reads the answer from the PATCH answer' do - expect(faraday).to receive(request_method).and_call_original + it 'calls PATCH when save is called' do + expect(faraday).to receive(request_method).and_call_original - subject.save - expect(subject.name).to eq('Production') - expect(subject.weight).to eq(1000) - end - end + expect(subject.save).to be(subject) + end - context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } + it 'Reads the answer from the PATCH answer' do + expect(faraday).to receive(request_method).and_call_original - subject do - entity = ConfigContext.new - entity.name = name - entity.weight = weight - entity - end + subject.save + expect(subject.name).to eq('Production') + expect(subject.weight).to eq(1000) + end + end + + context 'create' do + let(:request_method) { :post } + let(:request_url) { base_url } + + subject do + entity = NetboxClientRuby::Extras::ConfigContext.new + entity.name = name + entity.weight = weight + entity + end - it 'does not POST until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + it 'does not POST until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) - expect(subject.name).to eq(name) - expect(subject.weight).to eq(weight) - end + expect(subject.name).to eq(name) + expect(subject.weight).to eq(weight) + end - it 'POSTs the data upon a call of save' do - expect(faraday).to receive(request_method).and_call_original + it 'POSTs the data upon a call of save' do + expect(faraday).to receive(request_method).and_call_original - expect(subject.save).to be(subject) - end + expect(subject.save).to be(subject) + end - it 'Reads the answer from the POST' do - expect(faraday).to receive(request_method).and_call_original + it 'Reads the answer from the POST' do + expect(faraday).to receive(request_method).and_call_original - subject.save + subject.save - expect(subject.id).to be(1) - expect(subject.name).to eq('Production') - expect(subject.weight).to eq(1000) - end - end + expect(subject.id).to be(1) + expect(subject.name).to eq('Production') + expect(subject.weight).to eq(1000) end end end diff --git a/spec/netbox_client_ruby/api/extras/config_contexts_spec.rb b/spec/netbox_client_ruby/api/extras/config_contexts_spec.rb index a9a482e..2e184a1 100644 --- a/spec/netbox_client_ruby/api/extras/config_contexts_spec.rb +++ b/spec/netbox_client_ruby/api/extras/config_contexts_spec.rb @@ -1,60 +1,56 @@ require 'spec_helper' -module NetboxClientRuby - module Extras - RSpec.describe ConfigContexts, faraday_stub: true do - let(:expected_number_of_items) { 1 } - let(:expected_singular_type) { ConfigContext } - - let(:response) { File.read('spec/fixtures/extras/config_contexts.json') } - let(:request_url) { '/api/extras/config-contexts.json' } - let(:request_url_params) do - { limit: NetboxClientRuby.config.netbox.pagination.default_limit } - end +RSpec.describe NetboxClientRuby::Extras::ConfigContexts, faraday_stub: true do + let(:expected_number_of_items) { 1 } + let(:expected_singular_type) { NetboxClientRuby::Extras::ConfigContext } + + let(:response) { File.read('spec/fixtures/extras/config_contexts.json') } + let(:request_url) { '/api/extras/config-contexts.json' } + let(:request_url_params) do + { limit: NetboxClientRuby.config.netbox.pagination.default_limit } + end - context 'unpaged fetch' do - describe '#length' do - it 'shall be the expected length' do - expect(subject.length).to be expected_number_of_items - end - end - - describe '#total' do - it 'shall be the expected total' do - expect(subject.total).to be expected_number_of_items - end - end + context 'unpaged fetch' do + describe '#length' do + it 'shall be the expected length' do + expect(subject.length).to be expected_number_of_items end + end - describe '#reload' do - it 'fetches the correct data' do - expect(faraday).to receive(:get).and_call_original - subject.reload - end - - it 'caches the data' do - expect(faraday).to receive(:get).and_call_original - subject.total - subject.total - end - - it 'reloads the data' do - expect(faraday).to receive(:get).twice.and_call_original - subject.reload - subject.reload - end + describe '#total' do + it 'shall be the expected total' do + expect(subject.total).to be expected_number_of_items end + end + end + + describe '#reload' do + it 'fetches the correct data' do + expect(faraday).to receive(:get).and_call_original + subject.reload + end - describe '#as_array' do - it 'return the correct amount' do - expect(subject.to_a.length).to be expected_number_of_items - end + it 'caches the data' do + expect(faraday).to receive(:get).and_call_original + subject.total + subject.total + end + + it 'reloads the data' do + expect(faraday).to receive(:get).twice.and_call_original + subject.reload + subject.reload + end + end + + describe '#as_array' do + it 'return the correct amount' do + expect(subject.to_a.length).to be expected_number_of_items + end - it 'returns single instances' do - subject.to_a.each do |element| - expect(element).to be_a expected_singular_type - end - end + it 'returns single instances' do + subject.to_a.each do |element| + expect(element).to be_a expected_singular_type end end end diff --git a/spec/netbox_client_ruby/api/extras/journal_entries_spec.rb b/spec/netbox_client_ruby/api/extras/journal_entries_spec.rb index 101800e..8692888 100644 --- a/spec/netbox_client_ruby/api/extras/journal_entries_spec.rb +++ b/spec/netbox_client_ruby/api/extras/journal_entries_spec.rb @@ -1,60 +1,56 @@ require 'spec_helper' -module NetboxClientRuby - module Extras - RSpec.describe JournalEntries, faraday_stub: true do - let(:expected_number_of_items) { 1 } - let(:expected_singular_type) { JournalEntry } - - let(:response) { File.read('spec/fixtures/extras/journal_entries.json') } - let(:request_url) { '/api/extras/journal-entries.json' } - let(:request_url_params) do - { limit: NetboxClientRuby.config.netbox.pagination.default_limit } - end +RSpec.describe NetboxClientRuby::Extras::JournalEntries, faraday_stub: true do + let(:expected_number_of_items) { 1 } + let(:expected_singular_type) { NetboxClientRuby::Extras::JournalEntry } + + let(:response) { File.read('spec/fixtures/extras/journal_entries.json') } + let(:request_url) { '/api/extras/journal-entries.json' } + let(:request_url_params) do + { limit: NetboxClientRuby.config.netbox.pagination.default_limit } + end - context 'unpaged fetch' do - describe '#length' do - it 'shall be the expected length' do - expect(subject.length).to be expected_number_of_items - end - end - - describe '#total' do - it 'shall be the expected total' do - expect(subject.total).to be expected_number_of_items - end - end + context 'unpaged fetch' do + describe '#length' do + it 'shall be the expected length' do + expect(subject.length).to be expected_number_of_items end + end - describe '#reload' do - it 'fetches the correct data' do - expect(faraday).to receive(:get).and_call_original - subject.reload - end - - it 'caches the data' do - expect(faraday).to receive(:get).and_call_original - subject.total - subject.total - end - - it 'reloads the data' do - expect(faraday).to receive(:get).twice.and_call_original - subject.reload - subject.reload - end + describe '#total' do + it 'shall be the expected total' do + expect(subject.total).to be expected_number_of_items end + end + end + + describe '#reload' do + it 'fetches the correct data' do + expect(faraday).to receive(:get).and_call_original + subject.reload + end - describe '#as_array' do - it 'return the correct amount' do - expect(subject.to_a.length).to be expected_number_of_items - end + it 'caches the data' do + expect(faraday).to receive(:get).and_call_original + subject.total + subject.total + end + + it 'reloads the data' do + expect(faraday).to receive(:get).twice.and_call_original + subject.reload + subject.reload + end + end + + describe '#as_array' do + it 'return the correct amount' do + expect(subject.to_a.length).to be expected_number_of_items + end - it 'returns single instances' do - subject.to_a.each do |element| - expect(element).to be_a expected_singular_type - end - end + it 'returns single instances' do + subject.to_a.each do |element| + expect(element).to be_a expected_singular_type end end end diff --git a/spec/netbox_client_ruby/api/extras/journal_entry_spec.rb b/spec/netbox_client_ruby/api/extras/journal_entry_spec.rb index fd3998a..5006e0e 100644 --- a/spec/netbox_client_ruby/api/extras/journal_entry_spec.rb +++ b/spec/netbox_client_ruby/api/extras/journal_entry_spec.rb @@ -1,149 +1,145 @@ require 'spec_helper' -module NetboxClientRuby - module Extras - RSpec.describe JournalEntry, faraday_stub: true do - let(:entity_id) { 1 } - let(:base_url) { '/api/extras/journal-entries/' } - let(:request_url) { "#{base_url}#{entity_id}.json" } - let(:response) { File.read("spec/fixtures/extras/journal_entry_#{entity_id}.json") } - - subject { JournalEntry.new entity_id } - - describe '#id' do - it 'shall be the expected id' do - expect(subject.id).to eq(entity_id) - end +RSpec.describe NetboxClientRuby::Extras::JournalEntry, faraday_stub: true do + let(:entity_id) { 1 } + let(:base_url) { '/api/extras/journal-entries/' } + let(:request_url) { "#{base_url}#{entity_id}.json" } + let(:response) { File.read("spec/fixtures/extras/journal_entry_#{entity_id}.json") } + + subject { NetboxClientRuby::Extras::JournalEntry.new entity_id } + + describe '#id' do + it 'shall be the expected id' do + expect(subject.id).to eq(entity_id) + end + end + + describe '#comments' do + it 'should fetch the data' do + expect(faraday).to receive(:get).and_call_original + + subject.comments + end + + it 'shall be the expected comments' do + expect(subject.comments).to eq('Hello') + end + end + + describe '.delete' do + let(:request_method) { :delete } + let(:response_status) { 204 } + let(:response) { nil } + + it 'should delete the object' do + expect(faraday).to receive(request_method).and_call_original + subject.delete + end + end + + describe '.update' do + let(:request_method) { :patch } + let(:request_params) { { 'comments' => 'Hi' } } + + it 'should update the object' do + expect(faraday).to receive(request_method).and_call_original + expect(subject.update(comments: 'Hi').comments).to eq('Hello') + end + end + + describe '.reload' do + it 'should reload the object' do + expect(faraday).to receive(request_method).twice.and_call_original + + subject.reload + subject.reload + end + end + + describe '.save' do + let(:comments) { 'foobar' } + let(:assigned_object_type) { 'dcim.device' } + let(:assigned_object_id) { 2 } + let(:request_params) do + { + 'comments' => comments, + 'assigned_object_type' => assigned_object_type, + 'assigned_object_id' => assigned_object_id + } + end + + context 'update' do + let(:request_method) { :patch } + + subject do + entity = NetboxClientRuby::Extras::JournalEntry.new entity_id + entity.comments = comments + entity.assigned_object_type = assigned_object_type + entity.assigned_object_id = assigned_object_id + entity end - describe '#comments' do - it 'should fetch the data' do - expect(faraday).to receive(:get).and_call_original + it 'does not call PATCH until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) - subject.comments - end + expect(subject.comments).to eq(comments) + expect(subject.assigned_object_type).to eq(assigned_object_type) + expect(subject.assigned_object_id).to eq(assigned_object_id) + end + + it 'calls PATCH when save is called' do + expect(faraday).to receive(request_method).and_call_original + + expect(subject.save).to be(subject) + end - it 'shall be the expected comments' do - expect(subject.comments).to eq('Hello') - end + it 'Reads the answer from the PATCH answer' do + expect(faraday).to receive(request_method).and_call_original + + subject.save + expect(subject.comments).to eq('Hello') + expect(subject.assigned_object_type).to eq('dcim.device') + expect(subject.assigned_object_id).to eq(1) end + end - describe '.delete' do - let(:request_method) { :delete } - let(:response_status) { 204 } - let(:response) { nil } + context 'create' do + let(:request_method) { :post } + let(:request_url) { base_url } - it 'should delete the object' do - expect(faraday).to receive(request_method).and_call_original - subject.delete - end + subject do + entity = NetboxClientRuby::Extras::JournalEntry.new + entity.comments = comments + entity.assigned_object_type = assigned_object_type + entity.assigned_object_id = assigned_object_id + entity end - describe '.update' do - let(:request_method) { :patch } - let(:request_params) { { 'comments' => 'Hi' } } + it 'does not POST until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) - it 'should update the object' do - expect(faraday).to receive(request_method).and_call_original - expect(subject.update(comments: 'Hi').comments).to eq('Hello') - end + expect(subject.comments).to eq(comments) + expect(subject.assigned_object_type).to eq(assigned_object_type) + expect(subject.assigned_object_id).to eq(assigned_object_id) end - describe '.reload' do - it 'should reload the object' do - expect(faraday).to receive(request_method).twice.and_call_original + it 'POSTs the data upon a call of save' do + expect(faraday).to receive(request_method).and_call_original - subject.reload - subject.reload - end + expect(subject.save).to be(subject) end - describe '.save' do - let(:comments) { 'foobar' } - let(:assigned_object_type) { 'dcim.device' } - let(:assigned_object_id) { 2 } - let(:request_params) do - { - 'comments' => comments, - 'assigned_object_type' => assigned_object_type, - 'assigned_object_id' => assigned_object_id - } - end - - context 'update' do - let(:request_method) { :patch } - - subject do - entity = JournalEntry.new entity_id - entity.comments = comments - entity.assigned_object_type = assigned_object_type - entity.assigned_object_id = assigned_object_id - entity - end - - it 'does not call PATCH until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) - - expect(subject.comments).to eq(comments) - expect(subject.assigned_object_type).to eq(assigned_object_type) - expect(subject.assigned_object_id).to eq(assigned_object_id) - end - - it 'calls PATCH when save is called' do - expect(faraday).to receive(request_method).and_call_original - - expect(subject.save).to be(subject) - end - - it 'Reads the answer from the PATCH answer' do - expect(faraday).to receive(request_method).and_call_original - - subject.save - expect(subject.comments).to eq('Hello') - expect(subject.assigned_object_type).to eq('dcim.device') - expect(subject.assigned_object_id).to eq(1) - end - end - - context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - - subject do - entity = JournalEntry.new - entity.comments = comments - entity.assigned_object_type = assigned_object_type - entity.assigned_object_id = assigned_object_id - entity - end - - it 'does not POST until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) - - expect(subject.comments).to eq(comments) - expect(subject.assigned_object_type).to eq(assigned_object_type) - expect(subject.assigned_object_id).to eq(assigned_object_id) - end - - it 'POSTs the data upon a call of save' do - expect(faraday).to receive(request_method).and_call_original - - expect(subject.save).to be(subject) - end - - it 'Reads the answer from the POST' do - expect(faraday).to receive(request_method).and_call_original - - subject.save - - expect(subject.id).to be(1) - expect(subject.comments).to eq('Hello') - expect(subject.assigned_object_type).to eq('dcim.device') - expect(subject.assigned_object_id).to eq(1) - end - end + it 'Reads the answer from the POST' do + expect(faraday).to receive(request_method).and_call_original + + subject.save + + expect(subject.id).to be(1) + expect(subject.comments).to eq('Hello') + expect(subject.assigned_object_type).to eq('dcim.device') + expect(subject.assigned_object_id).to eq(1) end end end diff --git a/spec/netbox_client_ruby/api/extras/tag_spec.rb b/spec/netbox_client_ruby/api/extras/tag_spec.rb index d8c8f48..2e58dca 100644 --- a/spec/netbox_client_ruby/api/extras/tag_spec.rb +++ b/spec/netbox_client_ruby/api/extras/tag_spec.rb @@ -1,136 +1,132 @@ require 'spec_helper' -module NetboxClientRuby - module Extras - RSpec.describe Tag, faraday_stub: true do - let(:entity_id) { 1 } - let(:base_url) { '/api/extras/tags/' } - let(:request_url) { "#{base_url}#{entity_id}.json" } - let(:response) { File.read("spec/fixtures/extras/tag_#{entity_id}.json") } - - subject { Tag.new entity_id } - - describe '#id' do - it 'shall be the expected id' do - expect(subject.id).to eq(entity_id) - end - end +RSpec.describe NetboxClientRuby::Extras::Tag, faraday_stub: true do + let(:entity_id) { 1 } + let(:base_url) { '/api/extras/tags/' } + let(:request_url) { "#{base_url}#{entity_id}.json" } + let(:response) { File.read("spec/fixtures/extras/tag_#{entity_id}.json") } - describe '#name' do - it 'should fetch the data' do - expect(faraday).to receive(:get).and_call_original + subject { NetboxClientRuby::Extras::Tag.new entity_id } - subject.name - end + describe '#id' do + it 'shall be the expected id' do + expect(subject.id).to eq(entity_id) + end + end - it 'shall be the expected name' do - expect(subject.name).to eq('Production') - end - end + describe '#name' do + it 'should fetch the data' do + expect(faraday).to receive(:get).and_call_original - describe '.delete' do - let(:request_method) { :delete } - let(:response_status) { 204 } - let(:response) { nil } + subject.name + end - it 'should delete the object' do - expect(faraday).to receive(request_method).and_call_original - subject.delete - end - end + it 'shall be the expected name' do + expect(subject.name).to eq('Production') + end + end - describe '.update' do - let(:request_method) { :patch } - let(:request_params) { { 'name' => 'noob' } } + describe '.delete' do + let(:request_method) { :delete } + let(:response_status) { 204 } + let(:response) { nil } - it 'should update the object' do - expect(faraday).to receive(request_method).and_call_original - expect(subject.update(name: 'noob').name).to eq('Production') - end - end + it 'should delete the object' do + expect(faraday).to receive(request_method).and_call_original + subject.delete + end + end - describe '.reload' do - it 'should reload the object' do - expect(faraday).to receive(request_method).twice.and_call_original + describe '.update' do + let(:request_method) { :patch } + let(:request_params) { { 'name' => 'noob' } } - subject.reload - subject.reload - end - end + it 'should update the object' do + expect(faraday).to receive(request_method).and_call_original + expect(subject.update(name: 'noob').name).to eq('Production') + end + end - describe '.save' do - let(:name) { 'foobar' } - let(:slug) { name } - let(:request_params) { { 'name' => name, 'slug' => slug } } + describe '.reload' do + it 'should reload the object' do + expect(faraday).to receive(request_method).twice.and_call_original - context 'update' do - let(:request_method) { :patch } + subject.reload + subject.reload + end + end - subject do - entity = Tag.new entity_id - entity.name = name - entity.slug = slug - entity - end + describe '.save' do + let(:name) { 'foobar' } + let(:slug) { name } + let(:request_params) { { 'name' => name, 'slug' => slug } } - it 'does not call PATCH until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + context 'update' do + let(:request_method) { :patch } - expect(subject.name).to eq(name) - expect(subject.slug).to eq(slug) - end + subject do + entity = NetboxClientRuby::Extras::Tag.new entity_id + entity.name = name + entity.slug = slug + entity + end - it 'calls PATCH when save is called' do - expect(faraday).to receive(request_method).and_call_original + it 'does not call PATCH until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) - expect(subject.save).to be(subject) - end + expect(subject.name).to eq(name) + expect(subject.slug).to eq(slug) + end - it 'Reads the answer from the PATCH answer' do - expect(faraday).to receive(request_method).and_call_original + it 'calls PATCH when save is called' do + expect(faraday).to receive(request_method).and_call_original - subject.save - expect(subject.name).to eq('Production') - expect(subject.slug).to eq('production') - end - end + expect(subject.save).to be(subject) + end - context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } + it 'Reads the answer from the PATCH answer' do + expect(faraday).to receive(request_method).and_call_original - subject do - entity = Tag.new - entity.name = name - entity.slug = slug - entity - end + subject.save + expect(subject.name).to eq('Production') + expect(subject.slug).to eq('production') + end + end + + context 'create' do + let(:request_method) { :post } + let(:request_url) { base_url } + + subject do + entity = NetboxClientRuby::Extras::Tag.new + entity.name = name + entity.slug = slug + entity + end - it 'does not POST until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + it 'does not POST until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) - expect(subject.name).to eq(name) - expect(subject.slug).to eq(slug) - end + expect(subject.name).to eq(name) + expect(subject.slug).to eq(slug) + end - it 'POSTs the data upon a call of save' do - expect(faraday).to receive(request_method).and_call_original + it 'POSTs the data upon a call of save' do + expect(faraday).to receive(request_method).and_call_original - expect(subject.save).to be(subject) - end + expect(subject.save).to be(subject) + end - it 'Reads the answer from the POST' do - expect(faraday).to receive(request_method).and_call_original + it 'Reads the answer from the POST' do + expect(faraday).to receive(request_method).and_call_original - subject.save + subject.save - expect(subject.id).to be(1) - expect(subject.name).to eq('Production') - expect(subject.slug).to eq('production') - end - end + expect(subject.id).to be(1) + expect(subject.name).to eq('Production') + expect(subject.slug).to eq('production') end end end diff --git a/spec/netbox_client_ruby/api/extras/tags_spec.rb b/spec/netbox_client_ruby/api/extras/tags_spec.rb index b9f5aef..00497aa 100644 --- a/spec/netbox_client_ruby/api/extras/tags_spec.rb +++ b/spec/netbox_client_ruby/api/extras/tags_spec.rb @@ -1,60 +1,56 @@ require 'spec_helper' -module NetboxClientRuby - module Extras - RSpec.describe Tags, faraday_stub: true do - let(:expected_number_of_items) { 1 } - let(:expected_singular_type) { Tag } - - let(:response) { File.read('spec/fixtures/extras/tags.json') } - let(:request_url) { '/api/extras/tags.json' } - let(:request_url_params) do - { limit: NetboxClientRuby.config.netbox.pagination.default_limit } - end +RSpec.describe NetboxClientRuby::Extras::Tags, faraday_stub: true do + let(:expected_number_of_items) { 1 } + let(:expected_singular_type) { NetboxClientRuby::Extras::Tag } + + let(:response) { File.read('spec/fixtures/extras/tags.json') } + let(:request_url) { '/api/extras/tags.json' } + let(:request_url_params) do + { limit: NetboxClientRuby.config.netbox.pagination.default_limit } + end - context 'unpaged fetch' do - describe '#length' do - it 'shall be the expected length' do - expect(subject.length).to be expected_number_of_items - end - end - - describe '#total' do - it 'shall be the expected total' do - expect(subject.total).to be expected_number_of_items - end - end + context 'unpaged fetch' do + describe '#length' do + it 'shall be the expected length' do + expect(subject.length).to be expected_number_of_items end + end - describe '#reload' do - it 'fetches the correct data' do - expect(faraday).to receive(:get).and_call_original - subject.reload - end - - it 'caches the data' do - expect(faraday).to receive(:get).and_call_original - subject.total - subject.total - end - - it 'reloads the data' do - expect(faraday).to receive(:get).twice.and_call_original - subject.reload - subject.reload - end + describe '#total' do + it 'shall be the expected total' do + expect(subject.total).to be expected_number_of_items end + end + end + + describe '#reload' do + it 'fetches the correct data' do + expect(faraday).to receive(:get).and_call_original + subject.reload + end - describe '#as_array' do - it 'return the correct amount' do - expect(subject.to_a.length).to be expected_number_of_items - end + it 'caches the data' do + expect(faraday).to receive(:get).and_call_original + subject.total + subject.total + end + + it 'reloads the data' do + expect(faraday).to receive(:get).twice.and_call_original + subject.reload + subject.reload + end + end + + describe '#as_array' do + it 'return the correct amount' do + expect(subject.to_a.length).to be expected_number_of_items + end - it 'returns single instances' do - subject.to_a.each do |element| - expect(element).to be_a expected_singular_type - end - end + it 'returns single instances' do + subject.to_a.each do |element| + expect(element).to be_a expected_singular_type end end end diff --git a/spec/netbox_client_ruby/api/extras_spec.rb b/spec/netbox_client_ruby/api/extras_spec.rb index 21f676c..a598e04 100644 --- a/spec/netbox_client_ruby/api/extras_spec.rb +++ b/spec/netbox_client_ruby/api/extras_spec.rb @@ -1,30 +1,26 @@ require 'spec_helper' -module NetboxClientRuby - module Extras - RSpec.describe Extras do - { - tags: Tags - }.each do |method, klass| - describe ".#{method}" do - subject { described_class.public_send(method) } +RSpec.describe NetboxClientRuby::Extras do + { + tags: NetboxClientRuby::Extras::Tags + }.each do |method, klass| + describe ".#{method}" do + subject { described_class.public_send(method) } - context 'is of the correct type' do - it { is_expected.to be_a klass } - end - - context 'is a different instance each time' do - it do - is_expected - .to_not be described_class.public_send(method) - end - end + context 'is of the correct type' do + it { is_expected.to be_a klass } + end - context 'is an Entities object' do - it { is_expected.to respond_to(:get!) } - end + context 'is a different instance each time' do + it do + is_expected + .to_not be described_class.public_send(method) end end + + context 'is an Entities object' do + it { is_expected.to respond_to(:get!) } + end end end end diff --git a/spec/netbox_client_ruby/api/ipam_spec.rb b/spec/netbox_client_ruby/api/ipam_spec.rb index 79f4b3f..64bb462 100644 --- a/spec/netbox_client_ruby/api/ipam_spec.rb +++ b/spec/netbox_client_ruby/api/ipam_spec.rb @@ -1,68 +1,64 @@ require 'spec_helper' -module NetboxClientRuby - module IPAM - RSpec.describe IPAM do - { - roles: Roles, - ip_addresses: IpAddresses, - ip_ranges: IpRanges, - vlan_groups: VlanGroups, - vrfs: Vrfs, - vlans: Vlans, - rirs: Rirs, - prefixes: Prefixes - }.each do |method, klass| - describe ".#{method}" do - subject { described_class.public_send(method) } +RSpec.describe NetboxClientRuby::IPAM do + { + roles: NetboxClientRuby::IPAM::Roles, + ip_addresses: NetboxClientRuby::IPAM::IpAddresses, + ip_ranges: NetboxClientRuby::IPAM::IpRanges, + vlan_groups: NetboxClientRuby::IPAM::VlanGroups, + vrfs: NetboxClientRuby::IPAM::Vrfs, + vlans: NetboxClientRuby::IPAM::Vlans, + rirs: NetboxClientRuby::IPAM::Rirs, + prefixes: NetboxClientRuby::IPAM::Prefixes + }.each do |method, klass| + describe ".#{method}" do + subject { described_class.public_send(method) } - context 'is of the correct type' do - it { is_expected.to be_a klass } - end - - context 'is a different instance each time' do - it do - is_expected - .to_not be described_class.public_send(method) - end - end + context 'is of the correct type' do + it { is_expected.to be_a klass } + end - context 'is an Entities object' do - it { is_expected.to respond_to(:get!) } - end + context 'is a different instance each time' do + it do + is_expected + .to_not be described_class.public_send(method) end end - { - role: Role, - ip_address: IpAddress, - ip_range: IpRange, - vlan_group: VlanGroup, - vrf: Vrf, - vlan: Vlan, - rir: Rir, - prefix: Prefix - }.each do |method, expected_class| - describe ".#{method}" do - let(:id) { 1 } - subject { described_class.public_send(method, id) } + context 'is an Entities object' do + it { is_expected.to respond_to(:get!) } + end + end + end - context 'is of the expected type' do - it { is_expected.to be_a expected_class } - end + { + role: NetboxClientRuby::IPAM::Role, + ip_address: NetboxClientRuby::IPAM::IpAddress, + ip_range: NetboxClientRuby::IPAM::IpRange, + vlan_group: NetboxClientRuby::IPAM::VlanGroup, + vrf: NetboxClientRuby::IPAM::Vrf, + vlan: NetboxClientRuby::IPAM::Vlan, + rir: NetboxClientRuby::IPAM::Rir, + prefix: NetboxClientRuby::IPAM::Prefix + }.each do |method, expected_class| + describe ".#{method}" do + let(:id) { 1 } + subject { described_class.public_send(method, id) } - context 'it is a new instance each time' do - it do - is_expected - .to_not be described_class.public_send(method, id) - end - end + context 'is of the expected type' do + it { is_expected.to be_a expected_class } + end - context 'is an Entity object' do - it { is_expected.to respond_to(:get!) } - end + context 'it is a new instance each time' do + it do + is_expected + .to_not be described_class.public_send(method, id) end end + + context 'is an Entity object' do + it { is_expected.to respond_to(:get!) } + end end end end diff --git a/spec/netbox_client_ruby/api/secrets/rsa_key_pair_spec.rb b/spec/netbox_client_ruby/api/secrets/rsa_key_pair_spec.rb index cff57d0..a22ae78 100644 --- a/spec/netbox_client_ruby/api/secrets/rsa_key_pair_spec.rb +++ b/spec/netbox_client_ruby/api/secrets/rsa_key_pair_spec.rb @@ -1,72 +1,67 @@ require 'spec_helper' require 'digest/md5' -module NetboxClientRuby - module Secrets - RSpec.describe RSAKeyPair, faraday_stub: true do - let(:request_url) { '/api/secrets/generate-rsa-key-pair/' } - let(:response) { File.read('spec/fixtures/secrets/generate-rsa-key-pair.json') } - - # MD5, to keep the strings in this spec at a reasonable length - let(:expected_public_key_md5) { '29bdf13ae078d73fab4848634b2c3c37' } - let(:expected_private_key_md5) { '91e45a978633a43de04c3310bd550645' } - - describe '#public_key' do - it 'queries the api' do - expect(faraday).to receive(request_method).once.and_call_original - - expect(md5sum(subject.public_key)).to eql(expected_public_key_md5) - end - - context 'then #private_key' do - it 'queries the api just once' do - expect(faraday).to receive(request_method).once.and_call_original - - expect(md5sum(subject.public_key)).to eql(expected_public_key_md5) - expect(md5sum(subject.private_key)).to eql(expected_private_key_md5) - end - end - end +RSpec.describe NetboxClientRuby::Secrets::RSAKeyPair, faraday_stub: true do + let(:request_url) { '/api/secrets/generate-rsa-key-pair/' } + let(:response) { File.read('spec/fixtures/secrets/generate-rsa-key-pair.json') } - describe '#private_key' do - it 'queries the api' do - expect(faraday).to receive(request_method).once.and_call_original + # MD5, to keep the strings in this spec at a reasonable length + let(:expected_public_key_md5) { '29bdf13ae078d73fab4848634b2c3c37' } + let(:expected_private_key_md5) { '91e45a978633a43de04c3310bd550645' } - expect(md5sum(subject.private_key)).to eql(expected_private_key_md5) - end + describe '#public_key' do + it 'queries the api' do + expect(faraday).to receive(request_method).once.and_call_original - context 'then #public_key' do - it 'queries the api just once' do - expect(faraday).to receive(request_method).once.and_call_original + expect(md5sum(subject.public_key)).to eql(expected_public_key_md5) + end - expect(md5sum(subject.private_key)).to eql(expected_private_key_md5) - expect(md5sum(subject.public_key)).to eql(expected_public_key_md5) - end - end - end + context 'then #private_key' do + it 'queries the api just once' do + expect(faraday).to receive(request_method).once.and_call_original - describe '#reload' do - it 'sends a new query' do - expect(faraday).to receive(request_method).twice.and_call_original + expect(md5sum(subject.public_key)).to eql(expected_public_key_md5) + expect(md5sum(subject.private_key)).to eql(expected_private_key_md5) + end + end + end - expect(md5sum(subject.public_key)).to eql(expected_public_key_md5) - expect(md5sum(subject.private_key)).to eql(expected_private_key_md5) + describe '#private_key' do + it 'queries the api' do + expect(faraday).to receive(request_method).once.and_call_original - subject.reload + expect(md5sum(subject.private_key)).to eql(expected_private_key_md5) + end - expect(md5sum(subject.public_key)).to eql(expected_public_key_md5) - expect(md5sum(subject.private_key)).to eql(expected_private_key_md5) - end + context 'then #public_key' do + it 'queries the api just once' do + expect(faraday).to receive(request_method).once.and_call_original - it 'does not cause any effect' do - expect(subject.reload).to be_nil - end + expect(md5sum(subject.private_key)).to eql(expected_private_key_md5) + expect(md5sum(subject.public_key)).to eql(expected_public_key_md5) end + end + end - def md5sum(value) - Digest::MD5.hexdigest value - end + describe '#reload' do + it 'sends a new query' do + expect(faraday).to receive(request_method).twice.and_call_original + + expect(md5sum(subject.public_key)).to eql(expected_public_key_md5) + expect(md5sum(subject.private_key)).to eql(expected_private_key_md5) + + subject.reload + + expect(md5sum(subject.public_key)).to eql(expected_public_key_md5) + expect(md5sum(subject.private_key)).to eql(expected_private_key_md5) + end + + it 'does not cause any effect' do + expect(subject.reload).to be_nil end end -end + def md5sum(value) + Digest::MD5.hexdigest value + end +end diff --git a/spec/netbox_client_ruby/api/secrets/secret_role_spec.rb b/spec/netbox_client_ruby/api/secrets/secret_role_spec.rb index a1aae03..bceac5b 100644 --- a/spec/netbox_client_ruby/api/secrets/secret_role_spec.rb +++ b/spec/netbox_client_ruby/api/secrets/secret_role_spec.rb @@ -1,131 +1,126 @@ require 'spec_helper' -module NetboxClientRuby - module Secrets - RSpec.describe SecretRole, faraday_stub: true do - let(:secret_id) { 1 } - let(:base_url) { '/api/secrets/secret-roles/' } - let(:request_url) { "#{base_url}#{secret_id}.json" } - let(:response) { File.read("spec/fixtures/secrets/secret-role_#{secret_id}.json") } - - subject { SecretRole.new secret_id } - - describe '#id' do - it 'shall be the expected id' do - expect(subject.id).to eq(secret_id) - end - end +RSpec.describe NetboxClientRuby::Secrets::SecretRole, faraday_stub: true do + let(:secret_id) { 1 } + let(:base_url) { '/api/secrets/secret-roles/' } + let(:request_url) { "#{base_url}#{secret_id}.json" } + let(:response) { File.read("spec/fixtures/secrets/secret-role_#{secret_id}.json") } - describe '#name' do - it 'should fetch the data' do - expect(faraday).to receive(:get).and_call_original + subject { NetboxClientRuby::Secrets::SecretRole.new secret_id } - subject.name - end + describe '#id' do + it 'shall be the expected id' do + expect(subject.id).to eq(secret_id) + end + end - it 'shall be the expected name' do - expect(subject.name).to eq('ipmi_password') - end - end + describe '#name' do + it 'should fetch the data' do + expect(faraday).to receive(:get).and_call_original - describe '.delete' do - let(:request_method) { :delete } - let(:response_status) { 204 } - let(:response) { nil } + subject.name + end - it 'should delete the object' do - expect(faraday).to receive(request_method).and_call_original - subject.delete - end - end + it 'shall be the expected name' do + expect(subject.name).to eq('ipmi_password') + end + end - describe '.update' do - let(:request_method) { :patch } - let(:request_params) { { 'name' => 'noob' } } + describe '.delete' do + let(:request_method) { :delete } + let(:response_status) { 204 } + let(:response) { nil } - it 'should update the object' do - expect(faraday).to receive(request_method).and_call_original - expect(subject.update(name: 'noob').name).to eq('ipmi_password') - end - end + it 'should delete the object' do + expect(faraday).to receive(request_method).and_call_original + subject.delete + end + end - describe '.reload' do - it 'should reload the object' do - expect(faraday).to receive(request_method).twice.and_call_original + describe '.update' do + let(:request_method) { :patch } + let(:request_params) { { 'name' => 'noob' } } - subject.reload - subject.reload - end - end + it 'should update the object' do + expect(faraday).to receive(request_method).and_call_original + expect(subject.update(name: 'noob').name).to eq('ipmi_password') + end + end - describe '.save' do - let(:name) { 'foobar' } - let(:request_params) { { 'name' => name } } + describe '.reload' do + it 'should reload the object' do + expect(faraday).to receive(request_method).twice.and_call_original - context 'update' do - let(:request_method) { :patch } + subject.reload + subject.reload + end + end - subject do - entity = SecretRole.new secret_id - entity.name = name - entity - end + describe '.save' do + let(:name) { 'foobar' } + let(:request_params) { { 'name' => name } } - it 'does not call PATCH until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + context 'update' do + let(:request_method) { :patch } - expect(subject.name).to eq(name) - end + subject do + entity = NetboxClientRuby::Secrets::SecretRole.new secret_id + entity.name = name + entity + end - it 'calls PATCH when save is called' do - expect(faraday).to receive(request_method).and_call_original + it 'does not call PATCH until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) - expect(subject.save).to be(subject) - end + expect(subject.name).to eq(name) + end - it 'Reads the answer from the PATCH answer' do - expect(faraday).to receive(request_method).and_call_original + it 'calls PATCH when save is called' do + expect(faraday).to receive(request_method).and_call_original - subject.save - expect(subject.name).to eq('ipmi_password') - end - end + expect(subject.save).to be(subject) + end - context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } + it 'Reads the answer from the PATCH answer' do + expect(faraday).to receive(request_method).and_call_original - subject do - entity = SecretRole.new - entity.name = name - entity - end + subject.save + expect(subject.name).to eq('ipmi_password') + end + end - it 'does not POST until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + context 'create' do + let(:request_method) { :post } + let(:request_url) { base_url } - expect(subject.name).to eq(name) - end + subject do + entity = NetboxClientRuby::Secrets::SecretRole.new + entity.name = name + entity + end + + it 'does not POST until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) + + expect(subject.name).to eq(name) + end - it 'POSTs the data upon a call of save' do - expect(faraday).to receive(request_method).and_call_original + it 'POSTs the data upon a call of save' do + expect(faraday).to receive(request_method).and_call_original - expect(subject.save).to be(subject) - end + expect(subject.save).to be(subject) + end - it 'Reads the answer from the POST' do - expect(faraday).to receive(request_method).and_call_original + it 'Reads the answer from the POST' do + expect(faraday).to receive(request_method).and_call_original - subject.save + subject.save - expect(subject.id).to be(1) - expect(subject.name).to eq('ipmi_password') - end - end + expect(subject.id).to be(1) + expect(subject.name).to eq('ipmi_password') end end end end - diff --git a/spec/netbox_client_ruby/api/secrets/secret_roles_spec.rb b/spec/netbox_client_ruby/api/secrets/secret_roles_spec.rb index 7e38708..ec27dda 100644 --- a/spec/netbox_client_ruby/api/secrets/secret_roles_spec.rb +++ b/spec/netbox_client_ruby/api/secrets/secret_roles_spec.rb @@ -1,57 +1,53 @@ require 'spec_helper' -module NetboxClientRuby - module Secrets - RSpec.describe SecretRoles, faraday_stub: true do - let(:response) { File.read('spec/fixtures/secrets/secret-roles.json') } - let(:request_url) { '/api/secrets/secret-roles.json' } - let(:request_url_params) do - { limit: NetboxClientRuby.config.netbox.pagination.default_limit } - end +RSpec.describe NetboxClientRuby::Secrets::SecretRoles, faraday_stub: true do + let(:response) { File.read('spec/fixtures/secrets/secret-roles.json') } + let(:request_url) { '/api/secrets/secret-roles.json' } + let(:request_url_params) do + { limit: NetboxClientRuby.config.netbox.pagination.default_limit } + end - context 'unpaged fetch' do - describe '#length' do - it 'shall be the expected length' do - expect(subject.length).to be 2 - end - end - - describe '#total' do - it 'shall be the expected total' do - expect(subject.total).to be 2 - end - end + context 'unpaged fetch' do + describe '#length' do + it 'shall be the expected length' do + expect(subject.length).to be 2 end + end - describe '#reload' do - it 'fetches the correct data' do - expect(faraday).to receive(:get).and_call_original - subject.reload - end - - it 'caches the data' do - expect(faraday).to receive(:get).and_call_original - subject.total - subject.total - end - - it 'reloads the data' do - expect(faraday).to receive(:get).twice.and_call_original - subject.reload - subject.reload - end + describe '#total' do + it 'shall be the expected total' do + expect(subject.total).to be 2 end + end + end + + describe '#reload' do + it 'fetches the correct data' do + expect(faraday).to receive(:get).and_call_original + subject.reload + end - describe '#as_array' do - it 'return the correct amount' do - expect(subject.to_a.length).to be 2 - end + it 'caches the data' do + expect(faraday).to receive(:get).and_call_original + subject.total + subject.total + end + + it 'reloads the data' do + expect(faraday).to receive(:get).twice.and_call_original + subject.reload + subject.reload + end + end + + describe '#as_array' do + it 'return the correct amount' do + expect(subject.to_a.length).to be 2 + end - it 'returns single instances' do - subject.to_a.each do |element| - expect(element).to be_a SecretRole - end - end + it 'returns single instances' do + subject.to_a.each do |element| + expect(element).to be_a NetboxClientRuby::Secrets::SecretRole end end end diff --git a/spec/netbox_client_ruby/api/secrets/secret_spec.rb b/spec/netbox_client_ruby/api/secrets/secret_spec.rb index f2c322a..4b85d84 100644 --- a/spec/netbox_client_ruby/api/secrets/secret_spec.rb +++ b/spec/netbox_client_ruby/api/secrets/secret_spec.rb @@ -1,147 +1,142 @@ require 'spec_helper' -module NetboxClientRuby - module Secrets - RSpec.describe Secret, faraday_stub: true do - let(:secret_id) { 1 } - let(:base_url) { '/api/secrets/secrets/' } - let(:request_url) { "#{base_url}#{secret_id}.json" } - let(:response) { File.read("spec/fixtures/secrets/secret_#{secret_id}.json") } - - subject { Secret.new secret_id } - - describe '#id' do - it 'shall be the expected id' do - expect(subject.id).to eq(secret_id) - end - end +RSpec.describe NetboxClientRuby::Secrets::Secret, faraday_stub: true do + let(:secret_id) { 1 } + let(:base_url) { '/api/secrets/secrets/' } + let(:request_url) { "#{base_url}#{secret_id}.json" } + let(:response) { File.read("spec/fixtures/secrets/secret_#{secret_id}.json") } - describe '#name' do - it 'should fetch the data' do - expect(faraday).to receive(:get).and_call_original + subject { NetboxClientRuby::Secrets::Secret.new secret_id } - subject.name - end + describe '#id' do + it 'shall be the expected id' do + expect(subject.id).to eq(secret_id) + end + end - it 'shall be the expected name' do - expect(subject.name).to eq('secret1') - end - end + describe '#name' do + it 'should fetch the data' do + expect(faraday).to receive(:get).and_call_original - describe '#plaintext' do - context 'no plaintext value' do - it 'should return a nil value' do - expect(subject.plaintext).to be_nil - end - end + subject.name + end - context 'a plaintext value' do - let(:response) { File.read("spec/fixtures/secrets/secret_#{secret_id}_with_plaintext.json") } + it 'shall be the expected name' do + expect(subject.name).to eq('secret1') + end + end - it 'should return the plaintext value' do - expect(subject.plaintext).to eql('n00b') - end - end + describe '#plaintext' do + context 'no plaintext value' do + it 'should return a nil value' do + expect(subject.plaintext).to be_nil end + end - describe '.delete' do - let(:request_method) { :delete } - let(:response_status) { 204 } - let(:response) { nil } + context 'a plaintext value' do + let(:response) { File.read("spec/fixtures/secrets/secret_#{secret_id}_with_plaintext.json") } - it 'should delete the object' do - expect(faraday).to receive(request_method).and_call_original - subject.delete - end + it 'should return the plaintext value' do + expect(subject.plaintext).to eql('n00b') end + end + end - describe '.update' do - let(:request_method) { :patch } - let(:request_params) { { 'name' => 'noob' } } + describe '.delete' do + let(:request_method) { :delete } + let(:response_status) { 204 } + let(:response) { nil } - it 'should update the object' do - expect(faraday).to receive(request_method).and_call_original - expect(subject.update(name: 'noob').name).to eq('secret1') - end - end + it 'should delete the object' do + expect(faraday).to receive(request_method).and_call_original + subject.delete + end + end - describe '.reload' do - it 'should reload the object' do - expect(faraday).to receive(request_method).twice.and_call_original + describe '.update' do + let(:request_method) { :patch } + let(:request_params) { { 'name' => 'noob' } } - subject.reload - subject.reload - end - end + it 'should update the object' do + expect(faraday).to receive(request_method).and_call_original + expect(subject.update(name: 'noob').name).to eq('secret1') + end + end - describe '.save' do - let(:name) { 'foobar' } - let(:request_params) { { 'name' => name } } + describe '.reload' do + it 'should reload the object' do + expect(faraday).to receive(request_method).twice.and_call_original - context 'update' do - let(:request_method) { :patch } + subject.reload + subject.reload + end + end - subject do - entity = Secret.new secret_id - entity.name = name - entity - end + describe '.save' do + let(:name) { 'foobar' } + let(:request_params) { { 'name' => name } } - it 'does not call PATCH until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + context 'update' do + let(:request_method) { :patch } - expect(subject.name).to eq(name) - end + subject do + entity = NetboxClientRuby::Secrets::Secret.new secret_id + entity.name = name + entity + end + + it 'does not call PATCH until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) + + expect(subject.name).to eq(name) + end - it 'calls PATCH when save is called' do - expect(faraday).to receive(request_method).and_call_original + it 'calls PATCH when save is called' do + expect(faraday).to receive(request_method).and_call_original - expect(subject.save).to be(subject) - end + expect(subject.save).to be(subject) + end - it 'Reads the answer from the PATCH answer' do - expect(faraday).to receive(request_method).and_call_original + it 'Reads the answer from the PATCH answer' do + expect(faraday).to receive(request_method).and_call_original - subject.save - expect(subject.name).to eq('secret1') - end - end + subject.save + expect(subject.name).to eq('secret1') + end + end - context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } + context 'create' do + let(:request_method) { :post } + let(:request_url) { base_url } - subject do - entity = Secret.new - entity.name = name - entity - end + subject do + entity = NetboxClientRuby::Secrets::Secret.new + entity.name = name + entity + end - it 'does not POST until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + it 'does not POST until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) - expect(subject.name).to eq(name) - end + expect(subject.name).to eq(name) + end - it 'POSTs the data upon a call of save' do - expect(faraday).to receive(request_method).and_call_original + it 'POSTs the data upon a call of save' do + expect(faraday).to receive(request_method).and_call_original - expect(subject.save).to be(subject) - end + expect(subject.save).to be(subject) + end - it 'Reads the answer from the POST' do - expect(faraday).to receive(request_method).and_call_original + it 'Reads the answer from the POST' do + expect(faraday).to receive(request_method).and_call_original - subject.save + subject.save - expect(subject.id).to be(1) - expect(subject.name).to eq('secret1') - end - end + expect(subject.id).to be(1) + expect(subject.name).to eq('secret1') end end end end - diff --git a/spec/netbox_client_ruby/api/secrets/secrets_spec.rb b/spec/netbox_client_ruby/api/secrets/secrets_spec.rb index db3c12d..3fdc20f 100644 --- a/spec/netbox_client_ruby/api/secrets/secrets_spec.rb +++ b/spec/netbox_client_ruby/api/secrets/secrets_spec.rb @@ -1,57 +1,53 @@ require 'spec_helper' -module NetboxClientRuby - module Secrets - RSpec.describe Secrets, faraday_stub: true do - let(:response) { File.read('spec/fixtures/secrets/secrets.json') } - let(:request_url) { '/api/secrets/secrets.json' } - let(:request_url_params) do - { limit: NetboxClientRuby.config.netbox.pagination.default_limit } - end +RSpec.describe NetboxClientRuby::Secrets::Secrets, faraday_stub: true do + let(:response) { File.read('spec/fixtures/secrets/secrets.json') } + let(:request_url) { '/api/secrets/secrets.json' } + let(:request_url_params) do + { limit: NetboxClientRuby.config.netbox.pagination.default_limit } + end - context 'unpaged fetch' do - describe '#length' do - it 'shall be the expected length' do - expect(subject.length).to be 1 - end - end - - describe '#total' do - it 'shall be the expected total' do - expect(subject.total).to be 1 - end - end + context 'unpaged fetch' do + describe '#length' do + it 'shall be the expected length' do + expect(subject.length).to be 1 end + end - describe '#reload' do - it 'fetches the correct data' do - expect(faraday).to receive(:get).and_call_original - subject.reload - end - - it 'caches the data' do - expect(faraday).to receive(:get).and_call_original - subject.total - subject.total - end - - it 'reloads the data' do - expect(faraday).to receive(:get).twice.and_call_original - subject.reload - subject.reload - end + describe '#total' do + it 'shall be the expected total' do + expect(subject.total).to be 1 end + end + end + + describe '#reload' do + it 'fetches the correct data' do + expect(faraday).to receive(:get).and_call_original + subject.reload + end - describe '#as_array' do - it 'return the correct amount' do - expect(subject.to_a.length).to be 1 - end + it 'caches the data' do + expect(faraday).to receive(:get).and_call_original + subject.total + subject.total + end + + it 'reloads the data' do + expect(faraday).to receive(:get).twice.and_call_original + subject.reload + subject.reload + end + end + + describe '#as_array' do + it 'return the correct amount' do + expect(subject.to_a.length).to be 1 + end - it 'returns single instances' do - subject.to_a.each do |element| - expect(element).to be_a Secret - end - end + it 'returns single instances' do + subject.to_a.each do |element| + expect(element).to be_a NetboxClientRuby::Secrets::Secret end end end diff --git a/spec/netbox_client_ruby/api/secrets/session_key_spec.rb b/spec/netbox_client_ruby/api/secrets/session_key_spec.rb index f1eb094..113c02e 100644 --- a/spec/netbox_client_ruby/api/secrets/session_key_spec.rb +++ b/spec/netbox_client_ruby/api/secrets/session_key_spec.rb @@ -1,126 +1,121 @@ require 'spec_helper' -module NetboxClientRuby - module Secrets - RSpec.describe SessionKey, faraday_stub: true do - let(:request_method) { :post } - let(:request_url) { '/api/secrets/get-session-key/' } - let(:request_params) { { private_key: File.read('spec/fixtures/secrets/rsa_private_key') } } - let(:response) { File.read('spec/fixtures/secrets/get-session-key.json') } - let(:expected_session_key) { '+8t4SI6XikgVmB5+/urhozx9O5qCQANyOk1MNe6taRf=' } - - after do - NetboxClientRuby.secrets.session_key = nil - end +RSpec.describe NetboxClientRuby::Secrets::SessionKey, faraday_stub: true do + let(:request_method) { :post } + let(:request_url) { '/api/secrets/get-session-key/' } + let(:request_params) { { private_key: File.read('spec/fixtures/secrets/rsa_private_key') } } + let(:response) { File.read('spec/fixtures/secrets/get-session-key.json') } + let(:expected_session_key) { '+8t4SI6XikgVmB5+/urhozx9O5qCQANyOk1MNe6taRf=' } + + after do + NetboxClientRuby.secrets.session_key = nil + end - describe '#session_key' do - context 'unencrypted key' do - it 'receives the session key' do - expect(faraday).to receive(request_method).and_call_original + describe '#session_key' do + context 'unencrypted key' do + it 'receives the session key' do + expect(faraday).to receive(request_method).and_call_original - expect(subject.session_key).to eql(expected_session_key) - end + expect(subject.session_key).to eql(expected_session_key) + end - it 'sets the session_key for future requests with secrets' do - subject.session_key + it 'sets the session_key for future requests with secrets' do + subject.session_key - expect(NetboxClientRuby::Secrets.session_key).to eql(expected_session_key) - end + expect(NetboxClientRuby::Secrets.session_key).to eql(expected_session_key) + end - context 'but password is given' do - let(:netbox_auth_rsa_private_key_pass) { 'unnecessary_password' } + context 'but password is given' do + let(:netbox_auth_rsa_private_key_pass) { 'unnecessary_password' } - it 'receives the session key anyway' do - expect(faraday).to receive(request_method).and_call_original + it 'receives the session key anyway' do + expect(faraday).to receive(request_method).and_call_original - expect(subject.session_key).to eql(expected_session_key) - end - end + expect(subject.session_key).to eql(expected_session_key) end + end + end - context 'encrypted key' do - let(:netbox_auth_rsa_private_key_file) { 'spec/fixtures/secrets/rsa_private_key_pwd' } - let(:netbox_auth_rsa_private_key_pass) { 'password' } + context 'encrypted key' do + let(:netbox_auth_rsa_private_key_file) { 'spec/fixtures/secrets/rsa_private_key_pwd' } + let(:netbox_auth_rsa_private_key_pass) { 'password' } - it 'receives the session key' do - expect(faraday).to receive(request_method).and_call_original + it 'receives the session key' do + expect(faraday).to receive(request_method).and_call_original - expect(subject.session_key).to eql(expected_session_key) - end + expect(subject.session_key).to eql(expected_session_key) + end - context 'but a wrong password is given' do - let(:netbox_auth_rsa_private_key_pass) { 'wrong_password' } - it 'does not send any request to the server' do - expect(faraday).to_not receive(request_method) + context 'but a wrong password is given' do + let(:netbox_auth_rsa_private_key_pass) { 'wrong_password' } + it 'does not send any request to the server' do + expect(faraday).to_not receive(request_method) - expect { subject.session_key }.to raise_error(NetboxClientRuby::LocalError) - end - end + expect { subject.session_key }.to raise_error(NetboxClientRuby::LocalError) + end + end - context 'but no password is given' do - let(:netbox_auth_rsa_private_key_pass) { nil } + context 'but no password is given' do + let(:netbox_auth_rsa_private_key_pass) { nil } - it 'does not send any request to the server' do - expect(faraday).to_not receive(request_method) + it 'does not send any request to the server' do + expect(faraday).to_not receive(request_method) - expect { subject.session_key }.to raise_error(NetboxClientRuby::LocalError) - end - end + expect { subject.session_key }.to raise_error(NetboxClientRuby::LocalError) end + end + end - context 'invalid path' do - let(:netbox_auth_rsa_private_key_file) { '/does/not/exists' } + context 'invalid path' do + let(:netbox_auth_rsa_private_key_file) { '/does/not/exists' } - it 'does not send any request to the server' do - expect(faraday).to_not receive(request_method) + it 'does not send any request to the server' do + expect(faraday).to_not receive(request_method) - expect { subject.session_key }.to raise_error(NetboxClientRuby::LocalError) - end - end + expect { subject.session_key }.to raise_error(NetboxClientRuby::LocalError) + end + end - context 'empty key' do - let(:netbox_auth_rsa_private_key_file) { 'spec/fixtures/secrets/empty_file' } + context 'empty key' do + let(:netbox_auth_rsa_private_key_file) { 'spec/fixtures/secrets/empty_file' } - it 'does not send any request to the server' do - expect(faraday).to_not receive(request_method) + it 'does not send any request to the server' do + expect(faraday).to_not receive(request_method) - expect { subject.session_key }.to raise_error(NetboxClientRuby::LocalError) - end - end + expect { subject.session_key }.to raise_error(NetboxClientRuby::LocalError) + end + end - context 'existing session key' do - before do - NetboxClientRuby.secrets.session_key = expected_session_key - end + context 'existing session key' do + before do + NetboxClientRuby.secrets.session_key = expected_session_key + end - it 'does not send a request to the server' do - expect(faraday).to_not receive(request_method) + it 'does not send a request to the server' do + expect(faraday).to_not receive(request_method) - expect(subject.session_key).to eql(expected_session_key) - end - end + expect(subject.session_key).to eql(expected_session_key) end + end + end - describe '#reload' do - before do - NetboxClientRuby.secrets.session_key = expected_session_key - end + describe '#reload' do + before do + NetboxClientRuby.secrets.session_key = expected_session_key + end - it 'sends a request to the server' do - expect(faraday).to receive(request_method).once.and_call_original + it 'sends a request to the server' do + expect(faraday).to receive(request_method).once.and_call_original - expect(subject.reload).to eql(expected_session_key) - expect(subject.session_key).to eql(expected_session_key) - end + expect(subject.reload).to eql(expected_session_key) + expect(subject.session_key).to eql(expected_session_key) + end - it 'always sends a request to the server' do - expect(faraday).to receive(request_method).twice.and_call_original + it 'always sends a request to the server' do + expect(faraday).to receive(request_method).twice.and_call_original - expect(subject.reload).to eql(expected_session_key) - expect(subject.reload).to eql(expected_session_key) - end - end + expect(subject.reload).to eql(expected_session_key) + expect(subject.reload).to eql(expected_session_key) end end end - diff --git a/spec/netbox_client_ruby/api/secrets_spec.rb b/spec/netbox_client_ruby/api/secrets_spec.rb index b731d74..905941a 100644 --- a/spec/netbox_client_ruby/api/secrets_spec.rb +++ b/spec/netbox_client_ruby/api/secrets_spec.rb @@ -1,89 +1,85 @@ require 'spec_helper' -module NetboxClientRuby - module Secrets - RSpec.describe NetboxClientRuby::Secrets do - { - secret_roles: SecretRoles, - secrets: NetboxClientRuby::Secrets::Secrets - }.each do |method, klass| - describe ".#{method}" do - subject { described_class.public_send(method) } +RSpec.describe NetboxClientRuby::Secrets do + { + secret_roles: NetboxClientRuby::Secrets::SecretRoles, + secrets: NetboxClientRuby::Secrets::Secrets + }.each do |method, klass| + describe ".#{method}" do + subject { described_class.public_send(method) } - context 'is of the correct type' do - it { is_expected.to be_a klass } - end - - context 'is a different instance each time' do - it do - is_expected - .to_not be described_class.public_send(method) - end - end + context 'is of the correct type' do + it { is_expected.to be_a klass } + end - context 'is an Entities object' do - it { is_expected.to respond_to(:get!) } - end + context 'is a different instance each time' do + it do + is_expected + .to_not be described_class.public_send(method) end end - { - secret: Secret, - secret_role: SecretRole - }.each do |method, expected_class| - describe ".#{method}" do - let(:id) { 1 } - subject { described_class.public_send(method, id) } + context 'is an Entities object' do + it { is_expected.to respond_to(:get!) } + end + end + end - context 'is of the expected type' do - it { is_expected.to be_a expected_class } - end + { + secret: NetboxClientRuby::Secrets::Secret, + secret_role: NetboxClientRuby::Secrets::SecretRole + }.each do |method, expected_class| + describe ".#{method}" do + let(:id) { 1 } + subject { described_class.public_send(method, id) } - context 'it is a new instance each time' do - it do - is_expected - .to_not be described_class.public_send(method, id) - end - end + context 'is of the expected type' do + it { is_expected.to be_a expected_class } + end - context 'is an Entity object' do - it { is_expected.to respond_to(:get!) } - end + context 'it is a new instance each time' do + it do + is_expected + .to_not be described_class.public_send(method, id) end end - describe '.generate_rsa_key_pair' do - subject { described_class.generate_rsa_key_pair } + context 'is an Entity object' do + it { is_expected.to respond_to(:get!) } + end + end + end - context 'is of the expected type' do - it { is_expected.to be_a RSAKeyPair } - end + describe '.generate_rsa_key_pair' do + subject { described_class.generate_rsa_key_pair } - context 'it is a new instance each time' do - it do - is_expected - .to_not be described_class.generate_rsa_key_pair - end - end + context 'is of the expected type' do + it { is_expected.to be_a NetboxClientRuby::Secrets::RSAKeyPair } + end + + context 'it is a new instance each time' do + it do + is_expected + .to_not be described_class.generate_rsa_key_pair end + end + end - describe '.get_session_key' do - subject { described_class.get_session_key } + describe '.get_session_key' do + subject { described_class.get_session_key } - before do - allow_any_instance_of(NetboxClientRuby::Secrets::SessionKey).to receive(:session_key).and_return('a') - end + before do + allow_any_instance_of(NetboxClientRuby::Secrets::SessionKey).to receive(:session_key).and_return('a') + end - context 'is of the expected type' do - it { is_expected.to be_a SessionKey } - end + context 'is of the expected type' do + it { is_expected.to be_a NetboxClientRuby::Secrets::SessionKey } + end - context 'it is a new instance each time' do - it do - is_expected - .to_not be described_class.get_session_key - end - end + context 'it is a new instance each time' do + it do + is_expected + .to_not be described_class.get_session_key end end end diff --git a/spec/netbox_client_ruby/api/tenancy/tenant_group_spec.rb b/spec/netbox_client_ruby/api/tenancy/tenant_group_spec.rb index f251d8f..e21b295 100644 --- a/spec/netbox_client_ruby/api/tenancy/tenant_group_spec.rb +++ b/spec/netbox_client_ruby/api/tenancy/tenant_group_spec.rb @@ -1,136 +1,132 @@ require 'spec_helper' -module NetboxClientRuby - module Tenancy - RSpec.describe TenantGroup, faraday_stub: true do - let(:region_id) { 1 } - let(:base_url) { '/api/tenancy/tenant-groups/' } - let(:request_url) { "#{base_url}#{region_id}.json" } - let(:response) { File.read("spec/fixtures/tenancy/tenant-group_#{region_id}.json") } - - subject { TenantGroup.new region_id } - - describe '#id' do - it 'shall be the expected id' do - expect(subject.id).to eq(region_id) - end - end +RSpec.describe NetboxClientRuby::Tenancy::TenantGroup, faraday_stub: true do + let(:region_id) { 1 } + let(:base_url) { '/api/tenancy/tenant-groups/' } + let(:request_url) { "#{base_url}#{region_id}.json" } + let(:response) { File.read("spec/fixtures/tenancy/tenant-group_#{region_id}.json") } - describe '#name' do - it 'should fetch the data' do - expect(faraday).to receive(:get).and_call_original + subject { NetboxClientRuby::Tenancy::TenantGroup.new region_id } - subject.name - end + describe '#id' do + it 'shall be the expected id' do + expect(subject.id).to eq(region_id) + end + end - it 'shall be the expected name' do - expect(subject.name).to eq('Customer') - end - end + describe '#name' do + it 'should fetch the data' do + expect(faraday).to receive(:get).and_call_original - describe '.delete' do - let(:request_method) { :delete } - let(:response_status) { 204 } - let(:response) { nil } + subject.name + end - it 'should delete the object' do - expect(faraday).to receive(request_method).and_call_original - subject.delete - end - end + it 'shall be the expected name' do + expect(subject.name).to eq('Customer') + end + end - describe '.update' do - let(:request_method) { :patch } - let(:request_params) { { 'name' => 'noob' } } + describe '.delete' do + let(:request_method) { :delete } + let(:response_status) { 204 } + let(:response) { nil } - it 'should update the object' do - expect(faraday).to receive(request_method).and_call_original - expect(subject.update(name: 'noob').name).to eq('Customer') - end - end + it 'should delete the object' do + expect(faraday).to receive(request_method).and_call_original + subject.delete + end + end - describe '.reload' do - it 'should reload the object' do - expect(faraday).to receive(request_method).twice.and_call_original + describe '.update' do + let(:request_method) { :patch } + let(:request_params) { { 'name' => 'noob' } } - subject.reload - subject.reload - end - end + it 'should update the object' do + expect(faraday).to receive(request_method).and_call_original + expect(subject.update(name: 'noob').name).to eq('Customer') + end + end - describe '.save' do - let(:name) { 'foobar' } - let(:slug) { name } - let(:request_params) { { 'name' => name, 'slug' => slug } } + describe '.reload' do + it 'should reload the object' do + expect(faraday).to receive(request_method).twice.and_call_original - context 'update' do - let(:request_method) { :patch } + subject.reload + subject.reload + end + end - subject do - entity = TenantGroup.new region_id - entity.name = name - entity.slug = slug - entity - end + describe '.save' do + let(:name) { 'foobar' } + let(:slug) { name } + let(:request_params) { { 'name' => name, 'slug' => slug } } - it 'does not call PATCH until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + context 'update' do + let(:request_method) { :patch } - expect(subject.name).to eq(name) - expect(subject.slug).to eq(slug) - end + subject do + entity = NetboxClientRuby::Tenancy::TenantGroup.new region_id + entity.name = name + entity.slug = slug + entity + end - it 'calls PATCH when save is called' do - expect(faraday).to receive(request_method).and_call_original + it 'does not call PATCH until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) - expect(subject.save).to be(subject) - end + expect(subject.name).to eq(name) + expect(subject.slug).to eq(slug) + end - it 'Reads the answer from the PATCH answer' do - expect(faraday).to receive(request_method).and_call_original + it 'calls PATCH when save is called' do + expect(faraday).to receive(request_method).and_call_original - subject.save - expect(subject.name).to eq('Customer') - expect(subject.slug).to eq('customer') - end - end + expect(subject.save).to be(subject) + end - context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } + it 'Reads the answer from the PATCH answer' do + expect(faraday).to receive(request_method).and_call_original - subject do - entity = TenantGroup.new - entity.name = name - entity.slug = slug - entity - end + subject.save + expect(subject.name).to eq('Customer') + expect(subject.slug).to eq('customer') + end + end + + context 'create' do + let(:request_method) { :post } + let(:request_url) { base_url } + + subject do + entity = NetboxClientRuby::Tenancy::TenantGroup.new + entity.name = name + entity.slug = slug + entity + end - it 'does not POST until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + it 'does not POST until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) - expect(subject.name).to eq(name) - expect(subject.slug).to eq(slug) - end + expect(subject.name).to eq(name) + expect(subject.slug).to eq(slug) + end - it 'POSTs the data upon a call of save' do - expect(faraday).to receive(request_method).and_call_original + it 'POSTs the data upon a call of save' do + expect(faraday).to receive(request_method).and_call_original - expect(subject.save).to be(subject) - end + expect(subject.save).to be(subject) + end - it 'Reads the answer from the POST' do - expect(faraday).to receive(request_method).and_call_original + it 'Reads the answer from the POST' do + expect(faraday).to receive(request_method).and_call_original - subject.save + subject.save - expect(subject.id).to be(1) - expect(subject.name).to eq('Customer') - expect(subject.slug).to eq('customer') - end - end + expect(subject.id).to be(1) + expect(subject.name).to eq('Customer') + expect(subject.slug).to eq('customer') end end end diff --git a/spec/netbox_client_ruby/api/tenancy/tenant_spec.rb b/spec/netbox_client_ruby/api/tenancy/tenant_spec.rb index 21d3c45..b36149f 100644 --- a/spec/netbox_client_ruby/api/tenancy/tenant_spec.rb +++ b/spec/netbox_client_ruby/api/tenancy/tenant_spec.rb @@ -1,152 +1,148 @@ require 'spec_helper' -module NetboxClientRuby - module Tenancy - RSpec.describe Tenant, faraday_stub: true do - let(:region_id) { 1 } - let(:base_url) { '/api/tenancy/tenants/' } - let(:request_url) { "#{base_url}#{region_id}.json" } - let(:response) { File.read("spec/fixtures/tenancy/tenant_#{region_id}.json") } - - subject { Tenant.new region_id } - - describe '#id' do - it 'shall be the expected id' do - expect(subject.id).to eq(region_id) - end - end +RSpec.describe NetboxClientRuby::Tenancy::Tenant, faraday_stub: true do + let(:region_id) { 1 } + let(:base_url) { '/api/tenancy/tenants/' } + let(:request_url) { "#{base_url}#{region_id}.json" } + let(:response) { File.read("spec/fixtures/tenancy/tenant_#{region_id}.json") } - describe '#name' do - it 'should fetch the data' do - expect(faraday).to receive(:get).and_call_original + subject { NetboxClientRuby::Tenancy::Tenant.new region_id } - subject.name - end + describe '#id' do + it 'shall be the expected id' do + expect(subject.id).to eq(region_id) + end + end - it 'shall be the expected name' do - expect(subject.name).to eq('tenant1') - end - end + describe '#name' do + it 'should fetch the data' do + expect(faraday).to receive(:get).and_call_original - describe '.group' do - it 'should be nil' do - expect(subject.group).to be_nil - end + subject.name + end - context 'Tenant with Group' do - let(:region_id) { 3 } + it 'shall be the expected name' do + expect(subject.name).to eq('tenant1') + end + end - it 'should be a TenantGroup object' do - tenant_group = subject.group - expect(tenant_group).to be_a TenantGroup - expect(tenant_group.id).to eq(1) - end - end - end + describe '.group' do + it 'should be nil' do + expect(subject.group).to be_nil + end - describe '.delete' do - let(:request_method) { :delete } - let(:response_status) { 204 } - let(:response) { nil } + context 'Tenant with Group' do + let(:region_id) { 3 } - it 'should delete the object' do - expect(faraday).to receive(request_method).and_call_original - subject.delete - end + it 'should be a TenantGroup object' do + tenant_group = subject.group + expect(tenant_group).to be_a NetboxClientRuby::Tenancy::TenantGroup + expect(tenant_group.id).to eq(1) end + end + end - describe '.update' do - let(:request_method) { :patch } - let(:request_params) { { 'name' => 'noob' } } + describe '.delete' do + let(:request_method) { :delete } + let(:response_status) { 204 } + let(:response) { nil } - it 'should update the object' do - expect(faraday).to receive(request_method).and_call_original - expect(subject.update(name: 'noob').name).to eq('tenant1') - end - end + it 'should delete the object' do + expect(faraday).to receive(request_method).and_call_original + subject.delete + end + end - describe '.reload' do - it 'should reload the object' do - expect(faraday).to receive(request_method).twice.and_call_original + describe '.update' do + let(:request_method) { :patch } + let(:request_params) { { 'name' => 'noob' } } - subject.reload - subject.reload - end - end + it 'should update the object' do + expect(faraday).to receive(request_method).and_call_original + expect(subject.update(name: 'noob').name).to eq('tenant1') + end + end - describe '.save' do - let(:name) { 'foobar' } - let(:slug) { name } - let(:request_params) { { 'name' => name, 'slug' => slug } } + describe '.reload' do + it 'should reload the object' do + expect(faraday).to receive(request_method).twice.and_call_original - context 'update' do - let(:request_method) { :patch } + subject.reload + subject.reload + end + end - subject do - entity = Tenant.new region_id - entity.name = name - entity.slug = slug - entity - end + describe '.save' do + let(:name) { 'foobar' } + let(:slug) { name } + let(:request_params) { { 'name' => name, 'slug' => slug } } + + context 'update' do + let(:request_method) { :patch } + + subject do + entity = NetboxClientRuby::Tenancy::Tenant.new region_id + entity.name = name + entity.slug = slug + entity + end - it 'does not call PATCH until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + it 'does not call PATCH until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) - expect(subject.name).to eq(name) - expect(subject.slug).to eq(slug) - end + expect(subject.name).to eq(name) + expect(subject.slug).to eq(slug) + end - it 'calls PATCH when save is called' do - expect(faraday).to receive(request_method).and_call_original + it 'calls PATCH when save is called' do + expect(faraday).to receive(request_method).and_call_original - expect(subject.save).to be(subject) - end + expect(subject.save).to be(subject) + end - it 'Reads the answer from the PATCH answer' do - expect(faraday).to receive(request_method).and_call_original + it 'Reads the answer from the PATCH answer' do + expect(faraday).to receive(request_method).and_call_original - subject.save - expect(subject.name).to eq('tenant1') - expect(subject.slug).to eq('tenant1') - end - end + subject.save + expect(subject.name).to eq('tenant1') + expect(subject.slug).to eq('tenant1') + end + end - context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } + context 'create' do + let(:request_method) { :post } + let(:request_url) { base_url } - subject do - entity = Tenant.new - entity.name = name - entity.slug = slug - entity - end + subject do + entity = NetboxClientRuby::Tenancy::Tenant.new + entity.name = name + entity.slug = slug + entity + end - it 'does not POST until save is called' do - expect(faraday).to_not receive(request_method) - expect(faraday).to_not receive(:get) + it 'does not POST until save is called' do + expect(faraday).to_not receive(request_method) + expect(faraday).to_not receive(:get) - expect(subject.name).to eq(name) - expect(subject.slug).to eq(slug) - end + expect(subject.name).to eq(name) + expect(subject.slug).to eq(slug) + end - it 'POSTs the data upon a call of save' do - expect(faraday).to receive(request_method).and_call_original + it 'POSTs the data upon a call of save' do + expect(faraday).to receive(request_method).and_call_original - expect(subject.save).to be(subject) - end + expect(subject.save).to be(subject) + end - it 'Reads the answer from the POST' do - expect(faraday).to receive(request_method).and_call_original + it 'Reads the answer from the POST' do + expect(faraday).to receive(request_method).and_call_original - subject.save + subject.save - expect(subject.id).to be(1) - expect(subject.name).to eq('tenant1') - expect(subject.slug).to eq('tenant1') - end - end + expect(subject.id).to be(1) + expect(subject.name).to eq('tenant1') + expect(subject.slug).to eq('tenant1') end end end diff --git a/spec/netbox_client_ruby/api/tenancy/tenants_groups_spec.rb b/spec/netbox_client_ruby/api/tenancy/tenants_groups_spec.rb index f8eb905..03cfe76 100644 --- a/spec/netbox_client_ruby/api/tenancy/tenants_groups_spec.rb +++ b/spec/netbox_client_ruby/api/tenancy/tenants_groups_spec.rb @@ -1,60 +1,56 @@ require 'spec_helper' -module NetboxClientRuby - module Tenancy - RSpec.describe TenantGroups, faraday_stub: true do - let(:expected_number_of_items) { 1 } - let(:expected_singular_type) { TenantGroup } - - let(:response) { File.read('spec/fixtures/tenancy/tenant-groups.json') } - let(:request_url) { '/api/tenancy/tenant-groups.json' } - let(:request_url_params) do - { limit: NetboxClientRuby.config.netbox.pagination.default_limit } - end +RSpec.describe NetboxClientRuby::Tenancy::TenantGroups, faraday_stub: true do + let(:expected_number_of_items) { 1 } + let(:expected_singular_type) { NetboxClientRuby::Tenancy::TenantGroup } + + let(:response) { File.read('spec/fixtures/tenancy/tenant-groups.json') } + let(:request_url) { '/api/tenancy/tenant-groups.json' } + let(:request_url_params) do + { limit: NetboxClientRuby.config.netbox.pagination.default_limit } + end - context 'unpaged fetch' do - describe '#length' do - it 'shall be the expected length' do - expect(subject.length).to be expected_number_of_items - end - end - - describe '#total' do - it 'shall be the expected total' do - expect(subject.total).to be expected_number_of_items - end - end + context 'unpaged fetch' do + describe '#length' do + it 'shall be the expected length' do + expect(subject.length).to be expected_number_of_items end + end - describe '#reload' do - it 'fetches the correct data' do - expect(faraday).to receive(:get).and_call_original - subject.reload - end - - it 'caches the data' do - expect(faraday).to receive(:get).and_call_original - subject.total - subject.total - end - - it 'reloads the data' do - expect(faraday).to receive(:get).twice.and_call_original - subject.reload - subject.reload - end + describe '#total' do + it 'shall be the expected total' do + expect(subject.total).to be expected_number_of_items end + end + end + + describe '#reload' do + it 'fetches the correct data' do + expect(faraday).to receive(:get).and_call_original + subject.reload + end - describe '#as_array' do - it 'return the correct amount' do - expect(subject.to_a.length).to be expected_number_of_items - end + it 'caches the data' do + expect(faraday).to receive(:get).and_call_original + subject.total + subject.total + end + + it 'reloads the data' do + expect(faraday).to receive(:get).twice.and_call_original + subject.reload + subject.reload + end + end + + describe '#as_array' do + it 'return the correct amount' do + expect(subject.to_a.length).to be expected_number_of_items + end - it 'returns single instances' do - subject.to_a.each do |element| - expect(element).to be_a expected_singular_type - end - end + it 'returns single instances' do + subject.to_a.each do |element| + expect(element).to be_a expected_singular_type end end end diff --git a/spec/netbox_client_ruby/api/tenancy/tenants_spec.rb b/spec/netbox_client_ruby/api/tenancy/tenants_spec.rb index 3f0bf85..a4f51c5 100644 --- a/spec/netbox_client_ruby/api/tenancy/tenants_spec.rb +++ b/spec/netbox_client_ruby/api/tenancy/tenants_spec.rb @@ -1,57 +1,53 @@ require 'spec_helper' -module NetboxClientRuby - module Tenancy - RSpec.describe Tenants, faraday_stub: true do - let(:response) { File.read('spec/fixtures/tenancy/tenants.json') } - let(:request_url) { '/api/tenancy/tenants.json' } - let(:request_url_params) do - { limit: NetboxClientRuby.config.netbox.pagination.default_limit } - end +RSpec.describe NetboxClientRuby::Tenancy::Tenants, faraday_stub: true do + let(:response) { File.read('spec/fixtures/tenancy/tenants.json') } + let(:request_url) { '/api/tenancy/tenants.json' } + let(:request_url_params) do + { limit: NetboxClientRuby.config.netbox.pagination.default_limit } + end - context 'unpaged fetch' do - describe '#length' do - it 'shall be the expected length' do - expect(subject.length).to be 3 - end - end - - describe '#total' do - it 'shall be the expected total' do - expect(subject.total).to be 3 - end - end + context 'unpaged fetch' do + describe '#length' do + it 'shall be the expected length' do + expect(subject.length).to be 3 end + end - describe '#reload' do - it 'fetches the correct data' do - expect(faraday).to receive(:get).and_call_original - subject.reload - end - - it 'caches the data' do - expect(faraday).to receive(:get).and_call_original - subject.total - subject.total - end - - it 'reloads the data' do - expect(faraday).to receive(:get).twice.and_call_original - subject.reload - subject.reload - end + describe '#total' do + it 'shall be the expected total' do + expect(subject.total).to be 3 end + end + end + + describe '#reload' do + it 'fetches the correct data' do + expect(faraday).to receive(:get).and_call_original + subject.reload + end - describe '#as_array' do - it 'return the correct amount' do - expect(subject.to_a.length).to be 3 - end + it 'caches the data' do + expect(faraday).to receive(:get).and_call_original + subject.total + subject.total + end + + it 'reloads the data' do + expect(faraday).to receive(:get).twice.and_call_original + subject.reload + subject.reload + end + end + + describe '#as_array' do + it 'return the correct amount' do + expect(subject.to_a.length).to be 3 + end - it 'returns single instances' do - subject.to_a.each do |element| - expect(element).to be_a Tenant - end - end + it 'returns single instances' do + subject.to_a.each do |element| + expect(element).to be_a NetboxClientRuby::Tenancy::Tenant end end end diff --git a/spec/netbox_client_ruby/api/tenancy_spec.rb b/spec/netbox_client_ruby/api/tenancy_spec.rb index 080ba6d..1c6b5f8 100644 --- a/spec/netbox_client_ruby/api/tenancy_spec.rb +++ b/spec/netbox_client_ruby/api/tenancy_spec.rb @@ -1,32 +1,27 @@ require 'spec_helper' -module NetboxClientRuby - module Tenancy - RSpec.describe Tenancy do - { - tenant_groups: TenantGroups, - tenants: Tenants - }.each do |method, klass| - describe ".#{method}" do - subject { described_class.public_send(method) } +RSpec.describe NetboxClientRuby::Tenancy do + { + tenant_groups: NetboxClientRuby::Tenancy::TenantGroups, + tenants: NetboxClientRuby::Tenancy::Tenants + }.each do |method, klass| + describe ".#{method}" do + subject { described_class.public_send(method) } - context 'is of the correct type' do - it { is_expected.to be_a klass } - end - - context 'is a different instance each time' do - it do - is_expected - .to_not be described_class.public_send(method) - end - end + context 'is of the correct type' do + it { is_expected.to be_a klass } + end - context 'is an Entities object' do - it { is_expected.to respond_to(:get!) } - end + context 'is a different instance each time' do + it do + is_expected + .to_not be described_class.public_send(method) end end + + context 'is an Entities object' do + it { is_expected.to respond_to(:get!) } + end end end end - diff --git a/spec/netbox_client_ruby/api/virtualization_spec.rb b/spec/netbox_client_ruby/api/virtualization_spec.rb index e9bb9f5..16b8c74 100644 --- a/spec/netbox_client_ruby/api/virtualization_spec.rb +++ b/spec/netbox_client_ruby/api/virtualization_spec.rb @@ -1,62 +1,58 @@ require 'spec_helper' -module NetboxClientRuby - module Virtualization - RSpec.describe Virtualization do - { - cluster_groups: ClusterGroups, - cluster_types: ClusterTypes, - clusters: Clusters, - virtual_machines: VirtualMachines, - interfaces: Interfaces, - }.each do |method, klass| - describe ".#{method}" do - subject { described_class.public_send(method) } - - context 'is of the correct type' do - it { is_expected.to be_a klass } - end - - context 'is a different instance each time' do - it do - is_expected - .to_not be described_class.public_send(method) - end - end - - context 'is an Entities object' do - it { is_expected.to respond_to(:get!) } - end +RSpec.describe NetboxClientRuby::Virtualization do + { + cluster_groups: NetboxClientRuby::Virtualization::ClusterGroups, + cluster_types: NetboxClientRuby::Virtualization::ClusterTypes, + clusters: NetboxClientRuby::Virtualization::Clusters, + virtual_machines: NetboxClientRuby::Virtualization::VirtualMachines, + interfaces: NetboxClientRuby::Virtualization::Interfaces, + }.each do |method, klass| + describe ".#{method}" do + subject { described_class.public_send(method) } + + context 'is of the correct type' do + it { is_expected.to be_a klass } + end + + context 'is a different instance each time' do + it do + is_expected + .to_not be described_class.public_send(method) end end - { - cluster_group: ClusterGroup, - cluster_type: ClusterType, - cluster: Cluster, - virtual_machine: VirtualMachine, - interface: Interface, - }.each do |method, expected_class| - describe ".#{method}" do - let(:id) { 1 } - subject { described_class.public_send(method, id) } - - context 'is of the expected type' do - it { is_expected.to be_a expected_class } - end - - context 'it is a new instance each time' do - it do - is_expected - .to_not be described_class.public_send(method, id) - end - end - - context 'is an Entity object' do - it { is_expected.to respond_to(:get!) } - end + context 'is an Entities object' do + it { is_expected.to respond_to(:get!) } + end + end + end + + { + cluster_group: NetboxClientRuby::Virtualization::ClusterGroup, + cluster_type: NetboxClientRuby::Virtualization::ClusterType, + cluster: NetboxClientRuby::Virtualization::Cluster, + virtual_machine: NetboxClientRuby::Virtualization::VirtualMachine, + interface: NetboxClientRuby::Virtualization::Interface, + }.each do |method, expected_class| + describe ".#{method}" do + let(:id) { 1 } + subject { described_class.public_send(method, id) } + + context 'is of the expected type' do + it { is_expected.to be_a expected_class } + end + + context 'it is a new instance each time' do + it do + is_expected + .to_not be described_class.public_send(method, id) end end + + context 'is an Entity object' do + it { is_expected.to respond_to(:get!) } + end end end end