bearcat 1.3.52 → 1.3.53
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 +4 -4
- data/lib/bearcat/api_array.rb +13 -4
- data/lib/bearcat/spec_helpers.rb +1 -0
- data/lib/bearcat/version.rb +1 -1
- data/spec/bearcat/api_array_spec.rb +28 -2
- data/spec/bearcat/client/courses_spec.rb +2 -1
- data/spec/bearcat/client/discussions_spec.rb +12 -6
- data/spec/bearcat/client/quizzes_spec.rb +10 -5
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f0cf8e258d39569d2594318b7ab932d6330a6c431457209296ef15a2a0e2ce1c
|
|
4
|
+
data.tar.gz: 0271b96f8803739253365ab53c65246927a94f81a762f2ab935f1f5ecb47cb6e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f786b3e10b6c69e1de4d98221167099ea626abca6769394eff4d72eb53c99eb0fa4594070c08e259302e401dfca44b314c89246aead3e39afd1b038250e27e87
|
|
7
|
+
data.tar.gz: adb1e066f78c93c80e7ce0f326ddb9bfee40a93493fe5c184dd2f873111db53c44fe9bbd00d72ca2aef658177885e6b6acb959eee9f3fc7e9b5f57e5bd78c115
|
data/lib/bearcat/api_array.rb
CHANGED
|
@@ -10,7 +10,17 @@ module Bearcat
|
|
|
10
10
|
elsif key = array_key(response)
|
|
11
11
|
ApiArray.new(response, api_client, key)
|
|
12
12
|
else
|
|
13
|
-
response.body
|
|
13
|
+
make_indifferent(response.body)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.make_indifferent(thing)
|
|
18
|
+
if thing.is_a?(Array)
|
|
19
|
+
thing.map { |v| make_indifferent(v) }
|
|
20
|
+
elsif thing.is_a?(Hash)
|
|
21
|
+
thing.with_indifferent_access
|
|
22
|
+
else
|
|
23
|
+
thing
|
|
14
24
|
end
|
|
15
25
|
end
|
|
16
26
|
|
|
@@ -172,11 +182,10 @@ module Bearcat
|
|
|
172
182
|
|
|
173
183
|
def process_body(response)
|
|
174
184
|
if response.body.is_a?(Array)
|
|
175
|
-
response.body
|
|
185
|
+
ApiArray.make_indifferent(response.body)
|
|
176
186
|
elsif response.body.is_a?(Hash) && @array_key
|
|
177
|
-
response.body[@array_key]
|
|
187
|
+
ApiArray.make_indifferent(response.body[@array_key])
|
|
178
188
|
end
|
|
179
189
|
end
|
|
180
|
-
|
|
181
190
|
end
|
|
182
191
|
end
|
data/lib/bearcat/spec_helpers.rb
CHANGED
|
@@ -5,6 +5,7 @@ require 'bearcat'
|
|
|
5
5
|
# - `require 'bearcat/spec_helpers'`
|
|
6
6
|
# And
|
|
7
7
|
# - `config.include Bearcat::SpecHelpers`
|
|
8
|
+
# This helper requires `gem 'method_source'` in your test group
|
|
8
9
|
module Bearcat::SpecHelpers
|
|
9
10
|
SOURCE_REGEX = /(?<method>get|post|delete|put)\((?<quote>\\?('|"))(?<url>.*)\k<quote>/
|
|
10
11
|
|
data/lib/bearcat/version.rb
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
require 'helper'
|
|
2
2
|
|
|
3
3
|
describe Bearcat::ApiArray do
|
|
4
|
+
let(:api_client) { double }
|
|
5
|
+
let(:response_body) { @response_body || [] }
|
|
6
|
+
let(:original_response) { double(body: response_body, status: 200, headers: {}, env: {}) }
|
|
7
|
+
|
|
4
8
|
describe 'get_page' do
|
|
5
|
-
let(:api_client) { double }
|
|
6
|
-
let(:original_response) { double(body: [], status: 200, headers: {}, env: {}) }
|
|
7
9
|
let(:api_array) { described_class.process_response(original_response, api_client) }
|
|
8
10
|
let(:connection) { double }
|
|
9
11
|
let(:request) { double }
|
|
@@ -52,4 +54,28 @@ describe Bearcat::ApiArray do
|
|
|
52
54
|
api_array.send(:get_page, 'https://fake.com?', 'per_page' => 10)
|
|
53
55
|
end
|
|
54
56
|
end
|
|
57
|
+
|
|
58
|
+
context 'makes returned values indifferent' do
|
|
59
|
+
it 'makes a Hash response indifferent' do
|
|
60
|
+
@response_body = { something: 1 }
|
|
61
|
+
result = described_class.process_response(original_response, api_client)
|
|
62
|
+
expect(result[:something]).to eq 1
|
|
63
|
+
expect(result['something']).to eq 1
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it 'makes an Array response indifferent' do
|
|
67
|
+
@response_body = [{ something: 1 }]
|
|
68
|
+
result = described_class.process_response(original_response, api_client)
|
|
69
|
+
expect(result[0][:something]).to eq 1
|
|
70
|
+
expect(result[0]['something']).to eq 1
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it 'makes a single-key Hash response indifferent' do
|
|
74
|
+
@response_body = { 'something' => [ { foo: 1 } ] }
|
|
75
|
+
allow(described_class).to receive(:array_key).and_return('something')
|
|
76
|
+
result = described_class.process_response(original_response, api_client)
|
|
77
|
+
expect(result[0][:foo]).to eq 1
|
|
78
|
+
expect(result[0]['foo']).to eq 1
|
|
79
|
+
end
|
|
80
|
+
end
|
|
55
81
|
end
|
|
@@ -91,8 +91,9 @@ describe Bearcat::Client::Sections do
|
|
|
91
91
|
it 'sets extensions on a quiz' do
|
|
92
92
|
stub_post(@client, "/api/v1/courses/1/quiz_extensions").to_return(json_response("quizzes/quiz_extension.json"))
|
|
93
93
|
quiz_extension = @client.course_quiz_extensions('1', {quiz_extensions: [{user_id: 1}, {extra_time: 30}]})
|
|
94
|
-
quiz_extension.
|
|
94
|
+
quiz_extension.should be_a Hash
|
|
95
95
|
quiz_extension['quiz_extensions'].first['extra_time'].should eq(30)
|
|
96
|
+
quiz_extension[:quiz_extensions].first[:extra_time].should eq(30)
|
|
96
97
|
end
|
|
97
98
|
|
|
98
99
|
it 'gets learning outcome results' do
|
|
@@ -25,8 +25,9 @@ describe Bearcat::Client::Discussions do
|
|
|
25
25
|
discussions = @client.course_discussions('1')
|
|
26
26
|
discussions.class.should eq(Bearcat::ApiArray)
|
|
27
27
|
discussions.count.should == 1
|
|
28
|
-
discussions[0].
|
|
28
|
+
discussions[0].should be_a Hash
|
|
29
29
|
discussions[0]['id'].should == 1
|
|
30
|
+
discussions[0][:id].should == 1
|
|
30
31
|
end
|
|
31
32
|
|
|
32
33
|
it 'returns group discussion topics' do
|
|
@@ -34,8 +35,9 @@ describe Bearcat::Client::Discussions do
|
|
|
34
35
|
discussions = @client.group_discussions('1')
|
|
35
36
|
discussions.class.should eq(Bearcat::ApiArray)
|
|
36
37
|
discussions.count.should == 1
|
|
37
|
-
discussions[0].
|
|
38
|
+
discussions[0].should be_a Hash
|
|
38
39
|
discussions[0]['id'].should == 1
|
|
40
|
+
discussions[0][:id].should == 1
|
|
39
41
|
end
|
|
40
42
|
|
|
41
43
|
it 'returns course discussion entries' do
|
|
@@ -43,8 +45,9 @@ describe Bearcat::Client::Discussions do
|
|
|
43
45
|
discussions = @client.course_discussion_entries('1', '1')
|
|
44
46
|
discussions.class.should eq(Bearcat::ApiArray)
|
|
45
47
|
discussions.count.should == 1
|
|
46
|
-
discussions[0].
|
|
48
|
+
discussions[0].should be_a Hash
|
|
47
49
|
discussions[0]['id'].should == 1
|
|
50
|
+
discussions[0][:id].should == 1
|
|
48
51
|
end
|
|
49
52
|
|
|
50
53
|
it 'returns group discussion entries' do
|
|
@@ -52,8 +55,9 @@ describe Bearcat::Client::Discussions do
|
|
|
52
55
|
discussions = @client.group_discussion_entries('1', '1')
|
|
53
56
|
discussions.class.should eq(Bearcat::ApiArray)
|
|
54
57
|
discussions.count.should == 1
|
|
55
|
-
discussions[0].
|
|
58
|
+
discussions[0].should be_a Hash
|
|
56
59
|
discussions[0]['id'].should == 1
|
|
60
|
+
discussions[0][:id].should == 1
|
|
57
61
|
end
|
|
58
62
|
|
|
59
63
|
it 'returns course discussion entry replies' do
|
|
@@ -61,8 +65,9 @@ describe Bearcat::Client::Discussions do
|
|
|
61
65
|
discussions = @client.course_discussion_entry_replies('1', '1', '1')
|
|
62
66
|
discussions.class.should eq(Bearcat::ApiArray)
|
|
63
67
|
discussions.count.should == 1
|
|
64
|
-
discussions[0].
|
|
68
|
+
discussions[0].should be_a Hash
|
|
65
69
|
discussions[0]['id'].should == 3
|
|
70
|
+
discussions[0][:id].should == 3
|
|
66
71
|
end
|
|
67
72
|
|
|
68
73
|
it 'returns group discussion entry replies' do
|
|
@@ -70,8 +75,9 @@ describe Bearcat::Client::Discussions do
|
|
|
70
75
|
discussions = @client.group_discussion_entry_replies('1', '1', '1')
|
|
71
76
|
discussions.class.should eq(Bearcat::ApiArray)
|
|
72
77
|
discussions.count.should == 1
|
|
73
|
-
discussions[0].
|
|
78
|
+
discussions[0].should be_a Hash
|
|
74
79
|
discussions[0]['id'].should == 3
|
|
80
|
+
discussions[0][:id].should == 3
|
|
75
81
|
end
|
|
76
82
|
|
|
77
83
|
it 'returns a single group discussion' do
|
|
@@ -8,8 +8,9 @@ describe Bearcat::Client::Quizzes do
|
|
|
8
8
|
it "updates a single quiz" do
|
|
9
9
|
stub_put(@client, "/api/v1/courses/1/quizzes/38").to_return(json_response("quizzes/course_quiz.json"))
|
|
10
10
|
course_quiz = @client.edit_quiz('1', '38')
|
|
11
|
-
course_quiz.
|
|
11
|
+
course_quiz.should be_a Hash
|
|
12
12
|
course_quiz['id'].should == 38
|
|
13
|
+
course_quiz[:id].should == 38
|
|
13
14
|
end
|
|
14
15
|
|
|
15
16
|
it "returns a courses quizzes" do
|
|
@@ -24,22 +25,25 @@ describe Bearcat::Client::Quizzes do
|
|
|
24
25
|
it "returns a single quiz" do
|
|
25
26
|
stub_get(@client, "/api/v1/courses/1/quizzes/38").to_return(json_response("quizzes/course_quiz.json"))
|
|
26
27
|
course_quiz = @client.quiz('1', '38')
|
|
27
|
-
course_quiz.
|
|
28
|
+
course_quiz.should be_a Hash
|
|
28
29
|
course_quiz['id'].should == 38
|
|
30
|
+
course_quiz[:id].should == 38
|
|
29
31
|
end
|
|
30
32
|
|
|
31
33
|
it 'sets extensions on a quiz' do
|
|
32
34
|
stub_post(@client, "/api/v1/courses/1/quizzes/1/extensions").to_return(json_response("quizzes/quiz_extension.json"))
|
|
33
35
|
quiz_extension = @client.quiz_extensions('1', '1', {quiz_extensions: [{user_id: 1}, {extra_time: 30}]})
|
|
34
|
-
quiz_extension.
|
|
36
|
+
quiz_extension.should be_a Hash
|
|
35
37
|
quiz_extension['quiz_extensions'].first['extra_time'].should eq(30)
|
|
38
|
+
quiz_extension[:quiz_extensions].first[:extra_time].should eq(30)
|
|
36
39
|
end
|
|
37
40
|
|
|
38
41
|
it 'returns a quiz assignment override' do
|
|
39
42
|
stub_get(@client, "/api/v1/courses/1/quizzes/assignment_overrides?quiz_assignment_overrides%5B%5D%5Bquiz_ids%5D=13").to_return(json_response("quizzes/quiz_assignment_override.json"))
|
|
40
43
|
quiz_overrides = @client.quiz_assignment_overrides('1',{:quiz_assignment_overrides => [{ :quiz_ids => 13 }] })
|
|
41
|
-
quiz_overrides.
|
|
44
|
+
quiz_overrides.should be_a Hash
|
|
42
45
|
quiz_overrides['quiz_assignment_overrides'].first['quiz_id'].should eq(1014)
|
|
46
|
+
quiz_overrides[:quiz_assignment_overrides].first[:quiz_id].should eq(1014)
|
|
43
47
|
end
|
|
44
48
|
|
|
45
49
|
|
|
@@ -56,8 +60,9 @@ describe Bearcat::Client::Quizzes do
|
|
|
56
60
|
course_quiz_questions = @client.quiz_questions('1', '1')
|
|
57
61
|
course_quiz_questions.class.should eq(Bearcat::ApiArray)
|
|
58
62
|
course_quiz_questions.count.should == 1
|
|
59
|
-
course_quiz_questions[0].
|
|
63
|
+
course_quiz_questions[0].should be_a Hash
|
|
60
64
|
course_quiz_questions[0]['id'].should == 1
|
|
65
|
+
course_quiz_questions[0][:id].should == 1
|
|
61
66
|
end
|
|
62
67
|
|
|
63
68
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bearcat
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.3.
|
|
4
|
+
version: 1.3.53
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nathan Mills, Jake Sorce
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-
|
|
11
|
+
date: 2020-02-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|