DEV: Fix spec regressions caused by test-prof change (#326)
The change in question: e6a3483c9a
This commit is contained in:
parent
3f96352a43
commit
9132153ae6
|
@ -1,6 +1,18 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module ::DiscourseDataExplorer
|
||||
class QueryFinder
|
||||
def self.find(id)
|
||||
default_query = Queries.default[id.to_s]
|
||||
return raise ActiveRecord::RecordNotFound unless default_query
|
||||
|
||||
query = Query.find_by(id: id) || Query.new
|
||||
query.attributes = default_query
|
||||
query.user_id = Discourse::SYSTEM_USER_ID.to_s
|
||||
query
|
||||
end
|
||||
end
|
||||
|
||||
class Query < ActiveRecord::Base
|
||||
self.table_name = "data_explorer_queries"
|
||||
|
||||
|
@ -35,15 +47,17 @@ module ::DiscourseDataExplorer
|
|||
end
|
||||
|
||||
def self.find(id)
|
||||
if id.to_i < 0
|
||||
default_query = Queries.default[id.to_s]
|
||||
return raise ActiveRecord::RecordNotFound unless default_query
|
||||
query = Query.find_by(id: id) || Query.new
|
||||
query.attributes = default_query
|
||||
query.user_id = Discourse::SYSTEM_USER_ID.to_s
|
||||
query
|
||||
else
|
||||
super
|
||||
return super if id.to_i >= 0
|
||||
QueryFinder.find(id)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# for `Query.unscoped.find`
|
||||
class ActiveRecord_Relation
|
||||
def find(id)
|
||||
return super if id.to_i >= 0
|
||||
QueryFinder.find(id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe DiscourseDataExplorer::Query do
|
||||
before { SiteSetting.data_explorer_enabled = true }
|
||||
|
||||
describe ".find" do
|
||||
it "returns default queries" do
|
||||
expect(DiscourseDataExplorer::Query.find(-1)).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
describe "unscoped .find" do
|
||||
it "returns default queries" do
|
||||
expect(DiscourseDataExplorer::Query.unscoped.find(-1)).to be_present
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue