Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tests on rails 7.1 #37

Merged
merged 6 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Fix StandardRb offenses: double quotes, hash style, spacing
72906c4781348dbf04f94fa465482c325bb27446
13 changes: 12 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,27 @@ jobs:
- rails6.0
- rails6.1
- rails7.0
- rails7.1
include:
- {ruby-version: '2.7', gemfile: rails5.2}
env:
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
steps:
- uses: zendesk/checkout@v2
- uses: zendesk/checkout@v4
- name: Set up Ruby
uses: zendesk/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
- run: bundle install
- name: Tests
run: bundle exec rake test

linter:
runs-on: ubuntu-latest
name: Linting of Ruby files
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- run: bundle exec rake standard
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.7.8
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [2.7.0] - 2023-11-14

* Added support for Rails 7.1
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source 'https://rubygems.org'
source "https://rubygems.org"

eval_gemfile('gemfiles/rails5.2.gemfile')
eval_gemfile("gemfiles/rails5.2.gemfile")
12 changes: 1 addition & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,6 @@ Include the module `Charcoal::CrossOrigin` in the controller you'd like to allow

Included is a CORS pre-flight controller that must be hooked up to the Rails router:

Rails 2:
```ruby
map.connect "*path.:format", :conditions => { :method => :options }, :action => "preflight", :controller => "cross_origin", :namespace => "charcoal/"
```

Rails 3 / 4:
```ruby
match '*path.:format' => 'charcoal/cross_origin#preflight', :via => :options
```

Rails 5:
```ruby
match '*path', :to => 'charcoal/cross_origin#preflight', :via => :options
Expand Down Expand Up @@ -111,7 +101,7 @@ This example adds the `allow_animals` directive that logs "QUACK!" if an applica

## Supported Versions

Ruby >= 2.5 and Rails >= 5.0.
Ruby >= 2.7 and Rails >= 5.2.

[![Build Status](https://github.com/zendesk/charcoal/workflows/CI/badge.svg)](https://github.com/zendesk/charcoal/actions?query=workflow%3ACI)

Expand Down
18 changes: 10 additions & 8 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
require 'bundler/setup'
require 'bundler/gem_tasks'
require 'bump/tasks'
require 'rake/testtask'
require "bundler/setup"
require "bundler/gem_tasks"
require "rake/testtask"
require "standard/rake"
require "yard"

YARD::Rake::YardocTask.new

Rake::TestTask.new(:test) do |test|
test.libs << 'lib' << 'test'
test.pattern = 'test/**/*_test.rb'
test.libs << "lib" << "test"
test.pattern = "test/**/*_test.rb"
test.verbose = true
end

require 'yard'
YARD::Rake::YardocTask.new
task default: [:test, :standard]
21 changes: 10 additions & 11 deletions charcoal.gemspec
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
require './lib/charcoal/version'
require "./lib/charcoal/version"

Gem::Specification.new('charcoal', Charcoal::VERSION) do |s|
Gem::Specification.new("charcoal", Charcoal::VERSION) do |s|
s.authors = ["Steven Davidovitz"]
s.description = "Helps you support JSONP and CORS in your Rails app"
s.summary = "Cross-Origin helper for Rails"
s.email = "sdavidovitz@zendesk.com"
s.homepage = "https://github.com/zendesk/charcoal"

s.required_ruby_version = '>= 2.7'
s.required_ruby_version = ">= 2.7"

s.files = Dir.glob('{lib,config,app}/**/*')
s.files = Dir.glob("{lib,config,app}/**/*")

s.licenses = ['MIT']
s.licenses = ["MIT"]

s.add_runtime_dependency 'activesupport', '>= 5.2', '< 7.1'
s.add_runtime_dependency 'actionpack', '>= 5.2', '< 7.1'
s.add_runtime_dependency "activesupport", ">= 5.2", "< 7.2"
s.add_runtime_dependency "actionpack", ">= 5.2", "< 7.2"

s.add_development_dependency 'rake'
s.add_development_dependency 'bump'
s.add_development_dependency 'yard', '>= 0.9.11'
s.add_development_dependency "rake"
s.add_development_dependency "yard", ">= 0.9.11"

s.add_development_dependency 'shoulda', '~> 3.0'
s.add_development_dependency "shoulda", "~> 3.0"
end
7 changes: 4 additions & 3 deletions gemfiles/common.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
source 'https://rubygems.org'
source "https://rubygems.org"

gemspec path: '../'
gemspec path: "../"

gem 'byebug', :platforms => :mri
gem "byebug", platforms: :mri
gem "standard"
6 changes: 3 additions & 3 deletions gemfiles/rails5.2.gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
eval_gemfile 'common.rb'
eval_gemfile "common.rb"

gem 'rails', '~> 5.2.0'
gem 'actionpack-action_caching'
gem "rails", "~> 5.2.0"
gem "actionpack-action_caching"
6 changes: 3 additions & 3 deletions gemfiles/rails6.0.gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
eval_gemfile 'common.rb'
eval_gemfile "common.rb"

gem 'rails', '~> 6.0.0'
gem 'actionpack-action_caching'
gem "rails", "~> 6.0.0"
gem "actionpack-action_caching"
6 changes: 3 additions & 3 deletions gemfiles/rails6.1.gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
eval_gemfile 'common.rb'
eval_gemfile "common.rb"

gem 'rails', '~> 6.1.0'
gem 'actionpack-action_caching'
gem "rails", "~> 6.1.0"
gem "actionpack-action_caching"
6 changes: 3 additions & 3 deletions gemfiles/rails7.0.gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
eval_gemfile 'common.rb'
eval_gemfile "common.rb"

gem 'rails', '~> 7.0.0'
gem 'actionpack-action_caching'
gem "rails", "~> 7.0.0"
gem "actionpack-action_caching"
4 changes: 4 additions & 0 deletions gemfiles/rails7.1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
eval_gemfile "common.rb"

gem "rails", "~> 7.1.0"
gem "actionpack-action_caching"
13 changes: 6 additions & 7 deletions lib/charcoal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ module Charcoal
def self.configuration
@configuration ||= {
"credentials" => true,
"expose-headers" => %w{},
"allow-headers" => %w{X-Requested-With X-Prototype-Version},
"expose-headers" => %w[],
"allow-headers" => %w[X-Requested-With X-Prototype-Version],
"max-age" => 86400,
"allow-origin" => "*"
}
end

autoload :ControllerFilter, 'charcoal/controller_filter'
autoload :CrossOrigin, 'charcoal/cross_origin'
autoload :JSONP, 'charcoal/jsonp'
autoload :ControllerFilter, "charcoal/controller_filter"
autoload :CrossOrigin, "charcoal/cross_origin"
autoload :JSONP, "charcoal/jsonp"

autoload :CrossOriginController, 'charcoal/cross_origin_controller'
autoload :CrossOriginController, "charcoal/cross_origin_controller"
end

10 changes: 5 additions & 5 deletions lib/charcoal/controller_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ def allow(filter, &block)
methods = args.map(&:to_sym)
methods = [:all] if methods.empty?

if options[:unless]
directive = lambda {|c| !parse_directive(options[:unless]).call(c)}
directive = if options[:unless]
lambda { |c| !parse_directive(options[:unless]).call(c) }
else
directive = parse_directive(options[:if] || true)
parse_directive(options[:if] || true)
end

methods.each do |method|
Expand All @@ -34,9 +34,9 @@ def parse_directive(directive)
return directive if directive.respond_to?(:call)

if directive.respond_to?(:to_sym) && method_defined?(directive.to_sym)
lambda {|c| c.send(directive.to_sym)}
lambda { |c| c.send(directive.to_sym) }
else
lambda {|c| directive}
lambda { |c| directive }
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/charcoal/cross_origin.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
require 'charcoal/controller_filter'
require "charcoal/controller_filter"

module Charcoal
module CrossOrigin
def self.included(klass)
klass.extend(ClassMethods)
if klass.respond_to?(:around_action)
klass.around_action :set_cors_headers_filter, :if => :cors_allowed?
klass.around_action :set_cors_headers_filter, if: :cors_allowed?
else
klass.around_filter :set_cors_headers_filter, :if => :cors_allowed?
klass.around_filter :set_cors_headers_filter, if: :cors_allowed?
end
end

module ClassMethods
include ControllerFilter

def cors_allowed
@cors_allowed ||= Hash.new(lambda {|_| false})
@cors_allowed ||= Hash.new(lambda { |_| false })
end

allow :cors do |method, directive|
Expand Down
10 changes: 5 additions & 5 deletions lib/charcoal/cross_origin_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# This controller handles CORS preflight requests
# See https://developer.mozilla.org/En/HTTP_access_control for documentation

require 'action_controller/metal'
require 'active_support/version'
require 'charcoal/utilities'
require "action_controller/metal"
require "active_support/version"
require "charcoal/utilities"

class Charcoal::CrossOriginController < ActionController::Metal
include AbstractController::Callbacks
Expand All @@ -25,10 +25,10 @@ def preflight
set_cors_headers
headers["Access-Control-Allow-Methods"] = allowed_methods.join(",").upcase
headers["Access-Control-Max-Age"] = Charcoal.configuration["max-age"].to_s
headers['Access-Control-Allow-Headers'] = Charcoal.configuration["allow-headers"].join(",")
headers["Access-Control-Allow-Headers"] = Charcoal.configuration["allow-headers"].join(",")
end

head :ok, :content_type => "text/plain"
head :ok, content_type: "text/plain"
end

private
Expand Down
6 changes: 3 additions & 3 deletions lib/charcoal/jsonp.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'charcoal/controller_filter'
require "charcoal/controller_filter"

module Charcoal
module JSONP
Expand All @@ -15,7 +15,7 @@ module ClassMethods
include ControllerFilter

def jsonp_allowed
@jsonp_allowed ||= Hash.new(lambda {|_| false})
@jsonp_allowed ||= Hash.new(lambda { |_| false })
end

allow :jsonp do |method, directive|
Expand All @@ -41,7 +41,7 @@ def jsonp_request?
def add_jsonp_callback
yield

if response.status.to_s.starts_with?('200') && jsonp_request?
if response.status.to_s.starts_with?("200") && jsonp_request?
response.content_type = "application/javascript"
response.body = "#{params[:callback]}(#{response.body})"
end
Expand Down
14 changes: 6 additions & 8 deletions lib/charcoal/utilities.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'action_controller'
require "action_controller"

module Charcoal::Utilities
Routing = defined?(ActionDispatch) ? ActionDispatch::Routing : ActionController::Routing
Expand All @@ -15,7 +15,7 @@ def methods_allowed_for?(protocol)
Routing::HTTP_METHODS.select do |verb|
next if verb == :options

route = find_route(request.path, request.env.merge(:method => verb))
route = find_route(request.path, request.env.merge(method: verb))

if route
controller = route[:controller].camelize
Expand All @@ -28,7 +28,7 @@ def methods_allowed_for?(protocol)
instance.response = response

method_name = "#{protocol}_allowed"
controller.respond_to?(method_name.to_sym) && controller.send(method_name + '?', instance, action)
controller.respond_to?(method_name.to_sym) && controller.send(method_name + "?", instance, action)
else
false
end
Expand All @@ -40,13 +40,11 @@ def find_route(path, env)

railties = Rails.application.railties
railties = railties.respond_to?(:all) ? railties.all : railties._all
routes += railties.select {|tie| tie.is_a?(Rails::Engine)}.map(&:routes)
routes += railties.select { |tie| tie.is_a?(Rails::Engine) }.map(&:routes)

routes.each do |route_set|
begin
return route_set.recognize_path(path, env)
rescue ActionController::RoutingError
end
return route_set.recognize_path(path, env)
rescue ActionController::RoutingError
end

nil
Expand Down
2 changes: 1 addition & 1 deletion lib/charcoal/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Charcoal
VERSION = "2.6.0"
VERSION = "2.7.0"
end
Loading