diff --git a/.gitignore b/.gitignore index 9e998e64..d327dbe8 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ mkmf.log *.gem .DS_Store +Gemfile.lock \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index ff4cdf63..00000000 --- a/Gemfile.lock +++ /dev/null @@ -1,116 +0,0 @@ -PATH - remote: . - specs: - launchdarkly-server-sdk (6.0.0) - concurrent-ruby (~> 1.1) - http (~> 4.4.1) - json (~> 2.3.1) - ld-eventsource (~> 2.0) - semantic (~> 1.6) - -GEM - remote: https://rubygems.org/ - specs: - addressable (2.7.0) - public_suffix (>= 2.0.2, < 5.0) - ansi (1.5.0) - ast (2.4.2) - aws-eventstream (1.1.0) - aws-partitions (1.418.0) - aws-sdk-core (3.111.2) - aws-eventstream (~> 1, >= 1.0.2) - aws-partitions (~> 1, >= 1.239.0) - aws-sigv4 (~> 1.1) - jmespath (~> 1.0) - aws-sdk-dynamodb (1.58.0) - aws-sdk-core (~> 3, >= 3.109.0) - aws-sigv4 (~> 1.1) - aws-sigv4 (1.2.2) - aws-eventstream (~> 1, >= 1.0.2) - concurrent-ruby (1.1.8) - connection_pool (2.2.3) - deep_merge (1.2.1) - diff-lcs (1.4.4) - diplomat (2.4.2) - deep_merge (~> 1.0, >= 1.0.1) - faraday (>= 0.9, < 1.1.0) - domain_name (0.5.20190701) - unf (>= 0.0.5, < 1.0.0) - faraday (1.0.1) - multipart-post (>= 1.2, < 3) - ffi (1.14.2) - ffi-compiler (1.0.1) - ffi (>= 1.0.0) - rake - http (4.4.1) - addressable (~> 2.3) - http-cookie (~> 1.0) - http-form_data (~> 2.2) - http-parser (~> 1.2.0) - http-cookie (1.0.3) - domain_name (~> 0.5) - http-form_data (2.3.0) - http-parser (1.2.3) - ffi-compiler (>= 1.0, < 2.0) - jmespath (1.4.0) - json (2.3.1) - ld-eventsource (2.0.0) - concurrent-ruby (~> 1.0) - http (~> 4.4.1) - listen (3.4.1) - rb-fsevent (~> 0.10, >= 0.10.3) - rb-inotify (~> 0.9, >= 0.9.10) - multipart-post (2.1.1) - oga (2.15) - ast - ruby-ll (~> 2.1) - public_suffix (4.0.6) - rake (13.0.3) - rb-fsevent (0.10.4) - rb-inotify (0.10.1) - ffi (~> 1.0) - redis (4.2.5) - rspec (3.10.0) - rspec-core (~> 3.10.0) - rspec-expectations (~> 3.10.0) - rspec-mocks (~> 3.10.0) - rspec-core (3.10.1) - rspec-support (~> 3.10.0) - rspec-expectations (3.10.1) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-mocks (3.10.1) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-support (3.10.1) - rspec_junit_formatter (0.4.1) - rspec-core (>= 2, < 4, != 2.12.0) - ruby-ll (2.1.2) - ansi - ast - semantic (1.6.1) - timecop (0.9.2) - unf (0.1.4) - unf_ext - unf_ext (0.0.7.7) - webrick (1.7.0) - -PLATFORMS - ruby - -DEPENDENCIES - aws-sdk-dynamodb (~> 1.57) - bundler (~> 2.1) - connection_pool (~> 2.2.3) - diplomat (~> 2.4.2) - launchdarkly-server-sdk! - listen (~> 3.3) - oga (~> 2.2) - redis (~> 4.2) - rspec (~> 3.10) - rspec_junit_formatter (~> 0.4) - timecop (~> 0.9) - webrick (~> 1.7) - -BUNDLED WITH - 2.2.3 diff --git a/azure-pipelines.yml b/azure-pipelines.yml index cb66e704..88296f02 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -45,7 +45,7 @@ jobs: workingDirectory: $(System.DefaultWorkingDirectory) script: | ruby -v - gem install bundler:2.2.7 + gem install bundler bundle install mkdir rspec bundle exec rspec --format progress --format RspecJunitFormatter -o ./rspec/rspec.xml spec diff --git a/lib/ldclient-rb/events.rb b/lib/ldclient-rb/events.rb index c59db7d0..7b77c4db 100644 --- a/lib/ldclient-rb/events.rb +++ b/lib/ldclient-rb/events.rb @@ -443,7 +443,7 @@ def make_output_event(event) if @inline_users || is_debug out[:user] = process_user(event) else - out[:userKey] = event[:user].nil? ? nil : event[:user][:key] + out[:userKey] = event[:user][:key] end out[:reason] = event[:reason] if !event[:reason].nil? out @@ -451,7 +451,7 @@ def make_output_event(event) { kind: "identify", creationDate: event[:creationDate], - key: event[:user].nil? ? nil : event[:user][:key].to_s, + key: event[:user][:key].to_s, user: process_user(event) } when "custom" @@ -464,7 +464,7 @@ def make_output_event(event) if @inline_users out[:user] = process_user(event) else - out[:userKey] = event[:user].nil? ? nil : event[:user][:key] + out[:userKey] = event[:user][:key] end out[:metricValue] = event[:metricValue] if event.has_key?(:metricValue) out[:contextKind] = event[:contextKind] if event.has_key?(:contextKind) diff --git a/lib/ldclient-rb/ldclient.rb b/lib/ldclient-rb/ldclient.rb index 5d803ef3..37d80e9a 100644 --- a/lib/ldclient-rb/ldclient.rb +++ b/lib/ldclient-rb/ldclient.rb @@ -401,6 +401,12 @@ def evaluate_internal(key, user, default, event_factory) return Evaluator.error_result(EvaluationReason::ERROR_CLIENT_NOT_READY, default) end + unless user + @config.logger.error { "[LDClient] Must specify user" } + detail = Evaluator.error_result(EvaluationReason::ERROR_USER_NOT_SPECIFIED, default) + return detail + end + if !initialized? if @store.initialized? @config.logger.warn { "[LDClient] Client has not finished initializing; using last known values from feature store" } @@ -421,13 +427,6 @@ def evaluate_internal(key, user, default, event_factory) return detail end - unless user - @config.logger.error { "[LDClient] Must specify user" } - detail = Evaluator.error_result(EvaluationReason::ERROR_USER_NOT_SPECIFIED, default) - @event_processor.add_event(event_factory.new_default_event(feature, user, default, detail.reason)) - return detail - end - begin res = @evaluator.evaluate(feature, user, event_factory) if !res.events.nil? diff --git a/spec/ldclient_spec.rb b/spec/ldclient_spec.rb index f7d215e2..cad4c03c 100644 --- a/spec/ldclient_spec.rb +++ b/spec/ldclient_spec.rb @@ -145,19 +145,11 @@ def event_processor client.variation("key", user, "default") end - it "queues a feature event for an existing feature when user is nil" do + it "does not send an event if user is nil" do config.feature_store.init({ LaunchDarkly::FEATURES => {} }) config.feature_store.upsert(LaunchDarkly::FEATURES, feature_with_value) - expect(event_processor).to receive(:add_event).with(hash_including( - kind: "feature", - key: "key", - version: 100, - user: nil, - value: "default", - default: "default", - trackEvents: true, - debugEventsUntilDate: 1000 - )) + expect(event_processor).not_to receive(:add_event) + expect(logger).to receive(:error) client.variation("key", nil, "default") end @@ -313,6 +305,14 @@ def event_processor )) client.variation_detail("key", user, "default") end + + it "does not send an event if user is nil" do + config.feature_store.init({ LaunchDarkly::FEATURES => {} }) + config.feature_store.upsert(LaunchDarkly::FEATURES, feature_with_value) + expect(event_processor).not_to receive(:add_event) + expect(logger).to receive(:error) + client.variation_detail("key", nil, "default") + end end describe '#all_flags' do