Skip to content
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

Sets config.cache_classes to true in test env #722

Merged
merged 1 commit into from
May 20, 2024

Conversation

greveritt
Copy link
Contributor

@greveritt greveritt commented Apr 26, 2024

This is a 🐞 bug fix.

  • I've added tests (if it's a bug, feature or enhancement)
  • I've adjusted the documentation (if it's a feature or enhancement)
  • The test suite passes (run bundle exec rspec to verify this)

I need a little help getting this pull request up to snuff with the standards of this project because I'm editing a template used for the configuration of new apps. I'm not sure what sort of automated tests you want for something like this. Do you want me to try adding the config change that I've already added in the template to spec/fixtures/demo/config/environments/test.rb.

Also, while this pull request hasn't made any new tests fail for me, I also am strangely unable to get tests passing on master. I've included test results from master and from my branch for comparison purposes. I can create a support forum thread about this issue after creating this pull request, if you'd like. I'm running Ruby 3.2.3 on macOS 14.4.1 (23E224), and my master branch is currently at 82796a7.

Tests failing on master

Failures:

  1. Jets::Dotenv#load! ignores *.local files when JETS_ENV_REMOTE=1
    Failure/Error: expect(env["ONLY_REMOTE"]).to eq "1"

    expected: "1"
    got: nil

    (compared using ==)

    ./spec/lib/jets/dotenv_spec.rb:10:in `block (3 levels) in <top (required)>'

  2. Jets::Dotenv#load! replaces ssm: with SSM parameters prefixed with ///
    Failure/Error: expect(env.fetch("AUTENTICATED_URL")).to eq value

    KeyError:
    key not found: "AUTENTICATED_URL"

    ./spec/lib/jets/dotenv_spec.rb:31:in `fetch'

    ./spec/lib/jets/dotenv_spec.rb:31:in `block (3 levels) in <top (required)>'

  3. Jets::Dotenv#load! replaces ssm:/ with SSM parameters from the provided path
    Failure/Error: expect(env.fetch("ABSOLUTE_VARIABLE")).to eq value

    KeyError:
    key not found: "ABSOLUTE_VARIABLE"

    ./spec/lib/jets/dotenv_spec.rb:54:in `fetch'

    ./spec/lib/jets/dotenv_spec.rb:54:in `block (3 levels) in <top (required)>'

  4. Jets::Dotenv#load! aborts the process with a helpful error if an SSM parameter is not found at AWS
    Failure/Error:
    expect { Jets::Dotenv.new.load! }
    .to raise_error(SystemExit)
    .and output(/Error loading/).to_stderr

     expected SystemExit but nothing was raised
    

    ...and:

     expected block to output /Error loading/ to stderr, but output nothing
    

    Diff for (output /Error loading/ to stderr):
    @@ -1 +1 @@
    -/Error loading/
    +""

    ./spec/lib/jets/dotenv_spec.rb:66:in `block (3 levels) in <top (required)>'

Finished in 1.89 seconds (files took 0.73701 seconds to load)
490 examples, 4 failures

Failed examples:

rspec ./spec/lib/jets/dotenv_spec.rb:8 # Jets::Dotenv#load! ignores *.local files when JETS_ENV_REMOTE=1
rspec ./spec/lib/jets/dotenv_spec.rb:13 # Jets::Dotenv#load! replaces ssm: with SSM parameters prefixed with ///
rspec ./spec/lib/jets/dotenv_spec.rb:35 # Jets::Dotenv#load! replaces ssm:/ with SSM parameters from the provided path
rspec ./spec/lib/jets/dotenv_spec.rb:58 # Jets::Dotenv#load! aborts the process with a helpful error if an SSM parameter is not found at AWS

Tests failing on stubbing-fix

Failures:

  1. Jets::Dotenv#load! ignores *.local files when JETS_ENV_REMOTE=1
    Failure/Error: expect(env["ONLY_REMOTE"]).to eq "1"

    expected: "1"
    got: nil

    (compared using ==)

    ./spec/lib/jets/dotenv_spec.rb:10:in `block (3 levels) in <top (required)>'

  2. Jets::Dotenv#load! replaces ssm: with SSM parameters prefixed with ///
    Failure/Error: expect(env.fetch("AUTENTICATED_URL")).to eq value

    KeyError:
    key not found: "AUTENTICATED_URL"

    ./spec/lib/jets/dotenv_spec.rb:31:in `fetch'

    ./spec/lib/jets/dotenv_spec.rb:31:in `block (3 levels) in <top (required)>'

  3. Jets::Dotenv#load! replaces ssm:/ with SSM parameters from the provided path
    Failure/Error: expect(env.fetch("ABSOLUTE_VARIABLE")).to eq value

    KeyError:
    key not found: "ABSOLUTE_VARIABLE"

    ./spec/lib/jets/dotenv_spec.rb:54:in `fetch'

    ./spec/lib/jets/dotenv_spec.rb:54:in `block (3 levels) in <top (required)>'

  4. Jets::Dotenv#load! aborts the process with a helpful error if an SSM parameter is not found at AWS
    Failure/Error:
    expect { Jets::Dotenv.new.load! }
    .to raise_error(SystemExit)
    .and output(/Error loading/).to_stderr

     expected SystemExit but nothing was raised
    

    ...and:

     expected block to output /Error loading/ to stderr, but output nothing
    

    Diff for (output /Error loading/ to stderr):
    @@ -1 +1 @@
    -/Error loading/
    +""

    ./spec/lib/jets/dotenv_spec.rb:66:in `block (3 levels) in <top (required)>'

Finished in 1.95 seconds (files took 0.80936 seconds to load)
490 examples, 4 failures

Failed examples:

rspec ./spec/lib/jets/dotenv_spec.rb:8 # Jets::Dotenv#load! ignores *.local files when JETS_ENV_REMOTE=1
rspec ./spec/lib/jets/dotenv_spec.rb:13 # Jets::Dotenv#load! replaces ssm: with SSM parameters prefixed with ///
rspec ./spec/lib/jets/dotenv_spec.rb:35 # Jets::Dotenv#load! replaces ssm:/ with SSM parameters from the provided path
rspec ./spec/lib/jets/dotenv_spec.rb:58 # Jets::Dotenv#load! aborts the process with a helpful error if an SSM parameter is not found at AWS

Summary

This corrects the cache_classes setting in the template for test environment files.

Context

This fix addresses issue #721.

How to Test

  1. Create a new API Jets app.
  2. Copy the routes, controller, utility class, and tests from my example app to the new Jets app.
  • app/controllers/demo_controller.rb
  • app/utilities/demo_utility.rb
  • spec/controllers/demo_controller_spec.rb
  • config/routes.rb
  1. Run bundle exec rspec spec/controllers/demo_controller_spec.rb

This works on my machine.

Version Changes

Patch (unless this breaks something, of course)

This default allows users to make partial doubles of classes in app/.
This fix addresses issue rubyonjets#721.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants