Skip to content

Commit d883b2f

Browse files
committed
BRD-20938 fix Rubocop exceptions
1 parent 7ed56cb commit d883b2f

25 files changed

Lines changed: 907 additions & 617 deletions

lib/scorm_engine/faraday/request.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def request(method, path, options, body = nil)
5252
# Retry the original request and return the result
5353
retry_response = make_request(method, path, options, body, api_version)
5454
ScormEngine::Response.new(raw_response: retry_response)
55-
rescue StandardError => e
55+
rescue StandardError
5656
# If tenant creation or retry fails, return the original response
5757
wrapped_response
5858
end

lib/scorm_engine/models/course.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def self.new_from_api(options = {})
5858
this.version = options["version"]
5959
this.title = get_title_from_api(options)
6060
this.registration_count = options["registrationCount"]
61-
this.updated = Time.parse(options["updated"]) if options.key?("updated")
61+
this.updated = Time.zone.parse(options["updated"]) if options.key?("updated")
6262
this.description = options.fetch("metadata", {})["description"]
6363
this.scaled_passing_score = get_scaled_passing_score_from_api(options)
6464
this.course_learning_standard = options["courseLearningStandard"]&.upcase

lib/scorm_engine/models/dispatch.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def self.new_from_api(options = {})
9292
def self.get_expiration_date(options = {})
9393
expiration_date = options["expirationDate"]
9494
return if expiration_date.nil? || expiration_date == "none"
95-
Time.parse(expiration_date)
95+
Time.zone.parse(expiration_date)
9696
end
9797
end
9898
end

lib/scorm_engine/models/dispatch_registration_count.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def self.get_last_reset_time(options = {})
4242
time = options["lastResetTime"]
4343
return if time.nil? || time == "none"
4444

45-
Time.parse(time)
45+
Time.zone.parse(time)
4646
end
4747
end
4848
end

lib/scorm_engine/models/registration.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ def self.new_from_api(options = {})
8989
this.options = options.dup
9090
this.id = options["id"]
9191
this.instance = options["instance"]
92-
this.updated = Time.parse(options["updated"]) if options.key?("updated")
92+
this.updated = Time.zone.parse(options["updated"]) if options.key?("updated")
9393
this.registration_completion = options["registrationCompletion"]&.upcase
9494
this.registration_success = options["registrationSuccess"]&.upcase
9595
this.total_seconds_tracked = options["totalSecondsTracked"]&.to_i
96-
this.first_access_date = Time.parse(options["firstAccessDate"]) if options.key?("firstAccessDate")
97-
this.last_access_date = Time.parse(options["lastAccessDate"]) if options.key?("lastAccessDate")
98-
this.created_date = Time.parse(options["createdDate"]) if options.key?("createdDate")
99-
this.updated = Time.parse(options["updated"]) if options.key?("updated")
96+
this.first_access_date = Time.zone.parse(options["firstAccessDate"]) if options.key?("firstAccessDate")
97+
this.last_access_date = Time.zone.parse(options["lastAccessDate"]) if options.key?("lastAccessDate")
98+
this.created_date = Time.zone.parse(options["createdDate"]) if options.key?("createdDate")
99+
this.updated = Time.zone.parse(options["updated"]) if options.key?("updated")
100100
this.registration_completion_amount = options["registrationCompletionAmount"].to_f # Sometimes it returns "NaN"
101101

102102
this.score = get_score_from_api(options)
@@ -181,7 +181,7 @@ def self.get_completed_at_from_api(options = {})
181181
completed_date = options["completedDate"]
182182
completed_date ||= options.fetch("score", {})["completedDate"]
183183
return if completed_date.nil?
184-
Time.parse(completed_date)
184+
Time.zone.parse(completed_date)
185185
end
186186
end
187187
# rubocop:enable Metrics/AbcSize

lib/scorm_engine/models/registration_launch_history.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ def self.new_from_api(options = {})
7676
# @return [Time]
7777
#
7878
def self.parse_time(string)
79-
return nil if string.nil? || string.empty?
79+
return nil if string.blank?
8080
Time.strptime("#{string} UTC", "%m/%d/%Y %H:%M:%S %p %Z")
8181
rescue StandardError
82-
Time.parse(string)
82+
Time.zone.parse(string)
8383
end
8484

8585
#

lib/scorm_engine/models/registration_runtime_interaction.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ def self.get_learner_response_from_api(options)
8888

8989
def self.get_timestamp_from_api(options)
9090
timestamp = options["timestampUtc"]
91-
return if timestamp.nil? || timestamp.empty?
92-
Time.parse(timestamp)
91+
return if string.blank?
92+
Time.zone.parse(timestamp)
9393
end
9494
end
9595
end

lib/scorm_engine/response.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@ module ScormEngine
22
class Response
33
attr_reader :raw_response, :result
44

5-
delegate :success?, :status, to: :raw_response
5+
delegate :success?, :status, :body, to: :raw_response
66

77
def initialize(raw_response:, result: nil)
88
@raw_response = raw_response
99
@result = result
1010
end
1111

12-
def body
13-
raw_response.body
14-
end
15-
1612
def results
1713
result.is_a?(Enumerator) ? result : Array(result)
1814
end

spec/scorm_engine/api/endpoints/about_spec.rb

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,60 @@
11
RSpec.describe ScormEngine::Api::Endpoints::About do
22
describe "#get_about" do
3-
let(:subject) { scorm_engine_client.get_about }
3+
client(:client) { scorm_engine_client.get_about }
44

55
it "is successful" do
6-
expect(subject.success?).to eq true
6+
expect(client.success?).to eq true
77
end
88

99
it "knows the version" do
10-
expect(subject.result.version).to eq "20.1.12.336"
10+
expect(client.result.version).to eq "20.1.12.336"
1111
end
1212

1313
it "knows the platform" do
14-
expect(subject.result.platform).to eq "Java"
14+
expect(client.result.platform).to eq "Java"
1515
end
1616
end
1717

1818
describe "#get_about_user_count" do
19-
let(:subject) { scorm_engine_client.get_about_user_count }
19+
let(:client) { scorm_engine_client.get_about_user_count }
2020

2121
it "is successful" do
22-
expect(subject.success?).to eq true
22+
expect(client.success?).to eq true
2323
end
2424

2525
it "tracks combined counts" do
2626
aggregate_failures do
27-
expect(subject.result.total).to be >= 1
28-
expect(subject.result.dispatched).to be >= 0
29-
expect(subject.result.non_dispatched).to be >= 0
27+
expect(client.result.total).to be >= 1
28+
expect(client.result.dispatched).to be >= 0
29+
expect(client.result.non_dispatched).to be >= 0
3030
end
3131
end
3232

33+
# rubocop:disable RSpec/ExampleLength
3334
it "tracks per tenantcounts" do
3435
aggregate_failures do
35-
expect(subject.result.by_tenant).to be_a Hash
36-
tenant = subject.result.by_tenant[scorm_engine_client.tenant.downcase]
36+
expect(client.result.by_tenant).to be_a Hash
37+
tenant = client.result.by_tenant[scorm_engine_client.tenant.downcase]
3738
expect(tenant.total).to be >= 0
3839
expect(tenant.dispatched).to be >= 0
3940
expect(tenant.non_dispatched).to be >= 0
4041
end
4142
end
43+
# rubocop:enable RSpec/ExampleLength
4244

4345
it "accepts :before option" do
44-
subject = scorm_engine_client.get_about_user_count(before: Time.parse("1901-01-1 00:00:00 UTC"))
46+
client = scorm_engine_client.get_about_user_count(before: Time.parse("1901-01-1 00:00:00 UTC"))
4547
aggregate_failures do
46-
expect(subject.success?).to eq true
47-
expect(subject.result.total).to eq 0
48+
expect(client.success?).to eq true
49+
expect(client.result.total).to eq 0
4850
end
4951
end
5052

5153
it "accepts :since option" do
52-
subject = scorm_engine_client.get_about_user_count(since: Time.parse("2031-01-1 00:00:00 UTC"))
54+
client = scorm_engine_client.get_about_user_count(since: Time.parse("2031-01-1 00:00:00 UTC"))
5355
aggregate_failures do
54-
expect(subject.success?).to eq true
55-
expect(subject.result.total).to eq 0
56+
expect(client.success?).to eq true
57+
expect(client.result.total).to eq 0
5658
end
5759
end
5860
end
Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
1+
# rubocop:disable RSpec/ExampleLength
12
RSpec.describe ScormEngine::Api::Endpoints::Configuration do
23
describe "#get_app_configuration" do
3-
let(:subject) { scorm_engine_client.get_app_configuration }
4+
client(:client) { scorm_engine_client.get_app_configuration }
45

56
it "is successful" do
6-
expect(subject.success?).to eq true
7+
expect(client.success?).to eq true
78
end
89

910
it "returns settings and values" do
10-
expect(subject.result.UserCountReportLookBackDays).to be_truthy
11-
expect(subject.result["UserCountReportDaysBetweenReports"]).to be_truthy
11+
aggregate_failures do
12+
expect(client.result.UserCountReportLookBackDays).to be_truthy
13+
expect(client.result["UserCountReportDaysBetweenReports"]).to be_truthy
14+
end
1215
end
1316

1417
describe "includeMetadata" do
15-
let(:subject) { scorm_engine_client.get_app_configuration(includeMetadata: true) }
18+
let(:client) { scorm_engine_client.get_app_configuration(includeMetadata: true) }
1619

1720
it "is successful" do
18-
expect(subject.success?).to eq true
21+
expect(client.success?).to eq true
1922
end
2023

2124
it "returns metadata in raw_response when included in options" do
22-
expect(subject.raw_response.body["settingItems"].first["metadata"]).to_not be_nil
25+
expect(client.raw_response.body["settingItems"].first["metadata"]).not_to be_nil
2326
end
2427
end
2528
end
2629

2730
describe "#post_app_configuration" do
28-
let(:subject) { scorm_engine_client }
31+
let(:client) { scorm_engine_client }
2932
let(:response) {
30-
subject.post_app_configuration(
33+
client.post_app_configuration(
3134
settings: { "UserCountReportLookBackDays" => "90",
3235
"UserCountReportDaysBetweenReports" => 20 }
3336
)
@@ -37,46 +40,60 @@
3740
expect(response.success?).to eq true
3841
end
3942

40-
it "persists the settings" do
43+
it "persists the settings, default params" do
44+
response # trigger the api
45+
configuration = client.get_app_configuration.result
46+
aggregate_failures do
47+
expect(configuration["UserCountReportLookBackDays"]).to eq "90"
48+
expect(configuration["UserCountReportDaysBetweenReports"]).to eq "20"
49+
end
50+
end
51+
52+
it "persists the settings, modified params" do
4153
response # trigger the api
42-
configuration = subject.get_app_configuration.result
43-
expect(configuration["UserCountReportLookBackDays"]).to eq "90"
44-
expect(configuration["UserCountReportDaysBetweenReports"]).to eq "20"
4554

46-
subject.post_app_configuration(
55+
client.post_app_configuration(
4756
settings: { "UserCountReportLookBackDays" => "365",
4857
"UserCountReportDaysBetweenReports" => 30 }
4958
)
5059

5160
sleep 3 # there seems to be a delay between posting new values and when they're updated frd
5261

53-
configuration = subject.get_app_configuration.result
54-
expect(configuration["UserCountReportLookBackDays"]).to eq "365"
55-
expect(configuration["UserCountReportDaysBetweenReports"]).to eq "30"
62+
configuration = client.get_app_configuration.result
63+
aggregate_failures do
64+
expect(configuration["UserCountReportLookBackDays"]).to eq "365"
65+
expect(configuration["UserCountReportDaysBetweenReports"]).to eq "30"
66+
end
5667
end
5768

5869
it "fails when settings are invalid" do
59-
response = subject.post_app_configuration(settings: { "NonExistentSettingTotesBogus" => "YES" })
60-
expect(response.success?).to eq false
61-
expect(response.status).to eq 400
62-
expect(response.message).to match(/NonExistentSettingTotesBogus is not a valid setting ID/)
70+
response = client.post_app_configuration(settings: { "NonExistentSettingTotesBogus" => "YES" })
71+
aggregate_failures do
72+
expect(response.success?).to eq false
73+
expect(response.status).to eq 400
74+
expect(response.message).to match(/NonExistentSettingTotesBogus is not a valid setting ID/)
75+
end
6376
end
6477
end
6578

6679
describe "#delete_app_configuration" do
67-
let(:subject) { scorm_engine_client }
80+
let(:client) { scorm_engine_client }
6881
let(:response) {
69-
subject.delete_app_configuration(setting_id: "UserCountReportLookBackDays")
82+
client.delete_app_configuration(setting_id: "UserCountReportLookBackDays")
7083
}
7184

7285
it "is successful" do
7386
expect(response.success?).to eq true
7487
end
88+
7589
it "fails when settings are invalid" do
76-
response = subject.delete_app_configuration(setting_id: "NonExistentSettingTotesBogus")
77-
expect(response.success?).to eq false
78-
expect(response.status).to eq 400
79-
expect(response.message).to match(/NonExistentSettingTotesBogus/)
90+
response = client.delete_app_configuration(setting_id: "NonExistentSettingTotesBogus")
91+
aggregate_failures do
92+
expect(response.success?).to eq false
93+
expect(response.status).to eq 400
94+
expect(response.message).to match(/NonExistentSettingTotesBogus/)
95+
end
8096
end
8197
end
8298
end
99+
# rubocop:enable RSpec/ExampleLength

0 commit comments

Comments
 (0)