Skip to content

Commit

Permalink
Upgrade rails 5 1 (lobsters#367)
Browse files Browse the repository at this point in the history
* Upgrade to rails 5.1

- Update versions of dependencies
- Switch before_filter to before_action
- Use render plain rather than render text

* Generate new rails 5.1 scripts
  • Loading branch information
HParker authored and mtnygard committed Jan 30, 2018
1 parent 4f60094 commit d630328
Show file tree
Hide file tree
Showing 26 changed files with 281 additions and 70 deletions.
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source "https://rubygems.org"

gem "rails", "4.2.8"
gem "rails", "~> 5.1"

platforms :ruby do
gem "unicorn"
Expand All @@ -12,7 +12,7 @@ gem "mysql2", ">= 0.3.14"
# gem "pg"

gem "uglifier", ">= 1.3.0"
gem "jquery-rails", "~> 3.1.3"
gem "jquery-rails", "~> 4.3"
gem "dynamic_form"

gem "exception_notification"
Expand All @@ -37,7 +37,7 @@ gem "mail"
gem "tzinfo-data"

group :test, :development do
gem "rspec-rails", "~> 3.5", ">= 3.5.2"
gem "rspec-rails", "~> 3.6"
gem "machinist"
gem "sqlite3"
gem "faker"
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :authenticate_user
before_filter :increase_traffic_counter
before_action :authenticate_user
before_action :increase_traffic_counter

TRAFFIC_DECREMENTER = 0.40

Expand Down Expand Up @@ -92,7 +92,7 @@ def require_logged_in_user_or_400
if @user
true
else
render :text => "not logged in", :status => 400
render :plain => "not logged in", :status => 400
return false
end
end
Expand Down
40 changes: 20 additions & 20 deletions app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ class CommentsController < ApplicationController
COMMENTS_PER_PAGE = 20

# for rss feeds, load the user's tag filters if a token is passed
before_filter :find_user_from_rss_token, :only => [ :index ]
before_filter :require_logged_in_user_or_400,
before_action :find_user_from_rss_token, :only => [ :index ]
before_action :require_logged_in_user_or_400,
:only => [ :create, :preview, :upvote, :downvote, :unvote ]

# for rss feeds, load the user's tag filters if a token is passed
before_filter :find_user_from_rss_token, :only => [ :index ]
before_action :find_user_from_rss_token, :only => [ :index ]

def create
if !(story = Story.where(:short_id => params[:story_id]).first) ||
story.is_gone?
return render :text => "can't find story", :status => 400
return render :plain => "can't find story", :status => 400
end

comment = story.comments.build
Expand Down Expand Up @@ -61,7 +61,7 @@ def create

def show
if !((comment = find_comment) && comment.is_editable_by_user?(@user))
return render :text => "can't find comment", :status => 400
return render :plain => "can't find comment", :status => 400
end

render :partial => "comment", :layout => false,
Expand All @@ -70,7 +70,7 @@ def show

def show_short_id
if !(comment = find_comment)
return render :text => "can't find comment", :status => 400
return render :plain => "can't find comment", :status => 400
end

render :json => comment.as_json
Expand All @@ -80,13 +80,13 @@ def redirect_from_short_id
if comment = find_comment
return redirect_to comment.url
else
return render :text => "can't find comment", :status => 400
return render :plain => "can't find comment", :status => 400
end
end

def edit
if !((comment = find_comment) && comment.is_editable_by_user?(@user))
return render :text => "can't find comment", :status => 400
return render :plain => "can't find comment", :status => 400
end

render :partial => "commentbox", :layout => false,
Expand All @@ -95,7 +95,7 @@ def edit

def reply
if !(parent_comment = find_comment)
return render :text => "can't find comment", :status => 400
return render :plain => "can't find comment", :status => 400
end

comment = Comment.new
Expand All @@ -108,7 +108,7 @@ def reply

def delete
if !((comment = find_comment) && comment.is_deletable_by_user?(@user))
return render :text => "can't find comment", :status => 400
return render :plain => "can't find comment", :status => 400
end

comment.delete_for_user(@user, params[:reason])
Expand All @@ -119,7 +119,7 @@ def delete

def undelete
if !((comment = find_comment) && comment.is_undeletable_by_user?(@user))
return render :text => "can't find comment", :status => 400
return render :plain => "can't find comment", :status => 400
end

comment.undelete_for_user(@user)
Expand All @@ -130,7 +130,7 @@ def undelete

def update
if !((comment = find_comment) && comment.is_editable_by_user?(@user))
return render :text => "can't find comment", :status => 400
return render :plain => "can't find comment", :status => 400
end

comment.comment = params[:comment]
Expand All @@ -155,43 +155,43 @@ def update

def unvote
if !(comment = find_comment)
return render :text => "can't find comment", :status => 400
return render :plain => "can't find comment", :status => 400
end

Vote.vote_thusly_on_story_or_comment_for_user_because(0, comment.story_id,
comment.id, @user.id, nil)

render :text => "ok"
render :plain => "ok"
end

def upvote
if !(comment = find_comment)
return render :text => "can't find comment", :status => 400
return render :plain => "can't find comment", :status => 400
end

Vote.vote_thusly_on_story_or_comment_for_user_because(1, comment.story_id,
comment.id, @user.id, params[:reason])

render :text => "ok"
render :plain => "ok"
end

def downvote
if !(comment = find_comment)
return render :text => "can't find comment", :status => 400
return render :plain => "can't find comment", :status => 400
end

if !Vote::COMMENT_REASONS[params[:reason]]
return render :text => "invalid reason", :status => 400
return render :plain => "invalid reason", :status => 400
end

if !@user.can_downvote?(comment)
return render :text => "not permitted to downvote", :status => 400
return render :plain => "not permitted to downvote", :status => 400
end

Vote.vote_thusly_on_story_or_comment_for_user_because(-1, comment.story_id,
comment.id, @user.id, params[:reason])

render :text => "ok"
render :plain => "ok"
end

def index
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/filters_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class FiltersController < ApplicationController
before_filter :authenticate_user
before_action :authenticate_user

def index
@cur_url = "/filters"
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/hats_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class HatsController < ApplicationController
before_filter :require_logged_in_user, :except => [ :index ]
before_filter :require_logged_in_moderator,
before_action :require_logged_in_user, :except => [ :index ]
before_action :require_logged_in_moderator,
:except => [ :build_request, :index, :create_request ]

def build_request
Expand Down
16 changes: 8 additions & 8 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
class HomeController < ApplicationController
# for rss feeds, load the user's tag filters if a token is passed
before_filter :find_user_from_rss_token, :only => [ :index, :newest ]
before_filter { @page = page }
before_filter :require_logged_in_user, :only => [ :upvoted ]
before_action :find_user_from_rss_token, :only => [ :index, :newest ]
before_action { @page = page }
before_action :require_logged_in_user, :only => [ :upvoted ]

def four_oh_four
begin
@title = "Resource Not Found"
render :action => "404", :status => 404
rescue ActionView::MissingTemplate
render :text => "<div class=\"box wide\">" <<
render :plain => "<div class=\"box wide\">" <<
"<div class=\"legend\">404</div>" <<
"Resource not found" <<
"</div>", :layout => "application"
Expand All @@ -21,7 +21,7 @@ def about
@title = "About"
render :action => "about"
rescue ActionView::MissingTemplate
render :text => "<div class=\"box wide\">" <<
render :plain => "<div class=\"box wide\">" <<
"A mystery." <<
"</div>", :layout => "application"
end
Expand All @@ -32,7 +32,7 @@ def chat
@title = "Chat"
render :action => "chat"
rescue ActionView::MissingTemplate
render :text => "<div class=\"box wide\">" <<
render :plain => "<div class=\"box wide\">" <<
"<div class=\"legend\">Chat</div>" <<
"Keep it on-site" <<
"</div>", :layout => "application"
Expand All @@ -44,7 +44,7 @@ def privacy
@title = "Privacy"
render :action => "privacy"
rescue ActionView::MissingTemplate
render :text => "<div class=\"box wide\">" <<
render :plain => "<div class=\"box wide\">" <<
"You apparently have no privacy." <<
"</div>", :layout => "application"
end
Expand Down Expand Up @@ -84,7 +84,7 @@ def index
content = Rails.cache.fetch("rss", :expires_in => (60 * 2)) {
render_to_string :action => "rss", :layout => false
}
render :text => content, :layout => false
render :plain => content, :layout => false
end
}
format.json { render :json => @stories }
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/invitations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class InvitationsController < ApplicationController
before_filter :require_logged_in_user,
before_action :require_logged_in_user,
:except => [ :build, :create_by_request, :confirm_email ]

def build
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/login_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class LoginTOTPFailedError < StandardError; end
class LoginFailedError < StandardError; end

class LoginController < ApplicationController
before_filter :authenticate_user
before_action :authenticate_user

def logout
if @user
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/messages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class MessagesController < ApplicationController
before_filter :require_logged_in_user
before_filter :find_message, :only => [ :show, :destroy, :keep_as_new ]
before_action :require_logged_in_user
before_action :find_message, :only => [ :show, :destroy, :keep_as_new ]

def index
@cur_url = "/messages"
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/settings_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class SettingsController < ApplicationController
before_filter :require_logged_in_user
before_action :require_logged_in_user

TOTP_SESSION_TIMEOUT = (60 * 15)

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/signup_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class SignupController < ApplicationController
before_filter :require_logged_in_user, :only => :invite
before_action :require_logged_in_user, :only => :invite

def index
if @user
Expand Down
34 changes: 17 additions & 17 deletions app/controllers/stories_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class StoriesController < ApplicationController
before_filter :require_logged_in_user_or_400,
before_action :require_logged_in_user_or_400,
:only => [ :upvote, :downvote, :unvote, :hide, :unhide, :preview ]
before_filter :require_logged_in_user, :only => [ :destroy, :create, :edit,
before_action :require_logged_in_user, :only => [ :destroy, :create, :edit,
:fetch_url_attributes, :new, :suggest ]
before_filter :verify_user_can_submit_stories, :only => [ :new, :create ]
before_filter :find_user_story, :only => [ :destroy, :edit, :undelete,
before_action :verify_user_can_submit_stories, :only => [ :new, :create ]
before_action :find_user_story, :only => [ :destroy, :edit, :undelete,
:update ]
before_filter :find_story!, :only => [ :suggest, :submit_suggestions ]
before_action :find_story!, :only => [ :suggest, :submit_suggestions ]

def create
@title = "Submit Story"
Expand Down Expand Up @@ -249,63 +249,63 @@ def update

def unvote
if !(story = find_story)
return render :text => "can't find story", :status => 400
return render :plain => "can't find story", :status => 400
end

Vote.vote_thusly_on_story_or_comment_for_user_because(0, story.id,
nil, @user.id, nil)

render :text => "ok"
render :plain => "ok"
end

def upvote
if !(story = find_story)
return render :text => "can't find story", :status => 400
return render :plain => "can't find story", :status => 400
end

Vote.vote_thusly_on_story_or_comment_for_user_because(1, story.id,
nil, @user.id, nil)

render :text => "ok"
render :plain => "ok"
end

def downvote
if !(story = find_story)
return render :text => "can't find story", :status => 400
return render :plain => "can't find story", :status => 400
end

if !Vote::STORY_REASONS[params[:reason]]
return render :text => "invalid reason", :status => 400
return render :plain => "invalid reason", :status => 400
end

if !@user.can_downvote?(story)
return render :text => "not permitted to downvote", :status => 400
return render :plain => "not permitted to downvote", :status => 400
end

Vote.vote_thusly_on_story_or_comment_for_user_because(-1, story.id,
nil, @user.id, params[:reason])

render :text => "ok"
render :plain => "ok"
end

def hide
if !(story = find_story)
return render :text => "can't find story", :status => 400
return render :plain => "can't find story", :status => 400
end

HiddenStory.hide_story_for_user(story.id, @user.id)

render :text => "ok"
render :plain => "ok"
end

def unhide
if !(story = find_story)
return render :text => "can't find story", :status => 400
return render :plain => "can't find story", :status => 400
end

HiddenStory.where(:user_id => @user.id, :story_id => story.id).delete_all

render :text => "ok"
render :plain => "ok"
end

private
Expand Down
Loading

0 comments on commit d630328

Please sign in to comment.