migrate from turbolinks to turbo

This commit is contained in:
2021-06-21 20:54:17 +02:00
parent 62464846a3
commit 87c1c67b5c
19 changed files with 367 additions and 40 deletions

View File

@@ -18,8 +18,8 @@ gem 'puma', '~> 5.0'
gem 'sass-rails', '>= 6' gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker # Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 5.0' gem 'webpacker', '~> 5.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks # The speed of a single-page web application without having to write any JavaScript.
gem 'turbolinks', '~> 5' gem 'turbo-rails'
# Use Redis adapter to run Action Cable in production # Use Redis adapter to run Action Cable in production
gem 'redis', '~> 4.2.5' gem 'redis', '~> 4.2.5'
# Use Active Model has_secure_password # Use Active Model has_secure_password
@@ -71,7 +71,7 @@ group :development do
gem 'web-console', '>= 4.1.0' gem 'web-console', '>= 4.1.0'
# Display performance information such as SQL time and flame graphs for each request in your browser. # 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 # 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 # The Listen gem listens to file modifications and notifies you about the changes. Works everywhere
gem 'listen', '~> 3.3' gem 'listen', '~> 3.3'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring

View File

@@ -6,6 +6,14 @@ GIT
require_all require_all
typhoeus (~> 1.1) 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 GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
@@ -72,7 +80,7 @@ GEM
public_suffix (>= 2.0.2, < 5.0) public_suffix (>= 2.0.2, < 5.0)
ast (2.4.2) ast (2.4.2)
awesome_print (1.9.2) awesome_print (1.9.2)
backport (1.1.2) backport (1.2.0)
bcrypt (3.1.16) bcrypt (3.1.16)
benchmark (0.1.1) benchmark (0.1.1)
bindex (0.8.1) bindex (0.8.1)
@@ -163,7 +171,7 @@ GEM
multi_xml (0.6.0) multi_xml (0.6.0)
multipart-post (2.1.1) multipart-post (2.1.1)
nio4r (2.5.7) nio4r (2.5.7)
nokogiri (1.11.6-x86_64-linux) nokogiri (1.11.7-x86_64-linux)
racc (~> 1.4) racc (~> 1.4)
oauth2 (1.4.7) oauth2 (1.4.7)
faraday (>= 0.8, < 2.0) faraday (>= 0.8, < 2.0)
@@ -199,8 +207,6 @@ GEM
nio4r (~> 2.0) nio4r (~> 2.0)
racc (1.5.2) racc (1.5.2)
rack (2.2.3) rack (2.2.3)
rack-mini-profiler (2.3.1)
rack (>= 1.2.0)
rack-proxy (0.6.5) rack-proxy (0.6.5)
rack rack
rack-test (1.1.0) rack-test (1.1.0)
@@ -272,7 +278,7 @@ GEM
rspec-mocks (~> 3.10) rspec-mocks (~> 3.10)
rspec-support (~> 3.10) rspec-support (~> 3.10)
rspec-support (3.10.2) rspec-support (3.10.2)
rubocop (1.16.0) rubocop (1.17.0)
parallel (~> 1.10) parallel (~> 1.10)
parser (>= 3.0.0.0) parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0) rainbow (>= 2.2.2, < 4.0)
@@ -329,10 +335,11 @@ GEM
simplecov_json_formatter (~> 0.1) simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3) simplecov-html (0.12.3)
simplecov_json_formatter (0.1.2) simplecov_json_formatter (0.1.2)
solargraph (0.41.1) solargraph (0.42.3)
backport (~> 1.1) backport (~> 1.2)
benchmark benchmark
bundler (>= 1.17.2) bundler (>= 1.17.2)
diff-lcs (~> 1.4)
e2mmap e2mmap
jaro_winkler (~> 1.5) jaro_winkler (~> 1.5)
kramdown (~> 2.3) kramdown (~> 2.3)
@@ -353,9 +360,8 @@ GEM
sprockets (>= 3.0.0) sprockets (>= 3.0.0)
thor (1.1.0) thor (1.1.0)
tilt (2.0.10) tilt (2.0.10)
turbolinks (5.2.1) turbo-rails (0.5.9)
turbolinks-source (~> 5.2) rails (>= 6.0.0)
turbolinks-source (5.2.0)
typhoeus (1.4.0) typhoeus (1.4.0)
ethon (>= 0.9.0) ethon (>= 0.9.0)
tzinfo (2.0.4) tzinfo (2.0.4)
@@ -407,7 +413,7 @@ DEPENDENCIES
pg (~> 1.1) pg (~> 1.1)
pry-rails (~> 0.3.9) pry-rails (~> 0.3.9)
puma (~> 5.0) puma (~> 5.0)
rack-mini-profiler (~> 2.0) rack-mini-profiler (~> 2.3.2)!
rails (~> 6.1.3, >= 6.1.3.1) rails (~> 6.1.3, >= 6.1.3.1)
rails-erd rails-erd
rails-i18n (~> 6.0.0) rails-i18n (~> 6.0.0)
@@ -425,7 +431,7 @@ DEPENDENCIES
simplecov simplecov
solargraph solargraph
spring spring
turbolinks (~> 5) turbo-rails
tzinfo-data tzinfo-data
web-console (>= 4.1.0) web-console (>= 4.1.0)
webdrivers webdrivers

View File

@@ -1,9 +1,52 @@
class RpWorldsController < ApplicationController class RpWorldsController < ApplicationController
before_action :set_rp_world, only: [:show, :edit, :update, :destroy]
# GET /rp_worlds
def index def index
@rp_worlds = RpWorld.all @rp_worlds = RpWorld.all
end 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]) @rp_world = RpWorld.includes(:wow_characters).find(params[:id])
end end
# Only allow a list of trusted parameters through.
def rp_world_params
params.require(:rp_world).permit(:name, :description)
end
end end

View File

@@ -4,7 +4,7 @@
// that code so it'll be compiled. // that code so it'll be compiled.
import Rails from "@rails/ujs" import Rails from "@rails/ujs"
import Turbolinks from "turbolinks" import "@hotwired/turbo-rails"
import * as ActiveStorage from "@rails/activestorage" import * as ActiveStorage from "@rails/activestorage"
import "channels" import "channels"
@@ -20,5 +20,4 @@ document.addEventListener("turbolinks:load", () => {
}) })
Rails.start() Rails.start()
Turbolinks.start()
ActiveStorage.start() ActiveStorage.start()

View File

@@ -0,0 +1,15 @@
<%= form_with(model: rp_world) do |form| %>
<div class="field">
<%= form.label :name %>
<%= form.text_field :name %>
</div>
<div class="field">
<%= form.label :description %>
<%= form.text_field :description %>
</div>
<div class="actions">
<%= form.submit %>
</div>
<% end %>

View File

@@ -0,0 +1,6 @@
<h1>Editing Rp World</h1>
<%= render 'form', rp_world: @rp_world %>
<%= link_to 'Show', @rp_world %> |
<%= link_to 'Back', rp_worlds_path %>

View File

@@ -1,18 +1,27 @@
<h2>Characters list</h2> <p id="notice"><%= notice %></p>
<table class="table table-hover table-dark table-image"> <h1>Rp Worlds</h1>
<table>
<thead> <thead>
<tr> <tr>
<th scope="col"><%= t('rp_worlds.world_list.name') %></th> <th><%= t('rp_worlds.world_list.name') %></th>
<th scope="col"><%= t('rp_worlds.world_list.description') %></th> <th colspan="3"></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<% @rp_worlds.each do |world| %> <% @rp_worlds.each do |rp_world| %>
<tr> <tr>
<td><%= link_to world.name, world %></td> <td><%= rp_world.name %></td>
<td><%= world.description %></td> <td><%= link_to 'Show', rp_world %></td>
<td><%= link_to 'Edit', edit_rp_world_path(rp_world) %></td>
<td><%= link_to 'Destroy', rp_world, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr> </tr>
<% end %> <% end %>
</tbody> </tbody>
</table> </table>
<br>
<%= link_to 'New Rp World', new_rp_world_path %>

View File

@@ -0,0 +1,5 @@
<h1>New Rp World</h1>
<%= render 'form', rp_world: @rp_world %>
<%= link_to 'Back', rp_worlds_path %>

View File

@@ -1,3 +1,5 @@
<p id="notice"><%= notice %></p>
<div class="row"> <div class="row">
<div class="col-5"> <div class="col-5">
<div class="card"> <div class="card">
@@ -15,3 +17,6 @@
<h1>Suite...</h1> <h1>Suite...</h1>
</div> </div>
</div> </div>
<%= link_to 'Edit', edit_rp_world_path(@rp_world) %> |
<%= link_to 'Back', rp_worlds_path %>

View File

@@ -1,5 +1,6 @@
development: development:
adapter: async adapter: redis
url: redis://localhost:6379/1
test: test:
adapter: test adapter: test

View File

@@ -14,6 +14,6 @@ Rails.application.routes.draw do
resources :wow_mounts, only: [:index, :show] resources :wow_mounts, only: [:index, :show]
resources :wow_pets, only: [:index, :show] resources :wow_pets, only: [:index, :show]
resources :wow_reputations, only: [:index, :show] resources :wow_reputations, only: [:index, :show]
resources :rp_worlds, only: [:index, :show] resources :rp_worlds
end end
end end

View File

@@ -3,6 +3,7 @@
"private": true, "private": true,
"dependencies": { "dependencies": {
"@fortawesome/fontawesome-free": "^5.15.3", "@fortawesome/fontawesome-free": "^5.15.3",
"@hotwired/turbo-rails": "^7.0.0-beta.5",
"@popperjs/core": "^2.9.2", "@popperjs/core": "^2.9.2",
"@rails/actioncable": "^6.0.0", "@rails/actioncable": "^6.0.0",
"@rails/activestorage": "^6.0.0", "@rails/activestorage": "^6.0.0",
@@ -10,8 +11,7 @@
"@rails/webpacker": "5.2.1", "@rails/webpacker": "5.2.1",
"bootstrap": "^5.0.0-beta3", "bootstrap": "^5.0.0-beta3",
"flag-icon-css": "^3.5.0", "flag-icon-css": "^3.5.0",
"jquery": "^3.6.0", "jquery": "^3.6.0"
"turbolinks": "^5.2.0"
}, },
"version": "0.1.0", "version": "0.1.0",
"devDependencies": { "devDependencies": {

View File

@@ -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 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
end end

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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 <p>" do
render
expect(rendered).to match(/Name/)
end
end

20
yarn.lock generated
View File

@@ -852,6 +852,19 @@
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-free/-/fontawesome-free-5.15.3.tgz#c36ffa64a2a239bf948541a97b6ae8d729e09a9a" 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== 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": "@npmcli/move-file@^1.0.1":
version "1.1.2" version "1.1.2"
resolved "https://registry.yarnpkg.com/@npmcli/move-file/-/move-file-1.1.2.tgz#1a82c3e372f7cae9253eb66d72543d6b8685c674" 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" resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.9.2.tgz#adea7b6953cbb34651766b0548468e743c6a2353"
integrity sha512-VZMYa7+fXHdwIq1TDhSXoVmSPEGM/aa+6Aiq3nVVJ9bXr24zScr+NlKFKC3iPljA7ho/GAZr+d2jOf5GIRC30Q== 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" version "6.1.3"
resolved "https://registry.yarnpkg.com/@rails/actioncable/-/actioncable-6.1.3.tgz#c8a67ec4d22ecd6931f7ebd98143fddbc815419a" resolved "https://registry.yarnpkg.com/@rails/actioncable/-/actioncable-6.1.3.tgz#c8a67ec4d22ecd6931f7ebd98143fddbc815419a"
integrity sha512-m02524MR9cTnUNfGz39Lkx9jVvuL0tle4O7YgvouJ7H83FILxzG1nQ5jw8pAjLAr9XQGu+P1sY4SKE3zyhCNjw== integrity sha512-m02524MR9cTnUNfGz39Lkx9jVvuL0tle4O7YgvouJ7H83FILxzG1nQ5jw8pAjLAr9XQGu+P1sY4SKE3zyhCNjw==
@@ -7167,11 +7180,6 @@ tunnel-agent@^0.6.0:
dependencies: dependencies:
safe-buffer "^5.0.1" 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: tweetnacl@^0.14.3, tweetnacl@~0.14.0:
version "0.14.5" version "0.14.5"
resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64" resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64"