From 89ad2b590050fb9c8915d8aebcfe8f661e6012ea Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 5 Jun 2018 17:29:17 +1000 Subject: [PATCH] DEV: Rails 5.2 upgrade and global gem upgrade This updates tests to use latest rails 5 practice and updates ALL dependencies that could be updated Performance testing shows that performance has not regressed if anything it is marginally faster now. --- Gemfile | 14 +- Gemfile.lock | 284 +++++++++--------- app/controllers/application_controller.rb | 3 +- app/helpers/application_helper.rb | 7 +- app/models/concerns/trashable.rb | 8 +- app/models/invite.rb | 7 +- app/models/post.rb | 11 +- app/models/post_mover.rb | 2 +- app/models/topic.rb | 9 +- app/models/user.rb | 2 +- app/services/badge_granter.rb | 1 - lib/admin_user_index_query.rb | 3 +- lib/email/renderer.rb | 2 +- .../active_record_attribute_methods.rb | 18 ++ lib/freedom_patches/fast_pluck.rb | 31 +- lib/post_creator.rb | 2 +- lib/tasks/assets.rake | 1 - lib/topic_query_sql.rb | 13 +- package.json | 10 +- spec/components/file_store/base_store_spec.rb | 1 + .../components/migration/safe_migrate_spec.rb | 19 +- spec/components/post_revisor_spec.rb | 10 +- spec/components/search_spec.rb | 2 +- spec/components/topic_query_spec.rb | 6 +- .../validators/upload_validator_spec.rb | 1 + spec/controllers/admin/api_controller_spec.rb | 6 +- .../admin/backups_controller_spec.rb | 20 +- .../admin/badges_controller_spec.rb | 12 +- .../admin/color_schemes_controller_spec.rb | 12 +- .../admin/dashboard_controller_spec.rb | 4 +- .../admin/email_controller_spec.rb | 6 +- .../admin/emojis_controller_spec.rb | 2 +- .../admin/impersonate_controller_spec.rb | 4 +- .../admin/permalinks_controller_spec.rb | 6 +- .../admin/plugins_controller_spec.rb | 2 +- .../admin/reports_controller_spec.rb | 6 +- .../admin/screened_emails_controller_spec.rb | 2 +- .../screened_ip_addresses_controller_spec.rb | 8 +- .../admin/screened_urls_controller_spec.rb | 2 +- .../admin/site_settings_controller_spec.rb | 2 +- .../admin/site_texts_controller_spec.rb | 12 +- .../staff_action_logs_controller_spec.rb | 4 +- .../admin/themes_controller_spec.rb | 10 +- .../admin/user_fields_controller_spec.rb | 16 +- .../admin/users_controller_spec.rb | 58 ++-- .../admin/versions_controller_spec.rb | 2 +- .../admin/web_hooks_controller_spec.rb | 4 +- .../composer_messages_controller_spec.rb | 2 +- .../controllers/export_csv_controller_spec.rb | 10 +- .../extra_locales_controller_spec.rb | 6 +- .../finish_installation_controller_spec.rb | 12 +- .../inline_onebox_controller_spec.rb | 4 +- .../post_action_users_controller_spec.rb | 2 +- .../post_actions_controller_spec.rb | 6 +- .../queued_posts_controller_spec.rb | 14 +- spec/controllers/site_controller_spec.rb | 2 +- spec/controllers/steps_controller_spec.rb | 4 +- .../stylesheets_controller_spec.rb | 12 +- .../user_actions_controller_spec.rb | 2 +- .../user_avatars_controller_spec.rb | 2 +- spec/controllers/webhooks_controller_spec.rb | 10 +- spec/controllers/wizard_controller_spec.rb | 4 +- spec/fabricators/topic_fabricator.rb | 4 +- spec/jobs/toggle_topic_closed_spec.rb | 4 +- spec/models/post_action_spec.rb | 2 +- spec/models/tag_spec.rb | 42 +-- spec/models/topic_featured_users_spec.rb | 10 +- spec/models/topic_spec.rb | 15 +- spec/models/topic_timer_spec.rb | 4 + spec/requests/about_controller_spec.rb | 4 +- .../requests/admin/backups_controller_spec.rb | 8 +- .../admin/email_templates_controller_spec.rb | 10 +- .../admin/flagged_topics_controller_spec.rb | 2 +- spec/requests/admin/flags_controller_spec.rb | 13 +- .../moderation_history_controller_spec.rb | 14 +- spec/requests/admin/search_logs_spec.rb | 4 +- spec/requests/categories_controller_spec.rb | 8 +- .../directory_items_controller_spec.rb | 16 +- spec/requests/email_controller_spec.rb | 4 +- spec/requests/embed_controller_spec.rb | 10 +- spec/requests/groups_controller_spec.rb | 62 ++-- spec/requests/invites_controller_spec.rb | 38 +-- spec/requests/list_controller_spec.rb | 44 +-- .../requests/notifications_controller_spec.rb | 8 +- .../omniauth_callbacks_controller_spec.rb | 8 +- spec/requests/onebox_controller_spec.rb | 10 +- spec/requests/post_actions_controller_spec.rb | 6 +- spec/requests/posts_controller_spec.rb | 136 ++++----- spec/requests/search_controller_spec.rb | 32 +- spec/requests/session_controller_spec.rb | 56 ++-- spec/requests/static_controller_spec.rb | 10 +- spec/requests/tags_controller_spec.rb | 50 +-- spec/requests/topics_controller_spec.rb | 140 +++++---- spec/requests/uploads_controller_spec.rb | 4 +- spec/requests/user_badges_controller_spec.rb | 2 +- spec/requests/users_controller_spec.rb | 138 ++++----- spec/requests/users_email_controller_spec.rb | 20 +- spec/serializers/post_serializer_spec.rb | 13 +- spec/services/badge_granter_spec.rb | 3 +- spec/services/destroy_task_spec.rb | 8 +- spec/services/post_alerter_spec.rb | 13 +- spec/services/post_owner_changer_spec.rb | 26 +- spec/support/integration_helpers.rb | 4 +- 103 files changed, 900 insertions(+), 864 deletions(-) create mode 100644 lib/freedom_patches/active_record_attribute_methods.rb diff --git a/Gemfile b/Gemfile index daf906ca0d7..60b197bdcdd 100644 --- a/Gemfile +++ b/Gemfile @@ -13,13 +13,13 @@ if rails_master? gem 'rails', git: 'https://github.com/rails/rails.git' gem 'seed-fu', git: 'https://github.com/SamSaffron/seed-fu.git', branch: 'discourse' else - gem 'actionmailer', '~> 5.1' - gem 'actionpack', '~> 5.1' - gem 'actionview', '~> 5.1' - gem 'activemodel', '~> 5.1' - gem 'activerecord', '~> 5.1' - gem 'activesupport', '~> 5.1' - gem 'railties', '~> 5.1' + gem 'actionmailer', '~> 5.2' + gem 'actionpack', '~> 5.2' + gem 'actionview', '~> 5.2' + gem 'activemodel', '~> 5.2' + gem 'activerecord', '~> 5.2' + gem 'activesupport', '~> 5.2' + gem 'railties', '~> 5.2' gem 'sprockets-rails' gem 'seed-fu' end diff --git a/Gemfile.lock b/Gemfile.lock index 99ed6d189c5..3d018a32709 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,86 +1,88 @@ GEM remote: https://rubygems.org/ specs: - actionmailer (5.1.4) - actionpack (= 5.1.4) - actionview (= 5.1.4) - activejob (= 5.1.4) + actionmailer (5.2.0) + actionpack (= 5.2.0) + actionview (= 5.2.0) + activejob (= 5.2.0) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.1.4) - actionview (= 5.1.4) - activesupport (= 5.1.4) + actionpack (5.2.0) + actionview (= 5.2.0) + activesupport (= 5.2.0) rack (~> 2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.1.4) - activesupport (= 5.1.4) + actionview (5.2.0) + activesupport (= 5.2.0) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - active_model_serializers (0.8.3) + active_model_serializers (0.8.4) activemodel (>= 3.0) - activejob (5.1.4) - activesupport (= 5.1.4) + activejob (5.2.0) + activesupport (= 5.2.0) globalid (>= 0.3.6) - activemodel (5.1.4) - activesupport (= 5.1.4) - activerecord (5.1.4) - activemodel (= 5.1.4) - activesupport (= 5.1.4) - arel (~> 8.0) - activesupport (5.1.4) + activemodel (5.2.0) + activesupport (= 5.2.0) + activerecord (5.2.0) + activemodel (= 5.2.0) + activesupport (= 5.2.0) + arel (>= 9.0) + activesupport (5.2.0) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (~> 0.7) + i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) - addressable (2.5.1) - public_suffix (~> 2.0, >= 2.0.2) - annotate (2.7.2) + addressable (2.5.2) + public_suffix (>= 2.0.2, < 4.0) + annotate (2.7.4) activerecord (>= 3.2, < 6.0) rake (>= 10.4, < 13.0) - arel (8.0.0) + arel (9.0.0) ast (2.4.0) - aws-partitions (1.24.0) - aws-sdk-core (3.6.0) + aws-eventstream (1.0.0) + aws-partitions (1.91.0) + aws-sdk-core (3.21.2) + aws-eventstream (~> 1.0) aws-partitions (~> 1.0) aws-sigv4 (~> 1.0) jmespath (~> 1.0) - aws-sdk-kms (1.2.0) + aws-sdk-kms (1.5.0) aws-sdk-core (~> 3) aws-sigv4 (~> 1.0) - aws-sdk-s3 (1.4.0) - aws-sdk-core (~> 3) + aws-sdk-s3 (1.13.0) + aws-sdk-core (~> 3, >= 3.21.2) aws-sdk-kms (~> 1) aws-sigv4 (~> 1.0) aws-sigv4 (1.0.2) - barber (0.11.2) - ember-source (>= 1.0, < 3) + barber (0.12.0) + ember-source (>= 1.0, < 3.1) execjs (>= 1.2, < 3) - better_errors (2.1.1) + better_errors (2.4.0) coderay (>= 1.0.0) - erubis (>= 2.6.6) + erubi (>= 1.0.0) rack (>= 0.9.0) binding_of_caller (0.8.0) debug_inspector (>= 0.0.1) - bootsnap (1.1.8) + bootsnap (1.3.0) msgpack (~> 1.0) builder (3.2.3) - bullet (5.5.1) + bullet (5.7.5) activesupport (>= 3.0.0) - uniform_notifier (~> 1.10.0) - byebug (9.0.6) + uniform_notifier (~> 1.11.0) + byebug (10.0.2) certified (1.0.0) - chunky_png (1.3.8) + chunky_png (1.3.10) coderay (1.1.2) concurrent-ruby (1.0.5) - connection_pool (2.2.1) + connection_pool (2.2.2) cppjieba_rb (0.3.0) crack (0.4.3) safe_yaml (~> 1.0.0) - crass (1.0.3) + crass (1.0.4) debug_inspector (0.0.3) diff-lcs (1.3) discourse_image_optim (0.24.5) @@ -90,8 +92,8 @@ GEM in_threads (~> 1.3) progress (~> 3.0, >= 3.0.1) email_reply_trimmer (0.1.12) - ember-data-source (2.2.1) - ember-source (>= 1.8, < 3.0) + ember-data-source (3.0.2) + ember-source (>= 2, < 3.0) ember-handlebars-template (0.7.5) barber (>= 0.11.0) sprockets (>= 3.3, < 4) @@ -103,59 +105,60 @@ GEM jquery-rails (>= 1.0.17) railties (>= 3.1) ember-source (2.13.3) - erubi (1.6.1) - erubis (2.7.0) - excon (0.56.0) + erubi (1.7.1) + excon (0.62.0) execjs (2.7.0) - exifr (1.2.5) - fabrication (2.9.8) + exifr (1.3.4) + fabrication (2.20.1) fakeweb (1.3.0) - faraday (0.11.0) + faraday (0.12.2) multipart-post (>= 1.2, < 3) fast_blank (1.0.0) fast_xor (1.1.3) rake rake-compiler fast_xs (0.8.0) - fastimage (2.1.1) - ffi (1.9.18) + fastimage (2.1.3) + ffi (1.9.25) flamegraph (0.9.5) foreman (0.84.0) thor (~> 0.19.1) fspath (3.1.0) gc_tracer (1.5.1) - globalid (0.4.0) + globalid (0.4.1) activesupport (>= 4.2.0) guess_html_encoding (0.0.11) - hashdiff (0.3.4) - hashie (3.5.5) - highline (1.7.8) + hashdiff (0.3.7) + hashie (3.5.7) + highline (1.7.10) hiredis (0.6.1) hkdf (0.3.0) htmlentities (4.3.4) http_accept_language (2.0.5) - i18n (0.8.6) + i18n (1.0.1) + concurrent-ruby (~> 1.0) image_size (1.5.0) - in_threads (1.4.0) - jmespath (1.3.1) - jquery-rails (4.3.1) + in_threads (1.5.0) + jaro_winkler (1.5.1) + jmespath (1.4.0) + jquery-rails (4.3.3) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) jwt (1.5.6) - kgio (2.11.1) + kgio (2.11.2) libv8 (6.3.292.48.1) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) ruby_dep (~> 1.2) - lograge (0.7.1) - actionpack (>= 4, < 5.2) - activesupport (>= 4, < 5.2) - railties (>= 4, < 5.2) + lograge (0.10.0) + actionpack (>= 4) + activesupport (>= 4) + railties (>= 4) request_store (~> 1.0) logstash-event (1.2.02) - logstash-logger (0.25.1) + logstash-logger (0.26.1) logstash-event (~> 1.2) logster (1.2.9) loofah (2.2.2) @@ -175,10 +178,10 @@ GEM libv8 (~> 6.3) mini_suffix (0.3.0) ffi (~> 1.9) - minitest (5.10.3) - mocha (1.2.1) + minitest (5.11.3) + mocha (1.5.0) metaclass (~> 0.0.1) - mock_redis (0.17.3) + mock_redis (0.18.0) moneta (1.0.0) msgpack (1.2.4) multi_json (1.13.1) @@ -189,40 +192,39 @@ GEM mini_portile2 (~> 2.3.0) nokogumbo (1.5.0) nokogiri - oauth (0.5.1) - oauth2 (1.3.1) - faraday (>= 0.8, < 0.12) + oauth (0.5.4) + oauth2 (1.4.0) + faraday (>= 0.8, < 0.13) jwt (~> 1.0) multi_json (~> 1.3) multi_xml (~> 0.5) rack (>= 1.2, < 3) - oj (3.4.0) - omniauth (1.6.1) + oj (3.6.2) + omniauth (1.8.1) hashie (>= 3.4.6, < 3.6.0) rack (>= 1.6.2, < 3) - omniauth-facebook (4.0.0) + omniauth-facebook (5.0.0) omniauth-oauth2 (~> 1.2) omniauth-github (1.3.0) omniauth (~> 1.5) omniauth-oauth2 (>= 1.4.0, < 2.0) - omniauth-google-oauth2 (0.3.1) - jwt (~> 1.0) - multi_json (~> 1.3) + omniauth-google-oauth2 (0.5.3) + jwt (>= 1.5) omniauth (>= 1.1.1) - omniauth-oauth2 (>= 1.3.1) - omniauth-instagram (1.0.2) + omniauth-oauth2 (>= 1.5) + omniauth-instagram (1.3.0) omniauth (~> 1) omniauth-oauth2 (~> 1) omniauth-oauth (1.1.0) oauth omniauth (~> 1.0) - omniauth-oauth2 (1.4.0) - oauth2 (~> 1.0) + omniauth-oauth2 (1.5.0) + oauth2 (~> 1.1) omniauth (~> 1.2) omniauth-openid (1.0.1) omniauth (~> 1.0) rack-openid (~> 1.3.1) - omniauth-twitter (1.3.0) + omniauth-twitter (1.4.0) omniauth-oauth (~> 1.1) rack onebox (1.8.48) @@ -236,31 +238,31 @@ GEM redis ruby-openid parallel (1.12.1) - parser (2.5.0.3) + parser (2.5.1.0) ast (~> 2.4.0) pg (0.21.0) powerpack (0.1.1) - progress (3.3.1) + progress (3.4.0) pry (0.10.4) coderay (~> 1.1.0) method_source (~> 0.8.1) slop (~> 3.4) pry-nav (0.2.4) pry (>= 0.9.10, < 0.11.0) - pry-rails (0.3.4) - pry (>= 0.9.10) - public_suffix (2.0.5) - puma (3.9.1) - r2 (0.2.6) + pry-rails (0.3.6) + pry (>= 0.10.4) + public_suffix (3.0.2) + puma (3.11.4) + r2 (0.2.7) rack (2.0.5) rack-mini-profiler (1.0.0) rack (>= 1.2.0) rack-openid (1.3.1) rack (>= 1.1.0) ruby-openid (>= 2.1.8) - rack-protection (2.0.1) + rack-protection (2.0.2) rack - rack-test (0.7.0) + rack-test (1.0.0) rack (>= 1.0, < 3) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) @@ -270,20 +272,20 @@ GEM rails_multisite (2.0.4) activerecord (> 4.2, < 6) railties (> 4.2, < 6) - railties (5.1.4) - actionpack (= 5.1.4) - activesupport (= 5.1.4) + railties (5.2.0) + actionpack (= 5.2.0) + activesupport (= 5.2.0) method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rainbow (3.0.0) raindrops (0.19.0) - rake (12.3.0) + rake (12.3.1) rake-compiler (1.0.4) rake - rb-fsevent (0.9.8) - rb-inotify (0.9.8) - ffi (>= 0.5.0) + rb-fsevent (0.10.3) + rb-inotify (0.9.10) + ffi (>= 0.5.0, < 2) rbtrace (0.4.10) ffi (>= 1.0.6) msgpack (>= 0.4.3) @@ -291,37 +293,39 @@ GEM redis (4.0.1) redis-namespace (1.6.0) redis (>= 3.0.4) - request_store (1.3.2) - rinku (2.0.2) - rotp (3.3.0) + request_store (1.4.1) + rack (>= 1.4) + rinku (2.0.4) + rotp (3.3.1) rqrcode (0.10.1) chunky_png (~> 1.0) - rspec (3.6.0) - rspec-core (~> 3.6.0) - rspec-expectations (~> 3.6.0) - rspec-mocks (~> 3.6.0) - rspec-core (3.6.0) - rspec-support (~> 3.6.0) - rspec-expectations (3.6.0) + rspec (3.7.0) + rspec-core (~> 3.7.0) + rspec-expectations (~> 3.7.0) + rspec-mocks (~> 3.7.0) + rspec-core (3.7.1) + rspec-support (~> 3.7.0) + rspec-expectations (3.7.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.6.0) + rspec-support (~> 3.7.0) rspec-html-matchers (0.9.1) nokogiri (~> 1) rspec (>= 3.0.0.a, < 4) - rspec-mocks (3.6.0) + rspec-mocks (3.7.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.6.0) - rspec-rails (3.6.1) + rspec-support (~> 3.7.0) + rspec-rails (3.7.2) actionpack (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) - rspec-core (~> 3.6.0) - rspec-expectations (~> 3.6.0) - rspec-mocks (~> 3.6.0) - rspec-support (~> 3.6.0) - rspec-support (3.6.0) + rspec-core (~> 3.7.0) + rspec-expectations (~> 3.7.0) + rspec-mocks (~> 3.7.0) + rspec-support (~> 3.7.0) + rspec-support (3.7.1) rtlit (0.0.5) - rubocop (0.53.0) + rubocop (0.57.1) + jaro_winkler (~> 1.5.1) parallel (~> 1.10) parser (>= 2.5) powerpack (~> 0.1) @@ -329,23 +333,27 @@ GEM ruby-progressbar (~> 1.7) unicode-display_width (~> 1.0, >= 1.0.1) ruby-openid (2.7.0) - ruby-prof (0.16.2) + ruby-prof (0.17.0) ruby-progressbar (1.9.0) ruby-readability (0.7.0) guess_html_encoding (>= 0.0.4) nokogiri (>= 1.6.0) ruby_dep (1.5.0) safe_yaml (1.0.4) - sanitize (4.6.4) + sanitize (4.6.5) crass (~> 1.0.2) nokogiri (>= 1.4.4) nokogumbo (~> 1.4) - sass (3.4.24) - sassc (1.11.2) + 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) + sassc (1.11.4) bundler ffi (~> 1.9.6) sass (>= 3.3.0) - seed-fu (2.3.7) + seed-fu (2.3.9) activerecord (>= 3.1) activesupport (>= 3.1) shoulda (3.5.0) @@ -363,29 +371,29 @@ GEM sprockets (3.7.1) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.2.0) + sprockets-rails (3.2.1) actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) sshkey (1.9.0) - stackprof (0.2.10) + stackprof (0.2.11) thor (0.19.4) thread_safe (0.3.6) - tilt (2.0.7) + tilt (2.0.8) trollop (2.1.2) - tzinfo (1.2.3) + tzinfo (1.2.5) thread_safe (~> 0.1) - uglifier (3.2.0) + uglifier (4.1.11) execjs (>= 0.3.0, < 3) unf (0.1.4) unf_ext - unf_ext (0.0.7.4) - unicode-display_width (1.3.0) + unf_ext (0.0.7.5) + unicode-display_width (1.4.0) unicorn (5.4.0) kgio (~> 2.6) raindrops (~> 0.7) - uniform_notifier (1.10.0) - webmock (3.0.1) + uniform_notifier (1.11.0) + webmock (3.4.2) addressable (>= 2.3.6) crack (>= 0.3.2) hashdiff @@ -397,13 +405,13 @@ PLATFORMS ruby DEPENDENCIES - actionmailer (~> 5.1) - actionpack (~> 5.1) - actionview (~> 5.1) + actionmailer (~> 5.2) + actionpack (~> 5.2) + actionview (~> 5.2) active_model_serializers (~> 0.8.3) - activemodel (~> 5.1) - activerecord (~> 5.1) - activesupport (~> 5.1) + activemodel (~> 5.2) + activerecord (~> 5.2) + activesupport (~> 5.2) annotate aws-sdk-s3 barber @@ -471,7 +479,7 @@ DEPENDENCIES rack-mini-profiler rack-protection rails_multisite - railties (~> 5.1) + railties (~> 5.2) rake rb-fsevent rb-inotify (~> 0.9) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 218e04eb46b..d75e4152c82 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -96,7 +96,8 @@ class ApplicationController < ActionController::Base def dont_cache_page if !response.headers["Cache-Control"] && response.cache_control.blank? - response.headers["Cache-Control"] = "no-store, must-revalidate, no-cache, private" + response.cache_control[:no_cache] = true + response.cache_control[:extras] = ["no-store"] end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 696a2a870a6..f59ac7cfe6e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'current_user' require 'canonical_url' require_dependency 'guardian' @@ -62,17 +63,17 @@ module ApplicationHelper if GlobalSetting.use_s3? && GlobalSetting.s3_cdn_url if GlobalSetting.cdn_url - path.gsub!(GlobalSetting.cdn_url, GlobalSetting.s3_cdn_url) + path = path.gsub(GlobalSetting.cdn_url, GlobalSetting.s3_cdn_url) else path = "#{GlobalSetting.s3_cdn_url}#{path}" end if is_brotli_req? - path.gsub!(/\.([^.]+)$/, '.br.\1') + path = path.gsub(/\.([^.]+)$/, '.br.\1') end elsif GlobalSetting.cdn_url&.start_with?("https") && is_brotli_req? - path.gsub!("#{GlobalSetting.cdn_url}/assets/", "#{GlobalSetting.cdn_url}/brotli_asset/") + path = path.gsub("#{GlobalSetting.cdn_url}/assets/", "#{GlobalSetting.cdn_url}/brotli_asset/") end if Rails.env == "development" diff --git a/app/models/concerns/trashable.rb b/app/models/concerns/trashable.rb index ffd753a8054..0a8dae3f501 100644 --- a/app/models/concerns/trashable.rb +++ b/app/models/concerns/trashable.rb @@ -46,13 +46,7 @@ module Trashable private def trash_update(deleted_at, deleted_by_id) - # see: https://github.com/rails/rails/issues/8436 - # - # Fixed in Rails 4 - # - self.class.unscoped.where(id: self.id).update_all(deleted_at: deleted_at, deleted_by_id: deleted_by_id) - raw_write_attribute :deleted_at, deleted_at - raw_write_attribute :deleted_by_id, deleted_by_id + self.update_columns(deleted_at: deleted_at, deleted_by_id: deleted_by_id) end end diff --git a/app/models/invite.rb b/app/models/invite.rb index 0065d69c479..b613e22c5e6 100644 --- a/app/models/invite.rb +++ b/app/models/invite.rb @@ -166,13 +166,14 @@ class Invite < ActiveRecord::Base group_ids end + INVITE_ORDER = <<~SQL + SQL + def self.find_all_invites_from(inviter, offset = 0, limit = SiteSetting.invites_per_page) Invite.where(invited_by_id: inviter.id) .where('invites.email IS NOT NULL') .includes(user: :user_stat) - .order('CASE WHEN invites.user_id IS NOT NULL THEN 0 ELSE 1 END', - 'user_stats.time_read DESC', - 'invites.redeemed_at DESC') + .order("CASE WHEN invites.user_id IS NOT NULL THEN 0 ELSE 1 END, user_stats.time_read DESC, invites.redeemed_at DESC") .limit(limit) .offset(offset) .references('user_stats') diff --git a/app/models/post.rb b/app/models/post.rb index 142066cead5..57f56437dcc 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -654,11 +654,18 @@ class Post < ActiveRecord::Base result = public_posts.where('posts.created_at >= ? AND posts.created_at <= ?', start_date, end_date) .where(post_type: Post.types[:regular]) result = result.where('topics.category_id = ?', category_id) if category_id - result.group('date(posts.created_at)').order('date(posts.created_at)').count + result + .group('date(posts.created_at)') + .order('date(posts.created_at)') + .count end def self.private_messages_count_per_day(start_date, end_date, topic_subtype) - private_posts.with_topic_subtype(topic_subtype).where('posts.created_at >= ? AND posts.created_at <= ?', start_date, end_date).group('date(posts.created_at)').order('date(posts.created_at)').count + private_posts.with_topic_subtype(topic_subtype) + .where('posts.created_at >= ? AND posts.created_at <= ?', start_date, end_date) + .group('date(posts.created_at)') + .order('date(posts.created_at)') + .count end def reply_history(max_replies = 100, guardian = nil) diff --git a/app/models/post_mover.rb b/app/models/post_mover.rb index 14a41879eca..9f7eff0d18b 100644 --- a/app/models/post_mover.rb +++ b/app/models/post_mover.rb @@ -217,7 +217,7 @@ class PostMover attrs[:last_posted_at] = post.created_at attrs[:last_post_user_id] = post.user_id attrs[:bumped_at] = post.created_at unless post.no_bump - attrs[:updated_at] = 'now()' + attrs[:updated_at] = Time.now destination_topic.update_columns(attrs) end end diff --git a/app/models/topic.rb b/app/models/topic.rb index d179b12ee8f..9b1c1145ea0 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -278,7 +278,7 @@ class Topic < ActiveRecord::Base def ensure_topic_has_a_category if category_id.nil? && (archetype.nil? || self.regular?) - self.category_id = SiteSetting.uncategorized_category_id + self.category_id = category&.id || SiteSetting.uncategorized_category_id end end @@ -1334,7 +1334,12 @@ SQL end def self.private_message_topics_count_per_day(start_date, end_date, topic_subtype) - private_messages.with_subtype(topic_subtype).where('topics.created_at >= ? AND topics.created_at <= ?', start_date, end_date).group('date(topics.created_at)').order('date(topics.created_at)').count + private_messages + .with_subtype(topic_subtype) + .where('topics.created_at >= ? AND topics.created_at <= ?', start_date, end_date) + .group('date(topics.created_at)') + .order('date(topics.created_at)') + .count end def is_category_topic? diff --git a/app/models/user.rb b/app/models/user.rb index 90f5064c8f4..c28809f26b8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -844,7 +844,7 @@ class User < ActiveRecord::Base if start_date && end_date result = result.group("date(users.created_at)") result = result.where("users.created_at >= ? AND users.created_at <= ?", start_date, end_date) - result = result.order('date(users.created_at)') + result = result.order("date(users.created_at)") end if group_id diff --git a/app/services/badge_granter.rb b/app/services/badge_granter.rb index 5e88683cff8..1ac69bce482 100644 --- a/app/services/badge_granter.rb +++ b/app/services/badge_granter.rb @@ -43,7 +43,6 @@ class BadgeGranter end if SiteSetting.enable_badges? - unless @badge.badge_type_id == BadgeType::Bronze && user_badge.granted_at < 2.days.ago I18n.with_locale(@user.effective_locale) do notification = @user.notifications.create( diff --git a/lib/admin_user_index_query.rb b/lib/admin_user_index_query.rb index baf20275da7..67cc66626ef 100644 --- a/lib/admin_user_index_query.rb +++ b/lib/admin_user_index_query.rb @@ -63,7 +63,8 @@ class AdminUserIndexQuery if params[:stats].present? && params[:stats] == false klass.order(order.reject(&:blank?).join(",")) else - klass.includes(:user_stat, :user_second_factor).order(order.reject(&:blank?).join(",")) + klass.includes(:user_stat, :user_second_factor) + .order(order.reject(&:blank?).join(",")) end end diff --git a/lib/email/renderer.rb b/lib/email/renderer.rb index be802b7a991..77721ab4c52 100644 --- a/lib/email/renderer.rb +++ b/lib/email/renderer.rb @@ -10,7 +10,7 @@ module Email def text return @text if @text - @text = (@message.text_part ? @message.text_part : @message).body.to_s.force_encoding('UTF-8') + @text = (+(@message.text_part ? @message.text_part : @message).body.to_s).force_encoding('UTF-8') @text = CGI.unescapeHTML(@text) end diff --git a/lib/freedom_patches/active_record_attribute_methods.rb b/lib/freedom_patches/active_record_attribute_methods.rb new file mode 100644 index 00000000000..71fd5d44c7b --- /dev/null +++ b/lib/freedom_patches/active_record_attribute_methods.rb @@ -0,0 +1,18 @@ +# see: https://github.com/rails/rails/issues/32995 +# +# Rails 5.2 forces us to add Arel.sql to #order and #pluck +# Discourse is very SQL heavy and this makes the code much more +# verbose and confusing, especially since it is not enforced for +# #group, #join and many other relation methods +# For the time being we monkey patch this away, longer term we +# hope Rails will allow us for this to be optional + +module ActiveRecord + module AttributeMethods + module ClassMethods + def enforce_raw_sql_whitelist(*args) + return + end + end + end +end diff --git a/lib/freedom_patches/fast_pluck.rb b/lib/freedom_patches/fast_pluck.rb index 6034cf7a521..9999e5a9db6 100644 --- a/lib/freedom_patches/fast_pluck.rb +++ b/lib/freedom_patches/fast_pluck.rb @@ -36,39 +36,32 @@ class ActiveRecord::Relation class ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter def select_raw(arel, name = nil, binds = [], &block) - arel, binds = binds_from_relation arel, binds - sql = to_sql(arel, binds) + arel = arel_from_relation(arel) + sql, binds = to_sql_and_binds(arel, binds) execute_and_clear(sql, name, binds, &block) end end - def pluck(*cols) - - conn = ActiveRecord::Base.connection - relation = self - - cols.map! do |column_name| - if column_name.is_a?(Symbol) && attribute_alias?(column_name) - attribute_alias(column_name) - else - column_name.to_s - end + def pluck(*column_names) + if loaded? && (column_names.map(&:to_s) - @klass.attribute_names - @klass.attribute_aliases.keys).empty? + return records.pluck(*column_names) end - if has_include?(cols.first) - construct_relation_for_association_calculations.pluck(*cols) + if has_include?(column_names.first) + relation = apply_join_dependency + relation.pluck(*column_names) else + enforce_raw_sql_whitelist(column_names) relation = spawn - relation.select_values = cols.map { |cn| - columns_hash.key?(cn) ? arel_table[cn] : cn + relation.select_values = column_names.map { |cn| + @klass.has_attribute?(cn) || @klass.attribute_alias?(cn) ? arel_attribute(cn) : cn } - conn.select_raw(relation, nil, relation.bound_attributes) do |result, _| + klass.connection.select_raw(relation.arel) do |result, _| result.type_map = SqlBuilder.pg_type_map result.nfields == 1 ? result.column_values(0) : result.values end - end end end diff --git a/lib/post_creator.rb b/lib/post_creator.rb index 62874b36277..d4198e63338 100644 --- a/lib/post_creator.rb +++ b/lib/post_creator.rb @@ -411,7 +411,7 @@ class PostCreator attrs[:word_count] = (@topic.word_count || 0) + @post.word_count attrs[:excerpt] = @post.excerpt_for_topic if new_topic? attrs[:bumped_at] = @post.created_at unless @post.no_bump - attrs[:updated_at] = 'now()' + attrs[:updated_at] = Time.now @topic.update_columns(attrs) end end diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake index abb83aff2b3..6dcdbf88bf1 100644 --- a/lib/tasks/assets.rake +++ b/lib/tasks/assets.rake @@ -94,7 +94,6 @@ def compress_ruby(from, to) data = File.read("#{assets_path}/#{from}") uglified, map = Uglifier.new(comments: :none, - screw_ie8: true, source_map: { filename: File.basename(from), output_filename: File.basename(to) diff --git a/lib/topic_query_sql.rb b/lib/topic_query_sql.rb index 2f9bbe59930..93a2b9a8625 100644 --- a/lib/topic_query_sql.rb +++ b/lib/topic_query_sql.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # # SQL fragments used when querying a list of topics. # @@ -10,12 +11,12 @@ module TopicQuerySQL end def order_by_category_sql(dir) - "CASE WHEN categories.id = #{SiteSetting.uncategorized_category_id.to_i} THEN '' ELSE categories.name END #{dir}" + -"CASE WHEN categories.id = #{SiteSetting.uncategorized_category_id.to_i} THEN '' ELSE categories.name END #{dir}" end # If you've clearned the pin, use bumped_at, otherwise put it at the top def order_with_pinned_sql - "CASE + -"CASE WHEN (COALESCE(topics.pinned_at, '#{lowest_date}') > COALESCE(tu.cleared_pinned_at, '#{lowest_date}')) THEN topics.pinned_at + interval '9999 years' ELSE topics.bumped_at @@ -24,7 +25,7 @@ module TopicQuerySQL # If you've clearned the pin, use bumped_at, otherwise put it at the top def order_nocategory_with_pinned_sql - "CASE + -"CASE WHEN topics.pinned_globally AND (COALESCE(topics.pinned_at, '#{lowest_date}') > COALESCE(tu.cleared_pinned_at, '#{lowest_date}')) THEN topics.pinned_at + interval '9999 years' @@ -41,18 +42,18 @@ module TopicQuerySQL end def order_top_for(score) - "COALESCE(top_topics.#{score}, 0) DESC, topics.bumped_at DESC" + -"COALESCE(top_topics.#{score}, 0) DESC, topics.bumped_at DESC" end def order_top_with_pinned_category_for(score) # display pinned topics first - "CASE WHEN (COALESCE(topics.pinned_at, '#{lowest_date}') > COALESCE(tu.cleared_pinned_at, '#{lowest_date}')) THEN 0 ELSE 1 END, + -"CASE WHEN (COALESCE(topics.pinned_at, '#{lowest_date}') > COALESCE(tu.cleared_pinned_at, '#{lowest_date}')) THEN 0 ELSE 1 END, top_topics.#{score} DESC, topics.bumped_at DESC" end def order_top_with_notification_levels(score) - "COALESCE(topic_users.notification_level, 1) DESC, COALESCE(category_users.notification_level, 1) DESC, COALESCE(top_topics.#{score}, 0) DESC, topics.bumped_at DESC" + -"COALESCE(topic_users.notification_level, 1) DESC, COALESCE(category_users.notification_level, 1) DESC, COALESCE(top_topics.#{score}, 0) DESC, topics.bumped_at DESC" end end diff --git a/package.json b/package.json index df94fd92754..499196c42d8 100644 --- a/package.json +++ b/package.json @@ -7,10 +7,10 @@ "license": "MIT", "dependencies": {}, "devDependencies": { - "babel-eslint": "^8.0.3", - "chrome-launcher": "^0.10.0", - "chrome-remote-interface": "^0.25.4", - "eslint": "^4.13.1", - "puppeteer": "^1.4.0" + "babel-eslint": "^8.2.3", + "chrome-launcher": "^0.10.2", + "chrome-remote-interface": "^0.25.6", + "eslint": "^4.19.1", + "puppeteer": "^0.13.0" } } diff --git a/spec/components/file_store/base_store_spec.rb b/spec/components/file_store/base_store_spec.rb index 89f0a105da2..20d898ee36b 100644 --- a/spec/components/file_store/base_store_spec.rb +++ b/spec/components/file_store/base_store_spec.rb @@ -1,4 +1,5 @@ require 'rails_helper' +require_dependency 'file_store/base_store' RSpec.describe FileStore::BaseStore do let(:upload) { Fabricate(:upload, id: 9999, sha1: Digest::SHA1.hexdigest('9999')) } diff --git a/spec/components/migration/safe_migrate_spec.rb b/spec/components/migration/safe_migrate_spec.rb index 1be7f7c86d1..15659e4b900 100644 --- a/spec/components/migration/safe_migrate_spec.rb +++ b/spec/components/migration/safe_migrate_spec.rb @@ -21,6 +21,11 @@ describe Migration::SafeMigrate do $stdout = old_stdout end + def migrate_up(path) + migrations = ActiveRecord::MigrationContext.new(path).migrations + ActiveRecord::Migrator.new(:up, migrations, migrations.first.version).run + end + it "bans all table removal" do Migration::SafeMigrate.enable! @@ -28,7 +33,7 @@ describe Migration::SafeMigrate do output = capture_stdout do expect(lambda do - ActiveRecord::Migrator.up([path]) + migrate_up(path) end).to raise_error(StandardError) end @@ -45,14 +50,14 @@ describe Migration::SafeMigrate do output = capture_stdout do expect(lambda do - ActiveRecord::Migrator.up([path]) + migrate_up(path) end).to raise_error(StandardError) end - expect(output).to include("TableDropper") - expect { User.first }.not_to raise_error expect(User.first).not_to eq(nil) + + expect(output).to include("TableDropper") end it "bans all column removal" do @@ -62,7 +67,7 @@ describe Migration::SafeMigrate do output = capture_stdout do expect(lambda do - ActiveRecord::Migrator.up([path]) + migrate_up(path) end).to raise_error(StandardError) end @@ -79,7 +84,7 @@ describe Migration::SafeMigrate do output = capture_stdout do expect(lambda do - ActiveRecord::Migrator.up([path]) + migrate_up(path) end).to raise_error(StandardError) end @@ -96,7 +101,7 @@ describe Migration::SafeMigrate do path = File.expand_path "#{Rails.root}/spec/fixtures/migrate/drop_table" output = capture_stdout do - ActiveRecord::Migrator.up([path]) + migrate_up(path) end expect(output).to include("drop_table(:users)") diff --git a/spec/components/post_revisor_spec.rb b/spec/components/post_revisor_spec.rb index 3e6efb0a6f1..4734d94cec0 100644 --- a/spec/components/post_revisor_spec.rb +++ b/spec/components/post_revisor_spec.rb @@ -86,7 +86,7 @@ describe PostRevisor do let(:post) { Fabricate(:post, post_args) } let(:first_version_at) { post.last_version_at } - subject { described_class.new(post) } + subject { PostRevisor.new(post) } describe 'with the same body' do it "doesn't change version" do @@ -402,7 +402,7 @@ describe PostRevisor do describe "topic excerpt" do it "topic excerpt is updated only if first post is revised" do - revisor = described_class.new(post) + revisor = PostRevisor.new(post) first_post = topic.posts.by_post_number.first expect { revisor.revise!(first_post.user, { raw: 'Edit the first post' }, revised_at: first_post.updated_at + 10.seconds) @@ -410,7 +410,7 @@ describe PostRevisor do }.to change { topic.excerpt } second_post = Fabricate(:post, post_args.merge(post_number: 2, topic_id: topic.id)) expect { - described_class.new(second_post).revise!(second_post.user, raw: 'Edit the 2nd post') + PostRevisor.new(second_post).revise!(second_post.user, raw: 'Edit the 2nd post') topic.reload }.to_not change { topic.excerpt } end @@ -423,10 +423,10 @@ describe PostRevisor do end context "#publish_changes" do - let!(:post) { Fabricate(:post, topic_id: topic.id) } + let!(:post) { Fabricate(:post, topic: topic) } it "should publish topic changes to clients" do - revisor = described_class.new(topic.ordered_posts.first, topic) + revisor = PostRevisor.new(topic.ordered_posts.first, topic) message = MessageBus.track_publish("/topic/#{topic.id}") do revisor.revise!(newuser, title: 'this is a test topic') diff --git a/spec/components/search_spec.rb b/spec/components/search_spec.rb index e293a87fd2e..0a70342d403 100644 --- a/spec/components/search_spec.rb +++ b/spec/components/search_spec.rb @@ -964,7 +964,7 @@ describe Search do context 'in:title' do it 'allows for search in title' do topic = Fabricate(:topic, title: 'I am testing a title search') - _post = Fabricate(:post, topic_id: topic.id, raw: 'this is the first post') + _post = Fabricate(:post, topic: topic, raw: 'this is the first post') results = Search.execute('title in:title') expect(results.posts.length).to eq(1) diff --git a/spec/components/topic_query_spec.rb b/spec/components/topic_query_spec.rb index fcce4812528..08515a3e9da 100644 --- a/spec/components/topic_query_spec.rb +++ b/spec/components/topic_query_spec.rb @@ -17,8 +17,8 @@ describe TopicQuery do category.set_permissions(group => :full) category.save - topic = Fabricate(:topic, category: category) - topic = Fabricate(:topic, visible: false) + Fabricate(:topic, category: category) + Fabricate(:topic, visible: false) expect(TopicQuery.new(nil).list_latest.topics.count).to eq(0) expect(TopicQuery.new(user).list_latest.topics.count).to eq(0) @@ -98,7 +98,7 @@ describe TopicQuery do context 'bookmarks' do it "filters and returns bookmarks correctly" do post = Fabricate(:post) - reply = Fabricate(:post, topic_id: post.topic_id) + reply = Fabricate(:post, topic: post.topic) post2 = Fabricate(:post) diff --git a/spec/components/validators/upload_validator_spec.rb b/spec/components/validators/upload_validator_spec.rb index 77dd4a1f0c0..164d0b0a8e8 100644 --- a/spec/components/validators/upload_validator_spec.rb +++ b/spec/components/validators/upload_validator_spec.rb @@ -1,4 +1,5 @@ require 'rails_helper' +require_dependency 'validators/upload_validator' describe Validators::UploadValidator do subject(:validator) { described_class.new } diff --git a/spec/controllers/admin/api_controller_spec.rb b/spec/controllers/admin/api_controller_spec.rb index af72b0529ad..27d73ea3ea1 100644 --- a/spec/controllers/admin/api_controller_spec.rb +++ b/spec/controllers/admin/api_controller_spec.rb @@ -11,7 +11,7 @@ describe Admin::ApiController do context '.index' do it "succeeds" do get :index, format: :json - expect(response).to be_success + expect(response).to be_successful end end @@ -20,7 +20,7 @@ describe Admin::ApiController do it "returns 404 when there is no key" do put :regenerate_key, params: { id: 1234 }, format: :json - expect(response).not_to be_success + expect(response).not_to be_successful expect(response.status).to eq(404) end @@ -35,7 +35,7 @@ describe Admin::ApiController do it "returns 404 when there is no key" do delete :revoke_key, params: { id: 1234 }, format: :json - expect(response).not_to be_success + expect(response).not_to be_successful expect(response.status).to eq(404) end diff --git a/spec/controllers/admin/backups_controller_spec.rb b/spec/controllers/admin/backups_controller_spec.rb index 4f7a6c78946..a4f1757a464 100644 --- a/spec/controllers/admin/backups_controller_spec.rb +++ b/spec/controllers/admin/backups_controller_spec.rb @@ -28,7 +28,7 @@ describe Admin::BackupsController do get :index, format: :html, xhr: true - expect(response).to be_success + expect(response).to be_successful end end @@ -40,7 +40,7 @@ describe Admin::BackupsController do get :index, format: :json, xhr: true - expect(response).to be_success + expect(response).to be_successful json = JSON.parse(response.body) expect(json[0]["filename"]).to eq("backup1") @@ -58,7 +58,7 @@ describe Admin::BackupsController do get :status, format: :json - expect(response).to be_success + expect(response).to be_successful end end @@ -72,7 +72,7 @@ describe Admin::BackupsController do with_uploads: false, client_id: "foo" }, format: :json - expect(response).to be_success + expect(response).to be_successful end end @@ -139,14 +139,14 @@ describe Admin::BackupsController do delete :destroy, params: { id: backup_filename }, format: :json - expect(response).to be_success + expect(response).to be_successful end it "doesn't remove the backup if not found" do Backup.expects(:[]).with(backup_filename).returns(nil) b.expects(:remove).never delete :destroy, params: { id: backup_filename }, format: :json - expect(response).not_to be_success + expect(response).not_to be_successful end end @@ -162,7 +162,7 @@ describe Admin::BackupsController do get :logs, format: :html, xhr: true - expect(response).to be_success + expect(response).to be_successful end end @@ -175,7 +175,7 @@ describe Admin::BackupsController do post :restore, params: { id: backup_filename, client_id: "foo" }, format: :json expect(SiteSetting.disable_emails).to eq(true) - expect(response).to be_success + expect(response).to be_successful end end @@ -188,7 +188,7 @@ describe Admin::BackupsController do expect { put :readonly, params: { enable: true }, format: :json } .to change { UserHistory.count }.by(1) - expect(response).to be_success + expect(response).to be_successful user_history = UserHistory.last @@ -202,7 +202,7 @@ describe Admin::BackupsController do expect { put :readonly, params: { enable: false }, format: :json } .to change { UserHistory.count }.by(1) - expect(response).to be_success + expect(response).to be_successful user_history = UserHistory.last diff --git a/spec/controllers/admin/badges_controller_spec.rb b/spec/controllers/admin/badges_controller_spec.rb index d5995aac40f..6751072d3a4 100644 --- a/spec/controllers/admin/badges_controller_spec.rb +++ b/spec/controllers/admin/badges_controller_spec.rb @@ -9,7 +9,7 @@ describe Admin::BadgesController do context 'index' do it 'returns badge index' do get :index, format: :json - expect(response).to be_success + expect(response).to be_successful end end @@ -79,7 +79,7 @@ describe Admin::BadgesController do it 'returns JSON' do get :badge_types, format: :json - expect(response).to be_success + expect(response).to be_successful expect(::JSON.parse(response.body)["badge_types"]).to be_present end end @@ -87,7 +87,7 @@ describe Admin::BadgesController do context '.destroy' do it 'deletes the badge' do delete :destroy, params: { id: badge.id }, format: :json - expect(response).to be_success + expect(response).to be_successful expect(Badge.where(id: badge.id).exists?).to eq(false) expect(UserHistory.where(acting_user_id: user.id, action: UserHistory.actions[:delete_badge]).exists?).to eq(true) end @@ -104,7 +104,7 @@ describe Admin::BadgesController do name: "123456" }, format: :json - expect(response).to be_success + expect(response).to be_successful editor_badge.reload expect(editor_badge.name).to eq(editor_badge_name) @@ -127,7 +127,7 @@ describe Admin::BadgesController do enabled: true }, format: :json - expect(response).to be_success + expect(response).to be_successful badge.reload expect(badge.name).to eq('123456') expect(badge.query).to eq('select 123') @@ -147,7 +147,7 @@ describe Admin::BadgesController do enabled: true }, format: :json - expect(response).to be_success + expect(response).to be_successful badge.reload expect(badge.name).to eq('123456') expect(badge.query).to eq(sql) diff --git a/spec/controllers/admin/color_schemes_controller_spec.rb b/spec/controllers/admin/color_schemes_controller_spec.rb index 6b11e219fb8..e748d1e002c 100644 --- a/spec/controllers/admin/color_schemes_controller_spec.rb +++ b/spec/controllers/admin/color_schemes_controller_spec.rb @@ -21,7 +21,7 @@ describe Admin::ColorSchemesController do Fabricate(:color_scheme) get :index, format: :json - expect(response).to be_success + expect(response).to be_successful expect(::JSON.parse(response.body)).to be_present end end @@ -30,7 +30,7 @@ describe Admin::ColorSchemesController do it "returns JSON" do post :create, params: valid_params, format: :json - expect(response).to be_success + expect(response).to be_successful expect(::JSON.parse(response.body)['id']).to be_present end @@ -40,7 +40,7 @@ describe Admin::ColorSchemesController do post :create, params: valid_params, format: :json - expect(response).not_to be_success + expect(response).not_to be_successful expect(::JSON.parse(response.body)['errors']).to be_present end end @@ -51,7 +51,7 @@ describe Admin::ColorSchemesController do it "returns success" do ColorSchemeRevisor.expects(:revise).returns(existing) put :update, params: valid_params.merge(id: existing.id), format: :json - expect(response).to be_success + expect(response).to be_successful end it "returns JSON" do @@ -66,7 +66,7 @@ describe Admin::ColorSchemesController do params[:color_scheme][:colors][0][:name] = color_scheme.colors.first.name params[:color_scheme][:colors][0][:hex] = 'cool color please' put :update, params: params, format: :json - expect(response).not_to be_success + expect(response).not_to be_successful expect(::JSON.parse(response.body)['errors']).to be_present end end @@ -78,7 +78,7 @@ describe Admin::ColorSchemesController do expect { delete :destroy, params: { id: existing.id }, format: :json }.to change { ColorScheme.count }.by(-1) - expect(response).to be_success + expect(response).to be_successful end end end diff --git a/spec/controllers/admin/dashboard_controller_spec.rb b/spec/controllers/admin/dashboard_controller_spec.rb index c190f72b7ea..cfde3a4ef5f 100644 --- a/spec/controllers/admin/dashboard_controller_spec.rb +++ b/spec/controllers/admin/dashboard_controller_spec.rb @@ -23,7 +23,7 @@ describe Admin::DashboardController do it 'returns discourse version info' do get :index, format: :json - expect(response).to be_success + expect(response).to be_successful expect(JSON.parse(response.body)['version_check']).to be_present end end @@ -50,7 +50,7 @@ describe Admin::DashboardController do it 'returns an empty array' do get :problems, format: :json - expect(response).to be_success + expect(response).to be_successful json = JSON.parse(response.body) expect(json['problems'].size).to eq(0) end diff --git a/spec/controllers/admin/email_controller_spec.rb b/spec/controllers/admin/email_controller_spec.rb index 0b0c2ffca2d..7f881f974ff 100644 --- a/spec/controllers/admin/email_controller_spec.rb +++ b/spec/controllers/admin/email_controller_spec.rb @@ -35,7 +35,7 @@ describe Admin::EmailController do end subject { response } - it { is_expected.to be_success } + it { is_expected.to be_successful } end context '.skipped' do @@ -44,7 +44,7 @@ describe Admin::EmailController do end subject { response } - it { is_expected.to be_success } + it { is_expected.to be_successful } end context '.test' do @@ -76,7 +76,7 @@ describe Admin::EmailController do last_seen_at: 1.week.ago, username: user.username }, format: :json - expect(response).to be_success + expect(response).to be_successful end end diff --git a/spec/controllers/admin/emojis_controller_spec.rb b/spec/controllers/admin/emojis_controller_spec.rb index 1b494f05718..7a1f3618c62 100644 --- a/spec/controllers/admin/emojis_controller_spec.rb +++ b/spec/controllers/admin/emojis_controller_spec.rb @@ -23,7 +23,7 @@ describe Admin::EmojisController do it "returns a list of custom emojis" do Emoji.expects(:custom).returns([custom_emoji]) get :index, format: :json - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json[0]["name"]).to eq(custom_emoji.name) expect(json[0]["url"]).to eq(custom_emoji.url) diff --git a/spec/controllers/admin/impersonate_controller_spec.rb b/spec/controllers/admin/impersonate_controller_spec.rb index 866e6898b5e..b9793cc80c2 100644 --- a/spec/controllers/admin/impersonate_controller_spec.rb +++ b/spec/controllers/admin/impersonate_controller_spec.rb @@ -13,7 +13,7 @@ describe Admin::ImpersonateController do context 'index' do it 'returns success' do get :index, format: :json - expect(response).to be_success + expect(response).to be_successful end end @@ -48,7 +48,7 @@ describe Admin::ImpersonateController do it "returns success" do post :create, params: { username_or_email: user.email }, format: :json - expect(response).to be_success + expect(response).to be_successful end it "also works with an email address" do diff --git a/spec/controllers/admin/permalinks_controller_spec.rb b/spec/controllers/admin/permalinks_controller_spec.rb index 1075150ab16..3befb17ff5c 100644 --- a/spec/controllers/admin/permalinks_controller_spec.rb +++ b/spec/controllers/admin/permalinks_controller_spec.rb @@ -17,7 +17,7 @@ describe Admin::PermalinksController do get :index, params: { filter: "topic" }, format: :json - expect(response).to be_success + expect(response).to be_successful result = JSON.parse(response.body) expect(result.length).to eq(2) end @@ -30,7 +30,7 @@ describe Admin::PermalinksController do get :index, params: { filter: "discourse" }, format: :json - expect(response).to be_success + expect(response).to be_successful result = JSON.parse(response.body) expect(result.length).to eq(2) end @@ -43,7 +43,7 @@ describe Admin::PermalinksController do get :index, params: { filter: "discourse" }, format: :json - expect(response).to be_success + expect(response).to be_successful result = JSON.parse(response.body) expect(result.length).to eq(3) end diff --git a/spec/controllers/admin/plugins_controller_spec.rb b/spec/controllers/admin/plugins_controller_spec.rb index 9df2c2737e1..7e599c55337 100644 --- a/spec/controllers/admin/plugins_controller_spec.rb +++ b/spec/controllers/admin/plugins_controller_spec.rb @@ -11,7 +11,7 @@ describe Admin::PluginsController do it 'should return JSON' do get :index, format: :json - expect(response).to be_success + expect(response).to be_successful expect(::JSON.parse(response.body).has_key?('plugins')).to eq(true) end end diff --git a/spec/controllers/admin/reports_controller_spec.rb b/spec/controllers/admin/reports_controller_spec.rb index 740df64afb0..021576405ed 100644 --- a/spec/controllers/admin/reports_controller_spec.rb +++ b/spec/controllers/admin/reports_controller_spec.rb @@ -45,7 +45,7 @@ describe Admin::ReportsController do end it "renders the report as JSON" do - expect(response).to be_success + expect(response).to be_successful end it "renders the report as JSON" do @@ -67,7 +67,7 @@ describe Admin::ReportsController do get :show, params: { type: 'topics', category_id: category.id }, format: :json - expect(response).to be_success + expect(response).to be_successful report = JSON.parse(response.body)["report"] @@ -87,7 +87,7 @@ describe Admin::ReportsController do get :show, params: { type: 'signups', group_id: group.id }, format: :json - expect(response).to be_success + expect(response).to be_successful report = JSON.parse(response.body)["report"] diff --git a/spec/controllers/admin/screened_emails_controller_spec.rb b/spec/controllers/admin/screened_emails_controller_spec.rb index fb4486a9b48..bd0503a60cc 100644 --- a/spec/controllers/admin/screened_emails_controller_spec.rb +++ b/spec/controllers/admin/screened_emails_controller_spec.rb @@ -13,7 +13,7 @@ describe Admin::ScreenedEmailsController do end subject { response } - it { is_expected.to be_success } + it { is_expected.to be_successful } it 'returns JSON' do expect(::JSON.parse(subject.body)).to be_a(Array) diff --git a/spec/controllers/admin/screened_ip_addresses_controller_spec.rb b/spec/controllers/admin/screened_ip_addresses_controller_spec.rb index 664fc85cdb2..4176173d3be 100644 --- a/spec/controllers/admin/screened_ip_addresses_controller_spec.rb +++ b/spec/controllers/admin/screened_ip_addresses_controller_spec.rb @@ -18,13 +18,13 @@ describe Admin::ScreenedIpAddressesController do get :index, params: { filter: "1.2.*" }, format: :json - expect(response).to be_success + expect(response).to be_successful result = JSON.parse(response.body) expect(result.length).to eq(3) get :index, params: { filter: "4.5.6.7" }, format: :json - expect(response).to be_success + expect(response).to be_successful result = JSON.parse(response.body) expect(result.length).to eq(1) end @@ -45,7 +45,7 @@ describe Admin::ScreenedIpAddressesController do SiteSetting.min_ban_entries_for_roll_up = 3 post :roll_up, format: :json - expect(response).to be_success + expect(response).to be_successful subnet = ScreenedIpAddress.where(ip_address: "1.2.3.0/24").first expect(subnet).to be_present @@ -65,7 +65,7 @@ describe Admin::ScreenedIpAddressesController do SiteSetting.min_ban_entries_for_roll_up = 5 post :roll_up, format: :json - expect(response).to be_success + expect(response).to be_successful subnet = ScreenedIpAddress.where(ip_address: "1.2.0.0/16").first expect(subnet).to be_present diff --git a/spec/controllers/admin/screened_urls_controller_spec.rb b/spec/controllers/admin/screened_urls_controller_spec.rb index 86d7fce0b72..e54ad12d303 100644 --- a/spec/controllers/admin/screened_urls_controller_spec.rb +++ b/spec/controllers/admin/screened_urls_controller_spec.rb @@ -13,7 +13,7 @@ describe Admin::ScreenedUrlsController do end subject { response } - it { is_expected.to be_success } + it { is_expected.to be_successful } it 'returns JSON' do expect(::JSON.parse(subject.body)).to be_a(Array) diff --git a/spec/controllers/admin/site_settings_controller_spec.rb b/spec/controllers/admin/site_settings_controller_spec.rb index 874f3756026..b1f6007e932 100644 --- a/spec/controllers/admin/site_settings_controller_spec.rb +++ b/spec/controllers/admin/site_settings_controller_spec.rb @@ -14,7 +14,7 @@ describe Admin::SiteSettingsController do context 'index' do it 'returns success' do get :index, format: :json - expect(response).to be_success + expect(response).to be_successful end it 'returns JSON' do diff --git a/spec/controllers/admin/site_texts_controller_spec.rb b/spec/controllers/admin/site_texts_controller_spec.rb index 7a1676a8315..6acb89da03c 100644 --- a/spec/controllers/admin/site_texts_controller_spec.rb +++ b/spec/controllers/admin/site_texts_controller_spec.rb @@ -14,7 +14,7 @@ describe Admin::SiteTextsController do context '.index' do it 'returns json' do get :index, params: { q: 'title' }, format: :json - expect(response).to be_success + expect(response).to be_successful expect(::JSON.parse(response.body)).to be_present end end @@ -22,7 +22,7 @@ describe Admin::SiteTextsController do context '.show' do it 'returns a site text for a key that exists' do get :show, params: { id: 'title' }, format: :json - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json).to be_present @@ -36,7 +36,7 @@ describe Admin::SiteTextsController do it 'returns not found for missing keys' do get :show, params: { id: 'made_up_no_key_exists' }, format: :json - expect(response).not_to be_success + expect(response).not_to be_successful end end @@ -71,7 +71,7 @@ describe Admin::SiteTextsController do orig_title = I18n.t(:title) put :update, params: { id: 'title', site_text: { value: 'hello' } }, format: :json - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json).to be_present @@ -84,7 +84,7 @@ describe Admin::SiteTextsController do # Revert put :revert, params: { id: 'title' }, format: :json - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json).to be_present @@ -101,7 +101,7 @@ describe Admin::SiteTextsController do id: 'made_up_no_key_exists', site_text: { value: 'hello' } }, format: :json - expect(response).not_to be_success + expect(response).not_to be_successful end it 'logs the change' do diff --git a/spec/controllers/admin/staff_action_logs_controller_spec.rb b/spec/controllers/admin/staff_action_logs_controller_spec.rb index 3da6dfa1587..5f12839e38e 100644 --- a/spec/controllers/admin/staff_action_logs_controller_spec.rb +++ b/spec/controllers/admin/staff_action_logs_controller_spec.rb @@ -17,7 +17,7 @@ describe Admin::StaffActionLogsController do get :index, params: { action_id: UserHistory.actions[:delete_topic] }, format: :json json = JSON.parse(response.body) - expect(response).to be_success + expect(response).to be_successful expect(json["staff_action_logs"].length).to eq(1) expect(json["staff_action_logs"][0]["action_name"]).to eq("delete_topic") @@ -41,7 +41,7 @@ describe Admin::StaffActionLogsController do .log_theme_change(original_json, theme) get :diff, params: { id: record.id }, format: :json - expect(response).to be_success + expect(response).to be_successful parsed = JSON.parse(response.body) expect(parsed["side_by_side"]).to include("up") diff --git a/spec/controllers/admin/themes_controller_spec.rb b/spec/controllers/admin/themes_controller_spec.rb index c2c00b78df3..e129499d4cf 100644 --- a/spec/controllers/admin/themes_controller_spec.rb +++ b/spec/controllers/admin/themes_controller_spec.rb @@ -66,7 +66,7 @@ describe Admin::ThemesController do upload.destroy post :import, params: { theme: uploaded_json }, format: :json - expect(response).to be_success + expect(response).to be_successful temp.unlink theme = Theme.last @@ -79,7 +79,7 @@ describe Admin::ThemesController do it 'imports a theme' do post :import, params: { theme: theme_file }, format: :json - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) @@ -113,7 +113,7 @@ describe Admin::ThemesController do get :index, format: :json - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) @@ -133,7 +133,7 @@ describe Admin::ThemesController do } }, format: :json - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) @@ -186,7 +186,7 @@ describe Admin::ThemesController do } }, format: :json - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) diff --git a/spec/controllers/admin/user_fields_controller_spec.rb b/spec/controllers/admin/user_fields_controller_spec.rb index de46a1cf0ce..b885c8b3894 100644 --- a/spec/controllers/admin/user_fields_controller_spec.rb +++ b/spec/controllers/admin/user_fields_controller_spec.rb @@ -16,7 +16,7 @@ describe Admin::UserFieldsController do user_field: { name: 'hello', description: 'hello desc', field_type: 'text' } }, format: :json - expect(response).to be_success + expect(response).to be_successful }.to change(UserField, :count).by(1) end @@ -31,7 +31,7 @@ describe Admin::UserFieldsController do } }, format: :json - expect(response).to be_success + expect(response).to be_successful end.to change(UserField, :count).by(1) expect(UserFieldOption.count).to eq(3) @@ -43,7 +43,7 @@ describe Admin::UserFieldsController do it "returns a list of user fields" do get :index, format: :json - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json['user_fields']).to be_present end @@ -55,7 +55,7 @@ describe Admin::UserFieldsController do it "deletes the user field" do expect { delete :destroy, params: { id: user_field.id }, format: :json - expect(response).to be_success + expect(response).to be_successful }.to change(UserField, :count).by(-1) end end @@ -69,7 +69,7 @@ describe Admin::UserFieldsController do user_field: { name: 'fraggle', field_type: 'confirm', description: 'muppet' } }, format: :json - expect(response).to be_success + expect(response).to be_successful user_field.reload expect(user_field.name).to eq('fraggle') expect(user_field.field_type).to eq('confirm') @@ -86,7 +86,7 @@ describe Admin::UserFieldsController do } }, format: :json - expect(response).to be_success + expect(response).to be_successful user_field.reload expect(user_field.name).to eq('fraggle') expect(user_field.field_type).to eq('dropdown') @@ -105,7 +105,7 @@ describe Admin::UserFieldsController do } }, format: :json - expect(response).to be_success + expect(response).to be_successful user_field.reload expect(user_field.user_field_options.size).to eq(2) @@ -119,7 +119,7 @@ describe Admin::UserFieldsController do } }, format: :json - expect(response).to be_success + expect(response).to be_successful user_field.reload expect(user_field.user_field_options.size).to eq(2) end diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb index d026d7bfb53..d82e74e06fd 100644 --- a/spec/controllers/admin/users_controller_spec.rb +++ b/spec/controllers/admin/users_controller_spec.rb @@ -15,7 +15,7 @@ describe Admin::UsersController do context '#index' do it 'returns success' do get :index, format: :json - expect(response).to be_success + expect(response).to be_successful end it 'returns JSON' do @@ -48,14 +48,14 @@ describe Admin::UsersController do context 'an existing user' do it 'returns success' do get :show, params: { id: @user.id }, format: :json - expect(response).to be_success + expect(response).to be_successful end end context 'an existing user' do it 'returns success' do get :show, params: { id: 0 }, format: :json - expect(response).not_to be_success + expect(response).not_to be_successful end end end @@ -135,7 +135,7 @@ describe Admin::UsersController do format: :json } ) - expect(response).to be_success + expect(response).to be_successful user.reload expect(user).to be_suspended @@ -160,7 +160,7 @@ describe Admin::UsersController do it "can have an associated post" do put(:suspend, params: suspend_params) - expect(response).to be_success + expect(response).to be_successful log = UserHistory.where(target_user_id: user.id).order('id desc').first expect(log).to be_present @@ -171,7 +171,7 @@ describe Admin::UsersController do put(:suspend, params: suspend_params.merge(post_action: 'delete')) post.reload expect(post.deleted_at).to be_present - expect(response).to be_success + expect(response).to be_successful end it "can edit an associated post" do @@ -182,7 +182,7 @@ describe Admin::UsersController do post.reload expect(post.deleted_at).to be_blank expect(post.raw).to eq("this is the edited content") - expect(response).to be_success + expect(response).to be_successful end end @@ -205,7 +205,7 @@ describe Admin::UsersController do format: :json } ) - expect(response).to be_success + expect(response).to be_successful log = UserHistory.where(target_user_id: user.id).order('id desc').first expect(log).to be_present @@ -274,7 +274,7 @@ describe Admin::UsersController do group_id: group.id, user_id: user.id }, format: :json - expect(response).to be_success + expect(response).to be_successful expect(GroupUser.where(user_id: user.id, group_id: group.id).exists?).to eq(true) group_history = GroupHistory.last @@ -288,7 +288,7 @@ describe Admin::UsersController do group_id: group.id, user_id: user.id }, format: :json - expect(response).to be_success + expect(response).to be_successful end end @@ -358,7 +358,7 @@ describe Admin::UsersController do user_id: @another_user.id }, format: :json - expect(response).not_to be_success + expect(response).not_to be_successful end it "returns a 404 if the username doesn't exist" do @@ -366,7 +366,7 @@ describe Admin::UsersController do user_id: 123123 }, format: :json - expect(response).not_to be_success + expect(response).not_to be_successful end it "upgrades the user's trust level" do @@ -378,7 +378,7 @@ describe Admin::UsersController do @another_user.reload expect(@another_user.trust_level).to eq(2) - expect(response).to be_success + expect(response).to be_successful end it "raises no error when demoting a user below their current trust level (locks trust level)" do @@ -394,7 +394,7 @@ describe Admin::UsersController do level: TrustLevel[0] }, format: :json - expect(response).to be_success + expect(response).to be_successful @another_user.reload expect(@another_user.trust_level).to eq(TrustLevel[0]) expect(@another_user.manual_locked_trust_level).to eq(TrustLevel[0]) @@ -474,7 +474,7 @@ describe Admin::UsersController do users: [reject_me.id, reject_me_too.id] }, format: :json - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json['success'].to_i).to eq(2) expect(json['failed'].to_i).to eq(0) @@ -493,7 +493,7 @@ describe Admin::UsersController do users: [reject_me.id, reject_me_too.id] }, format: :json - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json['success'].to_i).to eq(1) expect(json['failed'].to_i).to eq(1) @@ -506,7 +506,7 @@ describe Admin::UsersController do users: [reject_me.id] }, format: :json - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json['success'].to_i).to eq(0) expect(json['failed'].to_i).to eq(1) @@ -538,7 +538,7 @@ describe Admin::UsersController do it "doesn't return an error if delete_posts == true" do delete :destroy, params: { id: delete_me.id, delete_posts: true }, format: :json - expect(response).to be_success + expect(response).to be_successful end end @@ -555,7 +555,7 @@ describe Admin::UsersController do it "returns success" do put :activate, params: { user_id: @reg_user.id }, format: :json - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json['success']).to eq("OK") end @@ -567,7 +567,7 @@ describe Admin::UsersController do expect(@reg_user.email_confirmed?).to eq(false) put :activate, params: { user_id: @reg_user.id }, format: :json - expect(response).to be_success + expect(response).to be_successful @reg_user.reload expect(@reg_user.email_confirmed?).to eq(true) @@ -581,14 +581,14 @@ describe Admin::UsersController do it "returns success" do put :log_out, params: { user_id: @reg_user.id }, format: :json - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json['success']).to eq("OK") end it "returns 404 when user_id does not exist" do put :log_out, params: { user_id: 123123 }, format: :json - expect(response).not_to be_success + expect(response).not_to be_successful end end @@ -612,7 +612,7 @@ describe Admin::UsersController do it "punishes the user for spamming" do put :silence, params: { user_id: @reg_user.id }, format: :json - expect(response).to be_success + expect(response).to be_successful @reg_user.reload expect(@reg_user).to be_silenced end @@ -626,7 +626,7 @@ describe Admin::UsersController do post_action: 'edit', post_edit: "this is the new contents for the post" }, format: :json - expect(response).to be_success + expect(response).to be_successful silence_post.reload expect(silence_post.raw).to eq("this is the new contents for the post") @@ -731,7 +731,7 @@ describe Admin::UsersController do name: 'Bill', username: 'bill22', email: 'bill@bill.com' }, format: :json - expect(response).not_to be_success + expect(response).not_to be_successful end it 'should invite admin' do @@ -742,7 +742,7 @@ describe Admin::UsersController do name: 'Bill', username: 'bill22', email: 'bill@bill.com' }, format: :json - expect(response).to be_success + expect(response).to be_successful u = User.find_by_email('bill@bill.com') expect(u.name).to eq("Bill") @@ -758,7 +758,7 @@ describe Admin::UsersController do name: 'Bill', username: 'bill22', email: 'bill@bill.com', send_email: '0' }, format: :json - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json["password_url"]).to be_present end @@ -806,7 +806,7 @@ describe Admin::UsersController do sso.email = "bob2@bob.com" post :sync_sso, params: Rack::Utils.parse_query(sso.payload), format: :json - expect(response).to be_success + expect(response).to be_successful user.reload expect(user.email).to eq("bob2@bob.com") @@ -820,7 +820,7 @@ describe Admin::UsersController do sso.email = "dr@claw.com" sso.external_id = "2" post :sync_sso, params: Rack::Utils.parse_query(sso.payload), format: :json - expect(response).to be_success + expect(response).to be_successful user = User.find_by_email('dr@claw.com') expect(user).to be_present diff --git a/spec/controllers/admin/versions_controller_spec.rb b/spec/controllers/admin/versions_controller_spec.rb index 62c8cea39df..0d0811d70c1 100644 --- a/spec/controllers/admin/versions_controller_spec.rb +++ b/spec/controllers/admin/versions_controller_spec.rb @@ -21,7 +21,7 @@ describe Admin::VersionsController do describe 'show' do subject { get :show, format: :json } - it { is_expected.to be_success } + it { is_expected.to be_successful } it 'should return the currently available version' do json = JSON.parse(subject.body) diff --git a/spec/controllers/admin/web_hooks_controller_spec.rb b/spec/controllers/admin/web_hooks_controller_spec.rb index 6b793dd0deb..1d87cb43ce1 100644 --- a/spec/controllers/admin/web_hooks_controller_spec.rb +++ b/spec/controllers/admin/web_hooks_controller_spec.rb @@ -28,7 +28,7 @@ describe Admin::WebHooksController do } }, format: :json - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json["web_hook"]["payload_url"]).to be_present @@ -62,7 +62,7 @@ describe Admin::WebHooksController do post :ping, params: { id: web_hook.id }, format: :json - expect(response).to be_success + expect(response).to be_successful end end end diff --git a/spec/controllers/composer_messages_controller_spec.rb b/spec/controllers/composer_messages_controller_spec.rb index c2333fa33fc..27338ed8906 100644 --- a/spec/controllers/composer_messages_controller_spec.rb +++ b/spec/controllers/composer_messages_controller_spec.rb @@ -15,7 +15,7 @@ describe ComposerMessagesController do it 'redirects to your user preferences' do get :index, format: :json - expect(response).to be_success + expect(response).to be_successful end it 'delegates args to the finder' do diff --git a/spec/controllers/export_csv_controller_spec.rb b/spec/controllers/export_csv_controller_spec.rb index 2e1256653c9..d79c06875a2 100644 --- a/spec/controllers/export_csv_controller_spec.rb +++ b/spec/controllers/export_csv_controller_spec.rb @@ -10,19 +10,19 @@ describe ExportCsvController do it "enqueues export job" do Jobs.expects(:enqueue).with(:export_csv_file, has_entries(entity: "user_archive", user_id: @user.id)) post :export_entity, params: { entity: "user_archive" }, format: :json - expect(response).to be_success + expect(response).to be_successful end it "should not enqueue export job if rate limit is reached" do Jobs::ExportCsvFile.any_instance.expects(:execute).never UserExport.create(file_name: "user-archive-codinghorror-150116-003249", user_id: @user.id) post :export_entity, params: { entity: "user_archive" }, format: :json - expect(response).not_to be_success + expect(response).not_to be_successful end it "returns 404 when normal user tries to export admin entity" do post :export_entity, params: { entity: "staff_action" }, format: :json - expect(response).not_to be_success + expect(response).not_to be_successful end end end @@ -34,14 +34,14 @@ describe ExportCsvController do it "enqueues export job" do Jobs.expects(:enqueue).with(:export_csv_file, has_entries(entity: "staff_action", user_id: @admin.id)) post :export_entity, params: { entity: "staff_action" }, format: :json - expect(response).to be_success + expect(response).to be_successful end it "should not rate limit export for staff" do Jobs.expects(:enqueue).with(:export_csv_file, has_entries(entity: "staff_action", user_id: @admin.id)) UserExport.create(file_name: "screened-email-150116-010145", user_id: @admin.id) post :export_entity, params: { entity: "staff_action" }, format: :json - expect(response).to be_success + expect(response).to be_successful end end end diff --git a/spec/controllers/extra_locales_controller_spec.rb b/spec/controllers/extra_locales_controller_spec.rb index c3aa308d517..50a4234ce3f 100644 --- a/spec/controllers/extra_locales_controller_spec.rb +++ b/spec/controllers/extra_locales_controller_spec.rb @@ -16,13 +16,13 @@ describe ExtraLocalesController do it "needs a valid bundle" do get :show, params: { bundle: 'made-up-bundle' } - expect(response).to_not be_success + expect(response).to_not be_successful expect(response.body).to be_blank end it "won't work with a weird parameter" do get :show, params: { bundle: '-invalid..character!!' } - expect(response).to_not be_success + expect(response).to_not be_successful end it "includes plugin translations" do @@ -43,7 +43,7 @@ describe ExtraLocalesController do get :show, params: { bundle: "admin" } - expect(response).to be_success + expect(response).to be_successful expect(response.body.include?("github_badges")).to eq(true) end diff --git a/spec/controllers/finish_installation_controller_spec.rb b/spec/controllers/finish_installation_controller_spec.rb index e239a9af302..a7ee627ebe1 100644 --- a/spec/controllers/finish_installation_controller_spec.rb +++ b/spec/controllers/finish_installation_controller_spec.rb @@ -10,7 +10,7 @@ describe FinishInstallationController do it "doesn't allow access" do get :index - expect(response).not_to be_success + expect(response).not_to be_successful end end @@ -21,7 +21,7 @@ describe FinishInstallationController do it "allows access" do get :index - expect(response).to be_success + expect(response).to be_successful end end end @@ -34,7 +34,7 @@ describe FinishInstallationController do it "doesn't allow access" do get :register - expect(response).not_to be_success + expect(response).not_to be_successful end end @@ -46,7 +46,7 @@ describe FinishInstallationController do it "allows access" do get :register - expect(response).to be_success + expect(response).to be_successful end it "raises an error when the email is not in the allowed list" do @@ -92,7 +92,7 @@ describe FinishInstallationController do it "shows the page" do get :confirm_email - expect(response).to be_success + expect(response).to be_successful end end end @@ -112,7 +112,7 @@ describe FinishInstallationController do it "resends the email" do Jobs.expects(:enqueue).with(:critical_user_email, has_entries(type: :signup)) get :resend_email - expect(response).to be_success + expect(response).to be_successful end end end diff --git a/spec/controllers/inline_onebox_controller_spec.rb b/spec/controllers/inline_onebox_controller_spec.rb index e68387fa550..880c69fd98c 100644 --- a/spec/controllers/inline_onebox_controller_spec.rb +++ b/spec/controllers/inline_onebox_controller_spec.rb @@ -12,7 +12,7 @@ describe InlineOneboxController do it "returns empty JSON for empty input" do get :show, params: { urls: [] }, format: :json - expect(response).to be_success + expect(response).to be_successful json = JSON.parse(response.body) expect(json['inline-oneboxes']).to eq([]) end @@ -22,7 +22,7 @@ describe InlineOneboxController do it "returns information for a valid link" do get :show, params: { urls: [ topic.url ] }, format: :json - expect(response).to be_success + expect(response).to be_successful json = JSON.parse(response.body) onebox = json['inline-oneboxes'][0] diff --git a/spec/controllers/post_action_users_controller_spec.rb b/spec/controllers/post_action_users_controller_spec.rb index fdd6add07cd..302156f5d92 100644 --- a/spec/controllers/post_action_users_controller_spec.rb +++ b/spec/controllers/post_action_users_controller_spec.rb @@ -59,7 +59,7 @@ describe PostActionUsersController do id: post.id, post_action_type_id: PostActionType.types[:like] } - expect(response).to be_success + expect(response).to be_successful end it "paginates post actions" do diff --git a/spec/controllers/post_actions_controller_spec.rb b/spec/controllers/post_actions_controller_spec.rb index 0994fc601d1..69a5bc23892 100644 --- a/spec/controllers/post_actions_controller_spec.rb +++ b/spec/controllers/post_actions_controller_spec.rb @@ -46,7 +46,7 @@ describe PostActionsController do it 'returns success' do delete :destroy, params: { id: post.id, post_action_type_id: 1 }, format: :json - expect(response).to be_success + expect(response).to be_successful end it 'deletes the action' do @@ -113,7 +113,7 @@ describe PostActionsController do id: flagged_post.id, post_action_type_id: PostActionType.types[:spam] }, format: :json - expect(response).to be_success + expect(response).to be_successful end it "works with a deleted post" do @@ -123,7 +123,7 @@ describe PostActionsController do id: flagged_post.id, post_action_type_id: PostActionType.types[:spam] }, format: :json - expect(response).to be_success + expect(response).to be_successful end end diff --git a/spec/controllers/queued_posts_controller_spec.rb b/spec/controllers/queued_posts_controller_spec.rb index ac88c50479c..89620c116dc 100644 --- a/spec/controllers/queued_posts_controller_spec.rb +++ b/spec/controllers/queued_posts_controller_spec.rb @@ -6,7 +6,7 @@ describe QueuedPostsController do context 'without authentication' do it 'fails' do get :index, format: :json - expect(response).not_to be_success + expect(response).not_to be_successful end end @@ -14,7 +14,7 @@ describe QueuedPostsController do let!(:user) { log_in(:user) } it 'fails' do get :index, format: :json - expect(response).not_to be_success + expect(response).not_to be_successful end end @@ -23,7 +23,7 @@ describe QueuedPostsController do it 'returns the queued posts' do get :index, format: :json - expect(response).to be_success + expect(response).to be_successful end end @@ -52,7 +52,7 @@ describe QueuedPostsController do id: qp.id, queued_post: { state: 'approved' } }, format: :json - expect(response).to be_success + expect(response).to be_successful qp.reload expect(qp.state).to eq(QueuedPost.states[:approved]) @@ -66,7 +66,7 @@ describe QueuedPostsController do id: qp.id, queued_post: { state: 'rejected' } }, format: :json - expect(response).to be_success + expect(response).to be_successful qp.reload expect(qp.state).to eq(QueuedPost.states[:rejected]) @@ -91,7 +91,7 @@ describe QueuedPostsController do id: queued_topic.id, queued_post: changes }, format: :json - expect(response).to be_success + expect(response).to be_successful end it 'updates raw' do @@ -119,7 +119,7 @@ describe QueuedPostsController do id: queued_reply.id, queued_post: changes }, format: :json - expect(response).to be_success + expect(response).to be_successful end it 'updates raw' do diff --git a/spec/controllers/site_controller_spec.rb b/spec/controllers/site_controller_spec.rb index c36a79589c6..78d2b8d4938 100644 --- a/spec/controllers/site_controller_spec.rb +++ b/spec/controllers/site_controller_spec.rb @@ -34,7 +34,7 @@ describe SiteController do get :statistics, format: :json json = JSON.parse(response.body) - expect(response).to be_success + expect(response).to be_successful expect(json["topic_count"]).to be_present expect(json["post_count"]).to be_present expect(json["user_count"]).to be_present diff --git a/spec/controllers/steps_controller_spec.rb b/spec/controllers/steps_controller_spec.rb index ec1f7fd6089..2c0603ca4cd 100644 --- a/spec/controllers/steps_controller_spec.rb +++ b/spec/controllers/steps_controller_spec.rb @@ -41,7 +41,7 @@ describe StepsController do id: 'contact', fields: { contact_email: "eviltrout@example.com" } }, format: :json - expect(response).to be_success + expect(response).to be_successful expect(SiteSetting.contact_email).to eq("eviltrout@example.com") end @@ -50,7 +50,7 @@ describe StepsController do id: 'contact', fields: { contact_email: "not-an-email" } }, format: :json - expect(response).to_not be_success + expect(response).to_not be_successful end end diff --git a/spec/controllers/stylesheets_controller_spec.rb b/spec/controllers/stylesheets_controller_spec.rb index a68ccc62bed..67f432f95bd 100644 --- a/spec/controllers/stylesheets_controller_spec.rb +++ b/spec/controllers/stylesheets_controller_spec.rb @@ -12,7 +12,7 @@ describe StylesheetsController do StylesheetCache.destroy_all get :show, params: { name: "desktop_rtl_#{digest}" }, format: :json - expect(response).to be_success + expect(response).to be_successful cached = StylesheetCache.first expect(cached.target).to eq 'desktop_rtl' @@ -22,7 +22,7 @@ describe StylesheetsController do `rm #{Stylesheet::Manager.cache_fullpath}/*` get :show, params: { name: "desktop_rtl_#{digest}" }, format: :json - expect(response).to be_success + expect(response).to be_successful # there is an edge case which is ... disk and db cache is nuked, very unlikely to happen @@ -41,13 +41,13 @@ describe StylesheetsController do name: builder.stylesheet_filename.sub(".css", "") }, format: :json - expect(response).to be_success + expect(response).to be_successful get :show, params: { name: builder.stylesheet_filename_no_digest.sub(".css", "") }, format: :json - expect(response).to be_success + expect(response).to be_successful builder = Stylesheet::Manager.new(:desktop_theme, theme.key) builder.compile @@ -58,13 +58,13 @@ describe StylesheetsController do name: builder.stylesheet_filename.sub(".css", "") }, format: :json - expect(response).to be_success + expect(response).to be_successful get :show, params: { name: builder.stylesheet_filename_no_digest.sub(".css", "") }, format: :json - expect(response).to be_success + expect(response).to be_successful end end diff --git a/spec/controllers/user_actions_controller_spec.rb b/spec/controllers/user_actions_controller_spec.rb index 79cf2ac1084..d6e6ae949c2 100644 --- a/spec/controllers/user_actions_controller_spec.rb +++ b/spec/controllers/user_actions_controller_spec.rb @@ -64,7 +64,7 @@ describe UserActionsController do get :index, params: { username: user.username, filter: UserAction::PENDING }, format: :json - expect(response).to_not be_success + expect(response).to_not be_successful end end diff --git a/spec/controllers/user_avatars_controller_spec.rb b/spec/controllers/user_avatars_controller_spec.rb index 7218cd8a065..9e485a091f6 100644 --- a/spec/controllers/user_avatars_controller_spec.rb +++ b/spec/controllers/user_avatars_controller_spec.rb @@ -72,7 +72,7 @@ describe UserAvatarsController do size: 51, username: user.username, version: upload.id, hostname: 'default' }, format: :json - expect(response).to be_success + expect(response).to be_successful end end end diff --git a/spec/controllers/webhooks_controller_spec.rb b/spec/controllers/webhooks_controller_spec.rb index b5b049ca8a4..cfd8c6f9de5 100644 --- a/spec/controllers/webhooks_controller_spec.rb +++ b/spec/controllers/webhooks_controller_spec.rb @@ -24,7 +24,7 @@ describe WebhooksController do "Message-Id" => "<12345@il.com>" }, format: :json - expect(response).to be_success + expect(response).to be_successful email_log.reload expect(email_log.bounced).to eq(true) @@ -50,7 +50,7 @@ describe WebhooksController do ] }, format: :json - expect(response).to be_success + expect(response).to be_successful email_log.reload expect(email_log.bounced).to eq(true) @@ -72,7 +72,7 @@ describe WebhooksController do "CustomID" => message_id }, format: :json - expect(response).to be_success + expect(response).to be_successful email_log.reload expect(email_log.bounced).to eq(true) @@ -99,7 +99,7 @@ describe WebhooksController do }] }, format: :json - expect(response).to be_success + expect(response).to be_successful email_log.reload expect(email_log.bounced).to eq(true) @@ -128,7 +128,7 @@ describe WebhooksController do }] }, format: :json - expect(response).to be_success + expect(response).to be_successful email_log.reload expect(email_log.bounced).to eq(true) diff --git a/spec/controllers/wizard_controller_spec.rb b/spec/controllers/wizard_controller_spec.rb index 0875e31c264..e99e911fede 100644 --- a/spec/controllers/wizard_controller_spec.rb +++ b/spec/controllers/wizard_controller_spec.rb @@ -37,13 +37,13 @@ describe WizardController do it "renders the wizard if you are an admin" do log_in(:admin) get :index, format: :json - expect(response).to be_success + expect(response).to be_successful end it "returns JSON when the mime type is appropriate" do log_in(:admin) get :index, format: 'json' - expect(response).to be_success + expect(response).to be_successful expect(::JSON.parse(response.body).has_key?('wizard')).to eq(true) end end diff --git a/spec/fabricators/topic_fabricator.rb b/spec/fabricators/topic_fabricator.rb index b3efbb98e3d..4e276237a70 100644 --- a/spec/fabricators/topic_fabricator.rb +++ b/spec/fabricators/topic_fabricator.rb @@ -1,7 +1,9 @@ Fabricator(:topic) do user title { sequence(:title) { |i| "This is a test topic #{i}" } } - category_id { SiteSetting.uncategorized_category_id } + category_id do |attrs| + attrs[:category] ? attrs[:category].id : SiteSetting.uncategorized_category_id + end end Fabricator(:deleted_topic, from: :topic) do diff --git a/spec/jobs/toggle_topic_closed_spec.rb b/spec/jobs/toggle_topic_closed_spec.rb index 77e1afbe081..8e65312eebb 100644 --- a/spec/jobs/toggle_topic_closed_spec.rb +++ b/spec/jobs/toggle_topic_closed_spec.rb @@ -10,7 +10,7 @@ describe Jobs::ToggleTopicClosed do it 'should be able to close a topic' do topic - freeze_time(1.hour.from_now) do + freeze_time(61.minutes.from_now) do described_class.new.execute( topic_timer_id: topic.public_topic_timer.id, state: true @@ -19,7 +19,7 @@ describe Jobs::ToggleTopicClosed do expect(topic.reload.closed).to eq(true) expect(Post.last.raw).to eq(I18n.t( - 'topic_statuses.autoclosed_enabled_minutes', count: 60 + 'topic_statuses.autoclosed_enabled_minutes', count: 61 )) end end diff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rb index b460306d369..96fe9ea0d2b 100644 --- a/spec/models/post_action_spec.rb +++ b/spec/models/post_action_spec.rb @@ -9,7 +9,7 @@ describe PostAction do let(:eviltrout) { Fabricate(:evil_trout) } let(:admin) { Fabricate(:admin) } let(:post) { Fabricate(:post) } - let(:second_post) { Fabricate(:post, topic_id: post.topic_id) } + let(:second_post) { Fabricate(:post, topic: post.topic) } let(:bookmark) { PostAction.new(user_id: post.user_id, post_action_type_id: PostActionType.types[:bookmark] , post_id: post.id) } def value_for(user_id, dt) diff --git a/spec/models/tag_spec.rb b/spec/models/tag_spec.rb index c7cc72496bb..69dd546e8da 100644 --- a/spec/models/tag_spec.rb +++ b/spec/models/tag_spec.rb @@ -48,12 +48,12 @@ describe Tag do describe '#top_tags' do it "returns nothing if nothing has been tagged" do make_some_tags(tag_a_topic: false) - expect(described_class.top_tags.sort).to be_empty + expect(Tag.top_tags.sort).to be_empty end it "can return all tags" do make_some_tags(tag_a_topic: true) - expect(described_class.top_tags.sort).to eq(@tags.map(&:name).sort) + expect(Tag.top_tags.sort).to eq(@tags.map(&:name).sort) end context "with categories" do @@ -69,27 +69,17 @@ describe Tag do @topics << Fabricate(:topic, category: @private_category, tags: [@tags[2]]) end - it "doesn't return tags that have only been used in private category to anon" do - expect(described_class.top_tags.sort).to eq([@tags[0].name, @tags[1].name].sort) - end + it "works correctly" do + expect(Tag.top_tags(category: @category1).sort).to eq([@tags[0].name].sort) + expect(Tag.top_tags(guardian: Guardian.new(Fabricate(:admin))).sort).to eq([@tags[0].name, @tags[1].name, @tags[2].name].sort) + expect(Tag.top_tags(category: @private_category, guardian: Guardian.new(Fabricate(:admin))).sort).to eq([@tags[2].name].sort) - it "returns tags used in private category to those who can see that category" do - expect(described_class.top_tags(guardian: Guardian.new(Fabricate(:admin))).sort).to eq([@tags[0].name, @tags[1].name, @tags[2].name].sort) - end + expect(Tag.top_tags.sort).to eq([@tags[0].name, @tags[1].name].sort) + expect(Tag.top_tags(category: @private_category)).to be_empty - it "returns tags scoped to a given category" do - expect(described_class.top_tags(category: @category1).sort).to eq([@tags[0].name].sort) - expect(described_class.top_tags(category: @private_category, guardian: Guardian.new(Fabricate(:admin))).sort).to eq([@tags[2].name].sort) - end - - it "returns tags from sub-categories too" do sub_category = Fabricate(:category, parent_category_id: @category1.id) Fabricate(:topic, category: sub_category, tags: [@tags[1]]) - expect(described_class.top_tags(category: @category1).sort).to eq([@tags[0].name, @tags[1].name].sort) - end - - it "returns nothing if category arg is private to you" do - expect(described_class.top_tags(category: @private_category)).to be_empty + expect(Tag.top_tags(category: @category1).sort).to eq([@tags[0].name, @tags[1].name].sort) end end @@ -105,15 +95,15 @@ describe Tag do end it "for category with restricted tags, lists those tags" do - expect(described_class.top_tags(category: @category1)).to eq([@tags[0].name]) + expect(Tag.top_tags(category: @category1)).to eq([@tags[0].name]) end it "for category without tags, lists allowed tags" do - expect(described_class.top_tags(category: @category2).sort).to eq([@tags[1].name, @tags[2].name].sort) + expect(Tag.top_tags(category: @category2).sort).to eq([@tags[1].name, @tags[2].name].sort) end it "for no category arg, lists all tags" do - expect(described_class.top_tags.sort).to eq([@tags[0].name, @tags[1].name, @tags[2].name].sort) + expect(Tag.top_tags.sort).to eq([@tags[0].name, @tags[1].name, @tags[2].name].sort) end end @@ -151,17 +141,17 @@ describe Tag do end it "returns nothing if user is not a staff" do - expect(described_class.pm_tags(guardian: Guardian.new(regular_user))).to be_empty + expect(Tag.pm_tags(guardian: Guardian.new(regular_user))).to be_empty end it "returns nothing if allow_staff_to_tag_pms setting is disabled" do SiteSetting.allow_staff_to_tag_pms = false - expect(described_class.pm_tags(guardian: Guardian.new(admin)).sort).to be_empty + expect(Tag.pm_tags(guardian: Guardian.new(admin)).sort).to be_empty end it "returns all pm tags if user is a staff and pm tagging is enabled" do SiteSetting.allow_staff_to_tag_pms = true - tags = described_class.pm_tags(guardian: Guardian.new(admin), allowed_user: regular_user) + tags = Tag.pm_tags(guardian: Guardian.new(admin), allowed_user: regular_user) expect(tags.length).to eq(2) expect(tags.map { |t| t[:id] }).to contain_exactly("tag-0", "tag-1") end @@ -171,7 +161,7 @@ describe Tag do it "should exclude private message topics" do topic Fabricate(:private_message_topic, tags: [tag]) - described_class.ensure_consistency! + Tag.ensure_consistency! tag.reload expect(tag.topic_count).to eq(1) end diff --git a/spec/models/topic_featured_users_spec.rb b/spec/models/topic_featured_users_spec.rb index 09459115eaa..b874854d6be 100644 --- a/spec/models/topic_featured_users_spec.rb +++ b/spec/models/topic_featured_users_spec.rb @@ -4,11 +4,11 @@ describe TopicFeaturedUsers do it 'ensures consistency' do t = Fabricate(:topic) - Fabricate(:post, topic_id: t.id, user_id: t.user_id) - p2 = Fabricate(:post, topic_id: t.id) - p3 = Fabricate(:post, topic_id: t.id, user_id: p2.user_id) - p4 = Fabricate(:post, topic_id: t.id) - p5 = Fabricate(:post, topic_id: t.id) + Fabricate(:post, topic: t, user: t.user) + p2 = Fabricate(:post, topic: t) + p3 = Fabricate(:post, topic: t, user: p2.user) + p4 = Fabricate(:post, topic: t) + p5 = Fabricate(:post, topic: t) t.update_columns(featured_user1_id: 66, featured_user2_id: 70, diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index 57ad210e343..0da4b29bd6b 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -1612,8 +1612,7 @@ describe Topic do it "doesn't return topics from TL0 users" do new_user = Fabricate(:user, trust_level: 0) - Fabricate(:topic, user_id: new_user.id) - + Fabricate(:topic, user: new_user) expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to be_blank end @@ -1626,7 +1625,7 @@ describe Topic do it "returns topics from TL0 users if enabled in preferences" do new_user = Fabricate(:user, trust_level: 0) - topic = Fabricate(:topic, user_id: new_user.id) + topic = Fabricate(:topic, user: new_user) u = Fabricate(:user) u.user_option.include_tl0_in_digests = true @@ -1656,7 +1655,7 @@ describe Topic do user = Fabricate(:user) muted_tag = Fabricate(:tag) TagUser.change(user.id, muted_tag.id, TagUser.notification_levels[:muted]) - topic1 = Fabricate(:topic, tags: [muted_tag]) + _topic1 = Fabricate(:topic, tags: [muted_tag]) topic2 = Fabricate(:topic, tags: [Fabricate(:tag), Fabricate(:tag)]) topic3 = Fabricate(:topic) @@ -1693,7 +1692,7 @@ describe Topic do it "excludes topics that are within the grace period" do topic1 = Fabricate(:topic, created_at: 6.minutes.ago) - topic2 = Fabricate(:topic, created_at: 4.minutes.ago) + _topic2 = Fabricate(:topic, created_at: 4.minutes.ago) expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to eq([topic1]) end end @@ -2180,9 +2179,9 @@ describe Topic do end it "returns 0 with a topic with 1 reply" do - topic = Fabricate(:topic, created_at: 5.hours.ago) - post1 = Fabricate(:post, topic: topic, user: topic.user, post_number: 1, created_at: 5.hours.ago) - post1 = Fabricate(:post, topic: topic, post_number: 2, created_at: 2.hours.ago) + topic = Fabricate(:topic, created_at: 5.hours.ago) + _post1 = Fabricate(:post, topic: topic, user: topic.user, post_number: 1, created_at: 5.hours.ago) + _post2 = Fabricate(:post, topic: topic, post_number: 2, created_at: 2.hours.ago) expect(Topic.with_no_response_per_day(5.days.ago, Time.zone.now).count).to eq(0) expect(Topic.with_no_response_total).to eq(0) end diff --git a/spec/models/topic_timer_spec.rb b/spec/models/topic_timer_spec.rb index 639ef1d55ea..dec05487fc3 100644 --- a/spec/models/topic_timer_spec.rb +++ b/spec/models/topic_timer_spec.rb @@ -5,6 +5,10 @@ RSpec.describe TopicTimer, type: :model do let(:topic) { Fabricate(:topic) } let(:admin) { Fabricate(:admin) } + before do + freeze_time Time.new(2018) + end + context "validations" do describe '#status_type' do it 'should ensure that only one active public topic status update exists' do diff --git a/spec/requests/about_controller_spec.rb b/spec/requests/about_controller_spec.rb index e4e4b01a0a2..ec4e07d4bc9 100644 --- a/spec/requests/about_controller_spec.rb +++ b/spec/requests/about_controller_spec.rb @@ -8,7 +8,7 @@ describe AboutController do SiteSetting.login_required = false get "/about" - expect(response).to be_success + expect(response).to be_successful end it 'should redirect to login page for anonymous user when login_required is true' do @@ -23,7 +23,7 @@ describe AboutController do sign_in(Fabricate(:user)) get "/about" - expect(response).to be_success + expect(response).to be_successful end end end diff --git a/spec/requests/admin/backups_controller_spec.rb b/spec/requests/admin/backups_controller_spec.rb index 7504cb31c3e..d4be1f1674a 100644 --- a/spec/requests/admin/backups_controller_spec.rb +++ b/spec/requests/admin/backups_controller_spec.rb @@ -11,7 +11,7 @@ RSpec.describe Admin::BackupsController do it "raises an error when backups are disabled" do SiteSetting.enable_backups = false get "/admin/backups.json" - expect(response).not_to be_success + expect(response).not_to be_successful end end @@ -21,7 +21,7 @@ RSpec.describe Admin::BackupsController do post "/admin/backups/rollback.json" - expect(response).to be_success + expect(response).to be_successful end it 'should not allow rollback via a GET request' do @@ -36,7 +36,7 @@ RSpec.describe Admin::BackupsController do delete "/admin/backups/cancel.json" - expect(response).to be_success + expect(response).to be_successful end it 'should not allow cancel via a GET request' do @@ -59,7 +59,7 @@ RSpec.describe Admin::BackupsController do put "/admin/backups/#{backup_filename}.json" - expect(response).to be_success + expect(response).to be_successful end it "returns 404 when the backup does not exist" do diff --git a/spec/requests/admin/email_templates_controller_spec.rb b/spec/requests/admin/email_templates_controller_spec.rb index 9babb31b383..8957a567172 100644 --- a/spec/requests/admin/email_templates_controller_spec.rb +++ b/spec/requests/admin/email_templates_controller_spec.rb @@ -33,7 +33,7 @@ RSpec.describe Admin::EmailTemplatesController do sign_in(admin) get '/admin/customize/email_templates.json' - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json['email_templates']).to be_present @@ -66,7 +66,7 @@ RSpec.describe Admin::EmailTemplatesController do email_template: { subject: 'Foo', body: 'Bar' } }, headers: headers - expect(response).not_to be_success + expect(response).not_to be_successful json = ::JSON.parse(response.body) expect(json['error_type']).to eq('not_found') @@ -169,7 +169,7 @@ RSpec.describe Admin::EmailTemplatesController do email_template: { subject: email_subject, body: email_body } }, headers: headers - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json).to be_present @@ -237,7 +237,7 @@ RSpec.describe Admin::EmailTemplatesController do it "returns 'not found' when an unknown email template id is used" do delete '/admin/customize/email_templates/non_existent_template', headers: headers - expect(response).not_to be_success + expect(response).not_to be_successful json = ::JSON.parse(response.body) expect(json['error_type']).to eq('not_found') @@ -265,7 +265,7 @@ RSpec.describe Admin::EmailTemplatesController do it "returns the restored email template" do delete '/admin/customize/email_templates/user_notifications.admin_login', headers: headers - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json).to be_present diff --git a/spec/requests/admin/flagged_topics_controller_spec.rb b/spec/requests/admin/flagged_topics_controller_spec.rb index 8f768294bc7..87dfde84e38 100644 --- a/spec/requests/admin/flagged_topics_controller_spec.rb +++ b/spec/requests/admin/flagged_topics_controller_spec.rb @@ -6,7 +6,7 @@ RSpec.describe Admin::FlaggedTopicsController do shared_examples "successfully retrieve list of flagged topics" do it "returns a list of flagged topics" do get "/admin/flagged_topics.json" - expect(response).to be_success + expect(response).to be_successful data = ::JSON.parse(response.body) expect(data['flagged_topics']).to be_present diff --git a/spec/requests/admin/flags_controller_spec.rb b/spec/requests/admin/flags_controller_spec.rb index 98ee91c8510..1d711d590ba 100644 --- a/spec/requests/admin/flags_controller_spec.rb +++ b/spec/requests/admin/flags_controller_spec.rb @@ -13,7 +13,7 @@ RSpec.describe Admin::FlagsController do it 'should return the right response when nothing is flagged' do get '/admin/flags.json' - expect(response).to be_success + expect(response).to be_successful data = ::JSON.parse(response.body) expect(data["users"]).to eq([]) @@ -25,11 +25,11 @@ RSpec.describe Admin::FlagsController do get '/admin/flags.json' - expect(response).to be_success + expect(response).to be_successful data = ::JSON.parse(response.body) - data["users"].length == 2 - data["posts"].length == 1 + expect(data["users"].length).to eq(2) + expect(data["posts"].length).to eq(1) end end @@ -49,9 +49,8 @@ RSpec.describe Admin::FlagsController do expect(post_action.agreed_by_id).to eq(admin.id) - post_1 = Post.offset(1).last - - expect(post_1.raw).to eq(I18n.with_locale(:en) { I18n.t('flags_dispositions.agreed') }) + agree_post = Topic.joins(:topic_allowed_users).where('topic_allowed_users.user_id = ?', user.id).order(:id).last.posts.last + expect(agree_post.raw).to eq(I18n.with_locale(:en) { I18n.t('flags_dispositions.agreed') }) end end end diff --git a/spec/requests/admin/moderation_history_controller_spec.rb b/spec/requests/admin/moderation_history_controller_spec.rb index f16d340faef..1b73f386688 100644 --- a/spec/requests/admin/moderation_history_controller_spec.rb +++ b/spec/requests/admin/moderation_history_controller_spec.rb @@ -10,28 +10,28 @@ RSpec.describe Admin::BackupsController do describe "parameters" do it "returns 404 without a valid filter" do get "/admin/moderation_history.json" - expect(response).not_to be_success + expect(response).not_to be_successful end it "returns 404 without a valid id" do get "/admin/moderation_history.json?filter=topic" - expect(response).not_to be_success + expect(response).not_to be_successful end end describe "for a post" do it "returns an empty array when the post doesn't exist" do get "/admin/moderation_history.json?filter=post&post_id=99999999" - expect(response).to be_success + expect(response).to be_successful expect(::JSON.parse(response.body)['moderation_history']).to be_blank end it "returns a history when the post exists" do p = Fabricate(:post) - p = Fabricate(:post, topic_id: p.topic_id) + p = Fabricate(:post, topic: p.topic) PostDestroyer.new(Discourse.system_user, p).destroy get "/admin/moderation_history.json?filter=post&post_id=#{p.id}" - expect(response).to be_success + expect(response).to be_successful expect(::JSON.parse(response.body)['moderation_history']).to be_present end @@ -40,7 +40,7 @@ RSpec.describe Admin::BackupsController do describe "for a topic" do it "returns empty history when the topic doesn't exist" do get "/admin/moderation_history.json?filter=topic&topic_id=1234" - expect(response).to be_success + expect(response).to be_successful expect(::JSON.parse(response.body)['moderation_history']).to be_blank end @@ -48,7 +48,7 @@ RSpec.describe Admin::BackupsController do p = Fabricate(:post) PostDestroyer.new(Discourse.system_user, p).destroy get "/admin/moderation_history.json?filter=topic&topic_id=#{p.topic_id}" - expect(response).to be_success + expect(response).to be_successful expect(::JSON.parse(response.body)['moderation_history']).to be_present end end diff --git a/spec/requests/admin/search_logs_spec.rb b/spec/requests/admin/search_logs_spec.rb index f811bfd44f4..f872fb87001 100644 --- a/spec/requests/admin/search_logs_spec.rb +++ b/spec/requests/admin/search_logs_spec.rb @@ -28,7 +28,7 @@ RSpec.describe Admin::SearchLogsController do sign_in(admin) get '/admin/logs/search_logs.json' - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json[0]['term']).to eq('ruby') @@ -51,7 +51,7 @@ RSpec.describe Admin::SearchLogsController do sign_in(admin) get '/admin/logs/search_logs/term/ruby.json' - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json['term']['type']).to eq('search_log_term') diff --git a/spec/requests/categories_controller_spec.rb b/spec/requests/categories_controller_spec.rb index 3c1ca0ea2d4..be6039564bf 100644 --- a/spec/requests/categories_controller_spec.rb +++ b/spec/requests/categories_controller_spec.rb @@ -136,7 +136,7 @@ describe CategoriesController do expect do delete "/categories/#{category.slug}.json" end.to change(Category, :count).by(-1) - expect(response).to be_success + expect(response).to be_successful expect(UserHistory.count).to eq(1) end end @@ -321,14 +321,14 @@ describe CategoriesController do it 'accepts valid custom slug' do put "/category/#{category.id}/slug.json", params: { slug: 'valid-slug' } - expect(response).to be_success + expect(response).to be_successful expect(category.reload.slug).to eq('valid-slug') end it 'accepts not well formed custom slug' do put "/category/#{category.id}/slug.json", params: { slug: ' valid slug' } - expect(response).to be_success + expect(response).to be_successful expect(category.reload.slug).to eq('valid-slug') end @@ -336,7 +336,7 @@ describe CategoriesController do SiteSetting.slug_generation_method = 'none' put "/category/#{category.id}/slug.json", params: { slug: ' another !_ slug @' } - expect(response).to be_success + expect(response).to be_successful expect(category.reload.slug).to eq('another-slug') SiteSetting.slug_generation_method = 'ascii' end diff --git a/spec/requests/directory_items_controller_spec.rb b/spec/requests/directory_items_controller_spec.rb index c9126347032..f9b0e08b888 100644 --- a/spec/requests/directory_items_controller_spec.rb +++ b/spec/requests/directory_items_controller_spec.rb @@ -14,7 +14,7 @@ describe DirectoryItemsController do it "requires a proper `period` param" do get '/directory_items.json', params: { period: 'eviltrout' } - expect(response).not_to be_success + expect(response).not_to be_successful end context "without data" do @@ -24,7 +24,7 @@ describe DirectoryItemsController do it "succeeds" do get '/directory_items.json', params: { period: 'all' } - expect(response).to be_success + expect(response).to be_successful end end @@ -37,7 +37,7 @@ describe DirectoryItemsController do it "succeeds with a valid value" do get '/directory_items.json', params: { period: 'all' } - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json).to be_present @@ -53,12 +53,12 @@ describe DirectoryItemsController do SiteSetting.enable_user_directory = false get '/directory_items.json', params: { period: 'all' } - expect(response).not_to be_success + expect(response).not_to be_successful end it "finds user by name" do get '/directory_items.json', params: { period: 'all', name: 'eviltrout' } - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json).to be_present @@ -69,7 +69,7 @@ describe DirectoryItemsController do it "finds staged user by name" do get '/directory_items.json', params: { period: 'all', name: 'stage_user' } - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json).to be_present @@ -80,7 +80,7 @@ describe DirectoryItemsController do it "excludes users by username" do get '/directory_items.json', params: { period: 'all', exclude_usernames: "stage_user,eviltrout" } - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json).to be_present @@ -92,7 +92,7 @@ describe DirectoryItemsController do it "filters users by group" do get '/directory_items.json', params: { period: 'all', group: group.name } - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json).to be_present diff --git a/spec/requests/email_controller_spec.rb b/spec/requests/email_controller_spec.rb index 188ac1807fb..062c24461a0 100644 --- a/spec/requests/email_controller_spec.rb +++ b/spec/requests/email_controller_spec.rb @@ -145,7 +145,7 @@ RSpec.describe EmailController do key = SecureRandom.hex $redis.set(key, user.email) get '/email/unsubscribed', params: { key: key, topic_id: topic.id } - expect(response).to be_success + expect(response).to be_successful expect(response.body).to include(topic.title) end end @@ -155,7 +155,7 @@ RSpec.describe EmailController do key = SecureRandom.hex $redis.set(key, user.email) get '/email/unsubscribed', params: { key: key, topic_id: private_topic.id } - expect(response).to be_success + expect(response).to be_successful expect(response.body).to_not include(private_topic.title) end end diff --git a/spec/requests/embed_controller_spec.rb b/spec/requests/embed_controller_spec.rb index 42b6f018d3f..c62222a8cc7 100644 --- a/spec/requests/embed_controller_spec.rb +++ b/spec/requests/embed_controller_spec.rb @@ -27,7 +27,7 @@ describe EmbedController do it "allows a topic to be embedded by id" do topic = Fabricate(:topic) get '/embed/comments', params: { topic_id: topic.id }, headers: headers - expect(response).to be_success + expect(response).to be_successful end end @@ -85,7 +85,7 @@ describe EmbedController do end after do - expect(response).to be_success + expect(response).to be_successful expect(response.headers['X-Frame-Options']).to eq("ALLOWALL") end @@ -139,7 +139,7 @@ describe EmbedController do params: { embed_url: embed_url }, headers: { 'REFERER' => "http://eviltrout.com/wat/1-2-3.html" } - expect(response).to be_success + expect(response).to be_successful end it "works with the second host" do @@ -147,7 +147,7 @@ describe EmbedController do params: { embed_url: embed_url }, headers: { 'REFERER' => "http://eviltrout.com/wat/1-2-3.html" } - expect(response).to be_success + expect(response).to be_successful end it "works with a host with a path" do @@ -155,7 +155,7 @@ describe EmbedController do params: { embed_url: embed_url }, headers: { 'REFERER' => "https://example.com/some-other-path" } - expect(response).to be_success + expect(response).to be_successful end it "contains custom class name" do diff --git a/spec/requests/groups_controller_spec.rb b/spec/requests/groups_controller_spec.rb index 9e9e4d4d42f..7e2b69fc776 100644 --- a/spec/requests/groups_controller_spec.rb +++ b/spec/requests/groups_controller_spec.rb @@ -152,7 +152,7 @@ describe GroupsController do staff_group get "/groups.json" - expect(response).to be_success + expect(response).to be_successful response_body = JSON.parse(response.body) @@ -192,7 +192,7 @@ describe GroupsController do describe 'owner groups' do it 'should return the right response' do group2 = Fabricate(:group) - group3 = Fabricate(:group) + _group3 = Fabricate(:group) group2.add_owner(admin) expect_type_to_return_right_groups('owner', [group.id, group2.id]) @@ -219,7 +219,7 @@ describe GroupsController do describe 'close groups' do it 'should return the right response' do group2 = Fabricate(:group, public_admission: false) - group3 = Fabricate(:group, public_admission: true) + _group3 = Fabricate(:group, public_admission: true) expect_type_to_return_right_groups('close', [group.id, group2.id]) end @@ -382,7 +382,7 @@ describe GroupsController do sign_in(user) get "/groups/#{group.name}/mentionable.json" - expect(response).to be_success + expect(response).to be_successful response_body = JSON.parse(response.body) expect(response_body["mentionable"]).to eq(false) @@ -393,7 +393,7 @@ describe GroupsController do ) get "/groups/#{group.name}/mentionable.json" - expect(response).to be_success + expect(response).to be_successful response_body = JSON.parse(response.body) expect(response_body["mentionable"]).to eq(true) @@ -405,7 +405,7 @@ describe GroupsController do sign_in(user) get "/groups/#{group.name}/messageable.json" - expect(response).to be_success + expect(response).to be_successful response_body = JSON.parse(response.body) expect(response_body["messageable"]).to eq(false) @@ -416,7 +416,7 @@ describe GroupsController do ) get "/groups/#{group.name}/messageable.json" - expect(response).to be_success + expect(response).to be_successful response_body = JSON.parse(response.body) expect(response_body["messageable"]).to eq(true) @@ -645,7 +645,7 @@ describe GroupsController do order: 'last_seen_at', desc: true } - expect(response).to be_success + expect(response).to be_successful members = JSON.parse(response.body)["members"] @@ -653,7 +653,7 @@ describe GroupsController do get "/groups/#{group.name}/members.json", params: { order: 'last_seen_at' } - expect(response).to be_success + expect(response).to be_successful members = JSON.parse(response.body)["members"] @@ -663,7 +663,7 @@ describe GroupsController do order: 'last_posted_at', desc: true } - expect(response).to be_success + expect(response).to be_successful members = JSON.parse(response.body)["members"] @@ -673,7 +673,7 @@ describe GroupsController do it "should not allow members to be sorted by columns that are not allowed" do get "/groups/#{group.name}/members.json", params: { order: 'email' } - expect(response).to be_success + expect(response).to be_successful members = JSON.parse(response.body)["members"] @@ -808,7 +808,7 @@ describe GroupsController do put "/groups/#{group.id}/members.json", params: { usernames: user2.username } end.to change { group.users.count }.by(1) - expect(response).to be_success + expect(response).to be_successful group_history = GroupHistory.last @@ -834,7 +834,7 @@ describe GroupsController do params: { usernames: [user1.username, user2.username].join(",") } end.to change { group.users.count }.by(2) - expect(response).to be_success + expect(response).to be_successful end it "adds by id" do @@ -843,7 +843,7 @@ describe GroupsController do params: { user_ids: [user1.id, user2.id].join(",") } end.to change { group.users.count }.by(2) - expect(response).to be_success + expect(response).to be_successful end it "adds by email" do @@ -852,7 +852,7 @@ describe GroupsController do params: { user_emails: [user1.email, user2.email].join(",") } end.to change { group.users.count }.by(2) - expect(response).to be_success + expect(response).to be_successful end it 'fails when multiple member already exists' do @@ -920,7 +920,7 @@ describe GroupsController do params: { usernames: other_user.username } end.to change { group.users.count }.by(1) - expect(response).to be_success + expect(response).to be_successful group_history = GroupHistory.last @@ -938,7 +938,7 @@ describe GroupsController do params: { usernames: other_user.username } end.to change { group.users.count }.by(1) - expect(response).to be_success + expect(response).to be_successful end it 'should not allow an underprivilege user to add another user to a group' do @@ -971,7 +971,7 @@ describe GroupsController do delete "/groups/#{group.id}/members.json", params: { user_id: user.id } end.to change { group.users.count }.by(-1) - expect(response).to be_success + expect(response).to be_successful end it "removes by username" do @@ -979,7 +979,7 @@ describe GroupsController do delete "/groups/#{group.id}/members.json", params: { username: user.username } end.to change { group.users.count }.by(-1) - expect(response).to be_success + expect(response).to be_successful end it "removes user.primary_group_id when user is removed from group" do @@ -996,7 +996,7 @@ describe GroupsController do params: { user_email: user.email } end.to change { group.users.count }.by(-1) - expect(response).to be_success + expect(response).to be_successful end context 'public group' do @@ -1010,7 +1010,7 @@ describe GroupsController do params: { username: other_user.username } end.to change { group.users.count }.by(-1) - expect(response).to be_success + expect(response).to be_successful end end @@ -1022,7 +1022,7 @@ describe GroupsController do params: { username: other_user.username } end.to change { group.users.count }.by(-1) - expect(response).to be_success + expect(response).to be_successful end it 'should not allow a underprivilege user to leave a group for another user' do @@ -1077,7 +1077,7 @@ describe GroupsController do it 'should allow group owner to view history' do get "/groups/#{group.name}/logs.json" - expect(response).to be_success + expect(response).to be_successful result = JSON.parse(response.body)["logs"].last @@ -1109,7 +1109,7 @@ describe GroupsController do get "/groups/#{group.name}/logs.json" - expect(response).to be_success + expect(response).to be_successful result = JSON.parse(response.body)["logs"].first @@ -1132,7 +1132,7 @@ describe GroupsController do filters: { "action" => "add_user_to_group" } } - expect(response).to be_success + expect(response).to be_successful logs = JSON.parse(response.body)["logs"] @@ -1167,7 +1167,7 @@ describe GroupsController do post "/groups/#{group.name}/request_membership.json", params: { reason: 'Please add me in' } - expect(response).to be_success + expect(response).to be_successful post = Post.last topic = post.topic @@ -1217,7 +1217,7 @@ describe GroupsController do get '/groups/search.json' - expect(response).to be_success + expect(response).to be_successful groups = JSON.parse(response.body) expected_ids = Group::AUTO_GROUPS.map { |name, id| id } @@ -1229,7 +1229,7 @@ describe GroupsController do ['GO', 'nerys'].each do |term| get "/groups/search.json?term=#{term}" - expect(response).to be_success + expect(response).to be_successful groups = JSON.parse(response.body) expect(groups.length).to eq(1) @@ -1238,7 +1238,7 @@ describe GroupsController do get "/groups/search.json?term=KingOfTheNorth" - expect(response).to be_success + expect(response).to be_successful groups = JSON.parse(response.body) expect(groups).to eq([]) @@ -1255,7 +1255,7 @@ describe GroupsController do get "/groups/search.json?term=north" - expect(response).to be_success + expect(response).to be_successful groups = JSON.parse(response.body) expect(groups.length).to eq(1) @@ -1269,7 +1269,7 @@ describe GroupsController do get '/groups/search.json?ignore_automatic=true' - expect(response).to be_success + expect(response).to be_successful groups = JSON.parse(response.body) expect(groups.length).to eq(2) diff --git a/spec/requests/invites_controller_spec.rb b/spec/requests/invites_controller_spec.rb index 05deb5a8321..b945453b712 100644 --- a/spec/requests/invites_controller_spec.rb +++ b/spec/requests/invites_controller_spec.rb @@ -8,7 +8,7 @@ describe InvitesController do it "returns error if invite not found" do get "/invites/nopeNOPEnope" - expect(response).to be_success + expect(response).to be_successful body = response.body expect(body).to_not have_tag(:script, with: { src: '/assets/application.js' }) @@ -18,7 +18,7 @@ describe InvitesController do it "renders the accept invite page if invite exists" do get "/invites/#{invite.invite_key}" - expect(response).to be_success + expect(response).to be_successful body = response.body expect(body).to have_tag(:script, with: { src: '/assets/application.js' }) @@ -29,7 +29,7 @@ describe InvitesController do invite.update_attributes!(redeemed_at: 1.day.ago) get "/invites/#{invite.invite_key}" - expect(response).to be_success + expect(response).to be_successful body = response.body expect(body).to_not have_tag(:script, with: { src: '/assets/application.js' }) @@ -100,7 +100,7 @@ describe InvitesController do group = Fabricate(:group) sign_in(Fabricate(:admin)) post "/invites.json", params: { email: email, group_names: group.name } - expect(response).to be_success + expect(response).to be_successful expect(Invite.find_by(email: email).invited_groups.count).to eq(1) end @@ -112,7 +112,7 @@ describe InvitesController do post "/invites.json", params: { email: email, group_names: group.name } - expect(response).to be_success + expect(response).to be_successful expect(Invite.find_by(email: email).invited_groups.count).to eq(1) end @@ -120,7 +120,7 @@ describe InvitesController do user = sign_in(Fabricate(:admin)) invite = Invite.invite_by_email("invite@example.com", user) post "/invites.json", params: { email: invite.email } - expect(response).to be_success + expect(response).to be_successful end it "responds with error message in case of validation failure" do @@ -182,7 +182,7 @@ describe InvitesController do email: email, group_names: group.name } - expect(response).to be_success + expect(response).to be_successful expect(Invite.find_by(email: email).invited_groups.count).to eq(1) end @@ -195,7 +195,7 @@ describe InvitesController do email: email, group_names: "security,support" } - expect(response).to be_success + expect(response).to be_successful expect(Invite.find_by(email: email).invited_groups.count).to eq(2) end end @@ -205,7 +205,7 @@ describe InvitesController do context 'with an invalid invite id' do it "redirects to the root and doesn't change the session" do put "/invites/show/doesntexist.json" - expect(response).to be_success + expect(response).to be_successful json = JSON.parse(response.body) expect(json["success"]).to eq(false) expect(json["message"]).to eq(I18n.t('invite.not_found')) @@ -223,7 +223,7 @@ describe InvitesController do it "redirects to the root" do put "/invites/show/#{invite.invite_key}.json" - expect(response).to be_success + expect(response).to be_successful json = JSON.parse(response.body) expect(json["success"]).to eq(false) expect(json["message"]).to eq(I18n.t('invite.not_found')) @@ -254,7 +254,7 @@ describe InvitesController do :user_logged_in, :user_first_logged_in ) invite.reload - expect(response).to be_success + expect(response).to be_successful expect(session[:current_user_id]).to eq(invite.user_id) expect(invite.redeemed?).to be_truthy end @@ -271,7 +271,7 @@ describe InvitesController do context 'failure' do it "doesn't log in the user if there's a validation error" do put "/invites/show/#{invite.invite_key}.json", params: { password: "password" } - expect(response).to be_success + expect(response).to be_successful json = JSON.parse(response.body) expect(json["success"]).to eq(false) expect(json["errors"]["password"]).to be_present @@ -286,13 +286,13 @@ describe InvitesController do it 'sends a welcome message if set' do user.send_welcome_message = true put "/invites/show/#{invite.invite_key}.json" - expect(response).to be_success + expect(response).to be_successful expect(Jobs::SendSystemMessage.jobs.size).to eq(1) end it "sends password reset email if password is not set" do put "/invites/show/#{invite.invite_key}.json" - expect(response).to be_success + expect(response).to be_successful expect(Jobs::InvitePasswordInstructionsEmail.jobs.size).to eq(1) end @@ -300,20 +300,20 @@ describe InvitesController do SiteSetting.sso_url = "https://www.example.com/sso" SiteSetting.enable_sso = true put "/invites/show/#{invite.invite_key}.json" - expect(response).to be_success + expect(response).to be_successful expect(Jobs::InvitePasswordInstructionsEmail.jobs.size).to eq(0) end it "does not send password reset email if local login is disabled" do SiteSetting.enable_local_logins = false put "/invites/show/#{invite.invite_key}.json" - expect(response).to be_success + expect(response).to be_successful expect(Jobs::InvitePasswordInstructionsEmail.jobs.size).to eq(0) end it 'sends an activation email if password is set' do put "/invites/show/#{invite.invite_key}.json", params: { password: "verystrongpassword" } - expect(response).to be_success + expect(response).to be_successful expect(Jobs::InvitePasswordInstructionsEmail.jobs.size).to eq(0) expect(Jobs::CriticalUserEmail.jobs.size).to eq(1) end @@ -381,7 +381,7 @@ describe InvitesController do it "resends the invite" do SiteSetting.queue_jobs = true post "/invites/reinvite.json", params: { email: invite.email } - expect(response).to be_success + expect(response).to be_successful expect(Jobs::InviteEmail.jobs.size).to eq(1) end end @@ -412,7 +412,7 @@ describe InvitesController do SiteSetting.queue_jobs = true sign_in(Fabricate(:admin)) post "/invites/upload_csv.json", params: { file: file, name: filename } - expect(response).to be_success + expect(response).to be_successful expect(Jobs::BulkInvite.jobs.size).to eq(1) end end diff --git a/spec/requests/list_controller_spec.rb b/spec/requests/list_controller_spec.rb index 5910aa3c57a..f7bb4286cfc 100644 --- a/spec/requests/list_controller_spec.rb +++ b/spec/requests/list_controller_spec.rb @@ -13,19 +13,19 @@ RSpec.describe ListController do describe '#index' do it "doesn't throw an error with a negative page" do get "/#{Discourse.anonymous_filters[1]}", params: { page: -1024 } - expect(response).to be_success + expect(response).to be_successful end it "doesn't throw an error with page params as an array" do get "/#{Discourse.anonymous_filters[1]}", params: { page: ['7'] } - expect(response).to be_success + expect(response).to be_successful end (Discourse.anonymous_filters - [:categories]).each do |filter| context "#{filter}" do it "succeeds" do get "/#{filter}" - expect(response).to be_success + expect(response).to be_successful end end end @@ -34,7 +34,7 @@ RSpec.describe ListController do p = create_post get "/latest.json", params: { topic_ids: "#{p.topic_id}" } - expect(response).to be_success + expect(response).to be_successful parsed = JSON.parse(response.body) expect(parsed["topic_list"]["topics"].length).to eq(1) end @@ -238,20 +238,20 @@ RSpec.describe ListController do describe 'RSS feeds' do it 'renders latest RSS' do get "/latest.rss" - expect(response).to be_success + expect(response).to be_successful expect(response.content_type).to eq('application/rss+xml') end it 'renders top RSS' do get "/top.rss" - expect(response).to be_success + expect(response).to be_successful expect(response.content_type).to eq('application/rss+xml') end TopTopic.periods.each do |period| it "renders #{period} top RSS" do get "/top/#{period}.rss" - expect(response).to be_success + expect(response).to be_successful expect(response.content_type).to eq('application/rss+xml') end end @@ -312,7 +312,7 @@ RSpec.describe ListController do it 'uses the correct category' do get "/c/#{other_category.slug}/l/latest.json" - expect(response).to be_success + expect(response).to be_successful body = JSON.parse(response.body) expect(body["topic_list"]["topics"].first["category_id"]) .to eq(other_category.id) @@ -340,7 +340,7 @@ RSpec.describe ListController do describe 'feed' do it 'renders RSS' do get "/c/#{category.slug}.rss" - expect(response).to be_success + expect(response).to be_successful expect(response.content_type).to eq('application/rss+xml') end end @@ -349,7 +349,7 @@ RSpec.describe ListController do it "has a top default view" do category.update_attributes!(default_view: 'top', default_top_period: 'monthly') get "/c/#{category.slug}.json" - expect(response).to be_success + expect(response).to be_successful json = JSON.parse(response.body) expect(json["topic_list"]["for_period"]).to eq("monthly") end @@ -357,7 +357,7 @@ RSpec.describe ListController do it "has a default view of nil" do category.update_attributes!(default_view: nil) get "/c/#{category.slug}.json" - expect(response).to be_success + expect(response).to be_successful json = JSON.parse(response.body) expect(json["topic_list"]["for_period"]).to be_blank end @@ -365,7 +365,7 @@ RSpec.describe ListController do it "has a default view of ''" do category.update_attributes!(default_view: '') get "/c/#{category.slug}.json" - expect(response).to be_success + expect(response).to be_successful json = JSON.parse(response.body) expect(json["topic_list"]["for_period"]).to be_blank end @@ -373,7 +373,7 @@ RSpec.describe ListController do it "has a default view of latest" do category.update_attributes!(default_view: 'latest') get "/c/#{category.slug}.json" - expect(response).to be_success + expect(response).to be_successful json = JSON.parse(response.body) expect(json["topic_list"]["for_period"]).to be_blank end @@ -382,13 +382,13 @@ RSpec.describe ListController do describe "renders canonical tag" do it 'for category default view' do get "/c/#{category.slug}" - expect(response).to be_success + expect(response).to be_successful expect(css_select("link[rel=canonical]").length).to eq(1) end it 'for category latest view' do get "/c/#{category.slug}/l/latest" - expect(response).to be_success + expect(response).to be_successful expect(css_select("link[rel=canonical]").length).to eq(1) end end @@ -403,7 +403,7 @@ RSpec.describe ListController do it "should respond with a list" do get "/topics/created-by/#{user.username}.json" - expect(response).to be_success + expect(response).to be_successful json = JSON.parse(response.body) expect(json["topic_list"]["topics"].size).to eq(1) end @@ -421,7 +421,7 @@ RSpec.describe ListController do pm.topic_allowed_users.create!(user: user) sign_in(user) get "/topics/private-messages/#{user.username}.json" - expect(response).to be_success + expect(response).to be_successful json = JSON.parse(response.body) expect(json["topic_list"]["topics"].size).to eq(1) end @@ -442,7 +442,7 @@ RSpec.describe ListController do it "succeeds when the user can see private messages" do sign_in(user) get "/topics/private-messages-sent/#{user.username}.json" - expect(response).to be_success + expect(response).to be_successful json = JSON.parse(response.body) expect(json["topic_list"]["topics"].size).to eq(1) end @@ -465,7 +465,7 @@ RSpec.describe ListController do it "succeeds when the user can see private messages" do sign_in(user) get "/topics/private-messages-unread/#{user.username}.json" - expect(response).to be_success + expect(response).to be_successful json = JSON.parse(response.body) expect(json["topic_list"]["topics"].size).to eq(1) end @@ -481,7 +481,7 @@ RSpec.describe ListController do it "succeeds" do sign_in(user) get "/read" - expect(response).to be_success + expect(response).to be_successful end end end @@ -546,7 +546,7 @@ RSpec.describe ListController do it "suppresses categories from the latest list" do get "/#{SiteSetting.homepage}.json" - expect(response).to be_success + expect(response).to be_successful topic_titles = JSON.parse(response.body)["topic_list"]["topics"].map { |t| t["title"] } expect(topic_titles).not_to include(topic_in_sub_category.title, topic_in_category_two.title) @@ -554,7 +554,7 @@ RSpec.describe ListController do it "does not suppress" do get "/#{SiteSetting.homepage}.json", params: { category: category_one.id } - expect(response).to be_success + expect(response).to be_successful topic_titles = JSON.parse(response.body)["topic_list"]["topics"].map { |t| t["title"] } expect(topic_titles).to include(topic_in_sub_category.title) diff --git a/spec/requests/notifications_controller_spec.rb b/spec/requests/notifications_controller_spec.rb index a55ae2e5b16..f7dede2aa5c 100644 --- a/spec/requests/notifications_controller_spec.rb +++ b/spec/requests/notifications_controller_spec.rb @@ -36,12 +36,12 @@ describe NotificationsController do describe '#index' do it 'should succeed for recent' do get "/notifications", params: { recent: true } - expect(response).to be_success + expect(response).to be_successful end it 'should succeed for history' do get "/notifications" - expect(response).to be_success + expect(response).to be_successful end it 'should mark notifications as viewed' do @@ -72,14 +72,14 @@ describe NotificationsController do it 'should succeed' do put "/notifications/mark-read.json" - expect(response).to be_success + expect(response).to be_successful end it "can update a single notification" do notification = Fabricate(:notification, user: user) notification2 = Fabricate(:notification, user: user) put "/notifications/mark-read.json", params: { id: notification.id } - expect(response).to be_success + expect(response).to be_successful notification.reload notification2.reload diff --git a/spec/requests/omniauth_callbacks_controller_spec.rb b/spec/requests/omniauth_callbacks_controller_spec.rb index 5e0a18edd90..a7316c76517 100644 --- a/spec/requests/omniauth_callbacks_controller_spec.rb +++ b/spec/requests/omniauth_callbacks_controller_spec.rb @@ -80,7 +80,7 @@ RSpec.describe Users::OmniauthCallbacksController do expect(events.map { |event| event[:event_name] }).to include(:user_logged_in, :user_first_logged_in) - expect(response).to be_success + expect(response).to be_successful response_body = JSON.parse(response.body) @@ -106,7 +106,7 @@ RSpec.describe Users::OmniauthCallbacksController do expect(events.map { |event| event[:event_name] }).to include(:user_logged_in, :user_first_logged_in) - expect(response).to be_success + expect(response).to be_successful user.reload expect(user.email_confirmed?).to eq(true) @@ -125,7 +125,7 @@ RSpec.describe Users::OmniauthCallbacksController do expect(events.map { |event| event[:event_name] }).to include(:user_logged_in, :user_first_logged_in) - expect(response).to be_success + expect(response).to be_successful user.reload expect(user.staged).to eq(false) @@ -185,7 +185,7 @@ RSpec.describe Users::OmniauthCallbacksController do it 'should return the right response' do get "/auth/google_oauth2/callback.json" - expect(response).to be_success + expect(response).to be_successful response_body = JSON.parse(response.body) diff --git a/spec/requests/onebox_controller_spec.rb b/spec/requests/onebox_controller_spec.rb index 3616c2a8198..04d9da91fc1 100644 --- a/spec/requests/onebox_controller_spec.rb +++ b/spec/requests/onebox_controller_spec.rb @@ -56,13 +56,13 @@ describe OneboxController do bypass_limiting Rails.cache.delete("onebox__#{url}") get "/onebox.json", params: { url: url } - expect(response).to be_success + expect(response).to be_successful expect(response.body).to include("Onebox1") bypass_limiting stub_request(:get, url).to_return(status: 200, body: html2).then.to_raise get "/onebox.json", params: { url: url, refresh: 'true' } - expect(response).to be_success + expect(response).to be_successful expect(response.body).to include("Onebox2") end @@ -75,12 +75,12 @@ describe OneboxController do get "/onebox.json", params: { url: url, refresh: "true" } - expect(response).to be_success + expect(response).to be_successful expect(response.body).to include('Onebox1') expect(response.body).to include('bodycontent') get "/onebox.json", params: { url: url } - expect(response).to be_success + expect(response).to be_successful expect(response.body).to include('Onebox1') expect(response.body).to include('bodycontent') end @@ -104,7 +104,7 @@ describe OneboxController do stub_request(:get, url).to_return(body: html).then.to_raise get "/onebox.json", params: { url: url, refresh: "true" } - expect(response).to be_success + expect(response).to be_successful expect(response.body).to include("Onebox1") end end diff --git a/spec/requests/post_actions_controller_spec.rb b/spec/requests/post_actions_controller_spec.rb index cb20f94f3a0..c89d68b7722 100644 --- a/spec/requests/post_actions_controller_spec.rb +++ b/spec/requests/post_actions_controller_spec.rb @@ -79,7 +79,7 @@ RSpec.describe PostActionsController do id: post_1.id, post_action_type_id: PostActionType.types[:off_topic] } - expect(response).to_not be_success + expect(response).to_not be_successful end it 'passes the message through' do @@ -133,7 +133,7 @@ RSpec.describe PostActionsController do take_action: 'true' } - expect(response).to be_success + expect(response).to be_successful post_action = PostAction.last @@ -149,7 +149,7 @@ RSpec.describe PostActionsController do post_action_type_id: PostActionType.types[:like] } - expect(response).to be_success + expect(response).to be_successful post_action = PostAction.last diff --git a/spec/requests/posts_controller_spec.rb b/spec/requests/posts_controller_spec.rb index cd225dabf37..74d6c3ea35f 100644 --- a/spec/requests/posts_controller_spec.rb +++ b/spec/requests/posts_controller_spec.rb @@ -14,7 +14,7 @@ shared_examples 'finding and showing post' do it 'succeeds' do get url - expect(response).to be_success + expect(response).to be_successful end context "deleted post" do @@ -36,13 +36,13 @@ shared_examples 'finding and showing post' do it "can find posts as a moderator" do sign_in(Fabricate(:moderator)) get url - expect(response).to be_success + expect(response).to be_successful end it "can find posts as a admin" do sign_in(Fabricate(:admin)) get url - expect(response).to be_success + expect(response).to be_successful end end end @@ -62,7 +62,7 @@ describe PostsController do let(:topicless_post) { Fabricate(:post, user: user, raw: '

Car 54, where are you?

') } let(:private_topic) do - Fabricate(:topic, archetype: Archetype.private_message, category: nil) + Fabricate(:topic, archetype: Archetype.private_message, category_id: nil) end let(:private_post) { Fabricate(:post, user: user, topic: private_topic) } @@ -127,7 +127,7 @@ describe PostsController do it 'does not allow to destroy when edit time limit expired' do SiteSetting.post_edit_time_limit = 5 - post = Fabricate(:post, topic_id: topic.id, created_at: 10.minutes.ago, user_id: user.id, post_number: 3) + post = Fabricate(:post, topic: topic, created_at: 10.minutes.ago, user: user, post_number: 3) sign_in(user) delete "/posts/#{post.id}.json" @@ -165,7 +165,7 @@ describe PostsController do describe 'when logged in' do let(:poster) { Fabricate(:moderator) } let(:post1) { Fabricate(:post, user: poster, post_number: 2) } - let(:post2) { Fabricate(:post, topic_id: post1.topic_id, user: poster, post_number: 3, reply_to_post_number: post1.post_number) } + let(:post2) { Fabricate(:post, topic: post1.topic, user: poster, post_number: 3, reply_to_post_number: post1.post_number) } it "raises invalid parameters no post_ids" do sign_in(poster) @@ -277,7 +277,7 @@ describe PostsController do it 'passes the edit reason through' do put "/posts/#{post.id}.json", params: update_params - expect(response).to be_success + expect(response).to be_successful post.reload expect(post.edit_reason).to eq("typo") expect(post.raw).to eq("edited body") @@ -307,7 +307,7 @@ describe PostsController do put "/posts/#{post.id}.json", params: param - expect(response).to be_success + expect(response).to be_successful expect(TopicLink.count).to eq(1) end @@ -316,7 +316,7 @@ describe PostsController do PostDestroyer.new(moderator, first_post).destroy put "/posts/#{first_post.id}.json", params: update_params - expect(response).not_to be_success + expect(response).not_to be_successful end end @@ -330,7 +330,7 @@ describe PostsController do PostDestroyer.new(moderator, first_post).destroy put "/posts/#{first_post.id}.json", params: update_params - expect(response).to be_success + expect(response).to be_successful post.reload expect(post.raw).to eq('edited body') @@ -373,7 +373,7 @@ describe PostsController do it 'creates a bookmark' do put "/posts/#{post.id}/bookmark.json", params: { bookmarked: "true" } - expect(response).to be_success + expect(response).to be_successful post_action = PostAction.find_by(user: user, post: post) expect(post_action.post_action_type_id).to eq(PostActionType.types[:bookmark]) @@ -435,7 +435,7 @@ describe PostsController do api_key: api_key.key } - expect(response).to be_success + expect(response).to be_successful expect(PostAction.where( post: post, user: user, @@ -460,7 +460,7 @@ describe PostsController do api_username: user.username } - expect(response).to be_success + expect(response).to be_successful expect(PostAction.where( post: post, user: user, @@ -587,7 +587,7 @@ describe PostsController do it "can rebake the post" do sign_in(Fabricate(:moderator)) put "/posts/#{post.id}/rebake.json" - expect(response).to be_success + expect(response).to be_successful end end end @@ -617,7 +617,7 @@ describe PostsController do wpid: 1 } - expect(response).to be_success + expect(response).to be_successful original = response.body post "/posts.json", params: { @@ -628,7 +628,7 @@ describe PostsController do wpid: 2 } - expect(response).to be_success + expect(response).to be_successful expect(response.body).to eq(original) end @@ -647,7 +647,7 @@ describe PostsController do reply_to_post_number: 1 } - expect(response).to be_success + expect(response).to be_successful expect(post_1.topic.user.notifications.count).to eq(1) post_1.topic.user.notifications.destroy_all @@ -660,7 +660,7 @@ describe PostsController do import_mode: true } - expect(response).to be_success + expect(response).to be_successful expect(post_1.topic.user.notifications.count).to eq(0) post "/posts.json", params: { @@ -672,7 +672,7 @@ describe PostsController do import_mode: false } - expect(response).to be_success + expect(response).to be_successful expect(post_1.topic.user.notifications.count).to eq(1) end end @@ -694,7 +694,7 @@ describe PostsController do title: 'this is the test title for the topic' } - expect(response).to be_success + expect(response).to be_successful parsed = ::JSON.parse(response.body) expect(parsed["action"]).to eq("enqueued") @@ -720,7 +720,7 @@ describe PostsController do topic_id: topic.id } - expect(response).not_to be_success + expect(response).not_to be_successful parsed = ::JSON.parse(response.body) expect(parsed["action"]).not_to eq("enqueued") end @@ -733,7 +733,7 @@ describe PostsController do title: 'this is the test title for the topic' } - expect(response).not_to be_success + expect(response).not_to be_successful parsed = ::JSON.parse(response.body) expect(parsed["action"]).not_to eq("enqueued") end @@ -747,7 +747,7 @@ describe PostsController do title: 'when I eat s3 sometimes when not looking' } - expect(response).to be_success + expect(response).to be_successful parsed = ::JSON.parse(response.body) expect(parsed["action"]).to eq("enqueued") @@ -768,7 +768,7 @@ describe PostsController do archetype: Archetype.private_message } - expect(response).not_to be_success + expect(response).not_to be_successful # allow pm to this group group.update_columns(messageable_level: Group::ALIAS_LEVELS[:everyone]) @@ -780,7 +780,7 @@ describe PostsController do archetype: Archetype.private_message } - expect(response).to be_success + expect(response).to be_successful parsed = ::JSON.parse(response.body) post = Post.find(parsed['id']) @@ -796,7 +796,7 @@ describe PostsController do nested_post: true } - expect(response).to be_success + expect(response).to be_successful parsed = ::JSON.parse(response.body) expect(parsed['post']).to be_present expect(parsed['post']['cooked']).to be_present @@ -807,10 +807,10 @@ describe PostsController do title = "this is a title #{SecureRandom.hash}" post "/posts.json", params: { raw: raw, title: title, wpid: 1 } - expect(response).to be_success + expect(response).to be_successful post "/posts.json", params: { raw: raw, title: title, wpid: 2 } - expect(response).not_to be_success + expect(response).not_to be_successful end it 'can not create a post in a disallowed category' do @@ -835,7 +835,7 @@ describe PostsController do meta_data: { xyz: 'abc' } } - expect(response).to be_success + expect(response).to be_successful new_post = Post.last topic = new_post.topic @@ -858,7 +858,7 @@ describe PostsController do image_sizes: { width: '100', height: '200' } } - expect(response).to be_success + expect(response).to be_successful new_post = Post.last topic = new_post.topic @@ -883,7 +883,7 @@ describe PostsController do target_usernames: "#{user_2.username},#{user_3.username}" } - expect(response).to be_success + expect(response).to be_successful new_post = Post.last new_topic = Topic.last @@ -896,7 +896,7 @@ describe PostsController do context "errors" do it "does not succeed" do post "/posts.json", params: { raw: 'test' } - expect(response).not_to be_success + expect(response).not_to be_successful expect(response.status).to eq(422) end @@ -925,7 +925,7 @@ describe PostsController do category: destination_category.id, shared_draft: 'true' } - expect(response).not_to be_success + expect(response).not_to be_successful end describe "as a staff user" do @@ -940,7 +940,7 @@ describe PostsController do category: destination_category.id, shared_draft: 'true' } - expect(response).not_to be_success + expect(response).not_to be_successful end context "with a shared category" do @@ -956,7 +956,7 @@ describe PostsController do category: destination_category.id, shared_draft: 'true' } - expect(response).to be_success + expect(response).to be_successful result = JSON.parse(response.body) topic = Topic.find(result['topic_id']) expect(topic.category_id).to eq(shared_category.id) @@ -983,7 +983,7 @@ describe PostsController do is_warning: true } - expect(response).to be_success + expect(response).to be_successful new_topic = Topic.last @@ -1000,7 +1000,7 @@ describe PostsController do is_warning: false } - expect(response).to be_success + expect(response).to be_successful new_topic = Topic.last @@ -1020,7 +1020,7 @@ describe PostsController do is_warning: true } - expect(response).to be_success + expect(response).to be_successful new_topic = Topic.last @@ -1058,7 +1058,7 @@ describe PostsController do it "ensures staff can see the revisions" do sign_in(Fabricate(:admin)) get "/posts/#{post.id}/revisions/#{post_revision.number}.json" - expect(response).to be_success + expect(response).to be_successful end it "ensures poster can see the revisions" do @@ -1069,13 +1069,13 @@ describe PostsController do pr = Fabricate(:post_revision, user: user, post: post) get "/posts/#{pr.post_id}/revisions/#{pr.number}.json" - expect(response).to be_success + expect(response).to be_successful end it "ensures trust level 4 can see the revisions" do sign_in(Fabricate(:user, trust_level: 4)) get "/posts/#{post_revision.post_id}/revisions/#{post_revision.number}.json" - expect(response).to be_success + expect(response).to be_successful end end @@ -1085,7 +1085,7 @@ describe PostsController do it "ensures anyone can see the revisions" do get "/posts/#{post_revision.post_id}/revisions/#{post_revision.number}.json" - expect(response).to be_success + expect(response).to be_successful end end @@ -1099,7 +1099,7 @@ describe PostsController do it "also work on deleted post" do sign_in(admin) get "/posts/#{deleted_post_revision.post_id}/revisions/#{deleted_post_revision.number}.json" - expect(response).to be_success + expect(response).to be_successful end end @@ -1114,7 +1114,7 @@ describe PostsController do it "also work on deleted topic" do sign_in(admin) get "/posts/#{post_revision.post_id}/revisions/#{post_revision.number}.json" - expect(response).to be_success + expect(response).to be_successful end end end @@ -1135,7 +1135,7 @@ describe PostsController do it "does not work" do sign_in(Fabricate(:user)) put "/posts/#{post_id}/revisions/#{revision_id}/revert.json" - expect(response).to_not be_success + expect(response).to_not be_successful end end @@ -1151,12 +1151,12 @@ describe PostsController do it "fails when post_revision record is not found" do put "/posts/#{post_id}/revisions/#{revision_id + 1}/revert.json" - expect(response).to_not be_success + expect(response).to_not be_successful end it "fails when post record is not found" do put "/posts/#{post_id + 1}/revisions/#{revision_id}/revert.json" - expect(response).to_not be_success + expect(response).to_not be_successful end it "fails when revision is blank" do @@ -1173,7 +1173,7 @@ describe PostsController do it "works!" do put "/posts/#{post_id}/revisions/#{revision_id}/revert.json" - expect(response).to be_success + expect(response).to be_successful end it "supports reverting posts in deleted topics" do @@ -1181,7 +1181,7 @@ describe PostsController do PostDestroyer.new(moderator, first_post).destroy put "/posts/#{post_id}/revisions/#{revision_id}/revert.json" - expect(response).to be_success + expect(response).to be_successful end end end @@ -1196,13 +1196,13 @@ describe PostsController do it "raises an error when you can't see the post" do post = Fabricate(:private_message_post) get "/posts/#{post.id}/expand-embed.json" - expect(response).not_to be_success + expect(response).not_to be_successful end it "retrieves the body when you can see the post" do TopicEmbed.expects(:expanded_for).with(post).returns("full content") get "/posts/#{post.id}/expand-embed.json" - expect(response).to be_success + expect(response).to be_successful expect(::JSON.parse(response.body)['cooked']).to eq("full content") end end @@ -1220,7 +1220,7 @@ describe PostsController do it "can see the flagged posts when authorized" do sign_in(Fabricate(:moderator)) get "/posts/system/flagged.json" - expect(response).to be_success + expect(response).to be_successful end it "only shows agreed and deferred flags" do @@ -1241,7 +1241,7 @@ describe PostsController do sign_in(Fabricate(:moderator)) get "/posts/#{user.username}/flagged.json" - expect(response).to be_success + expect(response).to be_successful expect(JSON.parse(response.body).length).to eq(2) end @@ -1261,7 +1261,7 @@ describe PostsController do it "can see the deleted posts when authorized" do sign_in(Fabricate(:moderator)) get "/posts/system/deleted.json" - expect(response).to be_success + expect(response).to be_successful end it "doesn't return secured categories for moderators if they don't have access" do @@ -1278,7 +1278,7 @@ describe PostsController do sign_in(Fabricate(:moderator)) get "/posts/#{user.username}/deleted.json" - expect(response).to be_success + expect(response).to be_successful data = JSON.parse(response.body) expect(data.length).to eq(0) @@ -1294,7 +1294,7 @@ describe PostsController do sign_in(Fabricate(:moderator)) get "/posts/#{user.username}/deleted.json" - expect(response).to be_success + expect(response).to be_successful data = JSON.parse(response.body) expect(data.length).to eq(0) @@ -1313,7 +1313,7 @@ describe PostsController do sign_in(Fabricate(:admin)) get "/posts/#{user.username}/deleted.json" - expect(response).to be_success + expect(response).to be_successful data = JSON.parse(response.body) expect(data.length).to eq(1) @@ -1327,7 +1327,7 @@ describe PostsController do it "can be viewed by anonymous" do post = Fabricate(:post, raw: "123456789") get "/posts/#{post.id}/raw.json" - expect(response).to be_success + expect(response).to be_successful expect(response.body).to eq("123456789") end end @@ -1338,7 +1338,7 @@ describe PostsController do post = Fabricate(:post, topic: topic, post_number: 1, raw: "123456789") post.save get "/raw/#{topic.id}/1.json" - expect(response).to be_success + expect(response).to be_successful expect(response.body).to eq("123456789") end end @@ -1366,7 +1366,7 @@ describe PostsController do get "/u/#{user.username}/activity.rss" - expect(response).to be_success + expect(response).to be_successful body = response.body @@ -1384,7 +1384,7 @@ describe PostsController do private_post get "/private-posts.rss" - expect(response).to be_success + expect(response).to be_successful body = response.body @@ -1398,7 +1398,7 @@ describe PostsController do public_post private_post get "/private-posts.json" - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) post_ids = json['private_posts'].map { |p| p['id'] } @@ -1415,7 +1415,7 @@ describe PostsController do get "/posts.rss" - expect(response).to be_success + expect(response).to be_successful body = response.body @@ -1431,7 +1431,7 @@ describe PostsController do topicless_post get "/posts.json" - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) post_ids = json['latest_posts'].map { |p| p['id'] } @@ -1448,7 +1448,7 @@ describe PostsController do post = Fabricate(:post, cooked: "WAt") get "/posts/#{post.id}/cooked.json" - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json).to be_present @@ -1473,7 +1473,7 @@ describe PostsController do sign_in(Fabricate(:moderator)) get "/posts/#{post.id}/raw-email.json" - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json['raw_email']).to eq('email_content') @@ -1488,12 +1488,12 @@ describe PostsController do it 'can lock and unlock the post' do put "/posts/#{public_post.id}/locked.json", params: { locked: "true" } - expect(response).to be_success + expect(response).to be_successful public_post.reload expect(public_post).to be_locked put "/posts/#{public_post.id}/locked.json", params: { locked: "false" } - expect(response).to be_success + expect(response).to be_successful public_post.reload expect(public_post).not_to be_locked end diff --git a/spec/requests/search_controller_spec.rb b/spec/requests/search_controller_spec.rb index 7c8de16e56d..1a5ab80d240 100644 --- a/spec/requests/search_controller_spec.rb +++ b/spec/requests/search_controller_spec.rb @@ -17,7 +17,7 @@ describe SearchController do term: 'awesome', include_blurb: true } - expect(response).to be_success + expect(response).to be_successful data = JSON.parse(response.body) expect(data['posts'][0]['id']).to eq(my_post.id) expect(data['posts'][0]['blurb']).to eq('this is my really awesome post') @@ -32,7 +32,7 @@ describe SearchController do term: user.username, type_filter: 'topic' } - expect(response).to be_success + expect(response).to be_successful data = JSON.parse(response.body) expect(data['posts'][0]['id']).to eq(my_post.id) @@ -42,7 +42,7 @@ describe SearchController do term: user.username, type_filter: 'user' } - expect(response).to be_success + expect(response).to be_successful data = JSON.parse(response.body) expect(data['posts']).to be_blank @@ -61,7 +61,7 @@ describe SearchController do search_for_id: true } - expect(response).to be_success + expect(response).to be_successful data = JSON.parse(response.body) expect(data['topics'][0]['id']).to eq(post.topic_id) @@ -77,7 +77,7 @@ describe SearchController do search_for_id: true } - expect(response).to be_success + expect(response).to be_successful data = JSON.parse(response.body) expect(data['topics'][0]['id']).to eq(my_post.topic_id) @@ -90,7 +90,7 @@ describe SearchController do SiteSetting.log_search_queries = true get "/search/query.json", params: { term: 'wookie' } - expect(response).to be_success + expect(response).to be_successful expect(SearchLog.where(term: 'wookie')).to be_present json = JSON.parse(response.body) @@ -105,7 +105,7 @@ describe SearchController do it "doesn't log when disabled" do SiteSetting.log_search_queries = false get "/search/query.json", params: { term: 'wookie' } - expect(response).to be_success + expect(response).to be_successful expect(SearchLog.where(term: 'wookie')).to be_blank end end @@ -114,14 +114,14 @@ describe SearchController do it "logs the search term" do SiteSetting.log_search_queries = true get "/search.json", params: { q: 'bantha' } - expect(response).to be_success + expect(response).to be_successful expect(SearchLog.where(term: 'bantha')).to be_present end it "doesn't log when disabled" do SiteSetting.log_search_queries = false get "/search.json", params: { q: 'bantha' } - expect(response).to be_success + expect(response).to be_successful expect(SearchLog.where(term: 'bantha')).to be_blank end end @@ -155,7 +155,7 @@ describe SearchController do term: 'test', search_context: { type: 'user', id: user.username } } - expect(response).to be_success + expect(response).to be_successful end end @@ -187,7 +187,7 @@ describe SearchController do search_result_type: 'topic' } - expect(response).to be_success + expect(response).to be_successful expect(SearchLog.find(search_log_id).search_result_id).to be_blank end @@ -207,7 +207,7 @@ describe SearchController do search_result_type: 'user' } - expect(response).to be_success + expect(response).to be_successful expect(SearchLog.find(search_log_id).search_result_id).to eq(12345) expect(SearchLog.find(search_log_id).search_result_type).to eq(SearchLog.search_result_types[:user]) end @@ -228,7 +228,7 @@ describe SearchController do search_result_type: 'topic' } - expect(response).to be_success + expect(response).to be_successful expect(SearchLog.find(search_log_id).search_result_id).to eq(22222) expect(SearchLog.find(search_log_id).search_result_type).to eq(SearchLog.search_result_types[:topic]) end @@ -246,7 +246,7 @@ describe SearchController do search_result_type: 'topic' } - expect(response).to be_success + expect(response).to be_successful expect(SearchLog.find(search_log_id).search_result_id).to be_blank end @@ -266,7 +266,7 @@ describe SearchController do search_result_type: 'category' } - expect(response).to be_success + expect(response).to be_successful expect(SearchLog.find(search_log_id).search_result_id).to eq(23456) expect(SearchLog.find(search_log_id).search_result_type).to eq(SearchLog.search_result_types[:category]) end @@ -288,7 +288,7 @@ describe SearchController do search_result_type: 'tag' } - expect(response).to be_success + expect(response).to be_successful expect(SearchLog.find(search_log_id).search_result_id).to eq(tag.id) expect(SearchLog.find(search_log_id).search_result_type).to eq(SearchLog.search_result_types[:tag]) end diff --git a/spec/requests/session_controller_spec.rb b/spec/requests/session_controller_spec.rb index 408cb6a3991..51bff909d03 100644 --- a/spec/requests/session_controller_spec.rb +++ b/spec/requests/session_controller_spec.rb @@ -7,7 +7,7 @@ RSpec.describe SessionController do shared_examples 'failed to continue local login' do it 'should return the right response' do - expect(response).not_to be_success + expect(response).not_to be_successful expect(response.status).to eq(500) end end @@ -28,7 +28,7 @@ RSpec.describe SessionController do it 'returns the right response' do get "/session/email-login/adasdad" - expect(response).to be_success + expect(response).to be_successful expect(CGI.unescapeHTML(response.body)).to match( I18n.t('email_login.invalid_token') @@ -41,7 +41,7 @@ RSpec.describe SessionController do get "/session/email-login/#{email_token.token}" - expect(response).to be_success + expect(response).to be_successful expect(CGI.unescapeHTML(response.body)).to match( I18n.t('email_login.invalid_token') @@ -823,7 +823,7 @@ RSpec.describe SessionController do login: user.username, password: 'sssss' } - expect(response).to be_success + expect(response).to be_successful expect(::JSON.parse(response.body)['error']).to eq( I18n.t("login.incorrect_username_email_or_password") ) @@ -837,7 +837,7 @@ RSpec.describe SessionController do login: user.username, password: ('s' * (User.max_password_length + 1)) } - expect(response).to be_success + expect(response).to be_successful expect(::JSON.parse(response.body)['error']).to eq( I18n.t("login.incorrect_username_email_or_password") ) @@ -855,7 +855,7 @@ RSpec.describe SessionController do login: user.username, password: 'myawesomepassword' } - expect(response).to be_success + expect(response).to be_successful expect(JSON.parse(response.body)['error']).to eq(I18n.t('login.suspended_with_reason', date: I18n.l(user.suspended_till, format: :date_only), reason: Rack::Utils.escape_html(user.suspend_reason) @@ -872,7 +872,7 @@ RSpec.describe SessionController do login: user.username, password: 'myawesomepassword' } - expect(response).to be_success + expect(response).to be_successful expect(JSON.parse(response.body)['error']).to eq(I18n.t('login.not_activated')) end end @@ -885,7 +885,7 @@ RSpec.describe SessionController do } end - expect(response).to be_success + expect(response).to be_successful expect(events.map { |event| event[:event_name] }).to contain_exactly( :user_logged_in, :user_first_logged_in ) @@ -908,7 +908,7 @@ RSpec.describe SessionController do password: 'myawesomepassword', } - expect(response).to be_success + expect(response).to be_successful expect(JSON.parse(response.body)['error']).to eq(I18n.t( 'login.invalid_second_factor_code' )) @@ -923,7 +923,7 @@ RSpec.describe SessionController do second_factor_token: '00000000' } - expect(response).to be_success + expect(response).to be_successful expect(JSON.parse(response.body)['error']).to eq(I18n.t( 'login.invalid_second_factor_code' )) @@ -937,7 +937,7 @@ RSpec.describe SessionController do password: 'myawesomepassword', second_factor_token: ROTP::TOTP.new(user_second_factor.data).now } - expect(response).to be_success + expect(response).to be_successful user.reload expect(session[:current_user_id]).to eq(user.id) @@ -957,7 +957,7 @@ RSpec.describe SessionController do post "/session.json", params: { login: "@" + user.username, password: 'myawesomepassword' } - expect(response).to be_success + expect(response).to be_successful user.reload expect(session[:current_user_id]).to be_nil @@ -969,7 +969,7 @@ RSpec.describe SessionController do post "/session.json", params: { login: "@" + user.username, password: 'myawesomepassword' } - expect(response).to be_success + expect(response).to be_successful user.reload expect(session[:current_user_id]).to eq(user.id) @@ -981,7 +981,7 @@ RSpec.describe SessionController do post "/session.json", params: { login: user.email, password: 'myawesomepassword' } - expect(response).to be_success + expect(response).to be_successful expect(session[:current_user_id]).to eq(user.id) end end @@ -994,7 +994,7 @@ RSpec.describe SessionController do post "/session.json", params: { login: username, password: 'myawesomepassword' } - expect(response).to be_success + expect(response).to be_successful expect(::JSON.parse(response.body)['error']).not_to be_present end @@ -1002,7 +1002,7 @@ RSpec.describe SessionController do post "/session.json", params: { login: email, password: 'myawesomepassword' } - expect(response).to be_success + expect(response).to be_successful expect(::JSON.parse(response.body)['error']).not_to be_present end end @@ -1020,12 +1020,12 @@ RSpec.describe SessionController do end it "doesn't log in the user" do - expect(response).to be_success + expect(response).to be_successful expect(session[:current_user_id]).to be_blank end it "shows the 'not approved' error message" do - expect(response).to be_success + expect(response).to be_successful expect(JSON.parse(response.body)['error']).to eq( I18n.t('login.not_approved') ) @@ -1040,7 +1040,7 @@ RSpec.describe SessionController do post "/session.json", params: { login: user.email, password: 'myawesomepassword' } - expect(response).to be_success + expect(response).to be_successful expect(session[:current_user_id]).to eq(user.id) end end @@ -1063,7 +1063,7 @@ RSpec.describe SessionController do post "/session.json", params: { login: user.username, password: 'myawesomepassword' } - expect(response).to be_success + expect(response).to be_successful expect(session[:current_user_id]).to eq(user.id) end @@ -1076,7 +1076,7 @@ RSpec.describe SessionController do login: user.username, password: 'myawesomepassword' } - expect(response).to be_success + expect(response).to be_successful expect(JSON.parse(response.body)['error']).to be_present expect(session[:current_user_id]).not_to eq(user.id) end @@ -1090,7 +1090,7 @@ RSpec.describe SessionController do login: user.username, password: 'myawesomepassword' } - expect(response).to be_success + expect(response).to be_successful expect(session[:current_user_id]).to eq(user.id) end end @@ -1105,13 +1105,13 @@ RSpec.describe SessionController do it "doesn't log in the user" do post_login - expect(response).to be_success + expect(response).to be_successful expect(session[:current_user_id]).to be_blank end it "shows the 'not activated' error message" do post_login - expect(response).to be_success + expect(response).to be_successful expect(JSON.parse(response.body)['error']).to eq( I18n.t 'login.not_activated' ) @@ -1122,7 +1122,7 @@ RSpec.describe SessionController do it "shows the 'not approved' error message" do post_login - expect(response).to be_success + expect(response).to be_successful expect(JSON.parse(response.body)['error']).to eq( I18n.t 'login.not_approved' ) @@ -1141,7 +1141,7 @@ RSpec.describe SessionController do login: user.username, password: 'myawesomepassword' } - expect(response).to be_success + expect(response).to be_successful end post "/session.json", params: { @@ -1164,7 +1164,7 @@ RSpec.describe SessionController do second_factor_token: '000000' } - expect(response).to be_success + expect(response).to be_successful end post "/session.json", params: { @@ -1285,7 +1285,7 @@ RSpec.describe SessionController do it "returns the JSON for the user" do get "/session/current.json" - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json['current_user']).to be_present expect(json['current_user']['id']).to eq(user.id) diff --git a/spec/requests/static_controller_spec.rb b/spec/requests/static_controller_spec.rb index 624bdadb2c6..994167fad76 100644 --- a/spec/requests/static_controller_spec.rb +++ b/spec/requests/static_controller_spec.rb @@ -98,7 +98,7 @@ describe StaticController do it "should return the right response" do get "/faq" - expect(response).to be_success + expect(response).to be_successful expect(response.body).to include(I18n.t('js.faq')) end end @@ -113,7 +113,7 @@ describe StaticController do it "renders the #{id} page" do get "/#{id}" - expect(response).to be_success + expect(response).to be_successful expect(response.body).to include(text) end end @@ -150,7 +150,7 @@ describe StaticController do get "/login" - expect(response).to be_success + expect(response).to be_successful expect(response.body).to include(PrettyText.cook(I18n.t( 'login_required.welcome_message', title: SiteSetting.title @@ -177,7 +177,7 @@ describe StaticController do get '/faq' - expect(response).to be_success + expect(response).to be_successful expect(response.body).to include(I18n.t('js.faq')) end @@ -186,7 +186,7 @@ describe StaticController do get '/guidelines' - expect(response).to be_success + expect(response).to be_successful expect(response.body).to include(I18n.t('guidelines')) end end diff --git a/spec/requests/tags_controller_spec.rb b/spec/requests/tags_controller_spec.rb index 107655ac6e3..3b58b6e89a4 100644 --- a/spec/requests/tags_controller_spec.rb +++ b/spec/requests/tags_controller_spec.rb @@ -16,7 +16,7 @@ describe TagsController do it "should return the right response" do get "/tags.json" - expect(response).to be_success + expect(response).to be_successful tags = JSON.parse(response.body)["tags"] expect(tags.length).to eq(1) @@ -41,7 +41,7 @@ describe TagsController do get "/tags.json" - expect(response).to be_success + expect(response).to be_successful tags = JSON.parse(response.body)["tags"] expect(tags.length).to eq(2) @@ -57,7 +57,7 @@ describe TagsController do it "should return the right response" do get "/tags/test" - expect(response).to be_success + expect(response).to be_successful end it "should handle invalid tags" do @@ -72,7 +72,7 @@ describe TagsController do it "should return the right response" do get "/tags/check.json", params: { tag_values: [tag.name] } - expect(response).to be_success + expect(response).to be_successful tag = JSON.parse(response.body)["valid"].first expect(tag["value"]).to eq('test') @@ -123,7 +123,7 @@ describe TagsController do it "can't see pm tags" do get "/tags/personal_messages/#{regular_user.username}.json" - expect(response).not_to be_success + expect(response).not_to be_successful end end @@ -135,13 +135,13 @@ describe TagsController do it "can't see pm tags for regular user" do get "/tags/personal_messages/#{regular_user.username}.json" - expect(response).not_to be_success + expect(response).not_to be_successful end it "can see their own pm tags" do get "/tags/personal_messages/#{moderator.username}.json" - expect(response).to be_success + expect(response).to be_successful tag = JSON.parse(response.body)['tags'] expect(tag[0]["id"]).to eq('test') @@ -156,7 +156,7 @@ describe TagsController do it "can see pm tags for regular user" do get "/tags/personal_messages/#{regular_user.username}.json" - expect(response).to be_success + expect(response).to be_successful tag = JSON.parse(response.body)['tags'] expect(tag[0]["id"]).to eq('test') @@ -165,7 +165,7 @@ describe TagsController do it "can see their own pm tags" do get "/tags/personal_messages/#{admin.username}.json" - expect(response).to be_success + expect(response).to be_successful tag = JSON.parse(response.body)['tags'] expect(tag[0]["id"]).to eq('test') @@ -195,7 +195,7 @@ describe TagsController do context 'tagging enabled' do it "can filter by tag" do get "/tags/#{tag.name}/l/latest.json" - expect(response).to be_success + expect(response).to be_successful end it "can filter by two tags" do @@ -205,7 +205,7 @@ describe TagsController do additional_tag_ids: other_tag.name } - expect(response).to be_success + expect(response).to be_successful topic_ids = JSON.parse(response.body)["topic_list"]["topics"] .map { |topic| topic["id"] } @@ -222,7 +222,7 @@ describe TagsController do additional_tag_ids: "#{other_tag.name}/#{third_tag.name}" } - expect(response).to be_success + expect(response).to be_successful topic_ids = JSON.parse(response.body)["topic_list"]["topics"] .map { |topic| topic["id"] } @@ -239,7 +239,7 @@ describe TagsController do additional_tag_ids: "notatag" } - expect(response).to be_success + expect(response).to be_successful topic_ids = JSON.parse(response.body)["topic_list"]["topics"] .map { |topic| topic["id"] } @@ -249,17 +249,17 @@ describe TagsController do it "can filter by category and tag" do get "/tags/c/#{category.slug}/#{tag.name}/l/latest.json" - expect(response).to be_success + expect(response).to be_successful end it "can filter by category, sub-category, and tag" do get "/tags/c/#{category.slug}/#{subcategory.slug}/#{tag.name}/l/latest.json" - expect(response).to be_success + expect(response).to be_successful end it "can filter by category, no sub-category, and tag" do get "/tags/c/#{category.slug}/none/#{tag.name}/l/latest.json" - expect(response).to be_success + expect(response).to be_successful end it "can handle subcategories with the same name" do @@ -272,7 +272,7 @@ describe TagsController do t = Fabricate(:topic, category_id: subcategory2.id, tags: [other_tag]) get "/tags/c/#{category2.slug}/#{subcategory2.slug}/#{other_tag.name}/l/latest.json" - expect(response).to be_success + expect(response).to be_successful topic_ids = JSON.parse(response.body)["topic_list"]["topics"] .map { |topic| topic["id"] } @@ -284,7 +284,7 @@ describe TagsController do sign_in(Fabricate(:user)) get "/tags/#{tag.name}/l/bookmarks.json" - expect(response).to be_success + expect(response).to be_successful end end end @@ -303,7 +303,7 @@ describe TagsController do tag_names = ['stuff', 'stinky', 'stumped'] tag_names.each { |name| Fabricate(:tag, name: name) } get "/tags/filter/search.json", params: { q: 'stu' } - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json["results"].map { |j| j["id"] }.sort).to eq(['stuff', 'stumped']) end @@ -312,7 +312,7 @@ describe TagsController do yup, nope = Fabricate(:tag, name: 'yup'), Fabricate(:tag, name: 'nope') category = Fabricate(:category, tags: [yup]) get "/tags/filter/search.json", params: { q: 'nope', categoryId: category.id } - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json["results"].map { |j| j["id"] }.sort).to eq([]) expect(json["forbidden"]).to be_present @@ -322,7 +322,7 @@ describe TagsController do c = Fabricate(:private_category, group: Fabricate(:group)) Fabricate(:topic, category: c, tags: [Fabricate(:tag, name: "cooltag")]) get "/tags/filter/search.json", params: { q: "cool" } - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json["results"].map { |j| j["id"] }).to eq(['cooltag']) end @@ -332,12 +332,12 @@ describe TagsController do tag_names.each { |name| Fabricate(:tag, name: name) } get "/tags/filter/search.json", params: { q: '房' } - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json["results"].map { |j| j["id"] }).to eq(['房地产']) get "/tags/filter/search.json", params: { q: 'тема' } - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json["results"].map { |j| j["id"] }).to eq(['тема-в-разработке']) end @@ -354,7 +354,7 @@ describe TagsController do it 'deletes the tag' do tag = Fabricate(:tag) delete "/tags/#{tag.name}.json" - expect(response).to be_success + expect(response).to be_successful expect(Tag.where(id: tag.id)).to be_empty end end @@ -362,7 +362,7 @@ describe TagsController do context 'with a nonexistent tag name' do it 'returns a tag not found message' do delete "/tags/doesntexists.json" - expect(response).not_to be_success + expect(response).not_to be_successful json = ::JSON.parse(response.body) expect(json['error_type']).to eq('not_found') end diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb index 9c471ee1ee1..f23881b74c5 100644 --- a/spec/requests/topics_controller_spec.rb +++ b/spec/requests/topics_controller_spec.rb @@ -15,7 +15,7 @@ RSpec.describe TopicsController do get "/t/#{topic.id}/wordpress.json", params: { best: 3 } - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) # The JSON has the data the wordpress plugin needs @@ -105,7 +105,7 @@ RSpec.describe TopicsController do } end.to change { Topic.count }.by(1) - expect(response).to be_success + expect(response).to be_successful result = ::JSON.parse(response.body) @@ -127,7 +127,7 @@ RSpec.describe TopicsController do } end.to change { Topic.count }.by(1) - expect(response).to be_success + expect(response).to be_successful result = JSON.parse(response.body) @@ -143,7 +143,7 @@ RSpec.describe TopicsController do post "/t/#{topic.id}/move-posts.json", params: { post_ids: [p2.id] } - expect(response).to be_success + expect(response).to be_successful result = ::JSON.parse(response.body) expect(result['success']).to eq(false) expect(result['url']).to be_blank @@ -193,7 +193,7 @@ RSpec.describe TopicsController do destination_topic_id: dest_topic.id } - expect(response).to be_success + expect(response).to be_successful result = ::JSON.parse(response.body) expect(result['success']).to eq(true) expect(result['url']).to be_present @@ -207,7 +207,7 @@ RSpec.describe TopicsController do post_ids: [p2.id] } - expect(response).to be_success + expect(response).to be_successful result = ::JSON.parse(response.body) expect(result['success']).to eq(false) expect(result['url']).to be_blank @@ -251,7 +251,7 @@ RSpec.describe TopicsController do destination_topic_id: dest_topic.id } - expect(response).to be_success + expect(response).to be_successful result = ::JSON.parse(response.body) expect(result['success']).to eq(true) expect(result['url']).to be_present @@ -298,8 +298,8 @@ RSpec.describe TopicsController do let!(:editor) { sign_in(Fabricate(:admin)) } let(:topic) { Fabricate(:topic) } let(:user_a) { Fabricate(:user) } - let(:p1) { Fabricate(:post, topic_id: topic.id) } - let(:p2) { Fabricate(:post, topic_id: topic.id) } + let(:p1) { Fabricate(:post, topic: topic) } + let(:p2) { Fabricate(:post, topic: topic) } it "raises an error with a parameter missing" do [ @@ -317,7 +317,7 @@ RSpec.describe TopicsController do } topic.reload p1.reload - expect(response).to be_success + expect(response).to be_successful expect(topic.user.username).to eq(user_a.username) expect(p1.user.username).to eq(user_a.username) end @@ -327,7 +327,7 @@ RSpec.describe TopicsController do username: user_a.username_lower, post_ids: [p1.id, p2.id] } - expect(response).to be_success + expect(response).to be_successful p1.reload p2.reload @@ -339,7 +339,7 @@ RSpec.describe TopicsController do it "works with deleted users" do deleted_user = Fabricate(:user) t2 = Fabricate(:topic, user: deleted_user) - p3 = Fabricate(:post, topic_id: t2.id, user: deleted_user) + p3 = Fabricate(:post, topic: t2, user: deleted_user) UserDestroyer.new(editor).destroy(deleted_user, delete_posts: true, context: 'test', delete_as_spammer: true) @@ -347,7 +347,7 @@ RSpec.describe TopicsController do username: user_a.username_lower, post_ids: [p3.id] } - expect(response).to be_success + expect(response).to be_successful t2.reload p3.reload expect(t2.deleted_at).to be_nil @@ -380,20 +380,19 @@ RSpec.describe TopicsController do let(:old_timestamp) { Time.zone.now } let(:new_timestamp) { old_timestamp - 1.day } let!(:topic) { Fabricate(:topic, created_at: old_timestamp) } - let!(:p1) { Fabricate(:post, topic_id: topic.id, created_at: old_timestamp) } - let!(:p2) { Fabricate(:post, topic_id: topic.id, created_at: old_timestamp + 1.day) } - - it 'raises an error with a missing parameter' do - put "/t/1/change-timestamp.json" - expect(response.status).to eq(400) - end + let!(:p1) { Fabricate(:post, topic: topic, created_at: old_timestamp) } + let!(:p2) { Fabricate(:post, topic: topic, created_at: old_timestamp + 1.day) } it 'should update the timestamps of selected posts' do + # try to see if we fail with invalid first + put "/t/1/change-timestamp.json" + expect(response.status).to eq(400) + put "/t/#{topic.id}/change-timestamp.json", params: { timestamp: new_timestamp.to_f } - expect(response).to be_success + expect(response).to be_successful expect(topic.reload.created_at).to be_within_one_second_of(new_timestamp) expect(p1.reload.created_at).to be_within_one_second_of(new_timestamp) expect(p2.reload.created_at).to be_within_one_second_of(old_timestamp) @@ -425,7 +424,7 @@ RSpec.describe TopicsController do expect do put "/t/#{topic.id}/clear-pin.json" end.to change { TopicUser.where(topic_id: topic.id, user_id: user.id).count }.by(1) - expect(response).to be_success + expect(response).to be_successful end end end @@ -473,15 +472,14 @@ RSpec.describe TopicsController do end it 'should update the status of the topic correctly' do - topic = Fabricate(:topic, user: user, closed: true, topic_timers: [ - Fabricate(:topic_timer, status_type: TopicTimer.types[:open]) - ]) + topic = Fabricate(:topic, user: user, closed: true) + Fabricate(:topic_timer, topic: topic, status_type: TopicTimer.types[:open]) put "/t/#{topic.id}/status.json", params: { status: 'closed', enabled: 'false' } - expect(response).to be_success + expect(response).to be_successful expect(topic.reload.closed).to eq(false) expect(topic.topic_timers).to eq([]) @@ -562,7 +560,7 @@ RSpec.describe TopicsController do put "/t/#{topic.id}/recover.json" topic.reload post.reload - expect(response).to be_success + expect(response).to be_successful expect(topic.trashed?).to be_falsey expect(post.trashed?).to be_falsey end @@ -597,7 +595,7 @@ RSpec.describe TopicsController do it 'succeeds' do delete "/t/#{topic.id}.json" - expect(response).to be_success + expect(response).to be_successful topic.reload expect(topic.trashed?).to be_truthy end @@ -611,7 +609,7 @@ RSpec.describe TopicsController do it "returns JSON for the slug" do get "/t/id_for/#{topic.slug}.json" - expect(response).to be_success + expect(response).to be_successful json = ::JSON.parse(response.body) expect(json['topic_id']).to eq(topic.id) expect(json['url']).to eq(topic.url) @@ -787,9 +785,9 @@ RSpec.describe TopicsController do it 'correctly renders canoicals' do get "/t/#{topic.id}", params: { slug: topic.slug } - expect(response).to be_success + expect(response).to be_successful expect(css_select("link[rel=canonical]").length).to eq(1) - expect(response.headers["Cache-Control"]).to eq("no-store, must-revalidate, no-cache, private") + expect(response.headers["Cache-Control"]).to eq("no-cache, no-store") end it 'returns 301 even if slug does not match URL' do @@ -804,7 +802,7 @@ RSpec.describe TopicsController do Fabricate(:post, topic: topic) get "/t/#{topic.id}.json", params: { slug: topic.slug } - expect(response).to be_success + expect(response).to be_successful get "/t/#{topic.id}.json", params: { slug: "just-guessing" } expect(response.status).to eq(301) @@ -815,7 +813,7 @@ RSpec.describe TopicsController do it 'shows a topic correctly' do get "/t/#{topic.slug}/#{topic.id}.json" - expect(response).to be_success + expect(response).to be_successful end it 'return 404 for an invalid page' do @@ -1110,20 +1108,20 @@ RSpec.describe TopicsController do it 'grabs the correct set of posts' do get "/t/#{topic.slug}/#{topic.id}.json" - expect(response).to be_success + expect(response).to be_successful expect(extract_post_stream).to eq(@post_ids[0..1]) get "/t/#{topic.slug}/#{topic.id}.json", params: { page: 1 } - expect(response).to be_success + expect(response).to be_successful expect(extract_post_stream).to eq(@post_ids[0..1]) get "/t/#{topic.slug}/#{topic.id}.json", params: { page: 2 } - expect(response).to be_success + expect(response).to be_successful expect(extract_post_stream).to eq(@post_ids[2..3]) post_number = topic.posts.pluck(:post_number).sort[3] get "/t/#{topic.slug}/#{topic.id}/#{post_number}.json" - expect(response).to be_success + expect(response).to be_successful expect(extract_post_stream).to eq(@post_ids[-2..-1]) end end @@ -1228,7 +1226,7 @@ RSpec.describe TopicsController do expect { get "/t/#{topic.id}.json" }.not_to change(IncomingLink, :count) - expect(response).to be_success + expect(response).to be_successful end it "doesn't raise an error on a very long link" do @@ -1247,7 +1245,7 @@ RSpec.describe TopicsController do body = response.body - expect(response).to be_success + expect(response).to be_successful expect(body).to have_tag(:script, with: { src: '/assets/application.js' }) expect(body).to_not have_tag(:meta, with: { name: 'fragment' }) end @@ -1274,7 +1272,7 @@ RSpec.describe TopicsController do body = response.body - expect(response).to be_success + expect(response).to be_successful expect(body).to have_tag(:body, with: { class: 'crawler' }) expect(body).to_not have_tag(:meta, with: { name: 'fragment' }) end @@ -1290,7 +1288,7 @@ RSpec.describe TopicsController do get "/t/#{topic.id}.json" - expect(response).to be_success + expect(response).to be_successful expect(response.cookies['cn']).to eq(nil) notification.reload @@ -1303,7 +1301,7 @@ RSpec.describe TopicsController do get "/t/#{topic.id}.json", headers: { "Discourse-Clear-Notifications" => "2828,100,#{notification.id}" } - expect(response).to be_success + expect(response).to be_successful notification.reload expect(notification.read).to eq(true) end @@ -1325,7 +1323,7 @@ RSpec.describe TopicsController do it "uses the default locale" do get "/t/#{topic.id}.json", headers: headers("fr") - expect(response).to be_success + expect(response).to be_successful expect(I18n.locale).to eq(:en) end end @@ -1337,7 +1335,7 @@ RSpec.describe TopicsController do get "/t/#{topic.id}.json", headers: headers("fr") - expect(response).to be_success + expect(response).to be_successful expect(I18n.locale).to eq(:en) end end @@ -1355,7 +1353,7 @@ RSpec.describe TopicsController do context "with an anonymous user" do it "uses the locale from the headers" do get "/t/#{topic.id}.json", headers: headers("fr") - expect(response).to be_success + expect(response).to be_successful expect(I18n.locale).to eq(:fr) end end @@ -1366,7 +1364,7 @@ RSpec.describe TopicsController do sign_in(user) get "/t/#{topic.id}.json", headers: headers("fr") - expect(response).to be_success + expect(response).to be_successful expect(I18n.locale).to eq(:fr) end end @@ -1379,7 +1377,7 @@ RSpec.describe TopicsController do SiteSetting.default_locale = "en" get "/t/#{topic.id}.json", headers: headers("zh-CN") - expect(response).to be_success + expect(response).to be_successful expect(I18n.locale).to eq(:zh_CN) end end @@ -1390,7 +1388,7 @@ RSpec.describe TopicsController do SiteSetting.default_locale = 'en' get "/t/#{topic.id}.json", headers: headers("") - expect(response).to be_success + expect(response).to be_successful expect(I18n.locale).to eq(:en) end end @@ -1400,14 +1398,14 @@ RSpec.describe TopicsController do describe "read only header" do it "returns no read only header by default" do get "/t/#{topic.id}.json" - expect(response).to be_success + expect(response).to be_successful expect(response.headers['Discourse-Readonly']).to eq(nil) end it "returns a readonly header if the site is read only" do Discourse.received_readonly! get "/t/#{topic.id}.json" - expect(response).to be_success + expect(response).to be_successful expect(response.headers['Discourse-Readonly']).to eq('true') end end @@ -1418,7 +1416,7 @@ RSpec.describe TopicsController do it 'returns first posts of the topic' do get "/t/#{topic.id}/posts.json" - expect(response).to be_success + expect(response).to be_successful expect(response.content_type).to eq('application/json') end end @@ -1428,7 +1426,7 @@ RSpec.describe TopicsController do it 'renders rss of the topic' do get "/t/foo/#{topic.id}.rss" - expect(response).to be_success + expect(response).to be_successful expect(response.content_type).to eq('application/rss+xml') end end @@ -1475,7 +1473,7 @@ RSpec.describe TopicsController do topic = Fabricate(:topic, user: sign_in(Fabricate(:admin))) put "/t/#{topic.id}/make-banner.json" - expect(response).to be_success + expect(response).to be_successful topic.reload expect(topic.archetype).to eq(Archetype.banner) end @@ -1494,7 +1492,7 @@ RSpec.describe TopicsController do topic = Fabricate(:topic, user: sign_in(Fabricate(:admin)), archetype: Archetype.banner) put "/t/#{topic.id}/remove-banner.json" - expect(response).to be_success + expect(response).to be_successful topic.reload expect(topic.archetype).to eq(Archetype.default) end @@ -1603,7 +1601,7 @@ RSpec.describe TopicsController do user.user_stat.update_column(:new_since, old_date) put "/topics/reset-new.json" - expect(response).to be_success + expect(response).to be_successful user.reload expect(user.user_stat.new_since.to_date).not_to eq(old_date.to_date) end @@ -1613,7 +1611,7 @@ RSpec.describe TopicsController do it "works" do get "/topics/feature_stats.json", params: { category_id: 1 } - expect(response).to be_success + expect(response).to be_successful json = JSON.parse(response.body) expect(json["pinned_in_category_count"]).to eq(0) expect(json["pinned_globally_count"]).to eq(0) @@ -1673,12 +1671,12 @@ RSpec.describe TopicsController do context "success" do it "returns success" do - admin = sign_in(Fabricate(:admin)) + sign_in(Fabricate(:admin)) put "/t/#{topic.id}/convert-topic/private.json" topic.reload expect(topic.archetype).to eq(Archetype.private_message) - expect(response).to be_success + expect(response).to be_successful result = ::JSON.parse(response.body) expect(result['success']).to eq(true) @@ -1699,12 +1697,12 @@ RSpec.describe TopicsController do context "success" do it "returns success" do - admin = sign_in(Fabricate(:admin)) + sign_in(Fabricate(:admin)) put "/t/#{topic.id}/convert-topic/public.json" topic.reload expect(topic.archetype).to eq(Archetype.default) - expect(response).to be_success + expect(response).to be_successful result = ::JSON.parse(response.body) expect(result['success']).to eq(true) @@ -1726,7 +1724,7 @@ RSpec.describe TopicsController do timings: { post_1.post_number => 2 } } - expect(response).to be_success + expect(response).to be_successful post_timing = PostTiming.first @@ -1774,7 +1772,7 @@ RSpec.describe TopicsController do status_type: TopicTimer.types[1] } - expect(response).to be_success + expect(response).to be_successful topic_status_update = TopicTimer.last @@ -1800,7 +1798,7 @@ RSpec.describe TopicsController do status_type: TopicTimer.types[1] } - expect(response).to be_success + expect(response).to be_successful expect(topic.reload.public_topic_timer).to eq(nil) json = JSON.parse(response.body) @@ -1818,7 +1816,7 @@ RSpec.describe TopicsController do category_id: topic.category_id } - expect(response).to be_success + expect(response).to be_successful topic_status_update = TopicTimer.last @@ -2038,7 +2036,7 @@ RSpec.describe TopicsController do let!(:shared_draft) { Fabricate(:shared_draft, topic: topic, category: category) } it "allows staff to update the category id" do put "/t/#{topic.id}/shared-draft.json", params: { category_id: other_cat.id } - expect(response).to be_success + expect(response).to be_successful topic.reload expect(topic.shared_draft.category_id).to eq(other_cat.id) end @@ -2047,7 +2045,7 @@ RSpec.describe TopicsController do context "without a shared draft" do it "allows staff to update the category id" do put "/t/#{topic.id}/shared-draft.json", params: { category_id: other_cat.id } - expect(response).to be_success + expect(response).to be_successful topic.reload expect(topic.shared_draft.category_id).to eq(other_cat.id) end @@ -2113,15 +2111,15 @@ RSpec.describe TopicsController do freeze_time page1_time topic = Fabricate(:topic) - Fabricate(:post, topic_id: topic.id) - Fabricate(:post, topic_id: topic.id) + Fabricate(:post, topic: topic) + Fabricate(:post, topic: topic) freeze_time page2_time - Fabricate(:post, topic_id: topic.id) - Fabricate(:post, topic_id: topic.id) + Fabricate(:post, topic: topic) + Fabricate(:post, topic: topic) freeze_time page3_time - Fabricate(:post, topic_id: topic.id) + Fabricate(:post, topic: topic) # ugly, but no inteface to set this and we don't want to create # 100 posts to test this thing diff --git a/spec/requests/uploads_controller_spec.rb b/spec/requests/uploads_controller_spec.rb index 31130e15c04..9fa184f0e5c 100644 --- a/spec/requests/uploads_controller_spec.rb +++ b/spec/requests/uploads_controller_spec.rb @@ -122,7 +122,7 @@ describe UploadsController do for_private_message: "true", } - expect(response).to be_success + expect(response).to be_successful id = JSON.parse(response.body)["id"] expect(id).to be_present end @@ -137,7 +137,7 @@ describe UploadsController do type: "composer", } - expect(response).to be_success + expect(response).to be_successful data = JSON.parse(response.body) expect(data["id"]).to be_present end diff --git a/spec/requests/user_badges_controller_spec.rb b/spec/requests/user_badges_controller_spec.rb index 20fd5d3b63c..84b1b2ebbb7 100644 --- a/spec/requests/user_badges_controller_spec.rb +++ b/spec/requests/user_badges_controller_spec.rb @@ -11,7 +11,7 @@ describe UserBadgesController do UserBadge.create!(badge: badge, user: user, post_id: p.id, granted_by_id: -1, granted_at: Time.now) get "/user_badges.json", params: { badge_id: badge.id } - expect(response).to be_success + expect(response).to be_successful parsed = JSON.parse(response.body) expect(parsed["topics"]).to eq(nil) diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb index 5b7e588c528..1714816a005 100644 --- a/spec/requests/users_controller_spec.rb +++ b/spec/requests/users_controller_spec.rb @@ -64,7 +64,7 @@ describe UsersController do :user_logged_in, :user_first_logged_in ) - expect(response).to be_success + expect(response).to be_successful expect(flash[:error]).to be_blank expect(session[:current_user_id]).to be_present @@ -81,7 +81,7 @@ describe UsersController do end it 'should return the right response' do - expect(response).to be_success + expect(response).to be_successful expect(CGI.unescapeHTML(response.body)) .to include(I18n.t('activation.approval_required')) @@ -116,7 +116,7 @@ describe UsersController do it "returns success" do SiteSetting.login_required = true get "/u/password-reset/#{token}" - expect(response).to be_success + expect(response).to be_successful expect(CGI.unescapeHTML(response.body)).to include(I18n.t('password_reset.no_token')) end end @@ -127,7 +127,7 @@ describe UsersController do end it 'disallows login' do - expect(response).to be_success + expect(response).to be_successful expect(CGI.unescapeHTML(response.body)) .to include(I18n.t('password_reset.no_token')) @@ -144,7 +144,7 @@ describe UsersController do it 'disallows login' do get "/u/password-reset/ev!l_trout@!" - expect(response).to be_success + expect(response).to be_successful expect(CGI.unescapeHTML(response.body)) .to include(I18n.t('password_reset.no_token')) @@ -159,7 +159,7 @@ describe UsersController do it "responds with proper error message" do put "/u/password-reset/evil_trout!.json", params: { password: "awesomeSecretPassword" } - expect(response).to be_success + expect(response).to be_successful expect(JSON.parse(response.body)["message"]).to eq(I18n.t('password_reset.no_token')) expect(session[:current_user_id]).to be_blank end @@ -189,7 +189,7 @@ describe UsersController do :user_logged_in, :user_first_logged_in ) - expect(response).to be_success + expect(response).to be_successful expect(response.body).to include('{"is_developer":false,"admin":false,"second_factor_required":false}') expect(session["password-#{token}"]).to be_blank @@ -294,7 +294,7 @@ describe UsersController do it "fails when the password is blank" do put "/u/password-reset/#{token}.json", params: { password: '' } - expect(response).to be_success + expect(response).to be_successful expect(JSON.parse(response.body)["errors"]).to be_present expect(session[:current_user_id]).to be_blank end @@ -302,7 +302,7 @@ describe UsersController do it "fails when the password is too long" do put "/u/password-reset/#{token}.json", params: { password: ('x' * (User.max_password_length + 1)) } - expect(response).to be_success + expect(response).to be_successful expect(JSON.parse(response.body)["errors"]).to be_present expect(session[:current_user_id]).to be_blank end @@ -310,7 +310,7 @@ describe UsersController do it "logs in the user" do put "/u/password-reset/#{token}.json", params: { password: 'ksjafh928r' } - expect(response).to be_success + expect(response).to be_successful expect(JSON.parse(response.body)["errors"]).to be_blank expect(session[:current_user_id]).to be_present end @@ -331,14 +331,14 @@ describe UsersController do it "token doesn't match any records" do email_token = user.email_tokens.create(email: user.email) get "/u/confirm-email-token/#{SecureRandom.hex}.json" - expect(response).to be_success + expect(response).to be_successful expect(email_token.reload.confirmed).to eq(false) end it "token matches" do email_token = user.email_tokens.create(email: user.email) get "/u/confirm-email-token/#{email_token.token}.json" - expect(response).to be_success + expect(response).to be_successful expect(email_token.reload.confirmed).to eq(true) end end @@ -442,11 +442,11 @@ describe UsersController do user.save! post "/u/toggle-anon.json" - expect(response).to be_success + expect(response).to be_successful expect(session[:current_user_id]).to eq(AnonymousShadowCreator.get(user).id) post "/u/toggle-anon.json" - expect(response).to be_success + expect(response).to be_successful expect(session[:current_user_id]).to eq(user.id) end end @@ -934,7 +934,7 @@ describe UsersController do it "should succeed without the optional field" do post "/u.json", params: create_params - expect(response).to be_success + expect(response).to be_successful inserted = User.find_by_email(@user.email) expect(inserted).to be_present expect(inserted.custom_fields).to be_present @@ -946,7 +946,7 @@ describe UsersController do it "should succeed with the optional field" do create_params[:user_fields][optional_field.id.to_s] = 'value3' post "/u.json", params: create_params.merge(create_params) - expect(response).to be_success + expect(response).to be_successful inserted = User.find_by_email(@user.email) expect(inserted).to be_present expect(inserted.custom_fields).to be_present @@ -958,7 +958,7 @@ describe UsersController do it "trims excessively long fields" do create_params[:user_fields][optional_field.id.to_s] = ('x' * 3000) post "/u.json", params: create_params.merge(create_params) - expect(response).to be_success + expect(response).to be_successful inserted = User.find_by_email(@user.email) val = inserted.custom_fields["user_field_#{optional_field.id}"] @@ -980,7 +980,7 @@ describe UsersController do it "should succeed" do post "/u.json", params: create_params - expect(response).to be_success + expect(response).to be_successful inserted = User.find_by_email(@user.email) expect(inserted).to be_present expect(inserted.custom_fields).not_to be_present @@ -1073,7 +1073,7 @@ describe UsersController do it 'should succeed in normal circumstances' do put "/u/#{user.username}/preferences/username.json", params: { new_username: new_username } - expect(response).to be_success + expect(response).to be_successful expect(user.reload.username).to eq(new_username) end @@ -1097,7 +1097,7 @@ describe UsersController do put "/u/#{user.username}/preferences/username.json", params: { new_username: new_username } - expect(response).to be_success + expect(response).to be_successful expect(UserHistory.where(action: UserHistory.actions[:change_username], target_user_id: user.id, acting_user_id: acting_user.id)).to be_present expect(user.reload.username).to eq(new_username) end @@ -1221,7 +1221,7 @@ describe UsersController do user = Fabricate(:user) get "/u/#{user.username}/invited.json", params: { username: user.username } - expect(response).to be_success + expect(response).to be_successful end it 'filters by email' do @@ -1366,14 +1366,14 @@ describe UsersController do it "should be able to update a user" do put "/u/#{user.username}.json", params: { name: 'test.test' } - expect(response).to be_success + expect(response).to be_successful expect(user.reload.name).to eq('test.test') end it "should be able to update a user" do put "/u/#{user.username}.json", params: { name: 'testing123' } - expect(response).to be_success + expect(response).to be_successful expect(user.reload.name).to eq('testing123') end end @@ -1391,7 +1391,7 @@ describe UsersController do user_fields: { user_field.id.to_s => 'happy' } } - expect(response).to be_success + expect(response).to be_successful user.reload @@ -1417,7 +1417,7 @@ describe UsersController do watched_tags: "#{tags[0].name},#{tags[1].name}" } - expect(response).to be_success + expect(response).to be_successful user.reload @@ -1460,7 +1460,7 @@ describe UsersController do it "should update the user field" do put "/u/#{user.username}.json", params: { name: 'Jim Tom', user_fields: { user_field.id.to_s => 'happy' } } - expect(response).to be_success + expect(response).to be_successful expect(user.user_fields[user_field.id.to_s]).to eq 'happy' end @@ -1480,13 +1480,13 @@ describe UsersController do it "should retain existing user fields" do put "/u/#{user.username}.json", params: { name: 'Jim Tom', user_fields: { user_field.id.to_s => 'happy', optional_field.id.to_s => 'feet' } } - expect(response).to be_success + expect(response).to be_successful expect(user.user_fields[user_field.id.to_s]).to eq('happy') expect(user.user_fields[optional_field.id.to_s]).to eq('feet') put "/u/#{user.username}.json", params: { name: 'Jim Tom', user_fields: { user_field.id.to_s => 'sad' } } - expect(response).to be_success + expect(response).to be_successful user.reload @@ -1501,7 +1501,7 @@ describe UsersController do it "does not update the user field" do put "/u/#{user.username}.json", params: { name: 'Jim Tom', user_fields: { user_field.id.to_s => 'happy' } } - expect(response).to be_success + expect(response).to be_successful expect(user.user_fields[user_field.id.to_s]).to be_blank end end @@ -1748,7 +1748,7 @@ describe UsersController do it 'can successfully pick the system avatar' do put "/u/#{user.username}/preferences/avatar/pick.json" - expect(response).to be_success + expect(response).to be_successful expect(user.reload.uploaded_avatar_id).to eq(nil) end @@ -1757,7 +1757,7 @@ describe UsersController do upload_id: upload.id, type: "gravatar" } - expect(response).to be_success + expect(response).to be_successful expect(user.reload.uploaded_avatar_id).to eq(upload.id) expect(user.user_avatar.reload.gravatar_upload_id).to eq(upload.id) end @@ -1767,7 +1767,7 @@ describe UsersController do upload_id: upload.id, type: "custom" } - expect(response).to be_success + expect(response).to be_successful expect(user.reload.uploaded_avatar_id).to eq(upload.id) expect(user.user_avatar.reload.custom_upload_id).to eq(upload.id) end @@ -1807,7 +1807,7 @@ describe UsersController do delete "/u/#{user.username}/preferences/user_image.json", params: { type: 'profile_background' } expect(user.reload.user_profile.profile_background).to eq("") - expect(response).to be_success + expect(response).to be_successful end end end @@ -1843,7 +1843,7 @@ describe UsersController do it "deletes your account when you're allowed to" do UserDestroyer.any_instance.expects(:destroy).with(user, anything).returns(user) delete "/u/#{user.username}.json" - expect(response).to be_success + expect(response).to be_successful end end end @@ -1894,7 +1894,7 @@ describe UsersController do get "/u/#{Fabricate(:user).username}/emails.json" - expect(response).to be_success + expect(response).to be_successful json = JSON.parse(response.body) expect(json["email"]).to be_present expect(json["associated_accounts"]).to be_present @@ -1906,7 +1906,7 @@ describe UsersController do get "/u/#{inactive_user.username}/emails.json" - expect(response).to be_success + expect(response).to be_successful json = JSON.parse(response.body) expect(json["email"]).to be_present expect(json["associated_accounts"]).to be_present @@ -2034,7 +2034,7 @@ describe UsersController do create_post(user: user) get "/u/#{user.username_lower}/summary.json" - expect(response).to be_success + expect(response).to be_successful json = JSON.parse(response.body) expect(json["user_summary"]["topic_count"]).to eq(1) @@ -2045,12 +2045,12 @@ describe UsersController do describe '#confirm_admin' do it "fails without a valid token" do get "/u/confirm-admin/invalid-token.josn" - expect(response).not_to be_success + expect(response).not_to be_successful end it "fails with a missing token" do get "/u/confirm-admin/a0a0a0a0a0.josn" - expect(response).to_not be_success + expect(response).to_not be_successful end it "succeeds with a valid code as anonymous" do @@ -2058,7 +2058,7 @@ describe UsersController do ac = AdminConfirmation.new(user, Fabricate(:admin)) ac.create_confirmation get "/u/confirm-admin/#{ac.token}.josn" - expect(response).to be_success + expect(response).to be_successful user.reload expect(user.admin?).to eq(false) @@ -2071,7 +2071,7 @@ describe UsersController do ac = AdminConfirmation.new(user, admin) ac.create_confirmation get "/u/confirm-admin/#{ac.token}.josn", params: { token: ac.token } - expect(response).to be_success + expect(response).to be_successful user.reload expect(user.admin?).to eq(false) @@ -2084,7 +2084,7 @@ describe UsersController do ac = AdminConfirmation.new(user, Fabricate(:admin)) ac.create_confirmation get "/u/confirm-admin/#{ac.token}.josn" - expect(response).to_not be_success + expect(response).to_not be_successful user.reload expect(user.admin?).to eq(false) @@ -2096,7 +2096,7 @@ describe UsersController do ac = AdminConfirmation.new(user, Fabricate(:admin)) ac.create_confirmation post "/u/confirm-admin/#{ac.token}.josn" - expect(response).to be_success + expect(response).to be_successful user.reload expect(user.admin?).to eq(true) @@ -2285,7 +2285,7 @@ describe UsersController do it "returns success" do get "/u/#{user.username}.json" - expect(response).to be_success + expect(response).to be_successful expect(JSON.parse(response.body)["user"]["username"]).to eq(user.username) end @@ -2320,7 +2320,7 @@ describe UsersController do it 'returns success' do get "/u/#{user.username}.json" - expect(response).to be_success + expect(response).to be_successful json = JSON.parse(response.body) expect(json["user"]["has_title_badges"]).to eq(false) @@ -2328,20 +2328,20 @@ describe UsersController do it "returns not found when the username doesn't exist" do get "/u/madeuppity.json" - expect(response).not_to be_success + expect(response).not_to be_successful end it 'returns not found when the user is inactive' do inactive = Fabricate(:user, active: false) get "/u/#{inactive.username}.json" - expect(response).not_to be_success + expect(response).not_to be_successful end it 'returns success when show_inactive_accounts is true and user is logged in' do SiteSetting.show_inactive_accounts = true inactive = Fabricate(:user, active: false) get "/u/#{inactive.username}.json" - expect(response).to be_success + expect(response).to be_successful end it "raises an error on invalid access" do @@ -2374,13 +2374,13 @@ describe UsersController do it "returns fetch for a matching external_id" do get "/u/by-external/997.json" - expect(response).to be_success + expect(response).to be_successful expect(JSON.parse(response.body)["user"]["username"]).to eq(user.username) end it "returns not found when external_id doesn't match" do get "/u/by-external/99.json" - expect(response).not_to be_success + expect(response).not_to be_successful end end @@ -2414,7 +2414,7 @@ describe UsersController do it "should be able to view a user" do get "/u/#{user.username}" - expect(response).to be_success + expect(response).to be_successful expect(response.body).to include(user.username) end @@ -2426,7 +2426,7 @@ describe UsersController do it "should be able to view a user" do get "/u/#{user.username}" - expect(response).to be_success + expect(response).to be_successful expect(response.body).to include(user.username) end end @@ -2435,7 +2435,7 @@ describe UsersController do describe '#badges' do it "renders fine by default" do get "/u/#{user.username}/badges" - expect(response).to be_success + expect(response).to be_successful end it "fails if badges are disabled" do @@ -2449,7 +2449,7 @@ describe UsersController do it "returns a message when no session is present" do get "/u/account-created" - expect(response).to be_success + expect(response).to be_successful body = response.body @@ -2470,7 +2470,7 @@ describe UsersController do user = create_user get "/u/account-created" - expect(response).to be_success + expect(response).to be_successful expect(response.body).to include( "{\"message\":\"#{I18n.t("login.activate_email", email: user.email).gsub!("