trusty-cms 7.1.3 → 7.2

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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +72 -68
  3. data/lib/string_extensions/string_extensions.rb +4 -2
  4. data/lib/trusty_cms/version.rb +1 -1
  5. data/spec/controllers/admin/assets_controller_spec.rb +124 -0
  6. data/spec/controllers/admin/changes_controller_spec.rb +72 -0
  7. data/spec/controllers/admin/configuration_controller_spec.rb +49 -0
  8. data/spec/controllers/admin/page_attachments_controller_spec.rb +54 -0
  9. data/spec/controllers/admin/pages_controller_spec.rb +162 -0
  10. data/spec/controllers/admin/preferences_controller_spec.rb +44 -0
  11. data/spec/controllers/admin/security_controller_spec.rb +85 -0
  12. data/spec/controllers/admin/sessions_controller_spec.rb +56 -0
  13. data/spec/controllers/admin/two_factor_controller_spec.rb +63 -0
  14. data/spec/controllers/admin/users_controller_spec.rb +132 -0
  15. data/spec/controllers/page_status_controller_spec.rb +66 -0
  16. data/spec/dummy/bin/rails +3 -3
  17. data/spec/dummy/bin/rake +2 -2
  18. data/spec/dummy/bin/setup +21 -13
  19. data/spec/dummy/config/boot.rb +1 -1
  20. data/spec/dummy/config/cable.yml +10 -0
  21. data/spec/dummy/config/initializers/content_security_policy.rb +25 -0
  22. data/spec/dummy/config/initializers/filter_parameter_logging.rb +6 -2
  23. data/spec/dummy/config/initializers/inflections.rb +4 -4
  24. data/spec/dummy/config/initializers/new_framework_defaults_7_2.rb +70 -0
  25. data/spec/dummy/config/initializers/permissions_policy.rb +13 -0
  26. data/spec/dummy/config/puma.rb +34 -0
  27. data/spec/dummy/config/storage.yml +28 -1
  28. data/spec/dummy/db/migrate/20260729201444_add_service_name_to_active_storage_blobs.active_storage.rb +22 -0
  29. data/spec/dummy/db/migrate/20260729201445_create_active_storage_variant_records.active_storage.rb +27 -0
  30. data/spec/dummy/db/migrate/20260729201446_remove_not_null_on_active_storage_blobs_checksum.active_storage.rb +8 -0
  31. data/spec/dummy/public/404.html +6 -6
  32. data/spec/dummy/public/406-unsupported-browser.html +66 -0
  33. data/spec/dummy/public/422.html +6 -6
  34. data/spec/dummy/public/500.html +6 -6
  35. data/spec/dummy/public/icon.png +0 -0
  36. data/spec/dummy/public/icon.svg +3 -0
  37. data/spec/dummy/public/robots.txt +1 -0
  38. data/spec/helpers/admin/configuration_helper_spec.rb +62 -0
  39. data/spec/helpers/admin/node_helper_spec.rb +132 -0
  40. data/spec/helpers/admin/pages_helper_spec.rb +84 -0
  41. data/spec/helpers/application_helper_spec.rb +115 -0
  42. data/spec/lib/string_extensions_spec.rb +41 -0
  43. data/spec/support/active_record_encryption.rb +10 -0
  44. data/spec/support/asset_type_registry.rb +29 -0
  45. data/trusty_cms.gemspec +1 -1
  46. metadata +68 -8
  47. data/spec/controllers/assets_controller.rb +0 -66
@@ -0,0 +1,10 @@
1
+ development:
2
+ adapter: async
3
+
4
+ test:
5
+ adapter: test
6
+
7
+ production:
8
+ adapter: redis
9
+ url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
10
+ channel_prefix: trusty_cms_production
@@ -0,0 +1,25 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Define an application-wide content security policy.
4
+ # See the Securing Rails Applications Guide for more information:
5
+ # https://guides.rubyonrails.org/security.html#content-security-policy-header
6
+
7
+ # Rails.application.configure do
8
+ # config.content_security_policy do |policy|
9
+ # policy.default_src :self, :https
10
+ # policy.font_src :self, :https, :data
11
+ # policy.img_src :self, :https, :data
12
+ # policy.object_src :none
13
+ # policy.script_src :self, :https
14
+ # policy.style_src :self, :https
15
+ # # Specify URI for violation reports
16
+ # # policy.report_uri "/csp-violation-report-endpoint"
17
+ # end
18
+ #
19
+ # # Generate session nonces for permitted importmap, inline scripts, and inline styles.
20
+ # config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s }
21
+ # config.content_security_policy_nonce_directives = %w(script-src style-src)
22
+ #
23
+ # # Report violations without enforcing the policy.
24
+ # # config.content_security_policy_report_only = true
25
+ # end
@@ -1,4 +1,8 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- # Configure sensitive parameters which will be filtered from the log file.
4
- Rails.application.config.filter_parameters += [:password]
3
+ # Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file.
4
+ # Use this to limit dissemination of sensitive information.
5
+ # See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors.
6
+ Rails.application.config.filter_parameters += [
7
+ :passw, :email, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn
8
+ ]
@@ -4,13 +4,13 @@
4
4
  # are locale specific, and you may define rules for as many different
5
5
  # locales as you wish. All of these examples are active by default:
6
6
  # ActiveSupport::Inflector.inflections(:en) do |inflect|
7
- # inflect.plural /^(ox)$/i, '\1en'
8
- # inflect.singular /^(ox)en/i, '\1'
9
- # inflect.irregular 'person', 'people'
7
+ # inflect.plural /^(ox)$/i, "\\1en"
8
+ # inflect.singular /^(ox)en/i, "\\1"
9
+ # inflect.irregular "person", "people"
10
10
  # inflect.uncountable %w( fish sheep )
11
11
  # end
12
12
 
13
13
  # These inflection rules are supported but not enabled by default:
14
14
  # ActiveSupport::Inflector.inflections(:en) do |inflect|
15
- # inflect.acronym 'RESTful'
15
+ # inflect.acronym "RESTful"
16
16
  # end
@@ -0,0 +1,70 @@
1
+ # Be sure to restart your server when you modify this file.
2
+ #
3
+ # This file eases your Rails 7.2 framework defaults upgrade.
4
+ #
5
+ # Uncomment each configuration one by one to switch to the new default.
6
+ # Once your application is ready to run with all new defaults, you can remove
7
+ # this file and set the `config.load_defaults` to `7.2`.
8
+ #
9
+ # Read the Guide for Upgrading Ruby on Rails for more info on each option.
10
+ # https://guides.rubyonrails.org/upgrading_ruby_on_rails.html
11
+
12
+ ###
13
+ # Controls whether Active Job's `#perform_later` and similar methods automatically defer
14
+ # the job queuing to after the current Active Record transaction is committed.
15
+ #
16
+ # Example:
17
+ # Topic.transaction do
18
+ # topic = Topic.create(...)
19
+ # NewTopicNotificationJob.perform_later(topic)
20
+ # end
21
+ #
22
+ # In this example, if the configuration is set to `:never`, the job will
23
+ # be enqueued immediately, even though the `Topic` hasn't been committed yet.
24
+ # Because of this, if the job is picked up almost immediately, or if the
25
+ # transaction doesn't succeed for some reason, the job will fail to find this
26
+ # topic in the database.
27
+ #
28
+ # If `enqueue_after_transaction_commit` is set to `:default`, the queue adapter
29
+ # will define the behaviour.
30
+ #
31
+ # Note: Active Job backends can disable this feature. This is generally done by
32
+ # backends that use the same database as Active Record as a queue, hence they
33
+ # don't need this feature.
34
+ #++
35
+ # Rails.application.config.active_job.enqueue_after_transaction_commit = :default
36
+
37
+ ###
38
+ # Adds image/webp to the list of content types Active Storage considers as an image
39
+ # Prevents automatic conversion to a fallback PNG, and assumes clients support WebP, as they support gif, jpeg, and png.
40
+ # This is possible due to broad browser support for WebP, but older browsers and email clients may still not support
41
+ # WebP. Requires imagemagick/libvips built with WebP support.
42
+ #++
43
+ # Rails.application.config.active_storage.web_image_content_types = %w[image/png image/jpeg image/gif image/webp]
44
+
45
+ ###
46
+ # Enable validation of migration timestamps. When set, an ActiveRecord::InvalidMigrationTimestampError
47
+ # will be raised if the timestamp prefix for a migration is more than a day ahead of the timestamp
48
+ # associated with the current time. This is done to prevent forward-dating of migration files, which can
49
+ # impact migration generation and other migration commands.
50
+ #
51
+ # Applications with existing timestamped migrations that do not adhere to the
52
+ # expected format can disable validation by setting this config to `false`.
53
+ #++
54
+ # Rails.application.config.active_record.validate_migration_timestamps = true
55
+
56
+ ###
57
+ # Controls whether the PostgresqlAdapter should decode dates automatically with manual queries.
58
+ #
59
+ # Example:
60
+ # ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.select_value("select '2024-01-01'::date") #=> Date
61
+ #
62
+ # This query used to return a `String`.
63
+ #++
64
+ # Rails.application.config.active_record.postgresql_adapter_decode_dates = true
65
+
66
+ ###
67
+ # Enables YJIT as of Ruby 3.3, to bring sizeable performance improvements. If you are
68
+ # deploying to a memory constrained environment you may want to set this to `false`.
69
+ #++
70
+ # Rails.application.config.yjit = true
@@ -0,0 +1,13 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Define an application-wide HTTP permissions policy. For further
4
+ # information see: https://developers.google.com/web/updates/2018/06/feature-policy
5
+
6
+ # Rails.application.config.permissions_policy do |policy|
7
+ # policy.camera :none
8
+ # policy.gyroscope :none
9
+ # policy.microphone :none
10
+ # policy.usb :none
11
+ # policy.fullscreen :self
12
+ # policy.payment :self, "https://secure.example.com"
13
+ # end
@@ -0,0 +1,34 @@
1
+ # This configuration file will be evaluated by Puma. The top-level methods that
2
+ # are invoked here are part of Puma's configuration DSL. For more information
3
+ # about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html.
4
+
5
+ # Puma starts a configurable number of processes (workers) and each process
6
+ # serves each request in a thread from an internal thread pool.
7
+ #
8
+ # The ideal number of threads per worker depends both on how much time the
9
+ # application spends waiting for IO operations and on how much you wish to
10
+ # to prioritize throughput over latency.
11
+ #
12
+ # As a rule of thumb, increasing the number of threads will increase how much
13
+ # traffic a given process can handle (throughput), but due to CRuby's
14
+ # Global VM Lock (GVL) it has diminishing returns and will degrade the
15
+ # response time (latency) of the application.
16
+ #
17
+ # The default is set to 3 threads as it's deemed a decent compromise between
18
+ # throughput and latency for the average Rails application.
19
+ #
20
+ # Any libraries that use a connection pool or another resource pool should
21
+ # be configured to provide at least as many connections as the number of
22
+ # threads. This includes Active Record's `pool` parameter in `database.yml`.
23
+ threads_count = ENV.fetch("RAILS_MAX_THREADS", 3)
24
+ threads threads_count, threads_count
25
+
26
+ # Specifies the `port` that Puma will listen on to receive requests; default is 3000.
27
+ port ENV.fetch("PORT", 3000)
28
+
29
+ # Allow puma to be restarted by `bin/rails restart` command.
30
+ plugin :tmp_restart
31
+
32
+ # Specify the PID file. Defaults to tmp/pids/server.pid in development.
33
+ # In other environments, only set the PID file if requested.
34
+ pidfile ENV["PIDFILE"] if ENV["PIDFILE"]
@@ -4,4 +4,31 @@ test:
4
4
 
5
5
  local:
6
6
  service: Disk
7
- root: <%= Rails.root.join("storage") %>
7
+ root: <%= Rails.root.join("storage") %>
8
+
9
+ # Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
10
+ # amazon:
11
+ # service: S3
12
+ # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
13
+ # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
14
+ # region: us-east-1
15
+ # bucket: your_own_bucket-<%= Rails.env %>
16
+
17
+ # Remember not to checkin your GCS keyfile to a repository
18
+ # google:
19
+ # service: GCS
20
+ # project: your_project
21
+ # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
22
+ # bucket: your_own_bucket-<%= Rails.env %>
23
+
24
+ # Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
25
+ # microsoft:
26
+ # service: AzureStorage
27
+ # storage_account_name: your_account_name
28
+ # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
29
+ # container: your_container_name-<%= Rails.env %>
30
+
31
+ # mirror:
32
+ # service: Mirror
33
+ # primary: local
34
+ # mirrors: [ amazon, google, microsoft ]
@@ -0,0 +1,22 @@
1
+ # This migration comes from active_storage (originally 20190112182829)
2
+ class AddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.0]
3
+ def up
4
+ return unless table_exists?(:active_storage_blobs)
5
+
6
+ unless column_exists?(:active_storage_blobs, :service_name)
7
+ add_column :active_storage_blobs, :service_name, :string
8
+
9
+ if configured_service = ActiveStorage::Blob.service.name
10
+ ActiveStorage::Blob.unscoped.update_all(service_name: configured_service)
11
+ end
12
+
13
+ change_column :active_storage_blobs, :service_name, :string, null: false
14
+ end
15
+ end
16
+
17
+ def down
18
+ return unless table_exists?(:active_storage_blobs)
19
+
20
+ remove_column :active_storage_blobs, :service_name
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+ # This migration comes from active_storage (originally 20191206030411)
2
+ class CreateActiveStorageVariantRecords < ActiveRecord::Migration[6.0]
3
+ def change
4
+ return unless table_exists?(:active_storage_blobs)
5
+
6
+ # Use Active Record's configured type for primary key
7
+ create_table :active_storage_variant_records, id: primary_key_type, if_not_exists: true do |t|
8
+ t.belongs_to :blob, null: false, index: false, type: blobs_primary_key_type
9
+ t.string :variation_digest, null: false
10
+
11
+ t.index %i[ blob_id variation_digest ], name: "index_active_storage_variant_records_uniqueness", unique: true
12
+ t.foreign_key :active_storage_blobs, column: :blob_id
13
+ end
14
+ end
15
+
16
+ private
17
+ def primary_key_type
18
+ config = Rails.configuration.generators
19
+ config.options[config.orm][:primary_key_type] || :primary_key
20
+ end
21
+
22
+ def blobs_primary_key_type
23
+ pkey_name = connection.primary_key(:active_storage_blobs)
24
+ pkey_column = connection.columns(:active_storage_blobs).find { |c| c.name == pkey_name }
25
+ pkey_column.bigint? ? :bigint : pkey_column.type
26
+ end
27
+ end
@@ -0,0 +1,8 @@
1
+ # This migration comes from active_storage (originally 20211119233751)
2
+ class RemoveNotNullOnActiveStorageBlobsChecksum < ActiveRecord::Migration[6.0]
3
+ def change
4
+ return unless table_exists?(:active_storage_blobs)
5
+
6
+ change_column_null(:active_storage_blobs, :checksum, true)
7
+ end
8
+ end
@@ -4,7 +4,7 @@
4
4
  <title>The page you were looking for doesn't exist (404)</title>
5
5
  <meta name="viewport" content="width=device-width,initial-scale=1">
6
6
  <style>
7
- body {
7
+ .rails-default-error-page {
8
8
  background-color: #EFEFEF;
9
9
  color: #2E2F30;
10
10
  text-align: center;
@@ -12,13 +12,13 @@
12
12
  margin: 0;
13
13
  }
14
14
 
15
- div.dialog {
15
+ .rails-default-error-page div.dialog {
16
16
  width: 95%;
17
17
  max-width: 33em;
18
18
  margin: 4em auto 0;
19
19
  }
20
20
 
21
- div.dialog > div {
21
+ .rails-default-error-page div.dialog > div {
22
22
  border: 1px solid #CCC;
23
23
  border-right-color: #999;
24
24
  border-left-color: #999;
@@ -31,13 +31,13 @@
31
31
  box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
32
  }
33
33
 
34
- h1 {
34
+ .rails-default-error-page h1 {
35
35
  font-size: 100%;
36
36
  color: #730E15;
37
37
  line-height: 1.5em;
38
38
  }
39
39
 
40
- div.dialog > p {
40
+ .rails-default-error-page div.dialog > p {
41
41
  margin: 0 0 1em;
42
42
  padding: 1em;
43
43
  background-color: #F7F7F7;
@@ -54,7 +54,7 @@
54
54
  </style>
55
55
  </head>
56
56
 
57
- <body>
57
+ <body class="rails-default-error-page">
58
58
  <!-- This file lives in public/404.html -->
59
59
  <div class="dialog">
60
60
  <div>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Your browser is not supported (406)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ .rails-default-error-page {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ .rails-default-error-page div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ .rails-default-error-page div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ .rails-default-error-page h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ .rails-default-error-page div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body class="rails-default-error-page">
58
+ <!-- This file lives in public/406-unsupported-browser.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>Your browser is not supported.</h1>
62
+ <p>Please upgrade your browser to continue.</p>
63
+ </div>
64
+ </div>
65
+ </body>
66
+ </html>
@@ -4,7 +4,7 @@
4
4
  <title>The change you wanted was rejected (422)</title>
5
5
  <meta name="viewport" content="width=device-width,initial-scale=1">
6
6
  <style>
7
- body {
7
+ .rails-default-error-page {
8
8
  background-color: #EFEFEF;
9
9
  color: #2E2F30;
10
10
  text-align: center;
@@ -12,13 +12,13 @@
12
12
  margin: 0;
13
13
  }
14
14
 
15
- div.dialog {
15
+ .rails-default-error-page div.dialog {
16
16
  width: 95%;
17
17
  max-width: 33em;
18
18
  margin: 4em auto 0;
19
19
  }
20
20
 
21
- div.dialog > div {
21
+ .rails-default-error-page div.dialog > div {
22
22
  border: 1px solid #CCC;
23
23
  border-right-color: #999;
24
24
  border-left-color: #999;
@@ -31,13 +31,13 @@
31
31
  box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
32
  }
33
33
 
34
- h1 {
34
+ .rails-default-error-page h1 {
35
35
  font-size: 100%;
36
36
  color: #730E15;
37
37
  line-height: 1.5em;
38
38
  }
39
39
 
40
- div.dialog > p {
40
+ .rails-default-error-page div.dialog > p {
41
41
  margin: 0 0 1em;
42
42
  padding: 1em;
43
43
  background-color: #F7F7F7;
@@ -54,7 +54,7 @@
54
54
  </style>
55
55
  </head>
56
56
 
57
- <body>
57
+ <body class="rails-default-error-page">
58
58
  <!-- This file lives in public/422.html -->
59
59
  <div class="dialog">
60
60
  <div>
@@ -4,7 +4,7 @@
4
4
  <title>We're sorry, but something went wrong (500)</title>
5
5
  <meta name="viewport" content="width=device-width,initial-scale=1">
6
6
  <style>
7
- body {
7
+ .rails-default-error-page {
8
8
  background-color: #EFEFEF;
9
9
  color: #2E2F30;
10
10
  text-align: center;
@@ -12,13 +12,13 @@
12
12
  margin: 0;
13
13
  }
14
14
 
15
- div.dialog {
15
+ .rails-default-error-page div.dialog {
16
16
  width: 95%;
17
17
  max-width: 33em;
18
18
  margin: 4em auto 0;
19
19
  }
20
20
 
21
- div.dialog > div {
21
+ .rails-default-error-page div.dialog > div {
22
22
  border: 1px solid #CCC;
23
23
  border-right-color: #999;
24
24
  border-left-color: #999;
@@ -31,13 +31,13 @@
31
31
  box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
32
  }
33
33
 
34
- h1 {
34
+ .rails-default-error-page h1 {
35
35
  font-size: 100%;
36
36
  color: #730E15;
37
37
  line-height: 1.5em;
38
38
  }
39
39
 
40
- div.dialog > p {
40
+ .rails-default-error-page div.dialog > p {
41
41
  margin: 0 0 1em;
42
42
  padding: 1em;
43
43
  background-color: #F7F7F7;
@@ -54,7 +54,7 @@
54
54
  </style>
55
55
  </head>
56
56
 
57
- <body>
57
+ <body class="rails-default-error-page">
58
58
  <!-- This file lives in public/500.html -->
59
59
  <div class="dialog">
60
60
  <div>
Binary file
@@ -0,0 +1,3 @@
1
+ <svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
2
+ <rect width="100%" height="100%" fill="red"/>
3
+ </svg>
@@ -0,0 +1 @@
1
+ # See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ # Exercises Admin::ConfigurationHelper, which renders TrustyCms::Config settings
4
+ # as read-only rows (show_config) and as edit fields (edit_config), branching on
5
+ # whether a setting is boolean, a selector, or free text.
6
+ describe Admin::ConfigurationHelper, type: :helper do
7
+ describe '#setting_for' do
8
+ it 'finds or initializes the config entry for a key' do
9
+ setting = helper.setting_for('admin.title')
10
+ expect(setting).to be_a(TrustyCms::Config)
11
+ expect(setting.key).to eq('admin.title')
12
+ end
13
+
14
+ it 'memoizes into @trusty_config' do
15
+ helper.setting_for('admin.title')
16
+ expect(helper.instance_variable_get(:@trusty_config)).to have_key('admin.title')
17
+ end
18
+ end
19
+
20
+ describe '#definition_for' do
21
+ it 'returns the setting definition' do
22
+ expect(helper.definition_for('admin.title')).to eq(TrustyCms.config.definition_for('admin.title'))
23
+ end
24
+ end
25
+
26
+ describe '#show_config' do
27
+ it 'renders a label and value span for a text setting' do
28
+ html = helper.show_config('admin.title')
29
+ expect(html).to include('<label')
30
+ expect(html).to include('id="admin_title"')
31
+ end
32
+
33
+ it 'renders yes/no for a boolean setting' do
34
+ html = helper.show_config('assets.create_image_thumbnails?')
35
+ expect(html).to match(/yes|no/i)
36
+ end
37
+
38
+ it 'includes a units span for a setting with units' do
39
+ html = helper.show_config('assets.max_asset_size')
40
+ expect(html).to include('class="units"')
41
+ end
42
+ end
43
+
44
+ describe '#edit_config' do
45
+ it 'renders a text field for a plain text setting' do
46
+ html = helper.edit_config('admin.title')
47
+ expect(html).to include('type="text"')
48
+ expect(html).to include('name="trusty_config[admin.title]"')
49
+ end
50
+
51
+ it 'renders a checkbox (plus hidden field) for a boolean setting' do
52
+ html = helper.edit_config('assets.create_image_thumbnails?')
53
+ expect(html).to include('type="checkbox"')
54
+ expect(html).to include('type="hidden"')
55
+ end
56
+
57
+ it 'renders a select for a selector setting' do
58
+ html = helper.edit_config('defaults.page.status')
59
+ expect(html).to include('<select')
60
+ end
61
+ end
62
+ end