Skip to content

Commit 2ddea33

Browse files
authored
Merge pull request #1482 from sul-dlss/named-subject
Fix Rspec/NamedSubject lint errors
2 parents 9cab39e + 15acfa3 commit 2ddea33

10 files changed

+79
-112
lines changed

.rubocop_todo.yml

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2025-08-04 20:22:48 UTC using RuboCop version 1.79.1.
3+
# on 2025-08-07 17:15:23 UTC using RuboCop version 1.79.1.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -19,9 +19,9 @@ Metrics/CyclomaticComplexity:
1919
# Offense count: 19
2020
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
2121
Metrics/MethodLength:
22-
Max: 25
22+
Max: 24
2323

24-
# Offense count: 25
24+
# Offense count: 23
2525
RSpec/AnyInstance:
2626
Exclude:
2727
- 'spec/controllers/media_controller_spec.rb'
@@ -34,10 +34,9 @@ RSpec/AnyInstance:
3434
- 'spec/requests/iiif/auth/v2/tokens_spec.rb'
3535
- 'spec/requests/iiif_auth_request_spec.rb'
3636
- 'spec/requests/iiif_spec.rb'
37-
- 'spec/requests/media_auth_request_spec.rb'
3837
- 'spec/requests/versioned_file_spec.rb'
3938

40-
# Offense count: 57
39+
# Offense count: 54
4140
# Configuration parameters: Prefixes, AllowedPatterns.
4241
# Prefixes: when, with, without
4342
RSpec/ContextWording:
@@ -48,7 +47,6 @@ RSpec/ContextWording:
4847
- 'spec/models/projection_spec.rb'
4948
- 'spec/requests/file_auth_request_spec.rb'
5049
- 'spec/requests/iiif_spec.rb'
51-
- 'spec/requests/media_auth_request_spec.rb'
5250
- 'spec/services/iiif_metadata_service_spec.rb'
5351
- 'spec/services/media_authentication_json_spec.rb'
5452

@@ -67,7 +65,7 @@ RSpec/EmptyLineAfterExampleGroup:
6765
Exclude:
6866
- 'spec/requests/file_auth_request_spec.rb'
6967

70-
# Offense count: 17
68+
# Offense count: 18
7169
# This cop supports safe autocorrection (--autocorrect).
7270
RSpec/EmptyLineAfterFinalLet:
7371
Exclude:
@@ -88,16 +86,15 @@ RSpec/EmptyLineAfterHook:
8886
- 'spec/features/status_spec.rb'
8987
- 'spec/requests/iiif_spec.rb'
9088

91-
# Offense count: 9
89+
# Offense count: 7
9290
# This cop supports safe autocorrection (--autocorrect).
9391
RSpec/EmptyLineAfterSubject:
9492
Exclude:
9593
- 'spec/controllers/webauth_controller_spec.rb'
96-
- 'spec/models/projection_spec.rb'
9794
- 'spec/models/stacks_image_spec.rb'
9895
- 'spec/services/iiif_metadata_service_spec.rb'
9996

100-
# Offense count: 39
97+
# Offense count: 47
10198
# Configuration parameters: CountAsOne.
10299
RSpec/ExampleLength:
103100
Max: 16
@@ -128,37 +125,28 @@ RSpec/LeadingSubject:
128125
- 'spec/models/stacks_media_token_spec.rb'
129126
- 'spec/services/media_authentication_json_spec.rb'
130127

131-
# Offense count: 8
128+
# Offense count: 7
132129
# Configuration parameters: EnforcedStyle.
133130
# SupportedStyles: have_received, receive
134131
RSpec/MessageSpies:
135132
Exclude:
136133
- 'spec/controllers/file_controller_spec.rb'
137134
- 'spec/controllers/media_controller_spec.rb'
138135

139-
# Offense count: 94
136+
# Offense count: 97
140137
RSpec/MultipleExpectations:
141138
Max: 12
142139

143-
# Offense count: 63
140+
# Offense count: 13
144141
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
145142
# SupportedStyles: always, named_only
146143
RSpec/NamedSubject:
147144
Exclude:
148-
- 'spec/controllers/application_controller_spec.rb'
149145
- 'spec/controllers/file_controller_spec.rb'
150146
- 'spec/controllers/webauth_controller_spec.rb'
151-
- 'spec/models/approved_location_spec.rb'
152-
- 'spec/models/projection_spec.rb'
153-
- 'spec/models/restricted_image_spec.rb'
154-
- 'spec/models/stacks_file_spec.rb'
155-
- 'spec/models/stacks_image_spec.rb'
156147
- 'spec/models/stacks_media_token_spec.rb'
157-
- 'spec/models/user_spec.rb'
158-
- 'spec/services/iiif_metadata_service_spec.rb'
159-
- 'spec/services/media_authentication_json_spec.rb'
160148

161-
# Offense count: 65
149+
# Offense count: 66
162150
# Configuration parameters: AllowedGroups.
163151
RSpec/NestedGroups:
164152
Max: 6
@@ -168,7 +156,7 @@ RSpec/RepeatedDescription:
168156
Exclude:
169157
- 'spec/routing/legacy_image_api_spec.rb'
170158

171-
# Offense count: 5
159+
# Offense count: 4
172160
RSpec/StubbedMock:
173161
Exclude:
174162
- 'spec/controllers/file_controller_spec.rb'
@@ -192,4 +180,3 @@ RSpec/VerifiedDoubles:
192180
Rails/I18nLocaleTexts:
193181
Exclude:
194182
- 'app/controllers/webauth_controller.rb'
195-

spec/controllers/application_controller_spec.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@
44

55
RSpec.describe ApplicationController do
66
describe '#current_user' do
7-
subject { controller.send(:current_user) }
7+
subject(:user) { controller.send(:current_user) }
88

99
context 'with a Bearer token' do
10-
let(:user) { User.new(id: 'test-user', ldap_groups: ['stanford:stanford']) }
10+
let(:persisted_user) { User.new(id: 'test-user', ldap_groups: ['stanford:stanford']) }
1111
let(:credentials) do
1212
# `encode_credentials` hardcodes `Token` so make sure to test `Bearer`
1313
# http://iiif.io/api/auth/1.0/#the-json-access-token-response
14-
ActionController::HttpAuthentication::Token.encode_credentials(user.token).gsub('Token', 'Bearer')
14+
ActionController::HttpAuthentication::Token.encode_credentials(persisted_user.token).gsub('Token', 'Bearer')
1515
end
1616

1717
before do
1818
request.env['HTTP_AUTHORIZATION'] = credentials
1919
end
2020

2121
it 'supports bearer auth users' do
22-
expect(subject.id).to eq 'test-user'
23-
expect(subject).to be_a_token_user
24-
expect(subject).to be_stanford
22+
expect(user.id).to eq 'test-user'
23+
expect(user).to be_a_token_user
24+
expect(user).to be_stanford
2525
end
2626
end
2727

@@ -31,14 +31,14 @@
3131
end
3232

3333
it 'supports webauth users' do
34-
expect(subject.id).to eq 'my-user'
35-
expect(subject).to be_a_webauth_user
34+
expect(user.id).to eq 'my-user'
35+
expect(user).to be_a_webauth_user
3636
end
3737

3838
context 'with shibboleth groups' do
3939
before { request.env['eduPersonEntitlement'] = 'a;b' }
4040
it 'supports shibboleth users' do
41-
expect(subject.ldap_groups).to match_array %w[a b]
41+
expect(user.ldap_groups).to match_array %w[a b]
4242
end
4343
end
4444
end
@@ -48,7 +48,7 @@
4848
request.env['REMOTE_USER'] = ''
4949
end
5050

51-
it { expect(subject).not_to be_a_webauth_user }
51+
it { expect(user).not_to be_a_webauth_user }
5252
end
5353

5454
context 'with session information' do
@@ -58,15 +58,15 @@
5858
end
5959

6060
it 'retrieves the remote user and workgroup information' do
61-
expect(subject.id).to eq 'my-user'
62-
expect(subject).to be_a_webauth_user
63-
expect(subject.ldap_groups).to match_array %w[a b]
61+
expect(user.id).to eq 'my-user'
62+
expect(user).to be_a_webauth_user
63+
expect(user.ldap_groups).to match_array %w[a b]
6464
end
6565
end
6666

6767
context 'with no other credentials' do
6868
it 'is an anonymous locatable user' do
69-
expect(subject).to be_an_anonymous_locatable_user
69+
expect(user).to be_an_anonymous_locatable_user
7070
end
7171
end
7272
end

spec/models/approved_location_spec.rb

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,23 @@
33
require 'rails_helper'
44

55
RSpec.describe ApprovedLocation do
6-
subject { described_class.new(locatable) }
6+
subject { described_class.new(locatable).locations }
77

88
context "when the locatable object's IP address does exist in the configuration" do
99
let(:locatable) { double('Locatable', ip_address: 'ip.address1') }
1010

11-
it 'returns the location name as a string' do
12-
expect(subject.locations).to eq %w[location1 location2]
13-
end
11+
it { is_expected.to eq %w[location1 location2] }
1412
end
1513

1614
context "when the locatable object's IP address does not exist in the configuration" do
1715
let(:locatable) { double('Locatable', ip_address: 'not.a.configured.ip') }
1816

19-
it 'returns an empty array' do
20-
expect(subject.locations).to eq []
21-
end
17+
it { is_expected.to be_empty }
2218
end
2319

2420
context 'when the locatable object has no IP address' do
2521
let(:locatable) { double('NotReallyLocatable') }
2622

27-
it 'returns an empty array' do
28-
expect(subject.locations).to eq []
29-
end
23+
it { is_expected.to be_empty }
3024
end
3125
end

spec/models/projection_spec.rb

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
end
2222

2323
describe '#tile_dimensions' do
24-
subject { instance.send(:tile_dimensions) }
24+
subject(:dimensions) { instance.send(:tile_dimensions) }
2525

2626
context "for an unrestricted image" do
2727
context "explicit sizes" do
@@ -51,10 +51,10 @@
5151
context 'for requests with "max" size' do
5252
let(:ability) { instance_double(Ability) }
5353
let(:permissive_ability) do
54-
ability.tap { |x| allow(x).to receive(:can?).with(:download, subject).and_return(true) }
54+
ability.tap { |x| allow(x).to receive(:can?).with(:download, dimensions).and_return(true) }
5555
end
5656
let(:restricted_ability) do
57-
ability.tap { |x| allow(x).to receive(:can?).with(:download, subject).and_return(false) }
57+
ability.tap { |x| allow(x).to receive(:can?).with(:download, dimensions).and_return(false) }
5858
end
5959
let(:options) { { size: 'max', region: '0,0,800,600' } }
6060

@@ -74,23 +74,23 @@
7474
let(:options) { { size: 'max', region: 'full' } }
7575

7676
it 'limits users to thumbnail sizes' do
77-
expect(subject).to eq IIIF::Image::Dimension.new(width: 400, height: 400)
77+
expect(dimensions).to eq IIIF::Image::Dimension.new(width: 400, height: 400)
7878
end
7979
end
8080

8181
context "best fit size" do
8282
let(:options) { { size: '!800,800', region: 'full' } }
8383

8484
it 'limits users to thumbnail sizes' do
85-
expect(subject).to eq IIIF::Image::Dimension.new(width: 400, height: 400)
85+
expect(dimensions).to eq IIIF::Image::Dimension.new(width: 400, height: 400)
8686
end
8787
end
8888

8989
context "specified region" do
9090
let(:options) { { size: 'max', region: '0,0,800,600' } }
9191

9292
it 'limits users to a maximum tiles size' do
93-
expect(subject).to eq IIIF::Image::Dimension.new(width: 512, height: 512)
93+
expect(dimensions).to eq IIIF::Image::Dimension.new(width: 512, height: 512)
9494
end
9595
end
9696
end
@@ -112,7 +112,7 @@
112112
it 'allows the user to see the full-resolution image' do
113113
allow(HTTP).to receive_message_chain(:timeout, :headers, :use).and_return(http_client)
114114
allow(http_client).to receive(:get).and_return(double(body: nil))
115-
subject.response
115+
projection.response
116116
expect(http_client).to have_received(:get).with(%r{/full/max/0/default.jpg})
117117
end
118118
end
@@ -123,7 +123,7 @@
123123
it 'returns original size when requested dimensions are larger' do
124124
allow(HTTP).to receive_message_chain(:timeout, :headers, :use).and_return(http_client)
125125
allow(http_client).to receive(:get).and_return(double(body: nil))
126-
subject.response
126+
projection.response
127127
expect(http_client).to have_received(:get).with(%r{/full/!800,600/0/default.jpg})
128128
end
129129
end
@@ -141,7 +141,7 @@
141141
allow(HTTP).to receive_message_chain(:timeout, :headers, :use)
142142
.and_return(http_client)
143143
allow(http_client).to receive(:get).and_return(double(body: nil))
144-
subject.response
144+
projection.response
145145
expect(http_client).to have_received(:get).with(%r{/full/!400,400/0/default.jpg})
146146
end
147147
end
@@ -153,7 +153,7 @@
153153
allow(HTTP).to receive_message_chain(:timeout, :headers, :use)
154154
.and_return(http_client)
155155
allow(http_client).to receive(:get).and_return(double(body: nil))
156-
subject.response
156+
projection.response
157157
expect(http_client).to have_received(:get).with(%r{/full/!100,100/0/default.jpg})
158158
end
159159
end
@@ -165,7 +165,7 @@
165165
allow(HTTP).to receive_message_chain(:timeout, :headers, :use)
166166
.and_return(http_client)
167167
allow(http_client).to receive(:get).and_return(double(body: nil))
168-
subject.response
168+
projection.response
169169
expect(http_client).to have_received(:get).with(%r{/full/!400,400/0/default.jpg})
170170
end
171171
end
@@ -177,7 +177,7 @@
177177
allow(HTTP).to receive_message_chain(:timeout, :headers, :use)
178178
.and_return(http_client)
179179
allow(http_client).to receive(:get).and_return(double(body: nil))
180-
subject.response
180+
projection.response
181181
expect(http_client).to have_received(:get).with(%r{/square/100,100/0/default.jpg})
182182
end
183183
end
@@ -272,35 +272,30 @@
272272

273273
describe '#region_dimensions' do
274274
subject { instance.region_dimensions }
275+
275276
context 'for a full region' do
276277
let(:options) { { size: 'full', region: 'full' } }
277278

278-
it 'uses the image dimensions' do
279-
expect(subject).to eq IIIF::Image::Dimension.new(width: 800, height: 600)
280-
end
279+
it { is_expected.to eq IIIF::Image::Dimension.new(width: 800, height: 600) }
281280
end
282281

283282
context 'for square' do
284283
let(:options) { { size: 'full', region: 'square' } }
285284

286-
it 'uses the image dimensions' do
287-
expect(subject).to eq IIIF::Image::Dimension.new(width: 600, height: 600)
288-
end
285+
it { is_expected.to eq IIIF::Image::Dimension.new(width: 600, height: 600) }
289286
end
290287

291288
context 'for an explicit region' do
292289
let(:options) { { size: 'full', region: '0,1,2,3' } }
293290

294-
it 'handles explicit region requests' do
295-
expect(subject).to eq IIIF::Image::Dimension.new(width: 2, height: 3)
296-
end
291+
it { is_expected.to eq IIIF::Image::Dimension.new(width: 2, height: 3) }
297292
end
298293

299294
context 'for an region that contains negative values' do
300295
let(:options) { { size: 'full', region: '-22832,-22832,22832,22832' } }
301296

302297
it 'raises an error' do
303-
expect { subject }.to raise_error IIIF::Image::InvalidAttributeError
298+
expect { instance.region_dimensions }.to raise_error IIIF::Image::InvalidAttributeError
304299
end
305300
end
306301
end

spec/models/restricted_image_spec.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@
66
let(:instance) { described_class.new(stacks_file: instance_double(StacksImage)) }
77

88
describe '#info' do
9-
subject { instance.info }
10-
119
let(:info_service) { instance_double(IiifMetadataService, fetch: {}) }
1210

1311
before do
1412
allow(instance).to receive(:info_service).and_return(info_service)
13+
instance.info
1514
end
1615

1716
it "adds tile size to the djatoka response" do
18-
subject
1917
expect(info_service).to have_received(:fetch).with(256)
2018
end
2119
end

0 commit comments

Comments
 (0)