10 | <% end %>
--------------------------------------------------------------------------------
/app/views/shared/_navigation.html.erb:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = function(api) {
2 | var validEnv = ['development', 'test', 'production']
3 | var currentEnv = api.env()
4 | var isDevelopmentEnv = api.env('development')
5 | var isProductionEnv = api.env('production')
6 | var isTestEnv = api.env('test')
7 |
8 | if (!validEnv.includes(currentEnv)) {
9 | throw new Error(
10 | 'Please specify a valid `NODE_ENV` or ' +
11 | '`BABEL_ENV` environment variables. Valid values are "development", ' +
12 | '"test", and "production". Instead, received: ' +
13 | JSON.stringify(currentEnv) +
14 | '.'
15 | )
16 | }
17 |
18 | return {
19 | presets: [
20 | isTestEnv && [
21 | '@babel/preset-env',
22 | {
23 | targets: {
24 | node: 'current'
25 | },
26 | modules: 'commonjs'
27 | },
28 | '@babel/preset-react'
29 | ],
30 | (isProductionEnv || isDevelopmentEnv) && [
31 | '@babel/preset-env',
32 | {
33 | forceAllTransforms: true,
34 | useBuiltIns: 'entry',
35 | corejs: 3,
36 | modules: false,
37 | exclude: ['transform-typeof-symbol']
38 | }
39 | ],
40 | [
41 | '@babel/preset-react',
42 | {
43 | development: isDevelopmentEnv || isTestEnv,
44 | useBuiltIns: true
45 | }
46 | ]
47 | ].filter(Boolean),
48 | plugins: [
49 | 'babel-plugin-macros',
50 | '@babel/plugin-syntax-dynamic-import',
51 | isTestEnv && 'babel-plugin-dynamic-import-node',
52 | '@babel/plugin-transform-destructuring',
53 | [
54 | '@babel/plugin-proposal-class-properties',
55 | {
56 | loose: true
57 | }
58 | ],
59 | [
60 | '@babel/plugin-proposal-object-rest-spread',
61 | {
62 | useBuiltIns: true
63 | }
64 | ],
65 | [
66 | '@babel/plugin-transform-runtime',
67 | {
68 | helpers: false,
69 | regenerator: true,
70 | corejs: false
71 | }
72 | ],
73 | [
74 | '@babel/plugin-transform-regenerator',
75 | {
76 | async: false
77 | }
78 | ],
79 | isProductionEnv && [
80 | 'babel-plugin-transform-react-remove-prop-types',
81 | {
82 | removeImport: true
83 | }
84 | ]
85 | ].filter(Boolean)
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/bin/bundle:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | # frozen_string_literal: true
3 |
4 | #
5 | # This file was generated by Bundler.
6 | #
7 | # The application 'bundle' is installed as part of a gem, and
8 | # this file is here to facilitate running it.
9 | #
10 |
11 | require "rubygems"
12 |
13 | m = Module.new do
14 | module_function
15 |
16 | def invoked_as_script?
17 | File.expand_path($0) == File.expand_path(__FILE__)
18 | end
19 |
20 | def env_var_version
21 | ENV["BUNDLER_VERSION"]
22 | end
23 |
24 | def cli_arg_version
25 | return unless invoked_as_script? # don't want to hijack other binstubs
26 | return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
27 | bundler_version = nil
28 | update_index = nil
29 | ARGV.each_with_index do |a, i|
30 | if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
31 | bundler_version = a
32 | end
33 | next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
34 | bundler_version = $1 || ">= 0.a"
35 | update_index = i
36 | end
37 | bundler_version
38 | end
39 |
40 | def gemfile
41 | gemfile = ENV["BUNDLE_GEMFILE"]
42 | return gemfile if gemfile && !gemfile.empty?
43 |
44 | File.expand_path("../../Gemfile", __FILE__)
45 | end
46 |
47 | def lockfile
48 | lockfile =
49 | case File.basename(gemfile)
50 | when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
51 | else "#{gemfile}.lock"
52 | end
53 | File.expand_path(lockfile)
54 | end
55 |
56 | def lockfile_version
57 | return unless File.file?(lockfile)
58 | lockfile_contents = File.read(lockfile)
59 | return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
60 | Regexp.last_match(1)
61 | end
62 |
63 | def bundler_version
64 | @bundler_version ||= begin
65 | env_var_version || cli_arg_version ||
66 | lockfile_version || "#{Gem::Requirement.default}.a"
67 | end
68 | end
69 |
70 | def load_bundler!
71 | ENV["BUNDLE_GEMFILE"] ||= gemfile
72 |
73 | # must dup string for RG < 1.8 compatibility
74 | activate_bundler(bundler_version.dup)
75 | end
76 |
77 | def activate_bundler(bundler_version)
78 | if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new("2.0")
79 | bundler_version = "< 2"
80 | end
81 | gem_error = activation_error_handling do
82 | gem "bundler", bundler_version
83 | end
84 | return if gem_error.nil?
85 | require_error = activation_error_handling do
86 | require "bundler/version"
87 | end
88 | return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION))
89 | warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`"
90 | exit 42
91 | end
92 |
93 | def activation_error_handling
94 | yield
95 | nil
96 | rescue StandardError, LoadError => e
97 | e
98 | end
99 | end
100 |
101 | m.load_bundler!
102 |
103 | if m.invoked_as_script?
104 | load Gem.bin_path("bundler", "bundle")
105 | end
106 |
--------------------------------------------------------------------------------
/bin/rails:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | begin
3 | load File.expand_path('../spring', __FILE__)
4 | rescue LoadError => e
5 | raise unless e.message.include?('spring')
6 | end
7 | APP_PATH = File.expand_path('../config/application', __dir__)
8 | require_relative '../config/boot'
9 | require 'rails/commands'
10 |
--------------------------------------------------------------------------------
/bin/rake:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | begin
3 | load File.expand_path('../spring', __FILE__)
4 | rescue LoadError => e
5 | raise unless e.message.include?('spring')
6 | end
7 | require_relative '../config/boot'
8 | require 'rake'
9 | Rake.application.run
10 |
--------------------------------------------------------------------------------
/bin/setup:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | require 'fileutils'
3 |
4 | # path to your application root.
5 | APP_ROOT = File.expand_path('..', __dir__)
6 |
7 | def system!(*args)
8 | system(*args) || abort("\n== Command #{args} failed ==")
9 | end
10 |
11 | FileUtils.chdir APP_ROOT do
12 | # This script is a way to setup or update your development environment automatically.
13 | # This script is idempotent, so that you can run it at anytime and get an expectable outcome.
14 | # Add necessary setup steps to this file.
15 |
16 | puts '== Installing dependencies =='
17 | system! 'gem install bundler --conservative'
18 | system('bundle check') || system!('bundle install')
19 |
20 | # Install JavaScript dependencies
21 | # system('bin/yarn')
22 |
23 | # puts "\n== Copying sample files =="
24 | # unless File.exist?('config/database.yml')
25 | # FileUtils.cp 'config/database.yml.sample', 'config/database.yml'
26 | # end
27 |
28 | puts "\n== Preparing database =="
29 | system! 'bin/rails db:prepare'
30 |
31 | puts "\n== Removing old logs and tempfiles =="
32 | system! 'bin/rails log:clear tmp:clear'
33 |
34 | puts "\n== Restarting application server =="
35 | system! 'bin/rails restart'
36 | end
37 |
--------------------------------------------------------------------------------
/bin/spring:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 |
3 | # This file loads Spring without using Bundler, in order to be fast.
4 | # It gets overwritten when you run the `spring binstub` command.
5 |
6 | unless defined?(Spring)
7 | require 'rubygems'
8 | require 'bundler'
9 |
10 | lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
11 | spring = lockfile.specs.detect { |spec| spec.name == 'spring' }
12 | if spring
13 | Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
14 | gem 'spring', spring.version
15 | require 'spring/binstub'
16 | end
17 | end
18 |
--------------------------------------------------------------------------------
/bin/webpack:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 |
3 | ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
4 | ENV["NODE_ENV"] ||= "development"
5 |
6 | require "pathname"
7 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
8 | Pathname.new(__FILE__).realpath)
9 |
10 | require "bundler/setup"
11 |
12 | require "webpacker"
13 | require "webpacker/webpack_runner"
14 |
15 | APP_ROOT = File.expand_path("..", __dir__)
16 | Dir.chdir(APP_ROOT) do
17 | Webpacker::WebpackRunner.run(ARGV)
18 | end
19 |
--------------------------------------------------------------------------------
/bin/webpack-dev-server:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 |
3 | ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
4 | ENV["NODE_ENV"] ||= "development"
5 |
6 | require "pathname"
7 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
8 | Pathname.new(__FILE__).realpath)
9 |
10 | require "bundler/setup"
11 |
12 | require "webpacker"
13 | require "webpacker/dev_server_runner"
14 |
15 | APP_ROOT = File.expand_path("..", __dir__)
16 | Dir.chdir(APP_ROOT) do
17 | Webpacker::DevServerRunner.run(ARGV)
18 | end
19 |
--------------------------------------------------------------------------------
/bin/yarn:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | APP_ROOT = File.expand_path('..', __dir__)
3 | Dir.chdir(APP_ROOT) do
4 | begin
5 | exec "yarnpkg", *ARGV
6 | rescue Errno::ENOENT
7 | $stderr.puts "Yarn executable was not detected in the system."
8 | $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
9 | exit 1
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/config.ru:
--------------------------------------------------------------------------------
1 | # This file is used by Rack-based servers to start the application.
2 |
3 | require_relative 'config/environment'
4 |
5 | run Rails.application
6 |
--------------------------------------------------------------------------------
/config/application.rb:
--------------------------------------------------------------------------------
1 | require_relative 'boot'
2 |
3 | require "rails"
4 | # Pick the frameworks you want:
5 | require "active_model/railtie"
6 | require "active_job/railtie"
7 | require "active_record/railtie"
8 | require "active_storage/engine"
9 | require "action_controller/railtie"
10 | require "action_mailer/railtie"
11 | require "action_mailbox/engine"
12 | require "action_text/engine"
13 | require "action_view/railtie"
14 | require "action_cable/engine"
15 | require "sprockets/railtie"
16 | # require "rails/test_unit/railtie"
17 |
18 | # Require the gems listed in Gemfile, including any gems
19 | # you've limited to :test, :development, or :production.
20 | Bundler.require(*Rails.groups)
21 |
22 | module RailsReactExample
23 | class Application < Rails::Application
24 | # Initialize configuration defaults for originally generated Rails version.
25 | config.load_defaults 6.0
26 |
27 | # Settings in config/environments/* take precedence over those specified here.
28 | # Application configuration can go into files in config/initializers
29 | # -- all .rb files in that directory are automatically loaded after loading
30 | # the framework and any gems in your application.
31 |
32 | # Don't generate system test files.
33 | config.generators.system_tests = nil
34 | end
35 | end
36 |
--------------------------------------------------------------------------------
/config/boot.rb:
--------------------------------------------------------------------------------
1 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
2 |
3 | require 'bundler/setup' # Set up gems listed in the Gemfile.
4 | require 'bootsnap/setup' # Speed up boot time by caching expensive operations.
5 |
--------------------------------------------------------------------------------
/config/cable.yml:
--------------------------------------------------------------------------------
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: rails_react_example_production
11 |
--------------------------------------------------------------------------------
/config/credentials.yml.enc:
--------------------------------------------------------------------------------
1 | +aBU89XICPyWZSvxKLFvFUemUqTIJs1d228PJMZZZHwDEXNdCZJBA9FjTF0jUqSi6RGazhDH7rTCcybWTQKaXQc3vJag1hfjHlEkxrY6qKIyqwQLOo0VKhjgs/uuDPPetKvjiWd1WGItXCixSaBCWMGyOXf21FfqrwKBbWv3JsQnjCQEoS43h1Uz0uBZxT663wsepoZ1Z13bvLJu5fKrzmK6QxODB5q7dBOxZ6Cy8T8qoJ334Jtr7sM/uZ8rmuG9I3NjLg8aBeH34EV9wx39ZSdib3qXliEb7I3F7aUY3ELe+iwO51SI43Wm+CikmAQvwukqy9L+d73oZQbV8syoJU0FW9qOg0S5GkqoXIa0H/OFsSDvGWg/gMzJPw+wtKfaIWYey78Gcsey/UpK+T1AkEHmUn8aIM8wxA2M--t8cslOzu2ve1cAdF--tPyZjViG6Z98GVXo1qQ7lg==
--------------------------------------------------------------------------------
/config/database.yml:
--------------------------------------------------------------------------------
1 | # PostgreSQL. Versions 9.3 and up are supported.
2 | #
3 | # Install the pg driver:
4 | # gem install pg
5 | # On macOS with Homebrew:
6 | # gem install pg -- --with-pg-config=/usr/local/bin/pg_config
7 | # On macOS with MacPorts:
8 | # gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
9 | # On Windows:
10 | # gem install pg
11 | # Choose the win32 build.
12 | # Install PostgreSQL and put its /bin directory on your path.
13 | #
14 | # Configure Using Gemfile
15 | # gem 'pg'
16 | #
17 | default: &default
18 | adapter: postgresql
19 | encoding: unicode
20 | # For details on connection pooling, see Rails configuration guide
21 | # https://guides.rubyonrails.org/configuring.html#database-pooling
22 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
23 |
24 | development:
25 | <<: *default
26 | database: rails_react_example_development
27 |
28 | # The specified database role being used to connect to postgres.
29 | # To create additional roles in postgres see `$ createuser --help`.
30 | # When left blank, postgres will use the default role. This is
31 | # the same name as the operating system user that initialized the database.
32 | #username: rails_react_example
33 |
34 | # The password associated with the postgres role (username).
35 | #password:
36 |
37 | # Connect on a TCP socket. Omitted by default since the client uses a
38 | # domain socket that doesn't need configuration. Windows does not have
39 | # domain sockets, so uncomment these lines.
40 | #host: localhost
41 |
42 | # The TCP port the server listens on. Defaults to 5432.
43 | # If your server runs on a different port number, change accordingly.
44 | #port: 5432
45 |
46 | # Schema search path. The server defaults to $user,public
47 | #schema_search_path: myapp,sharedapp,public
48 |
49 | # Minimum log levels, in increasing order:
50 | # debug5, debug4, debug3, debug2, debug1,
51 | # log, notice, warning, error, fatal, and panic
52 | # Defaults to warning.
53 | #min_messages: notice
54 |
55 | # Warning: The database defined as "test" will be erased and
56 | # re-generated from your development database when you run "rake".
57 | # Do not set this db to the same as development or production.
58 | test:
59 | <<: *default
60 | database: rails_react_example_test
61 |
62 | # As with config/credentials.yml, you never want to store sensitive information,
63 | # like your database password, in your source code. If your source code is
64 | # ever seen by anyone, they now have access to your database.
65 | #
66 | # Instead, provide the password as a unix environment variable when you boot
67 | # the app. Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
68 | # for a full rundown on how to provide these environment variables in a
69 | # production deployment.
70 | #
71 | # On Heroku and other platform providers, you may have a full connection URL
72 | # available as an environment variable. For example:
73 | #
74 | # DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
75 | #
76 | # You can use this database configuration with:
77 | #
78 | # production:
79 | # url: <%= ENV['DATABASE_URL'] %>
80 | #
81 | production:
82 | <<: *default
83 | database: rails_react_example_production
84 | username: rails_react_example
85 | password: <%= ENV['RAILS_REACT_EXAMPLE_DATABASE_PASSWORD'] %>
86 |
--------------------------------------------------------------------------------
/config/environment.rb:
--------------------------------------------------------------------------------
1 | # Load the Rails application.
2 | require_relative 'application'
3 |
4 | # Initialize the Rails application.
5 | Rails.application.initialize!
6 |
--------------------------------------------------------------------------------
/config/environments/development.rb:
--------------------------------------------------------------------------------
1 | Rails.application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # In the development environment your application's code is reloaded on
5 | # every request. This slows down response time but is perfect for development
6 | # since you don't have to restart the web server when you make code changes.
7 | config.cache_classes = false
8 |
9 | # Do not eager load code on boot.
10 | config.eager_load = false
11 |
12 | # Show full error reports.
13 | config.consider_all_requests_local = true
14 |
15 | # Enable/disable caching. By default caching is disabled.
16 | # Run rails dev:cache to toggle caching.
17 | if Rails.root.join('tmp', 'caching-dev.txt').exist?
18 | config.action_controller.perform_caching = true
19 | config.action_controller.enable_fragment_cache_logging = true
20 |
21 | config.cache_store = :memory_store
22 | config.public_file_server.headers = {
23 | 'Cache-Control' => "public, max-age=#{2.days.to_i}"
24 | }
25 | else
26 | config.action_controller.perform_caching = false
27 |
28 | config.cache_store = :null_store
29 | end
30 |
31 | # Store uploaded files on the local file system (see config/storage.yml for options).
32 | config.active_storage.service = :local
33 |
34 | # Don't care if the mailer can't send.
35 | config.action_mailer.raise_delivery_errors = false
36 |
37 | config.action_mailer.perform_caching = false
38 | config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
39 |
40 | # Print deprecation notices to the Rails logger.
41 | config.active_support.deprecation = :log
42 |
43 | # Raise an error on page load if there are pending migrations.
44 | config.active_record.migration_error = :page_load
45 |
46 | # Highlight code that triggered database queries in logs.
47 | config.active_record.verbose_query_logs = true
48 |
49 | # Debug mode disables concatenation and preprocessing of assets.
50 | # This option may cause significant delays in view rendering with a large
51 | # number of complex assets.
52 | config.assets.debug = true
53 |
54 | # Suppress logger output for asset requests.
55 | config.assets.quiet = true
56 |
57 | # Raises error for missing translations.
58 | # config.action_view.raise_on_missing_translations = true
59 |
60 | # Use an evented file watcher to asynchronously detect changes in source code,
61 | # routes, locales, etc. This feature depends on the listen gem.
62 | config.file_watcher = ActiveSupport::EventedFileUpdateChecker
63 | end
64 |
--------------------------------------------------------------------------------
/config/environments/production.rb:
--------------------------------------------------------------------------------
1 | Rails.application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # Code is not reloaded between requests.
5 | config.cache_classes = true
6 |
7 | # Eager load code on boot. This eager loads most of Rails and
8 | # your application in memory, allowing both threaded web servers
9 | # and those relying on copy on write to perform better.
10 | # Rake tasks automatically ignore this option for performance.
11 | config.eager_load = true
12 |
13 | # Full error reports are disabled and caching is turned on.
14 | config.consider_all_requests_local = false
15 | config.action_controller.perform_caching = true
16 |
17 | # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
18 | # or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
19 | # config.require_master_key = true
20 |
21 | # Disable serving static files from the `/public` folder by default since
22 | # Apache or NGINX already handles this.
23 | config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
24 |
25 | # Compress CSS using a preprocessor.
26 | # config.assets.css_compressor = :sass
27 |
28 | # Do not fallback to assets pipeline if a precompiled asset is missed.
29 | config.assets.compile = false
30 |
31 | # Enable serving of images, stylesheets, and JavaScripts from an asset server.
32 | # config.action_controller.asset_host = 'http://assets.example.com'
33 |
34 | # Specifies the header that your server uses for sending files.
35 | # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
36 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
37 |
38 | # Store uploaded files on the local file system (see config/storage.yml for options).
39 | config.active_storage.service = :local
40 |
41 | # Mount Action Cable outside main process or domain.
42 | # config.action_cable.mount_path = nil
43 | # config.action_cable.url = 'wss://example.com/cable'
44 | # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
45 |
46 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
47 | # config.force_ssl = true
48 |
49 | # Use the lowest log level to ensure availability of diagnostic information
50 | # when problems arise.
51 | config.log_level = :debug
52 |
53 | # Prepend all log lines with the following tags.
54 | config.log_tags = [ :request_id ]
55 |
56 | # Use a different cache store in production.
57 | # config.cache_store = :mem_cache_store
58 |
59 | # Use a real queuing backend for Active Job (and separate queues per environment).
60 | # config.active_job.queue_adapter = :resque
61 | # config.active_job.queue_name_prefix = "rails_react_example_production"
62 |
63 | config.action_mailer.perform_caching = false
64 |
65 | # Ignore bad email addresses and do not raise email delivery errors.
66 | # Set this to true and configure the email server for immediate delivery to raise delivery errors.
67 | # config.action_mailer.raise_delivery_errors = false
68 |
69 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
70 | # the I18n.default_locale when a translation cannot be found).
71 | config.i18n.fallbacks = true
72 |
73 | # Send deprecation notices to registered listeners.
74 | config.active_support.deprecation = :notify
75 |
76 | # Use default logging formatter so that PID and timestamp are not suppressed.
77 | config.log_formatter = ::Logger::Formatter.new
78 |
79 | # Use a different logger for distributed setups.
80 | # require 'syslog/logger'
81 | # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
82 |
83 | if ENV["RAILS_LOG_TO_STDOUT"].present?
84 | logger = ActiveSupport::Logger.new(STDOUT)
85 | logger.formatter = config.log_formatter
86 | config.logger = ActiveSupport::TaggedLogging.new(logger)
87 | end
88 |
89 | # Do not dump schema after migrations.
90 | config.active_record.dump_schema_after_migration = false
91 |
92 | # Inserts middleware to perform automatic connection switching.
93 | # The `database_selector` hash is used to pass options to the DatabaseSelector
94 | # middleware. The `delay` is used to determine how long to wait after a write
95 | # to send a subsequent read to the primary.
96 | #
97 | # The `database_resolver` class is used by the middleware to determine which
98 | # database is appropriate to use based on the time delay.
99 | #
100 | # The `database_resolver_context` class is used by the middleware to set
101 | # timestamps for the last write to the primary. The resolver uses the context
102 | # class timestamps to determine how long to wait before reading from the
103 | # replica.
104 | #
105 | # By default Rails will store a last write timestamp in the session. The
106 | # DatabaseSelector middleware is designed as such you can define your own
107 | # strategy for connection switching and pass that into the middleware through
108 | # these configuration options.
109 | # config.active_record.database_selector = { delay: 2.seconds }
110 | # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
111 | # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
112 | end
113 |
--------------------------------------------------------------------------------
/config/environments/test.rb:
--------------------------------------------------------------------------------
1 | # The test environment is used exclusively to run your application's
2 | # test suite. You never need to work with it otherwise. Remember that
3 | # your test database is "scratch space" for the test suite and is wiped
4 | # and recreated between test runs. Don't rely on the data there!
5 |
6 | Rails.application.configure do
7 | # Settings specified here will take precedence over those in config/application.rb.
8 |
9 | config.cache_classes = false
10 |
11 | # Do not eager load code on boot. This avoids loading your whole application
12 | # just for the purpose of running a single test. If you are using a tool that
13 | # preloads Rails for running tests, you may have to set it to true.
14 | config.eager_load = false
15 |
16 | # Configure public file server for tests with Cache-Control for performance.
17 | config.public_file_server.enabled = true
18 | config.public_file_server.headers = {
19 | 'Cache-Control' => "public, max-age=#{1.hour.to_i}"
20 | }
21 |
22 | # Show full error reports and disable caching.
23 | config.consider_all_requests_local = true
24 | config.action_controller.perform_caching = false
25 | config.cache_store = :null_store
26 |
27 | # Raise exceptions instead of rendering exception templates.
28 | config.action_dispatch.show_exceptions = false
29 |
30 | # Disable request forgery protection in test environment.
31 | config.action_controller.allow_forgery_protection = false
32 |
33 | # Store uploaded files on the local file system in a temporary directory.
34 | config.active_storage.service = :test
35 |
36 | config.action_mailer.perform_caching = false
37 |
38 | # Tell Action Mailer not to deliver emails to the real world.
39 | # The :test delivery method accumulates sent emails in the
40 | # ActionMailer::Base.deliveries array.
41 | config.action_mailer.delivery_method = :test
42 |
43 | # Print deprecation notices to the stderr.
44 | config.active_support.deprecation = :stderr
45 |
46 | # Raises error for missing translations.
47 | # config.action_view.raise_on_missing_translations = true
48 | end
49 |
--------------------------------------------------------------------------------
/config/initializers/application_controller_renderer.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # ActiveSupport::Reloader.to_prepare do
4 | # ApplicationController.renderer.defaults.merge!(
5 | # http_host: 'example.org',
6 | # https: false
7 | # )
8 | # end
9 |
--------------------------------------------------------------------------------
/config/initializers/assets.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Version of your assets, change this if you want to expire all your assets.
4 | Rails.application.config.assets.version = '1.0'
5 |
6 | # Add additional assets to the asset load path.
7 | # Rails.application.config.assets.paths << Emoji.images_path
8 | # Add Yarn node_modules folder to the asset load path.
9 | Rails.application.config.assets.paths << Rails.root.join('node_modules')
10 |
11 | # Precompile additional assets.
12 | # application.js, application.css, and all non-JS/CSS in the app/assets
13 | # folder are already added.
14 | # Rails.application.config.assets.precompile += %w( admin.js admin.css )
15 |
--------------------------------------------------------------------------------
/config/initializers/backtrace_silencers.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5 |
6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7 | # Rails.backtrace_cleaner.remove_silencers!
8 |
--------------------------------------------------------------------------------
/config/initializers/content_security_policy.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Define an application-wide content security policy
4 | # For further information see the following documentation
5 | # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
6 |
7 | # Rails.application.config.content_security_policy do |policy|
8 | # policy.default_src :self, :https
9 | # policy.font_src :self, :https, :data
10 | # policy.img_src :self, :https, :data
11 | # policy.object_src :none
12 | # policy.script_src :self, :https
13 | # policy.style_src :self, :https
14 | # # If you are using webpack-dev-server then specify webpack-dev-server host
15 | # policy.connect_src :self, :https, "http://localhost:3035", "ws://localhost:3035" if Rails.env.development?
16 |
17 | # # Specify URI for violation reports
18 | # # policy.report_uri "/csp-violation-report-endpoint"
19 | # end
20 |
21 | # If you are using UJS then enable automatic nonce generation
22 | # Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) }
23 |
24 | # Set the nonce only to specific directives
25 | # Rails.application.config.content_security_policy_nonce_directives = %w(script-src)
26 |
27 | # Report CSP violations to a specified URI
28 | # For further information see the following documentation:
29 | # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only
30 | # Rails.application.config.content_security_policy_report_only = true
31 |
--------------------------------------------------------------------------------
/config/initializers/cookies_serializer.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Specify a serializer for the signed and encrypted cookie jars.
4 | # Valid options are :json, :marshal, and :hybrid.
5 | Rails.application.config.action_dispatch.cookies_serializer = :json
6 |
--------------------------------------------------------------------------------
/config/initializers/devise.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | # Use this hook to configure devise mailer, warden hooks and so forth.
4 | # Many of these configuration options can be set straight in your model.
5 | Devise.setup do |config|
6 | # The secret key used by Devise. Devise uses this key to generate
7 | # random tokens. Changing this key will render invalid all existing
8 | # confirmation, reset password and unlock tokens in the database.
9 | # Devise will use the `secret_key_base` as its `secret_key`
10 | # by default. You can change it below and use your own secret key.
11 | # config.secret_key = 'f714f9ce26d4713935e45376d904e3a1ec7b95e0c6d4eac8d8581aa0bb328954c10d67c430bc181846445c5a0b7e931fdadbae849abcb0a1a5028004b46bdf43'
12 |
13 | # ==> Controller configuration
14 | # Configure the parent class to the devise controllers.
15 | # config.parent_controller = 'DeviseController'
16 |
17 | # ==> Mailer Configuration
18 | # Configure the e-mail address which will be shown in Devise::Mailer,
19 | # note that it will be overwritten if you use your own mailer class
20 | # with default "from" parameter.
21 | config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'
22 |
23 | # Configure the class responsible to send e-mails.
24 | # config.mailer = 'Devise::Mailer'
25 |
26 | # Configure the parent class responsible to send e-mails.
27 | # config.parent_mailer = 'ActionMailer::Base'
28 |
29 | # ==> ORM configuration
30 | # Load and configure the ORM. Supports :active_record (default) and
31 | # :mongoid (bson_ext recommended) by default. Other ORMs may be
32 | # available as additional gems.
33 | require 'devise/orm/active_record'
34 |
35 | # ==> Configuration for any authentication mechanism
36 | # Configure which keys are used when authenticating a user. The default is
37 | # just :email. You can configure it to use [:username, :subdomain], so for
38 | # authenticating a user, both parameters are required. Remember that those
39 | # parameters are used only when authenticating and not when retrieving from
40 | # session. If you need permissions, you should implement that in a before filter.
41 | # You can also supply a hash where the value is a boolean determining whether
42 | # or not authentication should be aborted when the value is not present.
43 | # config.authentication_keys = [:email]
44 |
45 | # Configure parameters from the request object used for authentication. Each entry
46 | # given should be a request method and it will automatically be passed to the
47 | # find_for_authentication method and considered in your model lookup. For instance,
48 | # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
49 | # The same considerations mentioned for authentication_keys also apply to request_keys.
50 | # config.request_keys = []
51 |
52 | # Configure which authentication keys should be case-insensitive.
53 | # These keys will be downcased upon creating or modifying a user and when used
54 | # to authenticate or find a user. Default is :email.
55 | config.case_insensitive_keys = [:email]
56 |
57 | # Configure which authentication keys should have whitespace stripped.
58 | # These keys will have whitespace before and after removed upon creating or
59 | # modifying a user and when used to authenticate or find a user. Default is :email.
60 | config.strip_whitespace_keys = [:email]
61 |
62 | # Tell if authentication through request.params is enabled. True by default.
63 | # It can be set to an array that will enable params authentication only for the
64 | # given strategies, for example, `config.params_authenticatable = [:database]` will
65 | # enable it only for database (email + password) authentication.
66 | # config.params_authenticatable = true
67 |
68 | # Tell if authentication through HTTP Auth is enabled. False by default.
69 | # It can be set to an array that will enable http authentication only for the
70 | # given strategies, for example, `config.http_authenticatable = [:database]` will
71 | # enable it only for database authentication. The supported strategies are:
72 | # :database = Support basic authentication with authentication key + password
73 | # config.http_authenticatable = false
74 |
75 | # If 401 status code should be returned for AJAX requests. True by default.
76 | # config.http_authenticatable_on_xhr = true
77 |
78 | # The realm used in Http Basic Authentication. 'Application' by default.
79 | # config.http_authentication_realm = 'Application'
80 |
81 | # It will change confirmation, password recovery and other workflows
82 | # to behave the same regardless if the e-mail provided was right or wrong.
83 | # Does not affect registerable.
84 | # config.paranoid = true
85 |
86 | # By default Devise will store the user in session. You can skip storage for
87 | # particular strategies by setting this option.
88 | # Notice that if you are skipping storage for all authentication paths, you
89 | # may want to disable generating routes to Devise's sessions controller by
90 | # passing skip: :sessions to `devise_for` in your config/routes.rb
91 | config.skip_session_storage = [:http_auth]
92 |
93 | # By default, Devise cleans up the CSRF token on authentication to
94 | # avoid CSRF token fixation attacks. This means that, when using AJAX
95 | # requests for sign in and sign up, you need to get a new CSRF token
96 | # from the server. You can disable this option at your own risk.
97 | # config.clean_up_csrf_token_on_authentication = true
98 |
99 | # When false, Devise will not attempt to reload routes on eager load.
100 | # This can reduce the time taken to boot the app but if your application
101 | # requires the Devise mappings to be loaded during boot time the application
102 | # won't boot properly.
103 | # config.reload_routes = true
104 |
105 | # ==> Configuration for :database_authenticatable
106 | # For bcrypt, this is the cost for hashing the password and defaults to 11. If
107 | # using other algorithms, it sets how many times you want the password to be hashed.
108 | #
109 | # Limiting the stretches to just one in testing will increase the performance of
110 | # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
111 | # a value less than 10 in other environments. Note that, for bcrypt (the default
112 | # algorithm), the cost increases exponentially with the number of stretches (e.g.
113 | # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation).
114 | config.stretches = Rails.env.test? ? 1 : 11
115 |
116 | # Set up a pepper to generate the hashed password.
117 | # config.pepper = '74805d92323943b7b84bee7a64fa657d93560c42efc57a2144b5db33c9e4a0b520529f43ab71a3643bb14d21670f48bbe677a8509e44c98c78a0e04ee4c5462c'
118 |
119 | # Send a notification to the original email when the user's email is changed.
120 | # config.send_email_changed_notification = false
121 |
122 | # Send a notification email when the user's password is changed.
123 | # config.send_password_change_notification = false
124 |
125 | # ==> Configuration for :confirmable
126 | # A period that the user is allowed to access the website even without
127 | # confirming their account. For instance, if set to 2.days, the user will be
128 | # able to access the website for two days without confirming their account,
129 | # access will be blocked just in the third day.
130 | # You can also set it to nil, which will allow the user to access the website
131 | # without confirming their account.
132 | # Default is 0.days, meaning the user cannot access the website without
133 | # confirming their account.
134 | # config.allow_unconfirmed_access_for = 2.days
135 |
136 | # A period that the user is allowed to confirm their account before their
137 | # token becomes invalid. For example, if set to 3.days, the user can confirm
138 | # their account within 3 days after the mail was sent, but on the fourth day
139 | # their account can't be confirmed with the token any more.
140 | # Default is nil, meaning there is no restriction on how long a user can take
141 | # before confirming their account.
142 | # config.confirm_within = 3.days
143 |
144 | # If true, requires any email changes to be confirmed (exactly the same way as
145 | # initial account confirmation) to be applied. Requires additional unconfirmed_email
146 | # db field (see migrations). Until confirmed, new email is stored in
147 | # unconfirmed_email column, and copied to email column on successful confirmation.
148 | config.reconfirmable = true
149 |
150 | # Defines which key will be used when confirming an account
151 | # config.confirmation_keys = [:email]
152 |
153 | # ==> Configuration for :rememberable
154 | # The time the user will be remembered without asking for credentials again.
155 | # config.remember_for = 2.weeks
156 |
157 | # Invalidates all the remember me tokens when the user signs out.
158 | config.expire_all_remember_me_on_sign_out = true
159 |
160 | # If true, extends the user's remember period when remembered via cookie.
161 | # config.extend_remember_period = false
162 |
163 | # Options to be passed to the created cookie. For instance, you can set
164 | # secure: true in order to force SSL only cookies.
165 | # config.rememberable_options = {}
166 |
167 | # ==> Configuration for :validatable
168 | # Range for password length.
169 | config.password_length = 6..128
170 |
171 | # Email regex used to validate email formats. It simply asserts that
172 | # one (and only one) @ exists in the given string. This is mainly
173 | # to give user feedback and not to assert the e-mail validity.
174 | config.email_regexp = /\A[^@\s]+@[^@\s]+\z/
175 |
176 | # ==> Configuration for :timeoutable
177 | # The time you want to timeout the user session without activity. After this
178 | # time the user will be asked for credentials again. Default is 30 minutes.
179 | # config.timeout_in = 30.minutes
180 |
181 | # ==> Configuration for :lockable
182 | # Defines which strategy will be used to lock an account.
183 | # :failed_attempts = Locks an account after a number of failed attempts to sign in.
184 | # :none = No lock strategy. You should handle locking by yourself.
185 | # config.lock_strategy = :failed_attempts
186 |
187 | # Defines which key will be used when locking and unlocking an account
188 | # config.unlock_keys = [:email]
189 |
190 | # Defines which strategy will be used to unlock an account.
191 | # :email = Sends an unlock link to the user email
192 | # :time = Re-enables login after a certain amount of time (see :unlock_in below)
193 | # :both = Enables both strategies
194 | # :none = No unlock strategy. You should handle unlocking by yourself.
195 | # config.unlock_strategy = :both
196 |
197 | # Number of authentication tries before locking an account if lock_strategy
198 | # is failed attempts.
199 | # config.maximum_attempts = 20
200 |
201 | # Time interval to unlock the account if :time is enabled as unlock_strategy.
202 | # config.unlock_in = 1.hour
203 |
204 | # Warn on the last attempt before the account is locked.
205 | # config.last_attempt_warning = true
206 |
207 | # ==> Configuration for :recoverable
208 | #
209 | # Defines which key will be used when recovering the password for an account
210 | # config.reset_password_keys = [:email]
211 |
212 | # Time interval you can reset your password with a reset password key.
213 | # Don't put a too small interval or your users won't have the time to
214 | # change their passwords.
215 | config.reset_password_within = 6.hours
216 |
217 | # When set to false, does not sign a user in automatically after their password is
218 | # reset. Defaults to true, so a user is signed in automatically after a reset.
219 | # config.sign_in_after_reset_password = true
220 |
221 | # ==> Configuration for :encryptable
222 | # Allow you to use another hashing or encryption algorithm besides bcrypt (default).
223 | # You can use :sha1, :sha512 or algorithms from others authentication tools as
224 | # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20
225 | # for default behavior) and :restful_authentication_sha1 (then you should set
226 | # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper).
227 | #
228 | # Require the `devise-encryptable` gem when using anything other than bcrypt
229 | # config.encryptor = :sha512
230 |
231 | # ==> Scopes configuration
232 | # Turn scoped views on. Before rendering "sessions/new", it will first check for
233 | # "users/sessions/new". It's turned off by default because it's slower if you
234 | # are using only default views.
235 | # config.scoped_views = false
236 |
237 | # Configure the default scope given to Warden. By default it's the first
238 | # devise role declared in your routes (usually :user).
239 | # config.default_scope = :user
240 |
241 | # Set this configuration to false if you want /users/sign_out to sign out
242 | # only the current scope. By default, Devise signs out all scopes.
243 | # config.sign_out_all_scopes = true
244 |
245 | # ==> Navigation configuration
246 | # Lists the formats that should be treated as navigational. Formats like
247 | # :html, should redirect to the sign in page when the user does not have
248 | # access, but formats like :xml or :json, should return 401.
249 | #
250 | # If you have any extra navigational formats, like :iphone or :mobile, you
251 | # should add them to the navigational formats lists.
252 | #
253 | # The "*/*" below is required to match Internet Explorer requests.
254 | # config.navigational_formats = ['*/*', :html]
255 |
256 | # The default HTTP method used to sign out a resource. Default is :delete.
257 | config.sign_out_via = :delete
258 |
259 | # ==> OmniAuth
260 | # Add a new OmniAuth provider. Check the wiki for more information on setting
261 | # up on your models and hooks.
262 | # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
263 |
264 | # ==> Warden configuration
265 | # If you want to use other strategies, that are not supported by Devise, or
266 | # change the failure app, you can configure them inside the config.warden block.
267 | #
268 | # config.warden do |manager|
269 | # manager.intercept_401 = false
270 | # manager.default_strategies(scope: :user).unshift :some_external_strategy
271 | # end
272 |
273 | # ==> Mountable engine configurations
274 | # When using Devise inside an engine, let's call it `MyEngine`, and this engine
275 | # is mountable, there are some extra configurations to be taken into account.
276 | # The following options are available, assuming the engine is mounted as:
277 | #
278 | # mount MyEngine, at: '/my_engine'
279 | #
280 | # The router that invoked `devise_for`, in the example above, would be:
281 | # config.router_name = :my_engine
282 | #
283 | # When using OmniAuth, Devise cannot automatically set OmniAuth path,
284 | # so you need to do it manually. For the users scope, it would be:
285 | # config.omniauth_path_prefix = '/my_engine/users/auth'
286 |
287 | # ==> Turbolinks configuration
288 | # If your app is using Turbolinks, Turbolinks::Controller needs to be included to make redirection work correctly:
289 | #
290 | # ActiveSupport.on_load(:devise_failure_app) do
291 | # include Turbolinks::Controller
292 | # end
293 |
294 | # ==> Configuration for :registerable
295 |
296 | # When set to false, does not sign a user in automatically after their password is
297 | # changed. Defaults to true, so a user is signed in automatically after changing a password.
298 | # config.sign_in_after_change_password = true
299 | end
300 |
--------------------------------------------------------------------------------
/config/initializers/filter_parameter_logging.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Configure sensitive parameters which will be filtered from the log file.
4 | Rails.application.config.filter_parameters += [:password]
5 |
--------------------------------------------------------------------------------
/config/initializers/inflections.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new inflection rules using the following format. Inflections
4 | # are locale specific, and you may define rules for as many different
5 | # locales as you wish. All of these examples are active by default:
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'
10 | # inflect.uncountable %w( fish sheep )
11 | # end
12 |
13 | # These inflection rules are supported but not enabled by default:
14 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
15 | # inflect.acronym 'RESTful'
16 | # end
17 |
--------------------------------------------------------------------------------
/config/initializers/mime_types.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new mime types for use in respond_to blocks:
4 | # Mime::Type.register "text/richtext", :rtf
5 |
--------------------------------------------------------------------------------
/config/initializers/wrap_parameters.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # This file contains settings for ActionController::ParamsWrapper which
4 | # is enabled by default.
5 |
6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7 | ActiveSupport.on_load(:action_controller) do
8 | wrap_parameters format: [:json]
9 | end
10 |
11 | # To enable root element in JSON for ActiveRecord objects.
12 | # ActiveSupport.on_load(:active_record) do
13 | # self.include_root_in_json = true
14 | # end
15 |
--------------------------------------------------------------------------------
/config/locales/devise.en.yml:
--------------------------------------------------------------------------------
1 | # Additional translations at https://github.com/plataformatec/devise/wiki/I18n
2 |
3 | en:
4 | devise:
5 | confirmations:
6 | confirmed: "Your email address has been successfully confirmed."
7 | send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes."
8 | send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes."
9 | failure:
10 | already_authenticated: "You are already signed in."
11 | inactive: "Your account is not activated yet."
12 | invalid: "Invalid %{authentication_keys} or password."
13 | locked: "Your account is locked."
14 | last_attempt: "You have one more attempt before your account is locked."
15 | not_found_in_database: "Invalid %{authentication_keys} or password."
16 | timeout: "Your session expired. Please sign in again to continue."
17 | unauthenticated: "You need to sign in or sign up before continuing."
18 | unconfirmed: "You have to confirm your email address before continuing."
19 | mailer:
20 | confirmation_instructions:
21 | subject: "Confirmation instructions"
22 | reset_password_instructions:
23 | subject: "Reset password instructions"
24 | unlock_instructions:
25 | subject: "Unlock instructions"
26 | email_changed:
27 | subject: "Email Changed"
28 | password_change:
29 | subject: "Password Changed"
30 | omniauth_callbacks:
31 | failure: "Could not authenticate you from %{kind} because \"%{reason}\"."
32 | success: "Successfully authenticated from %{kind} account."
33 | passwords:
34 | no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
35 | send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes."
36 | send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
37 | updated: "Your password has been changed successfully. You are now signed in."
38 | updated_not_active: "Your password has been changed successfully."
39 | registrations:
40 | destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon."
41 | signed_up: "Welcome! You have signed up successfully."
42 | signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated."
43 | signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked."
44 | signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account."
45 | update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirmation link to confirm your new email address."
46 | updated: "Your account has been updated successfully."
47 | updated_but_not_signed_in: "Your account has been updated successfully, but since your password was changed, you need to sign in again"
48 | sessions:
49 | signed_in: "Signed in successfully."
50 | signed_out: "Signed out successfully."
51 | already_signed_out: "Signed out successfully."
52 | unlocks:
53 | send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes."
54 | send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes."
55 | unlocked: "Your account has been unlocked successfully. Please sign in to continue."
56 | errors:
57 | messages:
58 | already_confirmed: "was already confirmed, please try signing in"
59 | confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one"
60 | expired: "has expired, please request a new one"
61 | not_found: "not found"
62 | not_locked: "was not locked"
63 | not_saved:
64 | one: "1 error prohibited this %{resource} from being saved:"
65 | other: "%{count} errors prohibited this %{resource} from being saved:"
66 |
--------------------------------------------------------------------------------
/config/locales/en.yml:
--------------------------------------------------------------------------------
1 | # Files in the config/locales directory are used for internationalization
2 | # and are automatically loaded by Rails. If you want to use locales other
3 | # than English, add the necessary files in this directory.
4 | #
5 | # To use the locales, use `I18n.t`:
6 | #
7 | # I18n.t 'hello'
8 | #
9 | # In views, this is aliased to just `t`:
10 | #
11 | # <%= t('hello') %>
12 | #
13 | # To use a different locale, set it with `I18n.locale`:
14 | #
15 | # I18n.locale = :es
16 | #
17 | # This would use the information in config/locales/es.yml.
18 | #
19 | # The following keys must be escaped otherwise they will not be retrieved by
20 | # the default I18n backend:
21 | #
22 | # true, false, on, off, yes, no
23 | #
24 | # Instead, surround them with single quotes.
25 | #
26 | # en:
27 | # 'true': 'foo'
28 | #
29 | # To learn more, please read the Rails Internationalization guide
30 | # available at https://guides.rubyonrails.org/i18n.html.
31 |
32 | en:
33 | hello: "Hello world"
34 |
--------------------------------------------------------------------------------
/config/puma.rb:
--------------------------------------------------------------------------------
1 | # Puma can serve each request in a thread from an internal thread pool.
2 | # The `threads` method setting takes two numbers: a minimum and maximum.
3 | # Any libraries that use thread pools should be configured to match
4 | # the maximum value specified for Puma. Default is set to 5 threads for minimum
5 | # and maximum; this matches the default thread size of Active Record.
6 | #
7 | max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
8 | min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
9 | threads min_threads_count, max_threads_count
10 |
11 | # Specifies the `port` that Puma will listen on to receive requests; default is 3000.
12 | #
13 | port ENV.fetch("PORT") { 3000 }
14 |
15 | # Specifies the `environment` that Puma will run in.
16 | #
17 | environment ENV.fetch("RAILS_ENV") { "development" }
18 |
19 | # Specifies the `pidfile` that Puma will use.
20 | pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
21 |
22 | # Specifies the number of `workers` to boot in clustered mode.
23 | # Workers are forked web server processes. If using threads and workers together
24 | # the concurrency of the application would be max `threads` * `workers`.
25 | # Workers do not work on JRuby or Windows (both of which do not support
26 | # processes).
27 | #
28 | # workers ENV.fetch("WEB_CONCURRENCY") { 2 }
29 |
30 | # Use the `preload_app!` method when specifying a `workers` number.
31 | # This directive tells Puma to first boot the application and load code
32 | # before forking the application. This takes advantage of Copy On Write
33 | # process behavior so workers use less memory.
34 | #
35 | # preload_app!
36 |
37 | # Allow puma to be restarted by `rails restart` command.
38 | plugin :tmp_restart
39 |
--------------------------------------------------------------------------------
/config/routes.rb:
--------------------------------------------------------------------------------
1 | Rails.application.routes.draw do
2 | # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
3 |
4 | devise_for :users
5 |
6 | authenticated :user do
7 | root "pages#my_todo_items", as: :authenticated_root
8 | end
9 | root "pages#home"
10 |
11 | namespace :api, defaults: { format: :json } do
12 | namespace :v1 do
13 | resources :todo_items, only: [:index, :show, :create, :update, :destroy]
14 | end
15 | end
16 |
17 | end
18 |
--------------------------------------------------------------------------------
/config/spring.rb:
--------------------------------------------------------------------------------
1 | Spring.watch(
2 | ".ruby-version",
3 | ".rbenv-vars",
4 | "tmp/restart.txt",
5 | "tmp/caching-dev.txt"
6 | )
7 |
--------------------------------------------------------------------------------
/config/storage.yml:
--------------------------------------------------------------------------------
1 | test:
2 | service: Disk
3 | root: <%= Rails.root.join("tmp/storage") %>
4 |
5 | local:
6 | service: Disk
7 | root: <%= Rails.root.join("storage") %>
8 |
9 | # Use 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
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
23 |
24 | # Use 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
30 |
31 | # mirror:
32 | # service: Mirror
33 | # primary: local
34 | # mirrors: [ amazon, google, microsoft ]
35 |
--------------------------------------------------------------------------------
/config/webpack/development.js:
--------------------------------------------------------------------------------
1 | process.env.NODE_ENV = process.env.NODE_ENV || 'development'
2 |
3 | const environment = require('./environment')
4 |
5 | module.exports = environment.toWebpackConfig()
6 |
--------------------------------------------------------------------------------
/config/webpack/environment.js:
--------------------------------------------------------------------------------
1 | const { environment } = require('@rails/webpacker')
2 |
3 | module.exports = environment
4 |
--------------------------------------------------------------------------------
/config/webpack/production.js:
--------------------------------------------------------------------------------
1 | process.env.NODE_ENV = process.env.NODE_ENV || 'production'
2 |
3 | const environment = require('./environment')
4 |
5 | module.exports = environment.toWebpackConfig()
6 |
--------------------------------------------------------------------------------
/config/webpack/test.js:
--------------------------------------------------------------------------------
1 | process.env.NODE_ENV = process.env.NODE_ENV || 'development'
2 |
3 | const environment = require('./environment')
4 |
5 | module.exports = environment.toWebpackConfig()
6 |
--------------------------------------------------------------------------------
/config/webpacker.yml:
--------------------------------------------------------------------------------
1 | # Note: You must restart bin/webpack-dev-server for changes to take effect
2 |
3 | default: &default
4 | source_path: app/javascript
5 | source_entry_path: packs
6 | public_root_path: public
7 | public_output_path: packs
8 | cache_path: tmp/cache/webpacker
9 | check_yarn_integrity: false
10 | webpack_compile_output: true
11 |
12 | # Additional paths webpack should lookup modules
13 | # ['app/assets', 'engine/foo/app/assets']
14 | resolved_paths: []
15 |
16 | # Reload manifest.json on all requests so we reload latest compiled packs
17 | cache_manifest: false
18 |
19 | # Extract and emit a css file
20 | extract_css: false
21 |
22 | static_assets_extensions:
23 | - .jpg
24 | - .jpeg
25 | - .png
26 | - .gif
27 | - .tiff
28 | - .ico
29 | - .svg
30 | - .eot
31 | - .otf
32 | - .ttf
33 | - .woff
34 | - .woff2
35 |
36 | extensions:
37 | - .jsx
38 | - .mjs
39 | - .js
40 | - .sass
41 | - .scss
42 | - .css
43 | - .module.sass
44 | - .module.scss
45 | - .module.css
46 | - .png
47 | - .svg
48 | - .gif
49 | - .jpeg
50 | - .jpg
51 |
52 | development:
53 | <<: *default
54 | compile: true
55 |
56 | # Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
57 | check_yarn_integrity: true
58 |
59 | # Reference: https://webpack.js.org/configuration/dev-server/
60 | dev_server:
61 | https: false
62 | host: localhost
63 | port: 3035
64 | public: localhost:3035
65 | hmr: false
66 | # Inline should be set to true if using HMR
67 | inline: true
68 | overlay: true
69 | compress: true
70 | disable_host_check: true
71 | use_local_ip: false
72 | quiet: false
73 | pretty: false
74 | headers:
75 | 'Access-Control-Allow-Origin': '*'
76 | watch_options:
77 | ignored: '**/node_modules/**'
78 |
79 |
80 | test:
81 | <<: *default
82 | compile: true
83 |
84 | # Compile test packs to a separate directory
85 | public_output_path: packs-test
86 |
87 | production:
88 | <<: *default
89 |
90 | # Production depends on precompilation of packs prior to booting for performance.
91 | compile: false
92 |
93 | # Extract and emit a css file
94 | extract_css: true
95 |
96 | # Cache manifest.json for performance
97 | cache_manifest: true
98 |
--------------------------------------------------------------------------------
/db/migrate/20191119160942_devise_create_users.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | class DeviseCreateUsers < ActiveRecord::Migration[6.0]
4 | def change
5 | create_table :users do |t|
6 | ## Database authenticatable
7 | t.string :email, null: false, default: ""
8 | t.string :encrypted_password, null: false, default: ""
9 |
10 | ## Recoverable
11 | t.string :reset_password_token
12 | t.datetime :reset_password_sent_at
13 |
14 | ## Rememberable
15 | t.datetime :remember_created_at
16 |
17 | ## Trackable
18 | # t.integer :sign_in_count, default: 0, null: false
19 | # t.datetime :current_sign_in_at
20 | # t.datetime :last_sign_in_at
21 | # t.inet :current_sign_in_ip
22 | # t.inet :last_sign_in_ip
23 |
24 | ## Confirmable
25 | # t.string :confirmation_token
26 | # t.datetime :confirmed_at
27 | # t.datetime :confirmation_sent_at
28 | # t.string :unconfirmed_email # Only if using reconfirmable
29 |
30 | ## Lockable
31 | # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
32 | # t.string :unlock_token # Only if unlock strategy is :email or :both
33 | # t.datetime :locked_at
34 |
35 |
36 | t.timestamps null: false
37 | end
38 |
39 | add_index :users, :email, unique: true
40 | add_index :users, :reset_password_token, unique: true
41 | # add_index :users, :confirmation_token, unique: true
42 | # add_index :users, :unlock_token, unique: true
43 | end
44 | end
45 |
--------------------------------------------------------------------------------
/db/migrate/20191119162915_create_todo_items.rb:
--------------------------------------------------------------------------------
1 | class CreateTodoItems < ActiveRecord::Migration[6.0]
2 | def change
3 | create_table :todo_items do |t|
4 | t.string :title
5 | t.references :user, null: false, foreign_key: true
6 | t.boolean :complete, default: false
7 |
8 | t.timestamps
9 | end
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/db/schema.rb:
--------------------------------------------------------------------------------
1 | # This file is auto-generated from the current state of the database. Instead
2 | # of editing this file, please use the migrations feature of Active Record to
3 | # incrementally modify your database, and then regenerate this schema definition.
4 | #
5 | # This file is the source Rails uses to define your schema when running `rails
6 | # db:schema:load`. When creating a new database, `rails db:schema:load` tends to
7 | # be faster and is potentially less error prone than running all of your
8 | # migrations from scratch. Old migrations may fail to apply correctly if those
9 | # migrations use external dependencies or application code.
10 | #
11 | # It's strongly recommended that you check this file into your version control system.
12 |
13 | ActiveRecord::Schema.define(version: 2019_11_19_162915) do
14 |
15 | # These are extensions that must be enabled in order to support this database
16 | enable_extension "plpgsql"
17 |
18 | create_table "todo_items", force: :cascade do |t|
19 | t.string "title"
20 | t.bigint "user_id", null: false
21 | t.boolean "complete", default: false
22 | t.datetime "created_at", precision: 6, null: false
23 | t.datetime "updated_at", precision: 6, null: false
24 | t.index ["user_id"], name: "index_todo_items_on_user_id"
25 | end
26 |
27 | create_table "users", force: :cascade do |t|
28 | t.string "email", default: "", null: false
29 | t.string "encrypted_password", default: "", null: false
30 | t.string "reset_password_token"
31 | t.datetime "reset_password_sent_at"
32 | t.datetime "remember_created_at"
33 | t.datetime "created_at", precision: 6, null: false
34 | t.datetime "updated_at", precision: 6, null: false
35 | t.index ["email"], name: "index_users_on_email", unique: true
36 | t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
37 | end
38 |
39 | add_foreign_key "todo_items", "users"
40 | end
41 |
--------------------------------------------------------------------------------
/db/seeds.rb:
--------------------------------------------------------------------------------
1 | # This file should contain all the record creation needed to seed the database with its default values.
2 | # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
3 | #
4 | # Examples:
5 | #
6 | # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
7 | # Character.create(name: 'Luke', movie: movies.first)
8 |
9 | 2.times do |i|
10 | User.create(email: "user-#{i+1}@example.com", password: "password", password_confirmation: "password")
11 | end
12 |
13 | User.all.each do |u|
14 | 10.times do |i|
15 | u.todo_items.create(title: "To Do Item #{i+1} for #{u.email}", complete: i % 3 == 0 ? true : false )
16 | end
17 | end
--------------------------------------------------------------------------------
/lib/assets/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stevepolitodesign/rails-react-example/446e5d2ed7b24556787d6f19bbcb8a652837db35/lib/assets/.keep
--------------------------------------------------------------------------------
/lib/tasks/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stevepolitodesign/rails-react-example/446e5d2ed7b24556787d6f19bbcb8a652837db35/lib/tasks/.keep
--------------------------------------------------------------------------------
/lib/tasks/reset_application.rake:
--------------------------------------------------------------------------------
1 | namespace :reset_application do
2 | desc "Deletes existing data, and replaces with a fresh set"
3 | task reset: :environment do
4 | User.destroy_all
5 | sh %{rails db:seed}
6 | end
7 |
8 | end
9 |
--------------------------------------------------------------------------------
/log/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stevepolitodesign/rails-react-example/446e5d2ed7b24556787d6f19bbcb8a652837db35/log/.keep
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "rails_react_example",
3 | "private": true,
4 | "dependencies": {
5 | "@babel/preset-react": "^7.7.0",
6 | "@rails/actioncable": "^6.0.0-alpha",
7 | "@rails/activestorage": "^6.0.0-alpha",
8 | "@rails/ujs": "^6.0.0-alpha",
9 | "@rails/webpacker": "^4.2.0",
10 | "axios": "^0.19.0",
11 | "babel-plugin-transform-react-remove-prop-types": "^0.4.24",
12 | "bootstrap": "^4.4.1",
13 | "jquery": "^3.4.1",
14 | "lodash": "^4.17.15",
15 | "popper.js": "^1.16.0",
16 | "prop-types": "^15.7.2",
17 | "react": "^16.12.0",
18 | "react-dom": "^16.12.0",
19 | "turbolinks": "^5.2.0"
20 | },
21 | "version": "0.1.0",
22 | "devDependencies": {
23 | "prettier": "1.19.1",
24 | "webpack-dev-server": "^3.9.0"
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/postcss.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | plugins: [
3 | require('postcss-import'),
4 | require('postcss-flexbugs-fixes'),
5 | require('postcss-preset-env')({
6 | autoprefixer: {
7 | flexbox: 'no-2009'
8 | },
9 | stage: 3
10 | })
11 | ]
12 | }
13 |
--------------------------------------------------------------------------------
/public/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The page you were looking for doesn't exist (404)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
The page you were looking for doesn't exist.
62 |
You may have mistyped the address or the page may have moved.
63 |
64 |
If you are the application owner check the logs for more information.
If you are the application owner check the logs for more information.
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/public/apple-touch-icon-precomposed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stevepolitodesign/rails-react-example/446e5d2ed7b24556787d6f19bbcb8a652837db35/public/apple-touch-icon-precomposed.png
--------------------------------------------------------------------------------
/public/apple-touch-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stevepolitodesign/rails-react-example/446e5d2ed7b24556787d6f19bbcb8a652837db35/public/apple-touch-icon.png
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stevepolitodesign/rails-react-example/446e5d2ed7b24556787d6f19bbcb8a652837db35/public/favicon.ico
--------------------------------------------------------------------------------
/public/robots.txt:
--------------------------------------------------------------------------------
1 | # See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
2 |
--------------------------------------------------------------------------------
/spec/controllers/api/v1/todo_items_controller_spec.rb:
--------------------------------------------------------------------------------
1 | require 'rails_helper'
2 |
3 | RSpec.describe Api::V1::TodoItemsController, type: :controller do
4 | render_views
5 | describe "index" do
6 | let!(:user_with_todo_items) { FactoryBot.create(:user_with_todo_items) }
7 | context "when authenticated" do
8 | it "displays the current users todo items" do
9 | sign_in user_with_todo_items
10 | get :index, format: :json
11 | expect(response.status).to eq(200)
12 | expect(JSON.parse(response.body)).to eq(JSON.parse(user_with_todo_items.todo_items.to_json))
13 | end
14 | end
15 | context "when not authenticated" do
16 | it "returns unauthorized" do
17 | get :index, format: :json
18 | expect(response.status).to eq(401)
19 | end
20 | end
21 | end
22 |
23 | describe "show" do
24 | let!(:user_with_todo_items) { FactoryBot.create(:user_with_todo_items) }
25 | let!(:another_user_with_todo_items) { FactoryBot.create(:user_with_todo_items) }
26 | context "when authenticated" do
27 | it "returns a todo_item" do
28 | todo_item = user_with_todo_items.todo_items.first
29 | sign_in user_with_todo_items
30 | get :show, format: :json, params: { id: todo_item.id }
31 | expect(response.status).to eq(200)
32 | expect(JSON.parse(response.body)).to eq(JSON.parse(todo_item.to_json))
33 | end
34 | it "does not allow a user to view other's todo_items" do
35 | another_users_todo_item = another_user_with_todo_items.todo_items.first
36 | sign_in user_with_todo_items
37 | get :show, format: :json, params: { id: another_users_todo_item.id }
38 | expect(response.status).to eq(401)
39 | end
40 | end
41 | context "when not authenticated" do
42 | it "returns unauthorized" do
43 | todo_item = user_with_todo_items.todo_items.first
44 | get :show, format: :json, params: { id: todo_item.id }
45 | expect(response.status).to eq(401)
46 | end
47 | end
48 | end
49 |
50 | describe "create" do
51 | let!(:user_with_todo_items) { FactoryBot.create(:user_with_todo_items) }
52 | let!(:another_user_with_todo_items) { FactoryBot.create(:user_with_todo_items) }
53 | context "when authenticated" do
54 | it "returns a todo_item" do
55 | sign_in user_with_todo_items
56 | new_todo = { title: "a new todo", user: user_with_todo_items }
57 | post :create, format: :json, params: { todo_item: new_todo }
58 | expect(response.status).to eq(201)
59 | expect(JSON.parse(response.body)["title"]).to eq(new_todo[:title])
60 | end
61 | it "creates a todo_item" do
62 | sign_in user_with_todo_items
63 | new_todo = { title: "a new todo", user: user_with_todo_items }
64 | expect { post :create, format: :json, params: { todo_item: new_todo } }.to change{ TodoItem.count }.by(1)
65 | end
66 | it "returns a message if invalid" do
67 | sign_in user_with_todo_items
68 | invalid_new_todo = { title: "", user: user_with_todo_items }
69 | expect { post :create, format: :json, params: { todo_item: invalid_new_todo } }.to_not change{ TodoItem.count }
70 | expect(response.status).to eq(422)
71 | end
72 | it "does not allow a user to create other's todo_items" do
73 | sign_in user_with_todo_items
74 | new_todo = { title: "a new todo create by the wrong accout", user: another_user_with_todo_items }
75 | post :create, format: :json, params: { todo_item: new_todo }
76 | expect(JSON.parse(response.body)["user_id"]).to eq(user_with_todo_items.id)
77 | expect(JSON.parse(response.body)["user_id"]).to_not eq(another_user_with_todo_items.id)
78 | end
79 | end
80 | context "when not authenticated" do
81 | it "returns unauthorized" do
82 | new_todo = { title: "a new todo", user: user_with_todo_items }
83 | post :create, format: :json, params: { todo_item: new_todo }
84 | expect(response.status).to eq(401)
85 | end
86 | end
87 | end
88 |
89 | describe "update" do
90 | let!(:user_with_todo_items) { FactoryBot.create(:user_with_todo_items) }
91 | let!(:another_user_with_todo_items) { FactoryBot.create(:user_with_todo_items) }
92 | context "when authenticated" do
93 | it "returns a todo_item" do
94 | sign_in user_with_todo_items
95 | updated_todo = user_with_todo_items.todo_items.first
96 | updated_todo_title = "updated"
97 | put :update, format: :json, params: { todo_item: { title: updated_todo_title }, id: updated_todo.id }
98 | expect(response.status).to eq(200)
99 | expect(JSON.parse(response.body)["title"]).to eq(updated_todo_title)
100 | end
101 | it "does not allow a user to update other's todo_items" do
102 | sign_in user_with_todo_items
103 | another_users_updated_todo = another_user_with_todo_items.todo_items.first
104 | updated_todo_title = "updated"
105 | put :update, format: :json, params: { todo_item: { title: updated_todo_title }, id: another_users_updated_todo.id }
106 | expect(response.status).to eq(401)
107 | end
108 | it "returns a message if invalid" do
109 | sign_in user_with_todo_items
110 | updated_todo = user_with_todo_items.todo_items.first
111 | updated_todo_title = ""
112 | put :update, format: :json, params: { todo_item: { title: updated_todo_title }, id: updated_todo.id }
113 | expect(response.status).to eq(422)
114 | end
115 | end
116 | context "when not authenticated" do
117 | it "returns unauthorized" do
118 | updated_todo = user_with_todo_items.todo_items.first
119 | updated_todo_title = "updated"
120 | put :update, format: :json, params: { todo_item: { title: updated_todo_title }, id: updated_todo.id }
121 | expect(response.status).to eq(401)
122 | end
123 | end
124 | end
125 |
126 | describe "destroy" do
127 | let!(:user_with_todo_items) { FactoryBot.create(:user_with_todo_items) }
128 | let!(:another_user_with_todo_items) { FactoryBot.create(:user_with_todo_items) }
129 | context "when authenticated" do
130 | it "returns no content" do
131 | sign_in user_with_todo_items
132 | destroyed_todo = user_with_todo_items.todo_items.first
133 | delete :destroy, format: :json, params: { id: destroyed_todo.id }
134 | expect(response.status).to eq(204)
135 | end
136 | it "destroys a todo_item" do
137 | sign_in user_with_todo_items
138 | destroyed_todo = user_with_todo_items.todo_items.first
139 | expect{ delete :destroy, format: :json, params: { id: destroyed_todo.id } }.to change{ TodoItem.count }.by(-1)
140 | end
141 | it "does not allow a user to destroy other's todo_items" do
142 | sign_in user_with_todo_items
143 | another_users_destroyed_todo = another_user_with_todo_items.todo_items.first
144 | expect{ delete :destroy, format: :json, params: { id: another_users_destroyed_todo.id } }.to_not change{ TodoItem.count }
145 | end
146 | end
147 | context "when not authenticated" do
148 | it "returns unauthorized" do
149 | destroyed_todo = user_with_todo_items.todo_items.first
150 | delete :destroy, format: :json, params: { id: destroyed_todo.id }
151 | expect(response.status).to eq(401)
152 | end
153 | end
154 | end
155 |
156 | end
157 |
--------------------------------------------------------------------------------
/spec/factories/todo_items.rb:
--------------------------------------------------------------------------------
1 | FactoryBot.define do
2 | factory :todo_item do
3 | sequence(:title) { |n| "To Do Item #{n}" }
4 | user
5 | complete { false }
6 |
7 | factory :completed_todo_item do
8 | complete { true }
9 | end
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/spec/factories/users.rb:
--------------------------------------------------------------------------------
1 | FactoryBot.define do
2 | factory :user do
3 | sequence(:email) { |n| "user-#{n}@example.com" }
4 | password { "password" }
5 |
6 | factory :user_with_todo_items do
7 | transient do
8 | todo_items_count { 5 }
9 | end
10 |
11 | after(:create) do |user, evaluator|
12 | create_list(:todo_item, evaluator.todo_items_count, user: user)
13 | end
14 | end
15 |
16 | factory :user_with_completed_todo_items do
17 | transient do
18 | todo_items_count { 5 }
19 | end
20 |
21 | after(:create) do |user, evaluator|
22 | create_list(:completed_todo_item, evaluator.todo_items_count, user: user)
23 | end
24 | end
25 |
26 | end
27 | end
28 |
--------------------------------------------------------------------------------
/spec/features/homepage_flow_spec.rb:
--------------------------------------------------------------------------------
1 | require 'rails_helper'
2 |
3 | RSpec.feature "HomepageFlows", type: :feature do
4 | describe "homepage" do
5 | let!(:user) { FactoryBot.create(:user) }
6 | context "when the user is anonymous" do
7 | it "renders a page with a link to the sign up form" do
8 | visit authenticated_root_path
9 | expect(page).to have_content("Please Sign In to continue")
10 | expect(page).to have_current_path(root_path)
11 | end
12 | end
13 | context "when the user is authenticated" do
14 | it "renders a page with their todo items" do
15 | sign_in user
16 | visit authenticated_root_path
17 | expect(page).to have_content("My To Do Items")
18 | expect(page).to have_current_path(authenticated_root_path)
19 | end
20 | end
21 | end
22 | end
23 |
--------------------------------------------------------------------------------
/spec/features/todos_flow_spec.rb:
--------------------------------------------------------------------------------
1 | require 'rails_helper'
2 |
3 | RSpec.feature "TodosFlows", type: :feature do
4 | describe "creating a todo item", js: true do
5 | let(:user) { FactoryBot.create(:user) }
6 | valid_todo_item = 'this is a new note'
7 | in_valid_todo_item = ''
8 | it "creates a new todo item on the top of the list" do
9 | login_as(user, :scope => :user)
10 | visit root_path
11 | fill_in('title', with: valid_todo_item)
12 | click_button('Add To Do Item')
13 | new_todo_item = find('.table > tbody > tr:first-of-type td:nth-child(2) input:first-of-type')
14 | expect(new_todo_item.value).to eq(valid_todo_item)
15 | end
16 | end
17 |
18 | describe "updating a todo item", js: true do
19 | let(:user_with_todo_items) { FactoryBot.create(:user_with_todo_items) }
20 | updated_todo_item_text = 'updated'
21 | context "todo item is valid" do
22 | it "updates the todo item" do
23 | login_as(user_with_todo_items, :scope => :user)
24 | visit root_path
25 | todo_item = user_with_todo_items.todo_items.first
26 | find("#todoItem__title-#{todo_item.id}").send_keys(updated_todo_item_text)
27 | sleep 2
28 | visit root_path
29 | updated_todo_item = find('.table > tbody > tr:first-of-type td:nth-child(2) input:first-of-type')
30 | expect(updated_todo_item.value).to eq(todo_item.title + updated_todo_item_text)
31 | end
32 | end
33 | context "todo item is invalid", js: true do
34 | it "displays an error message" do
35 | login_as(user_with_todo_items, :scope => :user)
36 | visit root_path
37 | todo_item = user_with_todo_items.todo_items.first
38 | fill_in("todoItem__title-#{todo_item.id}", with: "")
39 | expect(page).to have_content("can't be blank")
40 | end
41 | end
42 | end
43 |
44 | describe "deleting a todo item", js: true do
45 | let(:user_with_todo_items) { FactoryBot.create(:user_with_todo_items) }
46 | it "removes the todo item from the list" do
47 | login_as(user_with_todo_items, :scope => :user)
48 | visit root_path
49 | todo_item = user_with_todo_items.todo_items.first
50 | row = find(".table > tbody > tr:first-of-type td:nth-child(3)")
51 | accept_confirm do
52 | row.click_button("Delete")
53 | end
54 | expect(page).to_not have_content(todo_item.title)
55 | end
56 | end
57 |
58 | describe "filtering todo items", js: true do
59 | let(:user_with_completed_todo_items) { FactoryBot.create(:user_with_completed_todo_items) }
60 | let(:user_with_todo_items) { FactoryBot.create(:user_with_todo_items) }
61 | it "hides newly completed item" do
62 | login_as(user_with_todo_items, :scope => :user)
63 | visit root_path
64 | todo_item = user_with_todo_items.todo_items.first
65 | check("complete-#{todo_item.id}")
66 | click_button("Hide Completed Items")
67 | within(".table-responsive tbody") do
68 | expect(page).to_not have_content(todo_item.title)
69 | end
70 | end
71 | it "only shows incomplete todo items" do
72 | login_as(user_with_completed_todo_items, :scope => :user)
73 | visit root_path
74 | todo_items = user_with_completed_todo_items.todo_items
75 | todo_items.each do |todo_item|
76 | expect(find("#todoItem__title-#{todo_item.id}").value).to eq(todo_item.title)
77 | end
78 | click_button("Hide Completed Items")
79 | within(".table-responsive tbody") do
80 | todo_items.each do |todo_item|
81 | expect(page).to_not have_content(todo_item.title)
82 | end
83 | end
84 | end
85 | end
86 |
87 | end
88 |
--------------------------------------------------------------------------------
/spec/features/user_login_spec.rb:
--------------------------------------------------------------------------------
1 | require 'rails_helper'
2 |
3 | RSpec.feature "UserLogins", type: :feature do
4 | describe "logging in" do
5 | let!(:user) { FactoryBot.create(:user) }
6 | it "logs the user in and redirects to their todo items" do
7 | visit root_path
8 | click_link "Sign In"
9 | fill_in "Email", with: user.email
10 | fill_in "Password", with: user.password
11 | click_button "Log in"
12 | expect(page).to have_content("My To Do Items")
13 | expect(page).to have_current_path(authenticated_root_path)
14 | end
15 | end
16 | end
17 |
--------------------------------------------------------------------------------
/spec/models/todo_item_spec.rb:
--------------------------------------------------------------------------------
1 | require 'rails_helper'
2 |
3 | RSpec.describe TodoItem, type: :model do
4 |
5 | describe "creation" do
6 | let(:todo_item) { FactoryBot.create(:todo_item) }
7 | it "can be created" do
8 | expect(todo_item).to be_valid
9 | end
10 | end
11 |
12 | describe "validations" do
13 | let(:todo_item) { FactoryBot.build(:todo_item) }
14 | it "should have a title" do
15 | todo_item.title = nil
16 | expect(todo_item).to_not be_valid
17 | end
18 | it "should have a user" do
19 | todo_item.user = nil
20 | expect(todo_item).to_not be_valid
21 | end
22 | end
23 |
24 | describe "default values" do
25 | let(:todo_item) { FactoryBot.build(:todo_item) }
26 | it "should have complete set to false" do
27 | expect(todo_item.complete).to eq(false)
28 | end
29 | end
30 |
31 | describe "order scope" do
32 | let!(:old_todo_item) { FactoryBot.create(:todo_item, created_at: Time.now - 1.day) }
33 | let!(:future_todo_item) { FactoryBot.create(:todo_item, created_at: Time.now + 1.day) }
34 | it "short sort todo items in descending order" do
35 | expect(TodoItem.first).to eq(future_todo_item)
36 | end
37 | end
38 |
39 | end
40 |
--------------------------------------------------------------------------------
/spec/models/user_spec.rb:
--------------------------------------------------------------------------------
1 | require 'rails_helper'
2 |
3 | RSpec.describe User, type: :model do
4 |
5 | describe "creation" do
6 | let!(:user) { FactoryBot.create(:user) }
7 | it "can be created" do
8 | expect(user).to be_valid
9 | end
10 | end
11 |
12 | describe "validations" do
13 | let(:user) { FactoryBot.build(:user) }
14 | let(:duplicate_user) { FactoryBot.build(:user) }
15 | it "must have an email address" do
16 | user.email = nil
17 | expect(user).to_not be_valid
18 | end
19 | it "must have a unique email address" do
20 | user.save!
21 | duplicate_user.email = user.email
22 | expect(duplicate_user).to_not be_valid
23 | end
24 | it "must have a password" do
25 | user.password = nil
26 | expect(user).to_not be_valid
27 | end
28 | end
29 |
30 | describe "todo_item associations" do
31 | let!(:user_with_todo_items) { FactoryBot.create(:user_with_todo_items) }
32 | it "has many todo items" do
33 | relation = described_class.reflect_on_association(:todo_items)
34 | expect(relation.macro).to eq(:has_many)
35 | end
36 | it "destroys associated todo_items" do
37 | expect{ user_with_todo_items.destroy }.to change { TodoItem.count }.by(-5)
38 | end
39 | end
40 |
41 | end
42 |
--------------------------------------------------------------------------------
/spec/rails_helper.rb:
--------------------------------------------------------------------------------
1 | # This file is copied to spec/ when you run 'rails generate rspec:install'
2 | require 'spec_helper'
3 | ENV['RAILS_ENV'] ||= 'test'
4 |
5 | require File.expand_path('../config/environment', __dir__)
6 |
7 | # Prevent database truncation if the environment is production
8 | abort("The Rails environment is running in production mode!") if Rails.env.production?
9 | require 'rspec/rails'
10 | # Add additional requires below this line. Rails is not loaded until this point!
11 |
12 | # Requires supporting ruby files with custom matchers and macros, etc, in
13 | # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
14 | # run as spec files by default. This means that files in spec/support that end
15 | # in _spec.rb will both be required and run as specs, causing the specs to be
16 | # run twice. It is recommended that you do not name files matching this glob to
17 | # end with _spec.rb. You can configure this pattern with the --pattern
18 | # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
19 | #
20 | # The following line is provided for convenience purposes. It has the downside
21 | # of increasing the boot-up time by auto-requiring all files in the support
22 | # directory. Alternatively, in the individual `*_spec.rb` files, manually
23 | # require only the support files necessary.
24 | #
25 | Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f }
26 |
27 | # Checks for pending migrations and applies them before tests are run.
28 | # If you are not using ActiveRecord, you can remove these lines.
29 | begin
30 | ActiveRecord::Migration.maintain_test_schema!
31 | rescue ActiveRecord::PendingMigrationError => e
32 | puts e.to_s.strip
33 | exit 1
34 | end
35 | RSpec.configure do |config|
36 | # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
37 | config.fixture_path = "#{::Rails.root}/spec/fixtures"
38 |
39 | # If you're not using ActiveRecord, or you'd prefer not to run each of your
40 | # examples within a transaction, remove the following line or assign false
41 | # instead of true.
42 | # config.use_transactional_fixtures = true
43 |
44 | # RSpec Rails can automatically mix in different behaviours to your tests
45 | # based on their file location, for example enabling you to call `get` and
46 | # `post` in specs under `spec/controllers`.
47 | #
48 | # You can disable this behaviour by removing the line below, and instead
49 | # explicitly tag your specs with their type, e.g.:
50 | #
51 | # RSpec.describe UsersController, :type => :controller do
52 | # # ...
53 | # end
54 | #
55 | # The different available types are documented in the features, such as in
56 | # https://relishapp.com/rspec/rspec-rails/docs
57 | config.infer_spec_type_from_file_location!
58 |
59 | # Filter lines from Rails gems in backtraces.
60 | config.filter_rails_from_backtrace!
61 | # arbitrary gems may also be filtered via:
62 | # config.filter_gems_from_backtrace("gem name")
63 | end
64 |
--------------------------------------------------------------------------------
/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | # This file was generated by the `rails generate rspec:install` command. Conventionally, all
2 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3 | # The generated `.rspec` file contains `--require spec_helper` which will cause
4 | # this file to always be loaded, without a need to explicitly require it in any
5 | # files.
6 | #
7 | # Given that it is always loaded, you are encouraged to keep this file as
8 | # light-weight as possible. Requiring heavyweight dependencies from this file
9 | # will add to the boot time of your test suite on EVERY test run, even for an
10 | # individual file that may not need all of that loaded. Instead, consider making
11 | # a separate helper file that requires the additional dependencies and performs
12 | # the additional setup, and require it from the spec files that actually need
13 | # it.
14 | #
15 | # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16 | RSpec.configure do |config|
17 | # rspec-expectations config goes here. You can use an alternate
18 | # assertion/expectation library such as wrong or the stdlib/minitest
19 | # assertions if you prefer.
20 | config.expect_with :rspec do |expectations|
21 | # This option will default to `true` in RSpec 4. It makes the `description`
22 | # and `failure_message` of custom matchers include text for helper methods
23 | # defined using `chain`, e.g.:
24 | # be_bigger_than(2).and_smaller_than(4).description
25 | # # => "be bigger than 2 and smaller than 4"
26 | # ...rather than:
27 | # # => "be bigger than 2"
28 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true
29 | end
30 |
31 | # rspec-mocks config goes here. You can use an alternate test double
32 | # library (such as bogus or mocha) by changing the `mock_with` option here.
33 | config.mock_with :rspec do |mocks|
34 | # Prevents you from mocking or stubbing a method that does not exist on
35 | # a real object. This is generally recommended, and will default to
36 | # `true` in RSpec 4.
37 | mocks.verify_partial_doubles = true
38 | end
39 |
40 | # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
41 | # have no way to turn it off -- the option exists only for backwards
42 | # compatibility in RSpec 3). It causes shared context metadata to be
43 | # inherited by the metadata hash of host groups and examples, rather than
44 | # triggering implicit auto-inclusion in groups with matching metadata.
45 | config.shared_context_metadata_behavior = :apply_to_host_groups
46 |
47 | # The settings below are suggested to provide a good initial experience
48 | # with RSpec, but feel free to customize to your heart's content.
49 | =begin
50 | # This allows you to limit a spec run to individual examples or groups
51 | # you care about by tagging them with `:focus` metadata. When nothing
52 | # is tagged with `:focus`, all examples get run. RSpec also provides
53 | # aliases for `it`, `describe`, and `context` that include `:focus`
54 | # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
55 | config.filter_run_when_matching :focus
56 |
57 | # Allows RSpec to persist some state between runs in order to support
58 | # the `--only-failures` and `--next-failure` CLI options. We recommend
59 | # you configure your source control system to ignore this file.
60 | config.example_status_persistence_file_path = "spec/examples.txt"
61 |
62 | # Limits the available syntax to the non-monkey patched syntax that is
63 | # recommended. For more details, see:
64 | # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
65 | # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
66 | # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
67 | config.disable_monkey_patching!
68 |
69 | # Many RSpec users commonly either run the entire suite or an individual
70 | # file, and it's useful to allow more verbose output when running an
71 | # individual spec file.
72 | if config.files_to_run.one?
73 | # Use the documentation formatter for detailed output,
74 | # unless a formatter has already been configured
75 | # (e.g. via a command-line flag).
76 | config.default_formatter = "doc"
77 | end
78 |
79 | # Print the 10 slowest examples and example groups at the
80 | # end of the spec run, to help surface which specs are running
81 | # particularly slow.
82 | config.profile_examples = 10
83 |
84 | # Run specs in random order to surface order dependencies. If you find an
85 | # order dependency and want to debug it, you can fix the order by providing
86 | # the seed, which is printed after each run.
87 | # --seed 1234
88 | config.order = :random
89 |
90 | # Seed global randomization in this process using the `--seed` CLI option.
91 | # Setting this allows you to use `--seed` to deterministically reproduce
92 | # test failures related to randomization by passing the same `--seed` value
93 | # as the one that triggered the failure.
94 | Kernel.srand config.seed
95 | =end
96 | end
97 |
--------------------------------------------------------------------------------
/spec/support/capybara.rb:
--------------------------------------------------------------------------------
1 | require 'capybara/rspec'
2 |
3 | RSpec.configure do |config|
4 |
5 | config.use_transactional_fixtures = false
6 |
7 | config.before(:suite) do
8 | if config.use_transactional_fixtures?
9 | raise(<<-MSG)
10 | Delete line `config.use_transactional_fixtures = true` from rails_helper.rb
11 | (or set it to false) to prevent uncommitted transactions being used in
12 | JavaScript-dependent specs.
13 |
14 | During testing, the app-under-test that the browser driver connects to
15 | uses a different database connection to the database connection used by
16 | the spec. The app's database connection would not be able to access
17 | uncommitted transaction data setup over the spec's database connection.
18 | MSG
19 | end
20 | DatabaseCleaner.clean_with(:truncation)
21 | end
22 |
23 | config.before(:each) do
24 | DatabaseCleaner.strategy = :transaction
25 | end
26 |
27 | config.before(:each, type: :feature) do
28 | # :rack_test driver's Rack app under test shares database connection
29 | # with the specs, so continue to use transaction strategy for speed.
30 | driver_shares_db_connection_with_specs = Capybara.current_driver == :rack_test
31 |
32 | unless driver_shares_db_connection_with_specs
33 | # Driver is probably for an external browser with an app
34 | # under test that does *not* share a database connection with the
35 | # specs, so use truncation strategy.
36 | DatabaseCleaner.strategy = :truncation
37 | end
38 | end
39 |
40 | config.before(:each) do
41 | DatabaseCleaner.start
42 | end
43 |
44 | config.append_after(:each) do
45 | DatabaseCleaner.clean
46 | end
47 |
48 | end
--------------------------------------------------------------------------------
/spec/support/devise.rb:
--------------------------------------------------------------------------------
1 | require 'devise'
2 | RSpec.configure do |config|
3 | config.include Devise::Test::ControllerHelpers, type: :controller
4 | config.include Devise::Test::ControllerHelpers, type: :view
5 | config.include Devise::Test::IntegrationHelpers, type: :feature
6 | config.include Warden::Test::Helpers
7 | config.after :each do
8 | Warden.test_reset!
9 | end
10 | end
--------------------------------------------------------------------------------
/spec/support/factory_bot.rb:
--------------------------------------------------------------------------------
1 | RSpec.configure do |config|
2 | config.include FactoryBot::Syntax::Methods
3 | end
--------------------------------------------------------------------------------
/storage/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stevepolitodesign/rails-react-example/446e5d2ed7b24556787d6f19bbcb8a652837db35/storage/.keep
--------------------------------------------------------------------------------
/tmp/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stevepolitodesign/rails-react-example/446e5d2ed7b24556787d6f19bbcb8a652837db35/tmp/.keep
--------------------------------------------------------------------------------
/vendor/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stevepolitodesign/rails-react-example/446e5d2ed7b24556787d6f19bbcb8a652837db35/vendor/.keep
--------------------------------------------------------------------------------