Skip to content

Commit

Permalink
test: fix tests using badge service
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Sep 17, 2017
1 parent 2453c55 commit cb6cb8e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
7 changes: 6 additions & 1 deletion lib/pact_broker/badges/cached_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ def pact_verification_badge pact, label, initials, verification_status
CACHE[badge_key] ||= PactBroker::Badges::Service.pact_verification_badge(pact, label, initials, verification_status)
end

def clear_cache
CACHE.clear
end

private

def key pact, label, initials, verification_status
"#{pact.consumer.name}-#{pact.provider.name}-#{label}-#{initials}-#{verification_status}"
pact_name = pact ? "#{pact.consumer.name}-#{pact.provider.name}" : "nil"
"#{pact_name}-#{label}-#{initials}-#{verification_status}"
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions spec/lib/pact_broker/api/resources/badge_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'pact_broker/api/resources/badge'
require 'pact_broker/badges/service'
require 'pact_broker/badges/cached_service'

module PactBroker
module Api
Expand All @@ -11,7 +11,7 @@ module Resources
before do
allow(PactBroker::Pacts::Service).to receive(:find_latest_pact).and_return(pact)
allow(PactBroker::Verifications::Service).to receive(:find_latest_verification_for).and_return(verification)
allow(PactBroker::Badges::Service).to receive(:pact_verification_badge).and_return("badge")
allow(PactBroker::Badges::CachedService).to receive(:pact_verification_badge).and_return("badge")
allow(PactBroker::Verifications::Status).to receive(:new).and_return(verification_status)
end

Expand Down Expand Up @@ -68,7 +68,7 @@ module Resources
end

it "creates a badge" do
expect(PactBroker::Badges::Service).to receive(:pact_verification_badge).with(pact, nil, false, :verified)
expect(PactBroker::Badges::CachedService).to receive(:pact_verification_badge).with(pact, nil, false, :verified)
subject
end

Expand All @@ -84,7 +84,7 @@ module Resources
let(:params) { {label: 'consumer'} }

it "creates a badge with the specified label" do
expect(PactBroker::Badges::Service).to receive(:pact_verification_badge).with(anything, 'consumer', anything, anything)
expect(PactBroker::Badges::CachedService).to receive(:pact_verification_badge).with(anything, 'consumer', anything, anything)
subject
end
end
Expand All @@ -93,7 +93,7 @@ module Resources
let(:params) { {initials: 'true'} }

it "creates a badge with initials" do
expect(PactBroker::Badges::Service).to receive(:pact_verification_badge).with(anything, anything, true, anything)
expect(PactBroker::Badges::CachedService).to receive(:pact_verification_badge).with(anything, anything, true, anything)
subject
end
end
Expand Down
1 change: 0 additions & 1 deletion spec/lib/pact_broker/badges/cached_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module Badges

before do
allow(Service).to receive(:pact_verification_badge).and_return('badge')
stub_const('PactBroker::Badges::CachedService::CACHE', {})
end

subject { CachedService.pact_verification_badge pact, label, initials, verification_status }
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

config.before :each do
PactBroker.reset_configuration
require 'pact_broker/badges/cached_service'
PactBroker::Badges::CachedService.clear_cache
end

config.include Rack::Test::Methods
Expand Down

0 comments on commit cb6cb8e

Please sign in to comment.