diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
new file mode 100644
index 00000000..d08df6c4
--- /dev/null
+++ b/.github/workflows/test.yml
@@ -0,0 +1,77 @@
+# This workflow uses actions that are not certified by GitHub. They are
+# provided by a third-party and are governed by separate terms of service,
+# privacy policy, and support documentation.
+#
+# This workflow will install a prebuilt Ruby version, install dependencies, and
+# run tests and linters.
+name: "Ruby on Rails CI"
+on:
+ push:
+ branches: [ "master" ]
+ pull_request:
+ branches: [ "master" ]
+jobs:
+ test:
+ runs-on: ubuntu-latest
+ strategy:
+ fail-fast: false
+ services:
+ postgres:
+ image: postgres:11-alpine
+ ports:
+ - "5432:5432"
+ env:
+ POSTGRES_DB: rails_test
+ POSTGRES_USER: rails
+ POSTGRES_PASSWORD: password
+ env:
+ RAILS_ENV: test
+ NODE_ENV: test
+ DATABASE_URL: "postgres://rails:password@localhost:5432/rails_test"
+ DRIVER: selenium_chrome
+ CHROME_BIN: /usr/bin/google-chrome
+ USE_COVERALLS: true
+ steps:
+ - name: Install Chrome
+ uses: browser-actions/setup-chrome@latest
+
+ - name: Check Chrome version
+ run: chrome --version
+
+ - name: Check Chrome version
+ run: google-chrome --version
+
+ - name: Set Display environment variable
+ run: "export DISPLAY=:99"
+
+ - name: Checkout code
+ uses: actions/checkout@v3
+
+ - name: Install Ruby and gems
+ uses: ruby/setup-ruby@0a29871fe2b0200a17a4497bae54fe5df0d973aa # v1.115.3
+ with:
+ ruby: 3.x
+ bundler-cache: true
+
+ - name: Use Node.js 16.x
+ uses: actions/setup-node@v3
+ with:
+ node-version: 16.x
+ - name: Install Node Packages
+ run: npm install --legacy-peer-deps
+
+ - name: Set up database schema
+ run: bin/rails db:schema:load
+
+ - name: Build i18n libraries
+ run: bundle exec rake react_on_rails:locale
+
+ - name: Build webpacker chunks
+ run: NODE_ENV=development bundle exec bin/webpacker
+
+ - name: Run tests with xvfb
+ uses: GabrielBB/xvfb-action@v1
+ with:
+ run: bundle exec rake
+ working-directory: ./ #optional
+ options: ":99 -ac -screen scn 1600x1200x16"
diff --git a/.nvmrc b/.nvmrc
index 48082f72..b6a7d89c 100644
--- a/.nvmrc
+++ b/.nvmrc
@@ -1 +1 @@
-12
+16
diff --git a/Gemfile b/Gemfile
index 46c66a66..bef86920 100644
--- a/Gemfile
+++ b/Gemfile
@@ -41,10 +41,6 @@ gem "sdoc", group: :doc
# Use Rails Html Sanitizer for HTML sanitization
gem "rails-html-sanitizer"
-# See https://github.com/sstephenson/execjs#readme for more supported runtimes
-# mini_racer is probably faster than therubyracer
-gem "mini_racer", platforms: :ruby
-
gem "autoprefixer-rails"
gem "awesome_print"
@@ -97,7 +93,7 @@ end
group :test do
gem "capybara"
gem "capybara-screenshot"
- gem "coveralls", 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 602b157a..beb38aab 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -100,12 +100,11 @@ GEM
coffee-script-source (1.12.2)
concurrent-ruby (1.1.9)
connection_pool (2.2.5)
- coveralls (0.8.23)
- json (>= 1.8, < 3)
- simplecov (~> 0.16.1)
- term-ansicolor (~> 1.3)
- thor (>= 0.19.4, < 2.0)
- tins (~> 1.6)
+ coveralls_reborn (0.25.0)
+ simplecov (>= 0.18.1, < 0.22.0)
+ term-ansicolor (~> 1.6)
+ thor (>= 0.20.3, < 2.0)
+ tins (~> 1.16)
crass (1.0.6)
database_cleaner (2.0.1)
database_cleaner-active_record (~> 2.0.0)
@@ -140,7 +139,6 @@ GEM
json (2.6.1)
launchy (2.5.0)
addressable (~> 2.7)
- libv8-node (16.10.0.0)
listen (3.7.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
@@ -154,8 +152,6 @@ GEM
method_source (1.0.0)
mini_mime (1.1.2)
mini_portile2 (2.6.1)
- mini_racer (0.6.0)
- libv8-node (~> 16.10.0.0)
minitest (5.15.0)
nio4r (2.5.8)
nokogiri (1.12.5)
@@ -310,11 +306,12 @@ GEM
rack-proxy (>= 0.6.1)
railties (>= 5.2)
semantic_range (>= 2.3.0)
- simplecov (0.16.1)
+ simplecov (0.21.2)
docile (~> 1.1)
- json (>= 1.8, < 3)
- simplecov-html (~> 0.10.0)
- simplecov-html (0.10.2)
+ simplecov-html (~> 0.11)
+ simplecov_json_formatter (~> 0.1)
+ simplecov-html (0.12.3)
+ simplecov_json_formatter (0.1.4)
spring (4.0.0)
spring-commands-rspec (1.0.4)
spring (>= 0.9.1)
@@ -330,7 +327,7 @@ GEM
tins (~> 1.0)
thor (1.2.1)
tilt (2.0.10)
- tins (1.30.0)
+ tins (1.31.1)
sync
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
@@ -372,7 +369,7 @@ DEPENDENCIES
capybara
capybara-screenshot
coffee-rails
- coveralls
+ coveralls_reborn (~> 0.25.0)
database_cleaner
factory_bot_rails
foreman
@@ -380,7 +377,6 @@ DEPENDENCIES
jbuilder
launchy
listen
- mini_racer
pg
pry
pry-byebug
diff --git a/app/models/git_commit_sha.rb b/app/models/git_commit_sha.rb
index 57e45213..598ab20d 100644
--- a/app/models/git_commit_sha.rb
+++ b/app/models/git_commit_sha.rb
@@ -9,7 +9,7 @@ def self.current_sha
end
def self.reset_current_sha
- self.current_sha = nil
+ @current_sha = nil
end
# Assumes the git CLI is available. This is not the case in production on Heroku.
diff --git a/app/views/comments/index.html.erb b/app/views/comments/index.html.erb
index 0cf6de0e..a35b7206 100644
--- a/app/views/comments/index.html.erb
+++ b/app/views/comments/index.html.erb
@@ -19,9 +19,13 @@
<%= comment.author %> |
<%= comment.text %> |
+
+
<%= link_to 'Show', comment %> |
<%= link_to 'Edit', edit_comment_path(comment) %> |
- <%= link_to 'Destroy', comment, method: :delete, data: { confirm: 'Are you sure?' } %> |
+
+
+ <%= link_to 'Destroy', comment, method: :delete, data: { method: :delete, confirm: 'Are you sure?' } %> |
<% end %>
diff --git a/client/app/bundles/comments/startup/ClientRouterApp.jsx b/client/app/bundles/comments/startup/ClientRouterApp.jsx
index 8b34563e..9cbcffb6 100644
--- a/client/app/bundles/comments/startup/ClientRouterApp.jsx
+++ b/client/app/bundles/comments/startup/ClientRouterApp.jsx
@@ -5,17 +5,15 @@ import ReactOnRails from 'react-on-rails';
import { BrowserRouter } from 'react-router-dom';
import routes from '../routes/routes.jsx';
-function ClientRouterApp(_props, _railsContext) {
+function ClientRouterApp(_props) {
const store = ReactOnRails.getStore('routerCommentsStore');
// eslint-disable-next-line react/display-name
- return function () {
- return (
-
- {routes}
-
- );
- };
+ return (
+
+ {routes}
+
+ );
}
export default ClientRouterApp;
diff --git a/client/app/bundles/comments/startup/NavigationBarApp.jsx b/client/app/bundles/comments/startup/NavigationBarApp.jsx
index 2f346d6f..5c4f40ba 100644
--- a/client/app/bundles/comments/startup/NavigationBarApp.jsx
+++ b/client/app/bundles/comments/startup/NavigationBarApp.jsx
@@ -23,18 +23,16 @@ function NavigationBarApp(_props, railsContext) {
} else if (pathname === paths.NO_ROUTER_PATH) {
store = ReactOnRails.getStore('commentsStore', false);
} else {
- return ;
+ 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 function () {
- return (
-
-
-
- );
- };
+ return () => (
+
+
+
+ );
}
export default NavigationBarApp;
diff --git a/client/app/bundles/comments/startup/ServerRouterApp.jsx b/client/app/bundles/comments/startup/ServerRouterApp.jsx
index be1a1c51..49a611b6 100644
--- a/client/app/bundles/comments/startup/ServerRouterApp.jsx
+++ b/client/app/bundles/comments/startup/ServerRouterApp.jsx
@@ -25,15 +25,13 @@ 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 function () {
- return (
-
-
- {routes}
-
-
- );
- };
+ return () => (
+
+
+ {routes}
+
+
+ );
}
export default ServerRouterApp;
diff --git a/client/app/packs/bootstrap.js b/client/app/packs/bootstrap.js
deleted file mode 100644
index ce95fa89..00000000
--- a/client/app/packs/bootstrap.js
+++ /dev/null
@@ -1 +0,0 @@
-import 'bootstrap-loader';
diff --git a/client/app/packs/client-bundle.js b/client/app/packs/client-bundle.js
index 024c62d8..67ef7f49 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';
+import 'expose-loader?exposes=$,jQuery!jquery';
import 'jquery-ujs';
import App from '../bundles/comments/startup/App.jsx';
diff --git a/config/initializers/react_on_rails.rb b/config/initializers/react_on_rails.rb
index e49fcc0b..7c1acdf6 100644
--- a/config/initializers/react_on_rails.rb
+++ b/config/initializers/react_on_rails.rb
@@ -3,8 +3,9 @@
# 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[ app-bundle.js vendor-bundle.js app-bundle.css
- vendor-bundle.css server-bundle.js ]
+ config.webpack_generated_files = %w[ client-bundle.js server-bundle.js ]
+
+ config.build_test_command = "RAILS_ENV=test bin/webpacker"
# This is the file used for server rendering of React when using `(prerender: true)`
# If you are never using server rendering, you may set this to "".
diff --git a/config/webpacker.yml b/config/webpacker.yml
index 161cb48f..285182e2 100644
--- a/config/webpacker.yml
+++ b/config/webpacker.yml
@@ -49,9 +49,6 @@ test:
<<: *default
compile: true
- # Compile test packs to a separate directory
- public_output_path: packs-test
-
production:
<<: *default
diff --git a/package.json b/package.json
index e50ee31b..ea832b22 100644
--- a/package.json
+++ b/package.json
@@ -3,8 +3,8 @@
"version": "1.1.0",
"description": "Code from the React Webpack tutorial.",
"engines": {
- "node": "16.13.2",
- "yarn": "1.22.17"
+ "node": "16",
+ "yarn": "1.22"
},
"repository": {
"type": "git",
@@ -35,10 +35,10 @@
"@rails/actioncable": "6.1.4-4",
"autoprefixer": "^7.1.5",
"axios": "^0.17.1",
- "babel-loader": "8",
+ "babel-loader": "^8.2.3",
"babel-plugin-macros": "^3.1.0",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
- "bootstrap-loader": "judahmeek/bootstrap-loader#judahmeek/webpack-5",
+ "bootstrap-loader": "4.0.0",
"bootstrap-sass": "^3.3.7",
"classnames": "^2.2.5",
"compression-webpack-plugin": "9",
@@ -46,7 +46,7 @@
"css-minimizer-webpack-plugin": "^3.3.1",
"es5-shim": "^4.5.9",
"estraverse": "^4.2.0",
- "expose-loader": "^1.0.0",
+ "expose-loader": "^4.0.0",
"immutable": "^3.8.2",
"imports-loader": "^1.1.0",
"intl": "^1.2.5",
@@ -91,7 +91,6 @@
"@webpack-cli/serve": "^1.6.0",
"babel-eslint": "^8.0.2",
"babel-jest": "^23.4.2",
- "babel-loader": "^8.2.3",
"body-parser": "^1.18.2",
"eslint": "^8.6.0",
"eslint-config-prettier": "^8.3.0",
diff --git a/spec/system/add_new_comment_spec.rb b/spec/system/add_new_comment_spec.rb
index 343ab192..05d55901 100644
--- a/spec/system/add_new_comment_spec.rb
+++ b/spec/system/add_new_comment_spec.rb
@@ -1,64 +1,175 @@
# frozen_string_literal: true
require "rails_helper"
-require "system/shared/examples"
require "system/shared/contexts"
describe "Add new comment" do
context "when React Router", page: :main, js: true, type: :system do
- context "with Horizontal Form", form: :horizontal do
- include_examples "New Comment Submission", true
- include_examples "Validation errors displaying"
+ describe "with Horizontal Form" do
+ subject { page }
+ before {
+ 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
end
- context "with Inline Form", form: :inline do
- include_examples "New Comment Submission", true
- include_examples "Validation errors displaying"
+ describe "with Inline Form" do
+ subject { page }
+ before {
+ 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
end
- context "with Stacked Form", form: :stacked do
- include_examples "New Comment Submission", true
- include_examples "Validation errors displaying"
+ describe "with Stacked Form" do
+ subject { page }
+ before {
+ 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
end
end
context "when React/Redux", page: :react_demo, js: true, type: :system do
- context "with Horizontal Form", form: :horizontal do
- include_examples "New Comment Submission", true
- include_examples "Validation errors displaying"
+ describe "with Horizontal Form" do
+ subject { page }
+ before {
+ 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
end
- context "with Inline Form", form: :inline do
- include_examples "New Comment Submission", true
- include_examples "Validation errors displaying"
+ describe "with Inline Form" do
+ subject { page }
+ before {
+ 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
end
- context "with Stacked Form", form: :stacked do
- include_examples "New Comment Submission", true
- include_examples "Validation errors displaying"
+ describe "with Stacked Form" do
+ subject { page }
+ before {
+ 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
end
end
context "when simple page", page: :simple, js: true, type: :system do
- context "with Horizontal Form", form: :horizontal do
- include_examples "New Comment Submission", false
- include_examples "Validation errors displaying"
+ describe "with Horizontal Form" do
+ subject { page }
+ before {
+ 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
end
- context "with Inline Form", form: :inline do
- include_examples "New Comment Submission", false
- include_examples "Validation errors displaying"
+ describe "with Inline Form" do
+ subject { page }
+ before {
+ 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
end
- context "with the Stacked Form", form: :stacked do
- include_examples "New Comment Submission", false
- include_examples "Validation errors displaying"
+ describe "with the Stacked Form" do
+ subject { page }
+ before {
+ 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
end
end
-
- context "when from classic page", page: :classic do
- before { click_link "New Comment" }
-
- include_examples "New Comment Submission", false
- end
end
diff --git a/spec/system/destroy_comment_spec.rb b/spec/system/destroy_comment_spec.rb
index 984abd1a..cfa73f29 100644
--- a/spec/system/destroy_comment_spec.rb
+++ b/spec/system/destroy_comment_spec.rb
@@ -4,13 +4,20 @@
require "system/shared/contexts"
describe "Destroy a comment", existing_comment: true do
- context "when from classic page", page: :classic do
- let(:comment) { Comment.first }
+ context "when from classic page" do
+ let(:comment) { FactoryBot.build(:comment) }
it "clicking destroy link destroys comment" do
+ visit comments_path
+
+ click_link "New Comment"
+ submit_form(name: comment.author, text: comment.text)
+ click_link "Back"
+
accept_confirm do
- click_link "Destroy", href: comment_path(comment)
+ click_link "Destroy"
end
+
expect(page).not_to have_css(".comment", text: comment.author)
expect(page).not_to have_css(".comment", text: comment.text)
end
diff --git a/spec/system/edit_comment_spec.rb b/spec/system/edit_comment_spec.rb
index 0d0949bc..1b68737b 100644
--- a/spec/system/edit_comment_spec.rb
+++ b/spec/system/edit_comment_spec.rb
@@ -1,32 +1,36 @@
# frozen_string_literal: true
require "rails_helper"
-require "system/shared/examples"
require "system/shared/contexts"
describe "Edit a comment", existing_comment: true do
- let(:comment) { Comment.first }
+ let(:comment) { FactoryBot.build(:comment) }
+ let(:edited_name) { "Abraham Lincoln" }
- context "when from classic page", page: :classic do
- before { click_link "Edit", match: :first }
+ context "when from classic page" do
+ it "comment is updated when edit is submitted" do
+ visit comments_path
+ click_link "New Comment"
+ submit_form
- context "when edit is submitted" do
- let(:edited_name) { "Abraham Lincoln" }
+ click_link "Edit", match: :first
- include_context "Form Submitted", name: :edited_name
-
- it "comment is updated" do
- expect(page).to have_css(".comment", text: :edited_name)
- expect(page).to have_css("#notice", text: "Comment was successfully updated.")
- end
+ submit_form(name: :edited_name)
+ expect(page).to have_css(".comment", text: :edited_name)
+ expect(page).to have_css("#notice", text: "Comment was successfully updated.")
end
- context "when edit is submitted with blank fields", blank_form_submitted: true do
- it "comment is not updated" do
- expect(page).not_to have_success_message
- expect(page).to have_failure_message
- expect(page).not_to have_css(".comment", text: "")
- end
+ it "comment is not updated when edit is submitted with blank fields", blank_form_submitted: true do
+ visit comments_path
+ click_link "New Comment"
+ submit_form
+
+ click_link "Edit", match: :first
+ submit_form(name: "", text: "")
+
+ expect(page).not_to have_success_message
+ expect(page).to have_failure_message
+ expect(page).not_to have_css(".comment", text: "")
end
end
end
diff --git a/spec/system/pages_spec.rb b/spec/system/pages_spec.rb
index f95db2c8..c419de45 100644
--- a/spec/system/pages_spec.rb
+++ b/spec/system/pages_spec.rb
@@ -3,7 +3,7 @@
require "rails_helper"
shared_examples "Git Commit SHA" do
- background { visit root_path }
+ 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 24218478..48c419b6 100644
--- a/spec/system/react_router_demo_spec.rb
+++ b/spec/system/react_router_demo_spec.rb
@@ -6,6 +6,7 @@
describe "React Router Routes", js: true, type: :system do
context "when Root URL", page: :main do
it "shows comments section" do
+ visit root_path
click_link "Comments (Root URL)"
expect(page).to have_selector("h2", text: "Comments")
end
@@ -13,13 +14,17 @@
context "when /react-router URL", page: :main do
it "shows 'React Router is working!' message" do
+ visit root_path
click_link "Test React Router ('/react-router')"
expect(page).to have_selector("h1", text: "React Router is working!")
end
end
context "when /react-router/redirect URL", page: :main do
- before { click_link "Test Redirect (url to '/react-router/redirect' which goes to root '/')" }
+ before {
+ visit root_path
+ click_link "Test Redirect (url to '/react-router/redirect' which goes to root '/')"
+ }
it "shows comments section" do
expect(page).to have_selector("h2", text: "Comments")
diff --git a/spec/system/shared/contexts.rb b/spec/system/shared/contexts.rb
index 1faa9bdc..9b751e85 100644
--- a/spec/system/shared/contexts.rb
+++ b/spec/system/shared/contexts.rb
@@ -2,63 +2,9 @@
require "rails_helper"
-# Pages
-shared_context "when React Router Demo", page: :main do
- background { visit root_path }
-end
-shared_context "when React Demo", page: :react_demo do
- background { visit no_router_path }
-end
-shared_context "when Simple Page", page: :simple do
- background { visit simple_path }
-end
-shared_context "when Classic Page", page: :classic do
- background { visit comments_path }
-end
-
-# Forms
-shared_context "when Horizontal Form", form: :horizontal do
- background do
- # added an extra click on this the non-default link to try to tease out a poltergeist crash
- click_link "Inline Form"
- expect(page).to have_css("form.commentForm.form-inline")
-
- click_link "Horizontal Form"
- expect(page).to have_css("form.commentForm.form-horizontal")
- end
-end
-shared_context "when Inline Form", form: :inline do
- background do
- click_link "Inline Form"
- expect(page).to have_css("form.commentForm.form-inline")
- end
-end
-shared_context "when Stacked Form", form: :stacked do
- background do
- click_link "Stacked Form"
- expect(page).to have_css("form.commentForm.form-stacked")
- end
-end
-
# Form Submission
-shared_context "when Form Submitted", form_submitted: true do |name: "Spicoli", text: "dude!"|
- let(:hint_name) { "Your Name" }
- let(:hint_text) { "Say something using markdown..." }
- let(:name) { name }
- let(:text) { text }
-
- background do
- fill_in hint_name, with: name
- fill_in hint_text, with: text
- click_button "Post"
- end
-end
-
-shared_context "when Form Submitted with Blank Fields", blank_form_submitted: true do
- include_context "Form Submitted", name: "", text: ""
-end
-
-# Fixtures
-shared_context "when Existing Comment", existing_comment: true do
- before { Comment.create(author: "John Doe", text: "Hello there!") }
+def submit_form(name: "Spicoli", text: "dude!")
+ fill_in "Your Name", with: name
+ fill_in "Say something using markdown...", with: text
+ click_button "Post"
end
diff --git a/spec/system/shared/examples.rb b/spec/system/shared/examples.rb
deleted file mode 100644
index 9dc7e59e..00000000
--- a/spec/system/shared/examples.rb
+++ /dev/null
@@ -1,65 +0,0 @@
-# frozen_string_literal: true
-
-require "rails_helper"
-require "system/shared/contexts"
-
-shared_examples "when New Comment Submission" do |expect_comment_count|
- context "when the new comment is submitted" do
- let(:name) { "John Smith" }
- let(:text) { "Hello there!" }
-
- include_context "Form Submitted", name: :name, text: :text
-
- scenario "when comment is added" do
- expect(page).to have_css(".js-comment-author", text: name)
- expect(page).to have_css(".js-comment-text", text: text)
- expect(page).to have_no_content("Your comment was not saved!")
- if expect_comment_count
- expect(page).to have_css("#js-comment-count",
- text: "Comments: #{Comment.count}")
- end
- end
- end
-
- context "when the new comment is submitted with blank fields", blank_form_submitted: true do
- let!(:comments_count) { all(".comment").size }
-
- scenario "comment is not added" do
- expect(page).to have_selector(".comment", count: comments_count)
- if expect_comment_count
- expect(page).to have_css("#js-comment-count",
- text: "Comments: #{Comment.count}")
- end
- end
- end
-
- context "with iframe text" do
- let(:iframe_text) { '' }
-
- include_context "Form Submitted", text: :iframe_text
-
- scenario "doesn't add an iframe" do
- expect(page).not_to have_css("iframe")
- end
- end
-end
-
-shared_examples "Validation errors displaying" do
- context "when the new comment is submitted with blank fields", blank_form_submitted: true do
- scenario "validation errors displayed" do
- expect(page).to have_content("Your comment was not saved!")
- expect(page).to have_content("Author: can't be blank")
- expect(page).to have_content("Text: can't be blank")
-
- # with a successful consequent comment submitted
- # the validation warnings should disappear
- fill_in "Your Name", with: "Some name"
- fill_in "Say something using markdown...", with: "Some text"
- click_button "Post"
-
- 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/yarn.lock b/yarn.lock
index fd2ad060..ba3ab974 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -86,15 +86,6 @@
source-map "^0.5.0"
trim-right "^1.0.1"
-"@babel/generator@^7.16.7":
- version "7.16.7"
- resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.16.7.tgz#b42bf46a3079fa65e1544135f32e7958f048adbb"
- integrity sha512-/ST3Sg8MLGY5HVYmrjOgL60ENux/HfO/CsUh7y4MalThufhE/Ff/6EibFDHi4jiDCaWfJKoqbE6oTh21c5hrRg==
- dependencies:
- "@babel/types" "^7.16.7"
- jsesc "^2.5.1"
- source-map "^0.5.0"
-
"@babel/generator@^7.16.8":
version "7.16.8"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.16.8.tgz#359d44d966b8cd059d543250ce79596f792f2ebe"
@@ -2247,13 +2238,13 @@ babel-jest@^23.4.2, babel-jest@^23.6.0:
babel-plugin-istanbul "^4.1.6"
babel-preset-jest "^23.2.0"
-babel-loader@8:
- version "8.2.3"
- resolved "https://registry.yarnpkg.com/babel-loader/-/babel-loader-8.2.3.tgz#8986b40f1a64cacfcb4b8429320085ef68b1342d"
- integrity sha512-n4Zeta8NC3QAsuyiizu0GkmRcQ6clkV9WFUnUf1iXP//IeSKbWjofW3UHyZVwlOB4y039YQKefawyTn64Zwbuw==
+babel-loader@^8.2.3:
+ version "8.2.5"
+ resolved "https://registry.yarnpkg.com/babel-loader/-/babel-loader-8.2.5.tgz#d45f585e654d5a5d90f5350a779d7647c5ed512e"
+ integrity sha512-OSiFfH89LrEMiWd4pLNqGz4CwJDtbs2ZVc+iGu2HrkRfPxId9F2anQj38IxWpmRfsUY0aBZYi1EFcd3mhtRMLQ==
dependencies:
find-cache-dir "^3.3.1"
- loader-utils "^1.4.0"
+ loader-utils "^2.0.0"
make-dir "^3.1.0"
schema-utils "^2.6.5"
@@ -2504,9 +2495,10 @@ boolify@^1.0.0:
resolved "https://registry.yarnpkg.com/boolify/-/boolify-1.0.1.tgz#b5c09e17cacd113d11b7bb3ed384cc012994d86b"
integrity sha1-tcCeF8rNET0Rt7s+04TMASmU2Gs=
-bootstrap-loader@judahmeek/bootstrap-loader#judahmeek/webpack-5:
- version "3.0.4"
- resolved "https://codeload.github.com/judahmeek/bootstrap-loader/tar.gz/f9addb04f657b0a5ff2bed701ab66ac28f9a9a62"
+bootstrap-loader@4.0.0:
+ version "4.0.0"
+ resolved "https://registry.yarnpkg.com/bootstrap-loader/-/bootstrap-loader-4.0.0.tgz#ca8f9534f35ecb15a824ca60a6abc9cd5b70150d"
+ integrity sha512-LzeZySPqDcfRmNZcddwfLc83D1Szv0EI0U3z2oiupoBCmCKXPJ4sMqhMZwSV6IRLuX6eZjG38uuiWgCLlFZPXg==
dependencies:
chalk "2.4.2"
escape-regexp "0.0.1"
@@ -4357,13 +4349,10 @@ exports-loader@0.7.0:
loader-utils "^1.1.0"
source-map "0.5.0"
-expose-loader@^1.0.0:
- version "1.0.3"
- resolved "https://registry.yarnpkg.com/expose-loader/-/expose-loader-1.0.3.tgz#5686d3b78cac8831c4af11c3dc361563deb8a9c0"
- integrity sha512-gP6hs3vYeWIqyoVfsApGQcgCEpbcI1xe+celwI31zeDhXz2q03ycBC1+75IlQUGaYvj6rAloFIe/NIBnEElLsQ==
- dependencies:
- loader-utils "^2.0.0"
- schema-utils "^3.0.0"
+expose-loader@^4.0.0:
+ version "4.0.0"
+ resolved "https://registry.yarnpkg.com/expose-loader/-/expose-loader-4.0.0.tgz#aa6f06f57cbc904175de4fe4eaff6211337e0231"
+ integrity sha512-kUEvHyf6MPR2ubZCL9aziP9Br5wxMvq1cghTpYhM6MW52NPq+7hXixw2EqQuI1SvGb1fDjc2ehJOg6645wR6ww==
express@^4.16.2, express@^4.17.1:
version "4.17.2"
@@ -6487,7 +6476,7 @@ loader-utils@1.2.3:
emojis-list "^2.0.0"
json5 "^1.0.1"
-loader-utils@^1.0.2, loader-utils@^1.1.0, loader-utils@^1.4.0:
+loader-utils@^1.0.2, loader-utils@^1.1.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.4.0.tgz#c579b5e34cb34b1a74edc6c1fb36bfa371d5a613"
integrity sha512-qH0WSMBtn/oHuwjy/NucEgbx5dbxxnxup9s4PVXJUDHZBQY+s0NWA9rJf53RBnQZxfch7euUui7hpoAPvALZdA==