Skip to content

Commit

Permalink
Merge pull request #177 from alpaca-tc/support_rails6_1
Browse files Browse the repository at this point in the history
Do not attempt to convert ActionDispatch::Request/Response to JSON
  • Loading branch information
dejan authored Mar 18, 2021
2 parents 4204111 + 4133c4e commit 847ea41
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
11 changes: 11 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ jobs:
- setup_remote_docker
- run: docker-compose run --rm test-rails-6.0

test_rails_6_1:
docker:
- image: circleci/buildpack-deps
working_directory: ~/project/meta_request
steps:
- checkout:
path: ~/project
- setup_remote_docker
- run: docker-compose run --rm test-rails-6.1

workflows:
version: 2
test_all:
Expand All @@ -81,3 +91,4 @@ workflows:
- test_rails_5_1
- test_rails_5_2
- test_rails_6_0
- test_rails_6_1
31 changes: 31 additions & 0 deletions meta_request/Dockerfile-rails-6.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM ruby:2.6-alpine

RUN apk add --update --no-cache \
build-base curl-dev git sqlite-dev \
yaml-dev zlib-dev nodejs yarn tzdata

RUN mkdir /app /gem
WORKDIR /app

RUN gem install rails -v 6.1.0
RUN rails new .

RUN bundle install

COPY . /gem

RUN gem build /gem/meta_request.gemspec
RUN gem install /gem/meta_request-*.gem
RUN bundle add meta_request
RUN bundle install --local

COPY res/routes.rb /app/config/
COPY res/dummy_controller.rb /app/app/controllers/
COPY res/dummy /app/app/views/dummy
COPY res/meta_request_test.rb /app/test/integration/

RUN bundle exec rails db:migrate

ENV PARALLEL_WORKERS 1

CMD ["bin/rake"]
4 changes: 4 additions & 0 deletions meta_request/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ services:
build:
context: .
dockerfile: Dockerfile-rails-6.0
test-rails-6.1:
build:
context: .
dockerfile: Dockerfile-rails-6.1
8 changes: 7 additions & 1 deletion meta_request/lib/meta_request/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def json_encodable(payload)
transform_hash(payload, deep: true) do |hash, key, value|
if value.class.to_s == 'ActionDispatch::Http::Headers'
value = value.to_h.select { |k, _| k.upcase == k }
elsif defined?(ActiveRecord) && value.is_a?(ActiveRecord::ConnectionAdapters::AbstractAdapter)
elsif not_encodable?(value)
value = NOT_JSON_ENCODABLE
end

Expand All @@ -54,6 +54,12 @@ def json_encodable(payload)
end.with_indifferent_access
end

def not_encodable?(value)
(defined?(ActiveRecord) && value.is_a?(ActiveRecord::ConnectionAdapters::AbstractAdapter)) ||
(defined?(ActionDispatch) &&
(value.is_a?(ActionDispatch::Request) || value.is_a?(ActionDispatch::Response)))
end

# https://gist.github.com/dbenhur/1070399
def transform_hash(original, options = {}, &block)
options[:safe_descent] ||= {}
Expand Down

0 comments on commit 847ea41

Please sign in to comment.