Skip to content

Commit 4220987

Browse files
authored
Merge pull request #51 from calebl/upgrade-to-rails-72
upgrade to rails 72
2 parents 3a72710 + adceca0 commit 4220987

32 files changed

Lines changed: 623 additions & 452 deletions

Gemfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
44
ruby '3.3.8'
55

66
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
7-
gem 'rails', '~> 7.1.0'
7+
gem 'rails', '~> 7.2.0'
88
# Use Puma as the app server
99
gem 'puma', '~> 6.4'
1010
# Use SCSS for stylesheets
@@ -23,9 +23,6 @@ gem 'redis', '~> 5.0'
2323
gem 'stimulus-rails', '~> 1.3'
2424
gem 'turbo-rails', '~> 1.5'
2525

26-
gem 'delayed_job', '~> 4.1'
27-
gem 'delayed_job_active_record', '~> 4.1'
28-
2926
# Use Active Storage variant
3027
# gem 'image_processing', '~> 1.2'
3128

Gemfile.lock

Lines changed: 62 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,77 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
actioncable (7.1.5.1)
5-
actionpack (= 7.1.5.1)
6-
activesupport (= 7.1.5.1)
4+
actioncable (7.2.2.1)
5+
actionpack (= 7.2.2.1)
6+
activesupport (= 7.2.2.1)
77
nio4r (~> 2.0)
88
websocket-driver (>= 0.6.1)
99
zeitwerk (~> 2.6)
10-
actionmailbox (7.1.5.1)
11-
actionpack (= 7.1.5.1)
12-
activejob (= 7.1.5.1)
13-
activerecord (= 7.1.5.1)
14-
activestorage (= 7.1.5.1)
15-
activesupport (= 7.1.5.1)
16-
mail (>= 2.7.1)
17-
net-imap
18-
net-pop
19-
net-smtp
20-
actionmailer (7.1.5.1)
21-
actionpack (= 7.1.5.1)
22-
actionview (= 7.1.5.1)
23-
activejob (= 7.1.5.1)
24-
activesupport (= 7.1.5.1)
25-
mail (~> 2.5, >= 2.5.4)
26-
net-imap
27-
net-pop
28-
net-smtp
10+
actionmailbox (7.2.2.1)
11+
actionpack (= 7.2.2.1)
12+
activejob (= 7.2.2.1)
13+
activerecord (= 7.2.2.1)
14+
activestorage (= 7.2.2.1)
15+
activesupport (= 7.2.2.1)
16+
mail (>= 2.8.0)
17+
actionmailer (7.2.2.1)
18+
actionpack (= 7.2.2.1)
19+
actionview (= 7.2.2.1)
20+
activejob (= 7.2.2.1)
21+
activesupport (= 7.2.2.1)
22+
mail (>= 2.8.0)
2923
rails-dom-testing (~> 2.2)
30-
actionpack (7.1.5.1)
31-
actionview (= 7.1.5.1)
32-
activesupport (= 7.1.5.1)
24+
actionpack (7.2.2.1)
25+
actionview (= 7.2.2.1)
26+
activesupport (= 7.2.2.1)
3327
nokogiri (>= 1.8.5)
3428
racc
35-
rack (>= 2.2.4)
29+
rack (>= 2.2.4, < 3.2)
3630
rack-session (>= 1.0.1)
3731
rack-test (>= 0.6.3)
3832
rails-dom-testing (~> 2.2)
3933
rails-html-sanitizer (~> 1.6)
40-
actiontext (7.1.5.1)
41-
actionpack (= 7.1.5.1)
42-
activerecord (= 7.1.5.1)
43-
activestorage (= 7.1.5.1)
44-
activesupport (= 7.1.5.1)
34+
useragent (~> 0.16)
35+
actiontext (7.2.2.1)
36+
actionpack (= 7.2.2.1)
37+
activerecord (= 7.2.2.1)
38+
activestorage (= 7.2.2.1)
39+
activesupport (= 7.2.2.1)
4540
globalid (>= 0.6.0)
4641
nokogiri (>= 1.8.5)
47-
actionview (7.1.5.1)
48-
activesupport (= 7.1.5.1)
42+
actionview (7.2.2.1)
43+
activesupport (= 7.2.2.1)
4944
builder (~> 3.1)
5045
erubi (~> 1.11)
5146
rails-dom-testing (~> 2.2)
5247
rails-html-sanitizer (~> 1.6)
53-
activejob (7.1.5.1)
54-
activesupport (= 7.1.5.1)
48+
activejob (7.2.2.1)
49+
activesupport (= 7.2.2.1)
5550
globalid (>= 0.3.6)
56-
activemodel (7.1.5.1)
57-
activesupport (= 7.1.5.1)
58-
activerecord (7.1.5.1)
59-
activemodel (= 7.1.5.1)
60-
activesupport (= 7.1.5.1)
51+
activemodel (7.2.2.1)
52+
activesupport (= 7.2.2.1)
53+
activerecord (7.2.2.1)
54+
activemodel (= 7.2.2.1)
55+
activesupport (= 7.2.2.1)
6156
timeout (>= 0.4.0)
62-
activestorage (7.1.5.1)
63-
actionpack (= 7.1.5.1)
64-
activejob (= 7.1.5.1)
65-
activerecord (= 7.1.5.1)
66-
activesupport (= 7.1.5.1)
57+
activestorage (7.2.2.1)
58+
actionpack (= 7.2.2.1)
59+
activejob (= 7.2.2.1)
60+
activerecord (= 7.2.2.1)
61+
activesupport (= 7.2.2.1)
6762
marcel (~> 1.0)
68-
activesupport (7.1.5.1)
63+
activesupport (7.2.2.1)
6964
base64
7065
benchmark (>= 0.3)
7166
bigdecimal
72-
concurrent-ruby (~> 1.0, >= 1.0.2)
67+
concurrent-ruby (~> 1.0, >= 1.3.1)
7368
connection_pool (>= 2.2.5)
7469
drb
7570
i18n (>= 1.6, < 2)
7671
logger (>= 1.4.2)
7772
minitest (>= 5.1)
78-
mutex_m
7973
securerandom (>= 0.3)
80-
tzinfo (~> 2.0)
74+
tzinfo (~> 2.0, >= 2.0.5)
8175
acts_as_list (1.2.4)
8276
activerecord (>= 6.1)
8377
activesupport (>= 6.1)
@@ -117,11 +111,6 @@ GEM
117111
crass (1.0.6)
118112
csv (3.3.5)
119113
date (3.4.1)
120-
delayed_job (4.1.13)
121-
activesupport (>= 3.0, < 9.0)
122-
delayed_job_active_record (4.1.11)
123-
activerecord (>= 3.0, < 9.0)
124-
delayed_job (>= 3.0, < 5)
125114
devise (4.9.4)
126115
bcrypt (~> 3.0)
127116
orm_adapter (~> 0.1)
@@ -224,7 +213,6 @@ GEM
224213
minitest (5.25.5)
225214
msgpack (1.8.0)
226215
multi_json (1.15.0)
227-
mutex_m (0.3.0)
228216
nenv (0.3.0)
229217
net-http (0.6.0)
230218
uri
@@ -275,20 +263,20 @@ GEM
275263
rack (>= 1.3)
276264
rackup (2.2.1)
277265
rack (>= 3)
278-
rails (7.1.5.1)
279-
actioncable (= 7.1.5.1)
280-
actionmailbox (= 7.1.5.1)
281-
actionmailer (= 7.1.5.1)
282-
actionpack (= 7.1.5.1)
283-
actiontext (= 7.1.5.1)
284-
actionview (= 7.1.5.1)
285-
activejob (= 7.1.5.1)
286-
activemodel (= 7.1.5.1)
287-
activerecord (= 7.1.5.1)
288-
activestorage (= 7.1.5.1)
289-
activesupport (= 7.1.5.1)
266+
rails (7.2.2.1)
267+
actioncable (= 7.2.2.1)
268+
actionmailbox (= 7.2.2.1)
269+
actionmailer (= 7.2.2.1)
270+
actionpack (= 7.2.2.1)
271+
actiontext (= 7.2.2.1)
272+
actionview (= 7.2.2.1)
273+
activejob (= 7.2.2.1)
274+
activemodel (= 7.2.2.1)
275+
activerecord (= 7.2.2.1)
276+
activestorage (= 7.2.2.1)
277+
activesupport (= 7.2.2.1)
290278
bundler (>= 1.15.0)
291-
railties (= 7.1.5.1)
279+
railties (= 7.2.2.1)
292280
rails-controller-testing (1.0.5)
293281
actionpack (>= 5.0.1.rc1)
294282
actionview (>= 5.0.1.rc1)
@@ -300,10 +288,10 @@ GEM
300288
rails-html-sanitizer (1.6.2)
301289
loofah (~> 2.21)
302290
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
303-
railties (7.1.5.1)
304-
actionpack (= 7.1.5.1)
305-
activesupport (= 7.1.5.1)
306-
irb
291+
railties (7.2.2.1)
292+
actionpack (= 7.2.2.1)
293+
activesupport (= 7.2.2.1)
294+
irb (~> 1.13)
307295
rackup (>= 1.0.0)
308296
rake (>= 12.2)
309297
thor (~> 1.0, >= 1.2.2)
@@ -421,6 +409,7 @@ GEM
421409
unicode-emoji (~> 4.0, >= 4.0.4)
422410
unicode-emoji (4.0.4)
423411
uri (1.0.3)
412+
useragent (0.16.11)
424413
warden (1.2.9)
425414
rack (>= 2.0.9)
426415
web-console (4.2.1)
@@ -452,8 +441,6 @@ DEPENDENCIES
452441
byebug
453442
cancancan (~> 3.2)
454443
capybara (~> 3.39)
455-
delayed_job (~> 4.1)
456-
delayed_job_active_record (~> 4.1)
457444
devise (~> 4.9)
458445
foreman
459446
guard
@@ -470,7 +457,7 @@ DEPENDENCIES
470457
net-smtp
471458
pg (~> 1.5)
472459
puma (~> 6.4)
473-
rails (~> 7.1.0)
460+
rails (~> 7.2.0)
474461
rails-controller-testing
475462
redis (~> 5.0)
476463
rubocop

app/controllers/writing_sessions_controller.rb

Lines changed: 29 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,74 @@
11
class WritingSessionsController < ApplicationController
2-
protect_from_forgery with: :exception, if: Proc.new { |c| c.request.format != 'application/json' }
3-
protect_from_forgery with: :null_session, if: Proc.new { |c| c.request.format == 'application/json' }
4-
before_action :story
5-
before_action :writing_session, only: [:show, :edit, :update, :destroy, :header_actions]
6-
after_action :touch_story, only: [:create, :update, :destroy]
7-
layout "home", only: [:new, :edit]
2+
protect_from_forgery with: :exception, if: proc { |c| c.request.format != 'application/json' }
3+
protect_from_forgery with: :null_session, if: proc { |c| c.request.format == 'application/json' }
4+
after_action :touch_story, only: %i[create update destroy]
5+
layout 'home', only: %i[new edit]
86

9-
def index
10-
unless can? :read, @story
11-
redirect_to_home
12-
end
7+
load_and_authorize_resource :story
8+
load_and_authorize_resource :writing_session, through: :story, shallow: true
139

10+
def index
1411
@writing_sessions = @story.writing_sessions.order(updated_at: :desc)
1512
end
1613

1714
# GET /writing_sessions/1
1815
# GET /writing_sessions/1.json
19-
def show
20-
unless can? :read, @session
21-
redirect_to_home
22-
end
23-
end
16+
def show; end
2417

2518
# GET /writing_sessions/new
2619
def new
2720
@title = 'Compose'
28-
@session = @story.writing_sessions.create(user_id: current_user.id, text: "")
21+
@writing_session = @story.writing_sessions.create(user_id: current_user.id, text: '')
2922

30-
redirect_to edit_story_writing_session_path(@story, @session.id)
23+
redirect_to edit_story_writing_session_path(@story, @writing_session.id)
3124
end
3225

3326
# GET /writing_sessions/1/edit
34-
def edit
35-
unless can? :update, @session
36-
redirect_to_home
37-
end
38-
end
27+
def edit; end
3928

4029
# POST /writing_sessions
4130
# POST /writing_sessions.json
4231
def create
43-
unless can? :create, WritingSession
44-
redirect_to_home
45-
end
46-
47-
params = session_params
48-
params[:text] = "<div>#{params[:text]}</div>"
32+
text = "<div>#{writing_session_params[:text]}</div>"
4933

50-
@session = @story.writing_sessions.new params
51-
@session.user_id = current_user.id
52-
@session.word_count = @session.calculate_word_count
34+
@writing_session = @story.writing_sessions.new(writing_session_params.merge(text:, user_id: current_user.id))
35+
@writing_session.word_count = @writing_session.calculate_word_count
5336

5437
respond_to do |format|
55-
if @session.save
56-
format.html { redirect_to edit_story_writing_session_path(@story, @session.id), notice: 'Session was successfully created.', status: :see_other }
57-
format.json { render json: @session, status: :ok }
38+
if @writing_session.save
39+
format.html do
40+
redirect_to edit_story_writing_session_path(@story, @writing_session.id), notice: 'Session was successfully created.',
41+
status: :see_other
42+
end
43+
format.json { render json: @writing_session, status: :ok }
5844
else
5945
format.html { render :new }
60-
format.json { render json: @session.errors, status: :unprocessable_entity }
46+
format.json { render json: @writing_session.errors, status: :unprocessable_entity }
6147
end
6248
end
6349
end
6450

6551
# PATCH/PUT /writing_sessions/1
6652
# PATCH/PUT /writing_sessions/1.json
6753
def update
68-
unless can? :update, @session
69-
redirect_to_home
70-
end
71-
72-
@session.text += "<div>#{session_params[:text]}</div>"
73-
@session.word_count = @session.calculate_word_count
54+
@writing_session.text += "<div>#{writing_session_params[:text]}</div>"
55+
@writing_session.word_count = @writing_session.calculate_word_count
7456

7557
respond_to do |format|
76-
if @session.save
77-
format.html { redirect_to edit_story_writing_session_path(@story, @session.id), status: :see_other }
78-
format.json { render json: @session, status: :ok }
58+
if @writing_session.save
59+
format.html { redirect_to edit_story_writing_session_path(@story, @writing_session.id), status: :see_other }
60+
format.json { render json: @writing_session, status: :ok }
7961
else
8062
format.html { render :edit }
81-
format.json { render json: @session.errors, status: :unprocessable_entity }
63+
format.json { render json: @writing_session.errors, status: :unprocessable_entity }
8264
end
8365
end
8466
end
8567

8668
# DELETE /writing_sessions/1
8769
# DELETE /writing_sessions/1.json
8870
def destroy
89-
unless can? :destroy, @session
90-
redirect_to_home
91-
end
92-
93-
@session.destroy
71+
@writing_session.destroy
9472
respond_to do |format|
9573
format.html { redirect_to story_path(@story), notice: 'Session was successfully destroyed.', status: :see_other }
9674
format.json { head :no_content }
@@ -99,19 +77,8 @@ def destroy
9977

10078
private
10179

102-
# Use callbacks to share common setup or constraints between actions.
103-
def writing_session
104-
@session = @story.writing_sessions.find(params[:id])
105-
end
106-
107-
def story
108-
@story = current_user.stories.find(params[:story_id])
109-
rescue ActiveRecord::RecordNotFound
110-
redirect_to_home
111-
end
112-
11380
# Only allow a list of trusted parameters through.
114-
def session_params
81+
def writing_session_params
11582
params.require(:writing_session).permit(:text)
11683
end
11784

app/models/ability.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ def initialize(user)
88
#
99
return unless user.present?
1010

11-
if user.admin_role?
12-
can :manage, :all
13-
can :access, :blazer
14-
end
11+
can :access, :blazer if user.admin_role?
1512

1613
can :manage, WritingSession, user_id: user.id
1714
can :manage, Story, user_id: user.id

0 commit comments

Comments
 (0)