roda-gen 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +9 -0
- data/LICENSE.txt +21 -0
- data/README.md +94 -0
- data/bin/roda +11 -0
- data/lib/roda-gen.rb +3 -0
- data/lib/roda_gen/app_name.rb +29 -0
- data/lib/roda_gen/cli.rb +122 -0
- data/lib/roda_gen/generators/daemon.rb +78 -0
- data/lib/roda_gen/generators/migration.rb +68 -0
- data/lib/roda_gen/generators/migration_numbering.rb +21 -0
- data/lib/roda_gen/generators/model.rb +75 -0
- data/lib/roda_gen/generators/project.rb +145 -0
- data/lib/roda_gen/generators/route.rb +71 -0
- data/lib/roda_gen/generators/templates/daemon/bin/%daemon_name%.tt +13 -0
- data/lib/roda_gen/generators/templates/daemon/lib/daemon/%daemon_name%.rb.tt +22 -0
- data/lib/roda_gen/generators/templates/daemon/spec/daemons/%daemon_name%_spec.rb.tt +18 -0
- data/lib/roda_gen/generators/templates/migration/db/migrate/%migration_filename%.rb.tt +6 -0
- data/lib/roda_gen/generators/templates/model/db/migrate/%migration_filename%.rb.tt +12 -0
- data/lib/roda_gen/generators/templates/model/models/%resource_name%.rb.tt +5 -0
- data/lib/roda_gen/generators/templates/model/spec/models/%resource_name%_spec.rb.tt +18 -0
- data/lib/roda_gen/generators/templates/project/%app_name%.rb.tt +43 -0
- data/lib/roda_gen/generators/templates/project/.bundle/config.tt +3 -0
- data/lib/roda_gen/generators/templates/project/.erb_lint.yml.tt +29 -0
- data/lib/roda_gen/generators/templates/project/.gitignore.tt +19 -0
- data/lib/roda_gen/generators/templates/project/.reek.yml.tt +45 -0
- data/lib/roda_gen/generators/templates/project/.rspec.tt +4 -0
- data/lib/roda_gen/generators/templates/project/.rubocop.yml.tt +119 -0
- data/lib/roda_gen/generators/templates/project/.ruby-version.tt +1 -0
- data/lib/roda_gen/generators/templates/project/.rubycritic.yml.tt +15 -0
- data/lib/roda_gen/generators/templates/project/Gemfile.tt +109 -0
- data/lib/roda_gen/generators/templates/project/Procfile.dev.tt +7 -0
- data/lib/roda_gen/generators/templates/project/README.md.tt +891 -0
- data/lib/roda_gen/generators/templates/project/Rakefile.tt +3 -0
- data/lib/roda_gen/generators/templates/project/assets/javascripts/admin.js.tt +84 -0
- data/lib/roda_gen/generators/templates/project/assets/javascripts/app.js.tt +29 -0
- data/lib/roda_gen/generators/templates/project/assets/javascripts/push.js.tt +53 -0
- data/lib/roda_gen/generators/templates/project/assets/javascripts/upload.js.tt +200 -0
- data/lib/roda_gen/generators/templates/project/assets/stylesheets/app.css.tt +52 -0
- data/lib/roda_gen/generators/templates/project/assets/stylesheets/typography.css.tt +85 -0
- data/lib/roda_gen/generators/templates/project/bin/console.tt +2 -0
- data/lib/roda_gen/generators/templates/project/bin/dev.tt +8 -0
- data/lib/roda_gen/generators/templates/project/bin/gdpr_worker.tt +13 -0
- data/lib/roda_gen/generators/templates/project/bin/push_sender.tt +13 -0
- data/lib/roda_gen/generators/templates/project/bin/setup.tt +224 -0
- data/lib/roda_gen/generators/templates/project/bin/shrine_clean_cache.tt +13 -0
- data/lib/roda_gen/generators/templates/project/config/boot.rb.tt +23 -0
- data/lib/roda_gen/generators/templates/project/config/console.rb.tt +20 -0
- data/lib/roda_gen/generators/templates/project/config/database.rb.tt +45 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/00_environments.rb.tt +5 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/01_logger.rb.tt +46 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/02_app_config.rb.tt +19 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/10_database.rb.tt +3 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/15_mail.rb.tt +53 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/20_redis.rb.tt +13 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/25_rack_attack.rb.tt +96 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/30_i18n.rb.tt +37 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/35_listen_job.rb.tt +4 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/37_shrine.rb.tt +20 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/40_routing.rb.tt +20 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/41_render.rb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/43_static.rb.tt +30 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/44_sessions.rb.tt +62 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/45_security.rb.tt +49 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/46_flash.rb.tt +5 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/47_json.rb.tt +8 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/48_errors.rb.tt +43 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/49_misc.rb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/50_mailer.rb.tt +52 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/51_locale_kit.rb.tt +29 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/52_consent_kit.rb.tt +28 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/55_audit_log.rb.tt +16 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/56_form_helper.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/57_rodauth.rb.tt +304 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/60_web_push.rb.tt +12 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/61_flipper.rb.tt +15 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/62_split.rb.tt +15 -0
- data/lib/roda_gen/generators/templates/project/config/puma.rb.tt +24 -0
- data/lib/roda_gen/generators/templates/project/config/settings/development.yml.tt +9 -0
- data/lib/roda_gen/generators/templates/project/config/settings/production.yml.tt +13 -0
- data/lib/roda_gen/generators/templates/project/config/settings/test.yml.tt +9 -0
- data/lib/roda_gen/generators/templates/project/config/settings.yml.tt +45 -0
- data/lib/roda_gen/generators/templates/project/config.ru.tt +36 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_account_profiles.rb.tt +66 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_accounts.rb.tt +70 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_audit_log.rb.tt +185 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_authorization.rb.tt +68 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_countries.rb.tt +13 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_country_calling_codes.rb.tt +15 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_country_exit_codes.rb.tt +13 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_country_languages.rb.tt +19 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_country_time_zones.rb.tt +11 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_currencies.rb.tt +12 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_gdpr_requests.rb.tt +43 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_languages.rb.tt +11 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_push_subscriptions.rb.tt +16 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_rodauth_features.rb.tt +105 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_settings.rb.tt +60 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/01_countries.csv.tt +250 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/01_currencies.csv.tt +162 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/01_languages.csv.tt +144 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/02_country_calling_codes.csv.tt +237 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/02_country_exit_codes.csv.tt +239 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/02_country_languages.csv.tt +226 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/02_country_time_zones.csv.tt +369 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/03_setting_system_defaults.yml.tt +35 -0
- data/lib/roda_gen/generators/templates/project/db/seeds.rb.tt +69 -0
- data/lib/roda_gen/generators/templates/project/deploy/Caddyfile.tt +69 -0
- data/lib/roda_gen/generators/templates/project/deploy/logrotate/%app_name%-caddy.tt +11 -0
- data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-audit-partition.service.tt +21 -0
- data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-audit-partition.timer.tt +16 -0
- data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-gdpr-worker.service.tt +25 -0
- data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-push-sender.service.tt +25 -0
- data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-shrine-cleanup.service.tt +21 -0
- data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-shrine-cleanup.timer.tt +16 -0
- data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%.service.tt +36 -0
- data/lib/roda_gen/generators/templates/project/helpers/audit_helper.rb.tt +59 -0
- data/lib/roda_gen/generators/templates/project/helpers/authorization_helper.rb.tt +25 -0
- data/lib/roda_gen/generators/templates/project/helpers/current_account_helper.rb.tt +33 -0
- data/lib/roda_gen/generators/templates/project/helpers/feature_flag_helper.rb.tt +34 -0
- data/lib/roda_gen/generators/templates/project/helpers/form_helper.rb.tt +50 -0
- data/lib/roda_gen/generators/templates/project/helpers/http_cache_helper.rb.tt +15 -0
- data/lib/roda_gen/generators/templates/project/helpers/logger_helper.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/helpers/split_helper.rb.tt +22 -0
- data/lib/roda_gen/generators/templates/project/lib/audit_context.rb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/lib/audit_lookup.rb.tt +21 -0
- data/lib/roda_gen/generators/templates/project/lib/daemon/base.rb.tt +104 -0
- data/lib/roda_gen/generators/templates/project/lib/daemon/gdpr_worker.rb.tt +53 -0
- data/lib/roda_gen/generators/templates/project/lib/daemon/push_sender.rb.tt +47 -0
- data/lib/roda_gen/generators/templates/project/lib/daemon/shrine_cache_cleaner.rb.tt +22 -0
- data/lib/roda_gen/generators/templates/project/lib/deploy_check.rb.tt +96 -0
- data/lib/roda_gen/generators/templates/project/lib/filtered_logger.rb.tt +54 -0
- data/lib/roda_gen/generators/templates/project/lib/gdpr.rb.tt +106 -0
- data/lib/roda_gen/generators/templates/project/lib/rbac_audit.rb.tt +47 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/.rubocop.yml.tt +4 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/audit.rake.tt +85 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/console.rake.tt +8 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/db.rake.tt +104 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/deploy.rake.tt +38 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/flags.rake.tt +47 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/gdpr.rake.tt +31 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/parser_current_shim.rb.tt +13 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/quality.rake.tt +84 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/secrets.rake.tt +154 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/spec.rake.tt +136 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/split.rake.tt +27 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/tailwind.rake.tt +35 -0
- data/lib/roda_gen/generators/templates/project/locales/de.yml.tt +325 -0
- data/lib/roda_gen/generators/templates/project/locales/en.yml.tt +321 -0
- data/lib/roda_gen/generators/templates/project/locales/es.yml.tt +326 -0
- data/lib/roda_gen/generators/templates/project/locales/fr.yml.tt +329 -0
- data/lib/roda_gen/generators/templates/project/locales/it.yml.tt +325 -0
- data/lib/roda_gen/generators/templates/project/locales/rodauth/de.yml.tt +5 -0
- data/lib/roda_gen/generators/templates/project/locales/rodauth/en.yml.tt +6 -0
- data/lib/roda_gen/generators/templates/project/locales/rodauth/es.yml.tt +5 -0
- data/lib/roda_gen/generators/templates/project/locales/rodauth/fr.yml.tt +5 -0
- data/lib/roda_gen/generators/templates/project/locales/rodauth/it.yml.tt +5 -0
- data/lib/roda_gen/generators/templates/project/locales/rodauth/sv.yml.tt +274 -0
- data/lib/roda_gen/generators/templates/project/locales/rodauth/tru.yml.tt +274 -0
- data/lib/roda_gen/generators/templates/project/locales/sv.yml.tt +319 -0
- data/lib/roda_gen/generators/templates/project/locales/tru.yml.tt +294 -0
- data/lib/roda_gen/generators/templates/project/log/.keep.tt +0 -0
- data/lib/roda_gen/generators/templates/project/models/account.rb.tt +50 -0
- data/lib/roda_gen/generators/templates/project/models/account_privilege.rb.tt +15 -0
- data/lib/roda_gen/generators/templates/project/models/account_profile.rb.tt +115 -0
- data/lib/roda_gen/generators/templates/project/models/account_role.rb.tt +14 -0
- data/lib/roda_gen/generators/templates/project/models/audit_action.rb.tt +23 -0
- data/lib/roda_gen/generators/templates/project/models/audit_actor_type.rb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/models/audit_log.rb.tt +257 -0
- data/lib/roda_gen/generators/templates/project/models/audit_status.rb.tt +9 -0
- data/lib/roda_gen/generators/templates/project/models/country.rb.tt +17 -0
- data/lib/roda_gen/generators/templates/project/models/country_calling_code.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/models/country_exit_code.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/models/country_language.rb.tt +8 -0
- data/lib/roda_gen/generators/templates/project/models/country_time_zone.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/models/currency.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/models/gdpr_request.rb.tt +32 -0
- data/lib/roda_gen/generators/templates/project/models/gender.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/models/language.rb.tt +13 -0
- data/lib/roda_gen/generators/templates/project/models/privilege.rb.tt +21 -0
- data/lib/roda_gen/generators/templates/project/models/push_subscription.rb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/models/role.rb.tt +21 -0
- data/lib/roda_gen/generators/templates/project/models/role_privilege.rb.tt +14 -0
- data/lib/roda_gen/generators/templates/project/models/setting_system_default.rb.tt +11 -0
- data/lib/roda_gen/generators/templates/project/models/setting_user_value.rb.tt +12 -0
- data/lib/roda_gen/generators/templates/project/models/settings.rb.tt +22 -0
- data/lib/roda_gen/generators/templates/project/models/signup_form_data.rb.tt +61 -0
- data/lib/roda_gen/generators/templates/project/models.rb.tt +6 -0
- data/lib/roda_gen/generators/templates/project/package.json.tt +13 -0
- data/lib/roda_gen/generators/templates/project/public/apple-touch-icon.png +0 -0
- data/lib/roda_gen/generators/templates/project/public/favicon.ico +0 -0
- data/lib/roda_gen/generators/templates/project/public/favicon.svg.tt +5 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/JetBrainsMono-Italic-Variable.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/JetBrainsMono-Variable.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/Lato-Bold.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/Lato-BoldItalic.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/Lato-Italic.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/Lato-Regular.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/NOTICE.md +17 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/NotoSansSyriac-Bold.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/NotoSansSyriac-Regular.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/NotoSansSyriacWestern-Bold.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/NotoSansSyriacWestern-Regular.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/manifest.webmanifest.tt +12 -0
- data/lib/roda_gen/generators/templates/project/public/robots.txt.tt +4 -0
- data/lib/roda_gen/generators/templates/project/public/service-worker.js.tt +27 -0
- data/lib/roda_gen/generators/templates/project/routes/account.rb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/routes/admin.rb.tt +118 -0
- data/lib/roda_gen/generators/templates/project/routes/gdpr.rb.tt +32 -0
- data/lib/roda_gen/generators/templates/project/routes/heartbeat.rb.tt +35 -0
- data/lib/roda_gen/generators/templates/project/routes/legal.rb.tt +20 -0
- data/lib/roda_gen/generators/templates/project/routes/profile.rb.tt +56 -0
- data/lib/roda_gen/generators/templates/project/routes/push.rb.tt +25 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/role_boundary_spec.rb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/spec_helper.rb.tt +146 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/support/auth_helpers.rb.tt +71 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/uat/auth_spec.rb.tt +25 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/uat/consent_nojs_spec.rb.tt +60 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/uat/create_account_form_spec.rb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/uat/otp_lifecycle_spec.rb.tt +67 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/uat/profile_form_spec.rb.tt +17 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/uat/upload_spec.rb.tt +102 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/wcag/auth_pages_spec.rb.tt +61 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/wcag/legal_pages_spec.rb.tt +33 -0
- data/lib/roda_gen/generators/templates/project/spec/daemons/base_spec.rb.tt +106 -0
- data/lib/roda_gen/generators/templates/project/spec/daemons/gdpr_worker_spec.rb.tt +72 -0
- data/lib/roda_gen/generators/templates/project/spec/daemons/push_sender_spec.rb.tt +74 -0
- data/lib/roda_gen/generators/templates/project/spec/locale_parity_spec.rb.tt +58 -0
- data/lib/roda_gen/generators/templates/project/spec/models/account_profile_spec.rb.tt +180 -0
- data/lib/roda_gen/generators/templates/project/spec/models/account_spec.rb.tt +104 -0
- data/lib/roda_gen/generators/templates/project/spec/models/audit_actor_type_spec.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/spec/models/audit_log_spec.rb.tt +398 -0
- data/lib/roda_gen/generators/templates/project/spec/models/audit_status_spec.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/spec/models/authorization_spec.rb.tt +82 -0
- data/lib/roda_gen/generators/templates/project/spec/models/country_calling_code_spec.rb.tt +11 -0
- data/lib/roda_gen/generators/templates/project/spec/models/country_exit_code_spec.rb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/spec/models/country_language_spec.rb.tt +21 -0
- data/lib/roda_gen/generators/templates/project/spec/models/country_spec.rb.tt +29 -0
- data/lib/roda_gen/generators/templates/project/spec/models/country_time_zone_spec.rb.tt +9 -0
- data/lib/roda_gen/generators/templates/project/spec/models/currency_spec.rb.tt +9 -0
- data/lib/roda_gen/generators/templates/project/spec/models/deploy_check_spec.rb.tt +143 -0
- data/lib/roda_gen/generators/templates/project/spec/models/gdpr_spec.rb.tt +110 -0
- data/lib/roda_gen/generators/templates/project/spec/models/language_spec.rb.tt +15 -0
- data/lib/roda_gen/generators/templates/project/spec/models/rbac_audit_spec.rb.tt +110 -0
- data/lib/roda_gen/generators/templates/project/spec/models/setting_system_default_spec.rb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/spec/models/setting_user_value_spec.rb.tt +33 -0
- data/lib/roda_gen/generators/templates/project/spec/models/settings_spec.rb.tt +63 -0
- data/lib/roda_gen/generators/templates/project/spec/models/signup_form_data_spec.rb.tt +22 -0
- data/lib/roda_gen/generators/templates/project/spec/spec_helper.rb.tt +93 -0
- data/lib/roda_gen/generators/templates/project/spec/support/audit_log_helpers.rb.tt +21 -0
- data/lib/roda_gen/generators/templates/project/spec/support/audit_lookup_shared_examples.rb.tt +19 -0
- data/lib/roda_gen/generators/templates/project/spec/support/auth_helpers.rb.tt +62 -0
- data/lib/roda_gen/generators/templates/project/spec/support/faker.rb.tt +30 -0
- data/lib/roda_gen/generators/templates/project/spec/web/admin_spec.rb.tt +155 -0
- data/lib/roda_gen/generators/templates/project/spec/web/audit_log_spec.rb.tt +159 -0
- data/lib/roda_gen/generators/templates/project/spec/web/auth_spec.rb.tt +492 -0
- data/lib/roda_gen/generators/templates/project/spec/web/authorization_spec.rb.tt +110 -0
- data/lib/roda_gen/generators/templates/project/spec/web/boot_spec.rb.tt +27 -0
- data/lib/roda_gen/generators/templates/project/spec/web/consent_banner_spec.rb.tt +46 -0
- data/lib/roda_gen/generators/templates/project/spec/web/feature_flag_helper_spec.rb.tt +33 -0
- data/lib/roda_gen/generators/templates/project/spec/web/flags_spec.rb.tt +67 -0
- data/lib/roda_gen/generators/templates/project/spec/web/gdpr_spec.rb.tt +55 -0
- data/lib/roda_gen/generators/templates/project/spec/web/heartbeat_spec.rb.tt +65 -0
- data/lib/roda_gen/generators/templates/project/spec/web/host_allowlist_spec.rb.tt +27 -0
- data/lib/roda_gen/generators/templates/project/spec/web/legal_spec.rb.tt +61 -0
- data/lib/roda_gen/generators/templates/project/spec/web/locale_resolver_spec.rb.tt +34 -0
- data/lib/roda_gen/generators/templates/project/spec/web/logger_helper_spec.rb.tt +23 -0
- data/lib/roda_gen/generators/templates/project/spec/web/logger_spec.rb.tt +82 -0
- data/lib/roda_gen/generators/templates/project/spec/web/otp_audit_spec.rb.tt +147 -0
- data/lib/roda_gen/generators/templates/project/spec/web/profile_spec.rb.tt +97 -0
- data/lib/roda_gen/generators/templates/project/spec/web/push_spec.rb.tt +55 -0
- data/lib/roda_gen/generators/templates/project/spec/web/rack_attack_runtime_spec.rb.tt +52 -0
- data/lib/roda_gen/generators/templates/project/spec/web/rack_attack_spec.rb.tt +81 -0
- data/lib/roda_gen/generators/templates/project/spec/web/rbac_audit_spec.rb.tt +62 -0
- data/lib/roda_gen/generators/templates/project/spec/web/request_id_spec.rb.tt +62 -0
- data/lib/roda_gen/generators/templates/project/spec/web/role_boundary_spec.rb.tt +21 -0
- data/lib/roda_gen/generators/templates/project/spec/web/session_skip_spec.rb.tt +74 -0
- data/lib/roda_gen/generators/templates/project/spec/web/split_helper_spec.rb.tt +38 -0
- data/lib/roda_gen/generators/templates/project/spec/web/type_routing_spec.rb.tt +55 -0
- data/lib/roda_gen/generators/templates/project/spec/web/upload_zone_spec.rb.tt +91 -0
- data/lib/roda_gen/generators/templates/project/tmp/.keep.tt +0 -0
- data/lib/roda_gen/generators/templates/project/vendor/.keep.tt +0 -0
- data/lib/roda_gen/generators/templates/project/views/403.erb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/views/404.erb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/views/500.erb.tt +12 -0
- data/lib/roda_gen/generators/templates/project/views/_head_meta.erb.tt +29 -0
- data/lib/roda_gen/generators/templates/project/views/_impersonate_picker.erb.tt +21 -0
- data/lib/roda_gen/generators/templates/project/views/_language_switcher.erb.tt +22 -0
- data/lib/roda_gen/generators/templates/project/views/_locked_accounts.erb.tt +18 -0
- data/lib/roda_gen/generators/templates/project/views/_upload_zone.erb.tt +35 -0
- data/lib/roda_gen/generators/templates/project/views/account/profile.erb.tt +149 -0
- data/lib/roda_gen/generators/templates/project/views/admin/flags.erb.tt +51 -0
- data/lib/roda_gen/generators/templates/project/views/consent_kit/_banner.erb.tt +59 -0
- data/lib/roda_gen/generators/templates/project/views/consent_kit/_preferences.erb.tt +87 -0
- data/lib/roda_gen/generators/templates/project/views/gdpr/erased.erb.tt +6 -0
- data/lib/roda_gen/generators/templates/project/views/gdpr/index.erb.tt +28 -0
- data/lib/roda_gen/generators/templates/project/views/layout.erb.tt +112 -0
- data/lib/roda_gen/generators/templates/project/views/legal/contact.erb.tt +44 -0
- data/lib/roda_gen/generators/templates/project/views/legal/cookies.erb.tt +47 -0
- data/lib/roda_gen/generators/templates/project/views/legal/disclaimer.erb.tt +19 -0
- data/lib/roda_gen/generators/templates/project/views/legal/privacy.erb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/views/mailers/account_unlocked.erb.tt +5 -0
- data/lib/roda_gen/generators/templates/project/views/mailers/data_erased.erb.tt +5 -0
- data/lib/roda_gen/generators/templates/project/views/mailers/data_export.erb.tt +5 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/add-recovery-codes.erb.tt +30 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/change-login.erb.tt +44 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/change-password.erb.tt +41 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/close-account.erb.tt +27 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/confirm-password.erb.tt +23 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/create-account.erb.tt +183 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/login.erb.tt +51 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/logout.erb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/otp-auth.erb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/otp-disable.erb.tt +27 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/otp-setup.erb.tt +48 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/otp-unlock-not-available.erb.tt +18 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/otp-unlock.erb.tt +28 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/recovery-auth.erb.tt +23 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/recovery-codes.erb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/remember.erb.tt +35 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/reset-password-request.erb.tt +27 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/reset-password.erb.tt +30 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/two-factor-auth.erb.tt +8 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/two-factor-disable.erb.tt +20 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/two-factor-manage.erb.tt +36 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/unlock-account-request.erb.tt +13 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/unlock-account.erb.tt +23 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/verify-account-resend.erb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/verify-account.erb.tt +32 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/verify-login-change.erb.tt +8 -0
- data/lib/roda_gen/generators/templates/route/routes/%plural%.rb.tt +19 -0
- data/lib/roda_gen/generators/templates/route/spec/web/%plural%_spec.rb.tt +36 -0
- data/lib/roda_gen/generators/templates/route/views/%plural%/index.erb.tt +11 -0
- data/lib/roda_gen/generators/templates/route/views/%plural%/show.erb.tt +7 -0
- data/lib/roda_gen/generators/templates/upload/db/migrate/%migration_filename%.rb.tt +13 -0
- data/lib/roda_gen/generators/templates/upload/helpers/upload_serving.rb.tt +43 -0
- data/lib/roda_gen/generators/templates/upload/models/%resource_name%.rb.tt +11 -0
- data/lib/roda_gen/generators/templates/upload/models/%resource_name%_uploader.rb.tt +19 -0
- data/lib/roda_gen/generators/templates/upload/routes/%plural%.rb.tt +44 -0
- data/lib/roda_gen/generators/templates/upload/spec/web/%plural%_spec.rb.tt +56 -0
- data/lib/roda_gen/generators/templates/upload/views/%plural%/index.erb.tt +18 -0
- data/lib/roda_gen/generators/upload.rb +83 -0
- data/lib/roda_gen/project_context.rb +30 -0
- data/lib/roda_gen/version.rb +5 -0
- data/lib/roda_gen.rb +16 -0
- metadata +497 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require_relative '../../lib/deploy_check'
|
|
5
|
+
|
|
6
|
+
# rubocop:disable RSpec/SpecFilePathFormat -- Deploy::Check lives in lib/, spec/ has no lib/ subdir and every non-route/non-daemon spec goes here
|
|
7
|
+
RSpec.describe Deploy::Check do
|
|
8
|
+
# rubocop:enable RSpec/SpecFilePathFormat
|
|
9
|
+
describe '.settings_placeholders!' do
|
|
10
|
+
it 'passes when site.* has no [PLACEHOLDER] markers' do
|
|
11
|
+
filled = stub_site(company: { name: 'Acme', org_nr: '556677-1234' }, address: { street: 'Storgatan 1' })
|
|
12
|
+
stub_const('<%= @app.camel %>Config', filled)
|
|
13
|
+
expect { described_class.settings_placeholders! }.not_to raise_error
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'raises listing every offending key when placeholders remain' do
|
|
17
|
+
with_placeholders = stub_site(
|
|
18
|
+
company: { name: 'Acme', org_nr: '[ORG NR]' },
|
|
19
|
+
address: { street: '[STREET]', postal_code: '12345' },
|
|
20
|
+
contact: { email: '[EMAIL]' },
|
|
21
|
+
regulator: { supervisory_body: 'IMY' }
|
|
22
|
+
)
|
|
23
|
+
stub_const('<%= @app.camel %>Config', with_placeholders)
|
|
24
|
+
expect { described_class.settings_placeholders! }.to raise_error(
|
|
25
|
+
/site\.company\.org_nr.*site\.address\.street.*site\.contact\.email/m
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it 'recurses into nested hashes and reports the full dotted path' do
|
|
30
|
+
stub_const('<%= @app.camel %>Config', stub_site(company: { signatory: { name: '[FULL NAME]' } }))
|
|
31
|
+
expect { described_class.settings_placeholders! }
|
|
32
|
+
.to raise_error(/site\.company\.signatory\.name=\[FULL NAME\]/)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'skips a missing section without raising' do
|
|
36
|
+
site_with_holes = Struct.new(:company, :address, :contact, :regulator)
|
|
37
|
+
.new({ name: 'Acme' }, nil, nil, nil)
|
|
38
|
+
stub_const('<%= @app.camel %>Config', Struct.new(:site).new(site_with_holes))
|
|
39
|
+
expect { described_class.settings_placeholders! }.not_to raise_error
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Production code only calls section.to_h, and Hash#to_h returns self, so raw hashes suffice
|
|
43
|
+
def stub_site(company: {}, address: {}, contact: {}, regulator: {})
|
|
44
|
+
site = Struct.new(:company, :address, :contact, :regulator).new(company, address, contact, regulator)
|
|
45
|
+
Struct.new(:site).new(site)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
describe '.database_url!' do
|
|
50
|
+
it 'passes for a connectable URL' do
|
|
51
|
+
expect { described_class.database_url!(<%= @app.camel %>Config.database.url) }.not_to raise_error
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it 'raises when the URL is blank' do
|
|
55
|
+
expect { described_class.database_url!(nil) }.to raise_error(/blank/)
|
|
56
|
+
expect { described_class.database_url!('') }.to raise_error(/blank/)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it 'raises when the URL cannot connect' do
|
|
60
|
+
expect { described_class.database_url!('postgres://nouser:nopass@127.0.0.1:1/nonesuch') }
|
|
61
|
+
.to raise_error(Sequel::DatabaseConnectionError)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
describe '.redis!' do
|
|
66
|
+
it 'passes when REDIS responds to PING' do
|
|
67
|
+
expect { described_class.redis! }.not_to raise_error
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it 'raises when PING does not return PONG' do
|
|
71
|
+
fake_redis = instance_double(Redis, ping: 'NOTPONG')
|
|
72
|
+
fake_pool = instance_double(ConnectionPool)
|
|
73
|
+
allow(fake_pool).to receive(:with).and_yield(fake_redis)
|
|
74
|
+
stub_const('REDIS', fake_pool)
|
|
75
|
+
expect { described_class.redis! }.to raise_error(/expected PONG/)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
describe '.mail_smtp!' do
|
|
80
|
+
it 'passes when every account has non-empty address + user_name + password' do
|
|
81
|
+
stub_mail(
|
|
82
|
+
default: { address: 'smtp.example.com', user_name: 'u', password: 'p' }
|
|
83
|
+
)
|
|
84
|
+
expect { described_class.mail_smtp! }.not_to raise_error
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'raises listing every blank credential field across all accounts' do
|
|
88
|
+
stub_mail(
|
|
89
|
+
default: { address: 'smtp.example.com', user_name: '', password: 'p' },
|
|
90
|
+
billing: { address: '', user_name: 'u', password: '' }
|
|
91
|
+
)
|
|
92
|
+
expected = Regexp.new(
|
|
93
|
+
'mail\.accounts\.default\.smtp\.user_name' \
|
|
94
|
+
'.*mail\.accounts\.billing\.smtp\.address' \
|
|
95
|
+
'.*mail\.accounts\.billing\.smtp\.password',
|
|
96
|
+
Regexp::MULTILINE
|
|
97
|
+
)
|
|
98
|
+
expect { described_class.mail_smtp! }.to raise_error(expected)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# Production code only calls <%= @app.camel %>Config.mail.accounts.to_h, so a nested Hash suffices
|
|
102
|
+
def stub_mail(**accounts)
|
|
103
|
+
stubbed = accounts.transform_values { |smtp| { smtp: smtp } }
|
|
104
|
+
mail = Struct.new(:accounts).new(stubbed)
|
|
105
|
+
stub_const('<%= @app.camel %>Config', Struct.new(:mail).new(mail))
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
describe '.audit_partitions!' do
|
|
110
|
+
# test:db bootstraps audit:add_next[5], so current and next partitions exist
|
|
111
|
+
it 'passes when the current + next period partitions exist' do
|
|
112
|
+
expect { described_class.audit_partitions! }.not_to raise_error
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it 'raises naming the missing partitions' do
|
|
116
|
+
allow(AuditLog).to receive(:partition_for).and_return(
|
|
117
|
+
['audit_log_1999_q1', Date.new(1999, 1, 1), Date.new(1999, 4, 1)],
|
|
118
|
+
['audit_log_1999_q2', Date.new(1999, 4, 1), Date.new(1999, 7, 1)]
|
|
119
|
+
)
|
|
120
|
+
expect { described_class.audit_partitions! }
|
|
121
|
+
.to raise_error(/missing partitions: audit_log_1999_q1, audit_log_1999_q2/)
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
describe '.assets_tailwind!' do
|
|
126
|
+
it 'raises when no compiled CSS is on disk' do
|
|
127
|
+
allow(Dir).to receive(:[]).and_return([])
|
|
128
|
+
expect { described_class.assets_tailwind! }.to raise_error(/run `rake tailwind:build`/)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
it 'raises when the compiled CSS is empty' do
|
|
132
|
+
allow(Dir).to receive(:[]).and_return(['/tmp/empty.css'])
|
|
133
|
+
allow(File).to receive(:size).with('/tmp/empty.css').and_return(0)
|
|
134
|
+
expect { described_class.assets_tailwind! }.to raise_error(/run `rake tailwind:build`/)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
it 'passes when a non-empty compiled CSS is present' do
|
|
138
|
+
allow(Dir).to receive(:[]).and_return(['/tmp/app.css'])
|
|
139
|
+
allow(File).to receive(:size).with('/tmp/app.css').and_return(2048)
|
|
140
|
+
expect { described_class.assets_tailwind! }.not_to raise_error
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require_relative '../../lib/gdpr'
|
|
5
|
+
|
|
6
|
+
RSpec.describe Gdpr do
|
|
7
|
+
def create_subject(email: Faker::Internet.email(name: "gdpr-#{SecureRandom.hex(4)}"))
|
|
8
|
+
account = Account.create(email: email, status_id: 2)
|
|
9
|
+
create_profile(account.id)
|
|
10
|
+
AccountRole.create(account_id: account.id, role_id: 'user')
|
|
11
|
+
AccountPrivilege.create(account_id: account.id, privilege_id: 'accounts.read')
|
|
12
|
+
PushSubscription.create(account_id: account.id, endpoint: Faker::Internet.url,
|
|
13
|
+
p256dh: SecureRandom.base64(32), auth_key: SecureRandom.base64(16))
|
|
14
|
+
AuditLog.record(action: 'user.login', actor_type: :user, actor_id: account.id, actor_label: email)
|
|
15
|
+
account
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def create_profile(account_id)
|
|
19
|
+
AccountProfile.create(
|
|
20
|
+
account_id: account_id,
|
|
21
|
+
first_name: Faker::Name.first_name, last_name: Faker::Name.last_name,
|
|
22
|
+
address: Faker::Address.street_address, postal_code: Faker::Address.zip_code,
|
|
23
|
+
city: Faker::Address.city, country: 'SE', language: 'sv',
|
|
24
|
+
time_zone: 'Europe/Stockholm', mobile_number: Faker::PhoneNumber.cell_phone,
|
|
25
|
+
personal_identity_number: Faker::IDNumber.swedish_personal_identity_number
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe '.export' do
|
|
30
|
+
subject(:data) { described_class.export(account) }
|
|
31
|
+
|
|
32
|
+
let(:account) do
|
|
33
|
+
create_subject.tap do |a|
|
|
34
|
+
AuditLog.record(action: 'user.login', actor_type: :user, actor_id: a.id, ip_address: '203.0.113.9')
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'includes the account, profile PII, roles, privileges, push, and audit trail', :aggregate_failures do
|
|
39
|
+
expect(data[:account][:email]).to eq(account.email)
|
|
40
|
+
expect(data[:profile][:personal_identity_number]).to eq(account.profile.personal_identity_number)
|
|
41
|
+
expect(data[:roles]).to include('user')
|
|
42
|
+
expect(data[:privileges]).to include('accounts.read')
|
|
43
|
+
expect(data[:push_subscriptions].first[:endpoint]).to be_a(String)
|
|
44
|
+
expect(data[:audit_events].map { |e| e[:action] }).to include('user.login')
|
|
45
|
+
expect(data[:audit_events].map { |e| e[:ip_address] }).to include('203.0.113.9')
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
describe '.erase!' do
|
|
50
|
+
let!(:account) { create_subject }
|
|
51
|
+
let(:account_id) { account.id }
|
|
52
|
+
|
|
53
|
+
it 'returns the original email, scrubs it, and closes the account' do
|
|
54
|
+
original = account.email
|
|
55
|
+
expect(described_class.erase!(account)).to eq(original)
|
|
56
|
+
row = Account.with_pk(account_id)
|
|
57
|
+
expect(row.email).to match(/\Aerased-#{account_id}@/)
|
|
58
|
+
expect(row.status_id).to eq(3)
|
|
59
|
+
expect(row.deleted_at).not_to be_nil
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it 'deletes the profile + push subscriptions but retains roles/privileges + the skeleton' do
|
|
63
|
+
described_class.erase!(account)
|
|
64
|
+
expect(AccountProfile.where(account_id: account_id).count).to eq(0)
|
|
65
|
+
expect(PushSubscription.where(account_id: account_id).count).to eq(0)
|
|
66
|
+
expect(Account.where(id: account_id).count).to eq(1)
|
|
67
|
+
expect(AccountRole.where(account_id: account_id).count).to eq(1)
|
|
68
|
+
expect(AccountPrivilege.where(account_id: account_id).count).to eq(1)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it 'redacts the account audit PII and records system.data.erase' do
|
|
72
|
+
described_class.erase!(account)
|
|
73
|
+
login = AuditLog.where(actor_id: account_id, action_id: AuditAction.id_for!('user.login')).first
|
|
74
|
+
expect(login[:actor_label]).to eq('[redacted]')
|
|
75
|
+
erased = AuditLog.where(action_id: AuditAction.id_for!('system.data.erase'))
|
|
76
|
+
.where(Sequel.lit("payload->>'account_id' = ?", account_id.to_s))
|
|
77
|
+
expect(erased.count).to eq(1)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
describe '.purge_retained!' do
|
|
82
|
+
it 'hard-deletes an erased account once its audit rows have aged out' do
|
|
83
|
+
account = create_subject
|
|
84
|
+
id = account.id
|
|
85
|
+
described_class.erase!(account)
|
|
86
|
+
# Retention window passed, audit rows gone and the erasure predates every surviving row
|
|
87
|
+
AuditLog.where(actor_id: id).delete
|
|
88
|
+
AuditLog.where(Sequel.lit("payload->>'account_id' = ?", id.to_s)).delete
|
|
89
|
+
Account.where(id: id).update(deleted_at: Time.utc(2000, 1, 1))
|
|
90
|
+
|
|
91
|
+
expect { described_class.purge_retained! }.to change { Account.where(id: id).count }.from(1).to(0)
|
|
92
|
+
expect(AccountRole.where(account_id: id).count).to eq(0)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it 'purges an erased account outright when the audit log is empty (no surviving rows to wait for)' do
|
|
96
|
+
account = create_subject
|
|
97
|
+
id = account.id
|
|
98
|
+
described_class.erase!(account)
|
|
99
|
+
AuditLog.dataset.delete
|
|
100
|
+
|
|
101
|
+
expect { described_class.purge_retained! }.to change { Account.where(id: id).count }.from(1).to(0)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it 'leaves an erased account whose audit rows are still present' do
|
|
105
|
+
account = create_subject
|
|
106
|
+
described_class.erase!(account)
|
|
107
|
+
expect { described_class.purge_retained! }.not_to(change { Account.where(id: account.id).count })
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Language do
|
|
6
|
+
let(:language) { described_class['sv'] }
|
|
7
|
+
|
|
8
|
+
it 'persists and looks up by alpha-2 iso_code' do
|
|
9
|
+
expect(language.name).to eq('Swedish')
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'reaches countries via country_languages' do
|
|
13
|
+
expect(language.countries.map(&:iso_code)).to include('SE')
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe RbacAudit do
|
|
6
|
+
let(:account) { Account.create(email: Faker::Internet.email(name: "rbacaudit-#{SecureRandom.hex(4)}")) }
|
|
7
|
+
let(:role_name) { "role-#{SecureRandom.hex(4)}" }
|
|
8
|
+
|
|
9
|
+
# authorization_spec asserts the seeded role list exactly and nothing rolls back, so roles made here go
|
|
10
|
+
# Dataset deletes, so the teardown is not itself audited and does not trip the role_privileges FK
|
|
11
|
+
after do
|
|
12
|
+
RolePrivilege.where(role_id: role_name).delete
|
|
13
|
+
Role.where(role: role_name).delete
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Audit log is shared across the whole run, so filter to rows this example wrote
|
|
17
|
+
def rows_for(code)
|
|
18
|
+
AuditLog.where(action_id: AuditAction.id_for!(code)).order(:occurred_at).all
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def payloads_for(code, key, value)
|
|
22
|
+
rows_for(code).map { it[:payload] }.select { it[key] == value }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe 'grants against an account' do
|
|
26
|
+
it 'logs rbac.account_role.grant with the pair' do
|
|
27
|
+
AccountRole.create(account_id: account.id, role_id: 'admin')
|
|
28
|
+
expect(payloads_for('rbac.account_role.grant', 'account_id', account.id))
|
|
29
|
+
.to contain_exactly(hash_including('role_id' => 'admin'))
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'logs rbac.account_role.revoke on destroy' do
|
|
33
|
+
AccountRole.create(account_id: account.id, role_id: 'admin').destroy
|
|
34
|
+
expect(payloads_for('rbac.account_role.revoke', 'account_id', account.id))
|
|
35
|
+
.to contain_exactly(hash_including('role_id' => 'admin'))
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'logs rbac.account_privilege.grant for a direct grant' do
|
|
39
|
+
AccountPrivilege.create(account_id: account.id, privilege_id: 'accounts.read')
|
|
40
|
+
expect(payloads_for('rbac.account_privilege.grant', 'account_id', account.id))
|
|
41
|
+
.to contain_exactly(hash_including('privilege_id' => 'accounts.read'))
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe 'changes to the role and privilege definitions' do
|
|
46
|
+
it 'logs rbac.role.create' do
|
|
47
|
+
Role.create(role: role_name, description: 'first')
|
|
48
|
+
expect(payloads_for('rbac.role.create', 'role', role_name))
|
|
49
|
+
.to contain_exactly(hash_including('description' => 'first'))
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'logs rbac.role.update with the before/after diff' do
|
|
53
|
+
Role.create(role: role_name, description: 'first').update(description: 'second')
|
|
54
|
+
expect(payloads_for('rbac.role.update', 'role', role_name).first['changed'])
|
|
55
|
+
.to eq('description' => %w[first second])
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it 'logs rbac.role.delete' do
|
|
59
|
+
Role.create(role: role_name, description: 'first').destroy
|
|
60
|
+
expect(payloads_for('rbac.role.delete', 'role', role_name)).not_to be_empty
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'logs rbac.role_privilege.grant when a role gains a privilege' do
|
|
64
|
+
Role.create(role: role_name)
|
|
65
|
+
RolePrivilege.create(role_id: role_name, privilege_id: 'flags.read')
|
|
66
|
+
expect(payloads_for('rbac.role_privilege.grant', 'role_id', role_name))
|
|
67
|
+
.to contain_exactly(hash_including('privilege_id' => 'flags.read'))
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
describe 'actor attribution' do
|
|
72
|
+
it 'falls back to a system actor outside a request' do
|
|
73
|
+
AccountRole.create(account_id: account.id, role_id: 'admin')
|
|
74
|
+
row = rows_for('rbac.account_role.grant').find { it[:payload]['account_id'] == account.id }
|
|
75
|
+
expect(row[:actor_type_id]).to eq(AuditActorType.id_for!(:system))
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it 'attributes the change to the actor AuditContext.as names' do
|
|
79
|
+
AuditContext.as(actor_type: :user, actor_id: account.id, actor_label: 'granter@example.com') do
|
|
80
|
+
AccountPrivilege.create(account_id: account.id, privilege_id: 'flags.read')
|
|
81
|
+
end
|
|
82
|
+
row = rows_for('rbac.account_privilege.grant').find { it[:payload]['account_id'] == account.id }
|
|
83
|
+
expect(row[:actor_label]).to eq('granter@example.com')
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it 'restores the previous resolver after the block' do
|
|
87
|
+
AuditContext.as(actor_type: :user, actor_id: account.id) { nil }
|
|
88
|
+
expect(AuditContext.current).to eq(AuditContext::SYSTEM)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it 'skips an event missing from the verb map' do
|
|
93
|
+
Role.create(role: role_name, description: 'first')
|
|
94
|
+
partial = Class.new(Sequel::Model(:roles)) do
|
|
95
|
+
include RbacAudit
|
|
96
|
+
|
|
97
|
+
audit_rbac 'rbac.role', created: 'create'
|
|
98
|
+
end
|
|
99
|
+
partial.first(role: role_name).update(description: 'second')
|
|
100
|
+
expect(payloads_for('rbac.role.update', 'role', role_name)).to be_empty
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Documents a real hole, Gdpr.delete_skeleton! clears grants this way on purpose and logs
|
|
104
|
+
# system.data.erase for the erasure as a whole
|
|
105
|
+
it 'does not log dataset-level deletes, which bypass Sequel hooks' do
|
|
106
|
+
AccountRole.create(account_id: account.id, role_id: 'admin')
|
|
107
|
+
AccountRole.where(account_id: account.id).delete
|
|
108
|
+
expect(payloads_for('rbac.account_role.revoke', 'account_id', account.id)).to be_empty
|
|
109
|
+
end
|
|
110
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe SettingSystemDefault do
|
|
6
|
+
let(:unique_name) { "zz.#{SecureRandom.hex(4)}" }
|
|
7
|
+
|
|
8
|
+
it 'persists and looks up by name' do
|
|
9
|
+
described_class.create(name: unique_name, value: Sequel.pg_jsonb_wrap('light'))
|
|
10
|
+
expect(described_class[unique_name].value).to eq('light')
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'populates created_at and updated_at from column defaults on INSERT' do
|
|
14
|
+
row = described_class.create(name: unique_name, value: Sequel.pg_jsonb_wrap('en'))
|
|
15
|
+
expect(row.created_at).not_to be_nil
|
|
16
|
+
expect(row.updated_at).not_to be_nil
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'bumps updated_at on UPDATE via the :timestamps plugin' do
|
|
20
|
+
row = described_class.create(name: unique_name, value: Sequel.pg_jsonb_wrap('blue'))
|
|
21
|
+
before = row.updated_at
|
|
22
|
+
sleep 0.01
|
|
23
|
+
row.update(value: Sequel.pg_jsonb_wrap('red'))
|
|
24
|
+
expect(row.reload.updated_at).to be > before
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
# SecureRandom suffixes so rows committed by earlier runs don't collide on the composite PK (name, account_id)
|
|
6
|
+
RSpec.describe SettingUserValue do
|
|
7
|
+
let!(:account_id) { Account.create(email: Faker::Internet.email(name: "uvspec-#{SecureRandom.hex(4)}")).id }
|
|
8
|
+
let(:name) { "zz.#{SecureRandom.hex(4)}" }
|
|
9
|
+
|
|
10
|
+
before do
|
|
11
|
+
SettingSystemDefault.create(name: name, value: Sequel.pg_jsonb_wrap('light'))
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'persists a per-account override' do
|
|
15
|
+
described_class.create(name: name, account_id: account_id, value: Sequel.pg_jsonb_wrap('dark'))
|
|
16
|
+
expect(described_class[name: name, account_id: account_id].value).to eq('dark')
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'enforces composite PK uniqueness' do
|
|
20
|
+
described_class.create(name: name, account_id: account_id, value: Sequel.pg_jsonb_wrap('dark'))
|
|
21
|
+
expect do
|
|
22
|
+
described_class.create(name: name, account_id: account_id, value: Sequel.pg_jsonb_wrap('mint'))
|
|
23
|
+
end.to raise_error(Sequel::UniqueConstraintViolation)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'bumps updated_at on UPDATE via the :timestamps plugin' do
|
|
27
|
+
row = described_class.create(name: name, account_id: account_id, value: Sequel.pg_jsonb_wrap('dark'))
|
|
28
|
+
before = row.updated_at
|
|
29
|
+
sleep 0.01
|
|
30
|
+
row.update(value: Sequel.pg_jsonb_wrap('mint'))
|
|
31
|
+
expect(row.reload.updated_at).to be > before
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Settings do
|
|
6
|
+
describe 'tier resolution' do
|
|
7
|
+
let!(:account_id) { Account.create(email: Faker::Internet.email(name: "lookup-#{SecureRandom.hex(4)}")).id }
|
|
8
|
+
let(:name) { "zz.#{SecureRandom.hex(4)}" }
|
|
9
|
+
|
|
10
|
+
before { SettingSystemDefault.create(name: name, value: Sequel.pg_jsonb_wrap('light')) }
|
|
11
|
+
|
|
12
|
+
describe '.for_system' do
|
|
13
|
+
it 'returns the system default' do
|
|
14
|
+
expect(described_class.for_system(name)).to eq('light')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'returns nil for an unregistered name (LANGUAGE sql function, no raise)' do
|
|
18
|
+
expect(described_class.for_system("zz.never.#{SecureRandom.hex(4)}")).to be_nil
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe '.for_user' do
|
|
23
|
+
it 'falls back to the system default when no user value is set' do
|
|
24
|
+
expect(described_class.for_user(name, account_id)).to eq('light')
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'returns the user override when set' do
|
|
28
|
+
SettingUserValue.create(name: name, account_id: account_id, value: Sequel.pg_jsonb_wrap('mint'))
|
|
29
|
+
expect(described_class.for_user(name, account_id)).to eq('mint')
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe '.for_system against seeded values' do
|
|
35
|
+
it 'returns the seeded JSONB integer for a known name (scalar passes through)' do
|
|
36
|
+
expect(described_class.for_system('password_minimum_length')).to eq(12)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe 'interval auto-coercion' do
|
|
41
|
+
# session_expiration_default seeds as "4 hours"
|
|
42
|
+
it 'returns an ActiveSupport::Duration for duration-shaped JSONB strings' do
|
|
43
|
+
expect(described_class.for_system('session_expiration_default')).to eq(4.hours)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'auto-coerces under for_user too (falls back through to the system tier)' do
|
|
47
|
+
account_id = Account.create(email: Faker::Internet.email(name: "secspec-#{SecureRandom.hex(4)}")).id
|
|
48
|
+
expect(described_class.for_user('session_expiration_default', account_id)).to eq(4.hours)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "leaves non-interval strings unchanged (try_interval returns NULL for 'light')" do
|
|
52
|
+
name = "zz.#{SecureRandom.hex(4)}"
|
|
53
|
+
SettingSystemDefault.create(name: name, value: Sequel.pg_jsonb_wrap('light'))
|
|
54
|
+
expect(described_class.for_system(name)).to eq('light')
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it 'parses composite interval strings (PG accepts "1 day 6 hours")' do
|
|
58
|
+
name = "zz.#{SecureRandom.hex(4)}"
|
|
59
|
+
SettingSystemDefault.create(name: name, value: Sequel.pg_jsonb_wrap('1 day 6 hours'))
|
|
60
|
+
expect(described_class.for_system(name)).to eq(1.day + 6.hours)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
# cache is covered by the auth and browser specs rendering create-account.erb, reset! is the only
|
|
6
|
+
# call site no normal flow hits
|
|
7
|
+
RSpec.describe SignupFormData do
|
|
8
|
+
describe '.reset!' do
|
|
9
|
+
it 'clears the memoized cache so the next read re-runs the queries' do
|
|
10
|
+
# Warm the cache
|
|
11
|
+
described_class.countries
|
|
12
|
+
first_cache = described_class.cache
|
|
13
|
+
|
|
14
|
+
described_class.reset!
|
|
15
|
+
second_cache = described_class.cache
|
|
16
|
+
|
|
17
|
+
# Same content, fresh identity, so @cache was rebuilt and not returned from memo
|
|
18
|
+
expect(second_cache).not_to equal(first_cache)
|
|
19
|
+
expect(second_cache.keys).to eq(first_cache.keys)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
ENV['RACK_ENV'] = 'test'
|
|
4
|
+
|
|
5
|
+
# Web and browser specs boot under the web role so production's GRANT boundary fires in tests
|
|
6
|
+
# ||= so an explicit DATABASE_ROLE in the env wins
|
|
7
|
+
running_web_specs = ARGV.any? { it.include?('spec/web') || it.include?('spec/browser') }
|
|
8
|
+
ENV['DATABASE_ROLE'] ||= running_web_specs ? 'web' : 'app'
|
|
9
|
+
|
|
10
|
+
require 'fileutils'
|
|
11
|
+
require 'simplecov'
|
|
12
|
+
|
|
13
|
+
# Suite name from the first spec/ argument (spec/browser/wcag -> browser_wcag), keys the SimpleCov
|
|
14
|
+
# command_name so concurrent suites don't clobber each other and the JSON file lib/tasks/spec.rake rolls up
|
|
15
|
+
spec_arg = ARGV.find { it.start_with?('spec/') }
|
|
16
|
+
SUITE = if spec_arg
|
|
17
|
+
spec_arg.delete_prefix('spec/')
|
|
18
|
+
.delete_suffix('.rb')
|
|
19
|
+
.tr('/', '_')
|
|
20
|
+
.delete_suffix('_spec')
|
|
21
|
+
else
|
|
22
|
+
'all'
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Must match SPEC_SUMMARY_DIR in lib/tasks/spec.rake
|
|
26
|
+
SPEC_SUMMARY_DIR = 'tmp/spec_summary'
|
|
27
|
+
FileUtils.mkdir_p(SPEC_SUMMARY_DIR)
|
|
28
|
+
|
|
29
|
+
SimpleCov.start do
|
|
30
|
+
skip '/spec/'
|
|
31
|
+
skip '/db/migrate/'
|
|
32
|
+
# Initializers hold hook behavior the suite tests through the front
|
|
33
|
+
# door (Rodauth hooks, error handlers, session skip), so measure them.
|
|
34
|
+
# Boot plumbing's only test is that anything runs at all, keep it out.
|
|
35
|
+
skip '/config/boot.rb'
|
|
36
|
+
skip '/config/puma.rb'
|
|
37
|
+
skip '/config/database.rb'
|
|
38
|
+
skip '/config/console.rb'
|
|
39
|
+
enable_coverage :branch
|
|
40
|
+
coverage_dir 'tmp/coverage'
|
|
41
|
+
command_name "RSpec:#{SUITE}"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
RSpec.configure do |config|
|
|
45
|
+
config.add_formatter 'json', "#{SPEC_SUMMARY_DIR}/#{SUITE}.json"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
require_relative '../config/boot'
|
|
49
|
+
require_relative '../<%= @app.snake %>'
|
|
50
|
+
require 'rack/test'
|
|
51
|
+
require 'mail'
|
|
52
|
+
|
|
53
|
+
# Web role has INSERT-only on audit_log.audit_log, so specs inspect it through the app role
|
|
54
|
+
# Goes through Database.connect so pg_json is loaded, otherwise jsonb columns come back as raw strings
|
|
55
|
+
ADMIN_DB = if ENV['DATABASE_ROLE'] == 'app'
|
|
56
|
+
DB
|
|
57
|
+
else
|
|
58
|
+
Database.connect(<%= @app.camel %>Config.database.app_url)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
require 'shrine/storage/memory'
|
|
62
|
+
Shrine.storages = {
|
|
63
|
+
cache: Shrine::Storage::Memory.new,
|
|
64
|
+
store: Shrine::Storage::Memory.new
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
Dir[File.expand_path('support/**/*.rb', __dir__)].each { |f| require f }
|
|
68
|
+
|
|
69
|
+
RSpec.configure do |c|
|
|
70
|
+
c.include Rack::Test::Methods, type: :web
|
|
71
|
+
c.include AuthHelpers, type: :web
|
|
72
|
+
c.define_derived_metadata(file_path: %r{/spec/web/}) { |m| m[:type] = :web }
|
|
73
|
+
c.define_derived_metadata(file_path: %r{/spec/models/}) { |m| m[:type] = :model }
|
|
74
|
+
c.define_derived_metadata(file_path: %r{/spec/daemons/}) { |m| m[:type] = :daemon }
|
|
75
|
+
|
|
76
|
+
c.before { Mail::TestMailer.deliveries.clear }
|
|
77
|
+
|
|
78
|
+
c.expect_with :rspec do |expectations|
|
|
79
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
c.mock_with :rspec do |mocks|
|
|
83
|
+
mocks.verify_partial_doubles = true
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
c.disable_monkey_patching!
|
|
87
|
+
c.warnings = false
|
|
88
|
+
c.order = :random
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def app
|
|
92
|
+
<%= @app.camel %>.app
|
|
93
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module AuditLogHelpers
|
|
4
|
+
# Reads through ADMIN_DB since the web role has INSERT-only on audit_log.audit_log. Returns the raw
|
|
5
|
+
# row Hash (row[:actor_id], not row.actor_id). Pass at least one scope, parallel workers share the test DB
|
|
6
|
+
def last_audit(action, status: nil, actor_id: nil, request_id: nil, actor_label: nil)
|
|
7
|
+
scope = ADMIN_DB[Sequel[:audit_log][:audit_log]]
|
|
8
|
+
.where(action_id: AuditAction.id_for!(action))
|
|
9
|
+
scope = scope.where(status_id: AuditStatus.id_for!(status)) if status
|
|
10
|
+
scope = scope.where(actor_id: actor_id) if actor_id
|
|
11
|
+
scope = scope.where(request_id: request_id) if request_id
|
|
12
|
+
scope = scope.where(actor_label: actor_label) if actor_label
|
|
13
|
+
scope.order(Sequel.desc(:occurred_at)).first
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def last_request_id
|
|
17
|
+
last_response.headers['X-Request-Id']
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
RSpec.configure { |c| c.include AuditLogHelpers, type: :web }
|
data/lib/roda_gen/generators/templates/project/spec/support/audit_lookup_shared_examples.rb.tt
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.shared_examples 'an audit lookup table' do |seeded_code|
|
|
4
|
+
it '.id_for! returns a numeric id for a seeded code' do
|
|
5
|
+
expect(described_class.id_for!(seeded_code)).to be_a(Integer)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it '.id_for! raises ArgumentError on an unknown code' do
|
|
9
|
+
expect { described_class.id_for!('does.not.exist') }
|
|
10
|
+
.to raise_error(ArgumentError, /Unknown audit/)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it '.refresh_cache! clears the memo so the next read re-queries' do
|
|
14
|
+
described_class.id_for!(seeded_code) # warm
|
|
15
|
+
described_class.refresh_cache!
|
|
16
|
+
expect(described_class.instance_variable_get(:@cache)).to be_nil
|
|
17
|
+
expect(described_class.id_for!(seeded_code)).to be_a(Integer) # re-populates
|
|
18
|
+
end
|
|
19
|
+
end
|