module CcApiStub::Users
Public Class Methods
fail_to_create()
click to toggle source
# File lib/cc_api_stub/users.rb, line 51 def fail_to_create CcApiStub::Helper.fail_request(:post, 500, {}, /users/) end
fail_to_find(options = {})
click to toggle source
# File lib/cc_api_stub/users.rb, line 42 def fail_to_find(options = {}) stub_get(object_endpoint(options[:id]), {}, response(404, {:code => 20003, :description => "The user could not be found"})) end
fail_to_replace_permissions(options = {})
click to toggle source
# File lib/cc_api_stub/users.rb, line 59 def fail_to_replace_permissions(options = {}) stub_put(object_endpoint(options[:id]), {}, response(500)) end
organization_fixture_hash(options={})
click to toggle source
# File lib/cc_api_stub/users.rb, line 67 def organization_fixture_hash(options={}) fixture = organizations_fixture.first fixture["entity"].delete("spaces") if options[:no_spaces] fixture["entity"].delete("managers") if options[:no_managers] MultiJson.load(fixture.to_json, :symbolize_keys => true) end
organizations_fixture()
click to toggle source
# File lib/cc_api_stub/users.rb, line 63 def organizations_fixture Helper.load_fixtures("fake_cc_user")["entity"]["organizations"] end
space(space_id)
click to toggle source
# File lib/cc_api_stub/users.rb, line 13 def space(space_id) {"metadata" => { "guid" => space_id }, "entity" => {}} end
succeed_to_create()
click to toggle source
# File lib/cc_api_stub/users.rb, line 46 def succeed_to_create response_body = Helper.load_fixtures("fake_cc_created_user") stub_post(collection_endpoint, {}, response(201, response_body)) end
succeed_to_load(options={})
click to toggle source
# File lib/cc_api_stub/users.rb, line 6 def succeed_to_load(options={}) response_body = Helper.load_fixtures(options[:fixture] || "fake_cc_user") response_body["metadata"]["guid"] = options[:id] || "user-id-1" if options[:no_organizations] response_body["entity"]["organizations"] = [] else def space(space_id) {"metadata" => { "guid" => space_id }, "entity" => {}} end organization = response_body["entity"]["organizations"].first organization["metadata"]["guid"] = options[:organization_id] || "organization-id-1" organization["entity"]["spaces"] = [] if options[:no_spaces] permissions = options[:permissions] || [:organization_manager] response_body["entity"]["managed_organizations"] << organization if permissions.include?(:organization_manager) response_body["entity"]["billing_managed_organizations"] << organization if permissions.include?(:organization_billing_manager) response_body["entity"]["audited_organizations"] << organization if permissions.include?(:organization_auditor) unless options[:no_spaces] space = space("space-id-1") response_body["entity"]["spaces"] << space if permissions.include?(:space_developer) response_body["entity"]["managed_spaces"] << space if permissions.include?(:space_manager) response_body["entity"]["audited_spaces"] << space if permissions.include?(:space_auditor) space2 = space("space-id-2") response_body["entity"]["spaces"] << space2 if permissions.include?(:space2_developer) response_body["entity"]["managed_spaces"] << space2 if permissions.include?(:space2_manager) response_body["entity"]["audited_spaces"] << space2 if permissions.include?(:space2_auditor) end end stub_get(%r{/v2/users/[^/]+\?inline-relations-depth=2$}, {}, response(200, response_body)) stub_get(%r{/v2/users/[^/]+/summary(\?inline-relations-depth=\d)?$}, {}, response(200, response_body)) end
succeed_to_replace_permissions(options = {})
click to toggle source
# File lib/cc_api_stub/users.rb, line 55 def succeed_to_replace_permissions(options = {}) stub_put(object_endpoint(options[:id]), {}, response(200, "")) end
Private Class Methods
collection_endpoint()
click to toggle source
# File lib/cc_api_stub/users.rb, line 76 def collection_endpoint %r{/v2/users$} end
object_endpoint(id = nil)
click to toggle source
# File lib/cc_api_stub/users.rb, line 80 def object_endpoint(id = nil) %r{/v2/users/#{id}[^/]+(/summary)?} end