potassium 7.0.0 → 7.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +9 -1
  3. data/.node-version +1 -1
  4. data/.rubocop.yml +4 -0
  5. data/CHANGELOG.md +17 -0
  6. data/docs/CONTRIBUTING.md +6 -6
  7. data/lib/potassium/assets/.circleci/config.yml.erb +14 -14
  8. data/lib/potassium/assets/.env.development.erb +1 -0
  9. data/lib/potassium/assets/.env.test.erb +1 -0
  10. data/lib/potassium/assets/.eslintrc.json +1 -2
  11. data/lib/potassium/assets/.rubocop.yml +4 -0
  12. data/lib/potassium/assets/app/frontend/api/__mocks__/index.mock.ts +1 -1
  13. data/lib/potassium/assets/config/initializers/session_store.rb +20 -0
  14. data/lib/potassium/assets/lib/environment_variables.rb +9 -0
  15. data/lib/potassium/assets/testing/simplecov_config.rb +1 -0
  16. data/lib/potassium/assets/tsconfig.config.json +13 -3
  17. data/lib/potassium/assets/tsconfig.json +11 -5
  18. data/lib/potassium/helpers/rubocop-helpers.rb +6 -12
  19. data/lib/potassium/recipes/admin.rb +1 -0
  20. data/lib/potassium/recipes/background_processor.rb +0 -30
  21. data/lib/potassium/recipes/ci.rb +4 -0
  22. data/lib/potassium/recipes/coverage.rb +1 -1
  23. data/lib/potassium/recipes/environment_variables.rb +18 -0
  24. data/lib/potassium/recipes/front_end_vite.rb +3 -1
  25. data/lib/potassium/recipes/mailer.rb +1 -1
  26. data/lib/potassium/recipes/rails.rb +2 -0
  27. data/lib/potassium/recipes/redis.rb +57 -0
  28. data/lib/potassium/recipes/style.rb +3 -3
  29. data/lib/potassium/recipes/vue_admin.rb +11 -1
  30. data/lib/potassium/templates/application.rb +7 -5
  31. data/lib/potassium/version.rb +3 -2
  32. data/spec/features/ci_spec.rb +10 -3
  33. data/spec/features/coverage_spec.rb +0 -4
  34. data/spec/features/environment_variables_spec.rb +28 -0
  35. data/spec/features/mailer_spec.rb +1 -3
  36. data/spec/features/new_project_spec.rb +1 -7
  37. data/spec/features/node_spec.rb +1 -1
  38. data/spec/features/redis_spec.rb +43 -0
  39. data/spec/front_end_vite_spec.rb +1 -3
  40. data/spec/support/potassium_test_helpers.rb +0 -6
  41. metadata +12 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d5e76dc98fd706504cc3247552cef3ca64a0bb7d849d3e5fb22aad2fee7ec9d
4
- data.tar.gz: a5957889e338657dabad861765c2febd8c75c20a26eb2cec5603245feb265735
3
+ metadata.gz: bf8fa48bec3abe9c9a5a0b78b1bce9e5d3a16a7ae2026ca7675a46b4cd65900e
4
+ data.tar.gz: d0eb6c8fbc7d0efec8f2920ad3b94c240ec344ee8e0a5606072016193889f5e3
5
5
  SHA512:
6
- metadata.gz: 0c44956c6e4a6a85b0235f643ba73fd254a54743a2fd5ee9628849416b9718088474db66a80b4c8f1392eb370fe219ce5cee41b2d3d68baa3cbf156836f1d25b
7
- data.tar.gz: b6a540e566d9ec3119e40c0d2001564c2d59a785806d6f1c2fa384fccaabf1f6bb6b2ff5dfb603c2f684cfa72c723efffcab1f8562bde7afcd82609b46b360a0
6
+ metadata.gz: 555b3a8191c0eb1cee82b0fab20796827ee7e9a2191e61c9e462ab907ded83279e5e4a3472160db52cb43068dd5d969c07a9712767dedfafa769c436f647416f
7
+ data.tar.gz: 2e7358f4f012301fa59add914bc80692a3e135025bab6fc96c007c50f46808fcc19b33c21cca2876475f3f7ce978b0a9d0b4a01b8ac9f65113620427314c2569
data/.circleci/config.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  version: 2.1
2
2
 
3
- ruby-image: &ruby-image cimg/ruby:2.7.4-node
3
+ ruby-image: &ruby-image cimg/ruby:2.7
4
4
  env-vars: &env-vars
5
5
  BUNDLE_JOBS: 4
6
6
  RAILS_ENV: test
@@ -32,6 +32,14 @@ commands:
32
32
  gem install bundler:2.1.4
33
33
  bundle _2.1.4_ install
34
34
 
35
+ - run:
36
+ name: Install node and yarn
37
+ command: |
38
+ curl -sL https://deb.nodesource.com/setup_$(cat .node-version).x | sudo -E bash -
39
+ sudo apt-get install -y nodejs
40
+ curl -o- -sL https://yarnpkg.com/install.sh | bash
41
+ sudo ln -s $HOME/.yarn/bin/yarn /usr/local/bin/yarn
42
+
35
43
  - save_cache:
36
44
  key: potassium-vendor-bundle-{{ .Branch }}
37
45
  paths:
data/.node-version CHANGED
@@ -1 +1 @@
1
- 14
1
+ 20
data/.rubocop.yml CHANGED
@@ -528,3 +528,7 @@ RSpec/ExpectChange:
528
528
  EnforcedStyle: block
529
529
  RSpec/BeforeAfterAll:
530
530
  Enabled: false
531
+ RSpec/Focus:
532
+ AutoCorrect: false
533
+ RSpec/MultipleMemoizedHelpers:
534
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -2,6 +2,23 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 7.1.0
6
+ Features
7
+ - Add environment variables module recipe [#435](https://github.com/platanus/potassium/pull/435)
8
+ - Run [Brakeman](https://brakemanscanner.org/) with reviewdog on CI [#440](https://github.com/platanus/potassium/pull/440)
9
+ - Changes to a couple of rspec rubocop rules [#441](https://github.com/platanus/potassium/pull/441)
10
+ - Update node to 20 [#447](https://github.com/platanus/potassium/pull/447)
11
+
12
+ Fixes
13
+ - Fix CircleCI config [#434](https://github.com/platanus/potassium/pull/434)
14
+ - Fix `cannot load such file -- sassc` error [#436](https://github.com/platanus/potassium/pull/436)
15
+ - Set jsdom version for node compatibility [#436](https://github.com/platanus/potassium/pull/436)
16
+ - Fix `uninitialized constant RubocopHelpers::RuboCop` [#436](https://github.com/platanus/potassium/pull/436)
17
+ - Use Redis for sessions to address security issues [#437](https://github.com/platanus/potassium/pull/437)
18
+ - Comment vue mount in admin js to address security issues [#438](https://github.com/platanus/potassium/pull/438)
19
+ - Remove ActiveAdmin comments to address security issues [#439](https://github.com/platanus/potassium/pull/439)
20
+ - Various fixes related to TS, vite and vitest [#444](https://github.com/platanus/potassium/pull/444)
21
+
5
22
  ## 7.0.0
6
23
 
7
24
  Features
data/docs/CONTRIBUTING.md CHANGED
@@ -14,13 +14,13 @@ Now, to add some behavior, thanks to the [DSL](/docs/DSL.md) we have a kind of s
14
14
  4. Install the gems, filling the `Gemfile` before with all the gathered gems.
15
15
  5. Finally, create the database.
16
16
 
17
- The main step is the 3rd, when we call the `create` methods from the recipes. A recipe can do anything (because is a ruby script) but their responsability should be to gather gems and register callbacks for the process.
17
+ The main step is the 3rd, when we call the `create` methods from the recipes. A recipe can do anything (because is a ruby script) but their responsibility should be to gather gems and register callbacks for the process.
18
18
 
19
19
  ### Recipe
20
20
 
21
21
  The recipes are classes defined in the `Recipes` module that inherit from
22
22
  `Rails::AppBuilder` and by convention can implement some of the following
23
- methods `ask`, `create` and `install`. So they took this form.
23
+ methods `ask`, `create` and `install`. They take this form.
24
24
 
25
25
  ```ruby
26
26
  class Recipes::MyRecipe < Rails::AppBuilder
@@ -73,7 +73,7 @@ This method is used if you need to ask something to the user before doing someth
73
73
 
74
74
  We'll call this method to add specific functionality to the rails project.
75
75
 
76
- 1. In the `create` method register a gem using `gather_gem` and create a callback to be called after the `gem_install` action succeded to run the generator. `gem_install` is one of the main actions that should be easily visible with a sneak peek in [the template][the-template].
76
+ 1. In the `create` method register a gem using `gather_gem` and create a callback to be called after the `gem_install` action succeeds to run the generator. `gem_install` is one of the main actions that should be easily visible with a sneak peek in [the template][the-template].
77
77
 
78
78
  ```ruby
79
79
  def create
@@ -99,8 +99,8 @@ We'll call this method to add specific functionality to the rails project.
99
99
  ##### | `install`
100
100
 
101
101
  The install method will be called when you use the `install` command from potassium.
102
- For example if you run `portassium install devise` this will use
103
- [the recipe template](/lib/potassium/templates/recipe.rb) to load an execute the
102
+ For example, if you run `potassium install devise` this will use
103
+ [the recipe template](/lib/potassium/templates/recipe.rb) to load and execute the
104
104
  `install` method for the **devise** recipe.
105
105
 
106
106
  You can define the main functionallity of a recipe in a private method and call
@@ -127,6 +127,6 @@ end
127
127
 
128
128
  To see further documentation of what we added to the rails template's DSL, check the [DSL documentation](/docs/DSL.md).
129
129
 
130
- > Remember that the DSL we are documenting is an extension over the [Rails Application Template DSL](http://edgeguides.rubyonrails.org/rails_application_templates.html), that itself is a dsl based on [Thor](https://github.com/erikhuda/thor/wiki).
130
+ > Remember that the DSL we are documenting is an extension over the [Rails Application Template DSL](http://edgeguides.rubyonrails.org/rails_application_templates.html), that itself is a DSL based on [Thor](https://github.com/erikhuda/thor/wiki).
131
131
 
132
132
  [the-template]: /lib/potassium/templates/application.rb
@@ -4,9 +4,7 @@ ruby-image: &ruby-image cimg/ruby:<%= ruby_version %>
4
4
  <%- if selected?(:database, :postgresql) -%>
5
5
  postgres-image: &postgres-image postgres:<%= Potassium::POSTGRES_VERSION %>
6
6
  <%- end -%>
7
- <%- if selected?(:background_processor) -%>
8
- redis-image: &redis-image redis
9
- <%- end -%>
7
+ redis-image: &redis-image cimg/redis:6.2.12
10
8
  env-vars: &env-vars
11
9
  BUNDLE_JOBS: 4
12
10
  BUNDLE_PATH: vendor/bundle
@@ -23,9 +21,7 @@ executors:
23
21
  <%- if selected?(:database, :postgresql) -%>
24
22
  - image: *postgres-image
25
23
  <%- end -%>
26
- <%- if selected?(:background_processor) -%>
27
24
  - image: *redis-image
28
- <%- end -%>
29
25
 
30
26
  lint-executor:
31
27
  docker:
@@ -94,11 +90,10 @@ jobs:
94
90
  - browser-tools/install-chrome
95
91
  - browser-tools/install-chromedriver
96
92
 
97
- <%- if selected?(:background_processor) -%>
98
93
  - run:
99
94
  name: Wait for redis service
100
95
  command: dockerize -wait tcp://localhost:6379 -timeout 1m
101
- <%- end -%>
96
+
102
97
  <%- if selected?(:database, :postgresql) -%>
103
98
  - run:
104
99
  name: Wait for postgres service
@@ -122,7 +117,7 @@ jobs:
122
117
 
123
118
  - run:
124
119
  name: POST extracted data to nest
125
- command: bin/rake "repo_analyzer:analyze[platanus/<%= get(:app_name) %>]"
120
+ command: bin/rake "repo_analyzer:analyze[platanus/<%= get(:github_repo_name) || get(:dasherized_app_name) %>]"
126
121
 
127
122
  - run:
128
123
  name: Run simplecov
@@ -137,12 +132,10 @@ jobs:
137
132
  RSPEC_FORMAT_ARGS="--tag type:system -f progress --no-color -p 10"
138
133
  bundle exec rspec spec $RSPEC_FORMAT_ARGS $RSPEC_JUNIT_ARGS
139
134
 
140
- - run:
141
- name: Run vitest
142
- command: |
143
- yarn run test > coverage/input_vitest.txt
144
- ./node_modules/.bin/format-coverage coverage/input_vitest.txt coverage/output_vitest.txt /home/circleci/project/app/frontend
145
- cat coverage/output_vitest.txt | ./bin/reviewdog -reporter=github-pr-review -efm="%f:%l:%c: %m"
135
+ - run:
136
+ name: Run vitest
137
+ command: |
138
+ yarn run test
146
139
 
147
140
  - store_test_results:
148
141
  path: test_results
@@ -152,6 +145,13 @@ jobs:
152
145
  steps:
153
146
  - setup
154
147
 
148
+ - run:
149
+ name: Run brakeman
150
+ shell: /bin/bash
151
+ command: |
152
+ bundle exec brakeman --quiet --format tabs --no-exit-on-warn --no-exit-on-error --output "tmp/brakeman_report"; \
153
+ ./bin/reviewdog < "tmp/brakeman_report" -reporter=github-pr-review -f=brakeman -name="Brakeman"
154
+
155
155
  - run:
156
156
  name: Get files to lint
157
157
  command: git diff origin/master --name-only --diff-filter=d > tmp/files_to_lint
@@ -5,3 +5,4 @@ DEFAULT_EMAIL_ADDRESS=
5
5
  EXECJS_RUNTIME=Node
6
6
  SECRET_KEY_BASE=development_secret
7
7
  WEB_CONCURRENCY=1
8
+ APPLICATION_HOST=localhost:3000
@@ -0,0 +1 @@
1
+ APPLICATION_HOST=localhost:3000
@@ -3,14 +3,13 @@
3
3
  "browser": true,
4
4
  "es2021": true,
5
5
  "node": true,
6
- "jest/globals": true,
7
6
  "vue/setup-compiler-macros": true
8
7
  },
9
8
  "parserOptions": {
10
9
  "ecmaVersion": 2020,
11
10
  "sourceType": "module"
12
11
  },
13
- "plugins": ["import", "jest", "tailwindcss"],
12
+ "plugins": ["import", "tailwindcss"],
14
13
  "settings": {
15
14
  "import/resolver": {
16
15
  "node": {
@@ -588,3 +588,7 @@ RSpec/LetSetup:
588
588
  RSpec/ExpectChange:
589
589
  Enabled: true
590
590
  EnforcedStyle: block
591
+ RSpec/Focus:
592
+ AutoCorrect: false
593
+ RSpec/MultipleMemoizedHelpers:
594
+ Enabled: false
@@ -1,3 +1,3 @@
1
- const api = jest.fn();
1
+ const api = vi.fn();
2
2
 
3
3
  export { api };
@@ -0,0 +1,20 @@
1
+ # https://github.com/redis-store/redis-store/issues/358#issuecomment-1537920008
2
+ class RedisClient::Config
3
+ alias original_initialize initialize
4
+
5
+ def initialize(**kwargs)
6
+ # remove not supported kwargs
7
+ original_initialize(
8
+ **kwargs.except(:raw, :serializer, :marshalling, :namespace, :scheme)
9
+ )
10
+ end
11
+ end
12
+
13
+ Rails.application.config.session_store :redis_store, {
14
+ servers: [{
15
+ url: ENV['REDIS_URL']
16
+ }],
17
+ expire_after: 30.days,
18
+ key: '_app_session',
19
+ secure: Rails.env.production?
20
+ }
@@ -0,0 +1,9 @@
1
+ module EnvironmentVariables
2
+ extend self
3
+
4
+ APPLICATION_HOST = ENV.fetch('APPLICATION_HOST')
5
+
6
+ def application_host
7
+ APPLICATION_HOST
8
+ end
9
+ end
@@ -49,6 +49,7 @@ SimpleCov.start 'rails' do
49
49
  add_filter 'app/responders'
50
50
  add_filter 'lib/fake_data_loader.rb'
51
51
  add_filter 'lib/vue_component.rb'
52
+ add_filter 'lib/environment_variables.rb'
52
53
 
53
54
  if ENV["CIRCLECI"]
54
55
  formatter(
@@ -1,8 +1,18 @@
1
1
  {
2
- "extends": "@vue/tsconfig/tsconfig.node.json",
3
- "include": ["vite.config.*", "vitest.config.*", "cypress.config.*", "playwright.config.*"],
2
+ "extends": [
3
+ "@tsconfig/node14/tsconfig.json",
4
+ "@vue/tsconfig/tsconfig.json"
5
+ ],
6
+ "include": [
7
+ "vite.config.*",
8
+ "vitest.config.*",
9
+ "cypress.config.*",
10
+ "playwright.config.*"
11
+ ],
4
12
  "compilerOptions": {
5
13
  "composite": true,
6
- "types": ["node"]
14
+ "types": [
15
+ "node"
16
+ ]
7
17
  }
8
18
  }
@@ -1,13 +1,19 @@
1
1
  {
2
- "extends": "@vue/tsconfig/tsconfig.web.json",
3
- "include": ["env.d.ts", "app/**/*", "app/**/*.vue"],
2
+ "extends": "@vue/tsconfig/tsconfig.dom.json",
3
+ "include": [
4
+ "env.d.ts",
5
+ "app/**/*",
6
+ "app/**/*.vue"
7
+ ],
4
8
  "compilerOptions": {
5
9
  "baseUrl": ".",
6
10
  "paths": {
7
- "@/*": ["./app/frontend/*"]
8
- }
11
+ "@/*": [
12
+ "./app/frontend/*"
13
+ ]
14
+ },
15
+ "types": ["vitest/globals", "vite/client"]
9
16
  },
10
-
11
17
  "references": [
12
18
  {
13
19
  "path": "./tsconfig.config.json"
@@ -1,15 +1,9 @@
1
- module RubocopHelpers
2
- def rubocop_revision
3
- fix_environments
4
- end
1
+ require "rubocop"
5
2
 
6
- private
7
-
8
- def fix_environments
9
- # Style problem in Rails 5 production environments
10
- file_name = "config/environments/production.rb"
11
- production = File.read(file_name)
12
- production.gsub!("config.log_tags = [ :request_id ]", "config.log_tags = [:request_id]")
13
- File.open(file_name, "w") { |file| file.write(production) }
3
+ module RubocopHelpers
4
+ def run_rubocop
5
+ options, paths = RuboCop::Options.new.parse(["-A"])
6
+ runner = RuboCop::Runner.new(options, RuboCop::ConfigStore.new)
7
+ runner.run(paths)
14
8
  end
15
9
  end
@@ -52,6 +52,7 @@ class Recipes::Admin < Rails::AppBuilder
52
52
  meta_tags_options = { viewport: 'width=device-width, initial-scale=1' }
53
53
  config.meta_tags = meta_tags_options
54
54
  config.meta_tags_for_logged_out_pages = meta_tags_options
55
+ config.comments = false
55
56
  HERE
56
57
  end
57
58
 
@@ -14,8 +14,6 @@ class Recipes::BackgroundProcessor < Rails::AppBuilder
14
14
  def create
15
15
  if get(:background_processor)
16
16
  add_sidekiq
17
- add_docker_compose_redis_config
18
- set_redis_dot_env
19
17
  end
20
18
  end
21
19
 
@@ -40,7 +38,6 @@ class Recipes::BackgroundProcessor < Rails::AppBuilder
40
38
  append_to_file(".env.development", "DB_POOL=25\n")
41
39
  template("../assets/sidekiq.rb.erb", "config/initializers/sidekiq.rb", force: true)
42
40
  copy_file("../assets/sidekiq.yml", "config/sidekiq.yml", force: true)
43
- copy_file("../assets/redis.yml", "config/redis.yml", force: true)
44
41
  recipe.mount_sidekiq_routes
45
42
  end
46
43
  end
@@ -68,33 +65,6 @@ class Recipes::BackgroundProcessor < Rails::AppBuilder
68
65
 
69
66
  private
70
67
 
71
- def add_docker_compose_redis_config
72
- compose = DockerHelpers.new('docker-compose.yml')
73
-
74
- service_definition =
75
- <<~YAML
76
- image: redis
77
- ports:
78
- - 6379
79
- volumes:
80
- - redis_data:/data
81
- YAML
82
-
83
- compose.add_service('redis', service_definition)
84
- compose.add_volume('redis_data')
85
- end
86
-
87
- def set_redis_dot_env
88
- append_to_file(
89
- '.env.development',
90
- <<~TEXT
91
- REDIS_HOST=127.0.0.1
92
- REDIS_PORT=COMMAND_EXPAND(make services-port SERVICE=redis PORT=6379)
93
- REDIS_URL=redis://${REDIS_HOST}:${REDIS_PORT}/1
94
- TEXT
95
- )
96
- end
97
-
98
68
  def enabled_mailer?
99
69
  mailer_answer = get(:email_service)
100
70
  mailer_answer && ![:none, :None].include?(mailer_answer.to_sym)
@@ -7,6 +7,10 @@ class Recipes::Ci < Rails::AppBuilder
7
7
  gather_gem 'rspec_junit_formatter', '~> 0.4'
8
8
  end
9
9
 
10
+ gather_gems(:development, :test) do
11
+ gather_gem('brakeman')
12
+ end
13
+
10
14
  add_readme_header :ci
11
15
  application 'config.assets.js_compressor = :uglifier', env: 'test'
12
16
  end
@@ -18,7 +18,7 @@ class Recipes::Coverage < Rails::AppBuilder
18
18
  end
19
19
 
20
20
  def setup_coverage_dependencies
21
- run "yarn add jest-text-formatter@1.0.2 c8 --dev"
21
+ run "yarn add c8 --dev"
22
22
  end
23
23
 
24
24
  private
@@ -0,0 +1,18 @@
1
+ class Recipes::EnvironmentVariables < Rails::AppBuilder
2
+ def create
3
+ template '../assets/.env.test.erb', '.env.test'
4
+ copy_file '../assets/lib/environment_variables.rb', 'lib/environment_variables.rb'
5
+
6
+ application(before_configuration_require)
7
+ end
8
+
9
+ private
10
+
11
+ def before_configuration_require
12
+ <<~RUBY
13
+ config.before_configuration do
14
+ require Rails.root.join('lib/environment_variables.rb')
15
+ end
16
+ RUBY
17
+ end
18
+ end
@@ -4,6 +4,7 @@ class Recipes::FrontEndVite < Rails::AppBuilder
4
4
  TAILWINDCSS_VERSION = Potassium::TAILWINDCSS_VERSION
5
5
  AUTOPREFIXER_VERSION = Potassium::AUTOPREFIXER_VERSION
6
6
  VUE_TEST_UTILS_VERSION = Potassium::VUE_TEST_UTILS_VERSION
7
+ JSDOM_VERSION = Potassium::JSDOM_VERSION
7
8
 
8
9
  DEPENDENCIES = {
9
10
  tailwind: [
@@ -22,6 +23,7 @@ class Recipes::FrontEndVite < Rails::AppBuilder
22
23
  "vue@#{VUE_VERSION}"
23
24
  ],
24
25
  vue_dev: [
26
+ "@tsconfig/node14",
25
27
  "@vitejs/plugin-vue",
26
28
  "@vue/tsconfig",
27
29
  "vue-tsc"
@@ -29,7 +31,7 @@ class Recipes::FrontEndVite < Rails::AppBuilder
29
31
  vitest_dev: [
30
32
  "vitest",
31
33
  "@vue/test-utils@#{VUE_TEST_UTILS_VERSION}",
32
- "jsdom"
34
+ "jsdom@#{JSDOM_VERSION}"
33
35
  ],
34
36
  api: [
35
37
  "axios",
@@ -74,7 +74,7 @@ class Recipes::Mailer < Rails::AppBuilder
74
74
  RUBY
75
75
  application asset_host_prod, env: "production"
76
76
  mailer_config = <<~RUBY
77
- require Rails.root.join("config", "mailer")
77
+ require Rails.root.join("config/mailer")
78
78
  RUBY
79
79
 
80
80
  prepend_file "config/environments/production.rb", mailer_config
@@ -1,6 +1,8 @@
1
1
  class Recipes::Rails < Rails::AppBuilder
2
2
  def create
3
3
  gather_gem("bootsnap", require: false)
4
+ gather_gem("sassc", github: "sass/sassc-ruby", ref: 'refs/pull/233/head')
5
+ gather_gem("sassc-embedded")
4
6
  environment 'config.force_ssl = true', env: 'production'
5
7
  disable_automatic_nonce_generation
6
8
  end
@@ -0,0 +1,57 @@
1
+ class Recipes::Redis < Rails::AppBuilder
2
+ def create
3
+ add_redis
4
+ add_docker_compose_redis_config
5
+ set_redis_dot_env
6
+ add_session_store_config
7
+ end
8
+
9
+ def install
10
+ create
11
+ end
12
+
13
+ def installed?
14
+ gem_exists?(/redis-actionpack/)
15
+ end
16
+
17
+ def add_redis
18
+ run_action(:install_redis) do
19
+ gather_gem("redis-actionpack")
20
+ copy_file("../assets/redis.yml", "config/redis.yml", force: true)
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def add_docker_compose_redis_config
27
+ compose = DockerHelpers.new('docker-compose.yml')
28
+
29
+ service_definition =
30
+ <<~YAML
31
+ image: redis:6.2.12
32
+ ports:
33
+ - 6379
34
+ volumes:
35
+ - redis_data:/data
36
+ YAML
37
+
38
+ compose.add_service('redis', service_definition)
39
+ compose.add_volume('redis_data')
40
+ end
41
+
42
+ def set_redis_dot_env
43
+ append_to_file(
44
+ '.env.development',
45
+ <<~TEXT
46
+ REDIS_HOST=127.0.0.1
47
+ REDIS_PORT=COMMAND_EXPAND(make services-port SERVICE=redis PORT=6379)
48
+ REDIS_URL=redis://${REDIS_HOST}:${REDIS_PORT}/1
49
+ TEXT
50
+ )
51
+ end
52
+
53
+ def add_session_store_config
54
+ copy_file("../assets/config/initializers/session_store.rb",
55
+ "config/initializers/session_store.rb", force: true)
56
+ end
57
+ end
@@ -22,9 +22,9 @@ class Recipes::Style < Rails::AppBuilder
22
22
 
23
23
  after(:vite_install) do
24
24
  run "yarn add --dev stylelint eslint eslint-plugin-import "\
25
- "@typescript-eslint/eslint-plugin @types/jest @typescript-eslint/parser "\
26
- "eslint-plugin-jest eslint-plugin-platanus eslint-plugin-vue "\
27
- "@vue/eslint-config-typescript eslint-plugin-tailwindcss"
25
+ "@typescript-eslint/eslint-plugin @typescript-eslint/parser "\
26
+ "eslint-plugin-platanus eslint-plugin-vue @vue/eslint-config-typescript "\
27
+ "eslint-plugin-tailwindcss"
28
28
  end
29
29
  end
30
30
 
@@ -136,7 +136,17 @@ class Recipes::VueAdmin < Rails::AppBuilder
136
136
  },
137
137
  });
138
138
  app.component('admin_component', AdminComponent);
139
- app.mount('#wrapper');
139
+
140
+ // Avoid using '#wrapper' as the mount point, as that includes the entire admin page,
141
+ // which could be used for Client-Side Template Injection (CSTI) attacks. Limit the
142
+ // mount point to specific areas where you need Vue components.
143
+
144
+ // DO NOT mount Vue in elements that contain user input rendered by
145
+ // ActiveAdmin.
146
+ // By default ActiveAdmin doesn't escape {{ }} in user input, so it's
147
+ // possible to inject arbitrary JavaScript code into the page.
148
+
149
+ // app.mount('#wrapper');
140
150
  }
141
151
 
142
152
  return null;
@@ -4,10 +4,6 @@ set :titleized_app_name, get(:app_name).titleize
4
4
  set :underscorized_app_name, get(:app_name).underscore
5
5
  set :dasherized_app_name, get(:app_name).dasherize
6
6
 
7
- run_action(:after_create_rails) do
8
- rubocop_revision
9
- end
10
-
11
7
  run_action(:cleaning) do
12
8
  clean_gemfile
13
9
  end
@@ -36,7 +32,6 @@ run_action(:recipe_loading) do
36
32
  create :spring
37
33
  create :readme
38
34
  create :heroku
39
- create :ci
40
35
  create :style
41
36
  create :puma
42
37
  create :env
@@ -50,6 +45,7 @@ run_action(:recipe_loading) do
50
45
  create :yarn
51
46
  create :editorconfig
52
47
  create :mailer
48
+ create :redis
53
49
  create :background_processor
54
50
  create :schedule
55
51
  create :i18n
@@ -71,6 +67,7 @@ run_action(:recipe_loading) do
71
67
  create :tzinfo
72
68
  create :script
73
69
  create :github
70
+ create :ci
74
71
  create :cleanup
75
72
  create :google_tag_manager
76
73
  create :mjml
@@ -78,6 +75,7 @@ run_action(:recipe_loading) do
78
75
  create :front_end_vite
79
76
  create :admin
80
77
  create :vue_admin
78
+ create :environment_variables
81
79
  end
82
80
 
83
81
  info "Gathered enough information. Applying the template. Wait a minute."
@@ -91,3 +89,7 @@ run_action(:database_creation) do
91
89
  run "bundle exec rails db:create db:migrate"
92
90
  run "RACK_ENV=test bundle exec rails db:create db:migrate"
93
91
  end
92
+
93
+ run_action(:rubocop_revision) do
94
+ run_rubocop
95
+ end
@@ -1,12 +1,12 @@
1
1
  module Potassium
2
- VERSION = "7.0.0"
2
+ VERSION = "7.1.0"
3
3
  RUBY_VERSION = "2.7.0"
4
4
  RAILS_VERSION = "~> 7.0.4.2"
5
5
  RUBOCOP_VERSION = "~> 1.9"
6
6
  RUBOCOP_RSPEC_VERSION = "~> 2.2"
7
7
  POSTGRES_VERSION = "11.3"
8
8
  MYSQL_VERSION = "5.7"
9
- NODE_VERSION = "14"
9
+ NODE_VERSION = "20"
10
10
  TAILWINDCSS_VERSION = "^3.2.7"
11
11
  POSTCSS_VERSION = "^8.4.21"
12
12
  AUTOPREFIXER_VERSION = "^10.4.13"
@@ -14,4 +14,5 @@ module Potassium
14
14
  VUE_LOADER_VERSION = "^16.8.3"
15
15
  VUE_TEST_UTILS_VERSION = "^2.0.2"
16
16
  JEST_VERSION = "^29.0.0"
17
+ JSDOM_VERSION = "^21.1.2"
17
18
  end
@@ -13,11 +13,18 @@ RSpec.describe 'CI' do
13
13
  create_dummy_project
14
14
  end
15
15
 
16
+ it "adds brakeman to Gemfile" do
17
+ content = IO.read("#{project_path}/Gemfile")
18
+ expect(content).to include("brakeman")
19
+ end
20
+
16
21
  it "correctly bundles the config file" do
17
- expect(ci_config).to include('cimg/ruby', 'cache', 'rspec', 'reviewdog')
22
+ expect(ci_config).to include('cimg/ruby', 'cache', 'rspec', 'reviewdog', 'brakeman')
18
23
  end
19
24
 
20
- it "adds repo analyzer config" do
21
- expect(ci_config).to include('bin/rake "repo_analyzer:analyze[platanus/dummy_app]"')
25
+ it "uses dasherized app name for repo analyzer" do
26
+ expect(ci_config).to include(
27
+ "repo_analyzer:analyze[platanus/#{PotassiumTestHelpers::APP_NAME.dasherize}]"
28
+ )
22
29
  end
23
30
  end
@@ -36,9 +36,5 @@ RSpec.describe "Coverage" do
36
36
  it "adds vitest coverage configuration" do
37
37
  expect(vite_config).to include("provider: 'c8',")
38
38
  end
39
-
40
- it "adds jest text formatter package" do
41
- expect(node_modules_file).to include('jest-text-formatter')
42
- end
43
39
  end
44
40
  end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'EnvironmentVariables' do
4
+ let(:environment_variables) { IO.read("#{project_path}/lib/environment_variables.rb") }
5
+
6
+ before :all do
7
+ drop_dummy_database
8
+ remove_project_directory
9
+ create_dummy_project
10
+ end
11
+
12
+ it 'creates a .env.test file' do
13
+ expect(File.exists?("#{project_path}/.env.test")).to eq(true)
14
+ end
15
+
16
+ it 'creates an EnvironmentVariables module with a constant and its method' do
17
+ expect(environment_variables).to include(
18
+ 'module EnvironmentVariables',
19
+ "APPLICATION_HOST = ENV.fetch('APPLICATION_HOST')",
20
+ 'def application_host'
21
+ )
22
+ end
23
+
24
+ it 'requires module in application configuration' do
25
+ expect(File.read("#{project_path}/config/application.rb"))
26
+ .to include("require Rails.root.join('lib/environment_variables.rb')")
27
+ end
28
+ end
@@ -1,4 +1,3 @@
1
- # rubocop:disable Rspec/MultipleMemoizedHelpers
2
1
  require "spec_helper"
3
2
 
4
3
  RSpec.describe "Mailer" do
@@ -18,7 +17,7 @@ RSpec.describe "Mailer" do
18
17
  end
19
18
  let(:mailer_config_text) do
20
19
  <<~RUBY
21
- require Rails.root.join("config", "mailer")
20
+ require Rails.root.join("config/mailer")
22
21
  RUBY
23
22
  end
24
23
 
@@ -102,4 +101,3 @@ RSpec.describe "Mailer" do
102
101
  end
103
102
  end
104
103
  end
105
- # rubocop:enable Rspec/MultipleMemoizedHelpers
@@ -9,15 +9,9 @@ RSpec.describe "A new project" do
9
9
  end
10
10
 
11
11
  it "is correctly bundled" do
12
- expect { on_project { `bundle exec rails -v` } }.to_not output.to_stderr
12
+ expect { on_project { `bundle exec rails -v` } }.not_to output.to_stderr
13
13
  end
14
14
 
15
- # it "is a valid rubocop project" do
16
- # on_project do
17
- # expect(run_rubocop).to eq(true)
18
- # end
19
- # end
20
-
21
15
  it "configures postgresql" do
22
16
  database_config_file = IO.read("#{project_path}/config/database.yml")
23
17
  gemfile = IO.read("#{project_path}/Gemfile")
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  RSpec.describe "Node" do
4
- let(:version) { "14" }
4
+ let(:version) { Potassium::NODE_VERSION }
5
5
 
6
6
  before(:all) do
7
7
  drop_dummy_database
@@ -0,0 +1,43 @@
1
+ require "spec_helper"
2
+ require 'yaml'
3
+
4
+ RSpec.describe "RedisProcessor" do
5
+ before :all do
6
+ drop_dummy_database
7
+ remove_project_directory
8
+ create_dummy_project("heroku" => true)
9
+ end
10
+
11
+ context "when installed" do
12
+ it "adds redis-actionpack gem to Gemfile" do
13
+ gemfile_content = IO.read("#{project_path}/Gemfile")
14
+ expect(gemfile_content).to include("redis-actionpack")
15
+ end
16
+
17
+ it "adds ENV vars" do
18
+ content = IO.read("#{project_path}/.env.development")
19
+ expect(content).to include('REDIS_HOST=127.0.0.1')
20
+ expect(content).to include(
21
+ 'REDIS_PORT=COMMAND_EXPAND(make services-port SERVICE=redis PORT=6379)'
22
+ )
23
+ expect(content).to include('REDIS_URL=redis://${REDIS_HOST}:${REDIS_PORT}/1')
24
+ end
25
+
26
+ it "adds redis.yml file" do
27
+ content = IO.read("#{project_path}/config/redis.yml")
28
+ expect(content).to include("REDIS_URL")
29
+ end
30
+
31
+ it 'adds redis to docker-compose' do
32
+ compose_file = IO.read("#{project_path}/docker-compose.yml")
33
+ compose_content = YAML.safe_load(compose_file, symbolize_names: true)
34
+
35
+ expect(compose_content[:services]).to include(:redis)
36
+ end
37
+
38
+ it 'copies session store config' do
39
+ content = IO.read("#{project_path}/config/initializers/session_store.rb")
40
+ expect(content).to include("RedisClient::Config")
41
+ end
42
+ end
43
+ end
@@ -1,4 +1,3 @@
1
- # rubocop:disable RSpec/MultipleMemoizedHelpers
2
1
  require 'spec_helper'
3
2
 
4
3
  RSpec.describe 'Front end' do
@@ -70,7 +69,7 @@ RSpec.describe 'Front end' do
70
69
  end
71
70
 
72
71
  it 'includes mock example' do
73
- expect(mock_example_file).to include('jest.fn()')
72
+ expect(mock_example_file).to include('vi.fn()')
74
73
  end
75
74
 
76
75
  it 'includes the dotenv monkeypatch' do
@@ -78,4 +77,3 @@ RSpec.describe 'Front end' do
78
77
  expect(File.exists?(File.join(project_path, 'lib/dotenv_monkeypatch.rb'))).to be(true)
79
78
  end
80
79
  end
81
- # rubocop:enable RSpec/MultipleMemoizedHelpers
@@ -97,10 +97,4 @@ module PotassiumTestHelpers
97
97
  def run_command(command)
98
98
  system(command)
99
99
  end
100
-
101
- def run_rubocop
102
- options, paths = RuboCop::Options.new.parse(["."])
103
- runner = RuboCop::Runner.new(options, RuboCop::ConfigStore.new)
104
- runner.run(paths)
105
- end
106
100
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: potassium
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0
4
+ version: 7.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - juliogarciag
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-24 00:00:00.000000000 Z
11
+ date: 2023-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -266,6 +266,7 @@ files:
266
266
  - lib/potassium/assets/.dockerignore
267
267
  - lib/potassium/assets/.editorconfig
268
268
  - lib/potassium/assets/.env.development.erb
269
+ - lib/potassium/assets/.env.test.erb
269
270
  - lib/potassium/assets/.eslintrc.json
270
271
  - lib/potassium/assets/.github/pull_request_template.md
271
272
  - lib/potassium/assets/.pryrc
@@ -311,6 +312,7 @@ files:
311
312
  - lib/potassium/assets/bin/update.erb
312
313
  - lib/potassium/assets/config/database_mysql.yml.erb
313
314
  - lib/potassium/assets/config/database_postgresql.yml.erb
315
+ - lib/potassium/assets/config/initializers/session_store.rb
314
316
  - lib/potassium/assets/config/initializers/shrine/plugins/image_handling_utilities.rb
315
317
  - lib/potassium/assets/config/mailer.rb.erb
316
318
  - lib/potassium/assets/config/puma.rb
@@ -321,6 +323,7 @@ files:
321
323
  - lib/potassium/assets/docker-compose.yml
322
324
  - lib/potassium/assets/es-CL.yml
323
325
  - lib/potassium/assets/lib/dotenv_monkeypatch.rb
326
+ - lib/potassium/assets/lib/environment_variables.rb
324
327
  - lib/potassium/assets/lib/tasks/auto_annotate_models.rake
325
328
  - lib/potassium/assets/package.json
326
329
  - lib/potassium/assets/public/mails/platanus-logo.png
@@ -382,6 +385,7 @@ files:
382
385
  - lib/potassium/recipes/draper.rb
383
386
  - lib/potassium/recipes/editorconfig.rb
384
387
  - lib/potassium/recipes/env.rb
388
+ - lib/potassium/recipes/environment_variables.rb
385
389
  - lib/potassium/recipes/error_reporting.rb
386
390
  - lib/potassium/recipes/file_storage.rb
387
391
  - lib/potassium/recipes/front_end_vite.rb
@@ -401,6 +405,7 @@ files:
401
405
  - lib/potassium/recipes/rack_cors.rb
402
406
  - lib/potassium/recipes/rails.rb
403
407
  - lib/potassium/recipes/readme.rb
408
+ - lib/potassium/recipes/redis.rb
404
409
  - lib/potassium/recipes/ruby.rb
405
410
  - lib/potassium/recipes/schedule.rb
406
411
  - lib/potassium/recipes/script.rb
@@ -430,6 +435,7 @@ files:
430
435
  - spec/features/database_container_spec.rb
431
436
  - spec/features/database_spec.rb
432
437
  - spec/features/draper_spec.rb
438
+ - spec/features/environment_variables_spec.rb
433
439
  - spec/features/error_reporting_spec.rb
434
440
  - spec/features/file_storage_spec.rb
435
441
  - spec/features/github_spec.rb
@@ -442,6 +448,7 @@ files:
442
448
  - spec/features/node_spec.rb
443
449
  - spec/features/power_types_spec.rb
444
450
  - spec/features/pundit_spec.rb
451
+ - spec/features/redis_spec.rb
445
452
  - spec/features/schedule_spec.rb
446
453
  - spec/features/testing_spec.rb
447
454
  - spec/features/vue_admin_spec.rb
@@ -472,7 +479,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
472
479
  - !ruby/object:Gem::Version
473
480
  version: '0'
474
481
  requirements: []
475
- rubygems_version: 3.2.22
482
+ rubygems_version: 3.4.10
476
483
  signing_key:
477
484
  specification_version: 4
478
485
  summary: An application generator from Platanus
@@ -488,6 +495,7 @@ test_files:
488
495
  - spec/features/database_container_spec.rb
489
496
  - spec/features/database_spec.rb
490
497
  - spec/features/draper_spec.rb
498
+ - spec/features/environment_variables_spec.rb
491
499
  - spec/features/error_reporting_spec.rb
492
500
  - spec/features/file_storage_spec.rb
493
501
  - spec/features/github_spec.rb
@@ -500,6 +508,7 @@ test_files:
500
508
  - spec/features/node_spec.rb
501
509
  - spec/features/power_types_spec.rb
502
510
  - spec/features/pundit_spec.rb
511
+ - spec/features/redis_spec.rb
503
512
  - spec/features/schedule_spec.rb
504
513
  - spec/features/testing_spec.rb
505
514
  - spec/features/vue_admin_spec.rb