From 1f1a4d309596d39bb81213361458d99f5740505b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20J=C4=99drychowski?= Date: Thu, 4 Jul 2019 23:29:20 +0200 Subject: [PATCH] CircleCI 2.0 (#156) * Updated CircleCI config to 2.0 * updated tests. Now nearly all objects support to_json * added additional defined?(ActiveRecord) check. Fixes #152 * fixed method redefinition warning --- .circleci/config.yml | 42 +++++++++++++++++++ circle.yml | 11 ----- meta_request/lib/meta_request/config.rb | 2 - meta_request/lib/meta_request/event.rb | 2 +- .../test/unit/meta_request/event_test.rb | 31 +++----------- 5 files changed, 49 insertions(+), 39 deletions(-) create mode 100644 .circleci/config.yml delete mode 100644 circle.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..267c276 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,42 @@ +version: 2 +jobs: + unit_tests: + working_directory: ~/project/meta_request + docker: + - image: circleci/ruby:2.6.3-node-browsers + steps: + - checkout: + path: ~/project + - restore_cache: + key: main-bundle-{{ checksum "Gemfile" }} + - run: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3 + # Store bundle cache + - save_cache: + key: main-bundle-{{ checksum "Gemfile" }} + paths: + - vendor/bundle + - run: bundle exec rake test + + test_rails_5_1: + working_directory: ~/project/meta_request/test/functional/rails-5.1.1 + docker: + - image: circleci/ruby:2.6.3-node-browsers + steps: + - checkout: + path: ~/project + - restore_cache: + key: rails-5-1-bundle-{{ checksum "Gemfile" }} + - run: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3 + # Store bundle cache + - save_cache: + key: rails-5-1-bundle-{{ checksum "Gemfile" }} + paths: + - vendor/bundle + - run: bundle exec rake test + +workflows: + version: 2 + test_everything: + jobs: + - unit_tests + - test_rails_5_1 diff --git a/circle.yml b/circle.yml deleted file mode 100644 index eab0c3d..0000000 --- a/circle.yml +++ /dev/null @@ -1,11 +0,0 @@ -machine: - ruby: - version: 2.2.2 -general: - build_dir: meta_request -test: - override: - - bundle exec rake test TESTOPTS="--ci-dir=$CIRCLE_TEST_REPORTS": - parallel: true - files: - - test/**/*_test.rb diff --git a/meta_request/lib/meta_request/config.rb b/meta_request/lib/meta_request/config.rb index 5a49b7d..0c686fd 100644 --- a/meta_request/lib/meta_request/config.rb +++ b/meta_request/lib/meta_request/config.rb @@ -1,7 +1,5 @@ module MetaRequest class Config - attr_accessor :logger, :storage_pool_size - # logger used for reporting gem's fatal errors def logger @logger ||= Logger.new(File.join(Rails.root, 'log', 'meta_request.log')) diff --git a/meta_request/lib/meta_request/event.rb b/meta_request/lib/meta_request/event.rb index c627557..61abe04 100644 --- a/meta_request/lib/meta_request/event.rb +++ b/meta_request/lib/meta_request/event.rb @@ -38,7 +38,7 @@ def json_encodable(payload) transform_hash(payload, :deep => true) { |hash, key, value| if value.class.to_s == 'ActionDispatch::Http::Headers' value = value.to_h.select { |k, _| k.upcase == k } - elsif value.is_a?(ActiveRecord::ConnectionAdapters::AbstractAdapter) + elsif defined?(ActiveRecord) && value.is_a?(ActiveRecord::ConnectionAdapters::AbstractAdapter) value = NOT_JSON_ENCODABLE end diff --git a/meta_request/test/unit/meta_request/event_test.rb b/meta_request/test/unit/meta_request/event_test.rb index 87fa8e4..7114f9f 100644 --- a/meta_request/test/unit/meta_request/event_test.rb +++ b/meta_request/test/unit/meta_request/event_test.rb @@ -1,33 +1,14 @@ require 'test_helper' -require 'tempfile' describe MetaRequest::Event do - describe 'ignore_closed_tempfile_params' do + describe "ignores objects that can't be encoded as json" do it 'sets closed tempfiles in params to strings on create' do - tempfile = Tempfile.new('foo') - payload = {:params => {"user" => {"upload" => OpenStruct.new(:tempfile => tempfile)} } }.with_indifferent_access - event_1 = MetaRequest::Event.new('process_action.action_controller', 10, 11, 1705, payload) - assert_same tempfile, event_1.payload[:params][:user][:upload].tempfile + not_serializable_object = Object.new + not_serializable_object.define_singleton_method(:to_json) { raise "error" } + payload = {:params => {"user" => {"upload" => not_serializable_object} } }.with_indifferent_access - payload[:params][:user][:upload].tempfile.close - event_2 = MetaRequest::Event.new('process_action.action_controller', 10, 11, 1705, payload) - assert_equal 'Not JSON Encodable', event_2.payload[:params][:user][:upload] - end - end - - describe 'filter closed io objects in payload since they error on to_json' do - before do - io = Tempfile.new('foo') - io.close - @event = MetaRequest::Event.new('sql.active_record', 10, 11, 1705, {:sql => 'select now();', :binds => io}) - end - - it 'should be filtered out' do - assert_equal({'sql' => 'select now();', 'binds' => 'Not JSON Encodable'}, @event.payload) - end - - it 'should work to_json' do - @event.payload.to_json + event = MetaRequest::Event.new('process_action.action_controller', 10, 11, 1705, payload) + assert_equal 'Not JSON Encodable', event.payload[:params][:user][:upload] end end end