From b8625d130d4c5a8137cc140b79bc69c3d7f45004 Mon Sep 17 00:00:00 2001 From: Jeffrey Warren Date: Thu, 7 Jun 2018 17:22:30 -0400 Subject: [PATCH] Rails 5.0 upgrade (#2726) (#2783) * Rails 5.0 upgrade (#2726) * Upgraded the .gitignore according to rails diff * Initial Gemfile update * Update README.md * Showing message at the top of upgrade page (#2713) * added an upgrade alert tag * Additional questions page tweak (#2721) * added the tag to determine which upgrade is listed on the website * changed regex back * added an upgrade alert tag * added the tag to determine which upgrade is listed on the website * changed regex back * added upgrade after pull and rebase master * Upgrade to Rails 5 * Uncommented composite_primary_key gem * Removed the dual occurence of rails_autolink * Update readme installation, fixes #2729 (#2730) Updates the readme to change the installation instructions, fixes #2729 * Commented activerecord-tableless * Draft display on Dashboard (#2666) * draft display on dashboard * moderator file view permitted * checking * fix * test fix * Added and modified few config files according to railsdiff.org * Removed mass_assignment_sanitizer * Removed composite primary key gem * Removed all attr_accessible in all models * Added composite_primary_key gem again * Downgraded rails and removed few attr_accessible commands * Added strong parameters to the controllers * Added strong parameters gem and also include params.require inside private methods * Added strongparameters.rb file to initializers folder * Removed unnecessary strong_parameter functions * Removed some errors * Changed test command temporarily in .travis.yml * Corrected config/puma.rb file with adding some assets * Added all the config.precompile files in one line * Removed error of problem in updating of user profile * Removed the error while creating a user * Removed error RecordNotFound: Couldn't find Node with 'nid'= * Removed some errors related to ids * Removed comment.reload in comment_controller_test * Track Dockerfiles accross instances. (#2593) * Track Dockerfiles accross instances. * Specify jessie as base * Add commands to build&deploy container with Makefile. (#2746) * Added Sample Cron Job to check working of Whenever Gem (#2715) * Added Sample Cron Job to test Whenever Gem * Added make targets for deployment and cron service start * Added make to image * Tweak Makefile * Fix cron starting command in Makefile * Trim whitespace * Explicitly set jessie as base container * Fixed codeclimate issues * Auto-set wiki slug (#2743) * Added keyword arguments to the tag_model.rb * changed the query statement in search method of node.rb * Force removal of pid file (see https://github.com/docker/compose/issues/1393) * Updated the tests due to change in arguments of search function in node.rb * Removed all the failures from tag_controller_test.rb * Changed the style of params in notes_controller_test.rb * Removed all depreciation warnings related to notes_controller * Removed all deprecation warnings related to image_controller and answers_controller * Removed all deprecation warnings of like_controller and fixed syntax error of answer_controller_test.rb * Removed all dep warnings of editor_controller and syntax error of like_controller_test.rb * removed all errors of answer_controller and some errors of tag_controller.rb * Removed all dep warnings of tag_controller_test.rb * Removed several dep warnings * Removed dep warnings of wiki_controller * Removed dep warnings of talk_controller * Removed dep warnings of legacy_controller_test.rb * Removed some warnings related to comment_controller * Removed the syntax errors * Removed two failures regarding application/xml+rss * Removed 2 failures due to wrong way of passing parameters in tests * Removed 2 failures * Fix params * Remove deprecations * Removed some dep warnings * Remove deprecations * Reverted to nothing => true * Reverted to nothing => true * Avoid rendering more than once in the same action * Removed all dep warnings related to user_tags_controller_test * Remove deprecation * Removed Dep warnings * Fix deprecation * Replace before_filter * Remove deprecation * Remove deprecation * Remove deprecation * Remove deprecation * Bump Ruby version to match Travis' * Simplify email regex to work with Ruby 2.4.1 * Changed the ruby version in Dockerfile * Remove deprecation * Remove deprecation * Removed the depreciation warning related to dynamic :controller and :action segment in routes * Changed the default ActiveRecord to ApplicationRecord in models * Clean Gemfile * Reverted to ['nid'] in tag_controller_test.rb * Changed the tests to rake test:all in .travis.yml * Minor spacing correction in .travis.yml * added a commit in application.js an application.css regarding the precompilation of files * Added more indentation * Small fixes * Separated the rails test and jasmine and coveralls task * Modified ['nid'] to ['node']['nid'] * Removed the extra puts in Rakefile * Changed the serial of tests * Added rake/testtask to Rakefile * Removed puma * Changed to ruby 2.4.1-jessie * Removed the whitelist_attributes command from config/application.rb * Removed two failures due to old usage of params * Fixed some new deprecation warnigs introduced --- .gitignore | 2 +- .travis.yml | 1 + Dockerfile | 2 +- Gemfile | 151 ++++----- Gemfile.lock | 298 +++++++++--------- Rakefile | 4 +- app/assets/javascripts/application.js | 3 + app/assets/stylesheets/application.css | 3 + app/controllers/admin_controller.rb | 3 +- app/controllers/answer_like_controller.rb | 2 +- app/controllers/answers_controller.rb | 4 +- app/controllers/application_controller.rb | 2 +- app/controllers/comment_controller.rb | 18 +- app/controllers/editor_controller.rb | 2 +- app/controllers/features_controller.rb | 2 +- app/controllers/home_controller.rb | 2 +- app/controllers/images_controller.rb | 2 +- app/controllers/like_controller.rb | 2 +- app/controllers/map_controller.rb | 2 +- app/controllers/notes_controller.rb | 10 +- app/controllers/relationships_controller.rb | 2 +- app/controllers/stats_controller.rb | 3 +- app/controllers/subscription_controller.rb | 2 +- app/controllers/tag_controller.rb | 3 +- app/controllers/users_controller.rb | 21 +- app/controllers/wiki_controller.rb | 4 +- app/models/answer.rb | 3 +- app/models/answer_selection.rb | 3 +- app/models/application_record.rb | 3 + app/models/comment.rb | 7 +- .../drupal_content_field_image_gallery.rb | 2 +- app/models/drupal_content_field_map_editor.rb | 2 +- app/models/drupal_content_field_mapper.rb | 2 +- app/models/drupal_content_type_map.rb | 2 +- app/models/drupal_file.rb | 2 +- app/models/drupal_main_image.rb | 2 +- app/models/drupal_profile_field.rb | 2 +- app/models/drupal_profile_value.rb | 3 +- app/models/drupal_upload.rb | 3 +- app/models/drupal_user.rb | 3 +- app/models/image.rb | 3 +- app/models/node.rb | 6 +- app/models/node_selection.rb | 3 +- app/models/node_tag.rb | 3 +- app/models/relationship.rb | 3 +- app/models/revision.rb | 3 +- app/models/spamaway.rb | 18 +- app/models/tableless.rb | 2 +- app/models/tag.rb | 5 +- app/models/tag_selection.rb | 3 +- app/models/user.rb | 5 +- app/models/user_selection.rb | 3 +- app/models/user_tag.rb | 3 +- app/services/search_service.rb | 23 +- app/services/typeahead_service.rb | 15 +- config.ru | 2 +- config/application.rb | 8 - config/boot.rb | 2 +- config/environment.rb | 2 +- config/environments/development.rb | 8 +- config/environments/production.rb | 8 +- config/environments/test.rb | 6 +- config/initializers/assets.rb | 1 + config/initializers/strong_parameters.rb | 1 + config/initializers/wrap_parameters.rb | 4 +- config/routes.rb | 14 +- db/seeds.rb | 2 - test/functional/admin_controller_test.rb | 64 ++-- .../functional/answer_like_controller_test.rb | 8 +- test/functional/answers_controller_test.rb | 32 +- test/functional/comment_controller_test.rb | 122 +++---- test/functional/editor_controller_test.rb | 16 + test/functional/features_controller_test.rb | 7 +- test/functional/home_controller_test.rb | 4 +- test/functional/images_controller_test.rb | 4 +- test/functional/legacy_controller_test.rb | 2 +- test/functional/like_controller_test.rb | 10 +- test/functional/map_controller_test.rb | 17 +- test/functional/notes_controller_test.rb | 132 +++++--- test/functional/questions_controller_test.rb | 49 ++- .../relationships_controller_test.rb | 10 +- test/functional/searches_controller_test.rb | 4 +- .../subscription_controller_test.rb | 4 +- test/functional/tag_controller_test.rb | 120 ++++--- test/functional/talk_controller_test.rb | 4 +- .../user_sessions_controller_test.rb | 27 +- test/functional/user_tags_controller_test.rb | 30 +- test/functional/users_controller_test.rb | 110 ++----- test/functional/wiki_controller_test.rb | 114 +++---- test/integration/I18n_test.rb | 229 +++++++++----- test/integration/login_flow_test.rb | 24 +- test/integration/moderate_and_ban_test.rb | 32 +- test/integration/node_insert_extras_test.rb | 5 +- test/integration/node_series_tag_test.rb | 12 +- test/integration/node_update_test.rb | 19 +- test/integration/public_pages_test.rb | 2 +- test/integration/revision_spam_test.rb | 16 +- test/integration/search_flow_test.rb | 6 + test/integration/token_comment_test.rb | 34 +- test/integration/wiki_creation_test.rb | 16 +- test/unit/node_test.rb | 10 +- test/unit/typeahead_service_test.rb | 4 +- 102 files changed, 991 insertions(+), 1053 deletions(-) create mode 100644 app/models/application_record.rb create mode 100644 config/initializers/assets.rb create mode 100644 config/initializers/strong_parameters.rb diff --git a/.gitignore b/.gitignore index 3ae51f51e1..f9efa92dac 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ # Ignore all logfiles and tempfiles. log/*.log log/* -tmp +/tmp/* data *.swp .DS_Store diff --git a/.travis.yml b/.travis.yml index c47bf3ac76..d1dd3aa88a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,7 @@ install: script: - docker-compose exec web bash -c "CI=TRUE GENERATE_REPORT=true rake test:all" + - docker-compose exec web bash -c "CI=TRUE GENERATE_REPORT=true rails test -d" - echo -e '' > output.xml - tail -n +2 -q ./test/reports/TEST*.xml >> output.xml - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then danger --verbose; fi' diff --git a/Dockerfile b/Dockerfile index b12319b461..e3cb2324b3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # Dockerfile # Plots2 # https://github.com/publiclab/plots2 -FROM ruby:2.3-jessie +FROM ruby:2.4.1-jessie LABEL maintainer="Sebastian Silva " LABEL description="This image deploys Plots2." diff --git a/Gemfile b/Gemfile index 64a56f0113..53c617b69e 100644 --- a/Gemfile +++ b/Gemfile @@ -1,20 +1,65 @@ source 'https://rubygems.org' +ruby '2.4.1' -gem 'rails', '~> 4.2.10' -ruby '2.3.7' +git_source(:github) do |repo_name| + repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") + "https://github.com/#{repo_name}.git" +end +gem 'rails', '5.0.6' gem 'activerecord-session_store' -gem 'protected_attributes' gem 'passenger' - -gem 'rails-i18n', '~> 4.0.0' -gem 'responders', '~> 2.0' # for Rails 4.2 - -gem 'turbolinks' gem 'sidekiq' - -# Whenever provides a clear syntax for writing and deploying cron jobs +gem 'rails-i18n', '~> 5.1.1' +gem 'responders', '~> 2.0' +gem 'turbolinks', '~> 5' gem 'whenever', require: false +gem 'unicode-emoji' +gem 'gemoji' +gem "composite_primary_keys" +gem 'jquery-rails' +gem 'rdiscount', '~> 2.2', '>= 2.2.0.1' +gem 'will_paginate', '>= 3.0.6' +gem 'will_paginate-bootstrap', '>= 1.0.1' +gem 'georuby', '2.0' +gem 'geokit-rails' +gem 'rails_autolink' +gem 'rb-readline' +gem "paperclip", "~> 5.2.0" +gem "ruby-openid", :require => "openid" +gem "rack-openid" +gem "authlogic", "4.1.0" +gem 'authlogic-oid' +gem "php-serialize", :require => "php_serialize" +gem 'less-rails', '~> 3.0' +gem 'progress_bar' +gem 'impressionist' +gem "recaptcha", require: "recaptcha/rails" +gem 'grape' +gem 'grape-entity' +gem 'grape-swagger', '~> 0.28.0' +gem 'grape-swagger-entity', '= 0.1.5' +gem 'grape-swagger-rails' +gem 'grape-swagger-ui' +gem 'rack-cors', :require => 'rack/cors' +gem 'mocha', '~> 1.1' +gem 'geocoder' +gem "i18n-js", ">= 3.0.0.rc11" +gem 'http_accept_language' +gem 'friendly_id' +gem 'jbuilder', '~> 2.5' +gem 'mustermann' , '1.0.2' +gem 'rails-dom-testing' +gem 'omniauth', '~> 1.3', '>= 1.3.1' +gem 'omniauth-facebook', '~> 3.0' +gem 'omniauth-google-oauth2' +gem 'omniauth-twitter' +gem 'omniauth-github', '~> 1.1', '>= 1.1.2' +gem 'figaro' +gem 'sanitize' +gem 'tzinfo-data', platforms: %i(mingw mswin x64_mingw jruby) +gem 'rails-controller-testing' + # To implement incoming mail processing microframework gem 'mailman', require: false @@ -28,39 +73,30 @@ group :mysql, :production do # mysql 0.4.3+ causes a version mismatch, apparently, and demands 'activerecord-mysql2-adapter' end -# ships with sqlite set up for easy setup during development -# run with `bundle install --without development` or `bundle install --without sqlite` to exclude this group :sqlite, :development do gem 'sqlite3' end -#group :postgresql do -# gem "activerecord-postgresql-adapter" -#end - -# Gems used only for assets and not required in production environments by default. -gem 'sass-rails', '~> 4.0.0' -gem 'coffee-rails', '~> 4.0.0' +gem 'sass-rails', '~> 5.0', '>= 5.0.7' +gem 'coffee-rails', '~> 4.2.2' gem 'execjs' # See https://github.com/sstephenson/execjs#readme for more supported runtimes gem 'therubyracer' gem 'uglifier', '>= 1.0.3' -# run with `bundle install --without development` to exclude these group :development do - gem 'web-console', '~> 2.0' + gem 'web-console', '>= 3.3.0' + gem 'listen', '~> 3.0.5' gem "letter_opener" gem "nifty-generators" - gem 'byebug' + gem 'byebug', platform: :mri gem 'rubocop', '~> 0.52.1', require: false end -# run with `bundle install --without test` to exclude these group :test, :development do gem 'test-unit' gem 'rails-perftest' gem 'minitest-reporters', '~> 1.1.19' - gem 'rake', '~> 10.5.0' - # gems to test RESTful API + gem 'rake', '~> 12.3.1' gem 'rest-client' gem 'rspec' gem 'json_expressions' @@ -72,71 +108,6 @@ group :test, :development do gem 'openssl', '~> 2.0.0.beta.1' end -# run with `bundle install --without production` to exclude these group :production do gem "scrypt", "~> 3" end - -gem 'unicode-emoji' -gem 'gemoji' - -gem "skylight" # performance tracking via skylight.io - -gem 'composite_primary_keys' -gem 'jquery-rails' -gem 'rdiscount', '~> 2.2', '>= 2.2.0.1' # Markdown -gem 'will_paginate', '>= 3.0.6' -gem 'will_paginate-bootstrap', '>= 1.0.1' -# could be deprecated: -gem 'georuby', '2.0' -gem 'geokit-rails' - -gem 'rails_autolink' -gem 'rb-readline' -gem "paperclip", "~> 5.2.0" -gem "ruby-openid", :require => "openid" -gem "rack-openid" -gem "authlogic", "~> 3.5.0" -gem 'authlogic-oid' -gem "php-serialize", :require => "php_serialize" -gem 'less-rails', '~> 2.6' -gem 'progress_bar' -gem 'impressionist' -gem "recaptcha", require: "recaptcha/rails" - -# RESTful API Support -gem 'grape' -gem 'grape-entity' -gem 'grape-swagger', '~> 0.25.3' # later versions require -gem 'grape-swagger-entity', '= 0.1.5' # Ruby 2.2 or later -gem 'grape-swagger-rails' -gem 'grape-swagger-ui' -gem 'rack-cors', :require => 'rack/cors' - -gem 'mocha', '~> 1.1' - -gem 'geocoder' -gem "i18n-js", ">= 3.0.0.rc11" -gem 'http_accept_language' - -# The default friendly_id version compatible with Rails 3 is v4.0 -gem 'friendly_id' -gem 'jbuilder' -#gem 'strong_parameters' - -# Pin mustermann to Ruby 2.1 compatible -gem 'mustermann' , '~> 0.4' - -#Gem for assertions used in testing -gem 'rails-dom-testing' -#OAuth Based login -gem 'omniauth', '~> 1.3', '>= 1.3.1' -gem 'omniauth-facebook', '~> 3.0' -gem 'omniauth-google-oauth2' -gem 'omniauth-twitter' -gem 'omniauth-github', '~> 1.1', '>= 1.1.2' - -#Gem for making tableless models -gem 'activerecord-tableless' -gem 'figaro' -gem 'sanitize' diff --git a/Gemfile.lock b/Gemfile.lock index 6132c3ea34..2179a31f45 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,56 +1,57 @@ GEM remote: https://rubygems.org/ specs: - actionmailer (4.2.10) - actionpack (= 4.2.10) - actionview (= 4.2.10) - activejob (= 4.2.10) + actioncable (5.0.6) + actionpack (= 5.0.6) + nio4r (>= 1.2, < 3.0) + websocket-driver (~> 0.6.1) + actionmailer (5.0.6) + actionpack (= 5.0.6) + actionview (= 5.0.6) + activejob (= 5.0.6) mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (4.2.10) - actionview (= 4.2.10) - activesupport (= 4.2.10) - rack (~> 1.6) - rack-test (~> 0.6.2) - rails-dom-testing (~> 1.0, >= 1.0.5) + rails-dom-testing (~> 2.0) + actionpack (5.0.6) + actionview (= 5.0.6) + activesupport (= 5.0.6) + rack (~> 2.0) + rack-test (~> 0.6.3) + rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (4.2.10) - activesupport (= 4.2.10) + actionview (5.0.6) + activesupport (= 5.0.6) builder (~> 3.1) erubis (~> 2.7.0) - rails-dom-testing (~> 1.0, >= 1.0.5) + rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (4.2.10) - activesupport (= 4.2.10) - globalid (>= 0.3.0) - activemodel (4.2.10) - activesupport (= 4.2.10) - builder (~> 3.1) - activerecord (4.2.10) - activemodel (= 4.2.10) - activesupport (= 4.2.10) - arel (~> 6.0) + activejob (5.0.6) + activesupport (= 5.0.6) + globalid (>= 0.3.6) + activemodel (5.0.6) + activesupport (= 5.0.6) + activerecord (5.0.6) + activemodel (= 5.0.6) + activesupport (= 5.0.6) + arel (~> 7.0) activerecord-session_store (1.1.1) actionpack (>= 4.0) activerecord (>= 4.0) multi_json (~> 1.11, >= 1.11.2) rack (>= 1.5.2, < 3) railties (>= 4.0) - activerecord-tableless (2.0.0) - activerecord (>= 3.0.0, < 5.0.0) - activesupport (4.2.10) + activesupport (5.0.6) + concurrent-ruby (~> 1.0, >= 1.0.2) i18n (~> 0.7) minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) addressable (2.5.2) public_suffix (>= 2.0.2, < 4.0) ansi (1.5.0) - arel (6.0.4) + arel (7.1.4) ast (2.4.0) - authlogic (3.5.0) - activerecord (>= 3.2, < 5.1) - activesupport (>= 3.2, < 5.1) + authlogic (4.1.0) + activerecord (>= 4.2, < 5.3) + activesupport (>= 4.2, < 5.3) request_store (~> 1.0) scrypt (>= 1.2, < 4.0) authlogic-oid (1.0.4) @@ -59,12 +60,9 @@ GEM descendants_tracker (~> 0.0.4) ice_nine (~> 0.11.0) thread_safe (~> 0.3, >= 0.3.1) - binding_of_caller (0.8.0) - debug_inspector (>= 0.0.1) + bindex (0.5.0) builder (3.2.3) byebug (10.0.2) - celluloid (0.16.0) - timers (~> 4.0.0) chronic (0.10.2) ci_reporter (2.0.0) builder (>= 2.1.2) @@ -76,16 +74,16 @@ GEM climate_control (>= 0.0.3, < 1.0) coercible (1.0.0) descendants_tracker (~> 0.0.1) - coffee-rails (4.0.1) + coffee-rails (4.2.2) coffee-script (>= 2.2.0) - railties (>= 4.0.0, < 5.0) + railties (>= 4.0.0) coffee-script (2.4.1) coffee-script-source execjs coffee-script-source (1.12.2) commonjs (0.2.7) - composite_primary_keys (8.1.6) - activerecord (~> 4.2.0) + composite_primary_keys (9.0.9) + activerecord (~> 5.0.0) concurrent-ruby (1.0.5) connection_pool (2.2.2) coveralls (0.8.21) @@ -94,51 +92,47 @@ GEM term-ansicolor (~> 1.3) thor (~> 0.19.4) tins (~> 1.6) - crass (1.0.3) - debug_inspector (0.0.3) + crass (1.0.4) descendants_tracker (0.0.4) thread_safe (~> 0.3, >= 0.3.1) diff-lcs (1.3) docile (1.1.5) - domain_name (0.5.20170404) + domain_name (0.5.20180417) unf (>= 0.0.5, < 1.0.0) equalizer (0.0.11) erubis (2.7.0) execjs (2.7.0) faraday (0.12.2) multipart-post (>= 1.2, < 3) - ffi (1.9.23) + ffi (1.9.25) ffi-compiler (1.0.1) ffi (>= 1.0.0) rake figaro (1.1.1) thor (~> 0.14) - friendly_id (5.2.3) + friendly_id (5.2.4) activerecord (>= 4.0.0) gemoji (3.0.0) - geocoder (1.4.7) - geokit (1.11.0) - geokit-rails (2.3.0) + geocoder (1.4.9) + geokit (1.12.0) + geokit-rails (2.3.1) geokit (~> 1.5) rails (>= 3.0) georuby (2.0.0) globalid (0.4.1) activesupport (>= 4.2.0) - grape (0.19.1) + grape (1.0.3) activesupport builder - hashie (>= 2.1.0) - multi_json (>= 1.3.2) - multi_xml (>= 0.5.2) - mustermann-grape (~> 0.4.0) + mustermann-grape (~> 1.0.0) rack (>= 1.3.0) rack-accept virtus (>= 1.0.0) grape-entity (0.7.1) activesupport (>= 4.0) multi_json (>= 1.3.2) - grape-swagger (0.25.3) - grape (>= 0.12.0) + grape-swagger (0.28.0) + grape (>= 0.16.2) grape-swagger-entity (0.1.5) grape-entity grape-swagger (>= 0.20.4) @@ -146,19 +140,18 @@ GEM railties (>= 3.2.12) grape-swagger-ui (2.2.8) railties (>= 3.1) + grease (0.3.1) hashie (3.5.7) highline (1.7.10) - hike (1.2.3) - hitimes (1.2.6) http-cookie (1.0.3) domain_name (~> 0.5) http_accept_language (2.1.1) i18n (0.9.5) concurrent-ruby (~> 1.0) - i18n-js (3.0.5) + i18n-js (3.0.8) i18n (>= 0.6.6, < 2) ice_nine (0.11.2) - impressionist (1.6.0) + impressionist (1.6.1) nokogiri (~> 1) jasmine-core (2.99.2) jasmine-jquery-rails (2.0.3) @@ -170,7 +163,7 @@ GEM jbuilder (2.7.0) activesupport (>= 4.2.0) multi_json (>= 1.2) - jquery-rails (4.3.1) + jquery-rails (4.3.3) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) @@ -181,31 +174,32 @@ GEM addressable (~> 2.3) less (2.6.0) commonjs (~> 0.2.7) - less-rails (2.8.0) + less-rails (3.0.0) actionpack (>= 4.0) + grease less (~> 2.6.0) sprockets (> 2, < 4) tilt letter_opener (1.6.0) launchy (~> 2.2) libv8 (3.16.14.19) - listen (2.10.1) - celluloid (~> 0.16.0) - rb-fsevent (>= 0.9.3) - rb-inotify (>= 0.9) + listen (3.0.8) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) loofah (2.2.2) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.0) mini_mime (>= 0.1.1) maildir (2.2.1) - mailman (0.7.3) + mailman (0.7.0) activesupport (>= 2.3.4) i18n (>= 0.4.1) - listen (~> 2.2) + listen (>= 0.4.1) mail (>= 2.0.3) maildir (>= 0.5.0) metaclass (0.0.4) + method_source (0.9.0) mime-types (3.1) mime-types-data (~> 3.2015) mime-types-data (3.2016.0521) @@ -218,18 +212,18 @@ GEM builder minitest (>= 5.0) ruby-progressbar - mocha (1.4.0) + mocha (1.5.0) metaclass (~> 0.0.1) multi_json (1.13.1) multi_xml (0.6.0) multipart-post (2.0.0) - mustermann (0.4.0) - tool (~> 0.2) - mustermann-grape (0.4.0) - mustermann (= 0.4.0) + mustermann (1.0.2) + mustermann-grape (1.0.0) + mustermann (~> 1.0.0) mysql2 (0.3.21) netrc (0.11.0) nifty-generators (0.4.6) + nio4r (2.3.1) nokogiri (1.8.2) mini_portile2 (~> 2.3.0) nokogumbo (1.5.0) @@ -271,9 +265,9 @@ GEM mime-types mimemagic (~> 0.3.0) parallel (1.12.1) - parser (2.5.0.5) + parser (2.5.1.0) ast (~> 2.4.0) - passenger (5.2.3) + passenger (5.3.1) rack rake (>= 0.8.1) phantomjs (2.1.1.0) @@ -283,10 +277,8 @@ GEM progress_bar (1.2.0) highline (~> 1.6) options (~> 2.3.0) - protected_attributes (1.1.4) - activemodel (>= 4.0.1, < 5.0) public_suffix (3.0.2) - rack (1.6.9) + rack (2.0.5) rack-accept (0.4.5) rack (>= 0.4) rack-cors (1.0.2) @@ -297,44 +289,47 @@ GEM rack rack-test (0.6.3) rack (>= 1.0) - rails (4.2.10) - actionmailer (= 4.2.10) - actionpack (= 4.2.10) - actionview (= 4.2.10) - activejob (= 4.2.10) - activemodel (= 4.2.10) - activerecord (= 4.2.10) - activesupport (= 4.2.10) - bundler (>= 1.3.0, < 2.0) - railties (= 4.2.10) - sprockets-rails - rails-deprecated_sanitizer (1.0.3) - activesupport (>= 4.2.0.alpha) - rails-dom-testing (1.0.9) - activesupport (>= 4.2.0, < 5.0) - nokogiri (~> 1.6) - rails-deprecated_sanitizer (>= 1.0.1) + rails (5.0.6) + actioncable (= 5.0.6) + actionmailer (= 5.0.6) + actionpack (= 5.0.6) + actionview (= 5.0.6) + activejob (= 5.0.6) + activemodel (= 5.0.6) + activerecord (= 5.0.6) + activesupport (= 5.0.6) + bundler (>= 1.3.0) + railties (= 5.0.6) + sprockets-rails (>= 2.0.0) + rails-controller-testing (1.0.2) + actionpack (~> 5.x, >= 5.0.1) + actionview (~> 5.x, >= 5.0.1) + activesupport (~> 5.x) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) rails-html-sanitizer (1.0.4) loofah (~> 2.2, >= 2.2.2) - rails-i18n (4.0.9) - i18n (~> 0.7) - railties (~> 4.0) + rails-i18n (5.1.1) + i18n (>= 0.7, < 2) + railties (>= 5.0, < 6) rails-perftest (0.0.7) rails_autolink (1.1.6) rails (> 3.1) - railties (4.2.10) - actionpack (= 4.2.10) - activesupport (= 4.2.10) + railties (5.0.6) + actionpack (= 5.0.6) + activesupport (= 5.0.6) + method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rainbow (3.0.0) - rake (10.5.0) + rake (12.3.1) rb-fsevent (0.10.3) rb-inotify (0.9.10) ffi (>= 0.5.0, < 2) rb-readline (0.5.5) rdiscount (2.2.0.1) - recaptcha (4.7.0) + recaptcha (4.8.0) json redis (4.0.1) ref (2.0.0) @@ -371,16 +366,21 @@ GEM unicode-display_width (~> 1.0, >= 1.0.1) ruby-openid (2.7.0) ruby-progressbar (1.9.0) - sanitize (4.6.4) + sanitize (4.6.5) crass (~> 1.0.2) nokogiri (>= 1.4.4) nokogumbo (~> 1.4) - sass (3.2.19) - sass-rails (4.0.5) - railties (>= 4.0.0, < 5.0) - sass (~> 3.2.2) - sprockets (~> 2.8, < 3.0) - sprockets-rails (~> 2.0) + sass (3.5.6) + sass-listen (~> 4.0.0) + sass-listen (4.0.0) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + sass-rails (5.0.7) + railties (>= 4.0.0, < 6) + sass (~> 3.1) + sprockets (>= 2.8, < 4.0) + sprockets-rails (>= 2.0, < 4.0) + tilt (>= 1.1, < 3) scrypt (3.0.5) ffi-compiler (>= 1.0, < 2.0) sidekiq (5.1.3) @@ -393,57 +393,51 @@ GEM json (>= 1.8, < 3) simplecov-html (~> 0.10.0) simplecov-html (0.10.2) - skylight (2.0.2) - skylight-core (= 2.0.2) - skylight-core (2.0.2) - activesupport (>= 4.2.0) - sprockets (2.12.4) - 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.7.1) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.2.1) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) sqlite3 (1.3.13) term-ansicolor (1.6.0) tins (~> 1.0) - test-unit (3.2.7) + test-unit (3.2.8) power_assert therubyracer (0.12.3) libv8 (~> 3.16.14.15) ref thor (0.19.4) thread_safe (0.3.6) - tilt (1.4.1) + tilt (2.0.8) timecop (0.9.1) - timers (4.0.4) - hitimes tins (1.16.3) - tool (0.2.3) - turbolinks (5.1.0) + turbolinks (5.1.1) turbolinks-source (~> 5.1) turbolinks-source (5.1.0) tzinfo (1.2.5) thread_safe (~> 0.1) - uglifier (4.1.8) + uglifier (4.1.11) execjs (>= 0.3.0, < 3) unf (0.1.4) unf_ext unf_ext (0.0.7.5) - unicode-display_width (1.3.0) - unicode-emoji (1.0.0) + unicode-display_width (1.4.0) + unicode-emoji (1.1.0) virtus (1.0.5) axiom-types (~> 0.1) coercible (~> 1.0) descendants_tracker (~> 0.0, >= 0.0.3) equalizer (~> 0.0, >= 0.0.9) - web-console (2.3.0) - activemodel (>= 4.0) - binding_of_caller (>= 0.7.2) - railties (>= 4.0) - sprockets-rails (>= 2.0, < 4.0) + web-console (3.6.2) + actionview (>= 5.0) + activemodel (>= 5.0) + bindex (>= 0.4.0) + railties (>= 5.0) + websocket-driver (0.6.5) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.3) whenever (0.10.0) chronic (>= 0.6.3) will_paginate (3.1.6) @@ -455,12 +449,11 @@ PLATFORMS DEPENDENCIES activerecord-session_store - activerecord-tableless - authlogic (~> 3.5.0) + authlogic (= 4.1.0) authlogic-oid byebug ci_reporter_test_unit - coffee-rails (~> 4.0.0) + coffee-rails (~> 4.2.2) composite_primary_keys coveralls execjs @@ -472,7 +465,7 @@ DEPENDENCIES georuby (= 2.0) grape grape-entity - grape-swagger (~> 0.25.3) + grape-swagger (~> 0.28.0) grape-swagger-entity (= 0.1.5) grape-swagger-rails grape-swagger-ui @@ -481,15 +474,16 @@ DEPENDENCIES impressionist jasmine-jquery-rails jasmine-rails - jbuilder + jbuilder (~> 2.5) jquery-rails json_expressions - less-rails (~> 2.6) + less-rails (~> 3.0) letter_opener + listen (~> 3.0.5) mailman minitest-reporters (~> 1.1.19) mocha (~> 1.1) - mustermann (~> 0.4) + mustermann (= 1.0.2) mysql2 (~> 0.3.20) nifty-generators omniauth (~> 1.3, >= 1.3.1) @@ -502,15 +496,15 @@ DEPENDENCIES passenger php-serialize progress_bar - protected_attributes rack-cors rack-openid - rails (~> 4.2.10) + rails (= 5.0.6) + rails-controller-testing rails-dom-testing - rails-i18n (~> 4.0.0) + rails-i18n (~> 5.1.1) rails-perftest rails_autolink - rake (~> 10.5.0) + rake (~> 12.3.1) rb-readline rdiscount (~> 2.2, >= 2.2.0.1) recaptcha @@ -521,24 +515,24 @@ DEPENDENCIES rubocop (~> 0.52.1) ruby-openid sanitize - sass-rails (~> 4.0.0) + sass-rails (~> 5.0, >= 5.0.7) scrypt (~> 3) sidekiq - skylight sqlite3 test-unit therubyracer timecop - turbolinks + turbolinks (~> 5) + tzinfo-data uglifier (>= 1.0.3) unicode-emoji - web-console (~> 2.0) + web-console (>= 3.3.0) whenever will_paginate (>= 3.0.6) will_paginate-bootstrap (>= 1.0.1) RUBY VERSION - ruby 2.3.7p456 + ruby 2.4.1p111 BUNDLED WITH 1.16.2 diff --git a/Rakefile b/Rakefile index 721c1f788a..02795c1784 100644 --- a/Rakefile +++ b/Rakefile @@ -3,11 +3,11 @@ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require File.expand_path('../config/application', __FILE__) +require 'rake/testtask' Plots2::Application.load_tasks Rake::Task['test:run'].clear -Rake::Task['test:all'].clear namespace :test do @@ -26,8 +26,6 @@ namespace :test do require 'ci/reporter/rake/test_unit' Rake::Task["ci:setup:testunit"].execute end - puts "Running Rails tests" - Rake::Task["test:run"].execute puts "Running jasmine tests headlessly" Rake::Task["spec:javascript"].execute Rake::Task["coveralls:push"].execute diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 474b6e153a..7d08ac2406 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -6,6 +6,9 @@ // // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the // the compiled file. +// +//If there are other assets (which are not in this file) that are being precompiled by +//'javascript_include_tag' command in views, then add them on /config/initializers/assets.rb // // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD // GO AFTER THE REQUIRES BELOW. diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 4c4f0ef42c..205218de54 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -8,6 +8,9 @@ * You're free to add application-wide styles to this file and they'll appear at the top of the * compiled file, but it's generally better to create a new file per style scope. * + * If there are other assets (which are not in this file) that are being precompiled by + * 'stylesheet_link_tag' command in views, then add them on /config/initializers/assets.rb + *= require bootstrap/dist/css/bootstrap.min.css *= require bootstrap-datepicker/dist/css/bootstrap-datepicker3.css diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 4b86c6c255..7be9fd1a43 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -1,5 +1,6 @@ class AdminController < ApplicationController - before_filter :require_user, only: %i(spam spam_revisions mark_comment_spam publish_comment) + before_action :require_user, only: %i(spam spam_revisions mark_comment_spam publish_comment) + def promote_admin @user = User.find params[:id] diff --git a/app/controllers/answer_like_controller.rb b/app/controllers/answer_like_controller.rb index e7f3564d05..92b277f37b 100644 --- a/app/controllers/answer_like_controller.rb +++ b/app/controllers/answer_like_controller.rb @@ -1,5 +1,5 @@ class AnswerLikeController < ApplicationController - before_filter :require_user, only: :likes + before_action :require_user, only: :likes def show render json: Answer.find(params[:id]).cached_likes diff --git a/app/controllers/answers_controller.rb b/app/controllers/answers_controller.rb index c63361ad4b..425740df30 100644 --- a/app/controllers/answers_controller.rb +++ b/app/controllers/answers_controller.rb @@ -1,5 +1,5 @@ class AnswersController < ApplicationController - before_filter :require_user + before_action :require_user def create @node = Node.find(params[:nid]) @@ -72,7 +72,7 @@ def accept format.js end else - render text: "Answer couldn't be accepted" + render plain: "Answer couldn't be accepted" end end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 88109bf750..547d905abf 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,7 +5,7 @@ class ApplicationController < ActionController::Base helper_method :current_user_session, :current_user, :prompt_login, :sidebar - before_filter :set_locale + before_action :set_locale private diff --git a/app/controllers/comment_controller.rb b/app/controllers/comment_controller.rb index f0dad35a61..0a95f7b1ae 100644 --- a/app/controllers/comment_controller.rb +++ b/app/controllers/comment_controller.rb @@ -2,7 +2,7 @@ class CommentController < ApplicationController include CommentHelper respond_to :html, :xml, :json - before_filter :require_user, only: %i(create update make_answer delete) + before_action :require_user, only: %i(create update make_answer delete) def index @comments = Comment.paginate(page: params[:page], per_page: 30) @@ -28,8 +28,8 @@ def create if request.xhr? render partial: 'notes/comment', locals: { comment: @comment } else - tagnames = @node.tagnames.map do |tagname| - "#{ tagname }" + tagnames = @node.tagnames.map do |tagname| + "#{tagname}" end tagnames = tagnames.join(', ') tagnames = " Click to subscribe to updates on these tags or topics: " + tagnames unless tagnames.empty? @@ -41,7 +41,7 @@ def create end rescue CommentError flash[:error] = 'The comment could not be saved.' - render text: 'failure' + render plain: 'failure' end end @@ -58,16 +58,16 @@ def create_by_token # used in here because the module was `include`d right at the beginning @comment = create_comment(@node, @user, @body) respond_to do |format| - format.all { render :nothing => true, :status => :created } + format.all { head :created } end rescue CommentError respond_to do |format| - format.all { render :nothing => true, :status => :bad_request } + format.all { head :bad_request } end end else respond_to do |format| - format.all { render :nothing => true, :status => :unauthorized } + format.all { head :unauthorized } end end end @@ -88,7 +88,7 @@ def answer_create end else flash[:error] = 'The comment could not be saved.' - render text: 'failure' + render plain: 'failure' end end @@ -131,7 +131,7 @@ def delete else format.html do if request.xhr? - render text: 'success' + render plain: 'success' else flash[:notice] = 'Comment deleted.' redirect_to '/' + @node.path diff --git a/app/controllers/editor_controller.rb b/app/controllers/editor_controller.rb index a34070a044..5c59012a7e 100644 --- a/app/controllers/editor_controller.rb +++ b/app/controllers/editor_controller.rb @@ -1,5 +1,5 @@ class EditorController < ApplicationController - before_filter :require_user, only: %i(post rich legacy editor) + before_action :require_user, only: %i(post rich legacy editor) # main image via URL passed as GET param def legacy diff --git a/app/controllers/features_controller.rb b/app/controllers/features_controller.rb index 4f12b21717..118e2f6e39 100644 --- a/app/controllers/features_controller.rb +++ b/app/controllers/features_controller.rb @@ -1,5 +1,5 @@ class FeaturesController < ApplicationController - before_filter :require_user, except: [:embed] + before_action :require_user, except: [:embed] def index @features = Node.where(type: 'feature') diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index eb9bd3f1d7..b1b7c4542d 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,5 +1,5 @@ class HomeController < ApplicationController - before_filter :require_user, only: %i(subscriptions nearby) + before_action :require_user, only: %i(subscriptions nearby) # caches_action :index, :cache_path => proc { |c| # node = Node.find :last #c.params[:id] diff --git a/app/controllers/images_controller.rb b/app/controllers/images_controller.rb index 9fb288b0f7..79dbeb3d9a 100644 --- a/app/controllers/images_controller.rb +++ b/app/controllers/images_controller.rb @@ -2,7 +2,7 @@ class ImagesController < ApplicationController respond_to :html, :xml, :json - before_filter :require_user, only: %i(create new update delete) + before_action :require_user, only: %i(create new update delete) def shortlink params[:size] = params[:size] || :large diff --git a/app/controllers/like_controller.rb b/app/controllers/like_controller.rb index f489b2162b..6b8cf55eda 100644 --- a/app/controllers/like_controller.rb +++ b/app/controllers/like_controller.rb @@ -1,6 +1,6 @@ class LikeController < ApplicationController respond_to :html, :xml, :json - before_filter :require_user, only: %i(create delete) + before_action :require_user, only: %i(create delete) #list all recent likes def index diff --git a/app/controllers/map_controller.rb b/app/controllers/map_controller.rb index 7ce4924fda..019419910e 100644 --- a/app/controllers/map_controller.rb +++ b/app/controllers/map_controller.rb @@ -8,7 +8,7 @@ def index # I'm not sure if this is actually eager loading the tags... @maps = Node.joins(:tag) .where('type = "map" AND status = 1 AND (term_data.name LIKE ? OR term_data.name LIKE ?)', 'lat:%', 'lon:%') - .uniq + .distinct # This is supposed to eager load the url_aliases, and seems to run, but doesn't actually eager load them...? # @maps = Node.select("node.*,url_alias.dst AS dst").joins(:tag).where('type = "map" AND status = 1 AND (term_data.name LIKE ? OR term_data.name LIKE ?)', 'lat:%', 'lon:%').joins("INNER JOIN url_alias ON url_alias.src = CONCAT('node/',node.nid)") diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index b26b7cfde9..0d22fd82f9 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -1,6 +1,6 @@ class NotesController < ApplicationController respond_to :html - before_filter :require_user, only: %i(create edit update delete rsvp publish_draft) + before_action :require_user, only: %i(create edit update delete rsvp publish_draft) def index @title = I18n.t('notes_controller.research_notes') @@ -40,7 +40,7 @@ def shortlink # display a revision, raw def raw response.headers['Content-Type'] = 'text/plain; charset=utf-8' - render text: Node.find(params[:id]).latest.body + render plain: Node.find(params[:id]).latest.body end def show @@ -146,7 +146,7 @@ def create redirect_to @node.path(:question) else if request.xhr? # rich editor! - render text: @node.path + render plain: @node.path else redirect_to @node.path end @@ -259,7 +259,7 @@ def delete respond_with do |format| format.html do if request.xhr? - render text: I18n.t('notes_controller.content_deleted') + render plain: I18n.t('notes_controller.content_deleted') else flash[:notice] = I18n.t('notes_controller.content_deleted') redirect_to '/dashboard' + '?_=' + Time.now.to_i.to_s @@ -399,4 +399,4 @@ def publish_draft redirect_to '/' end end -end \ No newline at end of file +end diff --git a/app/controllers/relationships_controller.rb b/app/controllers/relationships_controller.rb index 949954dcec..f357c75d5a 100644 --- a/app/controllers/relationships_controller.rb +++ b/app/controllers/relationships_controller.rb @@ -1,5 +1,5 @@ class RelationshipsController < ApplicationController - before_filter :require_user + before_action :require_user def create user = User.find(params[:followed_id]) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 50085f6970..74d739daba 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -5,7 +5,7 @@ def subscriptions @tags[tag.tagname] = @tags[tag.tagname] || 0 @tags[tag.tagname] += 1 end - render text: @tags.inspect, status: 200 + render plain: @tags.inspect, status: 200 end def range @@ -70,7 +70,6 @@ def index @graph_wikis = Node.contribution_graph_making('page', 52, @time).to_a.to_json @graph_comments = Comment.contribution_graph_making(52, @time).to_a.to_json - users = [] nids = [] Node.where(type: 'note', status: 1).each do |note| diff --git a/app/controllers/subscription_controller.rb b/app/controllers/subscription_controller.rb index 01c321c1a8..9cb34bce46 100644 --- a/app/controllers/subscription_controller.rb +++ b/app/controllers/subscription_controller.rb @@ -5,7 +5,7 @@ class SubscriptionController < ApplicationController respond_to :html, :xml, :json - before_filter :require_user, :only => [:create, :delete, :index, :digest] + before_action :require_user, :only => [:create, :delete, :index, :digest] def index @title = "Subscriptions" diff --git a/app/controllers/tag_controller.rb b/app/controllers/tag_controller.rb index 1365c6edc9..b1910d6586 100644 --- a/app/controllers/tag_controller.rb +++ b/app/controllers/tag_controller.rb @@ -1,6 +1,7 @@ class TagController < ApplicationController respond_to :html, :xml, :json, :ics - before_filter :require_user, only: %i(create delete) + before_action :require_user, only: %i(create delete) + def index if params[:sort] diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index b7b9dd20d8..4d3001739f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,6 +1,6 @@ class UsersController < ApplicationController - before_filter :require_no_user, :only => [:new] - before_filter :require_user, :only => [:edit, :update] + before_action :require_no_user, :only => [:new] + before_action :require_user, :only => [:edit, :update] before_action :set_user, only: [:info, :followed, :following, :followers] def new @@ -10,11 +10,11 @@ def new end def create - @user = User.new(params[:user]) + @user = User.new(user_params) @user.status = 1 using_recaptcha = !params[:spamaway] && Rails.env == "production" recaptcha = verify_recaptcha(model: @user) if using_recaptcha - @spamaway = Spamaway.new(params[:spamaway]) unless using_recaptcha + @spamaway = Spamaway.new(spamaway_params) unless using_recaptcha if ((@spamaway&.valid?) || recaptcha) && @user.save({}) if current_user.crypted_password.nil? # the user has not created a pwd in the new site flash[:warning] = I18n.t('users_controller.account_migrated_create_new_password') @@ -42,7 +42,7 @@ def create def update # login required, see before filter @user = current_user - @user.attributes = params[:user] + @user.attributes = user_params @user.save({}) do |result| if result if session[:openid_return_to] # for openid login, redirects back to openid auth process @@ -51,7 +51,7 @@ def update # login required, see before filter redirect_to return_to else flash[:notice] = I18n.t('users_controller.successful_updated_profile')+""+I18n.t('users_controller.return_dashboard')+" »" - redirect_to "/profile/"+@user.username + return redirect_to "/profile/"+@user.username end else render :template => 'users/edit' @@ -307,4 +307,13 @@ def test_digest_email def set_user @user = User.find_by(username: params[:id]) end + private + def user_params + params.require(:user).permit(:username, :email, :password, :password_confirmation, :openid_identifier, :key, :photo, :photo_file_name, :bio, :status) + end + def spamaway_params + params.require(:spamaway).permit(:follow_instructions, :statement1, :statement2, :statement3, :statement4) + end end + + diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 9078fc2920..f0415ff191 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -1,7 +1,7 @@ require 'rss' class WikiController < ApplicationController - before_filter :require_user, only: %i(new create edit update delete replace) + before_action :require_user, only: %i(new create edit update delete replace) def subdomain url = "//#{request.host}/wiki/" @@ -92,7 +92,7 @@ def show # display a revision, raw def raw response.headers['Content-Type'] = 'text/plain; charset=utf-8' - render text: Revision.find(params[:id]).body + render plain: Revision.find(params[:id]).body end def edit diff --git a/app/models/answer.rb b/app/models/answer.rb index df14c93561..3fb58ac806 100644 --- a/app/models/answer.rb +++ b/app/models/answer.rb @@ -1,7 +1,6 @@ -class Answer < ActiveRecord::Base +class Answer < ApplicationRecord include NodeShared, CommentsShared # common methods for node-like and comment-like models - attr_accessible :uid, :nid, :content, :cached_likes, :created_at, :updated_at belongs_to :node, foreign_key: 'nid' belongs_to :drupal_user, foreign_key: 'uid' diff --git a/app/models/answer_selection.rb b/app/models/answer_selection.rb index ad6340be05..a86e8d1705 100644 --- a/app/models/answer_selection.rb +++ b/app/models/answer_selection.rb @@ -1,5 +1,4 @@ -class AnswerSelection < ActiveRecord::Base - attr_accessible :liking, :following, :user_id, :aid +class AnswerSelection < ApplicationRecord belongs_to :answer, foreign_key: :aid, dependent: :destroy belongs_to :drupal_user, foreign_key: :user_id diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 0000000000..863c094db6 --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/app/models/comment.rb b/app/models/comment.rb index 06c4b3f20b..5a369b0e1d 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,9 +1,6 @@ -class Comment < ActiveRecord::Base +class Comment < ApplicationRecord include CommentsShared # common methods for comment-like models - attr_accessible :pid, :nid, :uid, :aid, - :subject, :hostname, :comment, - :status, :format, :thread, :timestamp, :comment_via, :message_id belongs_to :node, foreign_key: 'nid', touch: true, counter_cache: true # dependent: :destroy, counter_cache: true @@ -116,7 +113,7 @@ def thread_participants; end def mentioned_users usernames = comment.scan(Callouts.const_get(:FINDER)) - User.where(username: usernames.map { |m| m[1] }).uniq + User.where(username: usernames.map { |m| m[1] }).distinct end def followers_of_mentioned_tags diff --git a/app/models/drupal_content_field_image_gallery.rb b/app/models/drupal_content_field_image_gallery.rb index eda0d43192..088f4aab81 100644 --- a/app/models/drupal_content_field_image_gallery.rb +++ b/app/models/drupal_content_field_image_gallery.rb @@ -1,6 +1,6 @@ require 'php_serialize' -class DrupalContentFieldImageGallery < ActiveRecord::Base +class DrupalContentFieldImageGallery < ApplicationRecord self.table_name = 'content_field_image_gallery' self.primary_keys = :vid, :nid diff --git a/app/models/drupal_content_field_map_editor.rb b/app/models/drupal_content_field_map_editor.rb index b54e7882ea..08fd79e77a 100644 --- a/app/models/drupal_content_field_map_editor.rb +++ b/app/models/drupal_content_field_map_editor.rb @@ -1,4 +1,4 @@ -class DrupalContentFieldMapEditor < ActiveRecord::Base +class DrupalContentFieldMapEditor < ApplicationRecord self.table_name = 'content_field_map_editor' self.primary_key = 'vid' diff --git a/app/models/drupal_content_field_mapper.rb b/app/models/drupal_content_field_mapper.rb index ca94861151..7dcf3478ac 100644 --- a/app/models/drupal_content_field_mapper.rb +++ b/app/models/drupal_content_field_mapper.rb @@ -1,4 +1,4 @@ -class DrupalContentFieldMapper < ActiveRecord::Base +class DrupalContentFieldMapper < ApplicationRecord self.table_name = 'content_field_mappers' self.primary_key = 'vid' diff --git a/app/models/drupal_content_type_map.rb b/app/models/drupal_content_type_map.rb index 73a9887692..8e4330f3db 100644 --- a/app/models/drupal_content_type_map.rb +++ b/app/models/drupal_content_type_map.rb @@ -1,4 +1,4 @@ -class DrupalContentTypeMap < ActiveRecord::Base +class DrupalContentTypeMap < ApplicationRecord self.table_name = 'content_type_map' self.primary_key = 'vid' diff --git a/app/models/drupal_file.rb b/app/models/drupal_file.rb index 55905e5267..d8e1e1a6ef 100644 --- a/app/models/drupal_file.rb +++ b/app/models/drupal_file.rb @@ -1,4 +1,4 @@ -class DrupalFile < ActiveRecord::Base +class DrupalFile < ApplicationRecord self.table_name = 'files' self.primary_key = 'fid' diff --git a/app/models/drupal_main_image.rb b/app/models/drupal_main_image.rb index 107170829f..e6faf17071 100644 --- a/app/models/drupal_main_image.rb +++ b/app/models/drupal_main_image.rb @@ -1,4 +1,4 @@ -class DrupalMainImage < ActiveRecord::Base +class DrupalMainImage < ApplicationRecord self.table_name = 'content_field_main_image' self.primary_key = :nid diff --git a/app/models/drupal_profile_field.rb b/app/models/drupal_profile_field.rb index ca53842cf9..87e372bb28 100644 --- a/app/models/drupal_profile_field.rb +++ b/app/models/drupal_profile_field.rb @@ -1,4 +1,4 @@ -class DrupalProfileField < ActiveRecord::Base +class DrupalProfileField < ApplicationRecord self.table_name = 'profile_fields' has_many :drupal_profile_values, foreign_key: 'fid' diff --git a/app/models/drupal_profile_value.rb b/app/models/drupal_profile_value.rb index c2bb1abfcb..e6f3765b47 100644 --- a/app/models/drupal_profile_value.rb +++ b/app/models/drupal_profile_value.rb @@ -1,5 +1,4 @@ -class DrupalProfileValue < ActiveRecord::Base - attr_accessible :bio, :fid, :uid +class DrupalProfileValue < ApplicationRecord self.table_name = 'profile_values' self.primary_key = 'uid' diff --git a/app/models/drupal_upload.rb b/app/models/drupal_upload.rb index 902e7fc7da..ab5ab8aafe 100644 --- a/app/models/drupal_upload.rb +++ b/app/models/drupal_upload.rb @@ -1,5 +1,4 @@ -class DrupalUpload < ActiveRecord::Base - attr_accessible :vid, :nid, :fid +class DrupalUpload < ApplicationRecord self.table_name = 'upload' belongs_to :node, foreign_key: 'nid', dependent: :destroy belongs_to :drupal_file, foreign_key: 'fid' diff --git a/app/models/drupal_user.rb b/app/models/drupal_user.rb index c1e76380f3..80323aaf70 100644 --- a/app/models/drupal_user.rb +++ b/app/models/drupal_user.rb @@ -1,5 +1,4 @@ -class DrupalUser < ActiveRecord::Base - attr_accessible :title, :body, :name, :pass, :mail, :mode, :sort, :threshold, :theme, :signature, :signature_format, :created, :access, :login, :status, :timezone, :language, :picture, :init, :data, :timezone_id, :timezone_name +class DrupalUser < ApplicationRecord ## User status can be: # 0: banned diff --git a/app/models/image.rb b/app/models/image.rb index b7ecef4320..8be4ea4700 100644 --- a/app/models/image.rb +++ b/app/models/image.rb @@ -1,7 +1,6 @@ require 'open-uri' -class Image < ActiveRecord::Base - attr_accessible :uid, :notes, :title, :photo, :nid, :remote_url +class Image < ApplicationRecord # has_many :comments, :dependent => :destroy # has_many :likes, :dependent => :destroy diff --git a/app/models/node.rb b/app/models/node.rb index 2ab7a527a3..3c14fe08ac 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -21,11 +21,10 @@ def validate(record) class Node < ActiveRecord::Base include NodeShared # common methods for node-like models - attr_accessible :title, :uid, :status, :type, :vid, :cached_likes, :comment, :path, :slug, :views self.table_name = 'node' self.primary_key = 'nid' - def self.search(query, order = :default) + def self.search(query:, order: :default, limit:) orderParam = {changed: :desc} if order == :default orderParam = {cached_likes: :desc} if order == :likes orderParam = {views: :desc} if order == :views @@ -44,7 +43,8 @@ def self.search(query, order = :default) end else nodes = Node.limit(limit) - .where('title LIKE ?', '%' + input + '%', status: 1) + .where('title LIKE ?', '%' + query + '%') + .where(status: 1) .order(orderParam) end end diff --git a/app/models/node_selection.rb b/app/models/node_selection.rb index bb0ed71d4c..abf94048d2 100644 --- a/app/models/node_selection.rb +++ b/app/models/node_selection.rb @@ -1,5 +1,4 @@ -class NodeSelection < ActiveRecord::Base - attr_accessible :following, :liking +class NodeSelection < ApplicationRecord self.primary_keys = :user_id, :nid # belongs_to :user belongs_to :node, foreign_key: :nid diff --git a/app/models/node_tag.rb b/app/models/node_tag.rb index 19fc7f051a..47c933c512 100644 --- a/app/models/node_tag.rb +++ b/app/models/node_tag.rb @@ -1,5 +1,4 @@ -class NodeTag < ActiveRecord::Base - attr_accessible :nid, :tid, :uid, :date +class NodeTag < ApplicationRecord self.table_name = 'community_tags' self.primary_keys = :tid, :nid belongs_to :node, foreign_key: 'nid' diff --git a/app/models/relationship.rb b/app/models/relationship.rb index 94a915f8b2..063df27351 100644 --- a/app/models/relationship.rb +++ b/app/models/relationship.rb @@ -1,5 +1,4 @@ -class Relationship < ActiveRecord::Base - attr_accessible :followed_id, :follower_id +class Relationship < ApplicationRecord belongs_to :follower, class_name: 'User' belongs_to :followed, class_name: 'User' validates :followed_id, presence: true diff --git a/app/models/revision.rb b/app/models/revision.rb index 8ec762bfa4..05745b1b33 100644 --- a/app/models/revision.rb +++ b/app/models/revision.rb @@ -1,6 +1,5 @@ -class Revision < ActiveRecord::Base +class Revision < ApplicationRecord - attr_accessible :title, :body, :nid, :uid, :teaser, :log, :timestamp, :format self.table_name = 'node_revisions' self.primary_key = 'vid' diff --git a/app/models/spamaway.rb b/app/models/spamaway.rb index b3d20a4abc..5827cd949a 100644 --- a/app/models/spamaway.rb +++ b/app/models/spamaway.rb @@ -1,19 +1,23 @@ -class Spamaway < ActiveRecord::Base +class Spamaway + include ActiveModel::Model + # This helper will generate pairs of human/robot statements and return # them alongside random strings. # There is no actual data in the database. - has_no_table + def self.columns() @columns ||= []; end + + def self.column(name, sql_type = nil, default = nil, null = true) + columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null) + end + column :follow_instructions, :string column :statement1, :string column :statement2, :string column :statement3, :string column :statement4, :string - attr_accessible :follow_instructions, - :statement1, - :statement2, - :statement3, - :statement4 + attr_accessor :follow_instructions, :statement1, :statement2, :statement3, :statement4 + validate :clean_honeypot, :human_responses diff --git a/app/models/tableless.rb b/app/models/tableless.rb index 592c391023..437a952fef 100644 --- a/app/models/tableless.rb +++ b/app/models/tableless.rb @@ -1,7 +1,7 @@ # http://stackoverflow.com/questions/937429/activerecordbase-without-table # Models without Tables -class Tableless < ActiveRecord::Base +class Tableless < ApplicationRecord def self.columns @columns ||= [] end diff --git a/app/models/tag.rb b/app/models/tag.rb index 0079bebfd9..1e08070750 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -1,5 +1,4 @@ -class Tag < ActiveRecord::Base - attr_accessible :vid, :name, :description, :weight +class Tag < ApplicationRecord self.table_name = 'term_data' self.primary_key = 'tid' @@ -72,7 +71,7 @@ def self.contributor_count(tagname) end # finds highest viewcount nodes - def self.find_top_nodes_by_type(tagname, type = 'wiki', limit = 10) + def self.find_top_nodes_by_type(tagname:, type: 'wiki', limit: 10) Node.where(type: type) .where('term_data.name = ?', tagname) .order('node.views DESC') diff --git a/app/models/tag_selection.rb b/app/models/tag_selection.rb index f47728ab97..fa7bdde6e8 100644 --- a/app/models/tag_selection.rb +++ b/app/models/tag_selection.rb @@ -1,5 +1,4 @@ -class TagSelection < ActiveRecord::Base - attr_accessible :following +class TagSelection < ApplicationRecord self.primary_keys = :user_id, :tid belongs_to :tag, foreign_key: :tid has_many :node_tags, foreign_key: :tid diff --git a/app/models/user.rb b/app/models/user.rb index 30ddd6ae7f..617ee8f5e2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -8,12 +8,11 @@ def validate(record) class User < ActiveRecord::Base self.table_name = 'rusers' - attr_accessible :username, :email, :password, :password_confirmation, :openid_identifier, :key, :photo, :photo_file_name, :bio, :status alias_attribute :name, :username acts_as_authentic do |c| c.openid_required_fields = %i(nickname email) - VALID_EMAIL_REGEX = /\A[-[:alnum:]+.]+@[[:alnum:]-.]+[.][[:alpha:]]+\z/ + VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i c.validates_format_of_email_field_options = { with: VALID_EMAIL_REGEX } c.crypto_provider = Authlogic::CryptoProviders::Sha512 end @@ -374,7 +373,7 @@ def content_followed_in_period(start_time, end_time) .references(:node_revision) .where("(created >= #{start_time.to_i} AND created <= #{end_time.to_i}) OR (timestamp >= #{start_time.to_i} AND timestamp <= #{end_time.to_i})") .order('node_revisions.timestamp DESC') - .uniq + .distinct end def social_link(site) diff --git a/app/models/user_selection.rb b/app/models/user_selection.rb index f64167d32d..b6d748d180 100644 --- a/app/models/user_selection.rb +++ b/app/models/user_selection.rb @@ -1,5 +1,4 @@ -class UserSelection < ActiveRecord::Base - attr_accessible :following +class UserSelection < ApplicationRecord self.primary_keys = :self_id, :other_id belongs_to :user, foreign_key: 'self_id' belongs_to :other, class_name: :User, foreign_key: 'other_id' diff --git a/app/models/user_tag.rb b/app/models/user_tag.rb index b76dfd1949..9b95ff872c 100644 --- a/app/models/user_tag.rb +++ b/app/models/user_tag.rb @@ -1,5 +1,4 @@ -class UserTag < ActiveRecord::Base - attr_accessible :uid, :value +class UserTag < ApplicationRecord belongs_to :user, foreign_key: :uid validates :value, presence: :true diff --git a/app/services/search_service.rb b/app/services/search_service.rb index 995b486cdf..861e50002b 100644 --- a/app/services/search_service.rb +++ b/app/services/search_service.rb @@ -233,29 +233,28 @@ def nearbyNodes(srchString) #GET X number of latest people/contributors # X = srchString - def recentPeople(srchString, tagName = nil) + def recentPeople(_srchString, tagName = nil) sresult = DocList.new - nodes = Node.all.order("changed DESC").limit(100).uniq + nodes = Node.all.order("changed DESC").limit(100).distinct users = [] nodes.each do |node| if node.author.status != 0 - unless tagName.blank? - users << node.author.user if node.author.user.has_tag(tagName) - else + if tagName.blank? users << node.author.user + else + users << node.author.user if node.author.user.has_tag(tagName) end end end users = users.uniq users.each do |user| - if user.has_power_tag("lat") && user.has_power_tag("lon") - blurred = false - if user.has_power_tag("location") - blurred = user.get_value_of_power_tag("location") - end - doc = DocResult.fromLocationSearch(user.id, 'people_coordinates', user.path , user.username , 0 , 0 , user.lat , user.lon , blurred) - sresult.addDoc(doc) + next unless user.has_power_tag("lat") && user.has_power_tag("lon") + blurred = false + if user.has_power_tag("location") + blurred = user.get_value_of_power_tag("location") end + doc = DocResult.fromLocationSearch(user.id, 'people_coordinates', user.path, user.username, 0, 0, user.lat, user.lon, blurred) + sresult.addDoc(doc) end sresult end diff --git a/app/services/typeahead_service.rb b/app/services/typeahead_service.rb index 9e20d53943..bd970f90aa 100644 --- a/app/services/typeahead_service.rb +++ b/app/services/typeahead_service.rb @@ -47,30 +47,29 @@ def comments(input, limit = 5) end # default order is recency - def nodes(input, limit = 5, order = :default) - Node.search(input, order) + def nodes(input, _limit = 5, order = :default) + Node.search(query: input, order: order, limit: 5) .group(:nid) .where('node.status': 1) - .limit(limit) end def notes(input, limit = 5, order = :default) - self.nodes(input, limit, order) + nodes(input, limit, order) .where("node.type": "note") end def wikis(input, limit = 5, order = :default) - self.nodes(input, limit, order) + nodes(input, limit, order) .where("node.type": "page") end def maps(input, limit = 5, order = :default) - self.nodes(input, limit, order) + nodes(input, limit, order) .where("node.type": "map") end def questions(input, limit = 5, order = :default) - self.nodes(input, limit, order) + nodes(input, limit, order) .where('node.type': 'note') .joins(:tag) .where('term_data.name LIKE ?', 'question:%') @@ -126,7 +125,7 @@ def search_profiles(search_string, limit = 5) def search_notes(search_string, limit = 5) sresult = TagList.new unless search_string.nil? || search_string.blank? - notes(search_string, limit).uniq.each do |match| + notes(search_string, limit).distinct.each do |match| tval = TagResult.new tval.tagId = match.nid tval.tagVal = match.title diff --git a/config.ru b/config.ru index eb80e3c6fb..917a8013f3 100644 --- a/config.ru +++ b/config.ru @@ -1,4 +1,4 @@ # This file is used by Rack-based servers to start the application. -require ::File.expand_path('../config/environment', __FILE__) +require_relative 'config/environment' run Plots2::Application diff --git a/config/application.rb b/config/application.rb index bddbc1e442..e782266acc 100644 --- a/config/application.rb +++ b/config/application.rb @@ -50,11 +50,6 @@ class Application < Rails::Application # like if you have constraints or database-specific column types # config.active_record.schema_format = :sql - # Enforce whitelist mode for mass assignment. - # This will create an empty whitelist of attributes available for mass-assignment for all models - # in your app. As such, your models will need to explicitly whitelist or blacklist accessible - # parameters by using an attr_accessible or attr_protected declaration. - config.active_record.whitelist_attributes = true config.active_job.queue_adapter = :sidekiq # Enable the asset pipeline @@ -105,8 +100,5 @@ class Application < Rails::Application config.paths.add File.join('app','api'), glob: File.join('**', '*.rb') config.autoload_paths += Dir[Rails.root.join('app', 'api', '*')] - # Allow mass assignments - config.active_record.whitelist_attributes = false - config.active_record.raise_in_transactional_callbacks = true end end diff --git a/config/boot.rb b/config/boot.rb index f2830ae316..24efefdb2e 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,6 +1,6 @@ require 'rubygems' # Set up gems listed in the Gemfile. -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) diff --git a/config/environment.rb b/config/environment.rb index 60770e143b..a7879e0c45 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,5 @@ # Load the rails application -require File.expand_path('../application', __FILE__) +require_relative 'application' # Initialize the rails application Plots2::Application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb index abc7c8e03e..b694c75033 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -11,21 +11,19 @@ # Log error messages when you accidentally call methods on nil. config.whiny_nils = true - # Show full error reports and disable caching - config.consider_all_requests_local = true - config.action_controller.perform_caching = false + # Show full error reports. + config.consider_all_requests_local = true # Don't care if the mailer can't send config.action_mailer.raise_delivery_errors = false + # Print deprecation notices to the Rails logger config.active_support.deprecation = :log # Only use best-standards-support built into browsers config.action_dispatch.best_standards_support = :builtin - # Raise exception on mass assignment protection for Active Record models - config.active_record.mass_assignment_sanitizer = :strict # Do not compress assets config.assets.compress = false diff --git a/config/environments/production.rb b/config/environments/production.rb index bc715c3663..d03192bc84 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -41,7 +41,7 @@ config.log_level = :info # Prepend all log lines with the following tags - # config.log_tags = [ :subdomain, :uuid ] + config.log_tags = [ :request_id ] # Use a different logger for distributed setups # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) @@ -49,8 +49,10 @@ # Use a different cache store in production # 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" + # Use a real queuing backend for Active Job (and separate queues per environment) + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "railsdiff_#{Rails.env}" + config.action_mailer.perform_caching = false # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) # config.assets.precompile += %w( search.js ) diff --git a/config/environments/test.rb b/config/environments/test.rb index 5fc714b4c1..ffe5a2457d 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -11,8 +11,8 @@ config.eager_load = false # Configure static asset server for tests with Cache-Control for performance - config.serve_static_files = true - config.static_cache_control = "public, max-age=3600" + config.public_file_server.enabled = true + config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' } # Show full error reports and disable caching config.consider_all_requests_local = true @@ -30,8 +30,6 @@ config.action_mailer.delivery_method = :test config.action_mailer.raise_delivery_errors = false - # Raise exception on mass assignment protection for Active Record models - config.active_record.mass_assignment_sanitizer = :strict # Print deprecation notices to the stderr config.active_support.deprecation = :stderr diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb new file mode 100644 index 0000000000..36de885db2 --- /dev/null +++ b/config/initializers/assets.rb @@ -0,0 +1 @@ +Rails.application.config.assets.precompile += %w( print.css I18n.css sidebar.js dashboard.css dashboard.js dragdrop.js methods.js post.js comment_expand.js leaflet-blurred-location/dist/Leaflet.BlurredLocation.js dynamic_search.js notes.js textbox_expand.js question.js ) diff --git a/config/initializers/strong_parameters.rb b/config/initializers/strong_parameters.rb new file mode 100644 index 0000000000..394c1f5fd4 --- /dev/null +++ b/config/initializers/strong_parameters.rb @@ -0,0 +1 @@ +ActiveRecord::Base.send(:include, ActiveModel::ForbiddenAttributesProtection) diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb index 007c0deff4..655abdca19 100644 --- a/config/initializers/wrap_parameters.rb +++ b/config/initializers/wrap_parameters.rb @@ -5,10 +5,10 @@ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do - wrap_parameters format: [:json] if respond_to?(:wrap_parameters) + wrap_parameters format: [:json] end # To enable root element in JSON for ActiveRecord objects. ActiveSupport.on_load(:active_record) do - self.include_root_in_json = false + self.include_root_in_json = true end diff --git a/config/routes.rb b/config/routes.rb index 9c29f9a37c..1c2835a4ef 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -36,6 +36,7 @@ get 'login' => "user_sessions#new", :as => :login get 'logout' => "user_sessions#destroy", :as => :logout get 'logoutRemotely' => 'user_sessions#logout_remotely' + get 'users' => 'users#index' post 'register' => 'users#create' get 'reset' => 'users#reset' post 'reset' => 'users#reset' @@ -112,9 +113,14 @@ get 'n/:id' => 'notes#shortlink' get 'i/:id' => 'images#shortlink' get 'p/:id' => 'users#shortlink' + get 'notes' => 'notes#index' get 'notes/raw/:id' => 'notes#raw' get 'notes/popular' => 'notes#popular' get 'notes/liked' => 'notes#liked' + get 'notes/image/:id' => 'notes#image' + post 'notes/delete/:id' => 'notes#delete' + post 'notes/update/:id' => 'notes#update' + post 'notes/update/:id' => 'notes#edit' post 'notes/create' => 'notes#create' get 'notes/publish_draft/:id' => 'notes#publish_draft' @@ -211,6 +217,7 @@ delete 'map/delete/:id' => 'map#delete' get 'map/:name/:date' => 'map#show' get 'archive' => 'map#index' + get 'stats/range' => 'stats#range' get 'stats' => 'stats#index' get 'stats/range/:start/:end' => 'stats#range' get 'stats/subscriptions' => 'stats#subscriptions' @@ -238,11 +245,14 @@ get 'admin/migrate/:id' => 'admin#migrate' get 'admin/moderate/:id' => 'admin#moderate' get 'admin/unmoderate/:id' => 'admin#unmoderate' + get 'admin/publish_comment/:id' => 'admin#publish_comment' + post 'admin/mark_comment_spam/:id' => 'admin#mark_comment_spam' get 'post' => 'editor#post' post 'post' => 'editor#post' get 'legacy' => 'editor#legacy' get 'editor' => 'editor#editor' + get 'editor/rich/(:n)' => 'editor#rich' post 'images/create' => 'images#create' put 'note/add' => 'legacy#note_add' put 'page/add' => 'legacy#page_add' @@ -272,8 +282,11 @@ get 'comment/answer_create/:aid' => 'comment#answer_create' + get 'comment/delete/:id' => 'comment#delete' + post 'comment/update/:id' => 'comment#update' post 'comment/make_answer/:id' => 'comment#make_answer' post '/comment/like' => 'comment#like_comment' + post 'comment/create/:id' => 'comment#create' # Sample resource route (maps HTTP verbs to controller actions automatically): # resources :products @@ -324,5 +337,4 @@ match '/auth/:provider/callback', to: 'user_sessions#create', via: [:get, :post] get 'auth/failure', to: redirect('/') - match ':controller(/:action(/:id))(.:format)', via: [:get, :post] end diff --git a/db/seeds.rb b/db/seeds.rb index b8057b6294..9007410b43 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -54,14 +54,12 @@ 35.times do |t| map_node = Node.create! "type"=>"map", "title"=>"test map #{t}", "uid"=>1, "status"=>1 - Revision.attr_accessible :nid, :vid map_node_revision = Revision.create! "nid" => map_node.nid, "vid" => map_node.nid, "uid"=>1, "title"=>"Test Map #{t}", "body"=>"Body of revision #{t}" tag_lat = Tag.create! name: "lat:#{rand * 80}", description: "Desc #{t}", weight: 5 tag_lon = Tag.create! name: "lon:#{rand * 80}", description: "Desc #{t}", weight: 5 drupal_comm_tag_lat = NodeTag.create! nid: map_node.nid, tid: tag_lat.tid, uid: 1 drupal_comm_tag_lon = NodeTag.create! nid: map_node.nid, tid: tag_lon.tid, uid: 1 - DrupalContentTypeMap.attr_accessible :nid, :vid, :field_publication_date_value, :field_capture_date_value, :field_tms_url_value, :field_license_value, :field_raw_images_value, :field_cartographer_notes_value, :field_notes_value, :field_zoom_min_value, :field_zoom_max_value, :authorship content_type_mape = DrupalContentTypeMap.create! "vid"=>map_node.nid, "nid"=>map_node.nid, "field_publication_date_value"=>Time.now.to_s(:short), "field_capture_date_value"=>Time.now.to_s(:short), diff --git a/test/functional/admin_controller_test.rb b/test/functional/admin_controller_test.rb index b26e5f6747..8a43c1daba 100644 --- a/test/functional/admin_controller_test.rb +++ b/test/functional/admin_controller_test.rb @@ -29,7 +29,7 @@ def teardown test 'admin should promote user role to admin' do UserSession.create(users(:jeff)) user = users(:bob) - get :promote_admin, id: user.id + get :promote_admin, params: { id: user.id } assert_equal "User '#{user.username}' is now an admin.", flash[:notice] assert_redirected_to '/profile/' + user.username + '?_=' + Time.now.to_i.to_s end @@ -37,7 +37,7 @@ def teardown test 'admin should promote user role to moderator' do UserSession.create(users(:jeff)) user = users(:bob) - get :promote_moderator, id: user.id + get :promote_moderator, params: { id: user.id } assert_equal "User '#{user.username}' is now a moderator.", flash[:notice] assert_redirected_to '/profile/' + user.username + '?_=' + Time.now.to_i.to_s end @@ -45,7 +45,7 @@ def teardown test 'moderator should promote user role to moderator' do UserSession.create(users(:moderator)) user = users(:jeff) - get :promote_moderator, id: user.id + get :promote_moderator, params: { id: user.id } assert_equal "User '#{user.username}' is now a moderator.", flash[:notice] assert_redirected_to '/profile/' + user.username + '?_=' + Time.now.to_i.to_s end @@ -53,7 +53,7 @@ def teardown test 'user should not promote other user role to moderator' do UserSession.create(users(:bob)) user = users(:jeff) - get :promote_moderator, id: user.id + get :promote_moderator, params: { id: user.id } assert_equal 'Only moderators can promote other users.', flash[:error] assert_redirected_to '/profile/' + user.username + '?_=' + Time.now.to_i.to_s end @@ -61,7 +61,7 @@ def teardown test 'user should not promote other user role to admin' do UserSession.create(users(:bob)) user = users(:moderator) - get :promote_admin, id: user.id + get :promote_admin, params: { id: user.id } assert_equal 'Only admins can promote other users to admins.', flash[:error] assert_redirected_to '/profile/' + user.username + '?_=' + Time.now.to_i.to_s end @@ -69,7 +69,7 @@ def teardown test 'admin should demote moderator role to basic' do UserSession.create(users(:admin)) user = users(:moderator) - get :demote_basic, id: user.id + get :demote_basic, params: { id: user.id } assert_equal "User '#{user.username}' is no longer a moderator.", flash[:notice] assert_redirected_to '/profile/' + user.username + '?_=' + Time.now.to_i.to_s end @@ -77,7 +77,7 @@ def teardown test 'user should not demote other moderator role to basic' do UserSession.create(users(:bob)) user = users(:moderator) - get :demote_basic, id: user.id + get :demote_basic, params: { id: user.id } assert_equal 'Only admins and moderators can demote other users.', flash[:error] assert_redirected_to '/profile/' + user.username + '?_=' + Time.now.to_i.to_s end @@ -85,7 +85,7 @@ def teardown test 'admin should be able to force reset user password' do UserSession.create(users(:admin)) user = users(:bob) - get :reset_user_password, id: user.id, email: user.email + get :reset_user_password, params: { id: user.id, email: user.email } #Testing whether email has been sent or not email = ActionMailer::Base.deliveries.last @@ -134,7 +134,7 @@ def teardown UserSession.create(users(:bob)) UserSession.find.destroy - get :mark_spam, id: nodes(:one).id + get :mark_spam, params: { id: nodes(:one).id } assert_equal 'Only moderators can moderate posts.', flash[:error] node = assigns(:node) @@ -145,7 +145,7 @@ def teardown test 'normal user should not be able to mark a node as spam' do UserSession.create(users(:bob)) - get :mark_spam, id: nodes(:one).id + get :mark_spam, params: { id: nodes(:one).id } assert_equal 'Only moderators can moderate posts.', flash[:error] node = assigns(:node) @@ -157,7 +157,7 @@ def teardown UserSession.create(users(:moderator)) node = nodes(:spam).publish - get :mark_spam, id: node.id + get :mark_spam, params: { id: node.id } assert_equal "Item marked as spam and author banned. You can undo this on the spam moderation page.", flash[:notice] node = assigns(:node) @@ -177,7 +177,7 @@ def teardown UserSession.create(users(:admin)) node = nodes(:spam).publish - get :mark_spam, id: node.id + get :mark_spam, params: { id: node.id } user = users(:moderator) email = AdminMailer.notify_moderators_of_spam(node, user) assert_emails 1 do @@ -201,7 +201,7 @@ def teardown UserSession.create(users(:admin)) assert_equal 0, nodes(:spam).status - get :mark_spam, id: nodes(:spam).id + get :mark_spam, params: { id: nodes(:spam).id } assert_equal "Item already marked as spam and author banned. You can undo this on the spam moderation page.", flash[:notice] assert_equal 0, nodes(:spam).status @@ -211,7 +211,7 @@ def teardown test 'normal user should not be able to unspam a note' do UserSession.create(users(:bob)) - get :publish, id: nodes(:spam).id + get :publish, params: { id: nodes(:spam).id } assert_equal 'Only moderators can publish posts.', flash[:error] assert_equal 0, nodes(:spam).status @@ -224,7 +224,7 @@ def teardown assert_equal 4, node.status ActionMailer::Base.deliveries.clear - get :publish, id: nodes(:first_timer_note).id + get :publish, params: { id: nodes(:first_timer_note).id } assert_equal "Post approved and published after #{time_ago_in_words(node.created_at)} in moderation. Now reach out to the new community member; thank them, just say hello, or help them revise/format their post in the comments.", flash[:notice] node = assigns(:node) @@ -257,7 +257,7 @@ def teardown node = nodes(:one) assert_equal 1, node.status - get :publish, id: node.id + get :publish, params: { id: node.id } assert_equal 'Item already published.', flash[:notice] assert_equal 1, node.status @@ -269,7 +269,7 @@ def teardown node = nodes(:spam) assert_equal 0, node.status - get :publish, id: node.id + get :publish, params: { id: node.id } assert_equal 'Item published.', flash[:notice] node = assigns(:node) @@ -281,7 +281,7 @@ def teardown test 'admin user should be able to unspam a note' do UserSession.create(users(:admin)) - get :publish, id: nodes(:spam).id + get :publish, params: { id: nodes(:spam).id } assert_equal 'Item published.', flash[:notice] node = assigns(:node) @@ -332,7 +332,7 @@ def teardown revision = revisions(:unmoderated_spam_revision) assert_equal nodes(:spam_targeted_page).latest.vid, revision.vid - get :mark_spam_revision, vid: revision.vid + get :mark_spam_revision, params: { vid: revision.vid } assert_equal "Item marked as spam and author banned. You can undo this on the spam moderation page.", flash[:notice] revision = assigns(:revision) @@ -349,7 +349,7 @@ def teardown revision.spam assert_not_equal nodes(:spam_targeted_page).latest.vid, revision.vid - get :publish_revision, vid: revision.vid + get :publish_revision, params: { vid: revision.vid } assert_equal 'Item published.', flash[:notice] revision = assigns(:revision) @@ -364,7 +364,7 @@ def teardown node = nodes(:first_timer_note) ActionMailer::Base.deliveries.clear - get :mark_spam, id: node.id + get :mark_spam, params: { id: node.id } assert_equal "Item marked as spam and author banned. You can undo this on the spam moderation page.", flash[:notice] @@ -400,7 +400,7 @@ def teardown user = users(:moderator) assert_equal 4, node.status - get :publish, id: nodes(:first_timer_question).id + get :publish, params: { id: nodes(:first_timer_question).id } assert_emails 3 do AdminMailer.notify_author_of_approval(node, user).deliver_now AdminMailer.notify_moderators_of_approval(node, user).deliver_now @@ -418,7 +418,7 @@ def teardown UserSession.create(users(:moderator)) comment = comments(:first) - post :mark_comment_spam, id: comment.id + post :mark_comment_spam, params: { id: comment.id } comment = assigns(:comment) assert_equal 0, comment.status @@ -430,7 +430,7 @@ def teardown UserSession.create(users(:admin)) comment = comments(:first) - post :mark_comment_spam, id: comment.id + post :mark_comment_spam, params: { id: comment.id } comment = assigns(:comment) assert_equal 0, comment.status @@ -441,7 +441,7 @@ def teardown test 'should not mark comment as spam if no user' do comment = comments(:first) - post :mark_comment_spam, id: comment.id + post :mark_comment_spam, params: { id: comment.id } assert_redirected_to '/login' end @@ -450,7 +450,7 @@ def teardown UserSession.create(users(:bob)) comment = comments(:first) - post :mark_comment_spam, id: comment.id + post :mark_comment_spam, params: { id: comment.id } comment = assigns(:comment) assert_equal 1, comment.status @@ -462,7 +462,7 @@ def teardown UserSession.create(users(:admin)) comment = comments(:spam_comment) - post :mark_comment_spam, id: comment.id + post :mark_comment_spam, params: { id: comment.id } comment = assigns(:comment) assert_equal 0, comment.status @@ -474,7 +474,7 @@ def teardown UserSession.create(users(:admin)) comment = comments(:spam_comment) node = comment.node - post :publish_comment, id: comment.id + post :publish_comment, params: { id: comment.id } comment = assigns(:comment) assert_equal 1, comment.status @@ -486,7 +486,7 @@ def teardown UserSession.create(users(:moderator)) comment = comments(:spam_comment) node = comment.node - post :publish_comment, id: comment.id + post :publish_comment, params: { id: comment.id } comment = assigns(:comment) assert_equal 1, comment.status @@ -497,7 +497,7 @@ def teardown test 'should login if want to publish comment from spam' do comment = comments(:spam_comment) - post :publish_comment, id: comment.id + post :publish_comment, params: { id: comment.id } assert_equal 0, comment.status assert_redirected_to '/login' @@ -508,7 +508,7 @@ def teardown comment = comments(:spam_comment) node = comment.node - post :publish_comment, id: comment.id + post :publish_comment, params: { id: comment.id } assert_equal 0, comment.status assert_equal "Only moderators can publish comments.", flash[:error] @@ -520,7 +520,7 @@ def teardown comment = comments(:first) node = comment.node - post :publish_comment, id: comment.id + post :publish_comment, params: { id: comment.id } assert_equal 1, comment.status assert_equal "Comment already published.", flash[:notice] diff --git a/test/functional/answer_like_controller_test.rb b/test/functional/answer_like_controller_test.rb index 3bcf39c967..87c35d7e5c 100644 --- a/test/functional/answer_like_controller_test.rb +++ b/test/functional/answer_like_controller_test.rb @@ -7,14 +7,14 @@ def setup test 'should get show' do answer = answers(:one) - get :show, id: answer.id + get :show, params: { id: answer.id } assert_response :success end test 'should get likes' do UserSession.create(users(:admin)) answer = answers(:one) - xhr :get, :likes, aid: answer.id + get :likes, params: { aid: answer.id }, xhr: true assert_response :success assert_not_nil assigns(:answer) end @@ -23,7 +23,7 @@ def setup UserSession.create(users(:admin)) answer = answers(:one) assert_difference 'answer.cached_likes' do - xhr :get, :likes, aid: answer.id + get :likes, params: { aid: answer.id }, xhr: true answer.reload end end @@ -32,7 +32,7 @@ def setup UserSession.create(users(:bob)) answer = answers(:one) assert_difference 'answer.cached_likes', -1 do - xhr :get, :likes, aid: answer.id + get :likes, params: { aid: answer.id }, xhr: true answer.reload end end diff --git a/test/functional/answers_controller_test.rb b/test/functional/answers_controller_test.rb index 867a4f4029..f61cb3eb3e 100644 --- a/test/functional/answers_controller_test.rb +++ b/test/functional/answers_controller_test.rb @@ -10,9 +10,7 @@ def setup node = nodes(:question) initial_mail_count = ActionMailer::Base.deliveries.size assert_difference 'Answer.count' do - xhr :post, :create, - nid: node.nid, - body: 'Sample answer' + post :create, params: { nid: node.nid, body: 'Sample answer'}, xhr: true end assert_not_equal initial_mail_count, ActionMailer::Base.deliveries.size assert ActionMailer::Base.deliveries.collect(&:to).include?([node.author.mail]) @@ -32,9 +30,7 @@ def setup node = nodes(:question) initial_mail_count = ActionMailer::Base.deliveries.size assert_difference 'Answer.count' do - xhr :post, :create, - nid: node.nid, - body: 'Sample answer by the current user' + post :create, params: { nid: node.nid, body: 'Sample answer by the current user'}, xhr: true end user_with_everything_tag = users(:moderator) @@ -46,8 +42,7 @@ def setup test 'should get update if user is logged in' do UserSession.create(users(:bob)) answer = answers(:one) - get :update, id: answer.id, - body: 'Some changes in answer' + get :update, params: { id: answer.id, body: 'Some changes in answer' } assert_redirected_to answer.node.path(:question) assert_equal 'Answer updated', flash[:notice] end @@ -55,8 +50,7 @@ def setup test 'should show error if user is not the author of post' do UserSession.create(users(:jeff)) answer = answers(:one) - get :update, id: answer.id, - body: 'Some changes' + get :update, params: { id: answer.id, body: 'Some changes' } assert_redirected_to answer.node.path(:question) assert_equal 'Only the author of the answer can edit it.', flash[:error] end @@ -65,7 +59,7 @@ def setup UserSession.create(users(:jeff)) answer = answers(:one) assert_difference 'Answer.count', -1 do - xhr :get, :delete, id: answer.id + get :delete, params: { id: answer.id }, xhr: true end assert_response :success end @@ -74,7 +68,7 @@ def setup UserSession.create(users(:bob)) answer = answers(:one) assert_difference 'Answer.count', -1 do - xhr :get, :delete, id: answer.id + get :delete, params: { id: answer.id }, xhr: true end assert_response :success end @@ -83,7 +77,7 @@ def setup UserSession.create(users(:admin)) answer = answers(:one) assert_difference 'Answer.count', -1 do - xhr :get, :delete, id: answer.id + get :delete, params: { id: answer.id }, xhr: true end assert_response :success end @@ -92,7 +86,7 @@ def setup UserSession.create(users(:moderator)) answer = answers(:one) assert_difference 'Answer.count', -1 do - xhr :get, :delete, id: answer.id + get :delete, params: { id: answer.id }, xhr: true end assert_response :success end @@ -101,7 +95,7 @@ def setup UserSession.create(users(:newcomer)) answer = answers(:one) assert_no_difference 'Answer.count' do - xhr :get, :delete, id: answer.id + get :delete, params: { id: answer.id }, xhr: true end assert_redirected_to '/login' assert_equal 'Only the answer or question author can delete this answer', flash[:warning] @@ -111,7 +105,7 @@ def setup UserSession.create(users(:jeff)) answer = answers(:one) assert !answer.accepted - xhr :get, :accept, id: answer.id + get :accept, params: { id: answer.id }, xhr: true answer.reload assert_response :success assert answer.accepted @@ -121,7 +115,7 @@ def setup UserSession.create(users(:bob)) answer = answers(:one) assert !answer.accepted - xhr :get, :accept, id: answer.id + get :accept, params: { id: answer.id }, xhr: true answer.reload assert !answer.accepted assert_equal "Answer couldn't be accepted", response.body @@ -133,7 +127,7 @@ def setup answer.accepted = false answer.save assert !answer.accepted - xhr :get, :accept, id: answer.id + get :accept, params: { id: answer.id }, xhr: true answer.reload assert_response :success assert answer.accepted @@ -146,7 +140,7 @@ def setup a = Answer.count b = Node.count - xhr :post, :delete, id: answer.id + post :delete, params: { id: answer.id }, xhr: true assert_equal Answer.count ,a - 1 assert_equal Node.count,b diff --git a/test/functional/comment_controller_test.rb b/test/functional/comment_controller_test.rb index 80b4998987..61143bab2a 100644 --- a/test/functional/comment_controller_test.rb +++ b/test/functional/comment_controller_test.rb @@ -21,12 +21,7 @@ def teardown test 'should create note comments' do UserSession.create(users(:bob)) assert_difference 'Comment.count' do - xhr :post, :create, - { - id: nodes(:one).nid, - body: 'Notes comment' - } - + post :create, params: { id: nodes(:one).nid, body: 'Notes comment' }, xhr: true end assert_response :success assert_not_nil :comment @@ -36,10 +31,7 @@ def teardown test 'should create question comments' do UserSession.create(users(:bob)) assert_difference 'Comment.count' do - xhr :post, :create, - id: nodes(:question).nid, - body: 'Questions comment', - type: 'question' + post :create, params: { id: nodes(:question).nid, body: 'Questions comment', type: 'question' }, xhr: true end assert_response :success assert_not_nil :comment @@ -50,9 +42,7 @@ def teardown UserSession.create(users(:bob)) assert_difference 'Comment.count' do assert_difference "nodes(:wiki_page).comments.count" do - xhr :post, :create, - id: nodes(:wiki_page).nid, - body: 'Wiki comment' + post :create, params: { id: nodes(:wiki_page).nid, body: 'Wiki comment' }, xhr: true end end assert_response :success @@ -62,8 +52,10 @@ def teardown test 'should show error if wiki comment not saved' do UserSession.create(users(:bob)) assert_no_difference 'Comment.count' do - xhr :post, :create, + post :create, + params: { id: nodes(:wiki_page).nid + } end assert_equal flash[:error], 'The comment could not be saved.' assert_equal 'failure', @response.body @@ -72,8 +64,10 @@ def teardown test 'should show error if node comment not saved' do UserSession.create(users(:bob)) assert_no_difference 'Comment.count' do - xhr :post, :create, + post :create, + params: { id: nodes(:one).nid + }, xhr: true end assert_equal flash[:error], 'The comment could not be saved.' assert_equal 'failure', @response.body @@ -82,9 +76,11 @@ def teardown test 'should create answer comments' do UserSession.create(users(:bob)) assert_difference 'Comment.count' do - xhr :post, :answer_create, + post :answer_create, + params: { aid: answers(:one).id, body: 'Answers comment' + }, xhr: true end assert_response :success assert_not_nil :comment @@ -94,8 +90,10 @@ def teardown test 'should show error if answer comment not saved' do UserSession.create(users(:bob)) assert_no_difference 'Comment.count' do - xhr :post, :answer_create, + post :answer_create, + params: { aid: answers(:one).id + }, xhr: true end assert_equal flash[:error], 'The comment could not be saved.' assert_equal 'failure', @response.body @@ -105,9 +103,7 @@ def teardown UserSession.create(users(:bob)) comment = comments(:first) new_comment_body = 'New body text' - post :update, - id: comment.id, - body: new_comment_body + post :update, params: { id: comment.id, body: new_comment_body } comment.reload assert_equal new_comment_body, comment.comment assert_redirected_to comment.node.path + '?_=' + Time.now.to_i.to_s @@ -118,10 +114,7 @@ def teardown UserSession.create(users(:bob)) comment = comments(:question) new_comment_body = 'New question text' - post :update, - id: comment.id, - body: new_comment_body, - type: 'question' + post :update, params: { id: comment.id, body: new_comment_body, type: 'question' } comment.reload assert_equal new_comment_body, comment.comment assert_redirected_to comment.node.path(:question) + '?_=' + Time.now.to_i.to_s @@ -132,10 +125,7 @@ def teardown UserSession.create(users(:bob)) comment = comments(:answer_comment_one) new_comment_body = 'New answer text' - post :update, - id: comment.id, - body: new_comment_body, - type: 'question' + post :update, params: { id: comment.id, body: new_comment_body, type: 'question' } comment.reload assert_equal new_comment_body, comment.comment assert_redirected_to comment.answer.node.path(:question) + '?_=' + Time.now.to_i.to_s @@ -147,7 +137,9 @@ def teardown comment = comments(:first) new_comment_body = '' post :update, + params: { id: comment.id + } assert_not_equal new_comment_body, comment.comment assert_redirected_to comment.node.path assert_equal flash[:error], 'The comment could not be updated.' @@ -157,9 +149,7 @@ def teardown UserSession.create(users(:jeff)) comment = comments(:first) new_comment_body = 'New body text' - post :update, - id: comment.id, - body: new_comment_body + post :update, params: { id: comment.id, body: new_comment_body } comment.reload assert_not_equal new_comment_body, comment.comment assert_redirected_to comment.node.path @@ -170,8 +160,10 @@ def teardown UserSession.create(users(:bob)) comment = comments(:first) assert_difference 'Comment.count', -1 do - xhr :get, :delete, + get :delete, + params: { id: comment.id + }, xhr: true end assert_response :success assert_equal 'success', @response.body @@ -181,8 +173,10 @@ def teardown UserSession.create(users(:bob)) comment = comments(:second) assert_difference 'Comment.count', -1 do - xhr :get, :delete, + get :delete, + params: { id: comment.id + }, xhr: true end assert_response :success assert_equal 'success', @response.body @@ -192,8 +186,7 @@ def teardown UserSession.create(users(:admin)) comment = comments(:first) assert_difference 'Comment.count', -1 do - xhr :get, :delete, - id: comment.id + get :delete, params: { id: comment.id }, xhr: true end assert_response :success assert_equal 'success', @response.body @@ -203,8 +196,10 @@ def teardown UserSession.create(users(:moderator)) comment = comments(:first) assert_difference 'Comment.count', -1 do - xhr :get, :delete, + get :delete, + params: { id: comment.id + }, xhr: true end assert_response :success assert_equal 'success', @response.body @@ -215,7 +210,9 @@ def teardown comment = comments(:first) assert_no_difference 'Comment.count' do get :delete, + params: { id: comment.id + } end assert_redirected_to '/login' assert_equal flash[:warning], 'Only the comment or post author can delete this comment' @@ -225,9 +222,11 @@ def teardown UserSession.create(users(:bob)) comment = comments(:first) assert_difference 'Comment.count', -1 do - xhr :get, :delete, + get :delete, + params: { id: comment.id, type: 'question' + }, xhr: true end assert_response :success assert_template 'comment/delete' @@ -235,20 +234,14 @@ def teardown test 'should send mail to tag followers in the comment' do UserSession.create(users(:jeff)) - xhr :post, :create, - id: nodes(:question).nid, - body: 'Question #awesome', - type: 'question' + post :create, params: { id: nodes(:question).nid, body: 'Question #awesome', type: 'question' }, xhr: true assert ActionMailer::Base.deliveries.collect(&:to).include?([users(:bob).email]) # tag followers can be found in tag_selection.yml end test 'should send mail to multiple tag followers in the comment' do UserSession.create(users(:jeff)) - xhr :post, :create, - id: nodes(:question).nid, - body: 'Question #everything #awesome', - type: 'question' + post :create, params: { id: nodes(:question).nid, body: 'Question #everything #awesome', type: 'question' }, xhr: true assert ActionMailer::Base.deliveries.collect(&:to).include?([users(:bob).email]) assert ActionMailer::Base.deliveries.collect(&:to).include?([users(:moderator).email]) # tag followers can be found in tag_selection.yml @@ -256,18 +249,13 @@ def teardown test 'should send notification email upon a new wiki comment' do UserSession.create(users(:jeff)) - xhr :post, :create, - id: nodes(:wiki_page).nid, - body: 'A comment by Jeff on a wiki page of author bob', - type: 'page' + post :create, params: { id: nodes(:wiki_page).nid, body: 'A comment by Jeff on a wiki page of author bob', type: 'page' }, xhr: true assert ActionMailer::Base.deliveries.collect(&:subject).include?("New comment on Wiki page title (#11) ") end test 'should prompt user if comment includes question mark' do UserSession.create(users(:jeff)) - xhr :post, :create, - id: nodes(:blog).id, - body: 'Test question?' + post :create, params: { id: nodes(:blog).id, body: 'Test question?' }, xhr: true assert_select 'a[href=?]', '/questions', { :count => 1, :text => 'Questions page' } end @@ -275,8 +263,10 @@ def teardown UserSession.create(users(:bob)) comment = comments(:first) assert_difference 'Comment.count', -1 do - xhr :post, :make_answer, + post :make_answer, + params: { id: comment.id + }, xhr: true end end @@ -284,8 +274,10 @@ def teardown UserSession.create(users(:moderator)) comment = comments(:first) assert_difference 'Comment.count', -1 do - xhr :post, :make_answer, + post :make_answer, + params: { id: comment.id + }, xhr: true end end @@ -293,8 +285,10 @@ def teardown UserSession.create(users(:admin)) comment = comments(:first) assert_difference 'Comment.count', -1 do - xhr :post, :make_answer, + post :make_answer, + params: { id: comment.id + }, xhr: true end end @@ -303,7 +297,9 @@ def teardown comment = comments(:first) assert_no_difference 'Comment.count' do post :make_answer, + params: { id: comment.id + } end assert_redirected_to '/login' assert_equal flash[:warning], 'Only the comment author can promote this comment to answer' @@ -314,8 +310,10 @@ def teardown comment = comments(:first) initial_mail_count = ActionMailer::Base.deliveries.size assert_difference 'Answer.count', +1 do - xhr :post, :make_answer, + post :make_answer, + params: { id: comment.id + }, xhr: true end assert_not_nil :answer assert_equal initial_mail_count, ActionMailer::Base.deliveries.size # check for ensuring that no Email is sent @@ -326,8 +324,10 @@ def teardown comment = comments(:first) initial_mail_count = ActionMailer::Base.deliveries.size assert_difference 'Answer.count', +1 do - xhr :post, :make_answer, + post :make_answer, + params: { id: comment.id + }, xhr: true end assert_not_nil :answer assert_equal initial_mail_count, ActionMailer::Base.deliveries.size # check for ensuring that no Email is sent @@ -338,8 +338,10 @@ def teardown comment = comments(:first) initial_mail_count = ActionMailer::Base.deliveries.size assert_difference 'Answer.count', +1 do - xhr :post, :make_answer, + post :make_answer, + params: { id: comment.id + }, xhr: true end assert_not_nil :answer assert_equal initial_mail_count, ActionMailer::Base.deliveries.size # check for ensuring that no Email is sent @@ -367,7 +369,7 @@ def teardown UserSession.create(users(:bob)) comment = comments(:first) like_count = Like.where(likeable_id: comment.id, likeable_type: "Comment").count - xhr :post, :like_comment, comment_id: comment.id, user_id: 7 + post :like_comment, params: { comment_id: comment.id, user_id: 7 }, xhr: true updated_like_count = Like.where(likeable_id: comment.id, likeable_type: "Comment").count assert_equal updated_like_count, like_count+1 end @@ -377,7 +379,7 @@ def teardown comment = comments(:first) Like.create(likeable_id: comment.id, user_id: 1, likeable_type: "Comment") like_count = Like.where(likeable_id: comment.id, likeable_type: "Comment").count - xhr :post, :like_comment, comment_id: comment.id, user_id: 1 + post :like_comment, params: { comment_id: comment.id, user_id: 1 }, xhr: true updated_like_count = Like.where(likeable_id: comment.id, likeable_type: "Comment").count assert_equal updated_like_count, like_count-1 end diff --git a/test/functional/editor_controller_test.rb b/test/functional/editor_controller_test.rb index b34b072337..dd786537a7 100644 --- a/test/functional/editor_controller_test.rb +++ b/test/functional/editor_controller_test.rb @@ -28,7 +28,9 @@ def setup test 'should get legacy form' do UserSession.create(users(:bob)) get :legacy, + params: { tags: 'one,two' + } assert_response :success assert_select 'h3', 'Share your work' selector = css_select 'span.moderation-notice' @@ -48,7 +50,9 @@ def setup test "should use existing node body as template in legacy form based on param 'n'" do UserSession.create(users(:bob)) get :legacy, + params: { n: nodes(:blog).id + } assert_response :success assert_select 'textarea#text-input', nodes(:blog).body end @@ -56,7 +60,9 @@ def setup test "should use existing node body as template in legacy form based on param 'n' in rich editor" do UserSession.create(users(:bob)) get :rich, + params: { n: nodes(:blog).id + } assert_response :success assert_select 'textarea#text-input', nodes(:blog).body end @@ -64,7 +70,9 @@ def setup test "should use existing node body as template in post form based on param 'n'" do UserSession.create(users(:bob)) get :post, + params: { n: nodes(:blog).id + } assert_response :success assert_select 'textarea#text-input', nodes(:blog).body end @@ -87,9 +95,11 @@ def setup test 'should redirect to login page while posting question' do get :legacy, + params: { tags: 'question:question', template: 'question', redirect: 'question' + } assert_redirected_to '/login' # uses ASCII format instead of utf-8 assert_equal '/legacy?redirect=question&tags=question%3Aquestion&template=question', session[:return_to] @@ -98,9 +108,11 @@ def setup test 'should show question template in legacy form for questions' do UserSession.create(users(:bob)) get :legacy, + params: { tags: 'question:question,one', template: 'question', redirect: 'question' + } assert_response :redirect assert_redirected_to '/questions/new?redirect=question&tags=question%3Aquestion%2Cone&template=question' # assert_select "h3", "Ask a question of the community" @@ -110,9 +122,11 @@ def setup test 'should show question template in post form for questions' do UserSession.create(users(:bob)) get :post, + params: { tags: 'question:question,one', template: 'question', redirect: 'question' + } assert_response :redirect assert_redirected_to '/questions/new?redirect=question&tags=question%3Aquestion%2Cone&template=question' # assert_select "h3", "Ask a question of the community" @@ -122,7 +136,9 @@ def setup test 'should show title form input if title parameter present' do UserSession.create(users(:bob)) get :legacy, + params: { title: 'New Question' + } assert_response :success assert_select 'input#title' do assert_select '[value=?]', 'New Question' diff --git a/test/functional/features_controller_test.rb b/test/functional/features_controller_test.rb index b5df018318..f28e864fec 100644 --- a/test/functional/features_controller_test.rb +++ b/test/functional/features_controller_test.rb @@ -77,11 +77,12 @@ def teardown # assert_difference 'Node.where(type: "feature").count', 1 do get :create, + params: { title: 'new-feature', body: "A new feature to display" + } # end - assert_equal 'Feature saved.', flash[:notice] assert_redirected_to '/features?_=' + Time.now.to_i.to_s end @@ -91,9 +92,7 @@ def teardown node = nodes(:feature) assert_difference 'Revision.count' do - get :update, - id: node.id, - body: "A new feature to display with additions" + get :update, params: { id: node.id, body: "A new feature to display with additions"} end assert_equal "A new feature to display with additions", Node.find(node.id).latest.body diff --git a/test/functional/home_controller_test.rb b/test/functional/home_controller_test.rb index a07a863e6f..6ac450c58e 100644 --- a/test/functional/home_controller_test.rb +++ b/test/functional/home_controller_test.rb @@ -83,7 +83,7 @@ def setup old_controller = @controller @controller = SettingsController.new - get :change_locale, locale: lang.to_s + get :change_locale, params: { locale: lang.to_s } @controller = old_controller @@ -100,7 +100,7 @@ def setup old_controller = @controller @controller = SettingsController.new - get :change_locale, locale: lang.to_s + get :change_locale, params: { locale: lang.to_s } @controller = old_controller diff --git a/test/functional/images_controller_test.rb b/test/functional/images_controller_test.rb index 59d6c7a6fa..5d45acd019 100644 --- a/test/functional/images_controller_test.rb +++ b/test/functional/images_controller_test.rb @@ -10,9 +10,9 @@ def setup end test "image shortlinks redirect properly" do - get :shortlink, id: Image.last.id + get :shortlink, params: { id: Image.last.id } assert_redirected_to Image.last.path(:large) - get :shortlink, id: Image.last.id, size: 'medium' + get :shortlink, params: { id: Image.last.id, size: 'medium' } assert_redirected_to Image.last.path(:medium) end diff --git a/test/functional/legacy_controller_test.rb b/test/functional/legacy_controller_test.rb index 27032037bc..393bfd51b2 100644 --- a/test/functional/legacy_controller_test.rb +++ b/test/functional/legacy_controller_test.rb @@ -3,7 +3,7 @@ class LegacyControllerTest < ActionController::TestCase test 'report redirect' do - get :report, id: nodes(:one).slug + get :report, params: { id: nodes(:one).slug } assert_response :redirect end diff --git a/test/functional/like_controller_test.rb b/test/functional/like_controller_test.rb index 4c97637b8a..b5f4ae01fe 100644 --- a/test/functional/like_controller_test.rb +++ b/test/functional/like_controller_test.rb @@ -15,7 +15,7 @@ def teardown; end test 'show like' do note = Node.where(type: 'note', status: 1).first - get :show, id: note.id + get :show, params: { id: note.id } assert_response :success end @@ -25,7 +25,7 @@ def teardown; end note = Node.where(type: 'note', status: 1).first cached_likes = note.cached_likes - get :create, id: note.id + get :create, params: { id: note.id } assert_response :success note = Node.find note.id @@ -39,11 +39,11 @@ def teardown; end current_user = User.find 2 note = Node.where(type: 'note', status: 1).first - get :create, id: note.id # ensure it's liked first + get :create, params: { id: note.id } # ensure it's liked first note = Node.find note.id cached_likes = note.cached_likes - get :delete, id: note.id + get :delete, params: { id: note.id } assert_response :success note = Node.find note.id @@ -65,7 +65,7 @@ def teardown; end note = Node.where(type: 'note', status: 1).first cached_likes = note.cached_likes - get :create, id: note.id #first liked + get :create, params: { id: note.id } #first liked note = Node.find note.id cached_likes = note.cached_likes diff --git a/test/functional/map_controller_test.rb b/test/functional/map_controller_test.rb index 5f8ff37cc0..dd73973ed1 100644 --- a/test/functional/map_controller_test.rb +++ b/test/functional/map_controller_test.rb @@ -1,28 +1,15 @@ -# def index -# def show -# def edit -# def delete -# def update -# def new -# def create -# def tag - require 'test_helper' class MapControllerTest < ActionController::TestCase test 'should get index' do get :index assert_response :success - # make some map test data: - # assert_not_nil @maps - # assert_not_nil @nodes end test 'should get show' do map = nodes(:map) - get :show, - name: map.title.parameterize, - date: map.created_at.strftime('%m-%d-%Y').slice(0, 19) + get :show, params: { name: map.title.parameterize, date: map.created_at.strftime('%m-%d-%Y').slice(0, 19) } + assert_response :success end end diff --git a/test/functional/notes_controller_test.rb b/test/functional/notes_controller_test.rb index 39d790256d..34f212b79c 100644 --- a/test/functional/notes_controller_test.rb +++ b/test/functional/notes_controller_test.rb @@ -14,7 +14,7 @@ def teardown test 'redirect note short url' do note = Node.where(type: 'note', status: 1).first - get :shortlink, id: note.id + get :shortlink, params: { id: note.id } assert_redirected_to note.path end @@ -23,7 +23,7 @@ def teardown note = Node.where(type: 'note', status: 1).first assert_not_nil note.id - get :show, id: note.id + get :show, params: { id: note.id } assert_response :success end @@ -34,9 +34,11 @@ def teardown assert_equal 'nonexistent', note.power_tag('activity') get :show, + params: { author: note.author.name, date: Time.at(note.created).strftime('%m-%d-%Y'), id: note.title.parameterize + } assert_response :success assert_select '#other-activities', false @@ -49,7 +51,7 @@ def teardown comment.comment = 'Test **markdown** and http://links.com' comment.save! - get :show, id: node.id + get :show, params: { id: node.id } assert_select 'strong', 'markdown' assert_select 'a', 'http://links.com' @@ -69,9 +71,11 @@ def teardown # assert_difference 'note.views', 1 do assert_difference 'Impression.count', 1 do get :show, + params: { author: note.author.name, date: Time.at(note.created).strftime('%m-%d-%Y'), id: note.title.parameterize + } end assert_equal '0.0.0.0', Impression.last.ip_address @@ -79,9 +83,11 @@ def teardown assert_difference 'note.totalviews', 1 do get :show, + params: { author: note.author.name, date: Time.at(note.created).strftime('%m-%d-%Y'), id: note.title.parameterize + } end assert_equal 2, note.totalviews @@ -89,9 +95,11 @@ def teardown # same IP won't add to views twice assert_difference 'note.totalviews', 0 do get :show, + params: { author: note.author.name, date: Time.at(note.created).strftime('%m-%d-%Y'), id: note.title.parameterize + } end end @@ -102,9 +110,11 @@ def teardown assert_equal blog.nid.to_s, note.power_tag('redirect') get :show, + params: { author: note.author.name, date: Time.at(note.created).strftime('%m-%d-%Y'), id: note.title.parameterize + } assert_redirected_to blog.path end @@ -118,9 +128,11 @@ def teardown UserSession.create(users(:jeff)) get :show, + params: { author: note.author.name, date: Time.at(note.created).strftime('%m-%d-%Y'), id: note.title.parameterize + } assert_response :success assert_equal "Only moderators and admins see this page, as it is redirected to #{blog.title}. @@ -134,9 +146,11 @@ def teardown assert !Tag.where(name: 'activities:' + note.power_tag('activity')).empty? get :show, + params: { author: note.author.name, date: Time.at(note.created).strftime('%m-%d-%Y'), id: note.title.parameterize + } assert_response :success assert_select '#other-activities' @@ -147,9 +161,11 @@ def teardown note = nodes(:spam) # spam fixture get :show, + params: { author: note.author.name, date: Time.at(note.created).strftime('%m-%d-%Y'), id: note.title.parameterize + } assert_redirected_to '/' end @@ -164,7 +180,7 @@ def teardown test 'should get raw note markup' do id = Node.where(type: 'note', status: 1).last.id - get :raw, id: id + get :raw, params: { id: id } assert_response :success end @@ -172,7 +188,7 @@ def teardown test 'should show main image for node, returning blank image if it has none' do node = nodes(:one) - get :image, id: node.id + get :image, params: { id: node.id } assert_response :redirect assert_redirected_to 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==' @@ -199,10 +215,11 @@ def teardown title = 'My new post about balloon mapping' post :create, - id: users(:bob).id, + params: { id: users(:bob).id, title: title, body: 'This is a fascinating post about a balloon mapping event.', tags: 'balloon-mapping,event' + } # , main_image: "/images/testimage.jpg" assert_redirected_to('/login') @@ -216,9 +233,10 @@ def teardown assert_difference 'ActionMailer::Base.deliveries.size', User.where(role: 'moderator').count do post :create, - title: title, + params: { title: title, body: 'This is a fascinating post about a balloon mapping event.', tags: 'balloon-mapping,event' + } # , main_image: "/images/testimage.jpg" end @@ -233,9 +251,10 @@ def teardown title = 'My first post to Public Lab' post :create, - title: title, + params: { title: title, body: 'This is a fascinating post about a balloon mapping event.', tags: 'balloon-mapping,event' + } # , :main_image => "/images/testimage.jpg" assert_equal "Success! Thank you for contributing open research, and thanks for your patience while your post is approved by community moderators and we'll email you when it is published. In the meantime, if you have more to contribute, feel free to do so.", flash[:notice] @@ -260,9 +279,11 @@ def teardown assert_equal 4, node.status get :show, + params: { author: node.author.username, date: node.created_at.strftime('%m-%d-%Y'), id: node.title.parameterize + } assert_redirected_to '/' end @@ -273,9 +294,11 @@ def teardown assert_equal 4, node.status get :show, + params: { author: node.author.username, date: node.created_at.strftime('%m-%d-%Y'), id: node.title.parameterize + } assert_response :success assert_equal "Thank you for contributing open research, and thanks for your patience while your post is approved by community moderators and we'll email you when it is published. In the meantime, if you have more to contribute, feel free to do so.", flash[:warning] @@ -300,9 +323,11 @@ def teardown assert_equal 4, node.status get :show, + params: { author: node.author.username, date: node.created_at.strftime('%m-%d-%Y'), id: node.title.parameterize + } assert_response :success assert_equal "First-time poster #{node.author.name} submitted this #{time_ago_in_words(node.created_at)} ago and it has not yet been approved by a moderator. Approve Spam", flash[:warning] @@ -325,8 +350,10 @@ def teardown UserSession.create(users(:bob)) post :create, + params: { body: 'This is a fascinating post about a balloon mapping event.', tags: 'balloon-mapping,event' + } assert_template 'editor/post' selector = css_select '.alert' @@ -336,11 +363,12 @@ def teardown test 'posting note successfully with no errors using xhr (rich editor)' do UserSession.create(users(:bob)) - xhr :post, - :create, + post :create, + params: { body: 'This is a fascinating post about a balloon mapping event.', title: 'A completely unique snowflake', tags: 'balloon-mapping,event' + }, xhr: true assert_response :success assert_not_nil @response.body @@ -350,10 +378,11 @@ def teardown test 'post_note_error_no_title_xhr' do UserSession.create(users(:bob)) - xhr :post, - :create, + post :create, + params: { body: 'This is a fascinating post about a balloon mapping event.', tags: 'balloon-mapping,event' + }, xhr: true assert_response :success assert_not_nil @response.body @@ -365,11 +394,12 @@ def teardown test 'posting note with an error using xhr (rich editor) returns a JSON error' do UserSession.create(users(:bob)) - xhr :post, - :create, + post :create, + params: { body: 'This is a fascinating post about a balloon mapping event.', title: '', tags: 'balloon-mapping,event' + }, xhr: true assert_response :success assert_not_nil @response.body @@ -378,10 +408,11 @@ def teardown test 'returning json errors on xhr note update' do user = UserSession.create(users(:jeff)) - xhr :post, - :update, + post :update, + params: { id: nodes(:blog).id, title: '' + }, xhr: true assert_response :success assert_not_nil @response.body @@ -401,7 +432,7 @@ def teardown comment.save node = nodes(:one).path.split('/') - get :show, id: node[4], author: node[2], date: node[3] + get :show, params: { id: node[4], author: node[2], date: node[3] } assert_select 'iframe[src=?]', 'http://mapknitter.org/embed/sattelite-imagery' end @@ -422,9 +453,11 @@ def teardown User.any_instance.stubs(:wiki_edit_streak).returns([9, 15]) User.any_instance.stubs(:comment_streak).returns([10, 30]) get :show, + params: { author: node.author.username, date: node.created_at.strftime('%m-%d-%Y'), id: node.title.parameterize + } selector = css_select '.fa-fire' assert_equal selector.size, 4 end @@ -433,10 +466,12 @@ def teardown user = UserSession.create(users(:bob)) title = 'How to use Spectrometer' post :create, + params: { title: title, body: 'Spectrometer question', tags: 'question:spectrometer', redirect: 'question' + } node = nodes(:blog) email = AdminMailer.notify_node_moderators(node) assert_emails 1 do @@ -450,10 +485,12 @@ def teardown UserSession.create(users(:jeff)) title = 'My first question to Public Lab' post :create, + params: { title: title, body: 'Spectrometer question', tags: 'question:spectrometer', redirect: 'question' + } assert_redirected_to '/questions/' + users(:jeff).username + '/' + Time.now.strftime('%m-%d-%Y') + '/' + title.parameterize assert_equal flash[:notice], 'Question published. In the meantime, if you have more to contribute, feel free to do so.' @@ -463,8 +500,10 @@ def teardown user = UserSession.create(users(:jeff)) note = nodes(:blog) post :edit, + params: { id: note.nid, legacy: true + } assert_response :success assert_select 'input#taginput[value=?]', note.tagnames.join(',') end @@ -474,8 +513,10 @@ def teardown note = nodes(:question) note.add_tag('nice', users(:jeff)) post :edit, + params: { id: note.nid, legacy: true + } assert_response :success assert_select 'input#taginput[value=?]', note.tagnames.join(',') + ',spectrometer' # for now, question subject is appended to end of form end @@ -484,7 +525,9 @@ def teardown user = UserSession.create(users(:jeff)) note = nodes(:blog) post :edit, + params: { id: note.nid + } assert_response :success selector = css_select "input.form-control.input-lg[value='#{note.tagnames.join(',')}']" assert_equal selector.size, 1 @@ -495,7 +538,9 @@ def teardown note = nodes(:question) note.add_tag('nice', users(:jeff)) post :edit, + params: { id: note.nid + } assert_response :success selector = css_select "input.form-control.input-lg[value='#{note.tagnames.join(',')}']" assert_equal selector.size, 1 @@ -504,12 +549,7 @@ def teardown test 'should redirect to questions show page when editing an existing question' do user = UserSession.create(users(:jeff)) note = nodes(:question) - post :update, - id: note.nid, - title: note.title, - body: 'Spectrometer doubts', - tags: 'question:spectrometer', - redirect: 'question' + post :update, params: { id: note.nid, title: note.title, body: 'Spectrometer doubts', tags: 'question:spectrometer', redirect: 'question' } assert_redirected_to note.path(:question) + '?_=' + Time.now.to_i.to_s end @@ -519,15 +559,17 @@ def teardown node.add_tag('question:foo', users(:bob)) post :update, + params: { id: node.nid, title: node.title + ' amended' + } assert_response :redirect end test 'should redirect to question path if node is a question when visiting shortlink' do node = nodes(:question) - get :shortlink, id: node.id + get :shortlink, params: { id: node.id} assert_redirected_to node.path(:question) end @@ -535,9 +577,11 @@ def teardown note = nodes(:question) get :show, + params: { author: note.author.name, date: Time.at(note.created).strftime('%m-%d-%Y'), id: note.title.parameterize + } assert_redirected_to note.path(:question) end @@ -594,7 +638,7 @@ def teardown old_controller = @controller @controller = SettingsController.new - get :change_locale, locale: lang.to_s + get :change_locale, params: { locale: lang.to_s } @controller = old_controller @@ -602,9 +646,11 @@ def teardown title = 'Some post to Public Lab' post :create, + params: { title: title + lang.to_s, body: 'Some text.', tags: 'event' + } assert_equal I18n.t('notes_controller.research_note_published'), flash[:notice] end @@ -617,7 +663,7 @@ def teardown assert_equal 1,length assert_difference 'Node.count', -1 do - post :delete, id: node.nid + post :delete, params: {id: node.nid} end assert_redirected_to '/dashboard' + '?_=' + Time.now.to_i.to_s @@ -630,7 +676,7 @@ def teardown user = UserSession.create(users(:jeff)) assert_no_difference 'Node.count' do - get :delete, id: node.nid + get :delete, params: { id: node.nid } end assert_redirected_to '/dashboard' + '?_=' + Time.now.to_i.to_s @@ -640,7 +686,7 @@ def teardown test 'title change feature in comments when author is logged in' do UserSession.create(users(:jeff)) node = nodes(:one) - post :update_title, id: '1',title: 'changed title' + post :update_title, params: { id: '1',title: 'changed title' } assert_redirected_to node.path+"#comments" assert_equal node.reload.title, 'changed title' end @@ -648,7 +694,7 @@ def teardown # should not change title test 'title change feature in comments when author is not logged in' do node = nodes(:one) - post :update_title, id: '1',title: 'changed title' + post :update_title, params: { id: '1',title: 'changed title' } assert_redirected_to node.path+"#comments" assert_equal I18n.t('notes_controller.author_can_edit_note'), flash[:error] assert_equal node.reload.title, node.title @@ -657,12 +703,12 @@ def teardown def test_get_rss_feed get :rss, :format => "rss" assert_response :success - assert_equal 'application/rss+xml', @response.content_type + assert_equal 'application/xml', @response.content_type end test 'draft should not be shown when no user' do node = nodes(:draft) - post :show, id: '21',title: 'Draft note' + post :show, params: { id: '21',title: 'Draft note' } assert_redirected_to '/login' assert_equal "You need to login to view the page", flash[:warning] end @@ -670,7 +716,7 @@ def test_get_rss_feed test 'draft should not be shown when user is not author' do node = nodes(:draft) UserSession.create(users(:bob)) - post :show, id: '21',title: 'Draft note' + post :show, params: { id: '21',title: 'Draft note' } assert_redirected_to '/' assert_equal "Only author can access the draft note", flash[:notice] end @@ -685,7 +731,7 @@ def test_get_rss_feed answer2.save n_count = Node.count - xhr :post, :delete, id: node.id + post :delete, params: { id: node.id }, xhr: true assert_response :success assert_equal Node.count, n_count - 1 @@ -698,7 +744,7 @@ def test_get_rss_feed assert_equal 3, node.status ActionMailer::Base.deliveries.clear - get :publish_draft, id: node.id + get :publish_draft, params: { id: node.id } assert_response :redirect assert_equal "Thanks for your contribution. Research note published! Now, it's visible publically.", flash[:notice] @@ -717,7 +763,7 @@ def test_get_rss_feed assert_equal 3, node.status ActionMailer::Base.deliveries.clear - get :publish_draft, id: node.id + get :publish_draft, params: { id: node.id } assert_response :redirect assert_equal "Thanks for your contribution. Research note published! Now, it's visible publically.", flash[:notice] @@ -736,7 +782,7 @@ def test_get_rss_feed assert_equal 3, node.status ActionMailer::Base.deliveries.clear - get :publish_draft, id: node.id + get :publish_draft, params: { id: node.id } assert_response :redirect assert_equal "Thanks for your contribution. Research note published! Now, it's visible publically.", flash[:notice] @@ -755,7 +801,7 @@ def test_get_rss_feed assert_equal 3, node.status ActionMailer::Base.deliveries.clear - get :publish_draft, id: node.id + get :publish_draft, params: { id: node.id } assert_response :redirect assert_equal "You are not author or moderator so you can't publish a draft!", flash[:warning] @@ -771,7 +817,7 @@ def test_get_rss_feed assert_equal 3, node.status ActionMailer::Base.deliveries.clear - get :publish_draft, id: node.id + get :publish_draft, params: { id: node.id } assert_response :redirect assert_equal "You must be logged in to access this page", flash[:warning] @@ -802,10 +848,12 @@ def test_get_rss_feed assert !users(:jeff).first_time_poster post :create, + params: { title: title, body: 'This is a fascinating post about a balloon mapping event.', tags: 'balloon-mapping,event', draft: "true" + } email = ActionMailer::Base.deliveries.last assert_equal '[PublicLab] ' + title + " (##{Node.last.id}) ", email.subject @@ -819,10 +867,12 @@ def test_get_rss_feed title = 'My first post to Public Lab' post :create, + params: { title: title, body: 'This is a fascinating post about a balloon mapping event.', tags: 'balloon-mapping,event', draft: "true" + } assert_equal "First-time users are not eligible to create a draft.", flash[:notice] assert_redirected_to '/' @@ -834,9 +884,11 @@ def test_get_rss_feed assert_equal 3, node.status get :show, + params: { author: node.author.username, date: node.created_at.strftime('%m-%d-%Y'), id: node.title.parameterize + } assert_response :success assert_equal "This is a Draft note. Kindly complete it and publish it using Publish Draft button.", flash[:warning] @@ -848,9 +900,11 @@ def test_get_rss_feed assert_equal 3, node.status get :show, + params: { author: node.author.username, date: node.created_at.strftime('%m-%d-%Y'), id: node.title.parameterize + } assert_response :success assert_equal "This is a Draft note. Kindly complete it and publish it using Publish Draft button.", flash[:warning] @@ -862,9 +916,11 @@ def test_get_rss_feed assert_equal 3, node.status get :show, + params: { author: node.author.username, date: node.created_at.strftime('%m-%d-%Y'), id: node.title.parameterize + } assert_response :success assert_equal "This is a Draft note. Kindly complete it and publish it using Publish Draft button.", flash[:warning] diff --git a/test/functional/questions_controller_test.rb b/test/functional/questions_controller_test.rb index d4f82d54a2..ce9669e40a 100644 --- a/test/functional/questions_controller_test.rb +++ b/test/functional/questions_controller_test.rb @@ -14,17 +14,17 @@ def setup test 'should get show' do note = nodes(:question) - get :show, - author: note.author.name, - date: Time.at(note.created).strftime('%m-%d-%Y'), - id: note.title.parameterize + + get :show, params: { author: note.author.name, date: Time.at(note.created).strftime('%m-%d-%Y'), id: note.title.parameterize } assert_response :success end test 'show question by id' do note = nodes(:question) - get :show, id: note.id + + get :show, params: { id: note.id } + assert_response :success end @@ -35,7 +35,7 @@ def setup comment.comment = 'Test **markdown** and http://links.com' comment.save! - get :show, id: node.id + get :show, params: { id: node.id } assert_select 'strong', 'markdown' assert_select 'a', 'http://links.com' @@ -49,26 +49,24 @@ def setup comment.comment = 'Test **markdown2** and http://links2.com' comment.save! - get :show, id: node.id + get :show, params: { id: node.id } assert_select 'strong', 'markdown2' assert_select 'a', 'http://links2.com' assert_response :success end - test 'should redirect notes other than question to note path' do note = nodes(:one) - get :show, - author: note.author.name, - date: Time.at(note.created).strftime('%m-%d-%Y'), - id: note.title.parameterize + + get :show, params: { author: note.author.name, date: Time.at(note.created).strftime('%m-%d-%Y'), id: note.title.parameterize } + assert_redirected_to note.path end test 'redirect question to short url' do note = nodes(:question) - get :shortlink, id: note.id + get :shortlink, params: { id: note.id } assert_redirected_to note.path(:question) end @@ -85,11 +83,9 @@ def setup test 'should show accepted label for accepted answers' do note = nodes(:question) answer = answers(:two) - get :show, - author: note.author.name, - date: Time.at(note.created).strftime('%m-%d-%Y'), - id: note.title.parameterize + get :show, params: { author: note.author.name, date: Time.at(note.created).strftime('%m-%d-%Y'), id: note.title.parameterize } + assert_response :success assert_select '#answer-' + answer.id.to_s + '-accept', 1 end @@ -97,10 +93,8 @@ def setup test 'should not show answer accept button to users if not logged in' do note = nodes(:question) answer = answers(:one) - get :show, - author: note.author.name, - date: Time.at(note.created).strftime('%m-%d-%Y'), - id: note.title.parameterize + + get :show, params: { author: note.author.name, date: Time.at(note.created).strftime('%m-%d-%Y'), id: note.title.parameterize } assert_response :success assert_select '#answer-' + answer.id.to_s + '-accept', 0 @@ -110,11 +104,9 @@ def setup UserSession.create(users(:jeff)) note = nodes(:question) answer = answers(:one) - get :show, - author: note.author.name, - date: Time.at(note.created).strftime('%m-%d-%Y'), - id: note.title.parameterize + get :show, params: { author: note.author.name, date: Time.at(note.created).strftime('%m-%d-%Y'), id: note.title.parameterize } + assert_response :success assert_select '#answer-' + answer.id.to_s + '-accept', 1 end @@ -123,10 +115,8 @@ def setup UserSession.create(users(:bob)) note = nodes(:question) answer = answers(:one) - get :show, - author: note.author.name, - date: Time.at(note.created).strftime('%m-%d-%Y'), - id: note.title.parameterize + + get :show, params: { author: note.author.name, date: Time.at(note.created).strftime('%m-%d-%Y'), id: note.title.parameterize } assert_response :success assert_select '#answer-' + answer.id.to_s + '-accept', 0 @@ -189,7 +179,6 @@ def setup end test 'should list only answered questions in answered' do - UserSession.create(users(:admin)) get :answered questions = assigns(:questions) expected = [nodes(:question)] diff --git a/test/functional/relationships_controller_test.rb b/test/functional/relationships_controller_test.rb index aa7dd6aee1..284236b407 100644 --- a/test/functional/relationships_controller_test.rb +++ b/test/functional/relationships_controller_test.rb @@ -10,7 +10,7 @@ def setup followed_user = users(:jeff) UserSession.create(user) assert_difference 'Relationship.count', 1 do - post :create, followed_id: followed_user.id + post :create, params: { followed_id: followed_user.id } end assert_response :redirect assert_redirected_to '/profile/' + followed_user.username @@ -20,10 +20,10 @@ def setup user = users(:jeff) UserSession.create(user) followed_user = users(:bob) - post :create, followed_id: followed_user.id + post :create, params: { followed_id: followed_user.id } assert_difference 'Relationship.count', -1 do - delete :destroy, id: Relationship.last.id + delete :destroy, params: { id: Relationship.last.id } end assert_response :redirect @@ -32,11 +32,11 @@ def setup test 'actions require authorization' do followed_user = users(:bob) - post :create, followed_id: followed_user.id + post :create, params: { followed_id: followed_user.id } assert_response :unprocessable_entity - post :destroy, id: 1 + post :destroy, params: { id: 1 } assert_response :unprocessable_entity end end diff --git a/test/functional/searches_controller_test.rb b/test/functional/searches_controller_test.rb index b5c3afa5ec..7386e78bca 100644 --- a/test/functional/searches_controller_test.rb +++ b/test/functional/searches_controller_test.rb @@ -10,7 +10,7 @@ class SearchesControllerTest < ActionController::TestCase end test "search results page at /search/foo" do - get :results, id: 'Organizers' + get :results, params: { id: 'Organizers' } assert_response :success assert_not_nil assigns(:tagnames) assert_not_nil assigns(:users) @@ -19,7 +19,7 @@ class SearchesControllerTest < ActionController::TestCase end test "search results page for no results at /search/somethingthathasnoresults" do - get :results, id: 'somethingthathasnoresults' + get :results, params: { id: 'somethingthathasnoresults' } assert_response :success assert_not_nil assigns(:tagnames) assert_not_nil assigns(:users) diff --git a/test/functional/subscription_controller_test.rb b/test/functional/subscription_controller_test.rb index 7f7d938943..253f643fe1 100644 --- a/test/functional/subscription_controller_test.rb +++ b/test/functional/subscription_controller_test.rb @@ -8,7 +8,7 @@ def setup test 'user should be able to subscribe to a tag' do UserSession.create(users(:bob)) - get :add, type: 'tag', name: 'blog' + get :add, params: { type: 'tag', name: 'blog' } assert_response :redirect assert users(:bob).following(:blog) @@ -27,4 +27,4 @@ def setup assert_response :success end -end \ No newline at end of file +end diff --git a/test/functional/tag_controller_test.rb b/test/functional/tag_controller_test.rb index dc138e3b28..5a5de49576 100644 --- a/test/functional/tag_controller_test.rb +++ b/test/functional/tag_controller_test.rb @@ -12,21 +12,23 @@ def setup test 'add one or two tags' do UserSession.create(users(:bob)) - post :create, name: 'mytag', nid: nodes(:one).nid, uid: users(:bob).id + post :create, params: { name: 'mytag', nid: nodes(:one).nid, uid: users(:bob).id } assert_equal 'mytag', assigns[:tags].last.name assert_redirected_to(nodes(:one).path) post :create, + params: { name: 'mysecondtag,mythirdtag', nid: nodes(:one).nid, uid: users(:bob).id + } assert_equal 'mysecondtag', assigns[:tags][assigns[:tags].length - 2].name assert_equal 'mythirdtag', assigns[:tags].last.name assert_redirected_to(nodes(:one).path) - xhr :post, :create, name: 'myfourthtag,myfifthtag', nid: nodes(:one).nid, uid: users(:bob).id + post :create, params: { name: 'myfourthtag,myfifthtag', nid: nodes(:one).nid, uid: users(:bob).id }, xhr: true assert_response :success assert_equal [['myfourthtag', Tag.find_by_name('myfourthtag').tid], ['myfifthtag', Tag.find_by_name('myfifthtag').tid]], JSON.parse(response.body)['saved'] @@ -36,7 +38,9 @@ def setup UserSession.create(users(:bob)) get :contributors, + params: { id: 'question:*' + } assert_template :contributors assert_select 'p', text: "No contributors for that tag; try searching for 'question:*':" @@ -46,8 +50,10 @@ def setup UserSession.create(users(:bob)) post :create, + params: { name: 'my invalid tag $_', nid: nodes(:one).nid + } assert_redirected_to(nodes(:one).path) assert_equal 'Error: tags can only include letters, numbers, and dashes', assigns[:output][:errors][0] @@ -57,8 +63,10 @@ def setup UserSession.create(users(:bob)) post :create, + params: { name: 'with:bob', nid: nodes(:one).nid # authored by jeff, not bob + } assert_redirected_to(nodes(:one).path) assert_equal I18n.t('node.only_author_use_powertag'), assigns[:output][:errors][0] @@ -68,8 +76,10 @@ def setup UserSession.create(users(:admin)) post :create, + params: { name: 'with:bob', nid: nodes(:one).nid # authored by jeff, not bob + } assert_redirected_to(nodes(:one).path) assert_equal 0, assigns[:output][:errors].length @@ -80,18 +90,22 @@ def setup UserSession.create(users(:bob)) post :create, + params: { name: 'mytag', nid: nodes(:one).nid, uid: users(:bob) + } assert_redirected_to(nodes(:one).path) # 2nd identical tag: post :create, + params: { name: 'mytag', nid: nodes(:one).nid, uid: users(:bob) + } assert_redirected_to(nodes(:one).path) assert_equal 'Error: that tag already exists.', assigns[:output][:errors][0] @@ -99,9 +113,11 @@ def setup test 'add tag not logged in' do post :create, + params: { name: 'mytag', nid: nodes(:one).nid, uid: 1 + } assert_redirected_to('/login') end @@ -117,7 +133,7 @@ def setup end test 'tag search' do - get :index , :search => "featured" + get :index , params: { search: "featured" } assert :success assert assigns(:tags).length > 0 @@ -125,7 +141,7 @@ def setup end test 'tag show' do - get :show, id: tags(:spectrometer).name + get :show, params: { id: tags(:spectrometer).name } assert :success assert_not_nil :tags @@ -143,33 +159,31 @@ def setup end test 'tag show range' do - get :show, id: tags(:spectrometer).name, + get :show, params: { id: tags(:spectrometer).name, start: (Time.now - 1.day).strftime('%d-%m-%Y'), - end: Time.now.strftime('%d-%m-%Y') + end: Time.now.strftime('%d-%m-%Y') } assert :success assert_not_nil :tags end test 'tag show JSON' do - get :show, id: tags(:spectrometer).name, format: 'json' + get :show, params: { id: tags(:spectrometer).name, format: 'json' } assert :success assert_not_nil :tags - json = ActiveSupport::JSON.decode(@response.body) - assert_not_nil json assert !assigns['notes'].empty? node = Node.find tags(:spectrometer).nodes.first.nid - assert_equal node.nid, json.first['nid'] + assert_equal node.nid, json.first['node']['nid'] assert_equal node.body_preview, json.first['preview'] #assert_equal node.main_image, json.first['image'] # this won't check anything bc there is no main image assert_equal node.tags.collect(&:name), json.first['tags'] end test 'wildcard tag show' do - get :show, id: 'question:*' + get :show, params: { id: 'question:*' } assert :success assert_not_nil :tags assert :wildcard @@ -177,7 +191,7 @@ def setup end test "wildcard tag show wiki pages" do - get :show, id: 'activities:*', node_type: 'wiki' + get :show, params: { id: 'activities:*', node_type: 'wiki' } assert :success assert_not_nil :tags assert :wildcard @@ -188,13 +202,13 @@ def setup end test 'wildcard tag should list answered questions' do - get :show, id: 'question:*' + get :show, params: { id: 'question:*' } assert_not_nil assigns(:answered_questions) end test 'wildcard tag should have a active asked and an inactive answered tab for question' do - get :show, id: 'question:*' + get :show, params: { id: 'question:*' } selector = css_select '#asked-tab.active' assert_equal selector.size, 1 @@ -202,7 +216,7 @@ def setup end test "wildcard tag show wiki pages with author" do - get :show_for_author, node_type: 'wiki', id: 'awes*', author: 'Bob' + get :show_for_author, params: { node_type: 'wiki', id: 'awes*', author: 'Bob' } assert :success assert_not_nil :tags assert assigns(:wildcard) @@ -217,7 +231,7 @@ def setup end test "tag show wiki pages with author" do - get :show, node_type: 'wiki', id: 'awesome', author: 'Bob' + get :show, params: { node_type: 'wiki', id: 'awesome', author: 'Bob' } assert :success assert_not_nil :tags assert_nil assigns(:wildcard) @@ -231,20 +245,20 @@ def setup end test "wildcard does not show wiki" do - get :show, id: 'question:*', node_type: 'wiki' + get :show, params: { id: 'question:*', node_type: 'wiki' } assert_equal true, assigns(:wikis).empty? end test "should show a featured wiki page at top, if it exists" do tag = tags(:test) - get :show, id: nodes(:organizers).slug + get :show, params: { id: nodes(:organizers).slug } assert_select '#wiki-content', 1 end test 'show note with author and tagname without wildcard' do - get :show_for_author, id: 'test', author: 'jeff' + get :show_for_author, params: { id: 'test', author: 'jeff' } assert_response :success assert_not_nil :tags assert_not_nil :authors @@ -259,7 +273,7 @@ def setup end test 'show note with author and tagname with wildcard' do - get :show_for_author, id: 'test*', author: 'jeff' + get :show_for_author, params: { id: 'test*', author: 'jeff' } assert_response :success assert_not_nil :tags assert_not_nil :authors @@ -275,33 +289,33 @@ def setup end test 'tag widget' do - get :widget, id: Tag.last.name + get :widget, params: { id: Tag.last.name } assert :success assert_not_nil :notes end test 'tag blog' do - get :blog, id: Tag.last.name + get :blog, params: { id: Tag.last.name } assert :success assert_not_nil :notes assert_not_nil :tags end test 'tag author' do - get :author, id: User.last.username + get :author, params: { id: User.last.username } assert :success end test 'tag rss' do - get :rss, tagname: Tag.last.name, format: 'rss' + get :rss, params: { tagname: Tag.last.name, format: 'rss' } assert :success assert_not_nil :notes end test 'tag contributors' do - get :contributors, id: Tag.last.name + get :contributors, params: { id: Tag.last.name } assert :success assert_not_nil :notes @@ -317,8 +331,10 @@ def setup node = Node.where(type: 'note').last post :barnstar, + params: { nid: node.nid, star: 'basic' + } assert_equal "[@#{User.first.username}](/profile/#{User.first.username}) awards a barnstar to #{node.author.name} for their awesome contribution!", Comment.last.body end @@ -332,8 +348,10 @@ def setup assert_difference 'Comment.count' do tagname = "with:#{user.name}" post :create, + params: { name: tagname, nid: node.id + } assert_equal " [@#{node.author.name}](/profile/#{node.author.name}) has marked #{tagname.split(':')[1]} as a co-author. ", Comment.last.body end @@ -342,7 +360,7 @@ def setup test 'should take node type as question if tag is a question tag' do tag = tags(:question) - get :show, id: tag.name + get :show, params: { id: tag.name } assert_equal 'questions', assigns(:node_type) end @@ -350,7 +368,7 @@ def setup test 'should take node type as note if tag is not a question tag' do tag = tags(:awesome) - get :show, id: tag.name + get :show, params: { id: tag.name } assert_equal 'note', assigns(:node_type) end @@ -358,7 +376,7 @@ def setup test 'should list only question in question view' do tag = tags(:question) - get :show, id: tag.name + get :show, params: { id: tag.name } questions = assigns(:questions) expected = [nodes(:question), nodes(:question2)] @@ -369,7 +387,7 @@ def setup test 'should list only notes in notes view' do tag = tags(:test) - get :show, id: tag.name + get :show, params: { id: tag.name } notes = assigns(:notes) expected = [nodes(:one)] @@ -380,7 +398,7 @@ def setup test 'should have active Research tab for notes' do tag = tags(:test) - get :show, id: tag.name + get :show, params: { id: tag.name } selector = css_select "ul>li>a[href = '/tag/test']" assert_equal selector.size, 1 @@ -391,7 +409,7 @@ def setup test 'should have active question tab for question' do tag = tags(:question) - get :show, id: tag.name + get :show, params: { id: tag.name } selector = css_select "ul>li>a[href = '/questions/tag/question:spectrometer']" assert_equal selector.size, 1 selector = css_select '#questions.active' @@ -401,7 +419,7 @@ def setup test 'can create tag instance (community_tag) using a parent tag' do UserSession.create(users(:bob)) - post :create, name: 'spectrometry', nid: nodes(:one).nid, uid: users(:bob).id + post :create, params: { name: 'spectrometry', nid: nodes(:one).nid, uid: users(:bob).id } assert_equal 'spectrometry', assigns[:tags].last.name assert_redirected_to(nodes(:one).path) @@ -420,7 +438,7 @@ def setup nodes(:blog).add_tag('spectrometry', users(:bob)) assert nodes(:blog).has_tag_without_aliasing('spectrometry') - get :show, id: 'spectrometry' + get :show, params: { id: 'spectrometry' } # order of timestamps during testing (almost same timestamps) was causing testing irregularities notes = assigns(:notes).sort_by(&:title).reverse @@ -453,7 +471,7 @@ def setup assert_equal '', tags(:spectrometry).parent nodes(:blog).add_tag('spectrometry', users(:bob)) - get :show, id: 'spectrometer' + get :show, params: { id: 'spectrometer' } assert_equal 1, assigns(:notes).length assert_not assigns(:notes).first.has_tag_without_aliasing('spectrometry') @@ -461,7 +479,7 @@ def setup end test 'shows suggested tags' do - get :suggested, id: 'spectr' + get :suggested, params: { id: 'spectr' } assert_equal 4, assigns(:suggestions).length assert_equal ['question:spectrometer', 'spectrometer', 'activity:spectrometer', 'activities:spectrometer'], JSON.parse(response.body) @@ -472,34 +490,34 @@ def setup old_controller = @controller @controller = SettingsController.new - get :change_locale, locale: lang.to_s + get :change_locale, params: { locale: lang.to_s } @controller = old_controller UserSession.create(users(:bob)) - post :create, name: 'mytag', nid: nodes(:one).nid, uid: users(:bob) - post :create, name: 'mytag', nid: nodes(:one).nid, uid: users(:bob) + post :create, params: { name: 'mytag', nid: nodes(:one).nid, uid: users(:bob) } + post :create, params: { name: 'mytag', nid: nodes(:one).nid, uid: users(:bob) } assert_equal I18n.t('tag_controller.tag_already_exists'), assigns[:output][:errors][0] end end test 'shows embeddable grid of tagged content' do - get :gridsEmbed, tagname: 'spectrometer' + get :gridsEmbed, params: { tagname: 'spectrometer' } assert_response :success assert_select 'table' # ensure a table is shown end test 'rss with tagname and authorname' do - get :rss_for_tagged_with_author, tagname: 'test*', authorname: 'jeff', format: 'rss' + get :rss_for_tagged_with_author, params: { tagname: 'test*', authorname: 'jeff', format: 'rss' } assert :success assert_not_nil :notes - assert_equal 'application/rss+xml', @response.content_type + assert_equal 'application/xml', @response.content_type end test 'should have active question tab for question for show_for_author' do tag = tags(:question) - get :show_for_author, id: tag.name, author: 'jeff' + get :show_for_author, params: { id: tag.name, author: 'jeff' } selector = css_select "ul>li>a[href = '/questions/tag/question:spectrometer/author/jeff']" assert_equal selector.size, 1 selector = css_select '#questions.active' @@ -509,7 +527,7 @@ def setup test 'should have a active asked and an inactive answered tab for question' do tag = tags(:question) - get :show_for_author, id: tag.name, author: 'jeff' + get :show_for_author, params: { id: tag.name, author: 'jeff' } selector = css_select '#asked-tab.active' assert_equal selector.size, 1 @@ -519,7 +537,7 @@ def setup test 'should list answered questions' do tag = tags(:question) - get :show_for_author, id: tag.name, author: 'jeff' + get :show_for_author, params: { id: tag.name, author: 'jeff' } assert_not_nil assigns(:answered_questions) end @@ -527,38 +545,38 @@ def setup test 'should take node type as note if tag is not a question tag for show_for_author' do tag = tags(:awesome) - get :show_for_author, id: tag.name, author: 'jeff' + get :show_for_author, params: { id: tag.name, author: 'jeff' } assert_equal 'note', assigns(:node_type) end test "does not show wiki for show_for_author" do - get :show_for_author, id: 'question', node_type: 'wiki', author: 'jeff' + get :show_for_author, params: { id: 'question', node_type: 'wiki', author: 'jeff' } assert_equal true, assigns(:wikis).empty? end test "wildcard does not show wiki for show_for_author" do - get :show_for_author, id: 'question:*', node_type: 'wiki', author: 'jeff' + get :show_for_author, params: { id: 'question:*', node_type: 'wiki', author: 'jeff' } assert_equal true, assigns(:wikis).empty? end test "does not show note for show_for_author" do - get :show_for_author, id: 'question', author: 'jeff' + get :show_for_author, params: { id: 'question', author: 'jeff' } assert_equal true, assigns(:notes).empty? end test "wildcard does not show note for show_for_author" do - get :show_for_author, id: 'question:*', author: 'jeff' + get :show_for_author, params: { id: 'question:*', author: 'jeff' } assert_equal true, assigns(:notes).empty? end test "wildcard does not show map for show_for_author" do - get :show_for_author, id: 'question:*', node_type: 'maps', author: 'jeff' + get :show_for_author, params: { id: 'question:*', node_type: 'maps', author: 'jeff' } assert_equal true, assigns(:nodes).empty? end test " does not show map for show_for_author" do - get :show_for_author, id: 'question', node_type: 'maps', author: 'jeff' + get :show_for_author, params: { id: 'question', node_type: 'maps', author: 'jeff' } assert_equal true, assigns(:nodes).empty? end diff --git a/test/functional/talk_controller_test.rb b/test/functional/talk_controller_test.rb index 35240777bc..208adec092 100644 --- a/test/functional/talk_controller_test.rb +++ b/test/functional/talk_controller_test.rb @@ -3,13 +3,13 @@ class TalkControllerTest < ActionController::TestCase test 'should get show for root page' do node = nodes(:about) - get :show, id: node.slug + get :show, params: { id: node.slug } assert_response :success end test 'should get show' do node = nodes(:organizers) - get :show, id: node.slug + get :show, params: { id: node.slug } assert_response :success end end diff --git a/test/functional/user_sessions_controller_test.rb b/test/functional/user_sessions_controller_test.rb index 4c9677313c..d2934ef5de 100644 --- a/test/functional/user_sessions_controller_test.rb +++ b/test/functional/user_sessions_controller_test.rb @@ -3,36 +3,24 @@ class UserSessionsControllerTest < ActionController::TestCase test 'should login an user' do - post :create, user_session: { - username: users(:jeff).username, - password: 'secretive' - } + post :create, params: { user_session: { username: users(:jeff).username, password: 'secretive' } } assert_redirected_to '/dashboard' end test 'should redirect to create new account if username doesnt exist' do - post :create, user_session: { - username: 'nobody', - password: 'blablabla' - } + post :create, params: { user_session: { username: 'nobody', password: 'blablabla' } } assert_redirected_to '/login' assert_equal 'There is nobody in our system by that name, are you sure you have the right username?', flash[:warning] end test 'login user with an email' do - post :create, user_session: { - username: users(:jeff).email, - password: 'secretive' - } + post :create, params: { user_session: { username: users(:jeff).email, password: 'secretive' } } assert_redirected_to '/dashboard' end test 'should login and redirect to corresct url' do session[:return_to] = '/post?tags=question:question&template=question' - post :create, user_session: { - username: users(:jeff).username, - password: 'secretive' - } + post :create, params: { user_session: { username: users(:jeff).username, password: 'secretive' } } assert_redirected_to '/post?tags=question:question&template=question' end @@ -42,14 +30,11 @@ class UserSessionsControllerTest < ActionController::TestCase @controller = SettingsController.new # set locale in cookie - get :change_locale, locale: lang.to_s + get :change_locale, params: { locale: lang.to_s } @controller = old_controller - post :create, user_session: { - username: users(:jeff).username, - password: 'secretive' - } + post :create, params: { user_session: { username: users(:jeff).username, password: 'secretive' } } assert_redirected_to '/dashboard' assert_equal I18n.t('user_sessions_controller.logged_in'), flash[:notice] diff --git a/test/functional/user_tags_controller_test.rb b/test/functional/user_tags_controller_test.rb index d2fcb99a44..e875032203 100644 --- a/test/functional/user_tags_controller_test.rb +++ b/test/functional/user_tags_controller_test.rb @@ -8,7 +8,7 @@ def setup test 'should create a new tags' do UserSession.create(users(:bob)) assert_difference 'UserTag.count' do - post :create, id: users(:bob).id, name: 'environment' + post :create, params: { id: users(:bob).id, name: 'environment' } end assert_equal 'environment tag created successfully', flash[:notice] assert_redirected_to "/profile/#{users(:bob).username}" @@ -16,7 +16,7 @@ def setup test 'should create a new tags via xhr' do UserSession.create(users(:bob)) - xhr :post, :create, id: users(:bob).id, name: 'environment' + post :create, params: { id: users(:bob).id, name: 'environment' }, xhr: true assert_response :success assert_equal [['environment', UserTag.where(value:'environment').first.id]], JSON.parse(response.body)['saved'] end @@ -24,7 +24,7 @@ def setup test 'should create two new tags from "one,two"' do UserSession.create(users(:bob)) assert_difference 'UserTag.count', 2 do - xhr :post, :create, name: 'one,two', nid: nodes(:one).nid, id: users(:bob).id + post :create, params: { name: 'one,two', nid: nodes(:one).nid, id: users(:bob).id }, xhr: true end assert_response :success assert_equal [['one', UserTag.where(value: 'one').first.id], ['two', UserTag.where(value: 'two').first.id]], JSON.parse(response.body)['saved'] @@ -33,62 +33,62 @@ def setup test 'should delete existing tag' do UserSession.create(users(:bob)) user_tag = user_tags(:one) - delete :delete , id: users(:bob).id , name: user_tag.name + delete :delete , params: { id: users(:bob).id , name: user_tag.name } assert_equal 'Tag deleted.', flash[:notice] assert_redirected_to info_path end test 'cannot delete non-existent tag' do UserSession.create(users(:bob)) - delete :delete, id: users(:bob).id , name: "temp tag" + delete :delete, params: { id: users(:bob).id , name: "temp tag" } assert_equal "Tag doesn't exist.", flash[:error] assert_redirected_to info_path end test 'should not create duplicate tag' do UserSession.create(users(:bob)) - post :create, id: users(:bob).id, name: 'environment' + post :create, params: { id: users(:bob).id, name: 'environment' } # duplicate tag - post :create, id: users(:bob).id, name: 'environment' + post :create, params: {id: users(:bob).id, name: 'environment' } assert_equal 'Error: tag already exists.', assigns[:output][:errors][0] assert_redirected_to "/profile/#{users(:bob).username}" end test 'should not allow empty tag name' do UserSession.create(users(:bob)) - post :create, id: users(:bob).id, value: '' + post :create, params: { id: users(:bob).id, value: '' } assert_equal 'Error: value cannot be empty', assigns[:output][:errors][0] assert_redirected_to "/profile/#{users(:bob).username}" end test 'admin should delete existing tag of normal user' do UserSession.create(users(:bob)) - post :create, id: users(:bob).id, name: 'role:organizer' + post :create, params: { id: users(:bob).id, name: 'role:organizer' } user_tag = UserTag.where(uid: users(:bob).id).last user_tags_count = UserTag.where(uid: users(:bob).id).count # Delete above tag UserSession.create(users(:jeff)) - delete :delete, id: users(:bob).id , name: user_tag.name + delete :delete, params: { id: users(:bob).id , name: user_tag.name } assert_equal user_tags_count - 1, UserTag.where(uid: users(:bob).id).count end test 'admin should create new tags for normal user' do UserSession.create(users(:jeff)) user_tags_count = UserTag.where(uid: users(:bob).id).count - post :create, id: users(:bob).id, name: 'role:organizer' + post :create, params: { id: users(:bob).id, name: 'role:organizer' } assert_equal user_tags_count + 1, UserTag.where(uid: users(:bob).id).count end test 'Normal user should not create tag for other user' do UserSession.create(users(:bob)) - post :create, id: users(:jeff).id, name: 'role:organizer' + post :create, params: { id: users(:jeff).id, name: 'role:organizer' } assert_equal 'Only admin (or) target user can manage tags', assigns[:output][:errors][0] end test 'Normal user should not delete tag for other user' do user_tag = UserTag.where(uid: users(:jeff).id).last UserSession.create(users(:bob)) - delete :delete, id: users(:jeff).id , name: user_tag.name + delete :delete, params: { id: users(:jeff).id , name: user_tag.name } assert_equal 'Only admin (or) target user can manage tags', flash[:error] end @@ -97,12 +97,12 @@ def setup old_controller = @controller @controller = SettingsController.new - get :change_locale, locale: lang.to_s + get :change_locale, params: { locale: lang.to_s } @controller = old_controller UserSession.create(users(:bob)) - delete :delete, id: users(:bob).id , name: "temp tag" + delete :delete, params: { id: users(:bob).id , name: "temp tag" } assert_equal I18n.t('user_tags_controller.tag_doesnt_exist'), flash[:error] end end diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb index fca820e7c0..3302a76857 100644 --- a/test/functional/users_controller_test.rb +++ b/test/functional/users_controller_test.rb @@ -1,14 +1,3 @@ -# def new -# def create -# def update -# def edit -# def list -# def likes -# def rss -# def reset -# def comments -# def photo - require 'test_helper' class UsersControllerTest < ActionController::TestCase @@ -60,25 +49,25 @@ def setup test 'list users by moderator role' do UserSession.create(users(:bob)) - get :list, id: 'moderator' + get :list, params: { id: 'moderator' } assert_response :success assert_not_nil :users end test 'list users by admin role' do UserSession.create(users(:bob)) - get :list, id: 'admin' + get :list, params: { id: 'admin' } assert_response :success assert_not_nil :users end test 'should not get spam profile' do - get :profile, id: User.find(3).username # spam user + get :profile, params: { id: User.find(3).username } assert_response 302 end test 'should get profile' do - get :profile, id: DrupalUser.where(status: 1).first.name + get :profile, params: { id: DrupalUser.where(status: 1).first.name } assert_response :success end @@ -86,7 +75,7 @@ def setup user = users(:jeff) assert_nil user.reset_key - get :reset, email: user.email + get :reset, params: { email: user.email } assert_not_nil User.find(user.id).reset_key @@ -105,8 +94,7 @@ def setup user_attributes[:password] = 'newpassword' user_attributes[:password_confirmation] = 'newpassword' - get :reset, key: key, - user: user_attributes + get :reset, params: { key: key, user: user_attributes } assert_response :redirect assert_redirected_to '/dashboard' @@ -124,7 +112,7 @@ def setup user.save({}) assert_not_nil User.find(user.id).reset_key - get :profile, id: user.username + get :profile, params: { id: user.username } selector = css_select 'a.user-reset-key' assert_equal selector.size, 0 @@ -138,7 +126,7 @@ def setup user.save({}) assert_not_nil User.find(user.id).reset_key - get :profile, id: user.username + get :profile, params: { id: user.username } assert_select 'a#user-reset-key' end @@ -148,73 +136,15 @@ def setup old_controller = @controller @controller = SettingsController.new - get :change_locale, locale: lang.to_s + get :change_locale, params: { locale: lang.to_s } @controller = old_controller end end - # test "should display map with success response" do - # UserSession.create(users(:jeff)) - # get :map - # assert_response 200 - # end - - # test "should display users map based on location" do - # UserSession.create(users(:jeff)) - # get :map, :country => 'United States', tag: "", value: "" - # assert_response 200 - # assert assigns[:users] - # end - - # test "should display user map on tag and value parameter" do - # UserSession.create(users(:jeff)) - # get :map, :tag => 'Skill', :value => 'Developer', country: '' - # assert_response 200 - # assert assigns[:location_tags] - # assert assigns[:location_tags].is_a? Hash - # end - - # test "should display flash error for invalid tag" do - # UserSession.create(users(:jeff)) - # get :map, :tag => 'abc', value: '', country: '' - # assert_response 200 - # assert_equal "abc doesn't exitst", flash[:error] - # end - - # def test_create_invalid - # User.any_instance.stubs(:valid?).returns(false) - # post :create - # assert_template 'new' - # end - - # def test_create_valid - # User.any_instance.stubs(:valid?).returns(true) - # post :create - # assert_redirected_to root_url - # end - - # def test_edit - # user = FactoryGirl.create(:user) - # get :edit, :id => user.id - # assert_template 'edit' - # end - - # def test_update_invalid - # User.any_instance.stubs(:valid?).returns(false) - # put :update, :id => FactoryGirl.create(:user).id - # assert_template 'edit' - # end - - # def test_update_valid - # User.any_instance.stubs(:valid?).returns(true) - # put :update, :id => User.first - # assert_redirected_to root_url - # end - test 'should list notes and questions in user profile' do user = drupal_users(:jeff) - get :profile, id: user.name + get :profile, params: { id: user.name } assert_not_nil assigns(:notes) assert_not_nil assigns(:questions) assert_not_nil assigns(:answered_questions) @@ -226,7 +156,7 @@ def setup test 'should get comments' do user = drupal_users(:jeff) - get :comments, id: user.id + get :comments, params: { id: user.id } assert_response :success assert_not_nil assigns(:comments) assert_template partial: 'comments/_comments' @@ -240,7 +170,7 @@ def setup test 'creating new account' do assert_difference 'User.count', 1 do - post :create, { + post :create, params: { user: { username: 'eleven', password: 'demagorgon', @@ -266,21 +196,21 @@ def setup test 'updating profile' do user = users(:bob) UserSession.create(user) - post :update, { user: { bio: 'Hello, there!' } } + post :update, params: { user: { bio: 'Hello, there!' } } assert_response :redirect assert_equal User.find(user.id).bio, 'Hello, there!' end test 'should redirect edit when not logged in' do user = drupal_users(:bob) - get :edit, { id: user.name } + get :edit, params: { id: user.name } assert_not flash.empty? assert_redirected_to '/login' end test 'should redirect update when not logged in' do user = users(:bob) - post :update, { user: { bio: 'Hello, there!' } } + post :update, params: { user: { bio: 'Hello, there!' } } assert_not flash.empty? assert_redirected_to '/login' end @@ -289,7 +219,7 @@ def setup user = users(:bob) UserSession.create(user) new_user = drupal_users(:newcomer).user - get :edit, { id: new_user.name } + get :edit, params: { id: new_user.name } assert_not flash.empty? assert_redirected_to '/profile/' + new_user.name end @@ -298,20 +228,20 @@ def setup user = users(:bob) email = users(:bob).email UserSession.create(user) - post :update, { user: { email: 'not an address' } } + post :update, params: { user: { email: 'not an address' } } assert_response :success assert_equal user.email, email end test 'rss feed when username is valid' do user = drupal_users(:jeff) - get :rss, author: user.name, format: 'rss' + get :rss, params: { author: user.name, format: 'rss' } assert_response :success - assert_equal 'application/rss+xml', @response.content_type + assert_equal 'application/xml', @response.content_type end test 'rss feed when username is not valid' do - get :rss, author: 'some hacker' + get :rss, params: { author: 'some hacker' } assert_response :redirect assert_equal I18n.t('users_controller.no_user_found'), flash[:error] end diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index 6dc46a6757..6c20309928 100644 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -25,7 +25,7 @@ def teardown end test 'should get wiki index in alphabetical order' do - get :index, order: 'alphabetic' + get :index, params: { order: 'alphabetic' } assert_response :success assert_not_nil :wikis @@ -42,8 +42,10 @@ def teardown UserSession.create(users(:bob)) get :new, + params: { tags: 'one,two', n: nodes(:blog).id + } assert_response :success assert_select '#taginput[value=?]', 'one,two' @@ -51,7 +53,7 @@ def teardown end test 'should get raw wiki markup' do - get :raw, id: revisions(:one).id + get :raw, params: { id: revisions(:one).id } assert_response :success end @@ -64,7 +66,7 @@ def teardown nodes(:about).save assert_difference 'Impression.count', 1 do - get :show, id: nodes(:about).slug + get :show, params: { id: nodes(:about).slug } assert_response :success end @@ -72,7 +74,7 @@ def teardown end test 'should get root-level (/about) wiki page' do - get :root, id: 'about' + get :root, params: { id: 'about' } assert_response :success end @@ -93,19 +95,23 @@ def teardown title = 'All about balloon mapping' post :create, + params: { uid: users(:bob).id, title: title, body: 'This is fascinating documentation about balloon mapping.', tags: 'balloon-mapping,event' + } assert_redirected_to '/wiki/' + title.parameterize end test 'post wiki with bad title' do post :create, + params: { uid: users(:bob).id, title: '', body: 'This is fascinating documentation about balloon mapping.' + } assert_template 'editor/wikiRich' selector = css_select '.alert' @@ -114,7 +120,9 @@ def teardown test 'viewing edit wiki page' do get :edit, + params: { id: 'organizers' + } assert_template 'wiki/edit' assert_not_nil assigns(:title) @@ -126,13 +134,8 @@ def teardown wiki = nodes(:organizers) newtitle = 'New Title' - post :update, - id: wiki.nid, - uid: users(:bob).id, - title: newtitle, - body: 'Editing about Page' + post :update, params: { id: wiki.nid, uid: users(:bob).id, title: newtitle, body: 'Editing about Page' } - wiki.reload assert_redirected_to wiki.path assert_equal flash[:notice], 'Edits saved.' end @@ -142,7 +145,9 @@ def teardown # then try editing it assert_difference 'Revision.count', 0 do post :edit, + params: { id: 'organizers' + } end assert_equal flash[:warning], "This page is locked, and only moderators can edit it." assert_redirected_to nodes(:organizers).path @@ -153,7 +158,9 @@ def teardown # then try editing it assert_difference 'Revision.count', 0 do post :update, + params: { id: nodes(:organizers).id + } end assert_equal flash[:warning], "This page is locked, and only moderators can update it." assert_redirected_to nodes(:organizers).path @@ -161,9 +168,11 @@ def teardown test 'updating wiki with bad title' do post :update, + params: { id: nodes(:organizers).id, uid: users(:bob).id, title: '' + } assert_template 'wiki/edit' selector = css_select '.alert' @@ -175,11 +184,7 @@ def teardown newtitle = 'New Title' assert_equal wiki.path, '/about' - post :update, - id: wiki.nid, - uid: users(:bob).id, - title: newtitle, - body: 'Editing about Page' + post :update, params: { id: wiki.nid, uid: users(:bob).id, title: newtitle, body: 'Editing about Page' } wiki.reload assert_redirected_to wiki.path @@ -190,13 +195,7 @@ def teardown node = nodes(:about) image = fixture_file_upload 'rails.png' - post :update, - id: node.nid, - uid: users(:bob).id, - title: 'New Title', - body: 'Editing about Page', - image: { title: 'new image', - photo: image } + post :update, params: { id: node.nid, uid: users(:bob).id, title: 'New Title', body: 'Editing about Page', image: { title: 'new image', photo: image } } node.reload assert_redirected_to node.path @@ -207,12 +206,7 @@ def teardown node = nodes(:about) image = node.images.where(photo_file_name: 'filename-1.jpg').last - post :update, - id: node.nid, - uid: users(:bob).id, - title: 'New Title', - body: 'Editing about Page', - image_revision: image.path(:default) + post :update, params: { id: node.nid, uid: users(:bob).id, title: 'New Title', body: 'Editing about Page', image_revision: image.path(:default) } node.reload assert_redirected_to node.path @@ -222,7 +216,7 @@ def teardown test 'normal user should not delete wiki page' do wiki = nodes(:about) - post :delete, id: wiki.nid + post :delete, params: { id: wiki.nid } assert_equal flash[:error], 'Only admins can delete wiki pages.' assert_redirected_to wiki.path @@ -233,7 +227,7 @@ def teardown UserSession.find.destroy UserSession.create(users(:admin)) - post :delete, id: wiki.nid + post :delete, params: { id: wiki.nid } assert_equal flash[:notice], 'Wiki page deleted.' assert_redirected_to '/dashboard' @@ -271,7 +265,7 @@ def teardown UserSession.find.destroy UserSession.create(users(:admin)) - get :root, id: 'about' + get :root, params: { id: 'about' } assert_response :success UserSession.find.destroy @@ -281,7 +275,7 @@ def teardown UserSession.find.destroy UserSession.create(users(:admin)) - get :root, id: 'madeup' + get :root, params: { id: 'madeup' } assert_redirected_to '/wiki/madeup' UserSession.find.destroy @@ -292,7 +286,7 @@ def teardown UserSession.create(users(:admin)) wiki = nodes(:spam_targeted_page) - get :revert, id: wiki.latest.vid # currently, just revert to same, which clones latest + get :revert, params: { id: wiki.latest.vid } # currently, just revert to same, which clones latest assert_equal flash[:notice], 'The wiki page was reverted.' assert_nil flash[:error] @@ -303,21 +297,21 @@ def teardown test 'user cannot revert wiki page' do wiki = nodes(:spam_targeted_page) - get :revert, id: wiki.latest.vid + get :revert, params: { id: wiki.latest.vid } assert_equal flash[:error], 'Only moderators and admins can delete wiki pages.' assert_redirected_to '/wiki/' + wiki.slug end test 'should display revisions' do - get :revisions, id: nodes(:spam_targeted_page).id + get :revisions, params: { id: nodes(:spam_targeted_page).id } assert_response :success assert_template :revisions end test 'should not error if no node exist' do - get :revisions, id: 'Invalid Node' + get :revisions, params: { id: 'Invalid Node' } assert_template :revisions assert_equal flash[:error], 'Invalid wiki page. No Revisions exist for this wiki page.' @@ -327,7 +321,7 @@ def teardown revision = revisions(:unmoderated_spam_revision) revision.spam - get :revision, id: revision.parent.slug, vid: revision.vid + get :revision, params: { id: revision.parent.slug, vid: revision.vid } assert_equal "That revision has been moderated. Please see the moderation page to learn more.", flash[:error] assert_redirected_to revision.parent.path @@ -337,7 +331,7 @@ def teardown revision = revisions(:unmoderated_spam_revision) revision.spam - get :revision, id: revision.parent.slug, vid: revision.vid + get :revision, params: { id: revision.parent.slug, vid: revision.vid } assert_equal "That revision has been moderated. Please see the moderation page to learn more.", flash[:error] assert_redirected_to revision.parent.path @@ -346,7 +340,7 @@ def teardown test 'should display individual revision' do revision = revisions(:unmoderated_spam_revision) - get :revision, id: revision.parent.slug, vid: revision.vid + get :revision, params: { id: revision.parent.slug, vid: revision.vid } assert_template 'show' assert_response :success @@ -361,7 +355,7 @@ def teardown test 'should display individual revision that is not the latest' do revision = revisions(:about_rev_2) - get :revision, id: revision.parent.slug, vid: revision.vid + get :revision, params: { id: revision.parent.slug, vid: revision.vid } assert_template 'show' assert_response :success @@ -374,14 +368,14 @@ def teardown test 'should display individual raw revision' do revision = revisions(:about) - get :raw, id: revision.vid + get :raw, params: { id: revision.vid } assert_response :success assert_equal @response.body, revision.body end test 'should display error message for invalid revision' do - get :revision, id: nodes(:about).slug, vid: -3 + get :revision, params: { id: nodes(:about).slug, vid: -3 } assert_equal flash[:error], 'Revision not found.' end @@ -414,18 +408,14 @@ def teardown old_controller = @controller @controller = SettingsController.new - get :change_locale, locale: lang.to_s + get :change_locale, params: { locale: lang.to_s } @controller = old_controller wiki = nodes(:organizers) newtitle = 'New Title' - post :update, - id: wiki.nid, - uid: users(:bob).id, - title: newtitle, - body: 'Editing about Page' + post :update, params: { id: wiki.nid, uid: users(:bob).id, title: newtitle, body: 'Editing about Page' } wiki.reload assert_redirected_to wiki.path @@ -436,13 +426,13 @@ def teardown test 'should get wiki with different title and path' do wiki = nodes(:wiki_page) slug = wiki.path.gsub('/wiki/', '') - get :show, id: slug + get :show, params: { id: slug } assert_response :success end test "should show the wiki post page if wiki page doesn't exist" do UserSession.create(users(:jeff)) - get :show, id: 'A-new-wiki-page' + get :show, params: { id: 'A-new-wiki-page' } assert_response :success assert_template 'wiki/edit' end @@ -453,7 +443,7 @@ def teardown assert_difference 'Revision.count' do assert_difference "Node.find(#{node.id}).revisions.count" do - get :replace, id: node.id, before: 'Public', after: 'Private' + get :replace, params: { id: node.id, before: 'Public', after: 'Private' } end end @@ -469,7 +459,7 @@ def teardown assert_difference 'Revision.count' do assert_difference "Node.find(#{node.id}).revisions.count" do - xhr :post, :replace, id: node.id, before: 'Public', after: 'Private' + post :replace, params: { id: node.id, before: 'Public', after: 'Private' }, xhr: true end end @@ -488,7 +478,7 @@ def teardown assert_difference 'Revision.count', 0 do assert_difference "Node.find(#{node.id}).revisions.count", 0 do - xhr :post, :replace, id: node.id, before: 'Elephants', after: 'Tigers' + post :replace, params: { id: node.id, before: 'Elephants', after: 'Tigers' }, xhr: true end end @@ -507,7 +497,7 @@ def teardown wiki.add_tag("abtest:#{place.nid}", users(:bob)) assert_equal wiki.power_tag('abtest'), place.nid.to_s - get :show, id: slug + get :show, params: { id: slug } # assert_response :success # we can't assert this since ~50% of the time it'll redirect end @@ -518,7 +508,7 @@ def teardown wiki.add_tag('redirect:nonsense', users(:bob)) assert_equal wiki.power_tag('redirect'), 'nonsense' - get :show, id: slug + get :show, params: { id: slug } assert_response :success end @@ -529,7 +519,7 @@ def teardown wiki.add_tag("redirect:#{blog.nid}", users(:bob)) assert_equal wiki.power_tag('redirect'), blog.nid.to_s - get :show, id: slug + get :show, params: { id: slug } assert_redirected_to blog.path end @@ -542,7 +532,7 @@ def teardown UserSession.find.destroy if UserSession.find UserSession.create(users(:jeff)) - get :show, id: slug + get :show, params: { id: slug } assert_response :success assert_equal "Only moderators and admins see this page, as it is redirected to #{blog.title}. @@ -569,14 +559,14 @@ def teardown end test 'should get methods page for given topic' do - get :methods, topic: 'mining' + get :methods, params: { topic: 'mining' } assert_response :success assert_not_nil :nodes end test 'should get methods page for given topic, for non-existent topic' do - get :methods, topic: 'mining' + get :methods, params: { topic: 'mining' } assert_response :success assert_not_nil :nodes @@ -590,14 +580,14 @@ def teardown assert_equal false, @node.has_power_tag('date') # assert_equal "anything goes", DateTime.strptime(@node.power_tag('date'),'%m- %d-%Y').to_date.to_s(:long) - get :show, id: @node.slug + get :show, params: { id: @node.slug } assert_response :success end test "should render comment template when comment icon is clicked" do wiki = nodes(:wiki_page) slug = wiki.path.gsub('/wiki/', '') - get :comments, id: slug + get :comments, params: { id: slug } assert_response :success assert_select 'div#comments h3', /Comments/ end @@ -608,7 +598,7 @@ def teardown wiki.add_tag("redirect:about", users(:bob)) assert_equal wiki.power_tag('redirect'), "about" - get :show, id: slug + get :show, params: { id: slug } assert_redirected_to "http://test.host/about" end diff --git a/test/integration/I18n_test.rb b/test/integration/I18n_test.rb index c8b69a02ae..dc54eed07b 100644 --- a/test/integration/I18n_test.rb +++ b/test/integration/I18n_test.rb @@ -5,15 +5,19 @@ class I18nTest < ActionDispatch::IntegrationTest test 'should choose i18n-locale for header partial' do available_testing_locales.each do |lang| - get '/home' - get_via_redirect '/change_locale/' + lang.to_s - assert_select 'p[class=facebook-summary]', I18n.t('layout._header.summary') - post '/user_sessions', user_session: { - username: users(:jeff).username, - password: 'secretive' - } - follow_redirect! - get_via_redirect '/dashboard', locale: lang + # This test could use a rewrite. Two `get`s in succession? + # get '/home' + # get '/change_locale/' + lang.to_s + # follow_redirect! + # assert_select 'p[class=facebook-summary]', I18n.t('layout._header.summary') + post '/user_sessions', + params: { + user_session: { + username: users(:jeff).username, + password: 'secretive' + } + } + get '/dashboard', params: { locale: lang } assert_select 'a[href=?]', '/dashboard' end end @@ -23,7 +27,8 @@ class I18nTest < ActionDispatch::IntegrationTest get '/change_locale/' + lang.to_s follow_redirect! assert_equal lang.to_s, I18n.locale.to_s - get_via_redirect '/dashboard' + get '/dashboard' + follow_redirect! assert_equal lang.to_s, I18n.locale.to_s end end @@ -37,10 +42,13 @@ class I18nTest < ActionDispatch::IntegrationTest test 'should choose i18n for subscriptions' do available_testing_locales.each do |lang| get '/change_locale/' + lang.to_s - post '/user_sessions', user_session: { - username: users(:jeff).username, - password: 'secretive' - } + post '/user_sessions', + params: { + user_session: { + username: users(:jeff).username, + password: 'secretive' + } + } follow_redirect! get '/subscriptions' assert_select 'b', I18n.t('home.subscriptions.title') @@ -50,10 +58,13 @@ class I18nTest < ActionDispatch::IntegrationTest test 'should choose i18n for dashboard/_activity' do available_testing_locales.each do |lang| get '/change_locale/' + lang.to_s - post '/user_sessions', user_session: { - username: users(:jeff).username, - password: 'secretive' - } + post '/user_sessions', + params: { + user_session: { + username: users(:jeff).username, + password: 'secretive' + } + } follow_redirect! assert_select 'h3', I18n.t('dashboard._activity.activity') end @@ -62,10 +73,13 @@ class I18nTest < ActionDispatch::IntegrationTest test 'should choose i18n for dashboard/_header' do available_testing_locales.each do |lang| get '/change_locale/' + lang.to_s - post '/user_sessions', user_session: { - username: users(:jeff).username, - password: 'secretive' - } + post '/user_sessions', + params: { + user_session: { + username: users(:jeff).username, + password: 'secretive' + } + } follow_redirect! assert_select 'h1', I18n.t('dashboard._header.dashboard') end @@ -75,10 +89,13 @@ class I18nTest < ActionDispatch::IntegrationTest available_testing_locales.each do |lang| get '/change_locale/' + lang.to_s follow_redirect! - post '/user_sessions', user_session: { - username: users(:jeff).username, - password: 'secretive' - } + post '/user_sessions', + params: { + user_session: { + username: users(:jeff).username, + password: 'secretive' + } + } follow_redirect! get '/dashboard' assert_select 'span', I18n.t('dashboard._node_comment.commented_on') @@ -89,16 +106,21 @@ class I18nTest < ActionDispatch::IntegrationTest available_testing_locales.each do |lang| get '/change_locale/' + lang.to_s follow_redirect! - post '/user_sessions', user_session: { - username: users(:jeff).username, - password: 'secretive' - } + post '/user_sessions', + params: { + user_session: { + username: users(:jeff).username, + password: 'secretive' + } + } follow_redirect! post '/notes/create', + params: { title: 'Some post', body: 'Some post body', tags: 'Some-tag', status: 4 + } get '/dashboard' assert_select 'a[class=?]', 'btn btn-default btn-xs', I18n.t('dashboard._node_moderate.approve') end @@ -108,15 +130,20 @@ class I18nTest < ActionDispatch::IntegrationTest available_testing_locales.each do |lang| get '/change_locale/' + lang.to_s follow_redirect! - post '/user_sessions', user_session: { - username: users(:jeff).username, - password: 'secretive' - } + post '/user_sessions', + params: { + user_session: { + username: users(:jeff).username, + password: 'secretive' + } + } follow_redirect! post '/notes/create', + params: { title: 'Some question', tags: 'question', status: 1 + } get '/dashboard' assert_select 'a[class=?]', 'btn btn-default btn-xs pull-right respond answer', I18n.t('dashboard._node_question.post_answer') end @@ -126,16 +153,21 @@ class I18nTest < ActionDispatch::IntegrationTest available_testing_locales.each do |lang| get '/change_locale/' + lang.to_s follow_redirect! - post '/user_sessions', user_session: { - username: users(:jeff).username, - password: 'secretive' - } + post '/user_sessions', + params: { + user_session: { + username: users(:jeff).username, + password: 'secretive' + } + } follow_redirect! post '/notes/create', + params: { title: 'Some topic', tags: 'some-tag', type: 'page', status: 1 + } get '/dashboard' assert_select 'span', I18n.t('dashboard._node_wiki.new_page_by') end @@ -145,10 +177,13 @@ class I18nTest < ActionDispatch::IntegrationTest available_testing_locales.each do |lang| get '/change_locale/' + lang.to_s follow_redirect! - post '/user_sessions', user_session: { - username: users(:jeff).username, - password: 'secretive' - } + post '/user_sessions', + params: { + user_session: { + username: users(:jeff).username, + password: 'secretive' + } + } follow_redirect! get '/dashboard' assert_select 'a', I18n.t('dashboard._wiki.more') + Sanitize.clean(' »') @@ -171,10 +206,13 @@ class I18nTest < ActionDispatch::IntegrationTest get '/change_locale/' + lang.to_s follow_redirect! - post '/user_sessions', user_session: { - username: users(:jeff).username, - password: 'secretive' - } + post '/user_sessions', + params: { + user_session: { + username: users(:jeff).username, + password: 'secretive' + } + } follow_redirect! get '/profile/edit' @@ -188,10 +226,13 @@ class I18nTest < ActionDispatch::IntegrationTest get '/change_locale/' + lang.to_s follow_redirect! - post '/user_sessions', user_session: { - username: users(:jeff).username, - password: 'secretive' - } + post '/user_sessions', + params: { + user_session: { + username: users(:jeff).username, + password: 'secretive' + } + } follow_redirect! username = users(:jeff).username.to_s @@ -226,10 +267,13 @@ class I18nTest < ActionDispatch::IntegrationTest get '/change_locale/' + lang.to_s follow_redirect! - post '/user_sessions', user_session: { - username: users(:jeff).username, - password: 'secretive' - } + post '/user_sessions', + params: { + user_session: { + username: users(:jeff).username, + password: 'secretive' + } + } follow_redirect! get '/profile/' + users(:jeff).username @@ -242,10 +286,13 @@ class I18nTest < ActionDispatch::IntegrationTest get '/change_locale/' + lang.to_s follow_redirect! - post '/user_sessions', user_session: { - username: users(:jeff).username, - password: 'secretive' - } + post '/user_sessions', + params: { + user_session: { + username: users(:jeff).username, + password: 'secretive' + } + } follow_redirect! get '/reset' @@ -270,10 +317,13 @@ class I18nTest < ActionDispatch::IntegrationTest get '/change_locale/' + lang.to_s follow_redirect! - post '/user_sessions', user_session: { - username: users(:jeff).username, - password: 'secretive' - } + post '/user_sessions', + params: { + user_session: { + username: users(:jeff).username, + password: 'secretive' + } + } follow_redirect! get '/wiki' @@ -287,10 +337,13 @@ class I18nTest < ActionDispatch::IntegrationTest get '/change_locale/' + lang.to_s follow_redirect! - post '/user_sessions', user_session: { - username: users(:jeff).username, - password: 'secretive' - } + post '/user_sessions', + params: { + user_session: { + username: users(:jeff).username, + password: 'secretive' + } + } follow_redirect! wiki = nodes(:about) @@ -323,10 +376,13 @@ class I18nTest < ActionDispatch::IntegrationTest get '/change_locale/' + lang.to_s follow_redirect! - post '/user_sessions', user_session: { - username: users(:jeff).username, - password: 'secretive' - } + post '/user_sessions', + params: { + user_session: { + username: users(:jeff).username, + password: 'secretive' + } + } follow_redirect! get '/notes/author/' + users(:jeff).username @@ -350,10 +406,13 @@ class I18nTest < ActionDispatch::IntegrationTest get '/change_locale/' + lang.to_s follow_redirect! - post '/user_sessions', user_session: { - username: users(:jeff).username, - password: 'secretive' - } + post '/user_sessions', + params: { + user_session: { + username: users(:jeff).username, + password: 'secretive' + } + } follow_redirect! get nodes(:one).path @@ -426,10 +485,13 @@ class I18nTest < ActionDispatch::IntegrationTest get '/change_locale/' + lang.to_s follow_redirect! - post '/user_sessions', user_session: { - username: users(:jeff).username, - password: 'secretive' - } + post '/user_sessions', + params: { + user_session: { + username: users(:jeff).username, + password: 'secretive' + } + } follow_redirect! get nodes(:one).path @@ -462,10 +524,13 @@ class I18nTest < ActionDispatch::IntegrationTest get '/change_locale/' + lang.to_s follow_redirect! - post '/user_sessions', user_session: { - username: users(:jeff).username, - password: 'secretive' - } + post '/user_sessions', + params: { + user_session: { + username: users(:jeff).username, + password: 'secretive' + } + } follow_redirect! get nodes(:first_timer_note).path diff --git a/test/integration/login_flow_test.rb b/test/integration/login_flow_test.rb index 8e9872407b..f209d43be4 100644 --- a/test/integration/login_flow_test.rb +++ b/test/integration/login_flow_test.rb @@ -6,28 +6,20 @@ class LoginFlowTest < ActionDispatch::IntegrationTest follow_redirect! assert_equal '/login', path - post '/user_sessions', user_session: { - username: users(:jeff).username, - password: 'secretive' - } + post '/user_sessions', params: { user_session: { username: users(:jeff).username, password: 'secretive' } } + follow_redirect! assert_equal '/post?tags=question:question&template=question', request.fullpath end # This test depend on question based search functionality test 'search a question and go through post mechanism if question not found when user is not logged in' do - get '/post', tags: 'question:question', - template: 'question', - title: 'What', - redirect: 'question' + get '/post', params: { tags: 'question:question', template: 'question', title: 'What', redirect: 'question' } follow_redirect! assert_equal '/login', path - post '/user_sessions', user_session: { - username: users(:jeff).username, - password: 'secretive' - } + post '/user_sessions', params: { user_session: { username: users(:jeff).username, password: 'secretive' } } follow_redirect! assert_response :redirect @@ -42,12 +34,8 @@ class LoginFlowTest < ActionDispatch::IntegrationTest get '/questions' assert_response :success - post '/user_sessions', - return_to: request.path, - user_session: { - username: users(:jeff).username, - password: 'secretive' - } + post '/user_sessions', params: { return_to: request.path, user_session: { username: users(:jeff).username, password: 'secretive' } } + follow_redirect! assert_equal '/questions', path end diff --git a/test/integration/moderate_and_ban_test.rb b/test/integration/moderate_and_ban_test.rb index a89828e608..eb22a24c09 100644 --- a/test/integration/moderate_and_ban_test.rb +++ b/test/integration/moderate_and_ban_test.rb @@ -3,10 +3,7 @@ class ModerateAndBanTest < ActionDispatch::IntegrationTest test 'users are logged out and alerted when banned, and notes are not accessible' do u = users(:unmoderated_user) - post '/user_sessions', user_session: { - username: u.username, - password: 'secretive' - } + post '/user_sessions', params: { user_session: { username: u.username, password: 'secretive' } } get '/post' # dashboard is actually world-readable, but /post is not @@ -50,10 +47,7 @@ class ModerateAndBanTest < ActionDispatch::IntegrationTest test 'users are logged out and alerted when moderated, and notes are not accessible' do u = users(:unmoderated_user) - post '/user_sessions', user_session: { - username: u.username, - password: 'secretive' - } + post '/user_sessions', params: { user_session: { username: u.username, password: 'secretive' } } get '/post' # dashboard is actually world-readable, but /post is not @@ -100,10 +94,7 @@ class ModerateAndBanTest < ActionDispatch::IntegrationTest u.drupal_user.ban admin = users(:admin) - post '/user_sessions', user_session: { - username: admin.username, - password: 'secretive' - } + post '/user_sessions', params: { user_session: { username: admin.username, password: 'secretive' } } get "/profile/#{u.username}" @@ -117,10 +108,7 @@ class ModerateAndBanTest < ActionDispatch::IntegrationTest u.drupal_user.unmoderate u.drupal_user.unban - post '/user_sessions', user_session: { - username: admin.username, - password: 'secretive' - } + post '/user_sessions', params: { user_session: { username: admin.username, password: 'secretive' } } get "/admin/moderate/#{u.uid}" @@ -143,10 +131,7 @@ class ModerateAndBanTest < ActionDispatch::IntegrationTest u.drupal_user.unmoderate u.drupal_user.unban - post '/user_sessions', user_session: { - username: normal_user.username, - password: 'secretive' - } + post '/user_sessions', params: { user_session: { username: normal_user.username, password: 'secretive' } } get "/admin/moderate/#{u.uid}" @@ -169,10 +154,13 @@ class ModerateAndBanTest < ActionDispatch::IntegrationTest u = users(:unmoderated_user) u.drupal_user.moderate - post '/user_sessions', user_session: { + post '/user_sessions', + params: { + user_session: { username: u.username, password: 'secretive' - } + } + } assert_response :redirect follow_redirect! diff --git a/test/integration/node_insert_extras_test.rb b/test/integration/node_insert_extras_test.rb index 15685585a5..0ee6b21b12 100644 --- a/test/integration/node_insert_extras_test.rb +++ b/test/integration/node_insert_extras_test.rb @@ -2,17 +2,20 @@ class NodeInsertExtrasTest < ActionDispatch::IntegrationTest test 'note with inline tagged notes table via insert_extras() helper' do - post '/user_sessions', user_session: { + post '/user_sessions', params: { user_session: { username: users(:jeff).username, password: 'secretive' } + } title = 'One more post about balloon mapping' post '/notes/create', + params: { title: title, body: "This is a fascinating post about a balloon mapping event. \n\n[notes:test] \n\n[activities:test] \n\n `[notes:shouldnt]` \n\n[upgrades:test]", tags: 'test' + } follow_redirect! diff --git a/test/integration/node_series_tag_test.rb b/test/integration/node_series_tag_test.rb index 982622d735..ec391e6748 100644 --- a/test/integration/node_series_tag_test.rb +++ b/test/integration/node_series_tag_test.rb @@ -2,17 +2,14 @@ class NodeSeriesTagTest < ActionDispatch::IntegrationTest test 'add series tag' do - post '/user_sessions', user_session: { - username: users(:bob).username, - password: 'secretive' - } + post '/user_sessions', params: { user_session: { username: users(:bob).username, password: 'secretive'} } title = 'My second post about balloon mapping' - post '/notes/create', + post '/notes/create', params: { title: title, body: 'This is a fascinating post about a balloon mapping event.', - tags: 'series:balloons' + tags: 'series:balloons' } follow_redirect! assert_equal '/notes/' + users(:bob).username + '/' + @@ -26,8 +23,7 @@ class NodeSeriesTagTest < ActionDispatch::IntegrationTest node.publish # visiting note with original path - get '/notes/' + users(:bob).username + '/' + - Time.now.strftime('%m-%d-%Y') + '/' + title.parameterize + get '/notes/' + users(:bob).username + '/' + Time.now.strftime('%m-%d-%Y') + '/' + title.parameterize assert_select 'div', 'This is part of a series on balloons.' end end diff --git a/test/integration/node_update_test.rb b/test/integration/node_update_test.rb index 66b2d39c78..fd39927cd5 100644 --- a/test/integration/node_update_test.rb +++ b/test/integration/node_update_test.rb @@ -2,17 +2,11 @@ class NodeUpdateTest < ActionDispatch::IntegrationTest test 'edit note after creating a new note' do - post '/user_sessions', user_session: { - username: users(:bob).username, - password: 'secretive' - } + post '/user_sessions', params: { user_session: { username: users(:bob).username, password: 'secretive' } } title = 'My second post about balloon mapping' - post '/notes/create', - title: title, - body: 'This is a fascinating post about a balloon mapping event.', - tags: 'balloon-mapping,event' + post '/notes/create', params: { title: title, body: 'This is a fascinating post about a balloon mapping event.', tags: 'balloon-mapping,event' } follow_redirect! assert_equal '/notes/' + users(:bob).username + '/' + @@ -27,9 +21,12 @@ class NodeUpdateTest < ActionDispatch::IntegrationTest newtitle = title + ' which I amended' post '/notes/update/' + node.id.to_s, - title: newtitle, - body: "This is a fascinating post about a balloon mapping event. added content", - tags: 'balloon-mapping,event,meetup' + params: { + title: newtitle, + body: "This is a fascinating post about a balloon mapping event. added content", + tags: 'balloon-mapping,event,meetup' + } + follow_redirect! # path does not get updated assert_equal '/notes/' + users(:bob).username + '/' + diff --git a/test/integration/public_pages_test.rb b/test/integration/public_pages_test.rb index 1480cdc32f..d56ad6b8bf 100644 --- a/test/integration/public_pages_test.rb +++ b/test/integration/public_pages_test.rb @@ -88,7 +88,7 @@ def setup get nodes(:redirect).path assert_response :redirect assert_redirected_to nodes(:blog).path - request_via_redirect :get, nodes(:blog).path + get nodes(:blog).path assert_select 'h1', nodes(:blog).title end diff --git a/test/integration/revision_spam_test.rb b/test/integration/revision_spam_test.rb index 0760d13ec5..26bc374eb9 100644 --- a/test/integration/revision_spam_test.rb +++ b/test/integration/revision_spam_test.rb @@ -2,11 +2,8 @@ class RevisionSpamTest < ActionDispatch::IntegrationTest test 'mark a wiki revision as spam' do - post '/user_sessions', user_session: { - username: users(:admin).username, - password: 'secretive' - } - + post '/user_sessions', params: { user_session: { username: users(:admin).username, password: 'secretive' } } + revision = revisions(:about_rev_2) assert revision.parent.revisions.length > 1 @@ -23,11 +20,8 @@ class RevisionSpamTest < ActionDispatch::IntegrationTest end test 'disallow marking a wiki revision as spam when its the only revision' do - post '/user_sessions', user_session: { - username: users(:admin).username, - password: 'secretive' - } - + post '/user_sessions', params: { user_session: { username: users(:admin).username, password: 'secretive' } } + revision = revisions(:wiki_page) assert_equal 1, revision.parent.revisions.length @@ -37,7 +31,7 @@ class RevisionSpamTest < ActionDispatch::IntegrationTest follow_redirect! assert_equal "You can't delete the last remaining revision of a page; try deleting the wiki page itself (if you're an admin) or contacting moderators@publiclab.org for assistance.", flash[:warning] - # assert_select ".alert.alert-warning" ,:text => "× You can't delete the last remaining revision of a page; try deleting the wiki page itself (if you're an admin) or contacting moderators@publiclab.org for assistance." + # assert_select ".alert.alert-warning" ,:text => "× You can't delete the last remaining revision of a page; try deleting the wiki page itself (if you're an admin) or contacting moderators@publiclab.org for assistance." get '/dashboard' assert_response :success diff --git a/test/integration/search_flow_test.rb b/test/integration/search_flow_test.rb index a771bf535d..8724ce6b1c 100644 --- a/test/integration/search_flow_test.rb +++ b/test/integration/search_flow_test.rb @@ -15,8 +15,10 @@ class SearchFlowTest < ActionDispatch::IntegrationTest # Perform a POST search submission without a term post '/search', + params: { key_words: 'blog', main_type: 'Notes or Wiki updates' + } assert_response :success @@ -25,17 +27,21 @@ class SearchFlowTest < ActionDispatch::IntegrationTest assert_response :success post '/search', + params: { 'search_record' => { key_words: 'post', main_type: 'Notes or Wiki updates' } + } assert_response :success # https://publiclab.org/searches?key_words=spec post '/search', + params: { key_words: 'spectrom' + } assert_response :success end diff --git a/test/integration/token_comment_test.rb b/test/integration/token_comment_test.rb index ac9b47791d..cbfdd7a9de 100644 --- a/test/integration/token_comment_test.rb +++ b/test/integration/token_comment_test.rb @@ -2,45 +2,17 @@ class TokenCommentTest < ActionDispatch::IntegrationTest test 'should not post comment through invalid token successfully' do - @params = { - body: 'Test Comment', - username: 'Bob' - } - - @headers = { - 'HTTP_TOKEN' => 'invalid-token' - } - - post '/comment/create/token/1.json', @params, @headers + post '/comment/create/token/1.json', params: { body: 'Test Comment', username: 'Bob' }, headers: { 'HTTP_TOKEN' => 'invalid-token' } assert_response :unauthorized end test 'should not post an invalid comment successfully' do - @params = { - body: '', - username: 'Bob' - } - - @headers = { - 'HTTP_TOKEN' => 'abcdefg12345' - } - - post '/comment/create/token/1.json', @params, @headers + post '/comment/create/token/1.json', params: { body: '', username: 'Bob' }, headers: { 'HTTP_TOKEN' => 'abcdefg12345' } assert_response :bad_request end test 'should post comment through valid token successfully' do - @params = { - body: 'Test Comment', - username: 'Bob' - } - - @headers = { - 'HTTP_TOKEN' => 'abcdefg12345' - } - - post '/comment/create/token/1.json', @params, @headers + post '/comment/create/token/1.json', params: { body: 'Test Comment', username: 'Bob' }, headers: { 'HTTP_TOKEN' => 'abcdefg12345' } assert_response :success end - end diff --git a/test/integration/wiki_creation_test.rb b/test/integration/wiki_creation_test.rb index 997d5e7876..232877fa64 100644 --- a/test/integration/wiki_creation_test.rb +++ b/test/integration/wiki_creation_test.rb @@ -2,15 +2,12 @@ class WikiCreationTest < ActionDispatch::IntegrationTest test 'create new wiki page' do - post '/user_sessions', user_session: { - username: users(:bob).username, - password: 'secretive' - } + post '/user_sessions', params: { user_session: { username: users(:bob).username, password: 'secretive' } } title = 'New wiki page title' body = 'This is the body of the new wiki page' - post '/wiki/create', title: title, body: body + post '/wiki/create', params: { title: title, body: body } follow_redirect! @@ -20,15 +17,12 @@ class WikiCreationTest < ActionDispatch::IntegrationTest end test 'create new wiki page without body' do - post '/user_sessions', user_session: { - username: users(:bob).username, - password: 'secretive' - } + post '/user_sessions', params: { user_session: { username: users(:bob).username, password: 'secretive' } } title = 'New wiki page title' body = nil - post '/wiki/create', title: title, body: body + post '/wiki/create', params: { title: title, body: body } # Check we get the corresponding error @@ -42,7 +36,7 @@ class WikiCreationTest < ActionDispatch::IntegrationTest body = 'This is the body of the new wiki page' - post '/wiki/create', title: title, body: body + post '/wiki/create', params: { title: title, body: body } follow_redirect! diff --git a/test/unit/node_test.rb b/test/unit/node_test.rb index a633975472..587b31e4d6 100644 --- a/test/unit/node_test.rb +++ b/test/unit/node_test.rb @@ -26,21 +26,21 @@ class NodeTest < ActiveSupport::TestCase test 'node mysql native fulltext search' do assert Node.count > 0 if ActiveRecord::Base.connection.adapter_name == 'Mysql2' - nodes = Node.search('organizers') + nodes = Node.search(query: 'organizers', limit: 1000) assert_not_nil nodes assert nodes.length > 0 # now sorted by natural language match - nodes_natural = Node.search('organizers', :natural) + nodes_natural = Node.search(query: 'organizers', order: :natural, limit: 1000) assert_not_nil nodes_natural assert nodes_natural.length > 0 assert_not_equal nodes_natural, nodes # now sorted by likes - nodes_likes = Node.search('organizers', :likes) + nodes_likes = Node.search(query: 'organizers', order: :likes, limit: 1000) assert_not_nil nodes_likes assert nodes_likes.length > 0 assert_not_equal nodes_likes, nodes # now sorted by views - nodes_views = Node.search('organizers', :views) + nodes_views = Node.search(query: 'organizers', order: :views, limit: 1000) assert_not_nil nodes_views assert nodes_views.length > 0 assert_not_equal nodes_views, nodes @@ -50,7 +50,7 @@ class NodeTest < ActiveSupport::TestCase test 'node mysql native fulltext search returning tag-based matches' do assert Node.count > 0 if ActiveRecord::Base.connection.adapter_name == 'Mysql2' - nodes = Node.search('awesome') + nodes = Node.search(query: 'awesome', limit: 1000) assert_not_nil nodes assert nodes.length > 0 assert_equal nodes.length, Tag.find_nodes_by_type('awesome', ['note', 'page']).length diff --git a/test/unit/typeahead_service_test.rb b/test/unit/typeahead_service_test.rb index 3dc511fc32..3ca78b8c94 100644 --- a/test/unit/typeahead_service_test.rb +++ b/test/unit/typeahead_service_test.rb @@ -6,7 +6,7 @@ class TypeaheadServiceTest < ActiveSupport::TestCase result = TypeaheadService.new.notes('blog') assert_not_nil result assert_equal 1, result.length - assert_equal result.length, result.uniq.length + assert_equal result.length, result.distinct.length end # test 'running TypeaheadService.new.wikis' do @@ -21,7 +21,7 @@ class TypeaheadServiceTest < ActiveSupport::TestCase result = TypeaheadService.new.tags('blog') assert_not_nil result assert_equal 1, result.length - assert_equal result.length, result.uniq.length + assert_equal result.length, result.distinct.length end test 'running TypeaheadService.new.users' do