Merge pull request #2139 from TracksApp/rails51

Upgrade to Rails 5.1
This commit is contained in:
Matt Rogers 2018-11-13 15:48:50 -06:00 committed by GitHub
commit 6754d8ffa9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 130 additions and 87 deletions

View file

@ -1,6 +1,6 @@
source 'https://rubygems.org'
gem 'rails', '~> 5.0.0'
gem 'rails', '~> 5.1.0'
gem 'sass-rails', '~> 5.0'
gem 'coffee-rails', '~> 4.2.0'
@ -61,6 +61,7 @@ end
group :development, :test do
gem 'byebug'
gem 'listen'
gem "rubocop", "~> 0.49", require: false
end

View file

@ -3,53 +3,53 @@ GEM
specs:
RedCloth (4.3.2)
aasm (3.4.0)
actioncable (5.0.7)
actionpack (= 5.0.7)
nio4r (>= 1.2, < 3.0)
actioncable (5.1.6)
actionpack (= 5.1.6)
nio4r (~> 2.0)
websocket-driver (~> 0.6.1)
actionmailer (5.0.7)
actionpack (= 5.0.7)
actionview (= 5.0.7)
activejob (= 5.0.7)
actionmailer (5.1.6)
actionpack (= 5.1.6)
actionview (= 5.1.6)
activejob (= 5.1.6)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (5.0.7)
actionview (= 5.0.7)
activesupport (= 5.0.7)
actionpack (5.1.6)
actionview (= 5.1.6)
activesupport (= 5.1.6)
rack (~> 2.0)
rack-test (~> 0.6.3)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionpack-xml_parser (2.0.1)
actionpack (>= 5.0)
railties (>= 5.0)
actionview (5.0.7)
activesupport (= 5.0.7)
actionview (5.1.6)
activesupport (= 5.1.6)
builder (~> 3.1)
erubis (~> 2.7.0)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.0.7)
activesupport (= 5.0.7)
activejob (5.1.6)
activesupport (= 5.1.6)
globalid (>= 0.3.6)
activemodel (5.0.7)
activesupport (= 5.0.7)
activemodel (5.1.6)
activesupport (= 5.1.6)
activemodel-serializers-xml (1.0.2)
activemodel (> 5.x)
activesupport (> 5.x)
builder (~> 3.1)
activerecord (5.0.7)
activemodel (= 5.0.7)
activesupport (= 5.0.7)
arel (~> 7.0)
activesupport (5.0.7)
activerecord (5.1.6)
activemodel (= 5.1.6)
activesupport (= 5.1.6)
arel (~> 8.0)
activesupport (5.1.6)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
acts_as_list (0.9.15)
activerecord (>= 3.0)
arel (7.1.4)
arel (8.0.0)
ast (2.4.0)
autoprefixer-rails (8.6.5)
execjs
@ -79,7 +79,7 @@ GEM
database_cleaner (1.7.0)
diff-lcs (1.3)
docile (1.3.1)
erubis (2.7.0)
erubi (1.7.1)
execjs (2.7.0)
factory_bot (4.10.0)
activesupport (>= 3.0.0)
@ -92,7 +92,7 @@ GEM
globalid (0.4.1)
activesupport (>= 4.2.0)
htmlentities (4.3.4)
i18n (1.1.0)
i18n (1.1.1)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.1)
jquery-rails (4.3.3)
@ -103,13 +103,17 @@ GEM
railties (>= 3.2.16)
json (2.1.0)
libv8 (3.16.14.19)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
loofah (2.2.3)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.0)
mail (2.7.1)
mini_mime (>= 0.1.1)
metaclass (0.0.4)
method_source (0.9.0)
method_source (0.9.1)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
@ -122,7 +126,7 @@ GEM
metaclass (~> 0.0.1)
mysql2 (0.3.21)
nio4r (2.3.1)
nokogiri (1.8.4)
nokogiri (1.8.5)
mini_portile2 (~> 2.3.0)
nokogumbo (1.5.0)
nokogiri
@ -142,19 +146,19 @@ GEM
rack (>= 1.1, < 2.1)
rack-mini-profiler (1.0.0)
rack (>= 1.2.0)
rack-test (0.6.3)
rack (>= 1.0)
rails (5.0.7)
actioncable (= 5.0.7)
actionmailer (= 5.0.7)
actionpack (= 5.0.7)
actionview (= 5.0.7)
activejob (= 5.0.7)
activemodel (= 5.0.7)
activerecord (= 5.0.7)
activesupport (= 5.0.7)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (5.1.6)
actioncable (= 5.1.6)
actionmailer (= 5.1.6)
actionpack (= 5.1.6)
actionview (= 5.1.6)
activejob (= 5.1.6)
activemodel (= 5.1.6)
activerecord (= 5.1.6)
activesupport (= 5.1.6)
bundler (>= 1.3.0)
railties (= 5.0.7)
railties (= 5.1.6)
sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.2)
actionpack (~> 5.x, >= 5.0.1)
@ -167,9 +171,9 @@ GEM
loofah (~> 2.2, >= 2.2.2)
rails_autolink (1.1.6)
rails (> 3.1)
railties (5.0.7)
actionpack (= 5.0.7)
activesupport (= 5.0.7)
railties (5.1.6)
actionpack (= 5.1.6)
activesupport (= 5.1.6)
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
@ -192,6 +196,7 @@ GEM
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.9.0)
ruby_dep (1.5.0)
rubyzip (1.2.2)
safe_yaml (1.0.4)
sanitize (4.6.6)
@ -276,6 +281,7 @@ DEPENDENCIES
htmlentities
jquery-rails (~> 4.0)
jquery-ui-rails (~> 5.0.5)
listen
minitest-stub-const
mocha
mysql2 (~> 0.3.17)
@ -283,7 +289,7 @@ DEPENDENCIES
puma (~> 3.0)
rack-dev-mark
rack-mini-profiler
rails (~> 5.0.0)
rails (~> 5.1.0)
rails-controller-testing
rails-dom-testing (~> 2.0.0)
rails_autolink

View file

@ -146,9 +146,11 @@ module Todos
end
def set_id_by_name(group_type, set, name)
group = set.where(:name => name).first_or_create
group = set.where(:name => name).first_or_initialize
group_is_new = group.new_record?
group.save if group_is_new
@attributes["#{group_type}_id"] = group.id
return group.new_record_before_save?
group_is_new
end
def set_id_by_id_string(group_type, set, id)

View file

@ -45,10 +45,6 @@ class Context < ApplicationRecord
name
end
def new_record_before_save?
@new_record_before_save
end
def no_active_todos?
return todos.active.count == 0
end

View file

@ -118,10 +118,6 @@ class Project < ApplicationRecord
end
end
def new_record_before_save?
@new_record_before_save
end
def age_in_days
@age_in_days ||= (Time.current.to_date - created_at.to_date).to_i + 1
end

View file

@ -1,6 +1,2 @@
<% @swf_count ||= 0 -%>
<div class="open-flash-chart"><%= swf_tag "open-flash-chart.swf",
:flashvars => { 'width' => chart.width, 'height' => chart.height, 'data' => url_for(:action => chart.action)},
:parameters => { 'allowScriptAccess' => 'sameDomain', 'wmode' => 'transparent'},
:div_id => "chart_#{@swf_count+=1}",
:size => chart.dimensions %></div>
<div class="open-flash-chart"></div>

View file

@ -18,6 +18,9 @@ chdir APP_ROOT do
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')
# Install JavaScript dependencies if using Yarn
# system('bin/yarn')
# puts "\n== Copying sample files =="
# unless File.exist?('config/database.yml')
# cp 'config/database.yml.sample', 'config/database.yml'

11
bin/yarn Executable file
View file

@ -0,0 +1,11 @@
#!/usr/bin/env ruby
VENDOR_PATH = File.expand_path('..', __dir__)
Dir.chdir(VENDOR_PATH) do
begin
exec "yarnpkg #{ARGV.join(" ")}"
rescue Errno::ENOENT
$stderr.puts "Yarn executable was not detected in the system."
$stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
exit 1
end
end

View file

@ -11,6 +11,9 @@ SITE_CONFIG = YAML.load_file(File.join(File.dirname(__FILE__), 'site.yml'))
module Tracksapp
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.1
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.

View file

@ -7,3 +7,4 @@ test:
production:
adapter: redis
url: redis://localhost:6379/1
channel_prefix: tracksapp_production

View file

@ -18,7 +18,7 @@ Rails.application.configure do
config.cache_store = :memory_store
config.public_file_server.headers = {
'Cache-Control' => 'public, max-age=172800'
'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}"
}
else
config.action_controller.perform_caching = false
@ -49,4 +49,8 @@ Rails.application.configure do
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
end

View file

@ -78,7 +78,7 @@ Rails.application.configure do
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
# Do not dump schema after migrations.

View file

@ -15,7 +15,7 @@ Rails.application.configure do
# Configure public file server for tests with Cache-Control for performance.
config.public_file_server.enabled = true
config.public_file_server.headers = {
'Cache-Control' => 'public, max-age=3600'
'Cache-Control' => "public, max-age=#{1.hour.seconds.to_i}"
}
# Show full error reports and disable caching.

View file

@ -3,11 +3,14 @@
# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = '1.0'
# Add additional assets to the asset load path
# Add additional assets to the asset load path.
# Rails.application.config.assets.paths << Emoji.images_path
# Add Yarn node_modules folder to the asset load path.
Rails.application.config.assets.paths << Rails.root.join('node_modules')
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
# application.js, application.css, and all non-JS/CSS in the app/assets
# folder are already added.
Rails.application.config.assets.precompile += %w( print.css mobile.css jquery-ui/datepicker-*.js swf_fu.js )
# add /app/assets/swfs to asset pipeline for charts

View file

@ -0,0 +1,14 @@
# Be sure to restart your server when you modify this file.
#
# This file contains migration options to ease your Rails 5.1 upgrade.
#
# Once upgraded flip defaults one by one to migrate to the new default.
#
# Read the Guide for Upgrading Ruby on Rails for more info on each option.
# Make `form_with` generate non-remote forms.
Rails.application.config.action_view.form_with_generates_remote_forms = false
# Unknown asset fallback will return the path passed in when the given
# asset is not present in the asset pipeline.
# Rails.application.config.assets.unknown_asset_fallback = false

View file

@ -1,13 +1,13 @@
# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers a minimum and maximum.
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum, this matches the default thread size of Active Record.
# and maximum; this matches the default thread size of Active Record.
#
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
threads threads_count, threads_count
# Specifies the `port` that Puma will listen on to receive requests, default is 3000.
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
port ENV.fetch("PORT") { 3000 }
@ -32,16 +32,25 @@ environment ENV.fetch("RAILS_ENV") { "development" }
#
# preload_app!
# If you are preloading your application and using Active Record, it's
# recommended that you close any connections to the database before workers
# are forked to prevent connection leakage.
#
# before_fork do
# ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
# end
# The code in the `on_worker_boot` will be called if you are using
# clustered mode by specifying a number of `workers`. After each worker
# process is booted this block will be run, if you are using `preload_app!`
# option you will want to use this block to reconnect to any threads
# or connections that may have been created at application boot, Ruby
# process is booted, this block will be run. If you are using the `preload_app!`
# option, you will want to use this block to reconnect to any threads
# or connections that may have been created at application boot, as Ruby
# cannot share connections between processes.
#
# on_worker_boot do
# ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
# end
#
# Allow puma to be restarted by `rails restart` command.
plugin :tmp_restart

View file

@ -10,13 +10,23 @@
# Make sure the secrets in this file are kept private
# if you're sharing your code publicly.
# Shared secrets are available across all environments.
# shared:
# api_key: a1B2c3D4e5F6
# Environmental secrets are only available for that specific environment.
development:
secret_key_base: <%= SITE_CONFIG["secret_token"] || SecureRandom.hex(64) %>
test:
secret_key_base: <%= SITE_CONFIG["secret_token"] || SecureRandom.hex(64) %>
# Do not keep production secrets in the repository,
# instead read values from the environment.
# Do not keep production secrets in the unencrypted secrets file.
# Instead, either read values from the environment.
# Or, use `bin/rails secrets:setup` to configure encrypted secrets
# and move the `production:` environment over there.
production:
secret_key_base: <%= SITE_CONFIG["secret_token"] || SecureRandom.hex(64) %>

View file

@ -61,12 +61,6 @@ class ContextTest < ActiveSupport::TestCase
assert_equal '', c.name
end
def test_new_record_before_save
assert !@agenda.new_record_before_save?, "existing records should not be new_record"
c = Context.where(:name => "I do not exist").first_or_create
assert c.new_record_before_save?, "newly created record should be new_record"
end
def test_hide_context
assert @agenda.active?
@agenda.hide!

View file

@ -174,12 +174,6 @@ class ProjectTest < ActiveSupport::TestCase
assert_equal 3, @moremoney.todos.not_completed.count
end
def test_new_record_before_save
assert !@timemachine.new_record_before_save?, "existing records should not be new_record"
p = Project.where(:name => "I do not exist").first_or_create
assert p.new_record_before_save?, "newly created record should be new_record"
end
def test_shortened_name
s = "project"*7 # len=49
p = users(:admin_user).projects.create(:name => s)