Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions spec/purple/client_inheritance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class BaseClient < Purple::Client
class InheritedClient < BaseClient
end

class ChildClient < InheritedClient
end

class OverriddenClient < BaseClient
domain 'https://other.example.com'
authorization :custom_headers, 'Authorization' => 'Bearer different-token'
Expand Down Expand Up @@ -54,6 +57,17 @@ class OverriddenClient < BaseClient
expect(InheritanceSpec::InheritedClient.authorization).to eq(InheritanceSpec::BaseClient.authorization)
end

it 'inherits domain and authorization in child class' do
response = instance_double(Faraday::Response, status: 200, body: { ok: true }.to_json)
expect(connection).to receive(:get).with('https://example.com/status', {}).and_return(response)

InheritanceSpec::ChildClient.status

expect(headers).to include('Authorization' => 'Bearer token')
expect(InheritanceSpec::ChildClient.domain).to eq('https://example.com')
expect(InheritanceSpec::ChildClient.authorization).to eq(InheritanceSpec::BaseClient.authorization)
end

it 'allows overriding inherited domain and authorization' do
response = instance_double(Faraday::Response, status: 200, body: { ok: true }.to_json)
expect(connection).to receive(:get).with('https://other.example.com/status', {}).and_return(response)
Expand Down
Loading