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.
This commit is contained in:
Sam 2018-06-05 17:29:17 +10:00
parent 2bd905c632
commit 89ad2b5900
103 changed files with 900 additions and 864 deletions

14
Gemfile
View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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"

View File

@ -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

View File

@ -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')

View File

@ -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)

View File

@ -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

View File

@ -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?

View File

@ -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

View File

@ -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(

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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"
}
}

View File

@ -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')) }

View File

@ -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)")

View File

@ -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')

View File

@ -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)

View File

@ -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)

View File

@ -1,4 +1,5 @@
require 'rails_helper'
require_dependency 'validators/upload_validator'
describe Validators::UploadValidator do
subject(:validator) { described_class.new }

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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"]

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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")

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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]

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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')

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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: '<p>Car 54, where are you?</p>') }
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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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!("</", "<\\/")}\",\"show_controls\":true,\"username\":\"#{user.username}\",\"email\":\"#{user.email}\"}"
@ -2491,14 +2491,14 @@ describe UsersController do
it "searches when provided the term only" do
get "/u/search/users.json", params: { term: user.name.split(" ").last }
expect(response).to be_success
expect(response).to be_successful
json = JSON.parse(response.body)
expect(json["users"].map { |u| u["username"] }).to include(user.username)
end
it "searches when provided the topic only" do
get "/u/search/users.json", params: { topic_id: topic.id }
expect(response).to be_success
expect(response).to be_successful
json = JSON.parse(response.body)
expect(json["users"].map { |u| u["username"] }).to include(user.username)
end
@ -2508,7 +2508,7 @@ describe UsersController do
term: user.name.split(" ").last, topic_id: topic.id
}
expect(response).to be_success
expect(response).to be_successful
json = JSON.parse(response.body)
expect(json["users"].map { |u| u["username"] }).to include(user.username)
end
@ -2529,7 +2529,7 @@ describe UsersController do
term: user.name.split(" ").last, topic_id: private_topic.id, topic_allowed_users: "true"
}
expect(response).to be_success
expect(response).to be_successful
json = JSON.parse(response.body)
expect(json["users"].map { |u| u["username"] }).to_not include(user.username)
expect(json["users"].map { |u| u["username"] }).to include(privileged_user.username)
@ -2591,7 +2591,7 @@ describe UsersController do
it "only returns visible groups" do
get "/u/search/users.json", params: { include_groups: "true" }
expect(response).to be_success
expect(response).to be_successful
groups = JSON.parse(response.body)["groups"]
@ -2605,7 +2605,7 @@ describe UsersController do
include_messageable_groups: 'false'
}
expect(response).to be_success
expect(response).to be_successful
expect(JSON.parse(response.body)).not_to have_key(:groups)
end
@ -2615,7 +2615,7 @@ describe UsersController do
include_messageable_groups: 'true'
}
expect(response).to be_success
expect(response).to be_successful
expect(JSON.parse(response.body)["groups"].map { |group| group['name'] })
.to contain_exactly(messageable_group.name, Group.find(Group::AUTO_GROUPS[:moderators]).name)
@ -2627,7 +2627,7 @@ describe UsersController do
include_mentionable_groups: 'true'
}
expect(response).to be_success
expect(response).to be_successful
groups = JSON.parse(response.body)["groups"]
@ -2643,7 +2643,7 @@ describe UsersController do
include_messageable_groups: 'false'
}
expect(response).to be_success
expect(response).to be_successful
expect(JSON.parse(response.body)).not_to have_key(:groups)
get "/u/search/users.json", params: {
@ -2651,7 +2651,7 @@ describe UsersController do
include_messageable_groups: 'true'
}
expect(response).to be_success
expect(response).to be_successful
expect(JSON.parse(response.body)).not_to have_key(:groups)
get "/u/search/users.json", params: {
@ -2659,7 +2659,7 @@ describe UsersController do
include_mentionable_groups: 'true'
}
expect(response).to be_success
expect(response).to be_successful
expect(JSON.parse(response.body)).not_to have_key(:groups)
end
end
@ -2687,7 +2687,7 @@ describe UsersController do
it "enqueues the right email" do
post "/u/email-login.json", params: { login: user.email }
expect(response).to be_success
expect(response).to be_successful
expect(JSON.parse(response.body)['user_found']).to eq(true)
job_args = Jobs::CriticalUserEmail.jobs.last["args"].first
@ -2713,7 +2713,7 @@ describe UsersController do
it 'should not enqueue the email to login' do
post "/u/email-login.json", params: { login: '@random' }
expect(response).to be_success
expect(response).to be_successful
expect(JSON.parse(response.body)['user_found']).to eq(false)
expect(Jobs::CriticalUserEmail.jobs).to eq([])
end
@ -2724,7 +2724,7 @@ describe UsersController do
SiteSetting.hide_email_address_taken = true
post "/u/email-login.json", params: { login: user.email }
expect(response).to be_success
expect(response).to be_successful
expect(JSON.parse(response.body).has_key?('user_found')).to eq(false)
end
end

View File

@ -6,7 +6,7 @@ describe UsersEmailController do
it 'errors out for invalid tokens' do
get "/u/authorize-email/asdfasdf"
expect(response).to be_success
expect(response).to be_successful
expect(response.body).to include(I18n.t('change_email.already_done'))
end
@ -21,7 +21,7 @@ describe UsersEmailController do
it 'confirms with a correct token' do
get "/u/authorize-email/#{user.email_tokens.last.token}"
expect(response).to be_success
expect(response).to be_successful
body = CGI.unescapeHTML(response.body)
@ -52,7 +52,7 @@ describe UsersEmailController do
:user_logged_in, :user_first_logged_in
)
expect(response).to be_success
expect(response).to be_successful
expect(response.body).to include(I18n.t('change_email.confirmed'))
user.reload
@ -66,7 +66,7 @@ describe UsersEmailController do
get "/u/authorize-email/#{user.email_tokens.last.token}"
expect(response).to be_success
expect(response).to be_successful
expect(group.reload.users.include?(user)).to eq(true)
end
@ -149,7 +149,7 @@ describe UsersEmailController do
email: other_user.email
}
expect(response).to_not be_success
expect(response).to_not be_successful
end
it 'raises an error if there is whitespace too' do
@ -157,7 +157,7 @@ describe UsersEmailController do
email: "#{other_user.email} "
}
expect(response).to_not be_success
expect(response).to_not be_successful
end
end
@ -171,7 +171,7 @@ describe UsersEmailController do
email: other_user.email
}
expect(response).to be_success
expect(response).to be_successful
end
end
end
@ -184,7 +184,7 @@ describe UsersEmailController do
email: other_user.email.upcase
}
expect(response).to_not be_success
expect(response).to_not be_successful
end
end
@ -195,7 +195,7 @@ describe UsersEmailController do
email: "not_good@mailinator.com"
}
expect(response).to_not be_success
expect(response).to_not be_successful
end
it 'raises an error when new email domain is not present in email_domains_whitelist site setting' do
@ -205,7 +205,7 @@ describe UsersEmailController do
email: new_email
}
expect(response).to_not be_success
expect(response).to_not be_successful
end
context 'success' do

View File

@ -80,7 +80,7 @@ describe PostSerializer do
end
context "a hidden post with add_raw enabled" do
let(:user) { Fabricate.build(:user) }
let(:user) { Fabricate.build(:user, id: 101) }
let(:raw) { "Raw contents of the post." }
def serialized_post_for_user(u)
@ -132,12 +132,19 @@ describe PostSerializer do
end
context "a hidden wiki post" do
let(:post) { Fabricate.build(:post, raw: raw, user: user, wiki: true, hidden: true, hidden_reason_id: Post.hidden_reasons[:flag_threshold_reached]) }
let(:post) {
Fabricate.build(
:post,
raw: raw,
user: user,
wiki: true,
hidden: true,
hidden_reason_id: Post.hidden_reasons[:flag_threshold_reached])
}
it "can view edit history only if authorized" do
expect(serialized_post_for_user(nil)[:can_view_edit_history]).to eq(false)
expect(serialized_post_for_user(Fabricate(:user))[:can_view_edit_history]).to eq(false)
expect(serialized_post_for_user(user)[:can_view_edit_history]).to eq(true)
expect(serialized_post_for_user(Fabricate(:moderator))[:can_view_edit_history]).to eq(true)
expect(serialized_post_for_user(Fabricate(:admin))[:can_view_edit_history]).to eq(true)

View File

@ -118,7 +118,8 @@ describe BadgeGranter do
describe 'grant' do
it 'allows overriding of granted_at does not notify old bronze' do
badge = Fabricate(:badge, badge_type_id: BadgeType::Bronze)
badge = Badge.create!(name: 'a badge', badge_type_id: BadgeType::Bronze)
time = 1.year.ago
user_badge = BadgeGranter.grant(badge, user, created_at: time)

View File

@ -4,11 +4,11 @@ describe DestroyTask do
describe 'destroy topics' do
let!(:c) { Fabricate(:category) }
let!(:t) { Fabricate(:topic, category_id: c.id) }
let!(:p) { Fabricate(:post, topic_id: t.id) }
let!(:t) { Fabricate(:topic, category: c) }
let!(:p) { Fabricate(:post, topic: t) }
let!(:c2) { Fabricate(:category) }
let!(:t2) { Fabricate(:topic, category_id: c2.id) }
let!(:p2) { Fabricate(:post, topic_id: t2.id) }
let!(:t2) { Fabricate(:topic, category: c2) }
let!(:p2) { Fabricate(:post, topic: t2) }
it 'destroys all topics in a category' do
before_count = Topic.where(category_id: c.id).count

Some files were not shown because too many files have changed in this diff Show More