Permalink
Browse files

exclude the fake in api gemspec. make fake service more subclass-able

  • Loading branch information...
jacobo committed Apr 4, 2012
1 parent ae99eea commit 03c886573acafb905bc56e0f198e6da3ce727060
Showing with 36 additions and 20 deletions.
  1. +1 −1 ey_services_api.gemspec
  2. +35 −19 fake/lib/ey_services_fake/mocking_bird_service.rb
View
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
s.rubyforge_project = "ey_services_api"
- s.files = `git ls-files`.split("\n")
+ s.files = (`git ls-files`.split("\n") - `git ls-files -- fake`.split("\n"))
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
@@ -2,33 +2,42 @@
module EyServicesFake
class MockingBirdService
- class Application < Sinatra::Base
+
+ def self.implement_the_app(app)
+ app.class_eval do
enable :raise_errors
disable :dump_errors
disable :show_exceptions
+ class << self
+ attr_accessor :parent
+ end
+ def parent
+ self.class.parent
+ end
+
delete '/api/1/some_provisioned_service' do
- if MockingBirdService.service_deprovisioning_handler
- instance_eval(&MockingBirdService.service_deprovisioning_handler)
+ if parent.service_deprovisioning_handler
+ instance_eval(&parent.service_deprovisioning_handler)
else
{}.to_json
end
end
delete '/api/1/some_service_account' do
- if MockingBirdService.service_account_cancel_handler
- instance_eval(&MockingBirdService.service_account_cancel_handler)
+ if parent.service_account_cancel_handler
+ instance_eval(&parent.service_account_cancel_handler)
else
{}.to_json
end
end
post '/api/1/service_accounts_callback' do
- if MockingBirdService.service_account_creation_handler
- instance_eval(&MockingBirdService.service_account_creation_handler)
+ if parent.service_account_creation_handler
+ instance_eval(&parent.service_account_creation_handler)
else
service_account = EY::ServicesAPI::ServiceAccountCreation.from_request(request.body.read)
- standard_response_params = MockingBirdService.service_account_creation_params
+ standard_response_params = parent.service_account_creation_params
EY::ServicesAPI::ServiceAccountResponse.new(
:provisioned_services_url => standard_response_params[:provisioned_services_url],
:url => standard_response_params[:url],
@@ -40,15 +49,15 @@ class Application < Sinatra::Base
end
post '/api/1/provisioned_services_callback' do
- if MockingBirdService.service_provisioning_handler
- instance_eval(&MockingBirdService.service_provisioning_handler)
+ if parent.service_provisioning_handler
+ instance_eval(&parent.service_provisioning_handler)
else
provisioned_service = EY::ServicesAPI::ProvisionedServiceCreation.from_request(request.body.read)
- standard_response_params = MockingBirdService.service_provisioned_params
+ standard_response_params = parent.service_provisioned_params
EY::ServicesAPI::ProvisionedServiceResponse.new(
:url => standard_response_params[:url],
:vars => standard_response_params[:vars],
- :configuration_required => false,
+ :configuration_required => standard_response_params[:configuration_required],
:configuration_url => standard_response_params[:configuration_url],
:message => EY::ServicesAPI::Message.new(:message_type => "status", :subject => "some provisioned service messages")
).to_hash.to_json
@@ -62,8 +71,8 @@ class Application < Sinatra::Base
get '/sso/some_provisioned_service' do
"SSO Hello Provisioned Service"
end
+ end
end
-
class << self
attr_accessor :service_account_creation_handler
attr_accessor :service_provisioning_handler
@@ -72,14 +81,21 @@ class << self
end
def reset!
- MockingBirdService.service_account_creation_handler = nil
- MockingBirdService.service_provisioning_handler = nil
- MockingBirdService.service_deprovisioning_handler = nil
- MockingBirdService.service_account_cancel_handler = nil
+ self.class.service_account_creation_handler = nil
+ self.class.service_provisioning_handler = nil
+ self.class.service_deprovisioning_handler = nil
+ self.class.service_account_cancel_handler = nil
+ end
+
+ def make_app
+ app = Class.new(Sinatra::Base)
+ self.class.implement_the_app(app)
+ app.parent = self.class
+ app
end
def app
- Application
+ @app ||= make_app
end
def setup(auth_id, auth_key, base_url = nil, backend = nil)
@@ -137,7 +153,7 @@ def self.service_provisioned_params
end
def register_service(registration_url)
- EY::ServicesAPI.connection.register_service(registration_url, MockingBirdService.registration_params)
+ EY::ServicesAPI.connection.register_service(registration_url, self.class.registration_params)
end
def send_message(message_url, message_type, message_subject, message_body)

0 comments on commit 03c8865

Please sign in to comment.