openstax_utilities 4.2.3 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- FactoryGirl.define do
1
+ FactoryBot.define do
2
2
  factory :user do
3
3
  username { SecureRandom.hex.to_s }
4
4
  password_hash { SecureRandom.hex.to_s }
@@ -5,7 +5,7 @@ module OpenStax
5
5
 
6
6
  describe AccessPolicy do
7
7
 
8
- let!(:user) { FactoryGirl.create :user }
8
+ let!(:user) { FactoryBot.create :user }
9
9
 
10
10
  it 'responds to any _allowed? calls' do
11
11
  AccessPolicy.register(User, DummyAccessPolicy)
@@ -0,0 +1,40 @@
1
+ require 'rails_helper'
2
+ require 'vcr_helper'
3
+
4
+ RSpec.describe OpenStax::Utilities::Assets, vcr: VCR_OPTS do
5
+ before { RequestStore.store[:assets_manifest] = nil }
6
+
7
+ it 'defaults to name.js when manifest is missing' do
8
+ expect_any_instance_of(Faraday::Connection).to receive(:get).and_return(
9
+ OpenStruct.new success?: false
10
+ )
11
+ expect(described_class.tags_for(:foo)).to include "src='http://localhost:8000/dist/foo.js'"
12
+ end
13
+
14
+ it 'reads asset url from manifest' do
15
+ expect_any_instance_of(Faraday::Connection).to receive(:get).and_return(
16
+ OpenStruct.new(
17
+ success?: true,
18
+ body: { entrypoints: { foo: { js: [ 'foo-732c56c32ff399b62.min.bar' ] } } }.to_json
19
+ )
20
+ )
21
+ expect(described_class.tags_for(:foo)).to include(
22
+ "src='http://localhost:8000/dist/foo-732c56c32ff399b62.min.bar'"
23
+ )
24
+ end
25
+
26
+ context 'loading remote manifest' do
27
+ before do
28
+ @previous_assets_url = Rails.application.secrets.assets_url
29
+ Rails.application.secrets.assets_url = 'https://tutor-dev.openstax.org/assets'
30
+ end
31
+ after { Rails.application.secrets.assets_url = @previous_assets_url }
32
+
33
+ it 'uses remote json' do
34
+ expect(described_class.manifest).to be_kind_of described_class::Manifest
35
+ expect(described_class.tags_for(:tutor)).to(
36
+ eq "<script type='text/javascript' src='https://tutor-dev.openstax.org/assets/tutor-b920eb0be760a7c440bf.min.js' crossorigin='anonymous' async></script>"
37
+ )
38
+ end
39
+ end
40
+ end
@@ -3,9 +3,8 @@ ENV["RAILS_ENV"] ||= 'test'
3
3
  require 'spec_helper'
4
4
  require File.expand_path("../dummy/config/environment", __FILE__)
5
5
  require 'rspec/rails'
6
- require 'factory_girl_rails'
6
+ require 'factory_bot_rails'
7
7
  require 'faker'
8
- require 'squeel'
9
8
 
10
9
  # Add additional requires below this line. Rails is not loaded until this point!
11
10
 
@@ -4,21 +4,21 @@ module OpenStax
4
4
  module Utilities
5
5
  describe SearchRelation do
6
6
 
7
- let!(:john_doe) { FactoryGirl.create :user, name: "John Doe",
7
+ let!(:john_doe) { FactoryBot.create :user, name: "John Doe",
8
8
  username: "doejohn",
9
9
  email: "john@doe.com" }
10
10
 
11
- let!(:jane_doe) { FactoryGirl.create :user, name: "Jane Doe",
11
+ let!(:jane_doe) { FactoryBot.create :user, name: "Jane Doe",
12
12
  username: "doejane",
13
13
  email: "jane@doe.com" }
14
14
 
15
- let!(:jack_doe) { FactoryGirl.create :user, name: "Jack Doe",
15
+ let!(:jack_doe) { FactoryBot.create :user, name: "Jack Doe",
16
16
  username: "doejack",
17
17
  email: "jack@doe.com" }
18
18
 
19
19
  before(:each) do
20
20
  100.times do
21
- FactoryGirl.create(:user)
21
+ FactoryBot.create(:user)
22
22
  end
23
23
 
24
24
  @relation = User.unscoped
@@ -3,32 +3,30 @@ require 'rails_helper'
3
3
  module OpenStax
4
4
  module Utilities
5
5
  describe SearchRelation do
6
+ let!(:john_doe) do
7
+ FactoryBot.create :user, name: "John Doe", username: "doejohn", email: "john@doe.com"
8
+ end
6
9
 
7
- let!(:john_doe) { FactoryGirl.create :user, name: "John Doe",
8
- username: "doejohn",
9
- email: "john@doe.com" }
10
-
11
- let!(:jane_doe) { FactoryGirl.create :user, name: "Jane Doe",
12
- username: "doejane",
13
- email: "jane@doe.com" }
10
+ let!(:jane_doe) do
11
+ FactoryBot.create :user, name: "Jane Doe", username: "doejane", email: "jane@doe.com"
12
+ end
14
13
 
15
- let!(:jack_doe) { FactoryGirl.create :user, name: "Jack Doe",
16
- username: "doejack",
17
- email: "jack@doe.com" }
14
+ let!(:jack_doe) do
15
+ FactoryBot.create :user, name: "Jack Doe", username: "doejack", email: "jack@doe.com"
16
+ end
18
17
 
19
18
  before(:each) do
20
- 100.times do
21
- FactoryGirl.create(:user)
22
- end
19
+ 100.times { FactoryBot.create(:user) }
23
20
 
24
- @relation = User.where{username.like 'doe%'}
21
+ @relation = User.where(User.arel_table[:username].matches('doe%'))
25
22
  end
26
23
 
27
24
  it "orders results by multiple fields in different directions" do
28
- items = OrderRelation.call(relation: @relation,
29
- sortable_fields: SearchUsers::SORTABLE_FIELDS,
30
- order_by: 'cReAtEd_At AsC, iD')
31
- .outputs[:items]
25
+ items = OrderRelation.call(
26
+ relation: @relation,
27
+ sortable_fields: SearchUsers::SORTABLE_FIELDS,
28
+ order_by: 'cReAtEd_At AsC, iD'
29
+ ).outputs[:items]
32
30
  expect(items).to include(john_doe)
33
31
  expect(items).to include(jane_doe)
34
32
  expect(items).to include(jack_doe)
@@ -38,10 +36,11 @@ module OpenStax
38
36
  expect(jane_index).to be > john_index
39
37
  expect(jack_index).to be > jane_index
40
38
 
41
- items = OrderRelation.call(relation: @relation,
42
- sortable_fields: SearchUsers::SORTABLE_FIELDS,
43
- order_by: 'CrEaTeD_aT dEsC, Id DeSc')
44
- .outputs[:items]
39
+ items = OrderRelation.call(
40
+ relation: @relation,
41
+ sortable_fields: SearchUsers::SORTABLE_FIELDS,
42
+ order_by: 'CrEaTeD_aT dEsC, Id DeSc'
43
+ ).outputs[:items]
45
44
  expect(items).to include(john_doe)
46
45
  expect(items).to include(jane_doe)
47
46
  expect(items).to include(jack_doe)
@@ -51,7 +50,6 @@ module OpenStax
51
50
  expect(jane_index).to be < john_index
52
51
  expect(jack_index).to be < jane_index
53
52
  end
54
-
55
53
  end
56
54
  end
57
55
  end
@@ -11,21 +11,21 @@ module OpenStax
11
11
  max_items: SearchUsers::MAX_ITEMS
12
12
  }
13
13
 
14
- let!(:john_doe) { FactoryGirl.create :user, name: "John Doe",
14
+ let!(:john_doe) { FactoryBot.create :user, name: "John Doe",
15
15
  username: "doejohn",
16
16
  email: "john@doe.com" }
17
17
 
18
- let!(:jane_doe) { FactoryGirl.create :user, name: "Jane Doe",
18
+ let!(:jane_doe) { FactoryBot.create :user, name: "Jane Doe",
19
19
  username: "doejane",
20
20
  email: "jane@doe.com" }
21
21
 
22
- let!(:jack_doe) { FactoryGirl.create :user, name: "Jack Doe",
22
+ let!(:jack_doe) { FactoryBot.create :user, name: "Jack Doe",
23
23
  username: "doejack",
24
24
  email: "jack@doe.com" }
25
25
 
26
26
  before(:each) do
27
27
  100.times do
28
- FactoryGirl.create(:user)
28
+ FactoryBot.create(:user)
29
29
  end
30
30
  end
31
31
 
@@ -3,22 +3,21 @@ require 'rails_helper'
3
3
  module OpenStax
4
4
  module Utilities
5
5
  describe SearchRelation do
6
+ let!(:john_doe) do
7
+ FactoryBot.create :user, name: "John Doe", username: "doejohn", email: "john@doe.com"
8
+ end
6
9
 
7
- let!(:john_doe) { FactoryGirl.create :user, name: "John Doe",
8
- username: "doejohn",
9
- email: "john@doe.com" }
10
-
11
- let!(:jane_doe) { FactoryGirl.create :user, name: "Jane Doe",
12
- username: "doejane",
13
- email: "jane@doe.com" }
10
+ let!(:jane_doe) do
11
+ FactoryBot.create :user, name: "Jane Doe", username: "doejane", email: "jane@doe.com"
12
+ end
14
13
 
15
- let!(:jack_doe) { FactoryGirl.create :user, name: "Jack Doe",
16
- username: "doejack",
17
- email: "jack@doe.com" }
14
+ let!(:jack_doe) do
15
+ FactoryBot.create :user, name: "Jack Doe", username: "doejack", email: "jack@doe.com"
16
+ end
18
17
 
19
18
  before(:each) do
20
19
  100.times do
21
- FactoryGirl.create(:user)
20
+ FactoryBot.create(:user)
22
21
  end
23
22
  end
24
23
 
@@ -64,9 +63,11 @@ module OpenStax
64
63
  end
65
64
 
66
65
  it "filters scoped results" do
67
- items = SearchRelation.call(relation: User.where{name.like 'jOhN%'},
68
- search_proc: SearchUsers::SEARCH_PROC,
69
- query: 'last_name:dOe').outputs[:items]
66
+ items = SearchRelation.call(
67
+ relation: User.where(User.arel_table[:name].matches('jOhN%')),
68
+ search_proc: SearchUsers::SEARCH_PROC,
69
+ query: 'last_name:dOe'
70
+ ).outputs[:items]
70
71
 
71
72
  expect(items).to include(john_doe)
72
73
  expect(items).not_to include(jane_doe)
@@ -75,7 +76,6 @@ module OpenStax
75
76
  expect(item.name.downcase).to match(/\Ajohn[\w]* doe[\w]*\z/i)
76
77
  end
77
78
  end
78
-
79
79
  end
80
80
  end
81
81
  end
@@ -0,0 +1,18 @@
1
+ require 'vcr'
2
+
3
+ VCR.configure do |c|
4
+ c.cassette_library_dir = 'spec/cassettes'
5
+ c.hook_into :webmock
6
+ c.configure_rspec_metadata!
7
+ c.allow_http_connections_when_no_cassette = Rails.env.development?
8
+ c.ignore_localhost = true
9
+ c.ignore_request { |request| Addressable::URI.parse(request.uri).path == '/oauth/token' } \
10
+ if Rails.env.development?
11
+ c.preserve_exact_body_bytes { |http_message| !http_message.body.valid_encoding? }
12
+ end
13
+
14
+ VCR_OPTS = {
15
+ # This should default to :none
16
+ record: ENV.fetch('VCR_OPTS_RECORD', :none).to_sym,
17
+ allow_unused_http_interactions: Rails.env.development?
18
+ }
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openstax_utilities
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.3
4
+ version: 4.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Slavinsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-05 00:00:00.000000000 Z
11
+ date: 2020-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.1'
19
+ version: '5.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '3.1'
26
+ version: '5.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: lev
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +52,48 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: request_store
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: faraday
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday-http-cache
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
55
97
  - !ruby/object:Gem::Dependency
56
98
  name: sqlite3
57
99
  requirement: !ruby/object:Gem::Requirement
@@ -81,7 +123,7 @@ dependencies:
81
123
  - !ruby/object:Gem::Version
82
124
  version: '0'
83
125
  - !ruby/object:Gem::Dependency
84
- name: factory_girl_rails
126
+ name: factory_bot_rails
85
127
  requirement: !ruby/object:Gem::Requirement
86
128
  requirements:
87
129
  - - ">="
@@ -109,7 +151,21 @@ dependencies:
109
151
  - !ruby/object:Gem::Version
110
152
  version: '0'
111
153
  - !ruby/object:Gem::Dependency
112
- name: squeel
154
+ name: vcr
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: webmock
113
169
  requirement: !ruby/object:Gem::Requirement
114
170
  requirements:
115
171
  - - ">="
@@ -142,6 +198,8 @@ files:
142
198
  - lib/openstax/utilities/action_list.rb
143
199
  - lib/openstax/utilities/active_record_extensions.rb
144
200
  - lib/openstax/utilities/acts_as_numberable.rb
201
+ - lib/openstax/utilities/assets.rb
202
+ - lib/openstax/utilities/assets/manifest.rb
145
203
  - lib/openstax/utilities/classy_helper.rb
146
204
  - lib/openstax/utilities/delegate_access_control.rb
147
205
  - lib/openstax/utilities/engine.rb
@@ -158,10 +216,12 @@ files:
158
216
  - lib/openstax/utilities/text.rb
159
217
  - lib/openstax/utilities/version.rb
160
218
  - lib/openstax_utilities.rb
219
+ - spec/cassettes/OpenStax_Utilities_Assets/loading_remote_manifest/uses_remote_json.yml
161
220
  - spec/dummy/README.md
162
221
  - spec/dummy/Rakefile
163
222
  - spec/dummy/app/access_policies/dummier_access_policy.rb
164
223
  - spec/dummy/app/access_policies/dummy_access_policy.rb
224
+ - spec/dummy/app/assets/config/manifest.js
165
225
  - spec/dummy/app/assets/javascripts/application.js
166
226
  - spec/dummy/app/assets/stylesheets/application.css
167
227
  - spec/dummy/app/controllers/application_controller.rb
@@ -194,18 +254,23 @@ files:
194
254
  - spec/dummy/config/secrets.yml
195
255
  - spec/dummy/db/migrate/0_create_users.rb
196
256
  - spec/dummy/db/schema.rb
257
+ - spec/dummy/db/test.sqlite3
258
+ - spec/dummy/log/test.log
197
259
  - spec/dummy/public/404.html
198
260
  - spec/dummy/public/422.html
199
261
  - spec/dummy/public/500.html
200
262
  - spec/dummy/public/favicon.ico
263
+ - spec/dummy/tmp/cache/C09/760/6da7b2a29da9cb0f80ef102c7effb91fab3374db
201
264
  - spec/factories/user.rb
202
265
  - spec/lib/openstax/utilities/access_policy_spec.rb
266
+ - spec/lib/openstax/utilities/assets_spec.rb
203
267
  - spec/rails_helper.rb
204
268
  - spec/routines/openstax/utilities/limit_and_paginate_relation_spec.rb
205
269
  - spec/routines/openstax/utilities/order_relation_spec.rb
206
270
  - spec/routines/openstax/utilities/search_and_organize_relation_spec.rb
207
271
  - spec/routines/openstax/utilities/search_relation_spec.rb
208
272
  - spec/spec_helper.rb
273
+ - spec/vcr_helper.rb
209
274
  homepage: http://github.com/openstax/openstax_utilities
210
275
  licenses:
211
276
  - MIT
@@ -225,57 +290,63 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
290
  - !ruby/object:Gem::Version
226
291
  version: '0'
227
292
  requirements: []
228
- rubyforge_project:
229
- rubygems_version: 2.2.2
293
+ rubygems_version: 3.1.4
230
294
  signing_key:
231
295
  specification_version: 4
232
296
  summary: Utilities for OpenStax web sites
233
297
  test_files:
234
- - spec/dummy/app/access_policies/dummier_access_policy.rb
235
- - spec/dummy/app/access_policies/dummy_access_policy.rb
298
+ - spec/rails_helper.rb
299
+ - spec/spec_helper.rb
300
+ - spec/vcr_helper.rb
301
+ - spec/factories/user.rb
302
+ - spec/dummy/app/models/user.rb
236
303
  - spec/dummy/app/assets/javascripts/application.js
237
304
  - spec/dummy/app/assets/stylesheets/application.css
305
+ - spec/dummy/app/assets/config/manifest.js
306
+ - spec/dummy/app/views/layouts/application.html.erb
307
+ - spec/dummy/app/access_policies/dummier_access_policy.rb
308
+ - spec/dummy/app/access_policies/dummy_access_policy.rb
238
309
  - spec/dummy/app/controllers/application_controller.rb
239
310
  - spec/dummy/app/helpers/application_helper.rb
240
- - spec/dummy/app/models/user.rb
241
- - spec/dummy/app/views/layouts/application.html.erb
242
- - spec/dummy/bin/bundle
311
+ - spec/dummy/tmp/cache/C09/760/6da7b2a29da9cb0f80ef102c7effb91fab3374db
312
+ - spec/dummy/db/migrate/0_create_users.rb
313
+ - spec/dummy/db/test.sqlite3
314
+ - spec/dummy/db/schema.rb
315
+ - spec/dummy/log/test.log
316
+ - spec/dummy/README.md
317
+ - spec/dummy/public/favicon.ico
318
+ - spec/dummy/public/422.html
319
+ - spec/dummy/public/404.html
320
+ - spec/dummy/public/500.html
321
+ - spec/dummy/config.ru
243
322
  - spec/dummy/bin/rails
244
323
  - spec/dummy/bin/rake
324
+ - spec/dummy/bin/bundle
245
325
  - spec/dummy/config/application.rb
246
- - spec/dummy/config/boot.rb
247
- - spec/dummy/config/database.yml
248
- - spec/dummy/config/environment.rb
249
- - spec/dummy/config/environments/development.rb
250
- - spec/dummy/config/environments/production.rb
251
- - spec/dummy/config/environments/test.rb
252
- - spec/dummy/config/initializers/access_policies.rb
326
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
327
+ - spec/dummy/config/initializers/search_users.rb
253
328
  - spec/dummy/config/initializers/assets.rb
254
- - spec/dummy/config/initializers/backtrace_silencers.rb
255
329
  - spec/dummy/config/initializers/cookies_serializer.rb
256
- - spec/dummy/config/initializers/filter_parameter_logging.rb
257
330
  - spec/dummy/config/initializers/inflections.rb
258
- - spec/dummy/config/initializers/mime_types.rb
259
- - spec/dummy/config/initializers/search_users.rb
260
- - spec/dummy/config/initializers/session_store.rb
331
+ - spec/dummy/config/initializers/backtrace_silencers.rb
261
332
  - spec/dummy/config/initializers/wrap_parameters.rb
333
+ - spec/dummy/config/initializers/access_policies.rb
334
+ - spec/dummy/config/initializers/session_store.rb
335
+ - spec/dummy/config/initializers/mime_types.rb
262
336
  - spec/dummy/config/locales/en.yml
263
337
  - spec/dummy/config/routes.rb
338
+ - spec/dummy/config/database.yml
339
+ - spec/dummy/config/environment.rb
340
+ - spec/dummy/config/boot.rb
341
+ - spec/dummy/config/environments/production.rb
342
+ - spec/dummy/config/environments/test.rb
343
+ - spec/dummy/config/environments/development.rb
264
344
  - spec/dummy/config/secrets.yml
265
- - spec/dummy/config.ru
266
- - spec/dummy/db/migrate/0_create_users.rb
267
- - spec/dummy/db/schema.rb
268
- - spec/dummy/public/404.html
269
- - spec/dummy/public/422.html
270
- - spec/dummy/public/500.html
271
- - spec/dummy/public/favicon.ico
272
345
  - spec/dummy/Rakefile
273
- - spec/dummy/README.md
274
- - spec/factories/user.rb
275
346
  - spec/lib/openstax/utilities/access_policy_spec.rb
276
- - spec/rails_helper.rb
347
+ - spec/lib/openstax/utilities/assets_spec.rb
277
348
  - spec/routines/openstax/utilities/limit_and_paginate_relation_spec.rb
349
+ - spec/routines/openstax/utilities/search_relation_spec.rb
278
350
  - spec/routines/openstax/utilities/order_relation_spec.rb
279
351
  - spec/routines/openstax/utilities/search_and_organize_relation_spec.rb
280
- - spec/routines/openstax/utilities/search_relation_spec.rb
281
- - spec/spec_helper.rb
352
+ - spec/cassettes/OpenStax_Utilities_Assets/loading_remote_manifest/uses_remote_json.yml