Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gemspec-author.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"posthog-ruby": patch
---

Set the gem author to PostHog. The gemspec listed an empty author.
5 changes: 5 additions & 0 deletions .changeset/rails-facade-evaluate-flags.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"posthog-rails": patch
---

`PostHog.evaluate_flags` is now defined on the Rails facade next to the other flag methods, instead of reaching the client only through `method_missing`. Use it in place of the deprecated `PostHog.is_feature_enabled` and `PostHog.get_feature_flag`.
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ updates:
interval: "weekly"
cooldown:
default-days: 7
ignore:
# commander 6 requires Ruby 3.1, but Dependabot resolves with the gemspec's Ruby 3.0 floor.
- dependency-name: "commander"
update-types: ["version-update:semver-major"]
groups:
bundler-dependencies:
patterns:
Expand Down
1 change: 1 addition & 0 deletions posthog-rails/lib/posthog/rails/facade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def ensure_initialized!
identify
alias
group_identify
evaluate_flags
is_feature_enabled
get_feature_flag
get_all_flags
Expand Down
2 changes: 1 addition & 1 deletion posthog-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
spec.executables = ['posthog']
spec.summary = 'PostHog library'
spec.description = 'The PostHog ruby library'
spec.authors = ['']
spec.authors = ['PostHog']
spec.email = 'engineering@posthog.com'
spec.homepage = 'https://github.com/PostHog/posthog-ruby'
spec.license = 'MIT'
Expand Down
1 change: 1 addition & 0 deletions public_api_snapshot.txt
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ class_method PostHog.capture(*args, **kwargs, &block)
class_method PostHog.capture_exception(*args, **kwargs, &block)
class_method PostHog.client()
class_method PostHog.client=(arg0)
class_method PostHog.evaluate_flags(*args, **kwargs, &block)
class_method PostHog.get_all_flags(*args, **kwargs, &block)
class_method PostHog.get_feature_flag(*args, **kwargs, &block)
class_method PostHog.group_identify(*args, **kwargs, &block)
Expand Down
2 changes: 1 addition & 1 deletion spec/posthog/feature_flag_evaluations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ def capture_stderr
end
end

describe 'Phase 2 deprecation warnings' do
describe 'Phase 2 deprecation warnings', :deprecation_warnings do
it 'is_feature_enabled emits a deprecation warning pointing at evaluate_flags' do
stub_flags(flags_response)
out = capture_stderr { client.is_feature_enabled('boolean-flag', 'user-1') }
Expand Down
21 changes: 21 additions & 0 deletions spec/posthog/rails/railtie_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,27 @@
expect(logger).not_to have_received(:error)
end

it 'delegates evaluate_flags explicitly with its arguments' do
snapshot = instance_double(PostHog::FeatureFlagEvaluations)
client = instance_double(PostHog::Client)
allow(client).to receive(:evaluate_flags).and_return(snapshot)
PostHog.client = client

expect(PostHog.singleton_class.instance_method(:evaluate_flags).owner).to eq(PostHog.singleton_class)
expect(PostHog.evaluate_flags('user', groups: { company: 'acme' }, flag_keys: ['beta'])).to be(snapshot)
expect(client).to have_received(:evaluate_flags).with('user', groups: { company: 'acme' }, flag_keys: ['beta'])
end

it 'evaluates flags through the facade without deprecation warnings', :deprecation_warnings do
client = PostHog.init(api_key: 'phc_test', test_mode: true)

expect do
expect(PostHog.evaluate_flags('user', only_evaluate_locally: true)).to be_a(PostHog::FeatureFlagEvaluations)
end.not_to output.to_stderr
ensure
client&.shutdown
end

it 'shuts down the previous client when init is called again' do
previous_client = instance_spy(PostHog::Client)
PostHog.client = previous_client
Expand Down
23 changes: 23 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,34 @@
require 'active_support/all'
require 'webmock/rspec'

# Specs still cover the deprecated flag APIs, and each spec builds a new client, so the
# once-per-client deprecation warnings would flood the output. Tag an example or group
# with `:deprecation_warnings` to let them through.
module PostHogDeprecationWarningFilter
class << self
attr_accessor :silenced
end

def warn(message, *args, **kwargs)
return if PostHogDeprecationWarningFilter.silenced && message.include?('[posthog-ruby] DEPRECATION:')

super
end
end
Warning.singleton_class.prepend(PostHogDeprecationWarningFilter)

RSpec.configure do |config|
config.before(:each) do
PostHog::Logging.logger = Logger.new(File::NULL) # Suppress all logging
PostHog::Client.reset_instance_tracking!
end

config.around(:each) do |example|
PostHogDeprecationWarningFilter.silenced = !example.metadata[:deprecation_warnings]
example.run
ensure
PostHogDeprecationWarningFilter.silenced = false
end
end

# Setting timezone for ActiveSupport::TimeWithZone to UTC
Expand Down
Loading