Skip to content

Commit

Permalink
add support for specifying domain root account to api spec helper
Browse files Browse the repository at this point in the history
test plan: n/a

Change-Id: I8e45bc88d9bcbea29b9ede3be0431487ee4e3cf8
Reviewed-on: https://gerrit.instructure.com/7428
Reviewed-by: Cody Cutrer <[email protected]>
Tested-by: Hudson <[email protected]>
  • Loading branch information
jtolio committed Dec 12, 2011
1 parent 43c5f0e commit 61c8670
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion app/middleware/load_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ def initialize(app)
end

def call(env)
domain_root_account = Account.default
domain_root_account = LoadAccount.default_domain_root_account
configure_for_root_account(domain_root_account)

env['canvas.domain_root_account'] = domain_root_account
@app.call(env)
end

def self.default_domain_root_account; Account.default; end

protected

def configure_for_root_account(domain_root_account)
Expand Down
8 changes: 5 additions & 3 deletions spec/apis/api_spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def []=(k,v)
# params generated by the Rails routing engine. body_params are params in a
# PUT/POST that are included in the body rather than the URI, and therefore
# don't affect routing.
def api_call(method, path, params, body_params = {}, headers = {})
raw_api_call(method, path, params, body_params, headers)
def api_call(method, path, params, body_params = {}, headers = {}, opts = {})
raw_api_call(method, path, params, body_params, headers, opts)
response.should be_success, response.body
case params[:format]
when 'json'
Expand All @@ -56,7 +56,7 @@ def api_call(method, path, params, body_params = {}, headers = {})
end

# like api_call, but don't assume success and a json response.
def raw_api_call(method, path, params, body_params = {}, headers = {})
def raw_api_call(method, path, params, body_params = {}, headers = {}, opts = {})
path = path.sub(%r{\Ahttps?://[^/]+}, '') # remove protocol+host
enable_forgery_protection do
params_from_with_nesting(method, path).should == params
Expand All @@ -67,6 +67,8 @@ def raw_api_call(method, path, params, body_params = {}, headers = {})
params[:access_token] = token.token
end

LoadAccount.stubs(:default_domain_root_account).returns(opts[:domain_root_account]) if opts.has_key?(:domain_root_account)

__send__(method, path, params.reject { |k,v| %w(controller action).include?(k.to_s) }.merge(body_params), headers)
end
end
Expand Down

0 comments on commit 61c8670

Please sign in to comment.