DEV: Fix spec regressions caused by test-prof change (#326)

The change in question: e6a3483c9a
This commit is contained in:
Jarek Radosz 2024-09-08 21:22:27 +02:00 committed by GitHub
parent 3f96352a43
commit 9132153ae6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 40 additions and 9 deletions

View File

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

17
spec/models/query_spec.rb Normal file
View File

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