Skip to content

Commit

Permalink
Add multiple versions of Rails and Ruby to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
duffn committed Mar 19, 2023
1 parent 857af06 commit 6006174
Show file tree
Hide file tree
Showing 13 changed files with 221 additions and 41 deletions.
17 changes: 16 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,27 @@ jobs:
env:
RAILS_ENV: test
DATABASE_URL: postgres://test:[email protected]:5432/grape_on_rails_test
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile.file }}.gemfile
continue-on-error: ${{ matrix.gemfile.experimental }}
strategy:
fail-fast: false
matrix:
ruby:
- "2.7"
- "3.0"
- "3.1"
- "3.2"
gemfile:
- { file: rails_6, experimental: false }
- { file: rails_6_1, experimental: false }
- { file: rails_7, experimental: false }
- { file: rails_edge, experimental: true }
steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.1.2"
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Setup Firefox
uses: browser-actions/setup-firefox@latest
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@

# Ignore master key for decrypting credentials and more.
/config/master.key

# Appraisal gem
.bundle
/gemfiles/*.lock
17 changes: 17 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

appraise 'rails-6' do
gem 'rails', '~> 6.0'
end

appraise 'rails-6-1' do
gem 'rails', '~> 6.1'
end

appraise 'rails-7' do
gem 'rails', '~> 7.0'
end

appraise 'rails-edge' do
gem 'rails', github: 'rails/rails'
end
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '3.1.2'

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem 'rails', '~> 7.0.3'

Expand Down Expand Up @@ -48,14 +46,16 @@ gem 'bootsnap', require: false
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"

gem 'grape', '~> 1.6', '>= 1.6.2'
gem 'grape', '~> 1.7'

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem 'debug', platforms: %i[mri mingw x64_mingw]
end

group :development do
gem 'appraisal'

# Use console on exceptions pages [https://github.com/rails/web-console]
gem 'web-console'

Expand Down
43 changes: 22 additions & 21 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ GEM
tzinfo (~> 2.0)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
appraisal (2.4.1)
bundler
rake
thor (>= 0.14.0)
ast (2.4.2)
bindex (0.8.1)
bootsnap (1.12.0)
Expand All @@ -90,28 +94,24 @@ GEM
reline (>= 0.2.7)
diff-lcs (1.5.0)
digest (3.1.0)
dry-configurable (0.15.0)
dry-core (1.0.0)
concurrent-ruby (~> 1.0)
dry-core (~> 0.6)
dry-container (0.9.0)
zeitwerk (~> 2.6)
dry-inflector (1.0.0)
dry-logic (1.5.0)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.13, >= 0.13.0)
dry-core (0.7.1)
dry-core (~> 1.0, < 2)
zeitwerk (~> 2.6)
dry-types (1.7.1)
concurrent-ruby (~> 1.0)
dry-inflector (0.2.1)
dry-logic (1.2.0)
concurrent-ruby (~> 1.0)
dry-core (~> 0.5, >= 0.5)
dry-types (1.5.1)
concurrent-ruby (~> 1.0)
dry-container (~> 0.3)
dry-core (~> 0.5, >= 0.5)
dry-inflector (~> 0.1, >= 0.1.2)
dry-logic (~> 1.0, >= 1.0.2)
dry-core (~> 1.0)
dry-inflector (~> 1.0)
dry-logic (~> 1.4)
zeitwerk (~> 2.6)
erubi (1.10.0)
globalid (1.0.1)
activesupport (>= 5.0)
grape (1.6.2)
grape (1.7.0)
activesupport
builder
dry-types (>= 1.1)
Expand Down Expand Up @@ -140,7 +140,7 @@ GEM
mini_mime (1.1.2)
minitest (5.17.0)
msgpack (1.5.2)
mustermann (1.1.1)
mustermann (3.0.0)
ruby2_keywords (~> 0.0.1)
mustermann-grape (1.0.2)
mustermann (>= 1.0.0)
Expand All @@ -159,6 +159,8 @@ GEM
net-protocol
timeout
nio4r (2.5.8)
nokogiri (1.13.10-arm64-darwin)
racc (~> 1.4)
nokogiri (1.13.10-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.13.10-x86_64-linux)
Expand Down Expand Up @@ -285,14 +287,16 @@ GEM
zeitwerk (2.6.0)

PLATFORMS
arm64-darwin-21
x86_64-darwin-20
x86_64-linux

DEPENDENCIES
appraisal
bootsnap
capybara
debug
grape (~> 1.6, >= 1.6.2)
grape (~> 1.7)
importmap-rails
jbuilder
pg (~> 1.1)
Expand All @@ -309,8 +313,5 @@ DEPENDENCIES
web-console
webdrivers

RUBY VERSION
ruby 3.1.2p20

BUNDLED WITH
2.3.16
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
Grape on Rails
==============
# Grape on Rails

[![Test](https://github.com/ruby-grape/grape-on-rails/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/ruby-grape/grape-on-rails/actions/workflows/test.yml)
[![Rubocop](https://github.com/ruby-grape/grape-on-rails/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/ruby-grape/grape-on-rails/actions/workflows/test.yml)
[![Code Climate](https://codeclimate.com/github/ruby-grape/grape-on-rails.svg)](https://codeclimate.com/github/ruby-grape/grape-on-rails)

A [Grape](http://github.com/ruby-grape/grape) API mounted on Rails.

* [ping](app/api/acme/ping.rb): a hello world `GET` API
* [post](app/api/acme/post.rb): post JSON data
* [raise](app/api/acme/raise.rb): raise an error, Rails handling exceptions
* [protected](app/api/acme/protected.rb): API protected with rudimentary Basic Authentication
* [headers](app/api/acme/headers.rb): demonstrates header handling
- [ping](app/api/acme/ping.rb): a hello world `GET` API
- [post](app/api/acme/post.rb): post JSON data
- [raise](app/api/acme/raise.rb): raise an error, Rails handling exceptions
- [protected](app/api/acme/protected.rb): API protected with rudimentary Basic Authentication
- [headers](app/api/acme/headers.rb): demonstrates header handling

Run
---
## Run

```
bundle install
rails s
```

Try http://localhost:3000/api/ping or http://localhost:3000/api/protected/ping with _username_ and _password_.

6 changes: 5 additions & 1 deletion app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
class ApplicationRecord < ActiveRecord::Base
primary_abstract_class
if Gem::Version.new(Rails.version) >= Gem::Version.new('7.0')
primary_abstract_class
else
self.abstract_class = true
end
end
13 changes: 10 additions & 3 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@

module GrapeOnRails
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 7.0

# Since we're testing against multiple versions, initialize configuration defaults
# based upon the version we're using.
rails_version = Gem::Version.new(Rails.version)
if rails_version >= Gem::Version.new('7.0')
config.load_defaults 7.0
elsif rails_version >= Gem::Version.new('6.1')
config.load_defaults 6.1
else
config.load_defaults 6.0
end
# Configuration for the application, engines, and railties goes here.
#
# These settings can be overridden in specific environments using the files
Expand Down
33 changes: 33 additions & 0 deletions gemfiles/rails_6.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This file was generated by Appraisal

source 'https://rubygems.org'

gem 'bootsnap', require: false
gem 'grape', '~> 1.7'
gem 'importmap-rails'
gem 'jbuilder'
gem 'pg', '~> 1.1'
gem 'puma', '~> 5.0'
gem 'rails', '~> 6.0'
gem 'sprockets-rails'
gem 'stimulus-rails'
gem 'turbo-rails'
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]

group :development, :test do
gem 'debug', platforms: %i[mri mingw x64_mingw]
end

group :development do
gem 'appraisal'
gem 'web-console'
end

group :test do
gem 'capybara'
gem 'rspec'
gem 'rspec-rails'
gem 'rubocop'
gem 'selenium-webdriver'
gem 'webdrivers'
end
33 changes: 33 additions & 0 deletions gemfiles/rails_6_1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This file was generated by Appraisal

source 'https://rubygems.org'

gem 'bootsnap', require: false
gem 'grape', '~> 1.7'
gem 'importmap-rails'
gem 'jbuilder'
gem 'pg', '~> 1.1'
gem 'puma', '~> 5.0'
gem 'rails', '~> 6.1'
gem 'sprockets-rails'
gem 'stimulus-rails'
gem 'turbo-rails'
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]

group :development, :test do
gem 'debug', platforms: %i[mri mingw x64_mingw]
end

group :development do
gem 'appraisal'
gem 'web-console'
end

group :test do
gem 'capybara'
gem 'rspec'
gem 'rspec-rails'
gem 'rubocop'
gem 'selenium-webdriver'
gem 'webdrivers'
end
33 changes: 33 additions & 0 deletions gemfiles/rails_7.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This file was generated by Appraisal

source 'https://rubygems.org'

gem 'bootsnap', require: false
gem 'grape', '~> 1.7'
gem 'importmap-rails'
gem 'jbuilder'
gem 'pg', '~> 1.1'
gem 'puma', '~> 5.0'
gem 'rails', '~> 7.0'
gem 'sprockets-rails'
gem 'stimulus-rails'
gem 'turbo-rails'
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]

group :development, :test do
gem 'debug', platforms: %i[mri mingw x64_mingw]
end

group :development do
gem 'appraisal'
gem 'web-console'
end

group :test do
gem 'capybara'
gem 'rspec'
gem 'rspec-rails'
gem 'rubocop'
gem 'selenium-webdriver'
gem 'webdrivers'
end
33 changes: 33 additions & 0 deletions gemfiles/rails_edge.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This file was generated by Appraisal

source 'https://rubygems.org'

gem 'bootsnap', require: false
gem 'grape', '~> 1.7'
gem 'importmap-rails'
gem 'jbuilder'
gem 'pg', '~> 1.1'
gem 'puma', '~> 5.0'
gem 'rails', git: 'https://github.com/rails/rails.git'
gem 'sprockets-rails'
gem 'stimulus-rails'
gem 'turbo-rails'
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]

group :development, :test do
gem 'debug', platforms: %i[mri mingw x64_mingw]
end

group :development do
gem 'appraisal'
gem 'web-console'
end

group :test do
gem 'capybara'
gem 'rspec'
gem 'rspec-rails'
gem 'rubocop'
gem 'selenium-webdriver'
gem 'webdrivers'
end
6 changes: 4 additions & 2 deletions spec/api/headers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
expect(JSON.parse(response.body)).to eq(
'Accept' => 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
'Cookie' => '',
'Host' => 'www.example.com'
'Host' => 'www.example.com',
'Version' => 'HTTP/1.0'
)
end

Expand All @@ -31,7 +32,8 @@
'Cookie' => '',
'Host' => 'www.example.com',
'Reticulated-Spline' => 42,
'Something' => 1
'Something' => 1,
'Version' => 'HTTP/1.0'
)
end
end

0 comments on commit 6006174

Please sign in to comment.