From 86bcc4d6c665a9e7ed7b924de615b0c6b491071b Mon Sep 17 00:00:00 2001 From: Dan Rice Date: Sun, 9 Aug 2015 17:05:04 -0400 Subject: [PATCH 1/8] Update Tolk to 1.9.3 Support Rails 4.2 --- Gemfile | 2 +- Gemfile.lock | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index 19c858b4e..4d907024f 100644 --- a/Gemfile +++ b/Gemfile @@ -52,7 +52,7 @@ group :development do gem "spring-commands-cucumber" gem "yard" - gem 'tolk', '~> 1.6.0' + gem 'tolk', '~> 1.9.3' gem "bullet" gem "rack-mini-profiler" diff --git a/Gemfile.lock b/Gemfile.lock index 05283aaaa..3d70300d8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -218,10 +218,9 @@ GEM thor (0.19.1) thread_safe (0.3.5) tilt (1.4.1) - tolk (1.6.0) - rails (>= 4.0, < 4.2) + tolk (1.9.3) + rails (>= 4.0, < 4.3) safe_yaml (>= 0.8.6) - will_paginate tzinfo (1.2.2) thread_safe (~> 0.1) uglifier (2.7.2) @@ -276,7 +275,7 @@ DEPENDENCIES swf_fu therubyracer thin - tolk (~> 1.6.0) + tolk (~> 1.9.3) uglifier (>= 1.3.0) will_paginate yard From d7d86446c028495312b98bb888643bead4425a14 Mon Sep 17 00:00:00 2001 From: Dan Rice Date: Sun, 9 Aug 2015 17:07:07 -0400 Subject: [PATCH 2/8] Upgrade to Rails 4.2 * Update boilerplate with `bin/rake rails:upgrade` * Use test instead of test:all rake task * Change stylesheet extensions from .css.scss to .scss * Update docs to use localhost instead of 0.0.0.0 because Rails 4.2 no longer listens on all addresses by default. --- Gemfile | 6 +- Gemfile.lock | 141 ++++++++++-------- app/assets/javascripts/application.js | 2 +- ...{application.css.scss => application.scss} | 2 +- .../{legacy.css.scss => legacy.scss} | 0 .../{login.css.scss => login.scss} | 0 .../{mobile.css.scss => mobile.scss} | 0 .../{print.css.scss => print.scss} | 0 ...{tracks-logo.css.scss => tracks-logo.scss} | 0 .../{tracks.css.scss => tracks.scss} | 0 bin/bundle | 3 + bin/rails | 10 +- bin/rake | 9 +- bin/setup | 29 ++++ config/application.rb | 3 + config/boot.rb | 3 +- config/environments/development.rb | 4 + config/environments/production.rb | 25 ++-- config/environments/test.rb | 7 +- config/initializers/assets.rb | 3 + config/initializers/cookies_serializer.rb | 3 + config/initializers/mime_types.rb | 1 - doc/CHANGELOG.md | 1 + doc/installation.md | 4 +- doc/tracks_api_wrapper.rb | 4 +- lib/tasks/continuous_integration.rake | 2 +- 26 files changed, 161 insertions(+), 101 deletions(-) rename app/assets/stylesheets/{application.css.scss => application.scss} (94%) rename app/assets/stylesheets/{legacy.css.scss => legacy.scss} (100%) rename app/assets/stylesheets/{login.css.scss => login.scss} (100%) rename app/assets/stylesheets/{mobile.css.scss => mobile.scss} (100%) rename app/assets/stylesheets/{print.css.scss => print.scss} (100%) rename app/assets/stylesheets/{tracks-logo.css.scss => tracks-logo.scss} (100%) rename app/assets/stylesheets/{tracks.css.scss => tracks.scss} (100%) create mode 100755 bin/bundle create mode 100755 bin/setup create mode 100644 config/initializers/cookies_serializer.rb diff --git a/Gemfile b/Gemfile index 4d907024f..d9e46cee9 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,8 @@ source 'https://rubygems.org' -gem 'rails', '~>4.1.11' -gem 'sass-rails', '~>4.0' -gem 'coffee-rails', '~>4.0' +gem 'rails', '~> 4.2.6' +gem 'sass-rails', '~> 5.0' +gem 'coffee-rails', '~> 4.1.0' #gem 'json' diff --git a/Gemfile.lock b/Gemfile.lock index 3d70300d8..9b841241a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,38 +3,47 @@ GEM specs: RedCloth (4.2.9) aasm (3.4.0) - actionmailer (4.1.14.1) - actionpack (= 4.1.14.1) - actionview (= 4.1.14.1) + actionmailer (4.2.6) + actionpack (= 4.2.6) + actionview (= 4.2.6) + activejob (= 4.2.6) mail (~> 2.5, >= 2.5.4) - actionpack (4.1.14.1) - actionview (= 4.1.14.1) - activesupport (= 4.1.14.1) - rack (~> 1.5.2) + rails-dom-testing (~> 1.0, >= 1.0.5) + actionpack (4.2.6) + actionview (= 4.2.6) + activesupport (= 4.2.6) + rack (~> 1.6) rack-test (~> 0.6.2) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.2) actionpack-xml_parser (1.0.1) actionpack (>= 4.0.0.rc1) - actionview (4.1.14.1) - activesupport (= 4.1.14.1) + actionview (4.2.6) + activesupport (= 4.2.6) builder (~> 3.1) erubis (~> 2.7.0) - activemodel (4.1.14.1) - activesupport (= 4.1.14.1) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + activejob (4.2.6) + activesupport (= 4.2.6) + globalid (>= 0.3.0) + activemodel (4.2.6) + activesupport (= 4.2.6) builder (~> 3.1) - activerecord (4.1.14.1) - activemodel (= 4.1.14.1) - activesupport (= 4.1.14.1) - arel (~> 5.0.0) + activerecord (4.2.6) + activemodel (= 4.2.6) + activesupport (= 4.2.6) + arel (~> 6.0) activerecord-deprecated_finders (1.0.3) - activesupport (4.1.14.1) - i18n (~> 0.6, >= 0.6.9) + activesupport (4.2.6) + i18n (~> 0.7) json (~> 1.7, >= 1.7.7) minitest (~> 5.1) - thread_safe (~> 0.1) + thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) acts_as_list (0.5.0) activerecord (>= 3.0) - arel (5.0.1.20140414130214) + arel (6.0.3) aruba (0.6.1) childprocess (>= 0.3.6) cucumber (>= 1.1.1) @@ -68,10 +77,11 @@ GEM coffee-rails (4.1.0) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.0) - coffee-script (2.3.0) + coffee-script (2.4.1) coffee-script-source execjs - coffee-script-source (1.8.0) + coffee-script-source (1.9.1.1) + concurrent-ruby (1.0.2) crass (0.2.1) cucumber (1.3.18) builder (>= 2.1.2) @@ -102,7 +112,8 @@ GEM sass (>= 3.2) gherkin (2.12.2) multi_json (~> 1.3) - hike (1.2.3) + globalid (0.3.6) + activesupport (>= 4.1.0) htmlentities (4.3.3) i18n (0.7.0) jquery-rails (3.1.3) @@ -112,20 +123,22 @@ GEM railties (>= 3.2.16) json (1.8.3) libv8 (3.16.14.7) - mail (2.6.3) - mime-types (>= 1.16, < 3) + loofah (2.0.3) + nokogiri (>= 1.5.9) + mail (2.6.4) + mime-types (>= 1.16, < 4) metaclass (0.0.4) method_source (0.8.2) - mime-types (2.99) + mime-types (2.99.2) mimemagic (0.3.0) mini_portile2 (2.0.0) - minitest (5.8.4) + minitest (5.9.0) mocha (1.1.0) metaclass (~> 0.0.1) multi_json (1.11.2) multi_test (0.1.1) mysql2 (0.3.20) - nokogiri (1.6.7) + nokogiri (1.6.7.2) mini_portile2 (~> 2.0.0.rc2) nokogumbo (1.1.12) nokogiri @@ -139,31 +152,40 @@ GEM coderay (~> 1.1.0) method_source (~> 0.8.1) slop (~> 3.4) - rack (1.5.5) + rack (1.6.4) rack-dev-mark (0.7.3) rack (>= 1.1) rack-mini-profiler (0.9.2) rack (>= 1.1.3) rack-test (0.6.3) rack (>= 1.0) - rails (4.1.14.1) - actionmailer (= 4.1.14.1) - actionpack (= 4.1.14.1) - actionview (= 4.1.14.1) - activemodel (= 4.1.14.1) - activerecord (= 4.1.14.1) - activesupport (= 4.1.14.1) + rails (4.2.6) + actionmailer (= 4.2.6) + actionpack (= 4.2.6) + actionview (= 4.2.6) + activejob (= 4.2.6) + activemodel (= 4.2.6) + activerecord (= 4.2.6) + activesupport (= 4.2.6) bundler (>= 1.3.0, < 2.0) - railties (= 4.1.14.1) - sprockets-rails (~> 2.0) + railties (= 4.2.6) + sprockets-rails + rails-deprecated_sanitizer (1.0.3) + activesupport (>= 4.2.0.alpha) + rails-dom-testing (1.0.7) + activesupport (>= 4.2.0.beta, < 5.0) + nokogiri (~> 1.6.0) + rails-deprecated_sanitizer (>= 1.0.1) + rails-html-sanitizer (1.0.3) + loofah (~> 2.0) rails_autolink (1.1.6) rails (> 3.1) - railties (4.1.14.1) - actionpack (= 4.1.14.1) - activesupport (= 4.1.14.1) + railties (4.2.6) + actionpack (= 4.2.6) + activesupport (= 4.2.6) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (10.5.0) + rake (11.1.2) ref (1.0.5) rspec-expectations (3.1.2) diff-lcs (>= 1.2.0, < 2.0) @@ -175,12 +197,13 @@ GEM crass (~> 0.2.0) nokogiri (>= 1.4.4) nokogumbo (= 1.1.12) - sass (3.2.19) - sass-rails (4.0.4) + sass (3.4.22) + sass-rails (5.0.4) railties (>= 4.0.0, < 5.0) - sass (~> 3.2.2) - sprockets (~> 2.8, < 2.12) - sprockets-rails (~> 2.0) + sass (~> 3.1) + sprockets (>= 2.8, < 4.0) + sprockets-rails (>= 2.0, < 4.0) + tilt (>= 1.1, < 3) selenium-webdriver (2.50.0) childprocess (~> 0.5) multi_json (~> 1.0) @@ -195,15 +218,13 @@ GEM spring (1.1.3) spring-commands-cucumber (1.0.1) spring (>= 0.9.1) - sprockets (2.11.3) - hike (~> 1.2) - multi_json (~> 1.0) - rack (~> 1.0) - tilt (~> 1.1, != 1.3.0) - sprockets-rails (2.3.3) - actionpack (>= 3.0) - activesupport (>= 3.0) - sprockets (>= 2.8, < 4.0) + sprockets (3.6.0) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.0.4) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) sqlite3 (1.3.10) swf_fu (2.0.4) coffee-script @@ -217,7 +238,7 @@ GEM rack (~> 1.0) thor (0.19.1) thread_safe (0.3.5) - tilt (1.4.1) + tilt (2.0.4) tolk (1.9.3) rails (>= 4.0, < 4.3) safe_yaml (>= 0.8.6) @@ -248,7 +269,7 @@ DEPENDENCIES bullet capybara codeclimate-test-reporter - coffee-rails (~> 4.0) + coffee-rails (~> 4.1.0) cucumber-rails database_cleaner factory_girl_rails @@ -262,11 +283,11 @@ DEPENDENCIES pry rack-dev-mark rack-mini-profiler - rails (~> 4.1.11) + rails (~> 4.2.6) rails_autolink rspec-expectations sanitize (>= 3.0.0) - sass-rails (~> 4.0) + sass-rails (~> 5.0) selenium-webdriver (>= 2.50) simplecov spring @@ -281,4 +302,4 @@ DEPENDENCIES yard BUNDLED WITH - 1.10.6 + 1.11.2 diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 6471f7f0b..854ff00f4 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -2,7 +2,7 @@ // listed below. // // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, -// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. +// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. // // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the // compiled file. diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.scss similarity index 94% rename from app/assets/stylesheets/application.css.scss rename to app/assets/stylesheets/application.scss index 222ff5202..5c73c7cfa 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.scss @@ -3,7 +3,7 @@ * listed below. * * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, - * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. + * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. * * You're free to add application-wide styles to this file and they'll appear at the bottom of the * compiled file so the styles you add here take precedence over styles defined in any styles diff --git a/app/assets/stylesheets/legacy.css.scss b/app/assets/stylesheets/legacy.scss similarity index 100% rename from app/assets/stylesheets/legacy.css.scss rename to app/assets/stylesheets/legacy.scss diff --git a/app/assets/stylesheets/login.css.scss b/app/assets/stylesheets/login.scss similarity index 100% rename from app/assets/stylesheets/login.css.scss rename to app/assets/stylesheets/login.scss diff --git a/app/assets/stylesheets/mobile.css.scss b/app/assets/stylesheets/mobile.scss similarity index 100% rename from app/assets/stylesheets/mobile.css.scss rename to app/assets/stylesheets/mobile.scss diff --git a/app/assets/stylesheets/print.css.scss b/app/assets/stylesheets/print.scss similarity index 100% rename from app/assets/stylesheets/print.css.scss rename to app/assets/stylesheets/print.scss diff --git a/app/assets/stylesheets/tracks-logo.css.scss b/app/assets/stylesheets/tracks-logo.scss similarity index 100% rename from app/assets/stylesheets/tracks-logo.css.scss rename to app/assets/stylesheets/tracks-logo.scss diff --git a/app/assets/stylesheets/tracks.css.scss b/app/assets/stylesheets/tracks.scss similarity index 100% rename from app/assets/stylesheets/tracks.css.scss rename to app/assets/stylesheets/tracks.scss diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 000000000..66e9889e8 --- /dev/null +++ b/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails index 1c894d52f..5191e6927 100755 --- a/bin/rails +++ b/bin/rails @@ -1,10 +1,4 @@ #!/usr/bin/env ruby -begin - load File.expand_path("../spring", __FILE__) -rescue LoadError -end -# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. - -APP_PATH = File.expand_path('../../config/application', __FILE__) -require File.expand_path('../../config/boot', __FILE__) +APP_PATH = File.expand_path('../../config/application', __FILE__) +require_relative '../config/boot' require 'rails/commands' diff --git a/bin/rake b/bin/rake index 0fb4e07e1..17240489f 100755 --- a/bin/rake +++ b/bin/rake @@ -1,7 +1,4 @@ #!/usr/bin/env ruby -begin - load File.expand_path("../spring", __FILE__) -rescue LoadError -end -require 'bundler/setup' -load Gem.bin_path('rake', 'rake') +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/bin/setup b/bin/setup new file mode 100755 index 000000000..acdb2c138 --- /dev/null +++ b/bin/setup @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +require 'pathname' + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +Dir.chdir APP_ROOT do + # This script is a starting point to setup your application. + # Add necessary setup steps to this file: + + puts "== Installing dependencies ==" + system "gem install bundler --conservative" + system "bundle check || bundle install" + + # puts "\n== Copying sample files ==" + # unless File.exist?("config/database.yml") + # system "cp config/database.yml.sample config/database.yml" + # end + + puts "\n== Preparing database ==" + system "bin/rake db:setup" + + puts "\n== Removing old logs and tempfiles ==" + system "rm -f log/*" + system "rm -rf tmp/cache" + + puts "\n== Restarting application server ==" + system "touch tmp/restart.txt" +end diff --git a/config/application.rb b/config/application.rb index 7a25146b3..038cf12d3 100644 --- a/config/application.rb +++ b/config/application.rb @@ -28,6 +28,9 @@ class Application < Rails::Application # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] # config.i18n.default_locale = :de + # Do not swallow errors in after_commit/after_rollback callbacks. + config.active_record.raise_in_transactional_callbacks = true + # configure Tracks to handle deployment in a subdir config.relative_url_root = SITE_CONFIG['subdir'] if SITE_CONFIG['subdir'] diff --git a/config/boot.rb b/config/boot.rb index 5e5f0c1fa..6b750f00b 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,4 +1,3 @@ -# Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) -require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) +require 'bundler/setup' # Set up gems listed in the Gemfile. diff --git a/config/environments/development.rb b/config/environments/development.rb index 4b57a9c34..a4af699c1 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -27,6 +27,10 @@ # number of complex assets. config.assets.debug = true + # Asset digests allow you to set far-future HTTP expiration dates on all assets, + # yet still be able to expire them through the digest params. + config.assets.digest = true + # Adds additional error checking when serving assets at runtime. # Checks for improperly declared sprockets dependencies. # Raises helpful error messages. diff --git a/config/environments/production.rb b/config/environments/production.rb index 6740382b9..03085a62c 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -16,11 +16,13 @@ # Enable Rack::Cache to put a simple HTTP cache in front of your application # Add `rack-cache` to your Gemfile before enabling this. - # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid. + # For large-scale production use, consider using a caching reverse proxy like + # NGINX, varnish or squid. # config.action_dispatch.rack_cache = true - # Disable Rails's static asset server (Apache or nginx will already do this). - config.serve_static_assets = SITE_CONFIG['serve_static_assets'] || false + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? || SITE_CONFIG['serve_static_assets'] || false # Compress JavaScripts and CSS. config.assets.js_compressor = :uglifier @@ -29,20 +31,22 @@ # Do not fallback to assets pipeline if a precompiled asset is missed. config.assets.compile = false - # Generate digests for assets URLs. + # Asset digests allow you to set far-future HTTP expiration dates on all assets, + # yet still be able to expire them through the digest params. config.assets.digest = true # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb # Specifies the header that your server uses for sending files. - # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache - # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx + # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true - # Set to :debug to see everything in the log. - config.log_level = :info + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. + config.log_level = :debug # Prepend all log lines with the following tags. # config.log_tags = [ :subdomain, :uuid ] @@ -54,7 +58,7 @@ # config.cache_store = :mem_cache_store # Enable serving of images, stylesheets, and JavaScripts from an asset server. - # config.action_controller.asset_host = "http://assets.example.com" + # config.action_controller.asset_host = 'http://assets.example.com' # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. @@ -67,9 +71,6 @@ # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify - # Disable automatic flushing of the log to improve performance. - # config.autoflush_log = false - # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new diff --git a/config/environments/test.rb b/config/environments/test.rb index 053f5b66d..1c19f08b2 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -12,8 +12,8 @@ # preloads Rails for running tests, you may have to set it to true. config.eager_load = false - # Configure static asset server for tests with Cache-Control for performance. - config.serve_static_assets = true + # Configure static file server for tests with Cache-Control for performance. + config.serve_static_files = true config.static_cache_control = 'public, max-age=3600' # Show full error reports and disable caching. @@ -31,6 +31,9 @@ # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test + # Randomize the order test cases are executed. + config.active_support.test_order = :random + # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 340e8daaa..68d7ce181 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -3,6 +3,9 @@ # 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 +# Rails.application.config.assets.paths << Emoji.images_path + # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. Rails.application.config.assets.precompile += %w( print.css mobile.css jquery-ui/datepicker-*.js ) diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb new file mode 100644 index 000000000..ac5f8b663 --- /dev/null +++ b/config/initializers/cookies_serializer.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +Rails.application.config.action_dispatch.cookies_serializer = :marshal diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index da62ea3e7..f3db7c925 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -2,7 +2,6 @@ # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf -# Mime::Type.register_alias "text/html", :iphone Mime::Type.register_alias "text/html", :m Mime::Type.register_alias "text/plain", :autocomplete diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index c644826b5..038ba777b 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -2,6 +2,7 @@ * Removed support for deprecated password-hashing algorithm. This eliminates config.salt. Note the addition of a pre-upgrade step to check for obsolete passwords. +* Rails 4.2 * Thin replaces WEBrick as the included web server * Tracks is tested on Ruby 1.9.3, 2.0.0, 2.1, and 2.2. * The MessageGateway will save the received email as an attachement to the todo diff --git a/doc/installation.md b/doc/installation.md index d5dbcd3ef..3b853ce3b 100644 --- a/doc/installation.md +++ b/doc/installation.md @@ -94,11 +94,11 @@ While still in the Terminal inside the Tracks root directory, issue the followin bundle exec rails server -e production -If all goes well, you should see some text informing you that the server is running: `=> Rails application starting in production on http://0.0.0.0:3000`. If you are already running other services on port 3000, you need to select a different port when running the server, using the `-p` option. +If all goes well, you should see some text informing you that the server is running: `=> Rails application starting in production on http://localhost:3000`. If you are already running other services on port 3000, you need to select a different port when running the server, using the `-p` option. ## Visit Tracks in a browser -Visit `http://0.0.0.0:3000/signup` in a browser (or whatever URL and port was reported when you started the server in the step above) and chose a user name and password for admin user. Once logged in as admin, you can add other (ordinary level) users. If you need to access Tracks from a mobile/cellular phone browser, visit `http://yourdomain.com/mobile/`. This mobile version is a special, lightweight version of Tracks, designed to use on a mobile browser. +Visit `http://localhost:3000/signup` in a browser (or whatever URL and port was reported when you started the server in the step above) and chose a user name and password for admin user. Once logged in as admin, you can add other (ordinary level) users. If you need to access Tracks from a mobile/cellular phone browser, visit `http://yourdomain.com/mobile/`. This mobile version is a special, lightweight version of Tracks, designed to use on a mobile browser. ## Customise Tracks diff --git a/doc/tracks_api_wrapper.rb b/doc/tracks_api_wrapper.rb index db01b0414..1911c8910 100644 --- a/doc/tracks_api_wrapper.rb +++ b/doc/tracks_api_wrapper.rb @@ -37,7 +37,7 @@ module Tracks class Base < ActiveResource::Base - self.site = ENV["SITE"] || "http://username:password@0.0.0.0:3000/" + self.site = ENV["SITE"] || "http://username:password@localhost:3000/" end class Todo < Base @@ -57,4 +57,4 @@ def todos end end -end \ No newline at end of file +end diff --git a/lib/tasks/continuous_integration.rake b/lib/tasks/continuous_integration.rake index a2df86bcd..b3d6536af 100644 --- a/lib/tasks/continuous_integration.rake +++ b/lib/tasks/continuous_integration.rake @@ -5,7 +5,7 @@ namespace :ci do puts 'Running "lite" test suite' - [:environment, 'db:create', 'test:all'].each do |t| + [:environment, 'db:create', :test].each do |t| Rake::Task[t].invoke end end From 689db4c9c3068681633f0b1dc204fa3c8ecb9dbe Mon Sep 17 00:00:00 2001 From: Dan Rice Date: Sun, 9 Aug 2015 17:43:40 -0400 Subject: [PATCH 3/8] Update assert_select for Nokogiri compatibility assert_select has been moved into the rails-dom-testing gem and is now based on Nokogiri. * Remove assert_tag and assert_xml_select * Quote CSS attribute selector values * Use decoded versions of HTML in assert_select. Nokogiri decodes elements prior to matching. * Add a test helper for entities such as ` ` for which it's difficult or confusing to include the decoded version directly in the assertion. * Assert directly on Atom feeds' XML namespace because it isn't selectable as an attribute --- test/controllers/contexts_controller_test.rb | 16 +++++---- test/controllers/feedlist_controller_test.rb | 2 +- test/controllers/projects_controller_test.rb | 15 ++++---- test/controllers/todos_controller_test.rb | 38 ++++++++++---------- test/integration/project_xml_api_test.rb | 11 +++--- test/integration/todo_xml_api_test.rb | 10 +++--- test/integration/users_xml_api_test.rb | 11 +++--- test/support/html_entity_helper.rb | 11 ++++++ test/test_helper.rb | 16 +-------- 9 files changed, 66 insertions(+), 64 deletions(-) create mode 100644 test/support/html_entity_helper.rb diff --git a/test/controllers/contexts_controller_test.rb b/test/controllers/contexts_controller_test.rb index 9b6b5c7da..6961a6536 100644 --- a/test/controllers/contexts_controller_test.rb +++ b/test/controllers/contexts_controller_test.rb @@ -1,6 +1,9 @@ require 'test_helper' +require 'support/html_entity_helper' class ContextsControllerTest < ActionController::TestCase + include HTMLEntityHelper + fixtures :users, :preferences, :contexts def test_contexts_list @@ -96,7 +99,7 @@ def test_show_xml_with_nil_context_returns_404 login_as :admin_user get :show, { :id => "0", :format => 'xml' } assert_response 404 - assert_xml_select 'error', 'Context not found' + assert_select 'error', 'Context not found' end # RSS @@ -107,7 +110,7 @@ def test_rss_feed_content assert_equal 'application/rss+xml', @response.content_type #puts @response.body - assert_xml_select 'rss[version="2.0"]' do + assert_select 'rss[version="2.0"]' do assert_select 'channel' do assert_select '>title', 'Tracks Contexts' assert_select '>description', "Lists all the contexts for #{users(:admin_user).display_name}" @@ -118,7 +121,7 @@ def test_rss_feed_content assert_select 'title', /.+/ assert_select 'description' do assert_select_encoded do - assert_select 'p', /\d+ actions. Context is (Active|Hidden)./ + assert_select 'p', /\d+#{nbsp}actions. Context is (Active|Hidden)./ end end %w(guid link).each do |node| @@ -153,16 +156,15 @@ def test_atom_feed_content login_as :admin_user get :index, { :format => "atom" } assert_equal 'application/atom+xml', @response.content_type - #puts @response.body - - assert_xml_select 'feed[xmlns="http://www.w3.org/2005/Atom"]' do + assert_equal 'http://www.w3.org/2005/Atom', html_document.children[0].namespace.href + assert_select 'feed' do assert_select '>title', 'Tracks Contexts' assert_select '>subtitle', "Lists all the contexts for #{users(:admin_user).display_name}" assert_select 'entry', 10 do assert_select 'title', /.+/ assert_select 'content[type="html"]' do assert_select_encoded do - assert_select 'p', /\d+ actions. Context is (Active|Hidden)./ + assert_select 'p', /\d+#{nbsp}actions. Context is (Active|Hidden)./ end end assert_select 'published', /(#{Regexp.escape(contexts(:agenda).created_at.xmlschema)}|#{Regexp.escape(contexts(:library).created_at.xmlschema)})/ diff --git a/test/controllers/feedlist_controller_test.rb b/test/controllers/feedlist_controller_test.rb index a14a94156..58a5491f7 100644 --- a/test/controllers/feedlist_controller_test.rb +++ b/test/controllers/feedlist_controller_test.rb @@ -26,4 +26,4 @@ def test_get_feeds_for_project_using_xhr assert_response 200 end -end \ No newline at end of file +end diff --git a/test/controllers/projects_controller_test.rb b/test/controllers/projects_controller_test.rb index 6af1cf159..6ebccb4cf 100644 --- a/test/controllers/projects_controller_test.rb +++ b/test/controllers/projects_controller_test.rb @@ -1,6 +1,8 @@ require 'test_helper' +require 'support/html_entity_helper' class ProjectsControllerTest < ActionController::TestCase + include HTMLEntityHelper def setup end @@ -83,7 +85,7 @@ def test_rss_feed_content assert_equal 'application/rss+xml', @response.content_type #puts @response.body - assert_xml_select 'rss[version="2.0"]' do + assert_select 'rss[version="2.0"]' do assert_select 'channel' do assert_select '>title', 'Tracks Projects' assert_select '>description', "Lists all the projects for #{users(:admin_user).display_name}" @@ -94,7 +96,7 @@ def test_rss_feed_content assert_select 'title', /.+/ assert_select 'description' do assert_select_encoded do - assert_select 'p', /^\d+ actions\. Project is (active|hidden|completed)\.$/ + assert_select 'p', /^\d+#{nbsp}actions\. Project is (active|hidden|completed)\.$/ end end %w(guid link).each do |node| @@ -127,16 +129,15 @@ def test_atom_feed_content login_as :admin_user get :index, { :format => "atom" } assert_equal 'application/atom+xml', @response.content_type - # puts @response.body - - assert_xml_select 'feed[xmlns="http://www.w3.org/2005/Atom"]' do + assert_equal 'http://www.w3.org/2005/Atom', html_document.children[0].namespace.href + assert_select 'feed' do assert_select '>title', 'Tracks Projects' assert_select '>subtitle', "Lists all the projects for #{users(:admin_user).display_name}" assert_select 'entry', 3 do assert_select 'title', /.+/ assert_select 'content[type="html"]' do assert_select_encoded do - assert_select 'p', /\d+ actions. Project is (active|hidden|completed)./ + assert_select 'p', /\d+#{nbsp}actions. Project is (active|hidden|completed)./ end end assert_select 'published', /(#{Regexp.escape(projects(:timemachine).updated_at.xmlschema)}|#{Regexp.escape(projects(:moremoney).updated_at.xmlschema)})/ @@ -239,7 +240,7 @@ def test_xml_content get :index, { :format => "xml" } assert_equal 'application/xml', @response.content_type - assert_xml_select 'projects' do + assert_select 'projects' do assert_select 'project', 3 do assert_select 'name', /.+/ assert_select 'state', 'active' diff --git a/test/controllers/todos_controller_test.rb b/test/controllers/todos_controller_test.rb index 17f2557da..5e3e368a8 100644 --- a/test/controllers/todos_controller_test.rb +++ b/test/controllers/todos_controller_test.rb @@ -1,7 +1,6 @@ require 'test_helper' class TodosControllerTest < ActionController::TestCase - def test_get_index_when_not_logged_in get :index assert_redirected_to login_url @@ -235,8 +234,8 @@ def test_fail_to_create_todo_via_xml "project_name"=>"Build a working time machine", "todo"=>{"notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2006"}, "tag_list"=>"foo bar" } assert_response 409 - assert_xml_select "errors" do - assert_xml_select "error", "Context can't be blank" + assert_select "errors" do + assert_select "error", "Context can't be blank" end end @@ -467,7 +466,7 @@ def test_rss_feed assert_equal 'application/rss+xml', @response.content_type # puts @response.body - assert_xml_select 'rss[version="2.0"]' do + assert_select 'rss[version="2.0"]' do assert_select 'channel' do assert_select '>title', 'Tracks Actions' assert_select '>description', "Actions for #{users(:admin_user).display_name}" @@ -488,7 +487,7 @@ def test_rss_feed_with_limit login_as(:admin_user) get :index, { :format => "rss", :limit => '5' } - assert_xml_select 'rss[version="2.0"]' do + assert_select 'rss[version="2.0"]' do assert_select 'channel' do assert_select '>title', 'Tracks Actions' assert_select '>description', "Actions for #{users(:admin_user).display_name}" @@ -522,15 +521,14 @@ def test_atom_feed_content login_as :admin_user get :index, { :format => "atom" } assert_equal 'application/atom+xml', @response.content_type - # #puts @response.body - - assert_xml_select 'feed[xmlns="http://www.w3.org/2005/Atom"]' do - assert_xml_select '>title', 'Tracks Actions' - assert_xml_select '>subtitle', "Actions for #{users(:admin_user).display_name}" - assert_xml_select 'entry', 17 do - assert_xml_select 'title', /.+/ - assert_xml_select 'content[type="html"]', /.*/ - assert_xml_select 'published', /(#{Regexp.escape(todos(:book).updated_at.xmlschema)}|#{Regexp.escape(projects(:moremoney).updated_at.xmlschema)})/ + assert_equal 'http://www.w3.org/2005/Atom', html_document.children[0].namespace.href + assert_select 'feed' do + assert_select '>title', 'Tracks Actions' + assert_select '>subtitle', "Actions for #{users(:admin_user).display_name}" + assert_select 'entry', 17 do + assert_select 'title', /.+/ + assert_select 'content[type="html"]', /.*/ + assert_select 'published', /(#{Regexp.escape(todos(:book).updated_at.xmlschema)}|#{Regexp.escape(projects(:moremoney).updated_at.xmlschema)})/ end end end @@ -846,7 +844,7 @@ def test_url_with_slash_in_query_string_are_parsed_correctly todo.notes = "foo #{url} bar" todo.save! get :index - assert_select "a[href=#{url}]" + assert_select "a[href='#{url}']" end def test_link_opened_in_new_window @@ -886,7 +884,7 @@ def test_format_note_link todo.save! get :index assert_select("div#notes_todo_#{todo.id}", 'A link to http://github.com/.') - assert_select("div#notes_todo_#{todo.id} a[href=http://github.com/]", 'http://github.com/') + assert_select("div#notes_todo_#{todo.id} a[href='http://github.com/']", 'http://github.com/') end def test_format_note_link_message @@ -895,9 +893,9 @@ def test_format_note_link_message todo.raw_notes = "A Mail.app message:// link" todo.save! get :index - assert_select("div#notes_todo_#{todo.id}", 'A Mail.app message://<ABCDEF-GHADB-123455-FOO-BAR@example.com> link') - assert_select("div#notes_todo_#{todo.id} a", 'message://<ABCDEF-GHADB-123455-FOO-BAR@example.com>') - assert_select("div#notes_todo_#{todo.id} a[href=message://<ABCDEF-GHADB-123455-FOO-BAR@example.com>]", 'message://<ABCDEF-GHADB-123455-FOO-BAR@example.com>') + assert_select("div#notes_todo_#{todo.id}", 'A Mail.app message:// link') + assert_select("div#notes_todo_#{todo.id} a", 'message://') + assert_select("div#notes_todo_#{todo.id} a[href='message://']", "message://") end def test_format_note_link_onenote @@ -908,7 +906,7 @@ def test_format_note_link_onenote get :index assert_select("div#notes_todo_#{todo.id}", 'link me to onenote') assert_select("div#notes_todo_#{todo.id} a", 'link me to onenote') - assert_select("div#notes_todo_#{todo.id} a[href=onenote:///E:%5COneNote%5Cdir%5Cnotes.one#PAGE&section-id=%7BFD597D3A-3793-495F-8345-23D34A00DD3B%7D&page-id=%7B1C95A1C7-6408-4804-B3B5-96C28426022B%7D&end]", 'link me to onenote') + assert_select("div#notes_todo_#{todo.id} a[href='onenote:///E:%5COneNote%5Cdir%5Cnotes.one#PAGE§ion-id=%7BFD597D3A-3793-495F-8345-23D34A00DD3B%7D&page-id=%7B1C95A1C7-6408-4804-B3B5-96C28426022B%7D&end']", 'link me to onenote') end ############## diff --git a/test/integration/project_xml_api_test.rb b/test/integration/project_xml_api_test.rb index 9cfbfab8e..f6dd305a7 100644 --- a/test/integration/project_xml_api_test.rb +++ b/test/integration/project_xml_api_test.rb @@ -6,11 +6,12 @@ class ProjectXmlApiTest < ActionDispatch::IntegrationTest def test_retrieve_project authenticated_get_xml "/projects/1.xml", users(:admin_user).login, 'abracadabra', {} - assert_tag :tag => "project" - assert_tag :tag => "project", :child => {:tag => "not_done" } - assert_tag :tag => "project", :child => {:tag => "deferred" } - assert_tag :tag => "project", :child => {:tag => "pending" } - assert_tag :tag => "project", :child => {:tag => "done" } + assert_select 'project' do + assert_select 'not_done' + assert_select 'deferred' + assert_select 'pending' + assert_select 'done' + end assert_response 200 end diff --git a/test/integration/todo_xml_api_test.rb b/test/integration/todo_xml_api_test.rb index 384bc8891..328545abe 100644 --- a/test/integration/todo_xml_api_test.rb +++ b/test/integration/todo_xml_api_test.rb @@ -24,12 +24,14 @@ def test_get_tickler_needs_authentication def test_get_tickler_returns_all_deferred_and_pending_todos number = @user.todos.deferred.count + @user.todos.pending.count authenticated_get_xml "/tickler.xml", @user.login, @password, {} - assert_tag :tag => "todos", :children => { :count => number } + assert_select 'todos' do + assert_select 'todo', count: number + end end def test_get_tickler_omits_user_id authenticated_get_xml "/tickler.xml", @user.login, @password, {} - assert_no_tag :tag => "user_id" + assert_select 'user_id', false end def test_get_index_with_only_active_todos @@ -245,7 +247,7 @@ def test_post_create_todo_with_wrong_project_and_context_id -11 " assert_response 409 - assert_xml_select 'errors' do + assert_select 'errors' do assert_select 'error', 2 end end @@ -261,4 +263,4 @@ def authenticated_post_xml_to_todo_create(postdata = @@valid_postdata, user = @u authenticated_post_xml "/todos.xml", user, password, postdata end -end \ No newline at end of file +end diff --git a/test/integration/users_xml_api_test.rb b/test/integration/users_xml_api_test.rb index d206de851..d47c354ae 100644 --- a/test/integration/users_xml_api_test.rb +++ b/test/integration/users_xml_api_test.rb @@ -69,16 +69,17 @@ def test_fails_with_get_verb def test_get_users_as_xml get '/users.xml', {}, basic_auth_headers() assert_response :success - assert_tag :tag => "users", - :children => { :count => 4, :only => { :tag => "user" } } - assert_no_tag :tag => "password" + assert_select 'users' do + assert_select 'user', count: 4 + end + assert_select 'password', false end def test_get_user_as_xml get "/users/#{users(:other_user).id}.xml", {}, basic_auth_headers() assert_response :success - assert_tag :tag => "user" - assert_no_tag :tag => "password" + assert_select 'user' + assert_select 'password', false end private diff --git a/test/support/html_entity_helper.rb b/test/support/html_entity_helper.rb new file mode 100644 index 000000000..f948d8e9d --- /dev/null +++ b/test/support/html_entity_helper.rb @@ -0,0 +1,11 @@ +require 'htmlentities' + +module HTMLEntityHelper + def entity(name) + HTMLEntities.new.decode("&#{name};") + end + + def nbsp + entity('nbsp') + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index ebb0e96e9..a7e16bef4 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -56,15 +56,6 @@ def generate_random_string(length) def assert_equal_dmy(date1, date2) assert_equal date1.strftime("%d-%m-%y"), date2.strftime("%d-%m-%y") end - - def xml_document - @xml_document ||= HTML::Document.new(@response.body, false, true) - end - - def assert_xml_select(*args, &block) - @html_document = xml_document - assert_select(*args, &block) - end end class ActionController::TestCase @@ -90,11 +81,6 @@ def ajax_create(name) xhr :post, :create, get_model_class.downcase => {:name => name} end - def assert_xml_select(*args, &block) - @html_document = xml_document - assert_select(*args, &block) - end - private def get_model_class @@ -145,7 +131,7 @@ def assert_401_unauthorized_admin def assert_responses_with_error(error_msg) assert_response 409 - assert_xml_select 'errors' do + assert_select 'errors' do assert_select 'error', 1, error_msg end end From a789a0296b768160f533eaaae91b18c015cd7742 Mon Sep 17 00:00:00 2001 From: Dan Rice Date: Mon, 10 Aug 2015 09:49:36 -0400 Subject: [PATCH 4/8] Reorder HTML tag attributes to fix failing tests --- test/helpers/todo_helpers_test.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/helpers/todo_helpers_test.rb b/test/helpers/todo_helpers_test.rb index 0e952a9dc..6491b561d 100644 --- a/test/helpers/todo_helpers_test.rb +++ b/test/helpers/todo_helpers_test.rb @@ -5,23 +5,23 @@ class TodosHelpersTest < ActionView::TestCase test "remote_edit_button" do html = remote_edit_button(todos(:call_bill)) - assert_equal "\"Edit\"", html + assert_equal "\"Edit\"", html end test "remote_delete_menu" do html = remote_delete_menu_item(todos(:call_bill)) - assert_equal "Delete", html + assert_equal "Delete", html end test "remote_delete_dependency" do todo = todos(:call_bill_gates_every_day) predecessor = todos(:call_bill) html = remote_delete_dependency(todo, predecessor) - assert_equal "\"Blank\"", html + assert_equal "\"Blank\"", html end test "remote_promote_to_project_menu_item" do html = remote_promote_to_project_menu_item(todos(:call_bill)) - assert_equal "Make project", html + assert_equal "Make project", html end end From d42bf5141ed4f689c0711944d884147bd9d13f4f Mon Sep 17 00:00:00 2001 From: Dan Rice Date: Sun, 17 Jan 2016 21:13:51 -0500 Subject: [PATCH 5/8] Update acts_as_list to fix sanitize_sql_hash_for_conditions deprecation --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 9b841241a..623504d3f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -41,7 +41,7 @@ GEM minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) - acts_as_list (0.5.0) + acts_as_list (0.7.2) activerecord (>= 3.0) arel (6.0.3) aruba (0.6.1) From 3ecf9d6cfc8a92ae37e4f44b166c464801b4bff6 Mon Sep 17 00:00:00 2001 From: Dan Rice Date: Sat, 21 May 2016 20:18:35 -0400 Subject: [PATCH 6/8] Update protocol whitelist for rails-html-sanitizer --- config/application.rb | 3 --- config/initializers/sanitizer.rb | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) create mode 100644 config/initializers/sanitizer.rb diff --git a/config/application.rb b/config/application.rb index 038cf12d3..972c93832 100644 --- a/config/application.rb +++ b/config/application.rb @@ -34,9 +34,6 @@ class Application < Rails::Application # configure Tracks to handle deployment in a subdir config.relative_url_root = SITE_CONFIG['subdir'] if SITE_CONFIG['subdir'] - # allow onenote:// and message:// as protocols for urls - config.action_view.sanitized_allowed_protocols = 'onenote', 'message' - config.middleware.insert_after ActionDispatch::ParamsParser, ActionDispatch::XmlParamsParser end end diff --git a/config/initializers/sanitizer.rb b/config/initializers/sanitizer.rb new file mode 100644 index 000000000..6d99f4042 --- /dev/null +++ b/config/initializers/sanitizer.rb @@ -0,0 +1 @@ +Loofah::HTML5::WhiteList::ALLOWED_PROTOCOLS.merge(%w(message onenote)) From 3de582f436086d7a152a1137e2fd28d90db93712 Mon Sep 17 00:00:00 2001 From: Dan Rice Date: Sun, 22 May 2016 17:23:11 -0400 Subject: [PATCH 7/8] Use rails-dom-testing from source to work around a bug --- Gemfile | 4 ++++ Gemfile.lock | 15 +++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index d9e46cee9..312e81857 100644 --- a/Gemfile +++ b/Gemfile @@ -65,6 +65,10 @@ group :development, :test do end group :test do + # Pull in the fix for rails-dom-testing issue #42 + # TODO: Remove with Rails 5 and rails-dom-testing 2.x + gem 'rails-dom-testing', github: 'rails/rails-dom-testing', ref: 'a64f30514ee65f172c43f42cfd4500b5e11a561a' + gem "factory_girl_rails" gem "capybara" gem "cucumber-rails", :require => false diff --git a/Gemfile.lock b/Gemfile.lock index 623504d3f..ef82298c3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,13 @@ +GIT + remote: git://github.com/rails/rails-dom-testing.git + revision: a64f30514ee65f172c43f42cfd4500b5e11a561a + ref: a64f30514ee65f172c43f42cfd4500b5e11a561a + specs: + rails-dom-testing (1.0.7) + activesupport (>= 4.2.0.beta, < 5.0) + nokogiri (~> 1.6.0) + rails-deprecated_sanitizer (>= 1.0.1) + GEM remote: https://rubygems.org/ specs: @@ -172,10 +182,6 @@ GEM sprockets-rails rails-deprecated_sanitizer (1.0.3) activesupport (>= 4.2.0.alpha) - rails-dom-testing (1.0.7) - activesupport (>= 4.2.0.beta, < 5.0) - nokogiri (~> 1.6.0) - rails-deprecated_sanitizer (>= 1.0.1) rails-html-sanitizer (1.0.3) loofah (~> 2.0) rails_autolink (1.1.6) @@ -284,6 +290,7 @@ DEPENDENCIES rack-dev-mark rack-mini-profiler rails (~> 4.2.6) + rails-dom-testing! rails_autolink rspec-expectations sanitize (>= 3.0.0) From 58e2b823155e2a384dfb69016076c6c0a599494f Mon Sep 17 00:00:00 2001 From: Dan Rice Date: Sun, 22 May 2016 16:21:00 -0400 Subject: [PATCH 8/8] Isolate SITE_CONFIG in tests using minitest-stub-const --- Gemfile | 1 + Gemfile.lock | 2 + .../integrations_controller_test.rb | 100 ++++++++++-------- test/controllers/mailgun_controller_test.rb | 80 +++++++------- test/integration/stories_test.rb | 34 +++--- test/support/stub_site_config_helper.rb | 9 ++ 6 files changed, 130 insertions(+), 96 deletions(-) create mode 100644 test/support/stub_site_config_helper.rb diff --git a/Gemfile b/Gemfile index 312e81857..e86021165 100644 --- a/Gemfile +++ b/Gemfile @@ -75,6 +75,7 @@ group :test do gem "rspec-expectations" gem "database_cleaner" gem "mocha", :require => false + gem "minitest-stub-const" gem "aruba", ">=0.5.4", :require => false diff --git a/Gemfile.lock b/Gemfile.lock index ef82298c3..70996d9d7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -143,6 +143,7 @@ GEM mimemagic (0.3.0) mini_portile2 (2.0.0) minitest (5.9.0) + minitest-stub-const (0.5) mocha (1.1.0) metaclass (~> 0.0.1) multi_json (1.11.2) @@ -283,6 +284,7 @@ DEPENDENCIES htmlentities jquery-rails jquery-ui-rails + minitest-stub-const mocha mysql2 (~> 0.3.17) paperclip diff --git a/test/controllers/integrations_controller_test.rb b/test/controllers/integrations_controller_test.rb index 6e15235cc..647b7f93b 100644 --- a/test/controllers/integrations_controller_test.rb +++ b/test/controllers/integrations_controller_test.rb @@ -1,6 +1,8 @@ require 'test_helper' +require 'support/stub_site_config_helper' class IntegrationsControllerTest < ActionController::TestCase + include StubSiteConfigHelper def setup end @@ -12,58 +14,64 @@ def test_page_load end def test_cloudmailin_integration_success - SITE_CONFIG['cloudmailin'] = "123456789" - SITE_CONFIG['email_dispatch'] = 'from' - post :cloudmailin, { - "html"=>"", - "plain"=>"asdasd", - "x_to_header"=>"[\"81496ecea21032d35a7a@cloudmailin.net\"]", - "disposable"=>"", - "from"=>"5555555555@tmomail.net", - "signature"=>"e85e908fb893394762047c21e54ce248", - "to"=>"<123123@cloudmailin.net>", - "subject"=>"asd", - "x_cc_header"=>"", - "message"=>"Received: from VMBX103.ihostexchange.net ([192.168.3.3]) by\r\n HUB103.ihostexchange.net ([66.46.182.53]) with mapi; Wed, 5 Oct 2011 17:12:44\r\n -0400\r\nFrom: SMS User <5555555555@tmomail.net>\r\nTo: Tracks <123123@cloudmailin.net>\r\nDate: Wed, 5 Oct 2011 17:12:43 -0400\r\nSubject: asd\r\nThread-Topic: asd\r\nThread-Index: AcyDo4aig2wghvcsTAOkleWqi4t/FQ==\r\nMessage-ID: <7D7CB176-7559-4997-A301-8DF9726264C7@tmomail.net>\r\nAccept-Language: de-DE, en-US\r\nContent-Language: en-US\r\nX-MS-Has-Attach:\r\nX-MS-TNEF-Correlator:\r\nacceptlanguage: de-DE, en-US\r\nContent-Type: text/plain; charset=\"us-ascii\"\r\nContent-Transfer-Encoding: quoted-printable\r\nMIME-Version: 1.0\r\n\r\nasdasd\r\n" - } - - assert_response :success + stub_site_config do + SITE_CONFIG['cloudmailin'] = "123456789" + SITE_CONFIG['email_dispatch'] = 'from' + post :cloudmailin, { + "html"=>"", + "plain"=>"asdasd", + "x_to_header"=>"[\"81496ecea21032d35a7a@cloudmailin.net\"]", + "disposable"=>"", + "from"=>"5555555555@tmomail.net", + "signature"=>"e85e908fb893394762047c21e54ce248", + "to"=>"<123123@cloudmailin.net>", + "subject"=>"asd", + "x_cc_header"=>"", + "message"=>"Received: from VMBX103.ihostexchange.net ([192.168.3.3]) by\r\n HUB103.ihostexchange.net ([66.46.182.53]) with mapi; Wed, 5 Oct 2011 17:12:44\r\n -0400\r\nFrom: SMS User <5555555555@tmomail.net>\r\nTo: Tracks <123123@cloudmailin.net>\r\nDate: Wed, 5 Oct 2011 17:12:43 -0400\r\nSubject: asd\r\nThread-Topic: asd\r\nThread-Index: AcyDo4aig2wghvcsTAOkleWqi4t/FQ==\r\nMessage-ID: <7D7CB176-7559-4997-A301-8DF9726264C7@tmomail.net>\r\nAccept-Language: de-DE, en-US\r\nContent-Language: en-US\r\nX-MS-Has-Attach:\r\nX-MS-TNEF-Correlator:\r\nacceptlanguage: de-DE, en-US\r\nContent-Type: text/plain; charset=\"us-ascii\"\r\nContent-Transfer-Encoding: quoted-printable\r\nMIME-Version: 1.0\r\n\r\nasdasd\r\n" + } + + assert_response :success + end end def test_cloudmailin_integration_invalid_signature - SITE_CONFIG['cloudmailin'] = "12345678901234567890" - post :cloudmailin, { - "html"=>"", - "plain"=>"asdasd", - "x_to_header"=>"[\"81496ecea21032d35a7a@cloudmailin.net\"]", - "disposable"=>"", - "from"=>"5555555555@tmomail.net", - "signature"=>"e85e908fb893394762047c21e54ce248", - "to"=>"<123123@cloudmailin.net>", - "subject"=>"asd", - "x_cc_header"=>"", - "message"=>"Received: from VMBX103.ihostexchange.net ([192.168.3.3]) by\r\n HUB103.ihostexchange.net ([66.46.182.53]) with mapi; Wed, 5 Oct 2011 17:12:44\r\n -0400\r\nFrom: SMS User <5555555555@tmomail.net>\r\nTo: Tracks <123123@cloudmailin.net>\r\nDate: Wed, 5 Oct 2011 17:12:43 -0400\r\nSubject: asd\r\nThread-Topic: asd\r\nThread-Index: AcyDo4aig2wghvcsTAOkleWqi4t/FQ==\r\nMessage-ID: <7D7CB176-7559-4997-A301-8DF9726264C7@tmomail.net>\r\nAccept-Language: de-DE, en-US\r\nContent-Language: en-US\r\nX-MS-Has-Attach:\r\nX-MS-TNEF-Correlator:\r\nacceptlanguage: de-DE, en-US\r\nContent-Type: text/plain; charset=\"us-ascii\"\r\nContent-Transfer-Encoding: quoted-printable\r\nMIME-Version: 1.0\r\n\r\nasdasd\r\n" - } - - assert_response 403 + stub_site_config do + SITE_CONFIG['cloudmailin'] = "12345678901234567890" + post :cloudmailin, { + "html"=>"", + "plain"=>"asdasd", + "x_to_header"=>"[\"81496ecea21032d35a7a@cloudmailin.net\"]", + "disposable"=>"", + "from"=>"5555555555@tmomail.net", + "signature"=>"e85e908fb893394762047c21e54ce248", + "to"=>"<123123@cloudmailin.net>", + "subject"=>"asd", + "x_cc_header"=>"", + "message"=>"Received: from VMBX103.ihostexchange.net ([192.168.3.3]) by\r\n HUB103.ihostexchange.net ([66.46.182.53]) with mapi; Wed, 5 Oct 2011 17:12:44\r\n -0400\r\nFrom: SMS User <5555555555@tmomail.net>\r\nTo: Tracks <123123@cloudmailin.net>\r\nDate: Wed, 5 Oct 2011 17:12:43 -0400\r\nSubject: asd\r\nThread-Topic: asd\r\nThread-Index: AcyDo4aig2wghvcsTAOkleWqi4t/FQ==\r\nMessage-ID: <7D7CB176-7559-4997-A301-8DF9726264C7@tmomail.net>\r\nAccept-Language: de-DE, en-US\r\nContent-Language: en-US\r\nX-MS-Has-Attach:\r\nX-MS-TNEF-Correlator:\r\nacceptlanguage: de-DE, en-US\r\nContent-Type: text/plain; charset=\"us-ascii\"\r\nContent-Transfer-Encoding: quoted-printable\r\nMIME-Version: 1.0\r\n\r\nasdasd\r\n" + } + + assert_response 403 + end end def test_cloudmailin_integration_unknown_address - SITE_CONFIG['cloudmailin'] = "123456789" - post :cloudmailin, { - "html"=>"", - "plain"=>"asdasd", - "x_to_header"=>"[\"81496ecea21032d35a7a@cloudmailin.net\"]", - "disposable"=>"", - "from"=>"444444444444@tmomail.net", - "signature"=>"6d2df0e807bfa9b77d24c31dce6d4515", - "to"=>"<123123@cloudmailin.net>", - "subject"=>"asd", - "x_cc_header"=>"", - "message"=>"Received: from VMBX103.ihostexchange.net ([192.168.3.3]) by\r\n HUB103.ihostexchange.net ([66.46.182.53]) with mapi; Wed, 5 Oct 2011 17:12:44\r\n -0400\r\nFrom: SMS User <444444444444@tmomail.net>\r\nTo: Tracks <123123@cloudmailin.net>\r\nDate: Wed, 5 Oct 2011 17:12:43 -0400\r\nSubject: asd\r\nThread-Topic: asd\r\nThread-Index: AcyDo4aig2wghvcsTAOkleWqi4t/FQ==\r\nMessage-ID: <7D7CB176-7559-4997-A301-8DF9726264C7@tmomail.net>\r\nAccept-Language: de-DE, en-US\r\nContent-Language: en-US\r\nX-MS-Has-Attach:\r\nX-MS-TNEF-Correlator:\r\nacceptlanguage: de-DE, en-US\r\nContent-Type: text/plain; charset=\"us-ascii\"\r\nContent-Transfer-Encoding: quoted-printable\r\nMIME-Version: 1.0\r\n\r\nasdasd\r\n" - } - - assert_response 404 + stub_site_config do + SITE_CONFIG['cloudmailin'] = "123456789" + post :cloudmailin, { + "html"=>"", + "plain"=>"asdasd", + "x_to_header"=>"[\"81496ecea21032d35a7a@cloudmailin.net\"]", + "disposable"=>"", + "from"=>"444444444444@tmomail.net", + "signature"=>"6d2df0e807bfa9b77d24c31dce6d4515", + "to"=>"<123123@cloudmailin.net>", + "subject"=>"asd", + "x_cc_header"=>"", + "message"=>"Received: from VMBX103.ihostexchange.net ([192.168.3.3]) by\r\n HUB103.ihostexchange.net ([66.46.182.53]) with mapi; Wed, 5 Oct 2011 17:12:44\r\n -0400\r\nFrom: SMS User <444444444444@tmomail.net>\r\nTo: Tracks <123123@cloudmailin.net>\r\nDate: Wed, 5 Oct 2011 17:12:43 -0400\r\nSubject: asd\r\nThread-Topic: asd\r\nThread-Index: AcyDo4aig2wghvcsTAOkleWqi4t/FQ==\r\nMessage-ID: <7D7CB176-7559-4997-A301-8DF9726264C7@tmomail.net>\r\nAccept-Language: de-DE, en-US\r\nContent-Language: en-US\r\nX-MS-Has-Attach:\r\nX-MS-TNEF-Correlator:\r\nacceptlanguage: de-DE, en-US\r\nContent-Type: text/plain; charset=\"us-ascii\"\r\nContent-Transfer-Encoding: quoted-printable\r\nMIME-Version: 1.0\r\n\r\nasdasd\r\n" + } + + assert_response 404 + end end end diff --git a/test/controllers/mailgun_controller_test.rb b/test/controllers/mailgun_controller_test.rb index 876cc9bd5..a0b7360ab 100644 --- a/test/controllers/mailgun_controller_test.rb +++ b/test/controllers/mailgun_controller_test.rb @@ -1,6 +1,8 @@ require 'test_helper' +require 'support/stub_site_config_helper' class MailgunControllerTest < ActionController::TestCase + include StubSiteConfigHelper def setup @user = users(:sms_user) @@ -12,55 +14,61 @@ def load_message(filename) end def test_mailgun_signature_verifies - SITE_CONFIG['mailgun_api_key'] = "123456789" - SITE_CONFIG['email_dispatch'] = 'from' + stub_site_config do + SITE_CONFIG['mailgun_api_key'] = "123456789" + SITE_CONFIG['email_dispatch'] = 'from' - post :mailgun, { - "timestamp" => "1379539674", - "token" => "5km6cwo0e3bfvg78hw4s69znro09xhk1h8u6-s633yasc8hcr5", - "signature" => "da92708b8f2c9dcd7ecdc91d52946c01802833e6683e46fc00b3f081920dd5b1", - "body-mime" => load_message('mailgun_message1.txt') - } + post :mailgun, { + "timestamp" => "1379539674", + "token" => "5km6cwo0e3bfvg78hw4s69znro09xhk1h8u6-s633yasc8hcr5", + "signature" => "da92708b8f2c9dcd7ecdc91d52946c01802833e6683e46fc00b3f081920dd5b1", + "body-mime" => load_message('mailgun_message1.txt') + } - assert_response :success + assert_response :success + end end def test_mailgun_creates_todo_with_mailmap - SITE_CONFIG['mailgun_api_key'] = "123456789" - SITE_CONFIG['email_dispatch'] = 'to' - SITE_CONFIG['mailmap'] = { - '5555555555@tmomail.net' => ['incoming@othermail.com', 'notused@foo.org'] - } + stub_site_config do + SITE_CONFIG['mailgun_api_key'] = "123456789" + SITE_CONFIG['email_dispatch'] = 'to' + SITE_CONFIG['mailmap'] = { + '5555555555@tmomail.net' => ['incoming@othermail.com', 'notused@foo.org'] + } - todo_count = Todo.count - post :mailgun, { - "timestamp" => "1379539674", - "token" => "5km6cwo0e3bfvg78hw4s69znro09xhk1h8u6-s633yasc8hcr5", - "signature" => "da92708b8f2c9dcd7ecdc91d52946c01802833e6683e46fc00b3f081920dd5b1", - "body-mime" => load_message('mailgun_message2.txt') - } + todo_count = Todo.count + post :mailgun, { + "timestamp" => "1379539674", + "token" => "5km6cwo0e3bfvg78hw4s69znro09xhk1h8u6-s633yasc8hcr5", + "signature" => "da92708b8f2c9dcd7ecdc91d52946c01802833e6683e46fc00b3f081920dd5b1", + "body-mime" => load_message('mailgun_message2.txt') + } - assert_response :success + assert_response :success - assert_equal(todo_count+1, Todo.count) - message_todo = Todo.where(:description => "test").first - assert_not_nil(message_todo) - assert_equal(@inbox, message_todo.context) - assert_equal(@user, message_todo.user) + assert_equal(todo_count+1, Todo.count) + message_todo = Todo.where(:description => "test").first + assert_not_nil(message_todo) + assert_equal(@inbox, message_todo.context) + assert_equal(@user, message_todo.user) + end end def test_mailgun_signature_fails - SITE_CONFIG['mailgun_api_key'] = "invalidkey" - SITE_CONFIG['email_dispatch'] = 'from' + stub_site_config do + SITE_CONFIG['mailgun_api_key'] = "invalidkey" + SITE_CONFIG['email_dispatch'] = 'from' - post :mailgun, { - "timestamp" => "1379539674", - "token" => "5km6cwo0e3bfvg78hw4s69znro09xhk1h8u6-s633yasc8hcr5", - "signature" => "da92708b8f2c9dcd7ecdc91d52946c01802833e6683e46fc00b3f081920dd5b1", - "body-mime" => load_message('mailgun_message1.txt') - } + post :mailgun, { + "timestamp" => "1379539674", + "token" => "5km6cwo0e3bfvg78hw4s69znro09xhk1h8u6-s633yasc8hcr5", + "signature" => "da92708b8f2c9dcd7ecdc91d52946c01802833e6683e46fc00b3f081920dd5b1", + "body-mime" => load_message('mailgun_message1.txt') + } - assert_response 406 + assert_response 406 + end end end diff --git a/test/integration/stories_test.rb b/test/integration/stories_test.rb index 471d4f093..1c6cbf79d 100644 --- a/test/integration/stories_test.rb +++ b/test/integration/stories_test.rb @@ -1,6 +1,8 @@ require 'test_helper' +require 'support/stub_site_config_helper' class StoriesTest < ActionDispatch::IntegrationTest + include StubSiteConfigHelper # #################################################### # Testing login and signup by different kinds of users @@ -14,23 +16,27 @@ def test_signup_new_user_by_admin end def test_signup_new_user_by_nonadmin - SITE_CONFIG['open_signups'] = false - other_user = new_session_as(:other_user,"sesame") - other_user.goes_to_signup_as_nonadmin + stub_site_config do + SITE_CONFIG['open_signups'] = false + other_user = new_session_as(:other_user,"sesame") + other_user.goes_to_signup_as_nonadmin + end end def test_open_signup_new_user - SITE_CONFIG['open_signups'] = true - get "/signup" - assert_response :success - assert_template "users/new" - post "/users", :user => {:login => "newbie", - :password => "newbiepass", - :password_confirmation => "newbiepass"} - assert_response :redirect - follow_redirect! - assert_response :success - assert_template "todos/index" + stub_site_config do + SITE_CONFIG['open_signups'] = true + get "/signup" + assert_response :success + assert_template "users/new" + post "/users", :user => {:login => "newbie", + :password => "newbiepass", + :password_confirmation => "newbiepass"} + assert_response :redirect + follow_redirect! + assert_response :success + assert_template "todos/index" + end end private diff --git a/test/support/stub_site_config_helper.rb b/test/support/stub_site_config_helper.rb new file mode 100644 index 000000000..ae3a27eb7 --- /dev/null +++ b/test/support/stub_site_config_helper.rb @@ -0,0 +1,9 @@ +require 'minitest/stub_const' + +module StubSiteConfigHelper + def stub_site_config + Object.stub_const(:SITE_CONFIG, SITE_CONFIG.clone) do + yield + end + end +end