Skip to content

Commit 1f1a4d3

Browse files
authored
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
1 parent 12ff22a commit 1f1a4d3

File tree

5 files changed

+49
-39
lines changed

5 files changed

+49
-39
lines changed

.circleci/config.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
version: 2
2+
jobs:
3+
unit_tests:
4+
working_directory: ~/project/meta_request
5+
docker:
6+
- image: circleci/ruby:2.6.3-node-browsers
7+
steps:
8+
- checkout:
9+
path: ~/project
10+
- restore_cache:
11+
key: main-bundle-{{ checksum "Gemfile" }}
12+
- run: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
13+
# Store bundle cache
14+
- save_cache:
15+
key: main-bundle-{{ checksum "Gemfile" }}
16+
paths:
17+
- vendor/bundle
18+
- run: bundle exec rake test
19+
20+
test_rails_5_1:
21+
working_directory: ~/project/meta_request/test/functional/rails-5.1.1
22+
docker:
23+
- image: circleci/ruby:2.6.3-node-browsers
24+
steps:
25+
- checkout:
26+
path: ~/project
27+
- restore_cache:
28+
key: rails-5-1-bundle-{{ checksum "Gemfile" }}
29+
- run: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
30+
# Store bundle cache
31+
- save_cache:
32+
key: rails-5-1-bundle-{{ checksum "Gemfile" }}
33+
paths:
34+
- vendor/bundle
35+
- run: bundle exec rake test
36+
37+
workflows:
38+
version: 2
39+
test_everything:
40+
jobs:
41+
- unit_tests
42+
- test_rails_5_1

circle.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

meta_request/lib/meta_request/config.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
module MetaRequest
22
class Config
3-
attr_accessor :logger, :storage_pool_size
4-
53
# logger used for reporting gem's fatal errors
64
def logger
75
@logger ||= Logger.new(File.join(Rails.root, 'log', 'meta_request.log'))

meta_request/lib/meta_request/event.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def json_encodable(payload)
3838
transform_hash(payload, :deep => true) { |hash, key, value|
3939
if value.class.to_s == 'ActionDispatch::Http::Headers'
4040
value = value.to_h.select { |k, _| k.upcase == k }
41-
elsif value.is_a?(ActiveRecord::ConnectionAdapters::AbstractAdapter)
41+
elsif defined?(ActiveRecord) && value.is_a?(ActiveRecord::ConnectionAdapters::AbstractAdapter)
4242
value = NOT_JSON_ENCODABLE
4343
end
4444

meta_request/test/unit/meta_request/event_test.rb

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,14 @@
11
require 'test_helper'
2-
require 'tempfile'
32

43
describe MetaRequest::Event do
5-
describe 'ignore_closed_tempfile_params' do
4+
describe "ignores objects that can't be encoded as json" do
65
it 'sets closed tempfiles in params to strings on create' do
7-
tempfile = Tempfile.new('foo')
8-
payload = {:params => {"user" => {"upload" => OpenStruct.new(:tempfile => tempfile)} } }.with_indifferent_access
9-
event_1 = MetaRequest::Event.new('process_action.action_controller', 10, 11, 1705, payload)
10-
assert_same tempfile, event_1.payload[:params][:user][:upload].tempfile
6+
not_serializable_object = Object.new
7+
not_serializable_object.define_singleton_method(:to_json) { raise "error" }
8+
payload = {:params => {"user" => {"upload" => not_serializable_object} } }.with_indifferent_access
119

12-
payload[:params][:user][:upload].tempfile.close
13-
event_2 = MetaRequest::Event.new('process_action.action_controller', 10, 11, 1705, payload)
14-
assert_equal 'Not JSON Encodable', event_2.payload[:params][:user][:upload]
15-
end
16-
end
17-
18-
describe 'filter closed io objects in payload since they error on to_json' do
19-
before do
20-
io = Tempfile.new('foo')
21-
io.close
22-
@event = MetaRequest::Event.new('sql.active_record', 10, 11, 1705, {:sql => 'select now();', :binds => io})
23-
end
24-
25-
it 'should be filtered out' do
26-
assert_equal({'sql' => 'select now();', 'binds' => 'Not JSON Encodable'}, @event.payload)
27-
end
28-
29-
it 'should work to_json' do
30-
@event.payload.to_json
10+
event = MetaRequest::Event.new('process_action.action_controller', 10, 11, 1705, payload)
11+
assert_equal 'Not JSON Encodable', event.payload[:params][:user][:upload]
3112
end
3213
end
3314
end

0 commit comments

Comments
 (0)