Skip to content

Commit 847ea41

Browse files
authored
Merge pull request #177 from alpaca-tc/support_rails6_1
Do not attempt to convert ActionDispatch::Request/Response to JSON
2 parents 4204111 + 4133c4e commit 847ea41

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

.circleci/config.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ jobs:
7070
- setup_remote_docker
7171
- run: docker-compose run --rm test-rails-6.0
7272

73+
test_rails_6_1:
74+
docker:
75+
- image: circleci/buildpack-deps
76+
working_directory: ~/project/meta_request
77+
steps:
78+
- checkout:
79+
path: ~/project
80+
- setup_remote_docker
81+
- run: docker-compose run --rm test-rails-6.1
82+
7383
workflows:
7484
version: 2
7585
test_all:
@@ -81,3 +91,4 @@ workflows:
8191
- test_rails_5_1
8292
- test_rails_5_2
8393
- test_rails_6_0
94+
- test_rails_6_1

meta_request/Dockerfile-rails-6.1

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM ruby:2.6-alpine
2+
3+
RUN apk add --update --no-cache \
4+
build-base curl-dev git sqlite-dev \
5+
yaml-dev zlib-dev nodejs yarn tzdata
6+
7+
RUN mkdir /app /gem
8+
WORKDIR /app
9+
10+
RUN gem install rails -v 6.1.0
11+
RUN rails new .
12+
13+
RUN bundle install
14+
15+
COPY . /gem
16+
17+
RUN gem build /gem/meta_request.gemspec
18+
RUN gem install /gem/meta_request-*.gem
19+
RUN bundle add meta_request
20+
RUN bundle install --local
21+
22+
COPY res/routes.rb /app/config/
23+
COPY res/dummy_controller.rb /app/app/controllers/
24+
COPY res/dummy /app/app/views/dummy
25+
COPY res/meta_request_test.rb /app/test/integration/
26+
27+
RUN bundle exec rails db:migrate
28+
29+
ENV PARALLEL_WORKERS 1
30+
31+
CMD ["bin/rake"]

meta_request/docker-compose.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ services:
2525
build:
2626
context: .
2727
dockerfile: Dockerfile-rails-6.0
28+
test-rails-6.1:
29+
build:
30+
context: .
31+
dockerfile: Dockerfile-rails-6.1

meta_request/lib/meta_request/event.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def json_encodable(payload)
4040
transform_hash(payload, deep: true) do |hash, key, value|
4141
if value.class.to_s == 'ActionDispatch::Http::Headers'
4242
value = value.to_h.select { |k, _| k.upcase == k }
43-
elsif defined?(ActiveRecord) && value.is_a?(ActiveRecord::ConnectionAdapters::AbstractAdapter)
43+
elsif not_encodable?(value)
4444
value = NOT_JSON_ENCODABLE
4545
end
4646

@@ -54,6 +54,12 @@ def json_encodable(payload)
5454
end.with_indifferent_access
5555
end
5656

57+
def not_encodable?(value)
58+
(defined?(ActiveRecord) && value.is_a?(ActiveRecord::ConnectionAdapters::AbstractAdapter)) ||
59+
(defined?(ActionDispatch) &&
60+
(value.is_a?(ActionDispatch::Request) || value.is_a?(ActionDispatch::Response)))
61+
end
62+
5763
# https://gist.github.com/dbenhur/1070399
5864
def transform_hash(original, options = {}, &block)
5965
options[:safe_descent] ||= {}

0 commit comments

Comments
 (0)