openstax_api 6.1.0 → 6.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c6a937a25d58a26e40c74de96835de8ad1f4d2c7
4
- data.tar.gz: c3c2beeb581971dbe6226b47b6fd53e72ebfd902
3
+ metadata.gz: 7dc286ebde4e9b6e9bf1a3f7efc08514e4f78610
4
+ data.tar.gz: a6be75bd1d025aabad6325fd0201778268e578fb
5
5
  SHA512:
6
- metadata.gz: dca5d4b8cd060781da95aec175e1a7cb084d223261b1cabe6a9db47012451f495e606ba8a74921ef6d9e1c9c0640c9e27ece001564ee99bf95d4907afa5451de
7
- data.tar.gz: c829a7fbef75369bbb3b1db6314539f1c13d303b98d6afdabd2f6476ebdcc0a50992986bb7d88c4844f132ea3fcc60bc61b00c9e65666be40aad284b96466e94
6
+ metadata.gz: 35474cafc2e08ab2429623f923bf0c8df44261a597be93e205221d1630907f3d585da87ff198aa32766b9448636d50c67a12ba8cb127cac659b069aa2d479d83
7
+ data.tar.gz: 12ff60007d7e23858a7b9c8447b59a997adf4bbc95e60cdd9392181a08d27548f3be4324e69237ded06ad41b4efad54ba6e73cf97d1e22e6bff5d1f4c5065368
@@ -12,8 +12,14 @@ module OpenStax
12
12
 
13
13
  respond_to :json
14
14
 
15
+ # after_filters are in place to make sure certain things are set how we
16
+ # want even if something else goes on during the request. These filters
17
+ # are also paired with before_filters in case an exception prevents
18
+ # normal action completion.
19
+
15
20
  # Always force JSON requests and send the Date header in the response
16
21
  before_filter :force_json_content_type
22
+ before_filter :set_date_header
17
23
  after_filter :set_date_header
18
24
 
19
25
  # Doorkeeper is used only if a token is present
@@ -24,6 +30,7 @@ module OpenStax
24
30
  skip_before_filter :verify_authenticity_token, unless: :session_user?
25
31
  skip_before_filter :verify_authenticity_token, only: :options
26
32
  before_filter :set_cors_preflight_headers, only: :options
33
+ before_filter :set_cors_headers
27
34
  after_filter :set_cors_headers
28
35
 
29
36
  # Keep old current_user method so we can use it
@@ -1,5 +1,5 @@
1
1
  module OpenStax
2
2
  module Api
3
- VERSION = "6.1.0"
3
+ VERSION = "6.1.1"
4
4
  end
5
5
  end
@@ -22,7 +22,7 @@ module OpenStax
22
22
  controller.doorkeeper_token = nil
23
23
  controller.present_user = nil
24
24
  end
25
-
25
+
26
26
  it 'has no human_user and no application' do
27
27
  expect(controller.send :session_user?).to eq false
28
28
  expect(controller.current_application).to be_nil
@@ -36,7 +36,7 @@ module OpenStax
36
36
  controller.doorkeeper_token = nil
37
37
  controller.present_user = user
38
38
  end
39
-
39
+
40
40
  it 'has a human_user but no application' do
41
41
  expect(controller.send :session_user?).to eq true
42
42
  expect(controller.current_application).to be_nil
@@ -50,7 +50,7 @@ module OpenStax
50
50
  controller.doorkeeper_token = doorkeeper_token
51
51
  controller.present_user = nil
52
52
  end
53
-
53
+
54
54
  it 'has a human_user from token and an application' do
55
55
  allow(doorkeeper_token).to receive(:application).and_return(application)
56
56
  allow(doorkeeper_token).to receive(:resource_owner_id).and_return(user.id)
@@ -67,7 +67,7 @@ module OpenStax
67
67
  controller.doorkeeper_token = doorkeeper_token
68
68
  controller.present_user = nil
69
69
  end
70
-
70
+
71
71
  it 'has an application but no human_user' do
72
72
  allow(doorkeeper_token).to receive(:application).and_return(application)
73
73
  allow(doorkeeper_token).to receive(:resource_owner_id).and_return(nil)
@@ -144,11 +144,21 @@ module OpenStax
144
144
  end
145
145
  after(:each) { OpenStax::Api.configuration.validate_cors_origin = nil }
146
146
 
147
- it 'when configured proc is true, it sets the origin to whatever was reqeusted' do
148
- @valid_origin = 'http://good-host'
149
- @request.headers['HTTP_ORIGIN'] = @valid_origin
150
- get 'dummy'
151
- expect(response.headers['Access-Control-Allow-Origin']).to eq @valid_origin
147
+ context 'when configured proc is true' do
148
+ before(:each) do
149
+ @valid_origin = 'http://good-host'
150
+ @request.headers['HTTP_ORIGIN'] = @valid_origin
151
+ end
152
+
153
+ it 'sets the origin to whatever was reqeusted' do
154
+ get 'dummy'
155
+ expect(response.headers['Access-Control-Allow-Origin']).to eq @valid_origin
156
+ end
157
+
158
+ it 'sets the origin to whatever was requested even if there was an exception raised' do
159
+ get 'explode'
160
+ expect(response.headers['Access-Control-Allow-Origin']).to eq @valid_origin
161
+ end
152
162
  end
153
163
 
154
164
  it 'clears the headers if the configured proc is falsy' do
@@ -158,6 +168,7 @@ module OpenStax
158
168
  expect(response.headers['Access-Control-Allow-Origin']).to eq ''
159
169
  end
160
170
 
171
+
161
172
  end
162
173
 
163
174
  end
@@ -1,12 +1,22 @@
1
1
  module Api
2
2
  module V1
3
3
 
4
+ class DummyControllerError < StandardError; end
5
+
4
6
  class DummyController < OpenStax::Api::V1::ApiController
5
7
 
8
+ rescue_from DummyControllerError do |e|
9
+ render nothing: true, status: 500
10
+ end
11
+
6
12
  def dummy
7
13
  head(:ok)
8
14
  end
9
15
 
16
+ def explode
17
+ raise DummyControllerError, "kaboom"
18
+ end
19
+
10
20
  end
11
21
 
12
22
  end
@@ -1,5 +1,6 @@
1
1
  Rails.application.routes.draw do
2
2
  api :v1, :default => true do
3
3
  get 'dummy', controller: 'dummy'
4
+ get 'explode', controller: 'dummy'
4
5
  end
5
6
  end
Binary file