From 5f7aed73045ffa76aacb6a1a70a8f0bcece40dbf Mon Sep 17 00:00:00 2001 From: Aleksandar Ivanov Date: Tue, 21 Dec 2021 11:31:09 +0200 Subject: [PATCH 1/3] Add rails 7 support The code seems to work without any changes. --- Appraisals | 10 +++++ gemfiles/rails61.gemfile | 11 ++++++ gemfiles/rails70.gemfile | 11 ++++++ lib/loga/railtie.rb | 2 +- spec/fixtures/rails61.rb | 80 ++++++++++++++++++++++++++++++++++++++++ spec/fixtures/rails70.rb | 80 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 193 insertions(+), 1 deletion(-) create mode 100644 gemfiles/rails61.gemfile create mode 100644 gemfiles/rails70.gemfile create mode 100644 spec/fixtures/rails61.rb create mode 100644 spec/fixtures/rails70.rb diff --git a/Appraisals b/Appraisals index 4c66aba..b32ffd4 100644 --- a/Appraisals +++ b/Appraisals @@ -36,6 +36,16 @@ if Gem::Version.new(RUBY_VERSION) > Gem::Version.new('2.5.0') end end +if Gem::Version.new(RUBY_VERSION) > Gem::Version.new('2.7.0') + appraise 'rails61' do + gem 'rails', '~> 6.1.4.4' + end + + appraise 'rails70' do + gem 'rails', '~> 7.0.0' + end +end + appraise 'sidekiq51' do gem 'sidekiq', '~> 5.1.0' end diff --git a/gemfiles/rails61.gemfile b/gemfiles/rails61.gemfile new file mode 100644 index 0000000..df49d08 --- /dev/null +++ b/gemfiles/rails61.gemfile @@ -0,0 +1,11 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "~> 6.1.4.4" + +group :test do + gem "simplecov", "~> 0.17.0" +end + +gemspec path: "../" diff --git a/gemfiles/rails70.gemfile b/gemfiles/rails70.gemfile new file mode 100644 index 0000000..01a984f --- /dev/null +++ b/gemfiles/rails70.gemfile @@ -0,0 +1,11 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "~> 7.0.0" + +group :test do + gem "simplecov", "~> 0.17.0" +end + +gemspec path: "../" diff --git a/lib/loga/railtie.rb b/lib/loga/railtie.rb index b9439e0..b38a9fc 100644 --- a/lib/loga/railtie.rb +++ b/lib/loga/railtie.rb @@ -125,7 +125,7 @@ def insert_exceptions_catcher def silence_rails_rack_logger case Rails::VERSION::MAJOR when 3 then require 'loga/ext/rails/rack/logger3.rb' - when 4..6 then require 'loga/ext/rails/rack/logger.rb' + when 4..7 then require 'loga/ext/rails/rack/logger.rb' else raise Loga::ConfigurationError, "Rails #{Rails::VERSION::MAJOR} is unsupported" diff --git a/spec/fixtures/rails61.rb b/spec/fixtures/rails61.rb new file mode 100644 index 0000000..5a9b872 --- /dev/null +++ b/spec/fixtures/rails61.rb @@ -0,0 +1,80 @@ +require 'action_controller/railtie' +require 'action_mailer/railtie' + +Bundler.require(*Rails.groups) + +STREAM = StringIO.new unless defined?(STREAM) + +class Dummy < Rails::Application + config.eager_load = true + config.filter_parameters += [:password] + config.secret_key_base = '2624599ca9ab3cf3823626240138a128118a87683bf03ab8f155844c33b3cd8cbbfa3ef5e29db6f5bd182f8bd4776209d9577cfb46ac51bfd232b00ab0136b24' + config.session_store :cookie_store, key: '_rails61_session' + + config.log_tags = [:uuid, 'TEST_TAG'] + config.loga = { + device: STREAM, + host: 'bird.example.com', + service_name: 'hello_world_app', + service_version: '1.0', + } + config.action_mailer.delivery_method = :test +end + +class ApplicationController < ActionController::Base + include Rails.application.routes.url_helpers + protect_from_forgery with: :null_session + + def ok + render plain: 'Hello Rails' + end + + def error + nil.name + end + + def show + render json: params + end + + def create + render json: params + end + + def new + redirect_to :ok + end + + def update + @id = params[:id] + render '/user' + end +end + +class FakeMailer < ActionMailer::Base + default from: 'notifications@example.com' + + def self.send_email + basic_mail.deliver_now + end + + def basic_mail + mail( + to: 'user@example.com', + subject: 'Welcome to My Awesome Site', + body: 'Banana muffin', + content_type: 'text/html', + ) + end +end + +Dummy.routes.append do + get 'ok' => 'application#ok' + get 'error' => 'application#error' + get 'show' => 'application#show' + post 'users' => 'application#create' + get 'new' => 'application#new' + put 'users/:id' => 'application#update' +end + +Dummy.initialize! diff --git a/spec/fixtures/rails70.rb b/spec/fixtures/rails70.rb new file mode 100644 index 0000000..5af8df3 --- /dev/null +++ b/spec/fixtures/rails70.rb @@ -0,0 +1,80 @@ +require 'action_controller/railtie' +require 'action_mailer/railtie' + +Bundler.require(*Rails.groups) + +STREAM = StringIO.new unless defined?(STREAM) + +class Dummy < Rails::Application + config.eager_load = true + config.filter_parameters += [:password] + config.secret_key_base = '2624599ca9ab3cf3823626240138a128118a87683bf03ab8f155844c33b3cd8cbbfa3ef5e29db6f5bd182f8bd4776209d9577cfb46ac51bfd232b00ab0136b24' + config.session_store :cookie_store, key: '_rails70_session' + + config.log_tags = [:uuid, 'TEST_TAG'] + config.loga = { + device: STREAM, + host: 'bird.example.com', + service_name: 'hello_world_app', + service_version: '1.0', + } + config.action_mailer.delivery_method = :test +end + +class ApplicationController < ActionController::Base + include Rails.application.routes.url_helpers + protect_from_forgery with: :null_session + + def ok + render plain: 'Hello Rails' + end + + def error + nil.name + end + + def show + render json: params + end + + def create + render json: params + end + + def new + redirect_to :ok + end + + def update + @id = params[:id] + render '/user' + end +end + +class FakeMailer < ActionMailer::Base + default from: 'notifications@example.com' + + def self.send_email + basic_mail.deliver_now + end + + def basic_mail + mail( + to: 'user@example.com', + subject: 'Welcome to My Awesome Site', + body: 'Banana muffin', + content_type: 'text/html', + ) + end +end + +Dummy.routes.append do + get 'ok' => 'application#ok' + get 'error' => 'application#error' + get 'show' => 'application#show' + post 'users' => 'application#create' + get 'new' => 'application#new' + put 'users/:id' => 'application#update' +end + +Dummy.initialize! From 8cbccb44f536a0b29eb1b32d89e8076cbc75e866 Mon Sep 17 00:00:00 2001 From: Aleksandar Ivanov Date: Tue, 21 Dec 2021 11:43:34 +0200 Subject: [PATCH 2/3] Update ci build - Add ruby 3 build - Remove ruby 2.3 build - Remove cc-test-reporter - Use the new circleci images -> `cimg/*` wherever possible, some are left on circleci because they have an older bundler version --- .circleci/config.yml | 68 ++++++-------------------------------------- Guardfile | 2 +- loga.gemspec | 6 ++-- 3 files changed, 12 insertions(+), 64 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3dd202e..9bee915 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,7 +1,7 @@ basic_build: &basic_build working_directory: ~/loga docker: - - image: circleci/ruby:2.5.1 + - image: cimg/ruby:2.7.5 test_build: &test_build working_directory: ~/loga @@ -25,43 +25,11 @@ test_build: &test_build at: ./tmp - run: RACK_ENV=development bundle exec appraisal rspec - run: RACK_ENV=production bundle exec appraisal rspec - - run: ./tmp/cc-test-reporter format-coverage -t simplecov -o $(ruby -e 'puts "tmp/codeclimate.#{RUBY_VERSION}.json"') coverage/.resultset.json - - persist_to_workspace: - root: tmp - paths: - - codeclimate.*.json - store_artifacts: path: coverage version: 2 jobs: - build: - <<: *basic_build - steps: - - run: - name: Download cc-test-reporter - command: | - mkdir -p tmp/ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./tmp/cc-test-reporter - chmod +x ./tmp/cc-test-reporter - - persist_to_workspace: - root: ./tmp - paths: - - cc-test-reporter - upload-coverage: - <<: *basic_build - steps: - - attach_workspace: - at: ./tmp - - run: - name: Upload coverage results to Code Climate - command: | - ./tmp/cc-test-reporter sum-coverage tmp/codeclimate.*.json -o tmp/codeclimate.total.json - ./tmp/cc-test-reporter upload-coverage -i tmp/codeclimate.total.json -r $CODECLIMATE_REPO_TOKEN - ruby-2.3: - docker: - - image: circleci/ruby:2.3 - <<: *test_build ruby-2.4: docker: - image: circleci/ruby:2.4 @@ -76,7 +44,11 @@ jobs: <<: *test_build ruby-2.7: docker: - - image: circleci/ruby:2.7 + - image: cimg/ruby:2.7 + <<: *test_build + ruby-3.0: + docker: + - image: cimg/ruby:3.0 <<: *test_build rubocop: <<: *basic_build @@ -107,54 +79,30 @@ workflows: version: 2 test-then-push-gem: jobs: - - build: - filters: - tags: - only: /.*/ - rubocop: filters: tags: only: /.*/ - - ruby-2.3: - filters: - tags: - only: /.*/ - requires: - - build - ruby-2.4: filters: tags: only: /.*/ - requires: - - build - ruby-2.5: filters: tags: only: /.*/ - requires: - - build - ruby-2.6: filters: tags: only: /.*/ - requires: - - build - ruby-2.7: filters: tags: only: /.*/ - requires: - - build - - upload-coverage: + - ruby-3.0: filters: tags: only: /.*/ - requires: - - ruby-2.3 - - ruby-2.4 - - ruby-2.5 - - ruby-2.6 - - ruby-2.7 - push-to-rubygems: filters: tags: @@ -163,8 +111,8 @@ workflows: ignore: /.*/ requires: - rubocop - - ruby-2.3 - ruby-2.4 - ruby-2.5 - ruby-2.6 - ruby-2.7 + - ruby-3.0 diff --git a/Guardfile b/Guardfile index 1542d79..575980a 100644 --- a/Guardfile +++ b/Guardfile @@ -15,7 +15,7 @@ end group :rails do %w[production development].each do |env| - %w[rails32 rails40 rails50 rails52].each do |appraisal| + %w[rails52 rails61 rails70].each do |appraisal| cmd = "RACK_ENV=#{env} bundle exec appraisal #{appraisal} rspec" guard :rspec, all_on_start: true, cmd: cmd do diff --git a/loga.gemspec b/loga.gemspec index 56ad76a..4688dd9 100644 --- a/loga.gemspec +++ b/loga.gemspec @@ -21,17 +21,17 @@ Gem::Specification.new do |spec| spec.add_dependency 'activesupport', '>= 2.3.8' spec.add_dependency 'rack' - spec.add_development_dependency 'appraisal', '~> 2.2.0' + spec.add_development_dependency 'appraisal', '~> 2.4' spec.add_development_dependency 'bundler', '>= 1.6' spec.add_development_dependency 'byebug' spec.add_development_dependency 'guard', '~> 2.13' - spec.add_development_dependency 'guard-rspec', '~> 4.7.3' + spec.add_development_dependency 'guard-rspec', '~> 4.7' spec.add_development_dependency 'guard-rubocop', '~> 1.2' spec.add_development_dependency 'pry' spec.add_development_dependency 'rack-test' spec.add_development_dependency 'rake' spec.add_development_dependency 'fakeredis' - spec.add_development_dependency 'rspec', '~> 3.7.0' + spec.add_development_dependency 'rspec', '~> 3.7' spec.add_development_dependency 'rubocop', '~> 0.57.0' spec.add_development_dependency 'rubocop-rspec' spec.add_development_dependency 'timecop' From 057f210ccc371c8d4650e1b35b20ea8dd68e6643 Mon Sep 17 00:00:00 2001 From: Aleksandar Ivanov Date: Wed, 22 Dec 2021 11:16:28 +0200 Subject: [PATCH 3/3] Update the changelog and version --- CHANGELOG.md | 8 ++++++++ lib/loga/version.rb | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d616ea..3a1917d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [2.6.0] - 2021-12-22 +### Added +- Allow using the gem with rails 7 +- Add a build for ruby 3.0 + +### Removed +- Remove build for ruby 2.3 + ## [2.5.4] - 2021-03-24 ### Fixed - Remove state from Rack middleware, to prevent race conditions where one request would overwrite the state of another diff --git a/lib/loga/version.rb b/lib/loga/version.rb index 57993e3..eae6033 100644 --- a/lib/loga/version.rb +++ b/lib/loga/version.rb @@ -1,3 +1,3 @@ module Loga - VERSION = '2.5.4'.freeze + VERSION = '2.6.0'.freeze end