diff --git a/.prettierignore b/.prettierignore index 13eef8ad..0ffec769 100644 --- a/.prettierignore +++ b/.prettierignore @@ -6,3 +6,4 @@ coverage/ spec/support/ client/app/libs/i18n/translations.js client/app/libs/i18n/default.js +vendor/bundle diff --git a/.rubocop.yml b/.rubocop.yml index b8cec199..4fbd5a12 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -70,7 +70,7 @@ Metrics/BlockLength: - 'lib/tasks/linters.rake' - 'spec/rails_helper.rb' - 'spec/system/add_new_comment_spec.rb' - - 'spec/system/shared/examples.rb' + - 'spec/system/react_router_demo_spec.rb' Metrics/ParameterLists: Max: 5 @@ -105,4 +105,3 @@ RSpec/MultipleExpectations: RSpec/MultipleMemoizedHelpers: Max: 12 - diff --git a/Gemfile b/Gemfile index bef86920..df4a3323 100644 --- a/Gemfile +++ b/Gemfile @@ -68,12 +68,10 @@ group :development, :test do ################################################################################ # Linters and Security gem "rubocop", "1.24.1", require: false - gem "rubocop-rspec", "~> 2.7" - gem 'rubocop-rails' gem "rubocop-performance", "~> 1.13" + gem "rubocop-rails" + gem "rubocop-rspec", "~> 2.7" # Critical that require: false be set! https://github.com/brigade/scss-lint/issues/278 - gem "brakeman", require: false - gem "bundler-audit", require: false gem "scss_lint", require: false ################################################################################ @@ -93,7 +91,7 @@ end group :test do gem "capybara" gem "capybara-screenshot" - gem 'coveralls_reborn', '~> 0.25.0', require: false + gem "coveralls_reborn", "~> 0.25.0", require: false gem "database_cleaner" gem "generator_spec" gem "launchy" diff --git a/Gemfile.lock b/Gemfile.lock index beb38aab..63604d32 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -69,11 +69,7 @@ GEM bindex (0.8.1) binding_of_caller (1.0.0) debug_inspector (>= 0.0.1) - brakeman (5.2.0) builder (3.2.4) - bundler-audit (0.9.0.1) - bundler (>= 1.2.0, < 3) - thor (~> 1.0) byebug (11.1.3) capybara (3.36.0) addressable @@ -364,8 +360,6 @@ PLATFORMS DEPENDENCIES autoprefixer-rails awesome_print - brakeman - bundler-audit capybara capybara-screenshot coffee-rails diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 00000000..71fbba5b --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/app/models/comment.rb b/app/models/comment.rb index 79a41eaa..f4ca8873 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Comment < ActiveRecord::Base +class Comment < ApplicationRecord validates :author, :text, presence: true after_commit { CommentRelayJob.perform_later(self) } end diff --git a/client/app/assets/styles/bootstrap-pre-customizations.scss b/client/app/assets/styles/bootstrap-pre-customizations.scss index 2003b430..96129ab7 100644 --- a/client/app/assets/styles/bootstrap-pre-customizations.scss +++ b/client/app/assets/styles/bootstrap-pre-customizations.scss @@ -1,8 +1,8 @@ // These variables get loaded BEFORE Bootstrap thus overriding them in Bootstrap. @import './app-variables'; -// This path is relative to this file! -$fonts-url-path: '../fonts'; +// This path is relative to node_modules/bootstrap-loader +$fonts-url-path: '../../client/app/assets/fonts'; @font-face { font-family: 'OpenSans-Light'; diff --git a/client/app/bundles/comments/startup/NavigationBarApp.jsx b/client/app/bundles/comments/startup/NavigationBarApp.jsx index 5c4f40ba..500a447f 100644 --- a/client/app/bundles/comments/startup/NavigationBarApp.jsx +++ b/client/app/bundles/comments/startup/NavigationBarApp.jsx @@ -14,7 +14,7 @@ import * as paths from '../constants/paths'; * This is used for the client rendering hook after the page html is rendered. * React will see that the state is the same and not do anything. */ -function NavigationBarApp(_props, railsContext) { +function NavigationBarAppFactory(_props, railsContext) { // This is where we get the existing store. const { pathname } = railsContext; let store; @@ -23,16 +23,20 @@ function NavigationBarApp(_props, railsContext) { } else if (pathname === paths.NO_ROUTER_PATH) { store = ReactOnRails.getStore('commentsStore', false); } else { - return () => ; + return function NavigationBarApp() { + return ; + }; } // eslint interprets the return as a new component definition, which is not the case // eslint-disable-next-line react/display-name, react/no-unstable-nested-components - return () => ( - - - - ); + return function NavigationBarApp() { + return ( + + + + ); + }; } -export default NavigationBarApp; +export default NavigationBarAppFactory; diff --git a/client/app/bundles/comments/startup/ServerRouterApp.jsx b/client/app/bundles/comments/startup/ServerRouterApp.jsx index 49a611b6..0a689fab 100644 --- a/client/app/bundles/comments/startup/ServerRouterApp.jsx +++ b/client/app/bundles/comments/startup/ServerRouterApp.jsx @@ -25,13 +25,15 @@ function ServerRouterApp(_props, railsContext) { // Important that you don't do this if you are redirecting or have an error. // eslint-disable-next-line react/display-name - return () => ( - - - {routes} - - - ); + return function ServerRouter() { + return ( + + + {routes} + + + ); + }; } export default ServerRouterApp; diff --git a/client/app/packs/client-bundle.js b/client/app/packs/client-bundle.js index 67ef7f49..f930c71c 100644 --- a/client/app/packs/client-bundle.js +++ b/client/app/packs/client-bundle.js @@ -1,5 +1,6 @@ import ReactOnRails from 'react-on-rails'; import 'bootstrap-loader'; +// eslint-disable-next-line import/no-webpack-loader-syntax import 'expose-loader?exposes=$,jQuery!jquery'; import 'jquery-ujs'; diff --git a/config/application.rb b/config/application.rb index 4fc8f530..d472d0ac 100644 --- a/config/application.rb +++ b/config/application.rb @@ -17,7 +17,6 @@ class Application < Rails::Application config.action_cable.allowed_request_origins = [Rails.application.secrets.action_cable_url] - # These settings can be overridden in specific environments using the files # in config/environments, which are processed later. # diff --git a/config/environments/development.rb b/config/environments/development.rb index ef23a393..ac8d085d 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "active_support/core_ext/integer/time" Rails.application.configure do @@ -17,13 +18,13 @@ # Enable/disable caching. By default caching is disabled. # Run rails dev:cache to toggle caching. - if Rails.root.join('tmp', 'caching-dev.txt').exist? + if Rails.root.join("tmp/caching-dev.txt").exist? config.action_controller.perform_caching = true config.action_controller.enable_fragment_cache_logging = true config.cache_store = :memory_store config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{2.days.to_i}" + "Cache-Control" => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false diff --git a/config/environments/production.rb b/config/environments/production.rb index e23479bb..0f0657ec 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "active_support/core_ext/integer/time" Rails.application.configure do @@ -23,7 +24,7 @@ # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. - config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? # Compress CSS using a preprocessor. # config.assets.css_compressor = :sass @@ -54,7 +55,7 @@ config.log_level = :info # Prepend all log lines with the following tags. - config.log_tags = [ :request_id ] + config.log_tags = [:request_id] # Use a different cache store in production. # config.cache_store = :mem_cache_store @@ -90,7 +91,7 @@ # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') if ENV["RAILS_LOG_TO_STDOUT"].present? - logger = ActiveSupport::Logger.new(STDOUT) + logger = ActiveSupport::Logger.new($stdout) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end diff --git a/config/environments/test.rb b/config/environments/test.rb index 17ce39cf..86ff12e0 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "active_support/core_ext/integer/time" # The test environment is used exclusively to run your application's @@ -18,7 +20,7 @@ # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{1.hour.to_i}" + "Cache-Control" => "public, max-age=#{1.hour.to_i}" } # Show full error reports and disable caching. diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index bcafccdd..101a2902 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -3,7 +3,7 @@ # Be sure to restart your server when you modify this file. # Version of your assets, change this if you want to expire all your assets. -Rails.application.config.assets.version = '1.0' +Rails.application.config.assets.version = "1.0" # Add additional assets to the asset load path. # Rails.application.config.assets.paths << Emoji.images_path diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb index 9290b504..74f30e88 100644 --- a/config/initializers/backtrace_silencers.rb +++ b/config/initializers/backtrace_silencers.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index 85c4e951..f7fadc06 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -1,10 +1,11 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Define an application-wide content security policy # For further information see the following documentation # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy -# Rails.application.config.content_security_policy do |policy| +# Rails.application.config.content_security_policy do |policy| # # If you are using webpack-dev-server then specify webpack-dev-server host # policy.connect_src :self, :https, "http://localhost:3035", "ws://localhost:3035" if Rails.env.development? diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index 5118eb69..3babc73f 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -3,6 +3,6 @@ # Be sure to restart your server when you modify this file. # Configure sensitive parameters which will be filtered from the log file. -Rails.application.config.filter_parameters += [ - :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn +Rails.application.config.filter_parameters += %i[ + passw secret token _key crypt salt certificate otp ssn ] diff --git a/config/initializers/new_framework_defaults_6_1.rb b/config/initializers/new_framework_defaults_6_1.rb index 9526b835..0b4ce023 100644 --- a/config/initializers/new_framework_defaults_6_1.rb +++ b/config/initializers/new_framework_defaults_6_1.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # # This file contains migration options to ease your Rails 6.1 upgrade. diff --git a/config/initializers/permissions_policy.rb b/config/initializers/permissions_policy.rb index 00f64d71..50bcf4ea 100644 --- a/config/initializers/permissions_policy.rb +++ b/config/initializers/permissions_policy.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Define an application-wide HTTP permissions policy. For further # information see https://developers.google.com/web/updates/2018/06/feature-policy # diff --git a/config/initializers/react_on_rails.rb b/config/initializers/react_on_rails.rb index 7c1acdf6..2713ee9e 100644 --- a/config/initializers/react_on_rails.rb +++ b/config/initializers/react_on_rails.rb @@ -3,7 +3,7 @@ # Shown below are the defaults for configuration ReactOnRails.configure do |config| # Define the files for we need to check for webpack compilation when running tests - config.webpack_generated_files = %w[ client-bundle.js server-bundle.js ] + config.webpack_generated_files = %w[client-bundle.js server-bundle.js] config.build_test_command = "RAILS_ENV=test bin/webpacker" @@ -60,7 +60,7 @@ # I18N OPTIONS ################################################################################ # Replace the following line to the location where you keep translation.js & default.js. - config.i18n_dir = Rails.root.join("client", "app", "libs", "i18n") + config.i18n_dir = Rails.root.join("client/app/libs/i18n") ################################################################################ # MISCELLANEOUS OPTIONS diff --git a/config/puma.rb b/config/puma.rb index 67043b86..e663c140 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -6,7 +6,7 @@ # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +max_threads_count = ENV.fetch("RAILS_MAX_THREADS", 5) min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } threads min_threads_count, max_threads_count @@ -17,14 +17,14 @@ # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -port ENV.fetch("PORT") { 3000 } +port ENV.fetch("PORT", 3000) # Specifies the `environment` that Puma will run in. # environment ENV.fetch("RAILS_ENV", "development") # Specifies the `pidfile` that Puma will use. -pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } +pidfile ENV.fetch("PIDFILE", "tmp/pids/server.pid") # Specifies the number of `workers` to boot in clustered mode. # Workers are forked web server processes. If using threads and workers together diff --git a/lib/tasks/brakeman.rake b/lib/tasks/brakeman.rake deleted file mode 100644 index 2412a7f9..00000000 --- a/lib/tasks/brakeman.rake +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -namespace :brakeman do - desc "Run Brakeman" - task :run, :output_files do |_t, args| - require "brakeman" - - files = args[:output_files].split if args[:output_files] - Brakeman.run app_path: ".", output_files: files, print_report: true - end - - desc "Check your code with Brakeman" - task :check do - require "brakeman" - result = Brakeman.run app_path: ".", print_report: true - exit Brakeman::Warnings_Found_Exit_Code unless result.filtered_warnings.empty? - end -end diff --git a/lib/tasks/ci.rake b/lib/tasks/ci.rake index 11594bc0..79d5808b 100644 --- a/lib/tasks/ci.rake +++ b/lib/tasks/ci.rake @@ -3,23 +3,12 @@ if Rails.env.development? || Rails.env.test? # See tasks/linters.rake - task :bundle_audit do - puts Rainbow("Running security audit on gems (bundle_audit)").green - Rake::Task["bundle_audit"].invoke - end - - task :security_audit do - puts Rainbow("Running security audit on code (brakeman)").green - - sh "brakeman --exit-on-warn --quiet -A -z" - end - - task :js_tests do + task js_tests: :environment do puts Rainbow("Running JavaScript tests").green sh "yarn run test:client" end - task :rspec_tests do + task rspec_tests: :environment do puts Rainbow("Running RSpec tests").green sh "rspec" end @@ -27,7 +16,7 @@ if Rails.env.development? || Rails.env.test? namespace :ci do desc "Run all audits and tests" # rspec_tests must be before lint and js_tests to build the locale files - task all: %i[environment rspec_tests lint js_tests bundle_audit security_audit] do + task all: %i[environment rspec_tests lint js_tests] do puts "All CI tasks" puts Rainbow("PASSED").green puts "" diff --git a/lib/tasks/linters.rake b/lib/tasks/linters.rake index 665562ff..de6637dc 100644 --- a/lib/tasks/linters.rake +++ b/lib/tasks/linters.rake @@ -10,7 +10,7 @@ if %w[development test].include? Rails.env # RuboCop::RakeTask.new desc "Run Rubocop lint as shell. Specify option fix to auto-correct (and don't have uncommitted files!)." - task :rubocop, [:fix] => [] do |_t, args| + task :rubocop, [:fix] => [:environment] do |_t, args| def to_bool(str) return true if /^(true|t|yes|y|1)$/i.match?(str) return false if str.blank? || str =~ /^(false|f|no|n|0)$/i @@ -24,13 +24,6 @@ if %w[development test].include? Rails.env sh cmd end - desc "Run ruby-lint as shell" - task :ruby do - cmd = "ruby-lint app config spec lib" - puts "Running ruby-lint Linters via `#{cmd}`" - sh cmd - end - # SlimLint::RakeTask.new do |t| # t.files = ["app/views"] # end @@ -40,7 +33,7 @@ if %w[development test].include? Rails.env end desc "eslint" - task :eslint do + task eslint: :environment do cmd = "yarn run lint" puts "Running eslint via `#{cmd}`" sh cmd @@ -57,7 +50,7 @@ if %w[development test].include? Rails.env desc "See docs for task 'scss_lint'" task scss: :scss_lint - task lint: %i[rubocop ruby js scss] do + task lint: %i[rubocop js scss] do puts "Completed all linting" end end diff --git a/lib/tasks/rails_best_practices.rake b/lib/tasks/rails_best_practices.rake index 5e3e0773..cc5c0b75 100644 --- a/lib/tasks/rails_best_practices.rake +++ b/lib/tasks/rails_best_practices.rake @@ -2,7 +2,7 @@ namespace :rails_best_practices do desc "Run Rails Best Practices" - task :run do + task run: :environment do sh "rails_best_practices" end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 12aa534b..5fa65a6e 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -36,9 +36,10 @@ # Requires supporting files with custom matchers and macros, etc, # in ./support/ and its subdirectories. -Dir[Rails.root.join("spec", "support", "**", "*.rb")].sort.each { |f| require f } +Dir[Rails.root.join("spec/support/**/*.rb")].sort.each { |f| require f } RSpec.configure do |config| + config.include FactoryBot::Syntax::Methods # Ensure that if we are running js tests, we are using latest webpack assets # This will use the defaults of :js and :server_rendering meta tags ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config) @@ -109,7 +110,7 @@ puts "Capybara using driver: #{Capybara.javascript_driver}" puts "=" * 80 - Capybara.save_path = Rails.root.join("tmp", "capybara") + Capybara.save_path = Rails.root.join("tmp/capybara") Capybara::Screenshot.prune_strategy = { keep: 10 } config.append_after do diff --git a/spec/system/add_new_comment_spec.rb b/spec/system/add_new_comment_spec.rb index 05d55901..4218f188 100644 --- a/spec/system/add_new_comment_spec.rb +++ b/spec/system/add_new_comment_spec.rb @@ -6,169 +6,168 @@ describe "Add new comment" do context "when React Router", page: :main, js: true, type: :system do describe "with Horizontal Form" do - subject { page } - before { + before do visit root_path click_link "Inline Form" click_link "Horizontal Form" submit_form - } - it "should have the submitted comment" do - is_expected.to have_css(".js-comment-author", text: "Spicoli") - is_expected.to have_css(".js-comment-text", text: "dude!") - is_expected.to have_no_content("Your comment was not saved!") - is_expected.to have_css("#js-comment-count", text: "Comments: #{Comment.count}") - is_expected.to have_no_content("Your comment was not saved!") - is_expected.to have_no_content("Author: can't be blank") - is_expected.to have_no_content("Text: can't be blank") + end + + it "has the submitted comment" do + expect(page).to have_css(".js-comment-author", text: "Spicoli") + expect(page).to have_css(".js-comment-text", text: "dude!") + expect(page).to have_no_content("Your comment was not saved!") + expect(page).to have_css("#js-comment-count", text: "Comments: #{Comment.count}") + expect(page).to have_no_content("Your comment was not saved!") + expect(page).to have_no_content("Author: can't be blank") + expect(page).to have_no_content("Text: can't be blank") end end describe "with Inline Form" do - subject { page } - before { + before do visit root_path click_link "Inline Form" submit_form - } - it "should have the submitted comment" do - is_expected.to have_css(".js-comment-author", text: "Spicoli") - is_expected.to have_css(".js-comment-text", text: "dude!") - is_expected.to have_no_content("Your comment was not saved!") - is_expected.to have_css("#js-comment-count", text: "Comments: #{Comment.count}") - is_expected.to have_no_content("Your comment was not saved!") - is_expected.to have_no_content("Author: can't be blank") - is_expected.to have_no_content("Text: can't be blank") + end + + it "has the submitted comment" do + expect(page).to have_css(".js-comment-author", text: "Spicoli") + expect(page).to have_css(".js-comment-text", text: "dude!") + expect(page).to have_no_content("Your comment was not saved!") + expect(page).to have_css("#js-comment-count", text: "Comments: #{Comment.count}") + expect(page).to have_no_content("Your comment was not saved!") + expect(page).to have_no_content("Author: can't be blank") + expect(page).to have_no_content("Text: can't be blank") end end describe "with Stacked Form" do - subject { page } - before { + before do visit root_path click_link "Stacked Form" submit_form - } - it "should have the submitted comment" do - is_expected.to have_css(".js-comment-author", text: "Spicoli") - is_expected.to have_css(".js-comment-text", text: "dude!") - is_expected.to have_no_content("Your comment was not saved!") - is_expected.to have_css("#js-comment-count", text: "Comments: #{Comment.count}") - is_expected.to have_no_content("Your comment was not saved!") - is_expected.to have_no_content("Author: can't be blank") - is_expected.to have_no_content("Text: can't be blank") + end + + it "has the submitted comment" do + expect(page).to have_css(".js-comment-author", text: "Spicoli") + expect(page).to have_css(".js-comment-text", text: "dude!") + expect(page).to have_no_content("Your comment was not saved!") + expect(page).to have_css("#js-comment-count", text: "Comments: #{Comment.count}") + expect(page).to have_no_content("Your comment was not saved!") + expect(page).to have_no_content("Author: can't be blank") + expect(page).to have_no_content("Text: can't be blank") end end end context "when React/Redux", page: :react_demo, js: true, type: :system do describe "with Horizontal Form" do - subject { page } - before { + before do visit root_path click_link "Inline Form" click_link "Horizontal Form" submit_form - } - it "should have the submitted comment" do - is_expected.to have_css(".js-comment-author", text: "Spicoli") - is_expected.to have_css(".js-comment-text", text: "dude!") - is_expected.to have_no_content("Your comment was not saved!") - is_expected.to have_css("#js-comment-count", text: "Comments: #{Comment.count}") - is_expected.to have_no_content("Your comment was not saved!") - is_expected.to have_no_content("Author: can't be blank") - is_expected.to have_no_content("Text: can't be blank") + end + + it "has the submitted comment" do + expect(page).to have_css(".js-comment-author", text: "Spicoli") + expect(page).to have_css(".js-comment-text", text: "dude!") + expect(page).to have_no_content("Your comment was not saved!") + expect(page).to have_css("#js-comment-count", text: "Comments: #{Comment.count}") + expect(page).to have_no_content("Your comment was not saved!") + expect(page).to have_no_content("Author: can't be blank") + expect(page).to have_no_content("Text: can't be blank") end end describe "with Inline Form" do - subject { page } - before { + before do visit root_path click_link "Inline Form" submit_form - } + end - it "should have the submitted comment" do - is_expected.to have_css(".js-comment-author", text: "Spicoli") - is_expected.to have_css(".js-comment-text", text: "dude!") - is_expected.to have_no_content("Your comment was not saved!") - is_expected.to have_css("#js-comment-count", text: "Comments: #{Comment.count}") - is_expected.to have_no_content("Your comment was not saved!") - is_expected.to have_no_content("Author: can't be blank") - is_expected.to have_no_content("Text: can't be blank") + it "has the submitted comment" do + expect(page).to have_css(".js-comment-author", text: "Spicoli") + expect(page).to have_css(".js-comment-text", text: "dude!") + expect(page).to have_no_content("Your comment was not saved!") + expect(page).to have_css("#js-comment-count", text: "Comments: #{Comment.count}") + expect(page).to have_no_content("Your comment was not saved!") + expect(page).to have_no_content("Author: can't be blank") + expect(page).to have_no_content("Text: can't be blank") end end describe "with Stacked Form" do - subject { page } - before { + before do visit root_path click_link "Stacked Form" submit_form - } - it "should have the submitted comment" do - is_expected.to have_css(".js-comment-author", text: "Spicoli") - is_expected.to have_css(".js-comment-text", text: "dude!") - is_expected.to have_no_content("Your comment was not saved!") - is_expected.to have_css("#js-comment-count", text: "Comments: #{Comment.count}") - is_expected.to have_no_content("Your comment was not saved!") - is_expected.to have_no_content("Author: can't be blank") - is_expected.to have_no_content("Text: can't be blank") + end + + it "has the submitted comment" do + expect(page).to have_css(".js-comment-author", text: "Spicoli") + expect(page).to have_css(".js-comment-text", text: "dude!") + expect(page).to have_no_content("Your comment was not saved!") + expect(page).to have_css("#js-comment-count", text: "Comments: #{Comment.count}") + expect(page).to have_no_content("Your comment was not saved!") + expect(page).to have_no_content("Author: can't be blank") + expect(page).to have_no_content("Text: can't be blank") end end end context "when simple page", page: :simple, js: true, type: :system do describe "with Horizontal Form" do - subject { page } - before { + before do visit root_path click_link "Inline Form" click_link "Horizontal Form" submit_form - } - it "should have the submitted comment" do - is_expected.to have_css(".js-comment-author", text: "Spicoli") - is_expected.to have_css(".js-comment-text", text: "dude!") - is_expected.to have_no_content("Your comment was not saved!") - is_expected.to have_no_content("Your comment was not saved!") - is_expected.to have_no_content("Author: can't be blank") - is_expected.to have_no_content("Text: can't be blank") + end + + it "has the submitted comment" do + expect(page).to have_css(".js-comment-author", text: "Spicoli") + expect(page).to have_css(".js-comment-text", text: "dude!") + expect(page).to have_no_content("Your comment was not saved!") + expect(page).to have_no_content("Your comment was not saved!") + expect(page).to have_no_content("Author: can't be blank") + expect(page).to have_no_content("Text: can't be blank") end end describe "with Inline Form" do - subject { page } - before { + before do visit root_path click_link "Inline Form" submit_form - } - it "should have the submitted comment" do - is_expected.to have_css(".js-comment-author", text: "Spicoli") - is_expected.to have_css(".js-comment-text", text: "dude!") - is_expected.to have_no_content("Your comment was not saved!") - is_expected.to have_no_content("Your comment was not saved!") - is_expected.to have_no_content("Author: can't be blank") - is_expected.to have_no_content("Text: can't be blank") + end + + it "has the submitted comment" do + expect(page).to have_css(".js-comment-author", text: "Spicoli") + expect(page).to have_css(".js-comment-text", text: "dude!") + expect(page).to have_no_content("Your comment was not saved!") + expect(page).to have_no_content("Your comment was not saved!") + expect(page).to have_no_content("Author: can't be blank") + expect(page).to have_no_content("Text: can't be blank") end end describe "with the Stacked Form" do - subject { page } - before { + before do visit root_path click_link "Stacked Form" submit_form - } - it "should have the submitted comment" do - is_expected.to have_css(".js-comment-author", text: "Spicoli") - is_expected.to have_css(".js-comment-text", text: "dude!") - is_expected.to have_no_content("Your comment was not saved!") - is_expected.to have_no_content("Your comment was not saved!") - is_expected.to have_no_content("Author: can't be blank") - is_expected.to have_no_content("Text: can't be blank") + end + + it "has the submitted comment" do + expect(page).to have_css(".js-comment-author", text: "Spicoli") + expect(page).to have_css(".js-comment-text", text: "dude!") + expect(page).to have_no_content("Your comment was not saved!") + expect(page).to have_no_content("Your comment was not saved!") + expect(page).to have_no_content("Author: can't be blank") + expect(page).to have_no_content("Text: can't be blank") end end end diff --git a/spec/system/destroy_comment_spec.rb b/spec/system/destroy_comment_spec.rb index cfa73f29..9e081f17 100644 --- a/spec/system/destroy_comment_spec.rb +++ b/spec/system/destroy_comment_spec.rb @@ -5,7 +5,7 @@ describe "Destroy a comment", existing_comment: true do context "when from classic page" do - let(:comment) { FactoryBot.build(:comment) } + let(:comment) { build(:comment) } it "clicking destroy link destroys comment" do visit comments_path diff --git a/spec/system/edit_comment_spec.rb b/spec/system/edit_comment_spec.rb index 1b68737b..4ab04ddb 100644 --- a/spec/system/edit_comment_spec.rb +++ b/spec/system/edit_comment_spec.rb @@ -4,7 +4,7 @@ require "system/shared/contexts" describe "Edit a comment", existing_comment: true do - let(:comment) { FactoryBot.build(:comment) } + let(:comment) { build(:comment) } let(:edited_name) { "Abraham Lincoln" } context "when from classic page" do diff --git a/spec/system/pages_spec.rb b/spec/system/pages_spec.rb index c419de45..ff8de8e8 100644 --- a/spec/system/pages_spec.rb +++ b/spec/system/pages_spec.rb @@ -4,6 +4,7 @@ shared_examples "Git Commit SHA" do before { visit root_path } + it "displays the current git commit" do el = find("#git-commit-sha") expect(el.text).to eq expected_text diff --git a/spec/system/react_router_demo_spec.rb b/spec/system/react_router_demo_spec.rb index 48c419b6..d1255e4f 100644 --- a/spec/system/react_router_demo_spec.rb +++ b/spec/system/react_router_demo_spec.rb @@ -21,10 +21,10 @@ end context "when /react-router/redirect URL", page: :main do - before { + before do visit root_path click_link "Test Redirect (url to '/react-router/redirect' which goes to root '/')" - } + end it "shows comments section" do expect(page).to have_selector("h2", text: "Comments")