diff --git a/ee/app/models/concerns/product_analytics/schema_validator.rb b/ee/app/models/concerns/product_analytics/schema_validator.rb index 5b8fc4d161d007b6c701685fd1f6af428e8c946a..140bfe8fe14d02a61b9430769651727d7dec7c59 100644 --- a/ee/app/models/concerns/product_analytics/schema_validator.rb +++ b/ee/app/models/concerns/product_analytics/schema_validator.rb @@ -3,7 +3,7 @@ module ProductAnalytics module SchemaValidator def schema_errors_for(yaml) - validator = JSONSchemer.schema(Pathname.new(self.class::SCHEMA_PATH)) + validator = JSONSchemer.schema(Pathname.new(Rails.root.join(self.class::SCHEMA_PATH))) validator_errors = validator.validate(yaml) validator_errors.map { |e| JSONSchemer::Errors.pretty(e) } if validator_errors.any? end diff --git a/ee/spec/models/product_analytics/visualization_spec.rb b/ee/spec/models/product_analytics/visualization_spec.rb index 174b6fb733ec175475e7b0e46b60b006222f0ce2..30cd6a21d413cbbe312432f0ce81fef6a2b20e63 100644 --- a/ee/spec/models/product_analytics/visualization_spec.rb +++ b/ee/spec/models/product_analytics/visualization_spec.rb @@ -47,6 +47,17 @@ end end + describe '#schema_errors_for' do + let(:dashboard) { dashboards.find { |d| d.title == 'Audience' } } + + it 'fetches correct schema path' do + allow(JSONSchemer).to receive(:schema).and_call_original + expect(JSONSchemer).to receive(:schema).with(Rails.root.join(described_class::SCHEMA_PATH)) + + dashboard.panels.first.visualization + end + end + describe '.for' do context 'when resource_parent is a Project' do subject { described_class.for(container: project, user: user) }