Skip to content

Commit

Permalink
chore: stop testing Rails secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan committed Jun 4, 2024
1 parent 2868aeb commit 138212e
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 105 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- ruby: "3.2"
gemfile: "gemfiles/rails7.gemfile"
rbs: 'false'
- ruby: "3.2"
- ruby: "3.3"
gemfile: "gemfiles/railsmaster.gemfile"
rbs: 'false'
- ruby: "3.1"
Expand Down Expand Up @@ -69,9 +69,6 @@ jobs:
- name: Run RSpec without rails
run: |
bundle exec rake spec:norails
- name: Run Rails secrets tests for uninitialized app
run: |
bundle exec rake spec:secrets
- name: Run Rails autoload tests
run: |
bundle exec rake spec:autoload
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ end

Using Ruby classes to represent configuration allows you to add helper methods and computed parameters easily, makes the configuration **testable**.

The `anyway_config` gem takes care of loading parameters from **different sources** (YAML, credentials/secrets, environment variables, etc.). Internally, we use a _pipeline pattern_ and provide the [Loaders API](#data-loaders) to manage and [extend](#custom-loaders) its functionality.
The `anyway_config` gem takes care of loading parameters from **different sources** (YAML, credentials, environment variables, etc.). Internally, we use a _pipeline pattern_ and provide the [Loaders API](#data-loaders) to manage and [extend](#custom-loaders) its functionality.

Check out the libraries using Anyway Config for more examples:

Expand Down Expand Up @@ -270,7 +270,6 @@ This feature is similar to `Rails.application.config_for` but more powerful:
| Feature | Rails | Anyway Config |
| ------------- |-------------:| -----:|
| Load data from `config/app.yml` |||
| Load data from `secrets` |||
| Load data from `credentials` |||
| Load data from environment |||
| Load data from [other sources](#data-loaders) |||
Expand Down
11 changes: 1 addition & 10 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ RSpec::Core::RakeTask.new("spec:norails") do |task|
task.verbose = false
end

desc "Run Rails secrets tests for uninitialized app"
RSpec::Core::RakeTask.new("spec:secrets") do |task|
ENV["DO_NOT_INITIALIZE_RAILS"] = "1"
ENV["USE_APP_CONFIGS"] = "0"
ENV["NORAILS"] = "0"
task.rspec_opts = "--order defined --tag secrets"
task.verbose = false
end

desc "Run Rails autoload tests for app/configs"
RSpec::Core::RakeTask.new("spec:autoload") do |task|
ENV["USE_APP_CONFIGS"] = "1"
Expand Down Expand Up @@ -107,4 +98,4 @@ namespace :spec do
end

desc "Run the all specs"
task default: %w[rubocop rubocop:md steep spec:norails spec spec:secrets spec:autoload spec:rbs]
task default: %w[rubocop rubocop:md steep spec:norails spec spec:autoload spec:rbs]
4 changes: 2 additions & 2 deletions spec/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ def submeta=(val)
end
end

describe "#to_source_trace" do
describe "#to_source_trace", env_kot: false do
let(:conf) { CoolConfig.new }

around do |ex|
Expand Down Expand Up @@ -606,7 +606,7 @@ def submeta=(val)
end
end

describe "#pretty_print" do
describe "#pretty_print", env_kot: false do
let(:overrides) { {} }
let(:conf) { CoolConfig.new(overrides) }

Expand Down
1 change: 1 addition & 0 deletions spec/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

module Dummy
class Application < Rails::Application
config.load_defaults Rails::VERSION::STRING.split(".").take(2).join(".").to_f
config.logger = Logger.new("/dev/null")
config.eager_load = ENV["DO_NOT_INITIALIZE_RAILS"] != "1"

Expand Down
32 changes: 0 additions & 32 deletions spec/dummy/config/secrets.yml

This file was deleted.

4 changes: 0 additions & 4 deletions spec/dynamic_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
data = Anyway::Config.for(:my_app)
expect(data[:test]).to eq 1
expect(data[:name]).to eq "my_app"
unless NOSECRETS
expect(data[:secret]).to eq "my_secret"
end
expect(data[:credo]).to eq "my_credo" if Rails.application.respond_to?(:credentials)
end

Expand Down Expand Up @@ -49,7 +46,6 @@
data = Anyway::Config.for(:my_app)
expect(data[:test]).to eq 1
expect(data[:name]).to eq "my_app"
expect(data[:secret]).to eq "my_secret" unless NOSECRETS
expect(data[:credo]).to eq "my_credo" if Rails.application.respond_to?(:credentials)
expect(data[:credo_local]).to eq "betheone" if Rails.application.respond_to?(:credentials)
end
Expand Down
13 changes: 5 additions & 8 deletions spec/rails/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@

if !NORAILS
if Rails.application.respond_to?(:credentials)
it "load config from secrets and credentials" do
it "load config from credentials" do
expect(conf.user[:name]).to eq "secret man"
expect(conf.meta).to eq("kot" => "leta")
expect(conf.user[:password]).to eq "root"
end

it "sets overrides after loading secrets" do
it "sets overrides after loading" do
config = CoolConfig.new(user: {"password" => "override"})
expect(config.user[:name]).to eq "secret man"
expect(config.user[:password]).to eq "override"
Expand All @@ -43,7 +42,7 @@
end
end

context "when using local files" do
context "when using local files", env_kot: false do
around do |ex|
Anyway::Settings.use_local_files = true
ex.run
Expand All @@ -52,9 +51,7 @@

it "load config local credentials too" do
expect(conf.user[:name]).to eq "secret man"
unless NOSECRETS
expect(conf.meta).to eq("kot" => "murkot")
end
expect(conf.meta).to eq("kot" => "murkot")
expect(conf.user[:password]).to eq "password"
end
end
Expand All @@ -81,7 +78,7 @@
},
"port" => {value: 8080, source: {type: :defaults}},
"meta" => {
"kot" => {value: "leta", source: NOSECRETS ? {type: :env, key: "COOL_META__KOT"} : {type: :secrets}}
"kot" => {value: "leta", source: {type: :env, key: "COOL_META__KOT"}}
}
}
)
Expand Down
39 changes: 0 additions & 39 deletions spec/rails/loaders/secrets_spec.rb

This file was deleted.

7 changes: 3 additions & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@
config.filter_run :focus
config.run_all_when_everything_filtered = true

if NOSECRETS
config.around(:each, type: :config) do |ex|
with_env("COOL_META__KOT" => "leta", &ex)
end
config.around(:each, type: :config) do |ex|
next ex.run if ex.metadata[:env_kot] == false
with_env("COOL_META__KOT" => "leta", &ex)
end

config.order = :random
Expand Down

0 comments on commit 138212e

Please sign in to comment.