Skip to content

Commit

Permalink
CircleCI 2.0 (#156)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
gogiel authored Jul 4, 2019
1 parent 12ff22a commit 1f1a4d3
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 39 deletions.
42 changes: 42 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 0 additions & 11 deletions circle.yml

This file was deleted.

2 changes: 0 additions & 2 deletions meta_request/lib/meta_request/config.rb
Original file line number Diff line number Diff line change
@@ -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'))
Expand Down
2 changes: 1 addition & 1 deletion meta_request/lib/meta_request/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
31 changes: 6 additions & 25 deletions meta_request/test/unit/meta_request/event_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 1f1a4d3

Please sign in to comment.