-
Notifications
You must be signed in to change notification settings - Fork 3
Remove activesupport due to its volatility and potential to generate … #211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b284a14
90333d2
c3208da
0e46287
17c84f7
49cc4eb
372cfa0
cc54fb9
cd5337a
c7f6676
b5fdb6d
b39dec3
a29c0b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| # Feel free to correct anything in this file | ||
|
|
||
| AllCops: | ||
| TargetRubyVersion: 3.1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| require "pstore" | ||
|
|
||
| module ChefLicensing | ||
| # Simple adapter to make PStore compatible with Faraday::HttpCache | ||
| class PStoreAdapter | ||
| def initialize(cache_dir) | ||
| @store_path = File.join(cache_dir, "chef_licensing_cache.pstore") | ||
| @store = PStore.new(@store_path) | ||
| end | ||
|
|
||
| # Interface methods required by faraday-http-cache | ||
| def read(key) | ||
| @store.transaction { @store[key] } | ||
| end | ||
|
|
||
| def write(key, value, options = {}) | ||
| # PStore handles persistence, Faraday::HttpCache handles | ||
| # HTTP cache headers for expiration | ||
| @store.transaction { @store[key] = value } | ||
| end | ||
|
|
||
| def delete(key) | ||
| @store.transaction { @store.delete(key) } | ||
| end | ||
|
|
||
| def exist?(key) | ||
| @store.transaction { @store.root?(key) } | ||
| end | ||
|
|
||
| def clear | ||
| @store.transaction do | ||
| @store.roots.each { |root| @store.delete(root) } | ||
| end | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,25 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| module ChefLicensing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # String refinements to provide pluralization functionality | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Replaces ActiveSupport::Inflector for our specific use case | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| module StringRefinements | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| refine String do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def pluralize(count = 2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return self if count == 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Simple pluralization rules | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case downcase | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| when /s$/, /sh$/, /ch$/, /x$/, /z$/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "#{self}es" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| when /[^aeiou]y$/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "#{self[0..-2]}ies" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| when /f$/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "#{self[0..-2]}ves" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| when /fe$/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "#{self[0..-3]}ves" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "#{self}s" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+9
to
+20
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Simple pluralization rules | |
| case downcase | |
| when /s$/, /sh$/, /ch$/, /x$/, /z$/ | |
| "#{self}es" | |
| when /[^aeiou]y$/ | |
| "#{self[0..-2]}ies" | |
| when /f$/ | |
| "#{self[0..-2]}ves" | |
| when /fe$/ | |
| "#{self[0..-3]}ves" | |
| else | |
| "#{self}s" | |
| # Determine the pluralized form in lowercase | |
| word = self | |
| plural = | |
| case word.downcase | |
| when /s$/, /sh$/, /ch$/, /x$/, /z$/ | |
| "#{word}es" | |
| when /[^aeiou]y$/ | |
| "#{word[0..-2]}ies" | |
| when /f$/ | |
| "#{word[0..-2]}ves" | |
| when /fe$/ | |
| "#{word[0..-3]}ves" | |
| else | |
| "#{word}s" | |
| end | |
| # Preserve original capitalization pattern | |
| if word.match?(/\A[A-Z]+\z/) | |
| plural.upcase | |
| elsif word.match?(/\A[A-Z][a-z]+\z/) | |
| plural.capitalize | |
| elsif word.match?(/\A[a-z]+\z/) | |
| plural.downcase | |
| else | |
| plural |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| Test harness notes for the chef-licensing specs | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can go under a testing section in https://github.com/chef/chef-licensing/blob/51652371610c597bdbe919e7ba8c08fd667cf296/components/ruby/README.md |
||
|
|
||
| Purpose | ||
| ------- | ||
| This file documents the decisions made in `spec/spec_helper.rb` to keep the | ||
| suite deterministic and hermetic. | ||
|
|
||
| Key points | ||
| ---------- | ||
| - WebMock is required before the library (`require "webmock/rspec"`) so any | ||
| HTTP client initialization that happens at require-time is intercepted. | ||
| This prevents accidental real HTTP connections during test bootstrap. | ||
|
|
||
| - The tests set a deterministic license server URL via | ||
| `ENV["CHEF_LICENSE_SERVER"]` and `ENV["LICENSE_SERVER"]` so tests don't | ||
| rely on developer/CI environment values or persisted files that might | ||
| point to production servers. | ||
|
|
||
| - `ENV.delete("CHEF_LICENSE_KEY")` is used to ensure tests don't pick up | ||
| real credentials from the environment. | ||
|
|
||
| - A suite-level temporary HOME (`TMP_TEST_HOME`) is created early so | ||
| require-time code that consults `ENV["HOME"]` or `ENV["USERPROFILE"]` | ||
| doesn't see a developer/CI home. Some specs still require a fresh HOME | ||
| per-example; the harness provides an `around(:each)` hook that swaps in a | ||
| temporary HOME for the duration of those examples. | ||
|
|
||
| - Tests that need HTTP interactions should stub them explicitly using | ||
| WebMock's `stub_request`. Consider adding common stubs to | ||
| `spec/support/license_server_stubs.rb` to reduce duplication. | ||
|
|
||
| Running the tests | ||
| ----------------- | ||
| From the `components/ruby` directory run: | ||
|
|
||
| ```bash | ||
| bundle exec rspec --format=documentation | ||
| ``` | ||
|
|
||
| If you only want to run a single spec file: | ||
|
|
||
| ```bash | ||
| bundle exec rspec spec/path/to/file_spec.rb | ||
| ``` | ||
|
|
||
| Adding a new spec | ||
| ----------------- | ||
| - If your spec touches the user's HOME, prefer creating temporary dirs | ||
| under `Dir.mktmpdir` and avoid writing into the suite-level HOME | ||
| directly. Use the provided per-example HOME swap when you need a | ||
| pristine HOME for each example. | ||
|
|
||
| - If your spec makes HTTP calls, add a `stub_request` for the exact | ||
| request the code will issue. If multiple specs need the same stubs, | ||
| factor them into `spec/support/license_server_stubs.rb` and require that | ||
| from `spec/spec_helper.rb`. | ||
|
|
||
| Contact | ||
| ------- | ||
| If you have questions about why this setup exists, check the Git history | ||
| for `spec/spec_helper.rb` or ask the maintainer team. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick, I see we use string refinements only here, and only for the purpose of
pluralizemay be we should just call it as a util and use the util directly something like below,Chef::Licensing::StringUtils.present?(str)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I did it as a string refinement was because was one of the prior uses for ActiveSupport. I'm absolutely fine with a module with an explicit method call, but assumed that that wasn't the desire of the original code.