Add rubocop to our build. (#5004)

This commit is contained in:
Guo Xiang Tan
2017-07-28 10:20:09 +09:00
committed by GitHub
parent ff4e295c4f
commit 5012d46cbd
871 changed files with 5480 additions and 6056 deletions

View File

@@ -6,11 +6,9 @@ describe ActiveRecord::ConnectionHandling do
let(:replica_port) { 6432 }
let(:config) do
ActiveRecord::Base.configurations[Rails.env].merge({
"adapter" => "postgresql_fallback",
"replica_host" => replica_host,
"replica_port" => replica_port
}).symbolize_keys!
ActiveRecord::Base.configurations[Rails.env].merge("adapter" => "postgresql_fallback",
"replica_host" => replica_host,
"replica_port" => replica_port).symbolize_keys!
end
let(:postgresql_fallback_handler) { PostgreSQLFallbackHandler.instance }
@@ -61,9 +59,7 @@ describe ActiveRecord::ConnectionHandling do
ActiveRecord::Base.expects(:postgresql_connection).with(configuration).raises(PG::ConnectionBad)
ActiveRecord::Base.expects(:verify_replica).with(@replica_connection)
ActiveRecord::Base.expects(:postgresql_connection).with(configuration.merge({
host: replica_host, port: replica_port
})).returns(@replica_connection)
ActiveRecord::Base.expects(:postgresql_connection).with(configuration.merge(host: replica_host, port: replica_port)).returns(@replica_connection)
end
expect(postgresql_fallback_handler.master_down?).to eq(nil)
@@ -71,8 +67,8 @@ describe ActiveRecord::ConnectionHandling do
expect { ActiveRecord::Base.postgresql_fallback_connection(config) }
.to raise_error(PG::ConnectionBad)
expect{ ActiveRecord::Base.postgresql_fallback_connection(config) }
.to change{ Discourse.readonly_mode? }.from(false).to(true)
expect { ActiveRecord::Base.postgresql_fallback_connection(config) }
.to change { Discourse.readonly_mode? }.from(false).to(true)
expect(postgresql_fallback_handler.master_down?).to eq(true)
@@ -82,8 +78,8 @@ describe ActiveRecord::ConnectionHandling do
expect { ActiveRecord::Base.postgresql_fallback_connection(multisite_config) }
.to raise_error(PG::ConnectionBad)
expect{ ActiveRecord::Base.postgresql_fallback_connection(multisite_config) }
.to change{ Discourse.readonly_mode? }.from(false).to(true)
expect { ActiveRecord::Base.postgresql_fallback_connection(multisite_config) }
.to change { Discourse.readonly_mode? }.from(false).to(true)
expect(postgresql_fallback_handler.master_down?).to eq(true)
end
@@ -109,9 +105,7 @@ describe ActiveRecord::ConnectionHandling do
it 'should raise the right error' do
ActiveRecord::Base.expects(:postgresql_connection).with(config).raises(PG::ConnectionBad).once
ActiveRecord::Base.expects(:postgresql_connection).with(config.dup.merge({
host: replica_host, port: replica_port
})).raises(PG::ConnectionBad).once
ActiveRecord::Base.expects(:postgresql_connection).with(config.dup.merge(host: replica_host, port: replica_port)).raises(PG::ConnectionBad).once
2.times do
expect { ActiveRecord::Base.postgresql_fallback_connection(config) }

View File

@@ -51,4 +51,3 @@ describe AdminConfirmation do
end
end

View File

@@ -13,32 +13,32 @@ describe AdminUserIndexQuery do
end
it "has active order" do
query = ::AdminUserIndexQuery.new({ query: "active" })
query = ::AdminUserIndexQuery.new(query: "active")
expect(query.find_users_query.to_sql).to match("last_seen_at")
end
it "can't be injected" do
query = ::AdminUserIndexQuery.new({ order: "wat, no" })
query = ::AdminUserIndexQuery.new(order: "wat, no")
expect(query.find_users_query.to_sql).not_to match("wat, no")
end
it "allows custom ordering" do
query = ::AdminUserIndexQuery.new({ order: "trust_level" })
query = ::AdminUserIndexQuery.new(order: "trust_level")
expect(query.find_users_query.to_sql).to match("trust_level DESC")
end
it "allows custom ordering asc" do
query = ::AdminUserIndexQuery.new({ order: "trust_level", ascending: true })
expect(query.find_users_query.to_sql).to match("trust_level ASC" )
query = ::AdminUserIndexQuery.new(order: "trust_level", ascending: true)
expect(query.find_users_query.to_sql).to match("trust_level ASC")
end
it "allows custom ordering for stats wtih default direction" do
query = ::AdminUserIndexQuery.new({ order: "topics_viewed" })
query = ::AdminUserIndexQuery.new(order: "topics_viewed")
expect(query.find_users_query.to_sql).to match("topics_entered DESC")
end
it "allows custom ordering and direction for stats" do
query = ::AdminUserIndexQuery.new({ order: "topics_viewed", ascending: true })
query = ::AdminUserIndexQuery.new(order: "topics_viewed", ascending: true)
expect(query.find_users_query.to_sql).to match("topics_entered ASC")
end
end
@@ -50,17 +50,17 @@ describe AdminUserIndexQuery do
end
it "offsets by 100 by default for page 2" do
query = ::AdminUserIndexQuery.new({ page: "2"})
query = ::AdminUserIndexQuery.new(page: "2")
expect(query.find_users.to_sql).to match("OFFSET 100")
end
it "offsets by limit for page 2" do
query = ::AdminUserIndexQuery.new({ page: "2"})
query = ::AdminUserIndexQuery.new(page: "2")
expect(query.find_users(10).to_sql).to match("OFFSET 10")
end
it "ignores negative pages" do
query = ::AdminUserIndexQuery.new({ page: "-2" })
query = ::AdminUserIndexQuery.new(page: "-2")
expect(query.find_users.to_sql).to match("OFFSET 0")
end
end
@@ -69,7 +69,7 @@ describe AdminUserIndexQuery do
TrustLevel.levels.each do |key, value|
it "#{key} returns no records" do
query = ::AdminUserIndexQuery.new({ query: key.to_s })
query = ::AdminUserIndexQuery.new(query: key.to_s)
expect(real_users_count(query)).to eq(0)
end
end
@@ -81,7 +81,7 @@ describe AdminUserIndexQuery do
TrustLevel.levels.each do |key, value|
it "finds user with trust #{key}" do
Fabricate(:user, trust_level: TrustLevel.levels[key])
query = ::AdminUserIndexQuery.new({ query: key.to_s })
query = ::AdminUserIndexQuery.new(query: key.to_s)
expect(real_users_count(query)).to eq(1)
end
end
@@ -93,14 +93,14 @@ describe AdminUserIndexQuery do
let!(:user) { Fabricate(:user, approved: false) }
it "finds the unapproved user" do
query = ::AdminUserIndexQuery.new({ query: 'pending' })
query = ::AdminUserIndexQuery.new(query: 'pending')
expect(query.find_users.count).to eq(1)
end
context 'and a suspended pending user' do
let!(:suspended_user) { Fabricate(:user, approved: false, suspended_at: 1.hour.ago, suspended_till: 20.years.from_now) }
it "doesn't return the suspended user" do
query = ::AdminUserIndexQuery.new({ query: 'pending' })
query = ::AdminUserIndexQuery.new(query: 'pending')
expect(query.find_users.count).to eq(1)
end
end
@@ -113,7 +113,7 @@ describe AdminUserIndexQuery do
end
it "shows nil values first with asc" do
users = ::AdminUserIndexQuery.new({ order: "last_emailed", ascending: true }).find_users
users = ::AdminUserIndexQuery.new(order: "last_emailed", ascending: true).find_users
expect(users.where('users.id > -2').count).to eq(2)
expect(users.first.username).to eq("system")
@@ -121,7 +121,7 @@ describe AdminUserIndexQuery do
end
it "shows nil values last with desc" do
users = ::AdminUserIndexQuery.new({ order: "last_emailed"}).find_users
users = ::AdminUserIndexQuery.new(order: "last_emailed").find_users
expect(users.where('users.id > -2').count).to eq(2)
expect(users.first.last_emailed_at).to_not eq(nil)
@@ -134,7 +134,7 @@ describe AdminUserIndexQuery do
let!(:user) { Fabricate(:user, admin: true) }
it "finds the admin" do
query = ::AdminUserIndexQuery.new({ query: 'admins' })
query = ::AdminUserIndexQuery.new(query: 'admins')
expect(real_users_count(query)).to eq(1)
end
@@ -145,7 +145,7 @@ describe AdminUserIndexQuery do
let!(:user) { Fabricate(:user, moderator: true) }
it "finds the moderator" do
query = ::AdminUserIndexQuery.new({ query: 'moderators' })
query = ::AdminUserIndexQuery.new(query: 'moderators')
expect(real_users_count(query)).to eq(1)
end
@@ -156,7 +156,7 @@ describe AdminUserIndexQuery do
let!(:user) { Fabricate(:user, blocked: true) }
it "finds the blocked user" do
query = ::AdminUserIndexQuery.new({ query: 'blocked' })
query = ::AdminUserIndexQuery.new(query: 'blocked')
expect(query.find_users.count).to eq(1)
end
@@ -169,12 +169,12 @@ describe AdminUserIndexQuery do
before(:each) { Fabricate(:user, email: "test1@example.com") }
it "matches the email" do
query = ::AdminUserIndexQuery.new({ filter: " est1" })
query = ::AdminUserIndexQuery.new(filter: " est1")
expect(query.find_users.count()).to eq(1)
end
it "matches the email using any case" do
query = ::AdminUserIndexQuery.new({ filter: "Test1\t" })
query = ::AdminUserIndexQuery.new(filter: "Test1\t")
expect(query.find_users.count()).to eq(1)
end
@@ -185,12 +185,12 @@ describe AdminUserIndexQuery do
before(:each) { Fabricate(:user, username: "test_user_1") }
it "matches the username" do
query = ::AdminUserIndexQuery.new({ filter: "user\n" })
query = ::AdminUserIndexQuery.new(filter: "user\n")
expect(query.find_users.count).to eq(1)
end
it "matches the username using any case" do
query = ::AdminUserIndexQuery.new({ filter: "\r\nUser" })
query = ::AdminUserIndexQuery.new(filter: "\r\nUser")
expect(query.find_users.count).to eq(1)
end
end
@@ -200,7 +200,7 @@ describe AdminUserIndexQuery do
let!(:user) { Fabricate(:user, ip_address: "117.207.94.9") }
it "matches the ip address" do
query = ::AdminUserIndexQuery.new({ filter: " 117.207.94.9 " })
query = ::AdminUserIndexQuery.new(filter: " 117.207.94.9 ")
expect(query.find_users.count()).to eq(1)
end

View File

@@ -36,10 +36,9 @@ describe Archetype do
@list = Archetype.list.dup
Archetype.register('glados')
expect(Archetype.list.size).to eq(@list.size + 1)
expect(Archetype.list.find {|a| a.id == 'glados'}).to be_present
expect(Archetype.list.find { |a| a.id == 'glados' }).to be_present
end
end
end

View File

@@ -10,14 +10,14 @@ describe Auth::DefaultCurrentUserProvider do
end
end
def provider(url, opts=nil)
opts ||= {method: "GET"}
def provider(url, opts = nil)
opts ||= { method: "GET" }
env = Rack::MockRequest.env_for(url, opts)
TestProvider.new(env)
end
it "raises errors for incorrect api_key" do
expect{
expect {
provider("/?api_key=INCORRECT").current_user
}.to raise_error(Discourse::InvalidAccess)
end
@@ -29,13 +29,13 @@ describe Auth::DefaultCurrentUserProvider do
user.update_columns(active: false)
expect{
expect {
provider("/?api_key=hello").current_user
}.to raise_error(Discourse::InvalidAccess)
user.update_columns(active: true, suspended_till: 1.day.from_now)
expect{
expect {
provider("/?api_key=hello").current_user
}.to raise_error(Discourse::InvalidAccess)
end
@@ -45,7 +45,7 @@ describe Auth::DefaultCurrentUserProvider do
user2 = Fabricate(:user)
ApiKey.create!(key: "hello", user_id: user.id, created_by_id: -1)
expect{
expect {
provider("/?api_key=hello&api_username=#{user2.username.downcase}").current_user
}.to raise_error(Discourse::InvalidAccess)
end
@@ -54,7 +54,7 @@ describe Auth::DefaultCurrentUserProvider do
user = Fabricate(:user)
ApiKey.create!(key: "hello", user_id: user.id, created_by_id: -1, allowed_ips: ['10.0.0.0/24'])
expect{
expect {
provider("/?api_key=hello&api_username=#{user.username.downcase}", "REMOTE_ADDR" => "10.1.0.1").current_user
}.to raise_error(Discourse::InvalidAccess)
@@ -69,7 +69,6 @@ describe Auth::DefaultCurrentUserProvider do
expect(found_user.id).to eq(user.id)
found_user = provider("/?api_key=hello&api_username=#{user.username.downcase}",
"HTTP_X_FORWARDED_FOR" => "10.1.1.1, 100.0.0.22").current_user
expect(found_user.id).to eq(user.id)
@@ -208,7 +207,7 @@ describe Auth::DefaultCurrentUserProvider do
end
it "correctly removes invalid cookies" do
cookies = {"_t" => SecureRandom.hex}
cookies = { "_t" => SecureRandom.hex }
provider('/').refresh_session(nil, {}, cookies)
expect(cookies.key?("_t")).to eq(false)
end
@@ -230,7 +229,6 @@ describe Auth::DefaultCurrentUserProvider do
cookies = {}
provider('/').log_on_user(user, {}, cookies)
expect(cookies["_t"][:same_site]).to eq("Lax")
expect(cookies["_t"][:httponly]).to eq(true)
expect(cookies["_t"][:secure]).to eq(false)
@@ -286,10 +284,9 @@ describe Auth::DefaultCurrentUserProvider do
expect(good_provider.is_user_api?).to eq(true)
expect {
provider("/", params.merge({"REQUEST_METHOD" => "POST"})).current_user
provider("/", params.merge("REQUEST_METHOD" => "POST")).current_user
}.to raise_error(Discourse::InvalidAccess)
user.update_columns(suspended_till: 1.year.from_now)
expect {
@@ -322,7 +319,6 @@ describe Auth::DefaultCurrentUserProvider do
provider("/", params).current_user
}.to raise_error(RateLimiter::LimitExceeded)
SiteSetting.max_user_api_reqs_per_day = 4
SiteSetting.max_user_api_reqs_per_minute = 3
@@ -340,4 +336,3 @@ describe Auth::DefaultCurrentUserProvider do
end
end
end

View File

@@ -48,7 +48,7 @@ describe Auth::FacebookAuthenticator do
}
},
"info" => {
:email => "bob@bob.com"
email: "bob@bob.com"
},
"uid" => "100"
}

View File

@@ -14,20 +14,20 @@ describe Auth::GithubAuthenticator do
user = Fabricate(:user)
hash = {
:extra => {
:all_emails => [{
:email => user.email,
:primary => true,
:verified => true,
extra: {
all_emails: [{
email: user.email,
primary: true,
verified: true,
}]
},
:info => {
:email => user.email,
:email_verified => true,
:nickname => user.username,
:name => user.name,
info: {
email: user.email,
email_verified: true,
nickname: user.username,
name: user.name,
},
:uid => "100"
uid: "100"
}
authenticator = Auth::GithubAuthenticator.new
@@ -44,20 +44,20 @@ describe Auth::GithubAuthenticator do
user = Fabricate(:user)
hash = {
:extra => {
:all_emails => [{
:email => user.email,
:primary => true,
:verified => false,
extra: {
all_emails: [{
email: user.email,
primary: true,
verified: false,
}]
},
:info => {
:email => user.email,
:email_verified => false,
:nickname => user.username,
:name => user.name,
info: {
email: user.email,
email_verified: false,
nickname: user.username,
name: user.name,
},
:uid => "100"
uid: "100"
}
authenticator = Auth::GithubAuthenticator.new
@@ -72,20 +72,20 @@ describe Auth::GithubAuthenticator do
it 'can create a proper result for non existing users' do
hash = {
:extra => {
:all_emails => [{
:email => "person@example.com",
:primary => true,
:verified => true,
extra: {
all_emails: [{
email: "person@example.com",
primary: true,
verified: true,
}]
},
:info => {
:email => "person@example.com",
:email_verified => true,
:nickname => "person",
:name => "Person Lastname",
info: {
email: "person@example.com",
email_verified: true,
nickname: "person",
name: "Person Lastname",
},
:uid => "100"
uid: "100"
}
authenticator = Auth::GithubAuthenticator.new
@@ -100,24 +100,24 @@ describe Auth::GithubAuthenticator do
it 'will skip blacklisted domains for non existing users' do
hash = {
:extra => {
:all_emails => [{
:email => "not_allowed@blacklist.com",
:primary => true,
:verified => true,
},{
:email => "allowed@whitelist.com",
:primary => false,
:verified => true,
extra: {
all_emails: [{
email: "not_allowed@blacklist.com",
primary: true,
verified: true,
}, {
email: "allowed@whitelist.com",
primary: false,
verified: true,
}]
},
:info => {
:email => "not_allowed@blacklist.com",
:email_verified => true,
:nickname => "person",
:name => "Person Lastname",
info: {
email: "not_allowed@blacklist.com",
email_verified: true,
nickname: "person",
name: "Person Lastname",
},
:uid => "100"
uid: "100"
}
authenticator = Auth::GithubAuthenticator.new
@@ -133,28 +133,28 @@ describe Auth::GithubAuthenticator do
it 'will find whitelisted domains for non existing users' do
hash = {
:extra => {
:all_emails => [{
:email => "person@example.com",
:primary => true,
:verified => true,
},{
:email => "not_allowed@blacklist.com",
:primary => true,
:verified => true,
},{
:email => "allowed@whitelist.com",
:primary => false,
:verified => true,
extra: {
all_emails: [{
email: "person@example.com",
primary: true,
verified: true,
}, {
email: "not_allowed@blacklist.com",
primary: true,
verified: true,
}, {
email: "allowed@whitelist.com",
primary: false,
verified: true,
}]
},
:info => {
:email => "person@example.com",
:email_verified => true,
:nickname => "person",
:name => "Person Lastname",
info: {
email: "person@example.com",
email_verified: true,
nickname: "person",
name: "Person Lastname",
},
:uid => "100"
uid: "100"
}
authenticator = Auth::GithubAuthenticator.new

View File

@@ -14,16 +14,16 @@ describe Auth::GoogleOAuth2Authenticator do
user = Fabricate(:user)
hash = {
:uid => "123456789",
:info => {
:name => "John Doe",
:email => user.email
uid: "123456789",
info: {
name: "John Doe",
email: user.email
},
:extra => {
:raw_info => {
:email => user.email,
:email_verified => false,
:name => "John Doe"
extra: {
raw_info: {
email: user.email,
email_verified: false,
name: "John Doe"
}
}
}
@@ -39,16 +39,16 @@ describe Auth::GoogleOAuth2Authenticator do
user = Fabricate(:user)
hash = {
:uid => "123456789",
:info => {
:name => "John Doe",
:email => user.email
uid: "123456789",
info: {
name: "John Doe",
email: user.email
},
:extra => {
:raw_info => {
:email => user.email,
:email_verified => true,
:name => "John Doe"
extra: {
raw_info: {
email: user.email,
email_verified: true,
name: "John Doe"
}
}
}
@@ -60,16 +60,16 @@ describe Auth::GoogleOAuth2Authenticator do
it 'can create a proper result for non existing users' do
hash = {
:uid => "123456789",
:info => {
:name => "Jane Doe",
:email => "jane.doe@the.google.com"
uid: "123456789",
info: {
name: "Jane Doe",
email: "jane.doe@the.google.com"
},
:extra => {
:raw_info => {
:email => "jane.doe@the.google.com",
:email_verified => true,
:name => "Jane Doe"
extra: {
raw_info: {
email: "jane.doe@the.google.com",
email_verified: true,
name: "Jane Doe"
}
}
}
@@ -87,9 +87,9 @@ describe Auth::GoogleOAuth2Authenticator do
authenticator = Auth::GoogleOAuth2Authenticator.new
user = Fabricate(:user)
session = {
:email_valid => "true",
:extra_data => {
:google_user_id => 1
email_valid: "true",
extra_data: {
google_user_id: 1
}
}
authenticator.after_create_account(user, session)

View File

@@ -13,7 +13,7 @@ describe Auth::OpenIdAuthenticator do
user = Fabricate(:user)
response = OpenStruct.new(identity_url: 'abc')
result = auth.after_authenticate(info: {email: user.email}, extra: {response: response})
result = auth.after_authenticate(info: { email: user.email }, extra: { response: response })
expect(result.user).to eq(user)
end

View File

@@ -4,7 +4,7 @@ require 'rails_helper'
require_dependency 'avatar_lookup'
describe AvatarLookup do
let!(:user){ Fabricate(:user) }
let!(:user) { Fabricate(:user) }
describe '#[]' do
before do

View File

@@ -13,7 +13,7 @@ describe Cache do
end
it "supports hash" do
hash = {a: 1, b: [1,2,3]}
hash = { a: 1, b: [1, 2, 3] }
cache.write("hash", hash)
expect(cache.read("hash")).to eq(hash)
end
@@ -50,7 +50,7 @@ describe Cache do
expect($redis.ttl(key)).to be_within(2.seconds).of(1.minute)
# we always expire withing a day
cache.fetch("bla"){ "hi" }
cache.fetch("bla") { "hi" }
key = cache.namespaced_key("bla")
expect($redis.ttl(key)).to be_within(2.seconds).of(1.day)

View File

@@ -17,8 +17,8 @@ RSpec.describe ColumnDropper do
it "can correctly drop columns after correct delay" do
Topic.exec_sql "ALTER TABLE topics ADD COLUMN junk int"
name = Topic
.exec_sql("SELECT name FROM schema_migration_details LIMIT 1")
.getvalue(0,0)
.exec_sql("SELECT name FROM schema_migration_details LIMIT 1")
.getvalue(0, 0)
Topic.exec_sql("UPDATE schema_migration_details SET created_at = :created_at WHERE name = :name",
name: name, created_at: 15.minutes.ago)
@@ -30,7 +30,7 @@ RSpec.describe ColumnDropper do
after_migration: name,
columns: ['junk'],
delay: 20.minutes,
on_drop: ->(){dropped_proc_called = true}
on_drop: ->() { dropped_proc_called = true }
)
expect(has_column?('topics', 'junk')).to eq(true)
@@ -41,7 +41,7 @@ RSpec.describe ColumnDropper do
after_migration: name,
columns: ['junk'],
delay: 10.minutes,
on_drop: ->(){dropped_proc_called = true}
on_drop: ->() { dropped_proc_called = true }
)
expect(has_column?('topics', 'junk')).to eq(false)

View File

@@ -13,7 +13,7 @@ describe CommonPasswords do
subject { described_class.common_password? @password }
it "returns false if password isn't in the common passwords list" do
described_class.stubs(:password_list).returns(stub_everything(:include? => false))
described_class.stubs(:password_list).returns(stub_everything(include?: false))
@password = 'uncommonPassword'
expect(subject).to eq(false)
end
@@ -31,7 +31,7 @@ describe CommonPasswords do
end
it "returns true if password is in the common passwords list" do
described_class.stubs(:password_list).returns(stub_everything(:include? => true))
described_class.stubs(:password_list).returns(stub_everything(include?: true))
@password = "password"
expect(subject).to eq(true)
end

View File

@@ -127,7 +127,7 @@ describe ComposerMessagesFinder do
end
it "doesn't notify users who have been notified already" do
UserHistory.create!(action: UserHistory.actions[:notified_about_avatar], target_user_id: user.id )
UserHistory.create!(action: UserHistory.actions[:notified_about_avatar], target_user_id: user.id)
expect(finder.check_avatar_notification).to be_blank
end
@@ -179,12 +179,12 @@ describe ComposerMessagesFinder do
end
it "doesn't notify a user it has already notified about sequential replies" do
UserHistory.create!(action: UserHistory.actions[:notified_about_sequential_replies], target_user_id: user.id, topic_id: topic.id )
UserHistory.create!(action: UserHistory.actions[:notified_about_sequential_replies], target_user_id: user.id, topic_id: topic.id)
expect(finder.check_sequential_replies).to be_blank
end
it "will notify you if it hasn't in the current topic" do
UserHistory.create!(action: UserHistory.actions[:notified_about_sequential_replies], target_user_id: user.id, topic_id: topic.id+1 )
UserHistory.create!(action: UserHistory.actions[:notified_about_sequential_replies], target_user_id: user.id, topic_id: topic.id + 1)
expect(finder.check_sequential_replies).to be_present
end
@@ -259,12 +259,12 @@ describe ComposerMessagesFinder do
end
it "doesn't notify a user it has already notified in this topic" do
UserHistory.create!(action: UserHistory.actions[:notified_about_dominating_topic], topic_id: topic.id, target_user_id: user.id )
UserHistory.create!(action: UserHistory.actions[:notified_about_dominating_topic], topic_id: topic.id, target_user_id: user.id)
expect(finder.check_dominating_topic).to be_blank
end
it "notifies a user if the topic is different" do
UserHistory.create!(action: UserHistory.actions[:notified_about_dominating_topic], topic_id: topic.id+1, target_user_id: user.id )
UserHistory.create!(action: UserHistory.actions[:notified_about_dominating_topic], topic_id: topic.id + 1, target_user_id: user.id)
expect(finder.check_dominating_topic).to be_present
end
@@ -359,7 +359,7 @@ describe ComposerMessagesFinder do
UserHistory.create!(
action: UserHistory.actions[:notified_about_get_a_room],
target_user_id: user.id,
topic_id: topic.id+1
topic_id: topic.id + 1
)
expect(finder.check_get_a_room(min_users_posted: 2)).to be_present
end
@@ -420,7 +420,6 @@ describe ComposerMessagesFinder do
end
context '.check_reviving_old_topic' do
let(:user) { Fabricate(:user) }
let(:topic) { Fabricate(:topic) }

View File

@@ -1,6 +1,5 @@
require "rails_helper"
describe HasCustomFields do
context "custom_fields" do
@@ -48,7 +47,7 @@ describe HasCustomFields do
test_item.save
test_item = CustomFieldsTestItem.find(test_item.id)
expect(test_item.custom_fields).to eq({"jack" => "jill"})
expect(test_item.custom_fields).to eq("jack" => "jill")
end
it "casts integers to string without error" do
@@ -88,35 +87,35 @@ describe HasCustomFields do
it "double save actually saves" do
test_item = CustomFieldsTestItem.new
test_item.custom_fields = {"a" => "b"}
test_item.custom_fields = { "a" => "b" }
test_item.save
test_item.custom_fields["c"] = "d"
test_item.save
db_item = CustomFieldsTestItem.find(test_item.id)
expect(db_item.custom_fields).to eq({"a" => "b", "c" => "d"})
expect(db_item.custom_fields).to eq("a" => "b", "c" => "d")
end
it "handles arrays properly" do
test_item = CustomFieldsTestItem.new
test_item.custom_fields = {"a" => ["b", "c", "d"]}
test_item.custom_fields = { "a" => ["b", "c", "d"] }
test_item.save
db_item = CustomFieldsTestItem.find(test_item.id)
expect(db_item.custom_fields).to eq({"a" => ["b", "c", "d"]})
expect(db_item.custom_fields).to eq("a" => ["b", "c", "d"])
db_item.custom_fields.update('a' => ['c', 'd'])
db_item.save
expect(db_item.custom_fields).to eq({"a" => ["c", "d"]})
expect(db_item.custom_fields).to eq("a" => ["c", "d"])
# It can be updated to the exact same value
db_item.custom_fields.update('a' => ['c'])
db_item.save
expect(db_item.custom_fields).to eq({"a" => "c"})
expect(db_item.custom_fields).to eq("a" => "c")
db_item.custom_fields.update('a' => ['c'])
db_item.save
expect(db_item.custom_fields).to eq({"a" => "c"})
expect(db_item.custom_fields).to eq("a" => "c")
db_item.custom_fields.delete('a')
expect(db_item.custom_fields).to eq({})
@@ -124,12 +123,12 @@ describe HasCustomFields do
it "casts integers in arrays properly without error" do
test_item = CustomFieldsTestItem.new
test_item.custom_fields = {"a" => ["b", 10, "d"]}
test_item.custom_fields = { "a" => ["b", 10, "d"] }
test_item.save
expect(test_item.custom_fields).to eq({"a" => ["b", "10", "d"]})
expect(test_item.custom_fields).to eq("a" => ["b", "10", "d"])
db_item = CustomFieldsTestItem.find(test_item.id)
expect(db_item.custom_fields).to eq({"a" => ["b", "10", "d"]})
expect(db_item.custom_fields).to eq("a" => ["b", "10", "d"])
end
it "supportes type coersion" do
@@ -138,11 +137,11 @@ describe HasCustomFields do
CustomFieldsTestItem.register_custom_field_type("int", :integer)
CustomFieldsTestItem.register_custom_field_type("json", :json)
test_item.custom_fields = {"bool" => true, "int" => 1, "json" => { "foo" => "bar" }}
test_item.custom_fields = { "bool" => true, "int" => 1, "json" => { "foo" => "bar" } }
test_item.save
test_item.reload
expect(test_item.custom_fields).to eq({"bool" => true, "int" => 1, "json" => { "foo" => "bar" }})
expect(test_item.custom_fields).to eq("bool" => true, "int" => 1, "json" => { "foo" => "bar" })
end
it "simple modifications don't interfere" do
@@ -165,17 +164,17 @@ describe HasCustomFields do
test_item = CustomFieldsTestItem.find(test_item.id)
test_item2 = CustomFieldsTestItem.find(test_item2.id)
expect(test_item.custom_fields).to eq({"jack" => "black", "bob" => "marley"})
expect(test_item2.custom_fields).to eq({"sixto" => "rodriguez", "de" => "la playa"})
expect(test_item.custom_fields).to eq("jack" => "black", "bob" => "marley")
expect(test_item2.custom_fields).to eq("sixto" => "rodriguez", "de" => "la playa")
end
it "supports bulk retrieval with a list of ids" do
item1 = CustomFieldsTestItem.new
item1.custom_fields = {"a" => ["b", "c", "d"], 'not_whitelisted' => 'secret'}
item1.custom_fields = { "a" => ["b", "c", "d"], 'not_whitelisted' => 'secret' }
item1.save
item2 = CustomFieldsTestItem.new
item2.custom_fields = {"e" => 'hallo'}
item2.custom_fields = { "e" => 'hallo' }
item2.save
fields = CustomFieldsTestItem.custom_fields_for_ids([item1.id, item2.id], ['a', 'e'])

View File

@@ -28,19 +28,19 @@ describe Positionable do
Topic.exec_sql("insert into test_items(id,position) values(#{i}, #{i})")
end
expect(positions).to eq([0,1,2,3,4])
expect(positions).to eq([0, 1, 2, 3, 4])
TestItem.find(3).move_to(0)
expect(positions).to eq([3,0,1,2,4])
expect(TestItem.pluck(:position).sort).to eq([0,1,2,3,4])
expect(positions).to eq([3, 0, 1, 2, 4])
expect(TestItem.pluck(:position).sort).to eq([0, 1, 2, 3, 4])
TestItem.find(3).move_to(1)
expect(positions).to eq([0,3,1,2,4])
expect(positions).to eq([0, 3, 1, 2, 4])
# this is somewhat odd, but when there is no such position, not much we can do
TestItem.find(1).move_to(5)
expect(positions).to eq([0,3,2,4,1])
expect(positions).to eq([0, 3, 2, 4, 1])
expect(TestItem.pluck(:position).sort).to eq([0,1,2,3,4])
expect(TestItem.pluck(:position).sort).to eq([0, 1, 2, 3, 4])
item = TestItem.new
item.id = 7

View File

@@ -5,24 +5,24 @@ describe ContentBuffer do
it "handles deletion across lines properly" do
c = ContentBuffer.new("a\nbc\nc")
c.apply_transform!(start: {row: 0, col: 0}, finish: {col: 1, row: 1}, operation: :delete)
c.apply_transform!(start: { row: 0, col: 0 }, finish: { col: 1, row: 1 }, operation: :delete)
expect(c.to_s).to eq("c\nc")
end
it "handles deletion inside lines properly" do
c = ContentBuffer.new("hello world")
c.apply_transform!(start: {row: 0, col: 1}, finish: {col: 4, row: 0}, operation: :delete)
c.apply_transform!(start: { row: 0, col: 1 }, finish: { col: 4, row: 0 }, operation: :delete)
expect(c.to_s).to eq("ho world")
end
it "handles inserts inside lines properly" do
c = ContentBuffer.new("hello!")
c.apply_transform!(start: {row: 0, col: 5}, operation: :insert, text: " world")
c.apply_transform!(start: { row: 0, col: 5 }, operation: :insert, text: " world")
expect(c.to_s).to eq("hello world!")
end
it "handles multiline inserts" do
c = ContentBuffer.new("hello!")
c.apply_transform!(start: {row: 0, col: 5}, operation: :insert, text: "\nworld")
c.apply_transform!(start: { row: 0, col: 5 }, operation: :insert, text: "\nworld")
expect(c.to_s).to eq("hello\nworld!")
end

View File

@@ -31,7 +31,7 @@ describe CookedPostProcessor do
end
context "admin user" do
let(:post) { Fabricate(:post, user: Fabricate(:admin) ) }
let(:post) { Fabricate(:post, user: Fabricate(:admin)) }
it "omits nofollow" do
cpp = CookedPostProcessor.new(post)
@@ -41,8 +41,8 @@ describe CookedPostProcessor do
end
context ".keep_reverse_index_up_to_date" do
let(:video_upload) { Fabricate(:upload, url: '/uploads/default/1/1234567890123456.mp4' ) }
let(:image_upload) { Fabricate(:upload, url: '/uploads/default/1/1234567890123456.jpg' ) }
let(:video_upload) { Fabricate(:upload, url: '/uploads/default/1/1234567890123456.mp4') }
let(:image_upload) { Fabricate(:upload, url: '/uploads/default/1/1234567890123456.jpg') }
let(:audio_upload) { Fabricate(:upload, url: '/uploads/default/1/1234567890123456.ogg') }
let(:attachment_upload) { Fabricate(:upload, url: '/uploads/default/1/1234567890123456.csv') }
@@ -100,7 +100,7 @@ describe CookedPostProcessor do
before { cpp.post_process_images }
context "valid" do
let(:image_sizes) { {"http://foo.bar/image.png" => {"width" => 111, "height" => 222}} }
let(:image_sizes) { { "http://foo.bar/image.png" => { "width" => 111, "height" => 222 } } }
it "uses them" do
@@ -113,17 +113,17 @@ describe CookedPostProcessor do
end
context "invalid width" do
let(:image_sizes) { {"http://foo.bar/image.png" => {"width" => 0, "height" => 222}} }
let(:image_sizes) { { "http://foo.bar/image.png" => { "width" => 0, "height" => 222 } } }
include_examples "leave dimensions alone"
end
context "invalid height" do
let(:image_sizes) { {"http://foo.bar/image.png" => {"width" => 111, "height" => 0}} }
let(:image_sizes) { { "http://foo.bar/image.png" => { "width" => 111, "height" => 0 } } }
include_examples "leave dimensions alone"
end
context "invalid width & height" do
let(:image_sizes) { {"http://foo.bar/image.png" => {"width" => 0, "height" => 0}} }
let(:image_sizes) { { "http://foo.bar/image.png" => { "width" => 0, "height" => 0 } } }
include_examples "leave dimensions alone"
end
@@ -287,31 +287,31 @@ describe CookedPostProcessor do
let(:cpp) { CookedPostProcessor.new(post) }
it "returns the size when width and height are specified" do
img = { 'src' => 'http://foo.bar/image3.png', 'width' => 50, 'height' => 70}
img = { 'src' => 'http://foo.bar/image3.png', 'width' => 50, 'height' => 70 }
expect(cpp.get_size_from_attributes(img)).to eq([50, 70])
end
it "returns the size when width and height are floats" do
img = { 'src' => 'http://foo.bar/image3.png', 'width' => 50.2, 'height' => 70.1}
img = { 'src' => 'http://foo.bar/image3.png', 'width' => 50.2, 'height' => 70.1 }
expect(cpp.get_size_from_attributes(img)).to eq([50, 70])
end
it "resizes when only width is specified" do
img = { 'src' => 'http://foo.bar/image3.png', 'width' => 100}
img = { 'src' => 'http://foo.bar/image3.png', 'width' => 100 }
SiteSetting.crawl_images = true
FastImage.expects(:size).returns([200, 400])
expect(cpp.get_size_from_attributes(img)).to eq([100, 200])
end
it "resizes when only height is specified" do
img = { 'src' => 'http://foo.bar/image3.png', 'height' => 100}
img = { 'src' => 'http://foo.bar/image3.png', 'height' => 100 }
SiteSetting.crawl_images = true
FastImage.expects(:size).returns([100, 300])
expect(cpp.get_size_from_attributes(img)).to eq([33, 100])
end
it "doesn't raise an error with a weird url" do
img = { 'src' => nil, 'height' => 100}
img = { 'src' => nil, 'height' => 100 }
SiteSetting.crawl_images = true
expect(cpp.get_size_from_attributes(img)).to be_nil
end
@@ -414,12 +414,12 @@ describe CookedPostProcessor do
end
it "returns the original filename of the upload when there is an upload" do
upload = build(:upload, { original_filename: "upload.jpg" })
upload = build(:upload, original_filename: "upload.jpg")
expect(cpp.get_filename(upload, "http://domain.com/image.png")).to eq("upload.jpg")
end
it "returns a generic name for pasted images" do
upload = build(:upload, { original_filename: "blob.png" })
upload = build(:upload, original_filename: "blob.png")
expect(cpp.get_filename(upload, "http://domain.com/image.png")).to eq(I18n.t('upload.pasted_image_filename'))
end
@@ -432,8 +432,8 @@ describe CookedPostProcessor do
before do
Oneboxer.expects(:onebox)
.with("http://www.youtube.com/watch?v=9bZkp7q19f0", post_id: 123, invalidate_oneboxes: true)
.returns("<div>GANGNAM STYLE</div>")
.with("http://www.youtube.com/watch?v=9bZkp7q19f0", post_id: 123, invalidate_oneboxes: true)
.returns("<div>GANGNAM STYLE</div>")
cpp.post_process_oneboxes
end

View File

@@ -11,7 +11,7 @@ describe DiscourseDiff do
prev = "<div>#{CGI::escapeHTML(a)}</div>"
cur = "<div>#{CGI::escapeHTML(b)}</div>"
diff = DiscourseDiff.new(prev,cur)
diff = DiscourseDiff.new(prev, cur)
expect(diff.inline_html).not_to match(/<\/?test>/)
expect(diff.side_by_side_html).not_to match(/<\/?test>/)
end

View File

@@ -61,7 +61,7 @@ describe DiscourseEvent do
before do
DiscourseEvent.on(:acid_face) do |user|
user.job = 'Supervillian'
user.job = 'Supervillian'
end
DiscourseEvent.trigger(:acid_face, harvey)

View File

@@ -4,7 +4,7 @@ require_dependency 'discourse_hub'
describe DiscourseHub do
describe '.discourse_version_check' do
it 'should return just return the json that the hub returns' do
hub_response = {'success' => 'OK', 'latest_version' => '0.8.1', 'critical_updates' => false}
hub_response = { 'success' => 'OK', 'latest_version' => '0.8.1', 'critical_updates' => false }
stub_request(:get, (ENV['HUB_BASE_URL'] || "http://local.hub:3000/api") + "/version_check").
with(query: DiscourseHub.version_check_payload).

View File

@@ -8,10 +8,10 @@ describe I18n::Backend::DiscourseI18n do
before do
I18n.reload!
backend.store_translations(:en, :foo => 'Foo in :en', :bar => 'Bar in :en', :wat => "Hello %{count}")
backend.store_translations(:en, :items => {:one => 'one item', :other => "%{count} items" })
backend.store_translations(:de, :bar => 'Bar in :de')
backend.store_translations(:'de-AT', :baz => 'Baz in :de-AT')
backend.store_translations(:en, foo: 'Foo in :en', bar: 'Bar in :en', wat: "Hello %{count}")
backend.store_translations(:en, items: { one: 'one item', other: "%{count} items" })
backend.store_translations(:de, bar: 'Bar in :de')
backend.store_translations(:'de-AT', baz: 'Baz in :de-AT')
end
after do
@@ -27,11 +27,11 @@ describe I18n::Backend::DiscourseI18n do
end
it 'can be searched by key or value' do
expect(backend.search(:en, 'fo')).to eq({'foo' => 'Foo in :en'})
expect(backend.search(:en, 'foo')).to eq({'foo' => 'Foo in :en' })
expect(backend.search(:en, 'Foo')).to eq({'foo' => 'Foo in :en' })
expect(backend.search(:en, 'hello')).to eq({'wat' => 'Hello %{count}' })
expect(backend.search(:en, 'items.one')).to eq({'items.one' => 'one item' })
expect(backend.search(:en, 'fo')).to eq('foo' => 'Foo in :en')
expect(backend.search(:en, 'foo')).to eq('foo' => 'Foo in :en')
expect(backend.search(:en, 'Foo')).to eq('foo' => 'Foo in :en')
expect(backend.search(:en, 'hello')).to eq('wat' => 'Hello %{count}')
expect(backend.search(:en, 'items.one')).to eq('items.one' => 'one item')
end
it 'can return multiple results' do
@@ -42,8 +42,8 @@ describe I18n::Backend::DiscourseI18n do
end
it 'uses fallback locales for searching' do
expect(backend.search(:de, 'bar')).to eq({'bar' => 'Bar in :de'})
expect(backend.search(:de, 'foo')).to eq({'foo' => 'Foo in :en'})
expect(backend.search(:de, 'bar')).to eq('bar' => 'Bar in :de')
expect(backend.search(:de, 'foo')).to eq('foo' => 'Foo in :en')
end
describe '#exists?' do
@@ -98,8 +98,8 @@ describe I18n::Backend::DiscourseI18n do
it "can be searched" do
TranslationOverride.upsert!('en', 'wat', 'Overwritten value')
expect(I18n.search('wat', backend: backend)).to eq({'wat' => 'Overwritten value'})
expect(I18n.search('Overwritten', backend: backend)).to eq({'wat' => 'Overwritten value'})
expect(I18n.search('wat', backend: backend)).to eq('wat' => 'Overwritten value')
expect(I18n.search('Overwritten', backend: backend)).to eq('wat' => 'Overwritten value')
expect(I18n.search('Hello', backend: backend)).to eq({})
end

View File

@@ -5,9 +5,7 @@ describe DiscourseRedis do
let(:slave_port) { 1234 }
let(:config) do
DiscourseRedis.config.dup.merge({
slave_host: 'testhost', slave_port: 1234, connector: DiscourseRedis::Connector
})
DiscourseRedis.config.dup.merge(slave_host: 'testhost', slave_port: 1234, connector: DiscourseRedis::Connector)
end
let(:fallback_handler) { DiscourseRedis::FallbackHandler.instance }

View File

@@ -108,7 +108,7 @@ describe Discourse do
yield
end
messages.first{|m| m.channel == Discourse.readonly_channel}
messages.first { |m| m.channel == Discourse.readonly_channel }
end
describe ".enable_readonly_mode" do
@@ -207,7 +207,7 @@ describe Discourse do
it "correctly passes extra context" do
exception = StandardError.new
Discourse.handle_job_exception(exception, {message: "Doing a test", post_id: 31}, nil)
Discourse.handle_job_exception(exception, { message: "Doing a test", post_id: 31 }, nil)
expect(logger.exception).to eq(exception)
expect(logger.context.keys.sort).to eq([:current_db, :current_hostname, :message, :post_id].sort)
end

View File

@@ -26,7 +26,6 @@ describe DistributedMutex do
$redis.setnx "test_mutex_key", Time.now.to_i - 1
start = Time.now.to_i
m.synchronize do
"nop"
@@ -41,7 +40,7 @@ describe DistributedMutex do
expect {
m.synchronize do
m.synchronize{}
m.synchronize {}
end
}.to raise_error(ThreadError)
end

View File

@@ -5,7 +5,7 @@ describe Email::MessageBuilder do
let(:to_address) { "jake@adventuretime.ooo" }
let(:subject) { "Tree Trunks has made some apple pie!" }
let(:body) { "oh my glob Jake, Tree Trunks just made the tastiest apple pie ever!"}
let(:body) { "oh my glob Jake, Tree Trunks just made the tastiest apple pie ever!" }
let(:builder) { Email::MessageBuilder.new(to_address, subject: subject, body: body) }
let(:build_args) { builder.build_args }
let(:header_args) { builder.header_args }

View File

@@ -507,10 +507,10 @@ describe Email::Receiver do
SiteSetting.always_show_trimmed_content = true
Fabricate(:user, email: "existing@bar.com", trust_level: SiteSetting.email_in_min_trust)
expect { process(:forwarded_email_to_category) }.to change{Topic.count}.by(1) # Topic created
expect { process(:forwarded_email_to_category) }.to change { Topic.count }.by(1) # Topic created
new_post, = Post.last
expect(new_post.raw).to include("Hi everyone, can you have a look at the email below?","<summary title='Show trimmed content'>&#183;&#183;&#183;</summary>","Discoursing much today?")
expect(new_post.raw).to include("Hi everyone, can you have a look at the email below?", "<summary title='Show trimmed content'>&#183;&#183;&#183;</summary>", "Discoursing much today?")
end
it "works when approving is enabled" do

View File

@@ -24,6 +24,3 @@ describe Email::Renderer do
end
end

View File

@@ -126,7 +126,7 @@ describe Email::Sender do
let(:topic) { Fabricate(:topic) }
let(:post) { Fabricate(:post, topic: topic) }
before do
before do
message.header['X-Discourse-Post-Id'] = post.id
message.header['X-Discourse-Topic-Id'] = topic.id
end
@@ -310,7 +310,6 @@ describe Email::Sender do
end
end
context 'email parts' do
it 'should contain the right message' do
email_sender.send

View File

@@ -132,4 +132,3 @@ describe EmailUpdater do
end
end
end

View File

@@ -31,15 +31,15 @@ describe Enum do
describe ".only" do
it "returns only the values we ask for" do
expect(array_enum.only(:jake, :princess_bubblegum)).to eq({ jake: 1, princess_bubblegum: 3 })
expect(hash_enum.only(:jake, :princess_bubblegum)).to eq({ jake: 1, princess_bubblegum: 3 })
expect(array_enum.only(:jake, :princess_bubblegum)).to eq(jake: 1, princess_bubblegum: 3)
expect(hash_enum.only(:jake, :princess_bubblegum)).to eq(jake: 1, princess_bubblegum: 3)
end
end
describe ".except" do
it "returns everything but the values we ask to delete" do
expect(array_enum.except(:jake, :princess_bubblegum)).to eq({ finn: 2, peppermint_butler: 4 })
expect(hash_enum.except(:jake, :princess_bubblegum)).to eq({ finn: 2, peppermint_butler: 4 })
expect(array_enum.except(:jake, :princess_bubblegum)).to eq(finn: 2, peppermint_butler: 4)
expect(hash_enum.except(:jake, :princess_bubblegum)).to eq(finn: 2, peppermint_butler: 4)
end
end

View File

@@ -30,7 +30,7 @@ describe FileStore::S3Store do
let(:s3_helper) { store.instance_variable_get(:@s3_helper) }
before do
SiteSetting.s3_region ='us-west-1'
SiteSetting.s3_region = 'us-west-1'
end
end

View File

@@ -10,9 +10,9 @@ describe FilterBestPosts do
let(:topic_view) { TopicView.new(topic.id, coding_horror) }
let!(:p1) { Fabricate(:post, topic: topic, user: first_poster, percent_rank: 1 )}
let!(:p2) { Fabricate(:post, topic: topic, user: coding_horror, percent_rank: 0.5 )}
let!(:p3) { Fabricate(:post, topic: topic, user: first_poster, percent_rank: 0 )}
let!(:p1) { Fabricate(:post, topic: topic, user: first_poster, percent_rank: 1) }
let!(:p2) { Fabricate(:post, topic: topic, user: coding_horror, percent_rank: 0.5) }
let!(:p3) { Fabricate(:post, topic: topic, user: first_poster, percent_rank: 0) }
let(:moderator) { Fabricate(:moderator) }
let(:admin) { Fabricate(:admin) }
@@ -46,14 +46,12 @@ describe FilterBestPosts do
expect(best.posts.count).to eq(0)
end
it "should filter out the posts with a score that is too low" do
best = FilterBestPosts.new(topic, @filtered_posts, 99, min_score: 99)
expect(best.posts.count).to eq(0)
end
it "should filter out everything if min replies not met" do
best = FilterBestPosts.new(topic, @filtered_posts, 99, min_replies: 99)
expect(best.posts.count).to eq(0)

View File

@@ -53,7 +53,7 @@ describe FlagQuery do
# chuck post in category a mod can not see and make sure its missing
category = Fabricate(:category)
category.set_permissions(:admins => :full)
category.set_permissions(admins: :full)
category.save
post2.topic.category_id = category.id
post2.topic.save

View File

@@ -15,7 +15,7 @@ describe 'pool drainer' do
pool.checkin conn
end.join
expect(pool.connections.length).to eq(old+1)
expect(pool.connections.length).to eq(old + 1)
pool.drain
expect(pool.connections.length).to eq(old)
end
@@ -25,15 +25,14 @@ describe 'pool drainer' do
old = pool.connections.length
expect(old).to eq(1)
Thread.new do
conn = pool.checkout
pool.checkin conn
end.join
expect(pool.connections.length).to eq(old+1)
expect(pool.connections.length).to eq(old + 1)
pool.drain(1.minute)
expect(pool.connections.length).to eq(old+1)
expect(pool.connections.length).to eq(old + 1)
# make sure we don't corrupt internal state
20.times do

View File

@@ -14,7 +14,7 @@ describe FreedomPatches::SchemaMigrationDetails do
end
it "logs information on migration" do
migration = TestMigration.new("awesome_migration","20160225050318")
migration = TestMigration.new("awesome_migration", "20160225050318")
ActiveRecord::Base.connection_pool.with_connection do |conn|
migration.exec_migration(conn, :up)

View File

@@ -12,11 +12,11 @@ describe Gaps do
end
it 'returns no gaps when all elements are present' do
expect(Gaps.new([1,2,3], [1,2,3])).to be_blank
expect(Gaps.new([1, 2, 3], [1, 2, 3])).to be_blank
end
context "single element gap" do
let(:gap) { Gaps.new([1,3], [1,2,3]) }
let(:gap) { Gaps.new([1, 3], [1, 2, 3]) }
it 'has a gap for post 3' do
expect(gap).not_to be_blank
@@ -26,28 +26,28 @@ describe Gaps do
end
context "larger gap" do
let(:gap) { Gaps.new([1,2,3,6,7], [1,2,3,4,5,6,7]) }
let(:gap) { Gaps.new([1, 2, 3, 6, 7], [1, 2, 3, 4, 5, 6, 7]) }
it 'has a gap for post 6' do
expect(gap).not_to be_blank
expect(gap.before[6]).to eq([4,5])
expect(gap.before[6]).to eq([4, 5])
expect(gap.after).to be_blank
end
end
context "multiple gaps" do
let(:gap) { Gaps.new([1,5,6,7,10], [1,2,3,4,5,6,7,8,9,10]) }
let(:gap) { Gaps.new([1, 5, 6, 7, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) }
it 'has both gaps' do
expect(gap).not_to be_blank
expect(gap.before[5]).to eq([2,3,4])
expect(gap.before[10]).to eq([8,9])
expect(gap.before[5]).to eq([2, 3, 4])
expect(gap.before[10]).to eq([8, 9])
expect(gap.after).to be_blank
end
end
context "a gap in the beginning" do
let(:gap) { Gaps.new([2,3,4], [1,2,3,4]) }
let(:gap) { Gaps.new([2, 3, 4], [1, 2, 3, 4]) }
it 'has the gap' do
expect(gap).not_to be_blank
@@ -57,7 +57,7 @@ describe Gaps do
end
context "a gap in the ending" do
let(:gap) { Gaps.new([1,2,3], [1,2,3,4]) }
let(:gap) { Gaps.new([1, 2, 3], [1, 2, 3, 4]) }
it 'has the gap' do
expect(gap).not_to be_blank
@@ -67,14 +67,13 @@ describe Gaps do
end
context "a large gap in the ending" do
let(:gap) { Gaps.new([1,2,3], [1,2,3,4,5,6]) }
let(:gap) { Gaps.new([1, 2, 3], [1, 2, 3, 4, 5, 6]) }
it 'has the gap' do
expect(gap).not_to be_blank
expect(gap.before).to be_blank
expect(gap.after[3]).to eq([4,5,6])
expect(gap.after[3]).to eq([4, 5, 6])
end
end
end

View File

@@ -57,11 +57,11 @@ describe Guardian do
end
it "returns false when you've already done it" do
expect(Guardian.new(user).post_can_act?(post, :like, taken_actions: {PostActionType.types[:like] => 1})).to be_falsey
expect(Guardian.new(user).post_can_act?(post, :like, taken_actions: { PostActionType.types[:like] => 1 })).to be_falsey
end
it "returns false when you already flagged a post" do
expect(Guardian.new(user).post_can_act?(post, :off_topic, taken_actions: {PostActionType.types[:spam] => 1})).to be_falsey
expect(Guardian.new(user).post_can_act?(post, :off_topic, taken_actions: { PostActionType.types[:spam] => 1 })).to be_falsey
end
it "returns false for notify_user if private messages are disabled" do
@@ -109,7 +109,6 @@ describe Guardian do
end
end
describe "can_defer_flags" do
let(:post) { Fabricate(:post) }
let(:user) { post.user }
@@ -244,7 +243,7 @@ describe Guardian do
describe 'can_see_post_actors?' do
let(:topic) { Fabricate(:topic, user: coding_horror)}
let(:topic) { Fabricate(:topic, user: coding_horror) }
it 'displays visibility correctly' do
guardian = Guardian.new(user)
@@ -419,7 +418,6 @@ describe Guardian do
end
end
describe 'can_invite_via_email?' do
it 'returns true for all (tl2 and above) users when sso is disabled, local logins are enabled, user approval is not required' do
expect(Guardian.new(trust_level_2).can_invite_via_email?(topic)).to be_truthy
@@ -691,34 +689,34 @@ describe Guardian do
describe 'a Topic' do
it 'does not allow moderators to create topics in readonly categories' do
category = Fabricate(:category)
category.set_permissions(:everyone => :read)
category.set_permissions(everyone: :read)
category.save
expect(Guardian.new(moderator).can_create?(Topic,category)).to be_falsey
expect(Guardian.new(moderator).can_create?(Topic, category)).to be_falsey
end
it 'should check for full permissions' do
category = Fabricate(:category)
category.set_permissions(:everyone => :create_post)
category.set_permissions(everyone: :create_post)
category.save
expect(Guardian.new(user).can_create?(Topic,category)).to be_falsey
expect(Guardian.new(user).can_create?(Topic, category)).to be_falsey
end
it "is true for new users by default" do
expect(Guardian.new(user).can_create?(Topic,Fabricate(:category))).to be_truthy
expect(Guardian.new(user).can_create?(Topic, Fabricate(:category))).to be_truthy
end
it "is false if user has not met minimum trust level" do
SiteSetting.min_trust_to_create_topic = 1
expect(Guardian.new(build(:user, trust_level: 0)).can_create?(Topic,Fabricate(:category))).to be_falsey
expect(Guardian.new(build(:user, trust_level: 0)).can_create?(Topic, Fabricate(:category))).to be_falsey
end
it "is true if user has met or exceeded the minimum trust level" do
SiteSetting.min_trust_to_create_topic = 1
expect(Guardian.new(build(:user, trust_level: 1)).can_create?(Topic,Fabricate(:category))).to be_truthy
expect(Guardian.new(build(:user, trust_level: 2)).can_create?(Topic,Fabricate(:category))).to be_truthy
expect(Guardian.new(build(:admin, trust_level: 0)).can_create?(Topic,Fabricate(:category))).to be_truthy
expect(Guardian.new(build(:moderator, trust_level: 0)).can_create?(Topic,Fabricate(:category))).to be_truthy
expect(Guardian.new(build(:user, trust_level: 1)).can_create?(Topic, Fabricate(:category))).to be_truthy
expect(Guardian.new(build(:user, trust_level: 2)).can_create?(Topic, Fabricate(:category))).to be_truthy
expect(Guardian.new(build(:admin, trust_level: 0)).can_create?(Topic, Fabricate(:category))).to be_truthy
expect(Guardian.new(build(:moderator, trust_level: 0)).can_create?(Topic, Fabricate(:category))).to be_truthy
end
end
@@ -727,7 +725,7 @@ describe Guardian do
it "is false on readonly categories" do
category = Fabricate(:category)
topic.category = category
category.set_permissions(:everyone => :readonly)
category.set_permissions(everyone: :readonly)
category.save
expect(Guardian.new(topic.user).can_create?(Post, topic)).to be_falsey
@@ -856,29 +854,27 @@ describe Guardian do
Guardian.new(user)
end
it "isn't allowed when not logged in" do
expect(Guardian.new(nil).post_can_act?(post,:vote)).to be_falsey
expect(Guardian.new(nil).post_can_act?(post, :vote)).to be_falsey
end
it "is allowed as a regular user" do
expect(guardian.post_can_act?(post,:vote)).to be_truthy
expect(guardian.post_can_act?(post, :vote)).to be_truthy
end
it "doesn't allow voting if the user has an action from voting already" do
expect(guardian.post_can_act?(post,:vote,taken_actions: {PostActionType.types[:vote] => 1})).to be_falsey
expect(guardian.post_can_act?(post, :vote, taken_actions: { PostActionType.types[:vote] => 1 })).to be_falsey
end
it "allows voting if the user has performed a different action" do
expect(guardian.post_can_act?(post,:vote,taken_actions: {PostActionType.types[:like] => 1})).to be_truthy
expect(guardian.post_can_act?(post, :vote, taken_actions: { PostActionType.types[:like] => 1 })).to be_truthy
end
it "isn't allowed on archived topics" do
topic.archived = true
expect(Guardian.new(user).post_can_act?(post,:like)).to be_falsey
expect(Guardian.new(user).post_can_act?(post, :like)).to be_falsey
end
describe 'multiple voting' do
it "isn't allowed if the user voted and the topic doesn't allow multiple votes" do
@@ -1080,7 +1076,7 @@ describe Guardian do
it "returns false if a wiki but the user can't create a post" do
c = Fabricate(:category)
c.set_permissions(:everyone => :readonly)
c.set_permissions(everyone: :readonly)
c.save
topic = Fabricate(:topic, category: c)
@@ -1665,7 +1661,6 @@ describe Guardian do
expect(Guardian.new(moderator).can_approve?(user)).to be_truthy
end
end
context 'can_grant_admin?' do
@@ -2039,7 +2034,6 @@ describe Guardian do
end
end
describe 'can_change_trust_level?' do
it 'is false without a logged in user' do

View File

@@ -13,7 +13,6 @@ describe HighlightJs do
expect(bundle).not_to match(/applescript/)
end
it 'can get a version string' do
version1 = HighlightJs.version("http|cpp")
version2 = HighlightJs.version("rust|cpp|fake")

View File

@@ -20,7 +20,7 @@ HTML
it "Can handle aside" do
source = <<~HTML
source = <<~HTML
<aside class="quote" data-topic="2" data-post="1">
<div class="title">
<div class="quote-controls"></div>

View File

@@ -3,7 +3,7 @@ require 'html_to_markdown'
describe HtmlToMarkdown do
def html_to_markdown(html, opts={})
def html_to_markdown(html, opts = {})
HtmlToMarkdown.new(html, opts).to_markdown
end

View File

@@ -18,4 +18,3 @@ MD
end
end
end

View File

@@ -83,6 +83,4 @@ describe InlineOneboxer do
end
end

View File

@@ -77,14 +77,13 @@ describe JsLocaleHelper do
end
it 'can strip out message formats' do
hash = {"a" => "b", "c" => { "d" => {"f_MF" => "bob"} }}
expect(JsLocaleHelper.strip_out_message_formats!(hash)).to eq({"c.d.f_MF" => "bob"})
hash = { "a" => "b", "c" => { "d" => { "f_MF" => "bob" } } }
expect(JsLocaleHelper.strip_out_message_formats!(hash)).to eq("c.d.f_MF" => "bob")
expect(hash["c"]["d"]).to eq({})
end
it 'handles message format special keys' do
JsLocaleHelper.set_translations('en', {
"en" => {
JsLocaleHelper.set_translations('en', "en" => {
"js" => {
"hello" => "world",
"test_MF" => "{HELLO} {COUNT, plural, one {1 duck} other {# ducks}}",
@@ -94,8 +93,7 @@ describe JsLocaleHelper do
"admin_js" => {
"foo_MF" => "{HELLO} {COUNT, plural, one {1 duck} other {# ducks}}"
}
}
})
})
ctx = MiniRacer::Context.new
ctx.eval("I18n = { pluralizationRules: {} };")
@@ -118,38 +116,32 @@ describe JsLocaleHelper do
end
it 'performs fallbacks to english if a translation is not available' do
JsLocaleHelper.set_translations('en', {
"en" => {
JsLocaleHelper.set_translations('en', "en" => {
"js" => {
"only_english" => "1-en",
"english_and_site" => "3-en",
"english_and_user" => "5-en",
"all_three" => "7-en",
}
}
})
})
JsLocaleHelper.set_translations('ru', {
"ru" => {
JsLocaleHelper.set_translations('ru', "ru" => {
"js" => {
"only_site" => "2-ru",
"english_and_site" => "3-ru",
"site_and_user" => "6-ru",
"all_three" => "7-ru",
}
}
})
})
JsLocaleHelper.set_translations('uk', {
"uk" => {
JsLocaleHelper.set_translations('uk', "uk" => {
"js" => {
"only_user" => "4-uk",
"english_and_user" => "5-uk",
"site_and_user" => "6-uk",
"all_three" => "7-uk",
}
}
})
})
expected = {
"none" => "[uk.js.none]",

View File

@@ -37,7 +37,7 @@ describe JsonError do
describe "with a string" do
it "returns the string in the error format" do
expect(creator.create_errors_json("test error")).to eq({errors: ["test error"]})
expect(creator.create_errors_json("test error")).to eq(errors: ["test error"])
end
end
@@ -52,4 +52,3 @@ describe JsonError do
end
end

View File

@@ -3,7 +3,7 @@ require_dependency "middleware/anonymous_cache"
describe Middleware::AnonymousCache::Helper do
def env(opts={})
def env(opts = {})
{
"HTTP_HOST" => "http://test.com",
"REQUEST_URI" => "/path?bla=1",
@@ -12,11 +12,10 @@ describe Middleware::AnonymousCache::Helper do
}.merge(opts)
end
def new_helper(opts={})
def new_helper(opts = {})
Middleware::AnonymousCache::Helper.new(env(opts))
end
context "cachable?" do
it "true by default" do
expect(new_helper.cacheable?).to eq(true)
@@ -27,7 +26,7 @@ describe Middleware::AnonymousCache::Helper do
end
it "is false if it has an auth cookie" do
expect(new_helper("HTTP_COOKIE" => "jack=1; _t=#{"1"*32}; jill=2").cacheable?).to eq(false)
expect(new_helper("HTTP_COOKIE" => "jack=1; _t=#{"1" * 32}; jill=2").cacheable?).to eq(false)
end
end
@@ -61,10 +60,10 @@ describe Middleware::AnonymousCache::Helper do
end
it "handles brotli switching" do
helper.cache([200, {"HELLO" => "WORLD"}, ["hello ", "my world"]])
helper.cache([200, { "HELLO" => "WORLD" }, ["hello ", "my world"]])
helper = new_helper("ANON_CACHE_DURATION" => 10)
expect(helper.cached).to eq([200, {"X-Discourse-Cached" => "true", "HELLO" => "WORLD"}, ["hello my world"]])
expect(helper.cached).to eq([200, { "X-Discourse-Cached" => "true", "HELLO" => "WORLD" }, ["hello my world"]])
helper = new_helper("ANON_CACHE_DURATION" => 10, "HTTP_ACCEPT_ENCODING" => "gz, br")
expect(helper.cached).to eq(nil)
@@ -73,17 +72,16 @@ describe Middleware::AnonymousCache::Helper do
it "returns cached data for cached requests" do
helper.is_mobile = true
expect(helper.cached).to eq(nil)
helper.cache([200, {"HELLO" => "WORLD"}, ["hello ", "my world"]])
helper.cache([200, { "HELLO" => "WORLD" }, ["hello ", "my world"]])
helper = new_helper("ANON_CACHE_DURATION" => 10)
helper.is_mobile = true
expect(helper.cached).to eq([200, {"X-Discourse-Cached" => "true", "HELLO" => "WORLD"}, ["hello my world"]])
expect(helper.cached).to eq([200, { "X-Discourse-Cached" => "true", "HELLO" => "WORLD" }, ["hello my world"]])
expect(crawler.cached).to eq(nil)
crawler.cache([200, {"HELLO" => "WORLD"}, ["hello ", "world"]])
expect(crawler.cached).to eq([200, {"X-Discourse-Cached" => "true", "HELLO" => "WORLD"}, ["hello world"]])
crawler.cache([200, { "HELLO" => "WORLD" }, ["hello ", "world"]])
expect(crawler.cached).to eq([200, { "X-Discourse-Cached" => "true", "HELLO" => "WORLD" }, ["hello world"]])
end
end
end

View File

@@ -3,7 +3,7 @@ require_dependency "middleware/request_tracker"
describe Middleware::RequestTracker do
def env(opts={})
def env(opts = {})
{
"HTTP_HOST" => "http://test.com",
"REQUEST_URI" => "/path?bla=1",
@@ -21,7 +21,7 @@ describe Middleware::RequestTracker do
def log_tracked_view(val)
data = Middleware::RequestTracker.get_data(env(
"HTTP_DISCOURSE_TRACK_VIEW" => val
), ["200",{"Content-Type" => 'text/html'}])
), ["200", { "Content-Type" => 'text/html' }])
Middleware::RequestTracker.log_request(data)
end
@@ -40,19 +40,19 @@ describe Middleware::RequestTracker do
data = Middleware::RequestTracker.get_data(env(
"HTTP_USER_AGENT" => "AdsBot-Google (+http://www.google.com/adsbot.html)"
), ["200",{"Content-Type" => 'text/html'}])
), ["200", { "Content-Type" => 'text/html' }])
Middleware::RequestTracker.log_request(data)
data = Middleware::RequestTracker.get_data(env(
"HTTP_DISCOURSE_TRACK_VIEW" => "1"
), ["200",{}])
), ["200", {}])
Middleware::RequestTracker.log_request(data)
data = Middleware::RequestTracker.get_data(env(
"HTTP_USER_AGENT" => "Mozilla/5.0 (iPhone; CPU iPhone OS 8_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B410 Safari/600.1.4"
), ["200",{"Content-Type" => 'text/html'}])
), ["200", { "Content-Type" => 'text/html' }])
Middleware::RequestTracker.log_request(data)

View File

@@ -151,16 +151,16 @@ describe NewPostManager do
let(:default_handler) { NewPostManager.method(:default_handler) }
it "adds in order by default" do
handler = ->{ nil }
handler = -> { nil }
NewPostManager.add_handler(&handler)
expect(NewPostManager.handlers).to eq([default_handler, handler])
end
it "can be added in high priority" do
a = ->{ nil }
b = ->{ nil }
c = ->{ nil }
a = -> { nil }
b = -> { nil }
c = -> { nil }
NewPostManager.add_handler(100, &a)
NewPostManager.add_handler(50, &b)
@@ -241,7 +241,6 @@ describe NewPostManager do
end
context "user needs approval?" do
let :user do
@@ -251,11 +250,9 @@ describe NewPostManager do
user
end
it "handles post_needs_approval? correctly" do
u = user
default = NewPostManager.new(u,{})
default = NewPostManager.new(u, {})
expect(NewPostManager.post_needs_approval?(default)).to eq(false)
with_check = NewPostManager.new(u, first_post_checks: true)

View File

@@ -30,7 +30,7 @@ describe Onebox::Engine::DiscourseLocalOnebox do
end
it "returns some onebox goodness if post exists and can be seen" do
url = "#{Discourse.base_url}#{post2.url}?source_topic_id=#{post2.topic_id+1}"
url = "#{Discourse.base_url}#{post2.url}?source_topic_id=#{post2.topic_id + 1}"
html = Onebox.preview(url).to_s
expect(html).to include(post2.excerpt)
expect(html).to include(post2.topic.title)
@@ -108,7 +108,7 @@ describe Onebox::Engine::DiscourseLocalOnebox do
let(:post2) { Fabricate(:post, topic: post.topic, post_number: 2) }
it "returns some onebox goodness if post exists and can be seen" do
url = "#{Discourse.base_url}#{post2.url}?source_topic_id=#{post2.topic_id+1}"
url = "#{Discourse.base_url}#{post2.url}?source_topic_id=#{post2.topic_id + 1}"
html = Onebox.preview(url).to_s
expect(html).to include(post2.excerpt)
expect(html).to include(post2.topic.title)

View File

@@ -32,4 +32,3 @@ describe ONPDiff do
end
end

View File

@@ -1,8 +1,8 @@
require 'pbkdf2'
describe Pbkdf2 do
# trivial test to ensure this does not regress during extraction
it "hashes stuff correctly" do
# trivial test to ensure this does not regress during extraction
it "hashes stuff correctly" do
expect(Pbkdf2.hash_password('test', 'abcd', 100)).to eq("0313a6aca54dd4c5d82a699a8a0f0ffb0191b4ef62414b8d9dbc11c0c5ac04da")
expect(Pbkdf2.hash_password('test', 'abcd', 101)).to eq("c7a7b2891bf8e6f82d08cf8d83824edcf6c7c6bacb6a741f38e21fc7977bd20f")
end

View File

@@ -50,8 +50,6 @@ describe PinnedCheck do
end
end
end
end

View File

@@ -2,14 +2,14 @@ require 'rails_helper'
require_dependency 'plugin/filter_manager'
describe Plugin::FilterManager do
let(:instance){ Plugin::FilterManager.new }
let(:instance) { Plugin::FilterManager.new }
it "calls registered filters correctly" do
instance.register(:added_numbers) do |context,result|
instance.register(:added_numbers) do |context, result|
context + result + 1
end
instance.register(:added_numbers) do |context,result|
instance.register(:added_numbers) do |context, result|
context + result + 2
end

View File

@@ -102,7 +102,7 @@ describe Plugin::Instance do
junk_file = "#{plugin.auto_generated_path}/junk"
plugin.ensure_directory(junk_file)
File.open("#{plugin.auto_generated_path}/junk", "w") {|f| f.write("junk")}
File.open("#{plugin.auto_generated_path}/junk", "w") { |f| f.write("junk") }
plugin.activate!
expect(plugin.auth_providers.count).to eq(1)
@@ -185,7 +185,7 @@ describe Plugin::Instance do
it "can add a color scheme for the first time" do
plugin = Plugin::Instance.new nil, "/tmp/test.rb"
expect {
plugin.register_color_scheme("Purple", {primary: 'EEE0E5'})
plugin.register_color_scheme("Purple", primary: 'EEE0E5')
plugin.notify_after_initialize
}.to change { ColorScheme.count }.by(1)
expect(ColorScheme.where(name: "Purple")).to be_present
@@ -195,7 +195,7 @@ describe Plugin::Instance do
Fabricate(:color_scheme, name: "Halloween")
plugin = Plugin::Instance.new nil, "/tmp/test.rb"
expect {
plugin.register_color_scheme("Halloween", {primary: 'EEE0E5'})
plugin.register_color_scheme("Halloween", primary: 'EEE0E5')
plugin.notify_after_initialize
}.to_not change { ColorScheme.count }
end

View File

@@ -6,7 +6,6 @@ describe PostActionCreator do
let(:post) { Fabricate(:post) }
let(:like_type_id) { PostActionType.types[:like] }
describe 'perform' do
it 'creates a post action' do
expect { PostActionCreator.new(user, post).perform(like_type_id) }.to change { PostAction.count }.by(1)

View File

@@ -9,12 +9,12 @@ describe PostCreator do
context "new topic" do
let(:category) { Fabricate(:category, user: user) }
let(:basic_topic_params) { {title: "hello world topic", raw: "my name is fred", archetype_id: 1} }
let(:image_sizes) { {'http://an.image.host/image.jpg' => {"width" => 111, "height" => 222}} }
let(:basic_topic_params) { { title: "hello world topic", raw: "my name is fred", archetype_id: 1 } }
let(:image_sizes) { { 'http://an.image.host/image.jpg' => { "width" => 111, "height" => 222 } } }
let(:creator) { PostCreator.new(user, basic_topic_params) }
let(:creator_with_category) { PostCreator.new(user, basic_topic_params.merge(category: category.id )) }
let(:creator_with_meta_data) { PostCreator.new(user, basic_topic_params.merge(meta_data: {hello: "world"} )) }
let(:creator_with_category) { PostCreator.new(user, basic_topic_params.merge(category: category.id)) }
let(:creator_with_meta_data) { PostCreator.new(user, basic_topic_params.merge(meta_data: { hello: "world" })) }
let(:creator_with_image_sizes) { PostCreator.new(user, basic_topic_params.merge(image_sizes: image_sizes)) }
let(:creator_with_featured_link) { PostCreator.new(user, title: "featured link topic", archetype_id: 1, featured_link: "http://www.discourse.org", raw: "http://www.discourse.org") }
@@ -34,12 +34,12 @@ describe PostCreator do
cat = Fabricate(:category)
cat.all_topics_wiki = true
cat.save
post = PostCreator.create(user, basic_topic_params.merge(category: cat.id ))
post = PostCreator.create(user, basic_topic_params.merge(category: cat.id))
expect(post.wiki).to eq(true)
end
it "ensures the user can create the topic" do
Guardian.any_instance.expects(:can_create?).with(Topic,nil).returns(false)
Guardian.any_instance.expects(:can_create?).with(Topic, nil).returns(false)
expect { creator.create }.to raise_error(Discourse::InvalidAccess)
end
@@ -100,8 +100,8 @@ describe PostCreator do
end
# don't notify on system messages they introduce too much noise
channels = messages.map(&:channel)
expect(channels.find{|s| s =~ /unread/}).to eq(nil)
expect(channels.find{|s| s =~ /new/}).to eq(nil)
expect(channels.find { |s| s =~ /unread/ }).to eq(nil)
expect(channels.find { |s| s =~ /new/ }).to eq(nil)
end
it "generates the correct messages for a secure topic" do
@@ -111,7 +111,7 @@ describe PostCreator do
admin = Fabricate(:admin)
cat = Fabricate(:category)
cat.set_permissions(:admins => :full)
cat.set_permissions(admins: :full)
cat.save
created_post = nil
@@ -122,9 +122,8 @@ describe PostCreator do
reply = PostCreator.new(admin, raw: "this is my test reply 123 testing", topic_id: created_post.topic_id).create
end
# 2 for topic, one to notify of new topic another for tracking state
expect(messages.map{|m| m.channel}.sort).to eq([ "/new",
expect(messages.map { |m| m.channel }.sort).to eq([ "/new",
"/u/#{admin.username}",
"/u/#{admin.username}",
"/unread/#{admin.id}",
@@ -136,7 +135,7 @@ describe PostCreator do
].sort)
admin_ids = [Group[:admins].id]
expect(messages.any?{|m| m.group_ids != admin_ids && m.user_ids != [admin.id]}).to eq(false)
expect(messages.any? { |m| m.group_ids != admin_ids && m.user_ids != [admin.id] }).to eq(false)
end
it 'generates the correct messages for a normal topic' do
@@ -148,16 +147,16 @@ describe PostCreator do
p = creator.create
end
latest = messages.find{|m| m.channel == "/latest"}
latest = messages.find { |m| m.channel == "/latest" }
expect(latest).not_to eq(nil)
latest = messages.find{|m| m.channel == "/new"}
latest = messages.find { |m| m.channel == "/new" }
expect(latest).not_to eq(nil)
read = messages.find{|m| m.channel == "/unread/#{p.user_id}"}
read = messages.find { |m| m.channel == "/unread/#{p.user_id}" }
expect(read).not_to eq(nil)
user_action = messages.find{|m| m.channel == "/u/#{p.user.username}"}
user_action = messages.find { |m| m.channel == "/u/#{p.user.username}" }
expect(user_action).not_to eq(nil)
expect(messages.length).to eq(5)
@@ -191,7 +190,7 @@ describe PostCreator do
Jobs.expects(:enqueue).with(:notify_mailing_list_subscribers, has_key(:post_id))
Jobs.expects(:enqueue).with(:post_alert, has_key(:post_id))
Jobs.expects(:enqueue).with(:process_post, has_key(:image_sizes))
creator.opts[:image_sizes] = {'http://an.image.host/image.jpg' => {'width' => 17, 'height' => 31}}
creator.opts[:image_sizes] = { 'http://an.image.host/image.jpg' => { 'width' => 17, 'height' => 31 } }
creator.create
end
@@ -344,14 +343,14 @@ describe PostCreator do
end
it "can create all tags if none exist" do
expect { @post = creator_with_tags.create }.to change { Tag.count }.by( tag_names.size )
expect { @post = creator_with_tags.create }.to change { Tag.count }.by(tag_names.size)
expect(@post.topic.tags.map(&:name).sort).to eq(tag_names.sort)
end
it "creates missing tags if some exist" do
existing_tag1 = Fabricate(:tag, name: tag_names[0])
existing_tag1 = Fabricate(:tag, name: tag_names[1])
expect { @post = creator_with_tags.create }.to change { Tag.count }.by( tag_names.size - 2 )
expect { @post = creator_with_tags.create }.to change { Tag.count }.by(tag_names.size - 2)
expect(@post.topic.tags.map(&:name).sort).to eq(tag_names.sort)
end
end
@@ -400,7 +399,6 @@ describe PostCreator do
expect(whisper).to be_present
expect(whisper.post_type).to eq(Post.types[:whisper])
whisper_reply = PostCreator.new(user,
topic_id: topic.id,
reply_to_post_number: whisper.post_number,
@@ -413,7 +411,6 @@ describe PostCreator do
# date is not precise enough in db
whisper_reply.reload
first.reload
# does not leak into the OP
expect(first.reply_count).to eq(0)
@@ -426,8 +423,8 @@ describe PostCreator do
expect(topic.posts_count).to eq(1)
expect(topic.highest_staff_post_number).to eq(3)
topic.update_columns(highest_staff_post_number:0,
highest_post_number:0,
topic.update_columns(highest_staff_post_number: 0,
highest_post_number: 0,
posts_count: 0,
last_posted_at: 1.year.ago)
@@ -444,7 +441,7 @@ describe PostCreator do
context 'uniqueness' do
let!(:topic) { Fabricate(:topic, user: user) }
let(:basic_topic_params) { { raw: 'test reply', topic_id: topic.id, reply_to_post_number: 4} }
let(:basic_topic_params) { { raw: 'test reply', topic_id: topic.id, reply_to_post_number: 4 } }
let(:creator) { PostCreator.new(user, basic_topic_params) }
context "disabled" do
@@ -502,11 +499,10 @@ describe PostCreator do
end
context "host spam" do
let!(:topic) { Fabricate(:topic, user: user) }
let(:basic_topic_params) { { raw: 'test reply', topic_id: topic.id, reply_to_post_number: 4} }
let(:basic_topic_params) { { raw: 'test reply', topic_id: topic.id, reply_to_post_number: 4 } }
let(:creator) { PostCreator.new(user, basic_topic_params) }
before do
@@ -523,7 +519,7 @@ describe PostCreator do
it "sends a message to moderators" do
GroupMessage.expects(:create).with do |group_name, msg_type, params|
group_name == Group[:moderators].name and msg_type == :spam_post_blocked and params[:user].id == user.id
group_name == (Group[:moderators].name) && msg_type == (:spam_post_blocked) && params[:user].id == (user.id)
end
creator.create
end
@@ -631,7 +627,7 @@ describe PostCreator do
# if an admin replies they should be added to the allowed user list
admin = Fabricate(:admin)
PostCreator.create(admin, raw: 'hi there welcome topic, I am a mod',
topic_id: post.topic_id)
topic_id: post.topic_id)
post.topic.reload
expect(post.topic.topic_allowed_users.where(user_id: admin.id).count).to eq(1)
@@ -817,11 +813,11 @@ describe PostCreator do
it "should give credit to creator" do
post = create_post
expect(PostTiming.find_by(topic_id: post.topic_id,
post_number: post.post_number,
user_id: post.user_id).msecs).to be > 0
post_number: post.post_number,
user_id: post.user_id).msecs).to be > 0
expect(TopicUser.find_by(topic_id: post.topic_id,
user_id: post.user_id).last_read_post_number).to eq(1)
user_id: post.user_id).last_read_post_number).to eq(1)
end
end
@@ -829,14 +825,14 @@ describe PostCreator do
it "does not allow suspended users to create topics" do
user = Fabricate(:user, suspended_at: 1.month.ago, suspended_till: 1.month.from_now)
creator = PostCreator.new(user, {title: "my test title 123", raw: "I should not be allowed to post"} )
creator = PostCreator.new(user, title: "my test title 123", raw: "I should not be allowed to post")
creator.create
expect(creator.errors.count).to be > 0
end
end
it "doesn't strip starting whitespaces" do
pc = PostCreator.new(user, { title: "testing whitespace stripping", raw: " <-- whitespaces --> " })
pc = PostCreator.new(user, title: "testing whitespace stripping", raw: " <-- whitespaces --> ")
post = pc.create
expect(post.raw).to eq(" <-- whitespaces -->")
end

View File

@@ -213,7 +213,7 @@ describe PostDestroyer do
expect(post2.deleted_at).to be_blank
expect(post2.deleted_by).to be_blank
expect(post2.user_deleted).to eq(true)
expect(post2.raw).to eq(I18n.t('js.post.deleted_by_author', {count: 24}))
expect(post2.raw).to eq(I18n.t('js.post.deleted_by_author', count: 24))
expect(post2.version).to eq(2)
expect(called).to eq(1)
@@ -360,7 +360,7 @@ describe PostDestroyer do
it "creates a new user history entry" do
expect {
PostDestroyer.new(admin, post).destroy
}.to change { UserHistory.count}.by(1)
}.to change { UserHistory.count }.by(1)
end
end
end
@@ -441,13 +441,11 @@ describe PostDestroyer do
let(:second_post) { Fabricate(:post, topic_id: post.topic_id) }
def create_user_action(action_type)
UserAction.log_action!({
action_type: action_type,
user_id: codinghorror.id,
acting_user_id: codinghorror.id,
target_topic_id: second_post.topic_id,
target_post_id: second_post.id
})
UserAction.log_action!(action_type: action_type,
user_id: codinghorror.id,
acting_user_id: codinghorror.id,
target_topic_id: second_post.topic_id,
target_post_id: second_post.id)
end
it "should delete the user actions" do

View File

@@ -40,14 +40,14 @@ describe PostMerger do
reply1 = create_post(topic: topic, post_number: post.post_number, user: user)
reply2 = create_post(topic: topic, post_number: post.post_number, user: user)
expect{ PostMerger.new(admin, [reply2, post, reply1]).merge }.to raise_error(Discourse::InvalidAccess)
expect { PostMerger.new(admin, [reply2, post, reply1]).merge }.to raise_error(Discourse::InvalidAccess)
end
it "should only allow staff user to merge posts" do
reply1 = create_post(topic: topic, post_number: post.post_number, user: user)
reply2 = create_post(topic: topic, post_number: post.post_number, user: user)
expect{ PostMerger.new(user, [reply2, reply1]).merge }.to raise_error(Discourse::InvalidAccess)
expect { PostMerger.new(user, [reply2, reply1]).merge }.to raise_error(Discourse::InvalidAccess)
end
it "should not allow posts from different topics to be merged" do
@@ -67,4 +67,3 @@ describe PostMerger do
end
end
end

View File

@@ -65,7 +65,7 @@ describe PostRevisor do
describe 'with the same body' do
it "doesn't change version" do
expect {
expect(subject.revise!(post.user, { raw: post.raw })).to eq(false)
expect(subject.revise!(post.user, raw: post.raw)).to eq(false)
post.reload
}.not_to change(post, :version)
end
@@ -150,7 +150,7 @@ describe PostRevisor do
context "after second window" do
let!(:new_revised_at) {revised_at + 2.minutes}
let!(:new_revised_at) { revised_at + 2.minutes }
before do
subject.revise!(post.user, { raw: 'yet another, another updated body' }, revised_at: new_revised_at)
@@ -185,7 +185,7 @@ describe PostRevisor do
context "one paragraph description" do
before do
subject.revise!(post.user, { raw: new_description })
subject.revise!(post.user, raw: new_description)
category.reload
end
@@ -200,7 +200,7 @@ describe PostRevisor do
context "multiple paragraph description" do
before do
subject.revise!(post.user, { raw: "#{new_description}\n\nOther content goes here." })
subject.revise!(post.user, raw: "#{new_description}\n\nOther content goes here.")
category.reload
end
@@ -215,7 +215,7 @@ describe PostRevisor do
context "invalid description without paragraphs" do
before do
subject.revise!(post.user, { raw: "# This is a title" })
subject.revise!(post.user, raw: "# This is a title")
category.reload
end
@@ -232,7 +232,7 @@ describe PostRevisor do
context 'when updating back to the original paragraph' do
before do
category.update_column(:description, 'this is my description')
subject.revise!(post.user, { raw: Category.post_template })
subject.revise!(post.user, raw: Category.post_template)
category.reload
end
@@ -252,7 +252,7 @@ describe PostRevisor do
it "triggers a rate limiter" do
EditRateLimiter.any_instance.expects(:performed!)
subject.revise!(changed_by, { raw: 'updated body' })
subject.revise!(changed_by, raw: 'updated body')
end
end
@@ -263,7 +263,7 @@ describe PostRevisor do
SiteSetting.newuser_max_images = 0
url = "http://i.imgur.com/wfn7rgU.jpg"
Oneboxer.stubs(:onebox).with(url, anything).returns("<img src='#{url}'>")
subject.revise!(changed_by, { raw: "So, post them here!\n#{url}" })
subject.revise!(changed_by, raw: "So, post them here!\n#{url}")
end
it "allows an admin to insert images into a new user's post" do
@@ -281,7 +281,7 @@ describe PostRevisor do
SiteSetting.newuser_max_images = 0
url = "http://i.imgur.com/FGg7Vzu.gif"
Oneboxer.stubs(:cached_onebox).with(url, anything).returns("<img src='#{url}'>")
subject.revise!(post.user, { raw: "So, post them here!\n#{url}" })
subject.revise!(post.user, raw: "So, post them here!\n#{url}")
end
it "doesn't allow images to be inserted" do
@@ -290,10 +290,9 @@ describe PostRevisor do
end
describe 'with a new body' do
let(:changed_by) { Fabricate(:coding_horror) }
let!(:result) { subject.revise!(changed_by, { raw: "lets update the body. Здравствуйте" }) }
let!(:result) { subject.revise!(changed_by, raw: "lets update the body. Здравствуйте") }
it 'returns true' do
expect(result).to eq(true)
@@ -343,7 +342,7 @@ describe PostRevisor do
context 'passing skip_revision as true' do
before do
SiteSetting.editing_grace_period = 1.minute
subject.revise!(changed_by, { raw: 'yet another updated body' }, { revised_at: post.updated_at + 10.hours, skip_revision: true })
subject.revise!(changed_by, { raw: 'yet another updated body' }, revised_at: post.updated_at + 10.hours, skip_revision: true)
post.reload
end
@@ -365,14 +364,14 @@ 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' })
described_class.new(second_post).revise!(second_post.user, raw: 'Edit the 2nd post')
topic.reload
}.to_not change { topic.excerpt }
end
end
it "doesn't strip starting whitespaces" do
subject.revise!(post.user, { raw: " <-- whitespaces --> " })
subject.revise!(post.user, raw: " <-- whitespaces --> ")
post.reload
expect(post.raw).to eq(" <-- whitespaces -->")
end
@@ -384,7 +383,7 @@ describe PostRevisor do
revisor = described_class.new(topic.ordered_posts.first, topic)
messages = MessageBus.track_publish do
revisor.revise!(newuser, { title: 'this is a test topic' })
revisor.revise!(newuser, title: 'this is a test topic')
end
message = messages.find { |m| m.channel == "/topic/#{topic.id}" }
@@ -400,7 +399,7 @@ describe PostRevisor do
end
it "doesn't add the tags" do
result = subject.revise!(Fabricate(:user), { raw: "lets totally update the body", tags: ['totally', 'update'] })
result = subject.revise!(Fabricate(:user), raw: "lets totally update the body", tags: ['totally', 'update'])
expect(result).to eq(true)
post.reload
expect(post.topic.tags.size).to eq(0)
@@ -420,7 +419,7 @@ describe PostRevisor do
it "can create all tags if none exist" do
expect {
@result = subject.revise!(Fabricate(:user), { raw: "lets totally update the body", tags: ['totally', 'update'] })
@result = subject.revise!(Fabricate(:user), raw: "lets totally update the body", tags: ['totally', 'update'])
}.to change { Tag.count }.by(2)
expect(@result).to eq(true)
post.reload
@@ -430,7 +429,7 @@ describe PostRevisor do
it "creates missing tags if some exist" do
Fabricate(:tag, name: 'totally')
expect {
@result = subject.revise!(Fabricate(:user), { raw: "lets totally update the body", tags: ['totally', 'update'] })
@result = subject.revise!(Fabricate(:user), raw: "lets totally update the body", tags: ['totally', 'update'])
}.to change { Tag.count }.by(1)
expect(@result).to eq(true)
post.reload
@@ -439,7 +438,7 @@ describe PostRevisor do
it "can remove all tags" do
topic.tags = [Fabricate(:tag, name: "super"), Fabricate(:tag, name: "stuff")]
result = subject.revise!(Fabricate(:user), { raw: "lets totally update the body", tags: [] })
result = subject.revise!(Fabricate(:user), raw: "lets totally update the body", tags: [])
expect(result).to eq(true)
post.reload
expect(post.topic.tags.size).to eq(0)
@@ -447,7 +446,7 @@ describe PostRevisor do
it "can remove all tags using tags_empty_array" do
topic.tags = [Fabricate(:tag, name: "stuff")]
result = subject.revise!(Fabricate(:user), { raw: "lets totally update the body", tags_empty_array: "true" })
result = subject.revise!(Fabricate(:user), raw: "lets totally update the body", tags_empty_array: "true")
expect(result).to eq(true)
post.reload
expect(post.topic.tags.size).to eq(0)
@@ -455,14 +454,14 @@ describe PostRevisor do
it "can't add staff-only tags" do
SiteSetting.staff_tags = "important"
result = subject.revise!(Fabricate(:user), { raw: "lets totally update the body", tags: ['important', 'stuff'] })
result = subject.revise!(Fabricate(:user), raw: "lets totally update the body", tags: ['important', 'stuff'])
expect(result).to eq(false)
expect(post.topic.errors.present?).to eq(true)
end
it "staff can add staff-only tags" do
SiteSetting.staff_tags = "important"
result = subject.revise!(Fabricate(:admin), { raw: "lets totally update the body", tags: ['important', 'stuff'] })
result = subject.revise!(Fabricate(:admin), raw: "lets totally update the body", tags: ['important', 'stuff'])
expect(result).to eq(true)
post.reload
expect(post.topic.tags.map(&:name).sort).to eq(['important', 'stuff'])
@@ -476,7 +475,7 @@ describe PostRevisor do
end
it "staff-only tags can't be removed" do
result = subject.revise!(Fabricate(:user), { raw: "lets totally update the body", tags: ['stuff'] })
result = subject.revise!(Fabricate(:user), raw: "lets totally update the body", tags: ['stuff'])
expect(result).to eq(false)
expect(post.topic.errors.present?).to eq(true)
post.reload
@@ -484,7 +483,7 @@ describe PostRevisor do
end
it "can't remove all tags if some are staff-only" do
result = subject.revise!(Fabricate(:user), { raw: "lets totally update the body", tags: [] })
result = subject.revise!(Fabricate(:user), raw: "lets totally update the body", tags: [])
expect(result).to eq(false)
expect(post.topic.errors.present?).to eq(true)
post.reload
@@ -492,14 +491,14 @@ describe PostRevisor do
end
it "staff-only tags can be removed by staff" do
result = subject.revise!(Fabricate(:admin), { raw: "lets totally update the body", tags: ['stuff'] })
result = subject.revise!(Fabricate(:admin), raw: "lets totally update the body", tags: ['stuff'])
expect(result).to eq(true)
post.reload
expect(post.topic.tags.map(&:name)).to eq(['stuff'])
end
it "staff can remove all tags" do
result = subject.revise!(Fabricate(:admin), { raw: "lets totally update the body", tags: [] })
result = subject.revise!(Fabricate(:admin), raw: "lets totally update the body", tags: [])
expect(result).to eq(true)
post.reload
expect(post.topic.tags.size).to eq(0)
@@ -517,7 +516,7 @@ describe PostRevisor do
it "only uses existing tags" do
Fabricate(:tag, name: 'totally')
expect {
@result = subject.revise!(Fabricate(:user), { raw: "lets totally update the body", tags: ['totally', 'update'] })
@result = subject.revise!(Fabricate(:user), raw: "lets totally update the body", tags: ['totally', 'update'])
}.to_not change { Tag.count }
expect(@result).to eq(true)
post.reload

View File

@@ -17,7 +17,7 @@ describe PrettyText do
end
let(:wrapped_image) { "<div class=\"lightbox-wrapper\"><a href=\"//localhost:3000/uploads/default/4399/33691397e78b4d75.png\" class=\"lightbox\" title=\"Screen Shot 2014-04-14 at 9.47.10 PM.png\"><img src=\"//localhost:3000/uploads/default/_optimized/bd9/b20/bbbcd6a0c0_655x500.png\" width=\"655\" height=\"500\"><div class=\"meta\">\n<span class=\"filename\">Screen Shot 2014-04-14 at 9.47.10 PM.png</span><span class=\"informations\">966x737 1.47 MB</span><span class=\"expand\"></span>\n</div></a></div>" }
let(:wrapped_image_excerpt) { }
let(:wrapped_image_excerpt) {}
describe "Quoting" do
@@ -91,7 +91,6 @@ describe PrettyText do
expect(PrettyText.cook(md)).to eq(html.strip)
end
it "trims spaces on quote params" do
md = <<~MD
[quote="#{user.username}, post:555, topic: 666"]
@@ -196,7 +195,6 @@ describe PrettyText do
expect(PrettyText.cook("<a> @inner</a> ")).to match_html '<p><a> @inner</a></p>'
end
it "can handle mentions inside a hyperlink" do
expect(PrettyText.cook("[link @inner](http://site.com)")).to match_html '<p><a href="http://site.com" rel="nofollow noopener">link @inner</a></p>'
end
@@ -271,7 +269,6 @@ describe PrettyText do
end
end
describe "rel nofollow" do
before do
SiteSetting.add_rel_nofollow_to_user_content = true
@@ -324,7 +321,7 @@ describe PrettyText do
context "images" do
it "should dump images" do
expect(PrettyText.excerpt("<img src='http://cnn.com/a.gif'>",100)).to eq("[image]")
expect(PrettyText.excerpt("<img src='http://cnn.com/a.gif'>", 100)).to eq("[image]")
end
context 'alt tags' do
@@ -366,32 +363,32 @@ describe PrettyText do
end
it "should have an option to strip links" do
expect(PrettyText.excerpt("<a href='http://cnn.com'>cnn</a>",100, strip_links: true)).to eq("cnn")
expect(PrettyText.excerpt("<a href='http://cnn.com'>cnn</a>", 100, strip_links: true)).to eq("cnn")
end
it "should preserve links" do
expect(PrettyText.excerpt("<a href='http://cnn.com'>cnn</a>",100)).to match_html "<a href='http://cnn.com'>cnn</a>"
expect(PrettyText.excerpt("<a href='http://cnn.com'>cnn</a>", 100)).to match_html "<a href='http://cnn.com'>cnn</a>"
end
it "should deal with special keys properly" do
expect(PrettyText.excerpt("<pre><b></pre>",100)).to eq("")
expect(PrettyText.excerpt("<pre><b></pre>", 100)).to eq("")
end
it "should truncate stuff properly" do
expect(PrettyText.excerpt("hello world",5)).to eq("hello&hellip;")
expect(PrettyText.excerpt("<p>hello</p><p>world</p>",6)).to eq("hello w&hellip;")
expect(PrettyText.excerpt("hello world", 5)).to eq("hello&hellip;")
expect(PrettyText.excerpt("<p>hello</p><p>world</p>", 6)).to eq("hello w&hellip;")
end
it "should insert a space between to Ps" do
expect(PrettyText.excerpt("<p>a</p><p>b</p>",5)).to eq("a b")
expect(PrettyText.excerpt("<p>a</p><p>b</p>", 5)).to eq("a b")
end
it "should strip quotes" do
expect(PrettyText.excerpt("<aside class='quote'><p>a</p><p>b</p></aside>boom",5)).to eq("boom")
expect(PrettyText.excerpt("<aside class='quote'><p>a</p><p>b</p></aside>boom", 5)).to eq("boom")
end
it "should not count the surrounds of a link" do
expect(PrettyText.excerpt("<a href='http://cnn.com'>cnn</a>",3)).to match_html "<a href='http://cnn.com'>cnn</a>"
expect(PrettyText.excerpt("<a href='http://cnn.com'>cnn</a>", 3)).to match_html "<a href='http://cnn.com'>cnn</a>"
end
it "uses an ellipsis instead of html entities if provided with the option" do
@@ -399,7 +396,7 @@ describe PrettyText do
end
it "should truncate links" do
expect(PrettyText.excerpt("<a href='http://cnn.com'>cnn</a>",2)).to match_html "<a href='http://cnn.com'>cn&hellip;</a>"
expect(PrettyText.excerpt("<a href='http://cnn.com'>cnn</a>", 2)).to match_html "<a href='http://cnn.com'>cn&hellip;</a>"
end
it "doesn't extract empty quotes as links" do
@@ -452,22 +449,22 @@ describe PrettyText do
end
it "should not preserve tags in code blocks" do
expect(PrettyText.excerpt("<pre><code class='handlebars'>&lt;h3&gt;Hours&lt;/h3&gt;</code></pre>",100)).to eq("&lt;h3&gt;Hours&lt;/h3&gt;")
expect(PrettyText.excerpt("<pre><code class='handlebars'>&lt;h3&gt;Hours&lt;/h3&gt;</code></pre>", 100)).to eq("&lt;h3&gt;Hours&lt;/h3&gt;")
end
it "should handle nil" do
expect(PrettyText.excerpt(nil,100)).to eq('')
expect(PrettyText.excerpt(nil, 100)).to eq('')
end
it "handles span excerpt at the beginning of a post" do
expect(PrettyText.excerpt("<span class='excerpt'>hi</span> test",100)).to eq('hi')
expect(PrettyText.excerpt("<span class='excerpt'>hi</span> test", 100)).to eq('hi')
post = Fabricate(:post, raw: "<span class='excerpt'>hi</span> test")
expect(post.excerpt).to eq("hi")
end
it "ignores max excerpt length if a span excerpt is specified" do
two_hundred = "123456789 " * 20 + "."
text = two_hundred + "<span class='excerpt'>#{two_hundred}</span>" + two_hundred
text = two_hundred + "<span class='excerpt'>#{two_hundred}</span>" + two_hundred
expect(PrettyText.excerpt(text, 100)).to eq(two_hundred)
post = Fabricate(:post, raw: text)
expect(post.excerpt).to eq(two_hundred)
@@ -479,12 +476,12 @@ describe PrettyText do
it "should have an option to preserve emoji images" do
emoji_image = "<img src='/images/emoji/twitter/heart.png?v=1' title=':heart:' class='emoji' alt='heart'>"
expect(PrettyText.excerpt(emoji_image, 100, { keep_emoji_images: true })).to match_html(emoji_image)
expect(PrettyText.excerpt(emoji_image, 100, keep_emoji_images: true)).to match_html(emoji_image)
end
it "should have an option to remap emoji to code points" do
emoji_image = "I <img src='/images/emoji/twitter/heart.png?v=1' title=':heart:' class='emoji' alt=':heart:'> you <img src='/images/emoji/twitter/heart.png?v=1' title=':unknown:' class='emoji' alt=':unknown:'> "
expect(PrettyText.excerpt(emoji_image, 100, { remap_emoji: true })).to match_html("I ❤ you :unknown:")
expect(PrettyText.excerpt(emoji_image, 100, remap_emoji: true)).to match_html("I ❤ you :unknown:")
end
it "should have an option to preserve emoji codes" do
@@ -626,7 +623,6 @@ describe PrettyText do
expect(PrettyText.cook(raw)).to eq(html.strip)
end
it 'can substitute s3 cdn correctly' do
SiteSetting.enable_s3_uploads = true
SiteSetting.s3_access_key_id = "XXX"
@@ -722,7 +718,7 @@ describe PrettyText do
end
it "produces tag links" do
Fabricate(:topic, {tags: [Fabricate(:tag, name: 'known')]})
Fabricate(:topic, tags: [Fabricate(:tag, name: 'known')])
cooked = PrettyText.cook(" #unknown::tag #known::tag")
@@ -772,7 +768,6 @@ describe PrettyText do
expect(PrettyText.cook("1\n2")).to match_html "<p>1<br>\n2</p>"
end
it "can handle emoji by name" do
expected = <<HTML
@@ -794,7 +789,7 @@ HTML
it "can handle multiple emojis by translation" do
cooked = PrettyText.cook(":) ;) :)")
expect(cooked.split("img").length-1).to eq(3)
expect(cooked.split("img").length - 1).to eq(3)
end
it "handles emoji boundries correctly" do
@@ -848,12 +843,10 @@ HTML
expect(PrettyText.cook("a[i]b[/i]c")).to eq('<p>a<span class="bbcode-i">b</span>c</p>')
end
it "can onebox local topics" do
op = Fabricate(:post)
reply = Fabricate(:post, topic_id: op.topic_id)
url = Discourse.base_url + reply.url
quote = create_post(topic_id: op.topic.id, raw: "This is a sample reply with a quote\n\n#{url}")
quote.reload
@@ -891,7 +884,6 @@ HTML
expect(PrettyText.cook(markdown)).to eq(expected.strip)
end
it "supports img bbcode" do
cooked = PrettyText.cook "[img]http://www.image/test.png[/img]"
html = "<p><img src=\"http://www.image/test.png\" alt></p>"

View File

@@ -15,7 +15,7 @@ describe Promotion do
context "newuser" do
let(:user) { Fabricate(:user, trust_level: TrustLevel[0], created_at: 2.days.ago)}
let(:user) { Fabricate(:user, trust_level: TrustLevel[0], created_at: 2.days.ago) }
let(:promotion) { Promotion.new(user) }
it "doesn't raise an error with a nil user" do
@@ -70,7 +70,7 @@ describe Promotion do
context "basic" do
let(:user) { Fabricate(:user, trust_level: TrustLevel[1], created_at: 2.days.ago)}
let(:user) { Fabricate(:user, trust_level: TrustLevel[1], created_at: 2.days.ago) }
let(:promotion) { Promotion.new(user) }
context 'that has done nothing' do
@@ -131,7 +131,7 @@ describe Promotion do
end
context "regular" do
let(:user) { Fabricate(:user, trust_level: TrustLevel[2])}
let(:user) { Fabricate(:user, trust_level: TrustLevel[2]) }
let(:promotion) { Promotion.new(user) }
context "doesn't qualify for promotion" do

View File

@@ -36,5 +36,3 @@ describe RetrieveTitle do
end
end

View File

@@ -37,7 +37,6 @@ describe Scheduler::Defer do
@defer.resume
@defer.later do
x = 3
end

View File

@@ -19,7 +19,7 @@ describe Scheduler::Manager do
every 5.minutes
def perform
self.class.runs+=1
self.class.runs += 1
sleep 0.001
end
end
@@ -69,11 +69,11 @@ describe Scheduler::Manager do
manager.remove(Testing::SuperLongJob)
manager.remove(Testing::PerHostJob)
$redis.flushall
expect(ActiveRecord::Base.connection_pool.connections.reject{|c| !c.in_use?}.length).to eq(1)
expect(ActiveRecord::Base.connection_pool.connections.reject { |c| !c.in_use? }.length).to eq(1)
# connections that are not in use must be removed
# otherwise active record gets super confused
ActiveRecord::Base.connection_pool.connections.reject{|c| c.in_use?}.each do |c|
ActiveRecord::Base.connection_pool.connections.reject { |c| c.in_use? }.each do |c|
ActiveRecord::Base.connection_pool.remove(c)
end
expect(ActiveRecord::Base.connection_pool.connections.length).to eq(1)
@@ -96,7 +96,7 @@ describe Scheduler::Manager do
it "correctly schedules on multiple hosts" do
Testing::PerHostJob.runs = 0
hosts = ['a','b','c']
hosts = ['a', 'b', 'c']
hosts.map do |host|

View File

@@ -4,7 +4,7 @@ require 'scheduler/scheduler'
describe Scheduler::ScheduleInfo do
let(:manager){ Scheduler::Manager.new }
let(:manager) { Scheduler::Manager.new }
context "every" do
class RandomJob

View File

@@ -166,12 +166,10 @@ describe Search do
let(:reply) { Fabricate(:post, topic: topic,
raw: 'hello from mars, we just landed') }
it 'searches correctly' do
expect do
Search.execute('mars', type_filter: 'private_messages')
Search.execute('mars', type_filter: 'private_messages')
end.to raise_error(Discourse::InvalidAccess)
TopicAllowedUser.create!(user_id: reply.user_id, topic_id: topic.id)
@@ -183,7 +181,6 @@ describe Search do
expect(results.posts.length).to eq(1)
results = Search.execute('mars',
search_context: topic,
guardian: Guardian.new(reply.user))
@@ -200,7 +197,6 @@ describe Search do
Fabricate(:topic, category_id: nil, archetype: 'private_message')
Fabricate(:post, topic: topic, raw: 'another secret pm from mars, testing')
# admin can search everything with correct context
results = Search.execute('mars',
type_filter: 'private_messages',
@@ -235,8 +231,7 @@ describe Search do
context 'topics' do
let(:post) { Fabricate(:post) }
let(:topic) { post.topic}
let(:topic) { post.topic }
context 'search within topic' do
@@ -311,7 +306,7 @@ describe Search do
end
context "search for a topic by url" do
let(:result) { Search.execute(topic.relative_url, search_for_id: true, type_filter: 'topic')}
let(:result) { Search.execute(topic.relative_url, search_for_id: true, type_filter: 'topic') }
it 'returns the topic' do
expect(result.posts.length).to eq(1)
@@ -331,7 +326,7 @@ describe Search do
topic.category_id = category.id
topic.save
category.set_permissions(:staff => :full)
category.set_permissions(staff: :full)
category.save
expect(result(nil).posts).not_to be_present
@@ -345,11 +340,11 @@ describe Search do
context 'cyrillic topic' do
let!(:cyrillic_topic) { Fabricate(:topic) do
user
user
title { sequence(:title) { |i| "Тестовая запись #{i}" } }
end
end
}
let!(:post) {Fabricate(:post, topic: cyrillic_topic, user: cyrillic_topic.user)}
let!(:post) { Fabricate(:post, topic: cyrillic_topic, user: cyrillic_topic.user) }
let(:result) { Search.execute('запись') }
it 'finds something when given cyrillic query' do
@@ -380,13 +375,11 @@ describe Search do
end
context 'type_filter' do
let!(:user) { Fabricate(:user, username: 'amazing', email: 'amazing@amazing.com') }
let!(:category) { Fabricate(:category, name: 'amazing category', user: user) }
context 'user filter' do
let(:results) { Search.execute('amazing', type_filter: 'user') }
@@ -435,12 +428,12 @@ describe Search do
subcategory = Fabricate(:category, parent_category_id: category.id)
sub_topic = Fabricate(:topic, category: subcategory)
post = Fabricate(:post, topic: topic, user: topic.user )
_another_post = Fabricate(:post, topic: topic_no_cat, user: topic.user )
sub_post = Fabricate(:post, raw: 'I am saying hello from a subcategory', topic: sub_topic, user: topic.user )
post = Fabricate(:post, topic: topic, user: topic.user)
_another_post = Fabricate(:post, topic: topic_no_cat, user: topic.user)
sub_post = Fabricate(:post, raw: 'I am saying hello from a subcategory', topic: sub_topic, user: topic.user)
search = Search.execute('hello', search_context: category)
expect(search.posts.map(&:id).sort).to eq([post.id,sub_post.id].sort)
expect(search.posts.map(&:id).sort).to eq([post.id, sub_post.id].sort)
expect(search.posts.length).to eq(2)
end
@@ -450,7 +443,7 @@ describe Search do
it 'splits English / Chinese' do
SiteSetting.default_locale = 'zh_CN'
data = Search.prepare_data('Discourse社区指南').split(' ')
expect(data).to eq(['Discourse', '社区','指南'])
expect(data).to eq(['Discourse', '社区', '指南'])
end
it 'finds chinese topic based on title' do
@@ -711,9 +704,9 @@ describe Search do
let(:topic1) { Fabricate(:topic, tags: [tag2, Fabricate(:tag)]) }
let(:topic2) { Fabricate(:topic, tags: [tag2]) }
let(:topic3) { Fabricate(:topic, tags: [tag1, tag2]) }
let!(:post1) { Fabricate(:post, topic: topic1)}
let!(:post2) { Fabricate(:post, topic: topic2)}
let!(:post3) { Fabricate(:post, topic: topic3)}
let!(:post1) { Fabricate(:post, topic: topic1) }
let!(:post2) { Fabricate(:post, topic: topic2) }
let!(:post3) { Fabricate(:post, topic: topic3) }
it 'can find posts with tag' do
post4 = Fabricate(:post, topic: topic3, raw: "It probably doesn't help that they're green...")
@@ -757,7 +750,6 @@ describe Search do
expect(Search.word_to_date('january')).to eq(Time.zone.parse('2001-01-01'))
expect(Search.word_to_date('jan')).to eq(Time.zone.parse('2001-01-01'))
expect(Search.word_to_date('100')).to eq(time.beginning_of_day.days_ago(100))
expect(Search.word_to_date('invalid')).to eq(nil)

View File

@@ -58,7 +58,7 @@ describe SiteSettingExtension do
settings.hello = 100
expect(settings.hello).to eq(100)
settings.provider.save(:hello, 99, SiteSetting.types[:integer] )
settings.provider.save(:hello, 99, SiteSetting.types[:integer])
settings.refresh!
expect(settings.hello).to eq(99)
@@ -97,7 +97,7 @@ describe SiteSettingExtension do
end
it "should have a key in all_settings" do
expect(settings.all_settings.detect {|s| s[:setting] == :test_setting }).to be_present
expect(settings.all_settings.detect { |s| s[:setting] == :test_setting }).to be_present
end
it "should have the correct desc" do
@@ -190,7 +190,6 @@ describe SiteSettingExtension do
end
end
describe "string setting with regex" do
it "Supports custom validation errors" do
settings.setting(:test_str, "bob", regex: "hi", regex_error: "oops")
@@ -256,7 +255,7 @@ describe SiteSettingExtension do
true
end
def self.values
[1,2,3]
[1, 2, 3]
end
end
@@ -297,7 +296,7 @@ describe SiteSettingExtension do
end
it 'should not hose all_settings' do
expect(settings.all_settings.detect {|s| s[:setting] == :test_enum }).to be_present
expect(settings.all_settings.detect { |s| s[:setting] == :test_enum }).to be_present
end
context 'when overridden' do
@@ -313,19 +312,19 @@ describe SiteSettingExtension do
it 'rejects invalid values' do
test_enum_class.expects(:valid_value?).with('gg').returns(false)
expect {settings.test_enum = 'gg' }.to raise_error(Discourse::InvalidParameters)
expect { settings.test_enum = 'gg' }.to raise_error(Discourse::InvalidParameters)
end
end
end
describe 'a setting with a category' do
before do
settings.setting(:test_setting, 88, {category: :tests})
settings.setting(:test_setting, 88, category: :tests)
settings.refresh!
end
it "should return the category in all_settings" do
expect(settings.all_settings.find {|s| s[:setting] == :test_setting }[:category]).to eq(:tests)
expect(settings.all_settings.find { |s| s[:setting] == :test_setting }[:category]).to eq(:tests)
end
context "when overidden" do
@@ -340,14 +339,14 @@ describe SiteSettingExtension do
it "should still have the correct category" do
settings.test_setting = 102
expect(settings.all_settings.find {|s| s[:setting] == :test_setting }[:category]).to eq(:tests)
expect(settings.all_settings.find { |s| s[:setting] == :test_setting }[:category]).to eq(:tests)
end
end
end
describe "setting with a validator" do
before do
settings.setting(:validated_setting, "info@example.com", {type: 'email'})
settings.setting(:validated_setting, "info@example.com", type: 'email')
settings.refresh!
end
@@ -417,11 +416,11 @@ describe SiteSettingExtension do
end
it "is not present in all_settings by default" do
expect(settings.all_settings.find {|s| s[:setting] == :superman_identity }).to be_blank
expect(settings.all_settings.find { |s| s[:setting] == :superman_identity }).to be_blank
end
it "is present in all_settings when we ask for hidden" do
expect(settings.all_settings(true).find {|s| s[:setting] == :superman_identity }).to be_present
expect(settings.all_settings(true).find { |s| s[:setting] == :superman_identity }).to be_present
end
end

View File

@@ -22,7 +22,6 @@ describe SiteSettings::DbProvider do
expect(provider.all.length).to eq(0)
expect(provider.find("test")).to eq(nil)
provider.save("test", "one", 1)
found = provider.find("test")
@@ -35,7 +34,7 @@ describe SiteSettings::DbProvider do
provider.save("test2", "three", 3)
all = provider.all.sort{|a,b| a.name <=> b.name}
all = provider.all.sort { |a, b| a.name <=> b.name }
expect_same_setting(all[0], setting.new("test", "two", 2))
expect_same_setting(all[1], setting.new("test2", "three", 3))

View File

@@ -13,8 +13,7 @@ describe SiteSettings::LocalProcessProvider do
SiteSettings::LocalProcessProvider.new
end
def setting(name,value,data_type)
def setting(name, value, data_type)
OpenStruct.new.tap do |setting|
setting.name = name
setting.value = value
@@ -29,13 +28,13 @@ describe SiteSettings::LocalProcessProvider do
it "can allows additional settings" do
provider.save("test", "bla", 2)
expect_same_setting(provider.all[0], setting("test","bla",2))
expect_same_setting(provider.all[0], setting("test", "bla", 2))
end
it "does not leak new stuff into list" do
provider.save("test", "bla", 2)
provider.save("test", "bla1", 2)
expect_same_setting(provider.all[0], setting("test","bla1",2))
expect_same_setting(provider.all[0], setting("test", "bla1", 2))
expect(provider.all.length).to eq(1)
end
end
@@ -46,19 +45,19 @@ describe SiteSettings::LocalProcessProvider do
end
it "can find a new setting" do
provider.save("one","two",3)
expect_same_setting(provider.find("one"),setting("one", "two", 3))
provider.save("one", "two", 3)
expect_same_setting(provider.find("one"), setting("one", "two", 3))
end
it "can amend a setting" do
provider.save("one","three",4)
expect_same_setting(provider.find("one"),setting("one", "three", 4))
provider.save("one", "three", 4)
expect_same_setting(provider.find("one"), setting("one", "three", 4))
end
end
describe "destroy" do
it "can destroy a setting" do
provider.save("one","three",4)
provider.save("one", "three", 4)
provider.destroy("one")
expect(provider.find("one")).to eq(nil)
end

View File

@@ -48,7 +48,7 @@ describe SiteSettings::YamlLoader do
it 'can take a File argument' do
receiver.expects(:setting).at_least_once
receiver.load_yaml( File.new(simple) )
receiver.load_yaml(File.new(simple))
end
it "maintains order of categories" do
@@ -64,13 +64,13 @@ describe SiteSettings::YamlLoader do
end
it "can load enum settings" do
receiver.expects(:setting).with('email', 'default_email_digest_frequency', 7, {enum: 'DigestEmailSiteSetting'})
receiver.expects(:setting).with('email', 'default_email_digest_frequency', 7, enum: 'DigestEmailSiteSetting')
receiver.load_yaml(enum)
end
it "can load enum client settings" do
receiver.expects(:client_setting).with do |category, name, default, opts|
category == 'basics' and name == 'default_locale' and default == 'en' and opts[:enum] == 'LocaleSiteSetting'
category == ('basics') && name == ('default_locale') && default == ('en') && opts[:enum] == ('LocaleSiteSetting')
end
receiver.load_yaml(enum_client)
end

View File

@@ -143,4 +143,3 @@ describe Slug do
end
end
end

View File

@@ -64,11 +64,11 @@ describe SqlBuilder do
it "should allow order by" do
expect(@builder.order_by("A desc").limit(1)
.exec(a:1, b:2).values[0][0]).to eq("2")
.exec(a: 1, b: 2).values[0][0]).to eq("2")
end
it "should allow offset" do
expect(@builder.order_by("A desc").offset(1)
.exec(a:1, b:2).values[0][0]).to eq("1")
.exec(a: 1, b: 2).values[0][0]).to eq("1")
end
end

View File

@@ -51,7 +51,7 @@ describe StatsSocket do
parsed = JSON.parse(line)
expect(parsed['total_physical_size']).to be>(0)
expect(parsed['total_physical_size']).to be > (0)
end
end

View File

@@ -14,14 +14,14 @@ describe Stylesheet::Compiler do
end
it "supports asset-url" do
css,_map = Stylesheet::Compiler.compile(".body{background-image: asset-url('foo.png');}","test.scss")
css, _map = Stylesheet::Compiler.compile(".body{background-image: asset-url('foo.png');}", "test.scss")
expect(css).to include("url('/foo.png')")
expect(css).not_to include('asset-url')
end
it "supports image-url" do
css,_map = Stylesheet::Compiler.compile(".body{background-image: image-url('foo.png');}","test.scss")
css, _map = Stylesheet::Compiler.compile(".body{background-image: image-url('foo.png');}", "test.scss")
expect(css).to include("url('/images/foo.png')")
expect(css).not_to include('image-url')

View File

@@ -28,7 +28,6 @@ describe Stylesheet::Manager do
theme.save!
child_theme = Theme.new(
name: 'parent',
user_id: -1,
@@ -55,7 +54,6 @@ describe Stylesheet::Manager do
expect(css).to match(/\.common/)
expect(css).to match(/\.desktop/)
child_theme.set_field(target: :desktop, name: :scss, value: ".nothing{color: green;}")
child_theme.save!
@@ -67,4 +65,3 @@ describe Stylesheet::Manager do
expect(new_link).to include("/stylesheets/desktop_theme_#{theme.id}_")
end
end

View File

@@ -17,30 +17,30 @@ describe SuggestedTopicsBuilder do
end
let(:builder) do
SuggestedTopicsBuilder.new(fake_topic(1,1))
SuggestedTopicsBuilder.new(fake_topic(1, 1))
end
it "prioritizes category correctly" do
builder.splice_results([fake_topic(2,2)], :high)
builder.splice_results([fake_topic(3,1)], :high)
builder.splice_results([fake_topic(4,1)], :high)
builder.splice_results([fake_topic(2, 2)], :high)
builder.splice_results([fake_topic(3, 1)], :high)
builder.splice_results([fake_topic(4, 1)], :high)
expect(builder.results.map(&:id)).to eq([3,4,2])
expect(builder.results.map(&:id)).to eq([3, 4, 2])
# we have 2 items in category 1
expect(builder.category_results_left).to eq(3)
end
it "inserts using default approach for non high priority" do
builder.splice_results([fake_topic(2,2)], :high)
builder.splice_results([fake_topic(3,1)], :low)
builder.splice_results([fake_topic(2, 2)], :high)
builder.splice_results([fake_topic(3, 1)], :low)
expect(builder.results.map(&:id)).to eq([2,3])
expect(builder.results.map(&:id)).to eq([2, 3])
end
it "inserts multiple results and puts topics in the correct order" do
builder.splice_results([fake_topic(2,1), fake_topic(3,2), fake_topic(4,1)], :high)
expect(builder.results.map(&:id)).to eq([2,4,3])
builder.splice_results([fake_topic(2, 1), fake_topic(3, 2), fake_topic(4, 1)], :high)
expect(builder.results.map(&:id)).to eq([2, 4, 3])
end
end
@@ -84,9 +84,9 @@ describe SuggestedTopicsBuilder do
end
context "adding topics that are not open" do
let!(:archived_topic) { Fabricate(:topic, archived: true)}
let!(:closed_topic) { Fabricate(:topic, closed: true)}
let!(:invisible_topic) { Fabricate(:topic, visible: false)}
let!(:archived_topic) { Fabricate(:topic, archived: true) }
let!(:closed_topic) { Fabricate(:topic, closed: true) }
let!(:invisible_topic) { Fabricate(:topic, visible: false) }
it "adds archived and closed, but not invisible topics" do
builder.add_results(Topic)
@@ -108,5 +108,4 @@ describe SuggestedTopicsBuilder do
end
end

View File

@@ -4,7 +4,6 @@ require 'topic_subtype'
describe SystemMessage do
context 'send' do
it 'should create a post correctly' do
@@ -28,5 +27,4 @@ describe SystemMessage do
end
end
end

View File

@@ -19,8 +19,8 @@ describe TableMigrationHelper do
ActiveRecord::Base.exec_sql "CREATE TABLE table_with_old_name (topic_id INTEGER)"
name = ActiveRecord::Base
.exec_sql("SELECT name FROM schema_migration_details LIMIT 1")
.getvalue(0,0)
.exec_sql("SELECT name FROM schema_migration_details LIMIT 1")
.getvalue(0, 0)
Topic.exec_sql("UPDATE schema_migration_details SET created_at = :created_at WHERE name = :name",
name: name, created_at: 15.minutes.ago)
@@ -32,7 +32,7 @@ describe TableMigrationHelper do
new_name: 'table_with_new_name',
after_migration: name,
delay: 20.minutes,
on_drop: ->(){dropped_proc_called = true}
on_drop: ->() { dropped_proc_called = true }
)
expect(table_exists?('table_with_old_name')).to eq(true)
@@ -43,7 +43,7 @@ describe TableMigrationHelper do
new_name: 'table_with_new_name',
after_migration: name,
delay: 10.minutes,
on_drop: ->(){dropped_proc_called = true}
on_drop: ->() { dropped_proc_called = true }
)
expect(table_exists?('table_with_old_name')).to eq(true)
@@ -56,7 +56,7 @@ describe TableMigrationHelper do
new_name: 'table_with_new_name',
after_migration: name,
delay: 10.minutes,
on_drop: ->(){dropped_proc_called = true}
on_drop: ->() { dropped_proc_called = true }
)
expect(table_exists?('table_with_old_name')).to eq(false)

View File

@@ -22,7 +22,7 @@ describe TimelineLookup do
end
it "respects a `max_values` setting" do
input = (1..100).map {|i| [1000+i, i, 100-i] }
input = (1..100).map { |i| [1000 + i, i, 100 - i] }
result = TimelineLookup.build(input, 5)
expect(result.size).to eq(5)
@@ -30,7 +30,7 @@ describe TimelineLookup do
end
it "respects an uneven `max_values` setting" do
input = (1..100).map {|i| [1000+i, i, 100-i] }
input = (1..100).map { |i| [1000 + i, i, 100 - i] }
result = TimelineLookup.build(input, 3)
expect(result.size).to eq(3)

View File

@@ -7,7 +7,7 @@ describe TopicCreator do
let(:admin) { Fabricate(:admin) }
let(:valid_attrs) { Fabricate.attributes_for(:topic) }
let(:pm_valid_attrs) { {raw: 'this is a new post', title: 'this is a new title', archetype: Archetype.private_message, target_usernames: moderator.username} }
let(:pm_valid_attrs) { { raw: 'this is a new post', title: 'this is a new title', archetype: Archetype.private_message, target_usernames: moderator.username } }
describe '#create' do
context 'topic success cases' do

View File

@@ -49,7 +49,7 @@ describe TopicQuery do
results = results.where('topics.id = ?', topic_query.options[:only_topic_id])
end
expect(TopicQuery.new(nil, {only_topic_id: topic1.id}).list_latest.topics.map(&:id)).to eq([topic1.id])
expect(TopicQuery.new(nil, only_topic_id: topic1.id).list_latest.topics.map(&:id)).to eq([topic1.id])
TopicQuery.remove_custom_filter(:only_topic_id)
end
@@ -76,21 +76,17 @@ describe TopicQuery do
topics = []
(num_topics - 1).downto(0).each do |i|
topics[i] = Fabricate(:topic)
topics[i] = Fabricate(:topic)
end
topic_query = TopicQuery.new(user)
results = topic_query.send(:default_results)
expect(topic_query.prioritize_pinned_topics(results, {
:per_page => per_page,
:page => 0
})).to eq(topics[0...per_page])
expect(topic_query.prioritize_pinned_topics(results, per_page: per_page,
page: 0)).to eq(topics[0...per_page])
expect(topic_query.prioritize_pinned_topics(results, {
:per_page => per_page,
:page => 1
})).to eq(topics[per_page...num_topics])
expect(topic_query.prioritize_pinned_topics(results, per_page: per_page,
page: 1)).to eq(topics[per_page...num_topics])
end
@@ -111,7 +107,7 @@ describe TopicQuery do
query = TopicQuery.new(user, filter: 'bookmarked').list_latest
expect(query.topics.length).to eq(1)
expect(query.topics.first.user_data.post_action_data).to eq({PostActionType.types[:bookmark] => [1,2]})
expect(query.topics.first.user_data.post_action_data).to eq(PostActionType.types[:bookmark] => [1, 2])
end
end
@@ -147,7 +143,7 @@ describe TopicQuery do
end
context 'subcategories' do
let!(:subcategory) { Fabricate(:category, parent_category_id: category.id)}
let!(:subcategory) { Fabricate(:category, parent_category_id: category.id) }
it "works with subcategories" do
expect(TopicQuery.new(moderator, category: category.id).list_latest.topics.size).to eq(1)
@@ -168,9 +164,9 @@ describe TopicQuery do
context "no category filter" do
# create some topics before each test:
let!(:tagged_topic1) { Fabricate(:topic, {tags: [tag]}) }
let!(:tagged_topic2) { Fabricate(:topic, {tags: [other_tag]}) }
let!(:tagged_topic3) { Fabricate(:topic, {tags: [tag, other_tag]}) }
let!(:tagged_topic1) { Fabricate(:topic, tags: [tag]) }
let!(:tagged_topic2) { Fabricate(:topic, tags: [other_tag]) }
let!(:tagged_topic3) { Fabricate(:topic, tags: [tag, other_tag]) }
let!(:no_tags_topic) { Fabricate(:topic) }
it "returns topics with the tag when filtered to it" do
@@ -207,10 +203,10 @@ describe TopicQuery do
let(:category2) { Fabricate(:category) }
it "returns topics in the given category with the given tag" do
tagged_topic1 = Fabricate(:topic, {category: category1, tags: [tag]})
tagged_topic2 = Fabricate(:topic, {category: category2, tags: [tag]})
tagged_topic3 = Fabricate(:topic, {category: category1, tags: [tag, other_tag]})
no_tags_topic = Fabricate(:topic, {category: category1})
tagged_topic1 = Fabricate(:topic, category: category1, tags: [tag])
tagged_topic2 = Fabricate(:topic, category: category2, tags: [tag])
tagged_topic3 = Fabricate(:topic, category: category1, tags: [tag, other_tag])
no_tags_topic = Fabricate(:topic, category: category1)
expect(TopicQuery.new(moderator, category: category1.id, tags: [tag.name]).list_latest.topics.map(&:id).sort).to eq([tagged_topic1.id, tagged_topic3.id].sort)
expect(TopicQuery.new(moderator, category: category2.id, tags: [other_tag.name]).list_latest.topics.size).to eq(0)
@@ -333,7 +329,7 @@ describe TopicQuery do
context 'sort_order' do
def ids_in_order(order, descending=true)
def ids_in_order(order, descending = true)
TopicQuery.new(admin, order: order, ascending: descending ? 'false' : 'true').list_latest.topics.map(&:id)
end
@@ -387,14 +383,12 @@ describe TopicQuery do
# returns the topics in reverse sheep order if requested" do
expect(ids_in_order('sheep', false)).to eq([invisible_topic, regular_topic, closed_topic, pinned_topic, future_topic, archived_topic].map(&:id))
end
end
end
context 'after clearring a pinned topic' do
before do
pinned_topic.clear_pin_for(user)
@@ -460,8 +454,8 @@ describe TopicQuery do
first = create_post(raw: 'this is the first post', title: 'super amazing title')
_whisper = create_post(topic_id: first.topic.id,
post_type: Post.types[:whisper],
raw: 'this is a whispered reply')
post_type: Post.types[:whisper],
raw: 'this is a whispered reply')
topic_id = first.topic.id
@@ -518,7 +512,7 @@ describe TopicQuery do
end
context 'preload api' do
let(:topics) { }
let(:topics) {}
it "preloads data correctly" do
TopicList.preloaded_custom_fields << "tag"
@@ -526,13 +520,13 @@ describe TopicQuery do
TopicList.preloaded_custom_fields << "foo"
topic = Fabricate.build(:topic, user: creator, bumped_at: 10.minutes.ago)
topic.custom_fields["tag"] = ["a","b","c"]
topic.custom_fields["tag"] = ["a", "b", "c"]
topic.custom_fields["age"] = 22
topic.save
new_topic = topic_query.list_new.topics.first
expect(new_topic.custom_fields["tag"].sort).to eq(["a","b","c"])
expect(new_topic.custom_fields["tag"].sort).to eq(["a", "b", "c"])
expect(new_topic.custom_fields["age"]).to eq("22")
expect(new_topic.custom_field_preloaded?("tag")).to eq(true)
@@ -543,7 +537,7 @@ describe TopicQuery do
TopicList.preloaded_custom_fields.clear
# if we attempt to access non preloaded fields explode
expect{new_topic.custom_fields["boom"]}.to raise_error(StandardError)
expect { new_topic.custom_fields["boom"] }.to raise_error(StandardError)
end
end
@@ -552,7 +546,6 @@ describe TopicQuery do
let!(:new_topic) { Fabricate(:topic, user: creator, bumped_at: 10.minutes.ago) }
let(:topics) { topic_query.list_new.topics }
it "contains no new topics for a user that has missed the window" do
expect(topic_query.list_new.topics).to eq([new_topic])
@@ -606,7 +599,7 @@ describe TopicQuery do
context "topic you've posted in" do
let(:other_users_topic) { create_post(user: creator).topic }
let!(:your_post) { create_post(user: user, topic: other_users_topic )}
let!(:your_post) { create_post(user: user, topic: other_users_topic) }
it "includes the posted topic" do
expect(topics.include?(other_users_topic)).to eq(true)
@@ -660,7 +653,7 @@ describe TopicQuery do
group
end
def create_pm(user, opts=nil)
def create_pm(user, opts = nil)
unless opts
opts = user
user = nil
@@ -669,30 +662,27 @@ describe TopicQuery do
create_post(opts.merge(user: user, archetype: Archetype.private_message)).topic
end
def read(user,topic,post_number)
def read(user, topic, post_number)
TopicUser.update_last_read(user, topic, post_number, 10000)
end
it 'returns the correct suggestions' do
pm_to_group = create_pm(sender, target_group_names: [group_with_user.name])
pm_to_group = create_pm(sender, target_group_names: [group_with_user.name])
pm_to_user = create_pm(sender, target_usernames: [user.username])
new_pm = create_pm(target_usernames: [user.username])
new_pm = create_pm(target_usernames: [user.username])
unread_pm = create_pm(target_usernames: [user.username])
read(user,unread_pm, 0)
unread_pm = create_pm(target_usernames: [user.username])
read(user, unread_pm, 0)
old_unrelated_pm = create_pm(target_usernames: [user.username])
read(user, old_unrelated_pm, 1)
related_by_user_pm = create_pm(sender, target_usernames: [user.username])
read(user, related_by_user_pm, 1)
related_by_group_pm = create_pm(sender, target_group_names: [group_with_user.name])
related_by_group_pm = create_pm(sender, target_group_names: [group_with_user.name])
read(user, related_by_group_pm, 1)
expect(TopicQuery.new(user).list_suggested_for(pm_to_group).topics.map(&:id)).to(
@@ -707,7 +697,7 @@ describe TopicQuery do
context 'suggested_for' do
def clear_cache!
$redis.keys('random_topic_cache*').each{|k| $redis.del k}
$redis.keys('random_topic_cache*').each { |k| $redis.del k }
end
before do
@@ -742,7 +732,7 @@ describe TopicQuery do
tt = topic
# lets clear cache once category is created - working around caching is hard
clear_cache!
topic_query.list_suggested_for(tt).topics.map{|t| t.id}
topic_query.list_suggested_for(tt).topics.map { |t| t.id }
}
it "should return empty results when there is nothing to find" do
@@ -792,13 +782,12 @@ describe TopicQuery do
fully_read_archived.save
end
it "returns unread, then new, then random" do
SiteSetting.suggested_topics = 7
expect(suggested_topics[0]).to eq(partially_read.id)
expect(suggested_topics[1,3]).to include(new_topic.id)
expect(suggested_topics[1,3]).to include(closed_topic.id)
expect(suggested_topics[1,3]).to include(archived_topic.id)
expect(suggested_topics[1, 3]).to include(new_topic.id)
expect(suggested_topics[1, 3]).to include(closed_topic.id)
expect(suggested_topics[1, 3]).to include(archived_topic.id)
# The line below appears to randomly fail, no idea why need to restructure test
#expect(suggested_topics[4]).to eq(fully_read.id)
@@ -813,9 +802,9 @@ describe TopicQuery do
it "won't return fully read if there are enough partially read topics and new topics" do
SiteSetting.suggested_topics = 4
expect(suggested_topics[0]).to eq(partially_read.id)
expect(suggested_topics[1,3]).to include(new_topic.id)
expect(suggested_topics[1,3]).to include(closed_topic.id)
expect(suggested_topics[1,3]).to include(archived_topic.id)
expect(suggested_topics[1, 3]).to include(new_topic.id)
expect(suggested_topics[1, 3]).to include(closed_topic.id)
expect(suggested_topics[1, 3]).to include(archived_topic.id)
end
end

View File

@@ -31,9 +31,9 @@ describe TopicRetriever do
end
context "when host is not invalid" do
before do
topic_retriever.stubs(:invalid_url?).returns(false)
end
before do
topic_retriever.stubs(:invalid_url?).returns(false)
end
context "when topics have been retrieived recently" do
before do

View File

@@ -43,9 +43,9 @@ describe TopicView do
end
context "with a few sample posts" do
let!(:p1) { Fabricate(:post, topic: topic, user: first_poster, percent_rank: 1 )}
let!(:p2) { Fabricate(:post, topic: topic, user: coding_horror, percent_rank: 0.5 )}
let!(:p3) { Fabricate(:post, topic: topic, user: first_poster, percent_rank: 0 )}
let!(:p1) { Fabricate(:post, topic: topic, user: first_poster, percent_rank: 1) }
let!(:p2) { Fabricate(:post, topic: topic, user: coding_horror, percent_rank: 0.5) }
let!(:p3) { Fabricate(:post, topic: topic, user: first_poster, percent_rank: 0) }
let(:moderator) { Fabricate(:moderator) }
let(:admin) { Fabricate(:admin) }
@@ -70,7 +70,6 @@ describe TopicView do
best = TopicView.new(topic.id, nil, best: 99, min_trust_level: coding_horror.trust_level + 1)
expect(best.posts.count).to eq(0)
# should filter out the posts with a score that is too low
best = TopicView.new(topic.id, nil, best: 99, min_score: 99)
expect(best.posts.count).to eq(0)
@@ -134,7 +133,7 @@ describe TopicView do
end
it "generates a canonical correctly for paged results" do
expect(TopicView.new(1234, user, post_number: 10 * TopicView.chunk_size )
expect(TopicView.new(1234, user, post_number: 10 * TopicView.chunk_size)
.canonical_path).to eql("/1234?page=10")
end
end
@@ -211,7 +210,6 @@ describe TopicView do
end
end
context '.read?' do
it 'tracks correctly' do
# anon is assumed to have read everything
@@ -223,7 +221,7 @@ describe TopicView do
coding_horror.created_at = 2.days.ago
# a real user that just read it should have it marked
PostTiming.process_timings(coding_horror, topic.id, 1, [[1,1000]])
PostTiming.process_timings(coding_horror, topic.id, 1, [[1, 1000]])
expect(TopicView.new(topic.id, coding_horror).read?(1)).to eq(true)
expect(TopicView.new(topic.id, coding_horror).topic_user).to be_present
end
@@ -277,13 +275,13 @@ describe TopicView do
context '.posts' do
# Create the posts in a different order than the sort_order
let!(:p5) { Fabricate(:post, topic: topic, user: coding_horror)}
let!(:p2) { Fabricate(:post, topic: topic, user: coding_horror)}
let!(:p6) { Fabricate(:post, topic: topic, user: Fabricate(:user), deleted_at: Time.now)}
let!(:p4) { Fabricate(:post, topic: topic, user: coding_horror, deleted_at: Time.now)}
let!(:p1) { Fabricate(:post, topic: topic, user: first_poster)}
let!(:p7) { Fabricate(:post, topic: topic, user: coding_horror, deleted_at: Time.now)}
let!(:p3) { Fabricate(:post, topic: topic, user: first_poster)}
let!(:p5) { Fabricate(:post, topic: topic, user: coding_horror) }
let!(:p2) { Fabricate(:post, topic: topic, user: coding_horror) }
let!(:p6) { Fabricate(:post, topic: topic, user: Fabricate(:user), deleted_at: Time.now) }
let!(:p4) { Fabricate(:post, topic: topic, user: coding_horror, deleted_at: Time.now) }
let!(:p1) { Fabricate(:post, topic: topic, user: first_poster) }
let!(:p7) { Fabricate(:post, topic: topic, user: coding_horror, deleted_at: Time.now) }
let!(:p3) { Fabricate(:post, topic: topic, user: first_poster) }
before do
TopicView.stubs(:chunk_size).returns(3)
@@ -320,15 +318,14 @@ describe TopicView do
topic.category_id = category.id
topic.save!
expect{
expect {
TopicView.new(topic.id, coding_horror).posts.count
}.to raise_error(Discourse::InvalidAccess)
expect(TopicView.new(t2.id, coding_horror, post_ids: [p1.id,p2.id]).posts.count).to eq(0)
expect(TopicView.new(t2.id, coding_horror, post_ids: [p1.id, p2.id]).posts.count).to eq(0)
end
describe '#filter_posts_paged' do
before { TopicView.stubs(:chunk_size).returns(2) }
@@ -342,7 +339,7 @@ describe TopicView do
describe "filter_posts_near" do
def topic_view_near(post, show_deleted=false)
def topic_view_near(post, show_deleted = false)
TopicView.new(topic.id, coding_horror, post_number: post.post_number, show_deleted: show_deleted)
end
@@ -372,8 +369,8 @@ describe TopicView do
near_view = topic_view_near(p3)
expect(near_view.desired_post).to eq(p3)
expect(near_view.posts).to eq([p2, p3, p5])
expect(near_view.gaps.before).to eq({p5.id => [p4.id]})
expect(near_view.gaps.after).to eq({p5.id => [p6.id, p7.id]})
expect(near_view.gaps.before).to eq(p5.id => [p4.id])
expect(near_view.gaps.after).to eq(p5.id => [p6.id, p7.id])
end
it "returns deleted posts to an admin with show_deleted" do
@@ -390,8 +387,8 @@ describe TopicView do
expect(near_view.desired_post).to eq(p5)
# note: both p4 and p6 get skipped
expect(near_view.posts).to eq([p2, p3, p5])
expect(near_view.gaps.before).to eq({p5.id => [p4.id]})
expect(near_view.gaps.after).to eq({p5.id => [p6.id, p7.id]})
expect(near_view.gaps.before).to eq(p5.id => [p4.id])
expect(near_view.gaps.after).to eq(p5.id => [p6.id, p7.id])
end
it "returns deleted posts by nuked users to an admin with show_deleted" do
@@ -415,8 +412,8 @@ describe TopicView do
coding_horror.admin = true
near_view = topic_view_near(p5)
expect(near_view.posts).to eq([p1, p2, p3, p5])
expect(near_view.gaps.before).to eq({p5.id => [p4.id]})
expect(near_view.gaps.after).to eq({p5.id => [p6.id, p7.id]})
expect(near_view.gaps.before).to eq(p5.id => [p4.id])
expect(near_view.gaps.after).to eq(p5.id => [p6.id, p7.id])
end
it 'returns deleted posts to admins' do
@@ -497,4 +494,3 @@ describe TopicView do
end
end
end

View File

@@ -7,8 +7,7 @@ describe Trashable do
p1 = Fabricate(:post)
p2 = Fabricate(:post)
expect { p1.trash! }.to change{Post.count}.by(-1)
expect { p1.trash! }.to change { Post.count }.by(-1)
expect(Post.with_deleted.count).to eq(Post.count + 1)
end
end

View File

@@ -36,7 +36,6 @@ describe Unread do
end
end
describe 'unread_posts' do
it 'should have 0 unread posts if the user has seen all posts' do
topic_user.last_read_post_number = 13

View File

@@ -3,7 +3,7 @@ require 'rails_helper'
describe AllowedIpAddressValidator do
let(:record) { Fabricate.build(:user, trust_level: TrustLevel[0], ip_address: '99.232.23.123') }
let(:validator) { described_class.new({attributes: :ip_address}) }
let(:validator) { described_class.new(attributes: :ip_address) }
subject(:validate) { validator.validate_each(record, :ip_address, record.ip_address) }
context "ip address should be blocked" do

View File

@@ -2,9 +2,9 @@ require 'rails_helper'
describe EmailValidator do
let(:record) { }
let(:validator) { described_class.new({attributes: :email}) }
subject(:validate) { validator.validate_each(record,:email,record.email) }
let(:record) {}
let(:validator) { described_class.new(attributes: :email) }
subject(:validate) { validator.validate_each(record, :email, record.email) }
def blocks?(email)
user = Fabricate.build(:user, email: email)

View File

@@ -3,7 +3,7 @@ require 'rails_helper'
describe IpAddressFormatValidator do
let(:record) { Fabricate.build(:screened_ip_address, ip_address: '99.232.23.123') }
let(:validator) { described_class.new({attributes: :ip_address}) }
let(:validator) { described_class.new(attributes: :ip_address) }
subject(:validate) { validator.validate_each(record, :ip_address, record.ip_address) }
['99.232.23.123', '99.232.0.0/16', 'fd12:db8::ff00:42:8329', 'fc00::/7'].each do |arg|

View File

@@ -7,8 +7,8 @@ describe PasswordValidator do
I18n.t("activerecord.errors.models.user.attributes.password.#{key.to_s}")
end
let(:validator) { described_class.new({attributes: :password}) }
subject(:validate) { validator.validate_each(record,:password,@password) }
let(:validator) { described_class.new(attributes: :password) }
subject(:validate) { validator.validate_each(record, :password, @password) }
context "password required" do
let(:record) { u = Fabricate.build(:user, password: @password); u.password_required!; u }

View File

@@ -7,20 +7,20 @@ require 'ostruct'
module QualityTitleValidatorSpec
class Validatable < OpenStruct
include ActiveModel::Validations
validates :title, :quality_title => { :unless => :private_message? }
validates :title, quality_title: { unless: :private_message? }
end
end
describe "A record validated with QualityTitleValidator" do
let(:valid_title){ "hello this is my cool topic! welcome: all;" }
let(:short_title){ valid_title.slice(0, SiteSetting.min_topic_title_length - 1) }
let(:long_title ){ valid_title.center(SiteSetting.max_topic_title_length + 1, 'x') }
let(:xxxxx_title){ valid_title.gsub(/./,'x')}
let(:valid_title) { "hello this is my cool topic! welcome: all;" }
let(:short_title) { valid_title.slice(0, SiteSetting.min_topic_title_length - 1) }
let(:long_title) { valid_title.center(SiteSetting.max_topic_title_length + 1, 'x') }
let(:xxxxx_title) { valid_title.gsub(/./, 'x') }
subject(:topic){ QualityTitleValidatorSpec::Validatable.new }
subject(:topic) { QualityTitleValidatorSpec::Validatable.new }
before(:each) do
topic.stubs(:private_message? => false)
topic.stubs(private_message?: false)
end
it "allows a regular title with a few ascii characters" do
@@ -39,7 +39,7 @@ describe "A record validated with QualityTitleValidator" do
end
it "allows anything in a private message" do
topic.stubs(:private_message? => true)
topic.stubs(private_message?: true)
[short_title, long_title, xxxxx_title].each do |bad_title|
topic.title = bad_title
expect(topic).to be_valid
@@ -75,4 +75,3 @@ describe "A record validated with QualityTitleValidator" do
# end
# end
end

View File

@@ -7,8 +7,8 @@ describe TopicTitleLengthValidator do
# simulate Rails behavior (singleton)
def validate
@validator ||= TopicTitleLengthValidator.new({ attributes: :title })
@validator.validate_each(record,:title,record.title)
@validator ||= TopicTitleLengthValidator.new(attributes: :title)
@validator.validate_each(record, :title, record.title)
end
shared_examples "validating any topic title" do

View File

@@ -1,8 +1,8 @@
require "rails_helper"
describe UserFullNameValidator do
let(:validator) { described_class.new({attributes: :name}) }
subject(:validate) { validator.validate_each(record,:name,@name) }
let(:validator) { described_class.new(attributes: :name) }
subject(:validate) { validator.validate_each(record, :name, @name) }
let(:record) { Fabricate.build(:user, name: @name) }
context "name not required" do

View File

@@ -37,4 +37,3 @@ describe Discourse::VERSION do
end
end

View File

@@ -268,8 +268,8 @@ describe Wizard::StepUpdater do
context "invites step" do
let(:invites) {
return [{ email: 'regular@example.com', role: 'regular'},
{ email: 'moderator@example.com', role: 'moderator'}]
return [{ email: 'regular@example.com', role: 'regular' },
{ email: 'moderator@example.com', role: 'moderator' }]
}
it "updates the fields correctly" do

View File

@@ -131,7 +131,7 @@ describe Wizard do
admin = Fabricate(:admin)
wizard = build_simple(admin)
wizard.max_topics_to_require_completion = Topic.count-1
wizard.max_topics_to_require_completion = Topic.count - 1
expect(wizard.requires_completion?).to eq(false)
expect(SiteSetting.bypass_wizard_check).to eq(true)
@@ -148,7 +148,7 @@ describe Wizard do
it "is false for staff when complete" do
wizard = build_simple(Fabricate(:admin))
updater = wizard.create_updater('simple', name: 'Evil Trout')
updater = wizard.create_updater('simple', name: 'Evil Trout')
updater.update
expect(wizard.requires_completion?).to eq(false)

View File

@@ -13,7 +13,7 @@ describe Wizard::Step do
dropdown = step.add_field(id: 'snacks', type: 'dropdown')
dropdown.add_choice('candy')
dropdown.add_choice('nachos', data: {color: 'yellow'})
dropdown.add_choice('nachos', data: { color: 'yellow' })
dropdown.add_choice('pizza', label: 'Pizza!')
expect(step.fields).to eq([text, dropdown])
@@ -21,4 +21,3 @@ describe Wizard::Step do
end
end

View File

@@ -16,5 +16,4 @@ describe Admin::AdminController do
end
end

View File

@@ -89,7 +89,6 @@ describe Admin::BackupsController do
get :show, id: backup_filename, token: token
expect(response.headers['Content-Length']).to eq("5")
expect(response.headers['Content-Disposition']).to match(/attachment; filename/)
ensure

View File

@@ -48,16 +48,15 @@ describe Admin::BadgesController do
groupings.shuffle!
names = groupings.map{|g| g.name}
ids = groupings.map{|g| g.id.to_s}
names = groupings.map { |g| g.name }
ids = groupings.map { |g| g.id.to_s }
xhr :post, :save_badge_groupings, ids: ids, names: names
groupings2 = BadgeGrouping.all.order(:position).to_a
expect(groupings2.map{|g| g.name}).to eq(names)
expect((groupings.map(&:id) - groupings2.map{|g| g.id}).compact).to be_blank
expect(groupings2.map { |g| g.name }).to eq(names)
expect((groupings.map(&:id) - groupings2.map { |g| g.id }).compact).to be_blank
expect(::JSON.parse(response.body)["badge_groupings"].length).to eq(groupings2.length)
end

View File

@@ -10,8 +10,8 @@ describe Admin::ColorSchemesController do
let(:valid_params) { { color_scheme: {
name: 'Such Design',
colors: [
{name: 'primary', hex: 'FFBB00'},
{name: 'secondary', hex: '888888'}
{ name: 'primary', hex: 'FFBB00' },
{ name: 'secondary', hex: '888888' }
]
}
} }

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