No more rails 4 deprecation warnings
This commit is contained in:
parent
b32e87c929
commit
d87389b38e
|
@ -43,9 +43,9 @@ class Category < ActiveRecord::Base
|
||||||
scope :secured, ->(guardian = nil) {
|
scope :secured, ->(guardian = nil) {
|
||||||
ids = guardian.secure_category_ids if guardian
|
ids = guardian.secure_category_ids if guardian
|
||||||
if ids.present?
|
if ids.present?
|
||||||
where("NOT categories.read_restricted or categories.id in (:cats)", cats: ids)
|
where("NOT categories.read_restricted or categories.id in (:cats)", cats: ids).references(:categories)
|
||||||
else
|
else
|
||||||
where("NOT categories.read_restricted")
|
where("NOT categories.read_restricted").references(:categories)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ class Category < ActiveRecord::Base
|
||||||
|
|
||||||
def self.scoped_to_permissions(guardian, permission_types)
|
def self.scoped_to_permissions(guardian, permission_types)
|
||||||
if guardian && guardian.is_staff?
|
if guardian && guardian.is_staff?
|
||||||
scoped
|
rails4? ? all : scoped
|
||||||
else
|
else
|
||||||
permission_types = permission_types.map{ |permission_type|
|
permission_types = permission_types.map{ |permission_type|
|
||||||
CategoryGroup.permission_types[permission_type]
|
CategoryGroup.permission_types[permission_type]
|
||||||
|
|
|
@ -89,7 +89,8 @@ class IncomingLinksReport
|
||||||
num_clicks = link_count_per_topic
|
num_clicks = link_count_per_topic
|
||||||
num_clicks = num_clicks.to_a.sort_by {|x| x[1]}.last(10).reverse # take the top 10
|
num_clicks = num_clicks.to_a.sort_by {|x| x[1]}.last(10).reverse # take the top 10
|
||||||
report.data = []
|
report.data = []
|
||||||
topics = Topic.select('id, slug, title').where('id in (?)', num_clicks.map {|z| z[0]}).all
|
topics = Topic.select('id, slug, title').where('id in (?)', num_clicks.map {|z| z[0]})
|
||||||
|
topics = topics.all unless rails4?
|
||||||
num_clicks.each do |topic_id, num_clicks_element|
|
num_clicks.each do |topic_id, num_clicks_element|
|
||||||
topic = topics.find {|t| t.id == topic_id}
|
topic = topics.find {|t| t.id == topic_id}
|
||||||
if topic
|
if topic
|
||||||
|
|
|
@ -135,7 +135,7 @@ class User < ActiveRecord::Base
|
||||||
{ username_lower: username_or_email.downcase }
|
{ username_lower: username_or_email.downcase }
|
||||||
end
|
end
|
||||||
|
|
||||||
users = User.where(conditions).all
|
users = User.where(conditions).to_a
|
||||||
|
|
||||||
if users.size > 1
|
if users.size > 1
|
||||||
raise Discourse::TooManyMatches
|
raise Discourse::TooManyMatches
|
||||||
|
@ -504,7 +504,7 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def secure_category_ids
|
def secure_category_ids
|
||||||
cats = self.staff? ? Category.select(:id).where(read_restricted: true) : secure_categories.select('categories.id')
|
cats = self.staff? ? Category.select(:id).where(read_restricted: true) : secure_categories.select('categories.id').references(:categories)
|
||||||
cats.map { |c| c.id }.sort
|
cats.map { |c| c.id }.sort
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -115,10 +115,10 @@ class Search
|
||||||
def category_search
|
def category_search
|
||||||
categories = Category.includes(:category_search_data)
|
categories = Category.includes(:category_search_data)
|
||||||
.where("category_search_data.search_data @@ #{ts_query}")
|
.where("category_search_data.search_data @@ #{ts_query}")
|
||||||
|
.references(:category_search_data)
|
||||||
.order("topics_month DESC")
|
.order("topics_month DESC")
|
||||||
.secured(@guardian)
|
.secured(@guardian)
|
||||||
.limit(@limit)
|
.limit(@limit)
|
||||||
.references(:category_search_data)
|
|
||||||
|
|
||||||
categories.each do |c|
|
categories.each do |c|
|
||||||
@results.add_result(SearchResult.from_category(c))
|
@results.add_result(SearchResult.from_category(c))
|
||||||
|
@ -164,9 +164,9 @@ class Search
|
||||||
.order("topics.bumped_at DESC")
|
.order("topics.bumped_at DESC")
|
||||||
|
|
||||||
if secure_category_ids.present?
|
if secure_category_ids.present?
|
||||||
posts = posts.where("(categories.id IS NULL) OR (NOT categories.read_restricted) OR (categories.id IN (?))", secure_category_ids)
|
posts = posts.where("(categories.id IS NULL) OR (NOT categories.read_restricted) OR (categories.id IN (?))", secure_category_ids).references(:categories)
|
||||||
else
|
else
|
||||||
posts = posts.where("(categories.id IS NULL) OR (NOT categories.read_restricted)")
|
posts = posts.where("(categories.id IS NULL) OR (NOT categories.read_restricted)").references(:categories)
|
||||||
end
|
end
|
||||||
posts.limit(limit)
|
posts.limit(limit)
|
||||||
end
|
end
|
||||||
|
|
|
@ -72,7 +72,7 @@ describe Admin::GroupsController do
|
||||||
usernames: usernames,
|
usernames: usernames,
|
||||||
name: " bob "
|
name: " bob "
|
||||||
}
|
}
|
||||||
}.should_not raise_error(ActiveRecord::RecordInvalid)
|
}.should_not raise_error()
|
||||||
Group.where(name: "bob").count.should == 1
|
Group.where(name: "bob").count.should == 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -214,7 +214,7 @@ describe PostAction do
|
||||||
u1 = Fabricate(:evil_trout)
|
u1 = Fabricate(:evil_trout)
|
||||||
PostAction.act(u1, post, PostActionType.types[:spam])
|
PostAction.act(u1, post, PostActionType.types[:spam])
|
||||||
PostAction.remove_act(u1, post, PostActionType.types[:spam])
|
PostAction.remove_act(u1, post, PostActionType.types[:spam])
|
||||||
lambda { PostAction.act(u1, post, PostActionType.types[:off_topic]) }.should_not raise_error(PostAction::AlreadyActed)
|
lambda { PostAction.act(u1, post, PostActionType.types[:off_topic]) }.should_not raise_error()
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should update counts when you clear flags' do
|
it 'should update counts when you clear flags' do
|
||||||
|
|
|
@ -913,7 +913,7 @@ describe User do
|
||||||
|
|
||||||
context 'when multiple users are found' do
|
context 'when multiple users are found' do
|
||||||
it 'raises an exception' do
|
it 'raises an exception' do
|
||||||
user_query = stub(all: [stub, stub])
|
user_query = stub(to_a: [stub, stub])
|
||||||
User.stubs(:where).with(username_lower: 'bob').returns(user_query)
|
User.stubs(:where).with(username_lower: 'bob').returns(user_query)
|
||||||
|
|
||||||
expect { User.find_by_username_or_email('bob') }.to raise_error(Discourse::TooManyMatches)
|
expect { User.find_by_username_or_email('bob') }.to raise_error(Discourse::TooManyMatches)
|
||||||
|
|
Loading…
Reference in New Issue