Module: JSONRequests

Included in:
RSpec::Rails::RequestExampleGroup
Defined in:
lib/xing/spec_helpers/json_requests.rb

Instance Method Summary collapse

Instance Method Details

#authenticated_json_delete(user, url, arg2 = nil) ⇒ Object



34
35
36
37
# File 'lib/xing/spec_helpers/json_requests.rb', line 34

def authenticated_json_delete(user, url, arg2 = nil)
  auth_header = user.create_new_auth_token
  delete rootify(url), arg2, auth_header.merge({ 'HTTP_ACCEPT' => 'application/json' })
end

#authenticated_json_get(user, url, arg2 = nil) ⇒ Object



19
20
21
22
# File 'lib/xing/spec_helpers/json_requests.rb', line 19

def authenticated_json_get(user, url, arg2 = nil)
  auth_header = user.create_new_auth_token
  get rootify(url), arg2, auth_header.merge({ 'HTTP_ACCEPT' => 'application/json' })
end

#authenticated_json_post(user, url, arg2 = nil) ⇒ Object



24
25
26
27
# File 'lib/xing/spec_helpers/json_requests.rb', line 24

def authenticated_json_post(user, url, arg2 = nil)
  auth_header = user.create_new_auth_token
  post rootify(url), arg2, auth_header.merge({ 'HTTP_ACCEPT' => 'application/json' })
end

#authenticated_json_put(user, url, arg2 = nil) ⇒ Object



29
30
31
32
# File 'lib/xing/spec_helpers/json_requests.rb', line 29

def authenticated_json_put(user, url, arg2 = nil)
  auth_header = user.create_new_auth_token
  put rootify(url), arg2, auth_header.merge({ 'HTTP_ACCEPT' => 'application/json' })
end

#json_delete(url, arg2 = nil) ⇒ Object



15
16
17
# File 'lib/xing/spec_helpers/json_requests.rb', line 15

def json_delete(url, arg2 = nil)
  delete rootify(url), arg2, { 'HTTP_ACCEPT' => 'application/json' }
end

#json_get(url, arg2 = nil) ⇒ Object



3
4
5
# File 'lib/xing/spec_helpers/json_requests.rb', line 3

def json_get(url, arg2 = nil)
  get rootify(url), arg2, { 'HTTP_ACCEPT' => 'application/json' }
end

#json_post(url, arg2 = nil) ⇒ Object



7
8
9
# File 'lib/xing/spec_helpers/json_requests.rb', line 7

def json_post(url, arg2 = nil)
  post rootify(url), arg2, { 'HTTP_ACCEPT' => 'application/json' }
end

#json_put(url, arg2 = nil) ⇒ Object



11
12
13
# File 'lib/xing/spec_helpers/json_requests.rb', line 11

def json_put(url, arg2 = nil)
  put rootify(url), arg2, { 'HTTP_ACCEPT' => 'application/json' }
end

#rootify(url) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/xing/spec_helpers/json_requests.rb', line 39

def rootify(url)
  if url[0] == '/'
    url
  else
    "/#{url}"
  end
end