From 87c1c67b5c5b13320c978a1794bab664a1b36160 Mon Sep 17 00:00:00 2001 From: Etienne Ischer Date: Mon, 21 Jun 2021 20:54:17 +0200 Subject: [PATCH] migrate from turbolinks to turbo --- Gemfile | 6 +- Gemfile.lock | 30 +++-- app/controllers/rp_worlds_controller.rb | 45 ++++++- app/javascript/packs/application.js | 3 +- app/views/rp_worlds/_form.html.erb | 15 +++ app/views/rp_worlds/edit.html.erb | 6 + app/views/rp_worlds/index.html.erb | 27 ++-- app/views/rp_worlds/new.html.erb | 5 + app/views/rp_worlds/show.html.erb | 5 + config/cable.yml | 3 +- config/routes.rb | 2 +- package.json | 4 +- spec/requests/rp_world_spec.rb | 129 +++++++++++++++++++- spec/routing/rp_worlds_routing_spec.rb | 38 ++++++ spec/views/rp_worlds/edit.html.erb_spec.rb | 18 +++ spec/views/rp_worlds/index.html.erb_spec.rb | 19 +++ spec/views/rp_worlds/new.html.erb_spec.rb | 18 +++ spec/views/rp_worlds/show.html.erb_spec.rb | 14 +++ yarn.lock | 20 ++- 19 files changed, 367 insertions(+), 40 deletions(-) create mode 100644 app/views/rp_worlds/_form.html.erb create mode 100644 app/views/rp_worlds/edit.html.erb create mode 100644 app/views/rp_worlds/new.html.erb create mode 100644 spec/routing/rp_worlds_routing_spec.rb create mode 100644 spec/views/rp_worlds/edit.html.erb_spec.rb create mode 100644 spec/views/rp_worlds/index.html.erb_spec.rb create mode 100644 spec/views/rp_worlds/new.html.erb_spec.rb create mode 100644 spec/views/rp_worlds/show.html.erb_spec.rb diff --git a/Gemfile b/Gemfile index 4654550..12ce9f7 100644 --- a/Gemfile +++ b/Gemfile @@ -18,8 +18,8 @@ gem 'puma', '~> 5.0' gem 'sass-rails', '>= 6' # Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker gem 'webpacker', '~> 5.0' -# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks -gem 'turbolinks', '~> 5' +# The speed of a single-page web application without having to write any JavaScript. +gem 'turbo-rails' # Use Redis adapter to run Action Cable in production gem 'redis', '~> 4.2.5' # Use Active Model has_secure_password @@ -71,7 +71,7 @@ group :development do gem 'web-console', '>= 4.1.0' # Display performance information such as SQL time and flame graphs for each request in your browser. # Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md - gem 'rack-mini-profiler', '~> 2.0' + gem 'rack-mini-profiler', '~> 2.3.2' , git: "https://github.com/ceritium/rack-mini-profiler", branch: 'turbodrive-support' # The Listen gem listens to file modifications and notifies you about the changes. Works everywhere gem 'listen', '~> 3.3' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring diff --git a/Gemfile.lock b/Gemfile.lock index f4d34d9..a33a153 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,6 +6,14 @@ GIT require_all typhoeus (~> 1.1) +GIT + remote: https://github.com/ceritium/rack-mini-profiler + revision: da799a00e15faa04f2d7e95ccea1ede6eb6ed622 + branch: turbodrive-support + specs: + rack-mini-profiler (2.3.2) + rack (>= 1.2.0) + GEM remote: https://rubygems.org/ specs: @@ -72,7 +80,7 @@ GEM public_suffix (>= 2.0.2, < 5.0) ast (2.4.2) awesome_print (1.9.2) - backport (1.1.2) + backport (1.2.0) bcrypt (3.1.16) benchmark (0.1.1) bindex (0.8.1) @@ -163,7 +171,7 @@ GEM multi_xml (0.6.0) multipart-post (2.1.1) nio4r (2.5.7) - nokogiri (1.11.6-x86_64-linux) + nokogiri (1.11.7-x86_64-linux) racc (~> 1.4) oauth2 (1.4.7) faraday (>= 0.8, < 2.0) @@ -199,8 +207,6 @@ GEM nio4r (~> 2.0) racc (1.5.2) rack (2.2.3) - rack-mini-profiler (2.3.1) - rack (>= 1.2.0) rack-proxy (0.6.5) rack rack-test (1.1.0) @@ -272,7 +278,7 @@ GEM rspec-mocks (~> 3.10) rspec-support (~> 3.10) rspec-support (3.10.2) - rubocop (1.16.0) + rubocop (1.17.0) parallel (~> 1.10) parser (>= 3.0.0.0) rainbow (>= 2.2.2, < 4.0) @@ -329,10 +335,11 @@ GEM simplecov_json_formatter (~> 0.1) simplecov-html (0.12.3) simplecov_json_formatter (0.1.2) - solargraph (0.41.1) - backport (~> 1.1) + solargraph (0.42.3) + backport (~> 1.2) benchmark bundler (>= 1.17.2) + diff-lcs (~> 1.4) e2mmap jaro_winkler (~> 1.5) kramdown (~> 2.3) @@ -353,9 +360,8 @@ GEM sprockets (>= 3.0.0) thor (1.1.0) tilt (2.0.10) - turbolinks (5.2.1) - turbolinks-source (~> 5.2) - turbolinks-source (5.2.0) + turbo-rails (0.5.9) + rails (>= 6.0.0) typhoeus (1.4.0) ethon (>= 0.9.0) tzinfo (2.0.4) @@ -407,7 +413,7 @@ DEPENDENCIES pg (~> 1.1) pry-rails (~> 0.3.9) puma (~> 5.0) - rack-mini-profiler (~> 2.0) + rack-mini-profiler (~> 2.3.2)! rails (~> 6.1.3, >= 6.1.3.1) rails-erd rails-i18n (~> 6.0.0) @@ -425,7 +431,7 @@ DEPENDENCIES simplecov solargraph spring - turbolinks (~> 5) + turbo-rails tzinfo-data web-console (>= 4.1.0) webdrivers diff --git a/app/controllers/rp_worlds_controller.rb b/app/controllers/rp_worlds_controller.rb index ed5eef5..5ba84dd 100644 --- a/app/controllers/rp_worlds_controller.rb +++ b/app/controllers/rp_worlds_controller.rb @@ -1,9 +1,52 @@ class RpWorldsController < ApplicationController + before_action :set_rp_world, only: [:show, :edit, :update, :destroy] + + # GET /rp_worlds def index @rp_worlds = RpWorld.all end - def show + # GET /rp_worlds/1 + def show; end + + # GET /rp_worlds/1/edit + def edit; end + + # POST /rp_worlds + def create + @rp_world = RpWorld.new(rp_world_params) + + if @rp_world.save + redirect_to @rp_world, notice: 'Rp world was successfully created.' + else + render :new + end + end + + # PATCH/PUT /rp_worlds/1 + def update + if @rp_world.update(rp_world_params) + redirect_to @rp_world, notice: 'Rp world was successfully updated.' + else + render :edit + end + end + + # DELETE /rp_worlds/1 + def destroy + @rp_world.destroy + redirect_to rp_worlds_url, notice: 'Rp world was successfully destroyed.' + end + + private + + # Use callbacks to share common setup or constraints between actions. + def set_rp_world @rp_world = RpWorld.includes(:wow_characters).find(params[:id]) end + + # Only allow a list of trusted parameters through. + def rp_world_params + params.require(:rp_world).permit(:name, :description) + end end diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index 2397e74..671b032 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -4,7 +4,7 @@ // that code so it'll be compiled. import Rails from "@rails/ujs" -import Turbolinks from "turbolinks" +import "@hotwired/turbo-rails" import * as ActiveStorage from "@rails/activestorage" import "channels" @@ -20,5 +20,4 @@ document.addEventListener("turbolinks:load", () => { }) Rails.start() -Turbolinks.start() ActiveStorage.start() diff --git a/app/views/rp_worlds/_form.html.erb b/app/views/rp_worlds/_form.html.erb new file mode 100644 index 0000000..5af5355 --- /dev/null +++ b/app/views/rp_worlds/_form.html.erb @@ -0,0 +1,15 @@ +<%= form_with(model: rp_world) do |form| %> +
+ <%= form.label :name %> + <%= form.text_field :name %> +
+ +
+ <%= form.label :description %> + <%= form.text_field :description %> +
+ +
+ <%= form.submit %> +
+<% end %> diff --git a/app/views/rp_worlds/edit.html.erb b/app/views/rp_worlds/edit.html.erb new file mode 100644 index 0000000..5e800e5 --- /dev/null +++ b/app/views/rp_worlds/edit.html.erb @@ -0,0 +1,6 @@ +

Editing Rp World

+ +<%= render 'form', rp_world: @rp_world %> + +<%= link_to 'Show', @rp_world %> | +<%= link_to 'Back', rp_worlds_path %> diff --git a/app/views/rp_worlds/index.html.erb b/app/views/rp_worlds/index.html.erb index a9e485c..a827513 100644 --- a/app/views/rp_worlds/index.html.erb +++ b/app/views/rp_worlds/index.html.erb @@ -1,18 +1,27 @@ -

Characters list

+

<%= notice %>

- +

Rp Worlds

+ +
- - + + + - <% @rp_worlds.each do |world| %> - - - - + <% @rp_worlds.each do |rp_world| %> + + + + + + <% end %>
<%= t('rp_worlds.world_list.name') %><%= t('rp_worlds.world_list.description') %><%= t('rp_worlds.world_list.name') %>
<%= link_to world.name, world %><%= world.description %>
<%= rp_world.name %><%= link_to 'Show', rp_world %><%= link_to 'Edit', edit_rp_world_path(rp_world) %><%= link_to 'Destroy', rp_world, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Rp World', new_rp_world_path %> diff --git a/app/views/rp_worlds/new.html.erb b/app/views/rp_worlds/new.html.erb new file mode 100644 index 0000000..2397b7f --- /dev/null +++ b/app/views/rp_worlds/new.html.erb @@ -0,0 +1,5 @@ +

New Rp World

+ +<%= render 'form', rp_world: @rp_world %> + +<%= link_to 'Back', rp_worlds_path %> diff --git a/app/views/rp_worlds/show.html.erb b/app/views/rp_worlds/show.html.erb index 6591874..8cd336d 100644 --- a/app/views/rp_worlds/show.html.erb +++ b/app/views/rp_worlds/show.html.erb @@ -1,3 +1,5 @@ +

<%= notice %>

+
@@ -15,3 +17,6 @@

Suite...

+ +<%= link_to 'Edit', edit_rp_world_path(@rp_world) %> | +<%= link_to 'Back', rp_worlds_path %> diff --git a/config/cable.yml b/config/cable.yml index c15f165..0268ca0 100644 --- a/config/cable.yml +++ b/config/cable.yml @@ -1,5 +1,6 @@ development: - adapter: async + adapter: redis + url: redis://localhost:6379/1 test: adapter: test diff --git a/config/routes.rb b/config/routes.rb index 618e185..944d29b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,6 +14,6 @@ Rails.application.routes.draw do resources :wow_mounts, only: [:index, :show] resources :wow_pets, only: [:index, :show] resources :wow_reputations, only: [:index, :show] - resources :rp_worlds, only: [:index, :show] + resources :rp_worlds end end diff --git a/package.json b/package.json index 394b2ce..12970c3 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "private": true, "dependencies": { "@fortawesome/fontawesome-free": "^5.15.3", + "@hotwired/turbo-rails": "^7.0.0-beta.5", "@popperjs/core": "^2.9.2", "@rails/actioncable": "^6.0.0", "@rails/activestorage": "^6.0.0", @@ -10,8 +11,7 @@ "@rails/webpacker": "5.2.1", "bootstrap": "^5.0.0-beta3", "flag-icon-css": "^3.5.0", - "jquery": "^3.6.0", - "turbolinks": "^5.2.0" + "jquery": "^3.6.0" }, "version": "0.1.0", "devDependencies": { diff --git a/spec/requests/rp_world_spec.rb b/spec/requests/rp_world_spec.rb index 6f84bc2..03243a4 100644 --- a/spec/requests/rp_world_spec.rb +++ b/spec/requests/rp_world_spec.rb @@ -1,7 +1,130 @@ -require 'rails_helper' + require 'rails_helper' + +# This spec was generated by rspec-rails when you ran the scaffold generator. +# It demonstrates how one might use RSpec to test the controller code that +# was generated by Rails when you ran the scaffold generator. +# +# It assumes that the implementation code is generated by the rails scaffold +# generator. If you are using any extension libraries to generate different +# controller code, this generated spec may or may not pass. +# +# It only uses APIs available in rails and/or rspec-rails. There are a number +# of tools you can use to make these specs even more expressive, but we're +# sticking to rails and rspec-rails APIs to keep things simple and stable. + +RSpec.describe "/rp_worlds", type: :request do + + # RpWorld. As you add validations to RpWorld, be sure to + # adjust the attributes here as well. + let(:valid_attributes) { + skip("Add a hash of attributes valid for your model") + } + + let(:invalid_attributes) { + skip("Add a hash of attributes invalid for your model") + } -RSpec.describe "RpWorlds", type: :request do describe "GET /index" do - pending "add some examples (or delete) #{__FILE__}" + it "renders a successful response" do + RpWorld.create! valid_attributes + get rp_worlds_url + expect(response).to be_successful + end + end + + describe "GET /show" do + it "renders a successful response" do + rp_world = RpWorld.create! valid_attributes + get rp_world_url(rp_world) + expect(response).to be_successful + end + end + + describe "GET /new" do + it "renders a successful response" do + get new_rp_world_url + expect(response).to be_successful + end + end + + describe "GET /edit" do + it "render a successful response" do + rp_world = RpWorld.create! valid_attributes + get edit_rp_world_url(rp_world) + expect(response).to be_successful + end + end + + describe "POST /create" do + context "with valid parameters" do + it "creates a new RpWorld" do + expect { + post rp_worlds_url, params: { rp_world: valid_attributes } + }.to change(RpWorld, :count).by(1) + end + + it "redirects to the created rp_world" do + post rp_worlds_url, params: { rp_world: valid_attributes } + expect(response).to redirect_to(rp_world_url(RpWorld.last)) + end + end + + context "with invalid parameters" do + it "does not create a new RpWorld" do + expect { + post rp_worlds_url, params: { rp_world: invalid_attributes } + }.to change(RpWorld, :count).by(0) + end + + it "renders a successful response (i.e. to display the 'new' template)" do + post rp_worlds_url, params: { rp_world: invalid_attributes } + expect(response).to be_successful + end + end + end + + describe "PATCH /update" do + context "with valid parameters" do + let(:new_attributes) { + skip("Add a hash of attributes valid for your model") + } + + it "updates the requested rp_world" do + rp_world = RpWorld.create! valid_attributes + patch rp_world_url(rp_world), params: { rp_world: new_attributes } + rp_world.reload + skip("Add assertions for updated state") + end + + it "redirects to the rp_world" do + rp_world = RpWorld.create! valid_attributes + patch rp_world_url(rp_world), params: { rp_world: new_attributes } + rp_world.reload + expect(response).to redirect_to(rp_world_url(rp_world)) + end + end + + context "with invalid parameters" do + it "renders a successful response (i.e. to display the 'edit' template)" do + rp_world = RpWorld.create! valid_attributes + patch rp_world_url(rp_world), params: { rp_world: invalid_attributes } + expect(response).to be_successful + end + end + end + + describe "DELETE /destroy" do + it "destroys the requested rp_world" do + rp_world = RpWorld.create! valid_attributes + expect { + delete rp_world_url(rp_world) + }.to change(RpWorld, :count).by(-1) + end + + it "redirects to the rp_worlds list" do + rp_world = RpWorld.create! valid_attributes + delete rp_world_url(rp_world) + expect(response).to redirect_to(rp_worlds_url) + end end end diff --git a/spec/routing/rp_worlds_routing_spec.rb b/spec/routing/rp_worlds_routing_spec.rb new file mode 100644 index 0000000..14cbfa2 --- /dev/null +++ b/spec/routing/rp_worlds_routing_spec.rb @@ -0,0 +1,38 @@ +require "rails_helper" + +RSpec.describe RpWorldsController, type: :routing do + describe "routing" do + it "routes to #index" do + expect(get: "/rp_worlds").to route_to("rp_worlds#index") + end + + it "routes to #new" do + expect(get: "/rp_worlds/new").to route_to("rp_worlds#new") + end + + it "routes to #show" do + expect(get: "/rp_worlds/1").to route_to("rp_worlds#show", id: "1") + end + + it "routes to #edit" do + expect(get: "/rp_worlds/1/edit").to route_to("rp_worlds#edit", id: "1") + end + + + it "routes to #create" do + expect(post: "/rp_worlds").to route_to("rp_worlds#create") + end + + it "routes to #update via PUT" do + expect(put: "/rp_worlds/1").to route_to("rp_worlds#update", id: "1") + end + + it "routes to #update via PATCH" do + expect(patch: "/rp_worlds/1").to route_to("rp_worlds#update", id: "1") + end + + it "routes to #destroy" do + expect(delete: "/rp_worlds/1").to route_to("rp_worlds#destroy", id: "1") + end + end +end diff --git a/spec/views/rp_worlds/edit.html.erb_spec.rb b/spec/views/rp_worlds/edit.html.erb_spec.rb new file mode 100644 index 0000000..093b521 --- /dev/null +++ b/spec/views/rp_worlds/edit.html.erb_spec.rb @@ -0,0 +1,18 @@ +require 'rails_helper' + +RSpec.describe "rp_worlds/edit", type: :view do + before(:each) do + @rp_world = assign(:rp_world, RpWorld.create!( + name: "MyString" + )) + end + + it "renders the edit rp_world form" do + render + + assert_select "form[action=?][method=?]", rp_world_path(@rp_world), "post" do + + assert_select "input[name=?]", "rp_world[name]" + end + end +end diff --git a/spec/views/rp_worlds/index.html.erb_spec.rb b/spec/views/rp_worlds/index.html.erb_spec.rb new file mode 100644 index 0000000..b821093 --- /dev/null +++ b/spec/views/rp_worlds/index.html.erb_spec.rb @@ -0,0 +1,19 @@ +require 'rails_helper' + +RSpec.describe "rp_worlds/index", type: :view do + before(:each) do + assign(:rp_worlds, [ + RpWorld.create!( + name: "Name" + ), + RpWorld.create!( + name: "Name" + ) + ]) + end + + it "renders a list of rp_worlds" do + render + assert_select "tr>td", text: "Name".to_s, count: 2 + end +end diff --git a/spec/views/rp_worlds/new.html.erb_spec.rb b/spec/views/rp_worlds/new.html.erb_spec.rb new file mode 100644 index 0000000..27d3364 --- /dev/null +++ b/spec/views/rp_worlds/new.html.erb_spec.rb @@ -0,0 +1,18 @@ +require 'rails_helper' + +RSpec.describe "rp_worlds/new", type: :view do + before(:each) do + assign(:rp_world, RpWorld.new( + name: "MyString" + )) + end + + it "renders new rp_world form" do + render + + assert_select "form[action=?][method=?]", rp_worlds_path, "post" do + + assert_select "input[name=?]", "rp_world[name]" + end + end +end diff --git a/spec/views/rp_worlds/show.html.erb_spec.rb b/spec/views/rp_worlds/show.html.erb_spec.rb new file mode 100644 index 0000000..0f4c9dd --- /dev/null +++ b/spec/views/rp_worlds/show.html.erb_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe "rp_worlds/show", type: :view do + before(:each) do + @rp_world = assign(:rp_world, RpWorld.create!( + name: "Name" + )) + end + + it "renders attributes in

" do + render + expect(rendered).to match(/Name/) + end +end diff --git a/yarn.lock b/yarn.lock index 6f06790..11809a2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -852,6 +852,19 @@ resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-free/-/fontawesome-free-5.15.3.tgz#c36ffa64a2a239bf948541a97b6ae8d729e09a9a" integrity sha512-rFnSUN/QOtnOAgqFRooTA3H57JLDm0QEG/jPdk+tLQNL/eWd+Aok8g3qCI+Q1xuDPWpGW/i9JySpJVsq8Q0s9w== +"@hotwired/turbo-rails@^7.0.0-beta.5": + version "7.0.0-beta.5" + resolved "https://registry.yarnpkg.com/@hotwired/turbo-rails/-/turbo-rails-7.0.0-beta.5.tgz#a0efdb7a20613845c43afe6f376b353e62f7e68d" + integrity sha512-zj+ZYbs2IHeJHtLavcLX5K0oW/3K8s3zjok4lpujxqLactp3OpuqBZxKBr+tgODnAX/WYFoKLpzivyx3xVRfTw== + dependencies: + "@hotwired/turbo" "^7.0.0-beta.4" + "@rails/actioncable" "^6.1.0" + +"@hotwired/turbo@^7.0.0-beta.4": + version "7.0.0-beta.5" + resolved "https://registry.yarnpkg.com/@hotwired/turbo/-/turbo-7.0.0-beta.5.tgz#3167e8e882b9075c5b3b2e2f32432cca2862c61c" + integrity sha512-z10dI2U/StkMSmnfJUsyez6jrhnitgzjyw2CxE3LnAAzW/TBhvsMYKsVG7Xu337r3gh0r6UwIFWyvvtm3in6gg== + "@npmcli/move-file@^1.0.1": version "1.1.2" resolved "https://registry.yarnpkg.com/@npmcli/move-file/-/move-file-1.1.2.tgz#1a82c3e372f7cae9253eb66d72543d6b8685c674" @@ -865,7 +878,7 @@ resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.9.2.tgz#adea7b6953cbb34651766b0548468e743c6a2353" integrity sha512-VZMYa7+fXHdwIq1TDhSXoVmSPEGM/aa+6Aiq3nVVJ9bXr24zScr+NlKFKC3iPljA7ho/GAZr+d2jOf5GIRC30Q== -"@rails/actioncable@^6.0.0": +"@rails/actioncable@^6.0.0", "@rails/actioncable@^6.1.0": version "6.1.3" resolved "https://registry.yarnpkg.com/@rails/actioncable/-/actioncable-6.1.3.tgz#c8a67ec4d22ecd6931f7ebd98143fddbc815419a" integrity sha512-m02524MR9cTnUNfGz39Lkx9jVvuL0tle4O7YgvouJ7H83FILxzG1nQ5jw8pAjLAr9XQGu+P1sY4SKE3zyhCNjw== @@ -7167,11 +7180,6 @@ tunnel-agent@^0.6.0: dependencies: safe-buffer "^5.0.1" -turbolinks@^5.2.0: - version "5.2.0" - resolved "https://registry.yarnpkg.com/turbolinks/-/turbolinks-5.2.0.tgz#e6877a55ea5c1cb3bb225f0a4ae303d6d32ff77c" - integrity sha512-pMiez3tyBo6uRHFNNZoYMmrES/IaGgMhQQM+VFF36keryjb5ms0XkVpmKHkfW/4Vy96qiGW3K9bz0tF5sK9bBw== - tweetnacl@^0.14.3, tweetnacl@~0.14.0: version "0.14.5" resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64"