Commit 697ab2f4 authored by Alishan Ladhani's avatar Alishan Ladhani

Remove namespace and project serialization from StandardContext

parent b7b7a5d6
......@@ -11,24 +11,12 @@ module Gitlab
@data = data
end
def namespace_id
namespace&.id
end
def project_id
@project&.id
end
def to_context
SnowplowTracker::SelfDescribingJson.new(GITLAB_STANDARD_SCHEMA_URL, to_h)
end
private
def namespace
@namespace || @project&.namespace
end
def to_h
public_methods(false).each_with_object({}) do |method, hash|
next if method == :to_context
......
......@@ -28,8 +28,8 @@ RSpec.describe Gitlab::Tracking::StandardContext do
context 'with namespace' do
subject { described_class.new(namespace: namespace) }
it 'creates a Snowplow context using the given data' do
expect(snowplow_context.to_json.dig(:data, :namespace_id)).to eq(namespace.id)
it 'creates a Snowplow context without namespace and project' do
expect(snowplow_context.to_json.dig(:data, :namespace_id)).to be_nil
expect(snowplow_context.to_json.dig(:data, :project_id)).to be_nil
end
end
......@@ -37,18 +37,18 @@ RSpec.describe Gitlab::Tracking::StandardContext do
context 'with project' do
subject { described_class.new(project: project) }
it 'creates a Snowplow context using the given data' do
expect(snowplow_context.to_json.dig(:data, :namespace_id)).to eq(project.namespace.id)
expect(snowplow_context.to_json.dig(:data, :project_id)).to eq(project.id)
it 'creates a Snowplow context without namespace and project' do
expect(snowplow_context.to_json.dig(:data, :namespace_id)).to be_nil
expect(snowplow_context.to_json.dig(:data, :project_id)).to be_nil
end
end
context 'with project and namespace' do
subject { described_class.new(namespace: namespace, project: project) }
it 'creates a Snowplow context using the given data' do
expect(snowplow_context.to_json.dig(:data, :namespace_id)).to eq(namespace.id)
expect(snowplow_context.to_json.dig(:data, :project_id)).to eq(project.id)
it 'creates a Snowplow context without namespace and project' do
expect(snowplow_context.to_json.dig(:data, :namespace_id)).to be_nil
expect(snowplow_context.to_json.dig(:data, :project_id)).to be_nil
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment