diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 0000000..20bcd6b --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,2 @@ +# Fix StandardRb offenses: double quotes, hash style, spacing +72906c4781348dbf04f94fa465482c325bb27446 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7471db7..bceec59 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,12 +18,13 @@ 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: @@ -31,3 +32,13 @@ jobs: - 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 diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..6a81b4c --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.7.8 diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e452823 --- /dev/null +++ b/CHANGELOG.md @@ -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 diff --git a/Gemfile b/Gemfile index 22f71c4..31d6d85 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,3 @@ -source 'https://rubygems.org' +source "https://rubygems.org" -eval_gemfile('gemfiles/rails5.2.gemfile') +eval_gemfile("gemfiles/rails5.2.gemfile") diff --git a/README.md b/README.md index 4bc307b..7db9acc 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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) diff --git a/Rakefile b/Rakefile index 85eb4d9..b650f61 100644 --- a/Rakefile +++ b/Rakefile @@ -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] diff --git a/charcoal.gemspec b/charcoal.gemspec index 2caef02..6850427 100644 --- a/charcoal.gemspec +++ b/charcoal.gemspec @@ -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 diff --git a/gemfiles/common.rb b/gemfiles/common.rb index 0134537..7fbe618 100644 --- a/gemfiles/common.rb +++ b/gemfiles/common.rb @@ -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" diff --git a/gemfiles/rails5.2.gemfile b/gemfiles/rails5.2.gemfile index d837565..11c5d8c 100644 --- a/gemfiles/rails5.2.gemfile +++ b/gemfiles/rails5.2.gemfile @@ -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" diff --git a/gemfiles/rails6.0.gemfile b/gemfiles/rails6.0.gemfile index 7f8706f..b098679 100644 --- a/gemfiles/rails6.0.gemfile +++ b/gemfiles/rails6.0.gemfile @@ -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" diff --git a/gemfiles/rails6.1.gemfile b/gemfiles/rails6.1.gemfile index a48703a..5a3bc6e 100644 --- a/gemfiles/rails6.1.gemfile +++ b/gemfiles/rails6.1.gemfile @@ -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" diff --git a/gemfiles/rails7.0.gemfile b/gemfiles/rails7.0.gemfile index 0923316..b8d20d1 100644 --- a/gemfiles/rails7.0.gemfile +++ b/gemfiles/rails7.0.gemfile @@ -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" diff --git a/gemfiles/rails7.1.gemfile b/gemfiles/rails7.1.gemfile new file mode 100644 index 0000000..060c568 --- /dev/null +++ b/gemfiles/rails7.1.gemfile @@ -0,0 +1,4 @@ +eval_gemfile "common.rb" + +gem "rails", "~> 7.1.0" +gem "actionpack-action_caching" diff --git a/lib/charcoal.rb b/lib/charcoal.rb index b6849ee..17a54b9 100644 --- a/lib/charcoal.rb +++ b/lib/charcoal.rb @@ -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 - diff --git a/lib/charcoal/controller_filter.rb b/lib/charcoal/controller_filter.rb index 1178cf2..33621b0 100644 --- a/lib/charcoal/controller_filter.rb +++ b/lib/charcoal/controller_filter.rb @@ -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| @@ -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 diff --git a/lib/charcoal/cross_origin.rb b/lib/charcoal/cross_origin.rb index 0b3f337..afb6088 100644 --- a/lib/charcoal/cross_origin.rb +++ b/lib/charcoal/cross_origin.rb @@ -1,13 +1,13 @@ -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 @@ -15,7 +15,7 @@ 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| diff --git a/lib/charcoal/cross_origin_controller.rb b/lib/charcoal/cross_origin_controller.rb index 9f05a41..68521dd 100644 --- a/lib/charcoal/cross_origin_controller.rb +++ b/lib/charcoal/cross_origin_controller.rb @@ -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 @@ -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 diff --git a/lib/charcoal/jsonp.rb b/lib/charcoal/jsonp.rb index b9c10f1..94fee54 100644 --- a/lib/charcoal/jsonp.rb +++ b/lib/charcoal/jsonp.rb @@ -1,4 +1,4 @@ -require 'charcoal/controller_filter' +require "charcoal/controller_filter" module Charcoal module JSONP @@ -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| @@ -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 diff --git a/lib/charcoal/utilities.rb b/lib/charcoal/utilities.rb index 67254cf..a3a4e7a 100644 --- a/lib/charcoal/utilities.rb +++ b/lib/charcoal/utilities.rb @@ -1,4 +1,4 @@ -require 'action_controller' +require "action_controller" module Charcoal::Utilities Routing = defined?(ActionDispatch) ? ActionDispatch::Routing : ActionController::Routing @@ -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 @@ -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 @@ -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 diff --git a/lib/charcoal/version.rb b/lib/charcoal/version.rb index 77c5757..7aada45 100644 --- a/lib/charcoal/version.rb +++ b/lib/charcoal/version.rb @@ -1,3 +1,3 @@ module Charcoal - VERSION = "2.6.0" + VERSION = "2.7.0" end diff --git a/test/cross_origin_controller_test.rb b/test/cross_origin_controller_test.rb index 642ed53..3c1d57d 100644 --- a/test/cross_origin_controller_test.rb +++ b/test/cross_origin_controller_test.rb @@ -5,7 +5,8 @@ class TestController < ActionController::Base allow_cors :test # GET, PUT - def test; end + def test + end end class EngineController < ActionController::Base @@ -13,7 +14,8 @@ class EngineController < ActionController::Base allow_cors :test # POST - def test; end + def test + end end class Charcoal::CrossOriginControllerTest < ActionController::TestCase @@ -46,7 +48,7 @@ class Charcoal::CrossOriginControllerTest < ActionController::TestCase should "allow proper methods" do allowed = ["GET", "HEAD", "PUT"] - assert_equal allowed.join(','), @response.headers["Access-Control-Allow-Methods"], @response.headers.inspect + assert_equal allowed.join(","), @response.headers["Access-Control-Allow-Methods"], @response.headers.inspect end should "set Access-Control-Allow-Headers header" do @@ -59,7 +61,7 @@ class Charcoal::CrossOriginControllerTest < ActionController::TestCase should "render text/plain response" do assert @response.body.blank? - assert_match %r[text/plain], @response.headers["Content-Type"], @response.headers.inspect + assert_match %r{text/plain}, @response.headers["Content-Type"], @response.headers.inspect end end end @@ -84,7 +86,7 @@ class Charcoal::CrossOriginControllerTest < ActionController::TestCase should "render text/plain response" do assert @response.body.blank? - assert_match %r[text/plain], @response.headers["Content-Type"], @response.headers.inspect + assert_match %r{text/plain}, @response.headers["Content-Type"], @response.headers.inspect end end end diff --git a/test/cross_origin_test.rb b/test/cross_origin_test.rb index d39a55b..31e229b 100644 --- a/test/cross_origin_test.rb +++ b/test/cross_origin_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', File.dirname(__FILE__)) +require File.expand_path("helper", File.dirname(__FILE__)) class TestCorsController < ActionController::Base include Charcoal::CrossOrigin @@ -23,7 +23,7 @@ def test_error_action class TestCorsControllerTest < ActionController::TestCase ACTIONS = { "success" => :test_action, - "error" => :test_error_action + "error" => :test_error_action } context TestCorsController do @@ -31,7 +31,7 @@ class TestCorsControllerTest < ActionController::TestCase subject { TestCorsController.new } setup do - subject.params = { :action => "test_action" } + subject.params = {action: "test_action"} end should "allow cors" do @@ -40,7 +40,7 @@ class TestCorsControllerTest < ActionController::TestCase end context "cors callback" do - ["success","error"].each do |response_state| + ["success", "error"].each do |response_state| context "with #{response_state} response" do context "CORS header -> Access-Control-Allow-Origin" do setup do @@ -158,7 +158,7 @@ class TestCorsControllerTest < ActionController::TestCase context "without any other request method" do setup do - @original, Charcoal.configuration["expose-headers"] = Charcoal.configuration["expose-headers"], %w{test 123} + @original, Charcoal.configuration["expose-headers"] = Charcoal.configuration["expose-headers"], %w[test 123] get :test_action end diff --git a/test/filters_test.rb b/test/filters_test.rb index 405454f..e055d61 100644 --- a/test/filters_test.rb +++ b/test/filters_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', File.dirname(__FILE__)) +require File.expand_path("helper", File.dirname(__FILE__)) class FiltersControllerTester < ActionController::Base class << self @@ -9,7 +9,7 @@ class << self end def filtering_allowed - @filtering_allowed ||= Hash.new(lambda {|_| false }) + @filtering_allowed ||= Hash.new(lambda { |_| false }) end def filtering_allowed?(instance, action) @@ -22,13 +22,18 @@ def filtering_allowed? self.class.filtering_allowed?(self, params[:action]) end - def test_action1; true; end - def test_action2; false; end + def test_action1 + true + end + + def test_action2 + false + end end class FiltersTest < ActiveSupport::TestCase context Charcoal::ControllerFilter do - subject { FiltersControllerTester.new } + subject { FiltersControllerTester.new } setup do subject.params = {} end @@ -40,28 +45,28 @@ class FiltersTest < ActiveSupport::TestCase context "if" do context "with a lambda" do - setup { FiltersControllerTester.allow_filtering :test_action1, :if => lambda {|c| c.test_action1 } } + setup { FiltersControllerTester.allow_filtering :test_action1, if: lambda { |c| c.test_action1 } } should "should allow filtering for test_action1" do - change_params(:action => :test_action1) + change_params(action: :test_action1) assert subject.filtering_allowed? end end context "with a method" do - setup { FiltersControllerTester.allow_filtering :test_action1, :if => :test_action1 } + setup { FiltersControllerTester.allow_filtering :test_action1, if: :test_action1 } should "should allow filtering for test_action1" do - change_params(:action => :test_action1) + change_params(action: :test_action1) assert subject.filtering_allowed? end end context "with a true/false" do - setup { FiltersControllerTester.allow_filtering :test_action1, :if => true } + setup { FiltersControllerTester.allow_filtering :test_action1, if: true } should "should allow filtering for test_action1" do - change_params(:action => :test_action1) + change_params(action: :test_action1) assert subject.filtering_allowed? end end @@ -69,28 +74,28 @@ class FiltersTest < ActiveSupport::TestCase context "unless" do context "with a lambda" do - setup { FiltersControllerTester.allow_filtering :test_action1, :unless => lambda {|c| c.test_action2 } } + setup { FiltersControllerTester.allow_filtering :test_action1, unless: lambda { |c| c.test_action2 } } should "should allow filtering for test_action1" do - change_params(:action => :test_action1) + change_params(action: :test_action1) assert subject.filtering_allowed? end end context "with a method" do - setup { FiltersControllerTester.allow_filtering :test_action1, :unless => :test_action2 } + setup { FiltersControllerTester.allow_filtering :test_action1, unless: :test_action2 } should "should allow filtering for test_action1" do - change_params(:action => :test_action1) + change_params(action: :test_action1) assert subject.filtering_allowed? end end context "with a true/false" do - setup { FiltersControllerTester.allow_filtering :test_action1, :unless => false } + setup { FiltersControllerTester.allow_filtering :test_action1, unless: false } should "should allow filtering for test_action1" do - change_params(:action => :test_action1) + change_params(action: :test_action1) assert subject.filtering_allowed? end end @@ -100,12 +105,12 @@ class FiltersTest < ActiveSupport::TestCase setup { FiltersControllerTester.allow_filtering :test_action1 } should "should allow filtering for test_action1" do - change_params(:action => :test_action1) + change_params(action: :test_action1) assert subject.filtering_allowed? end should "should not allow filtering for test_action2" do - change_params(:action => :test_action2) + change_params(action: :test_action2) assert !subject.filtering_allowed? end end @@ -114,12 +119,12 @@ class FiltersTest < ActiveSupport::TestCase setup { FiltersControllerTester.allow_filtering } should "should allow filtering for test_action1" do - change_params(:action => :test_action1) + change_params(action: :test_action1) assert subject.filtering_allowed? end should "should allow filtering for test_action2" do - change_params(:action => :test_action1) + change_params(action: :test_action1) assert subject.filtering_allowed? end end diff --git a/test/helper.rb b/test/helper.rb index 78bce43..ec8d678 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -1,16 +1,16 @@ -require 'bundler/setup' +require "bundler/setup" ENV["RAILS_ENV"] = "test" begin - require 'byebug' + require "byebug" rescue LoadError end -require 'minitest/autorun' +require "minitest/autorun" -require 'shoulda' -require 'active_support/version' +require "shoulda" +require "active_support/version" require "action_controller/railtie" require "rails/test_unit/railtie" @@ -20,7 +20,7 @@ class TestApp < Rails::Application config.active_support.test_order = :random if config.active_support.respond_to?(:test_order=) config.eager_load = false config.secret_key_base = "secret" - config.logger = Logger.new(RUBY_PLATFORM =~ /(mingw|bccwin|wince|mswin32)/i ? 'NUL:' : '/dev/null') + config.logger = Logger.new(RUBY_PLATFORM.match?(/(mingw|bccwin|wince|mswin32)/i) ? "NUL:" : "/dev/null") end class TestEngine < Rails::Engine @@ -29,14 +29,14 @@ class TestEngine < Rails::Engine TestApp.initialize! TestEngine.routes.draw do - match '/engine/abc/test' => "engine#test", :via => :post + match "/engine/abc/test" => "engine#test", :via => :post end TestApp.routes.draw do - mount TestEngine => '' - match '/test' => "test#test", :via => [:get, :put] - match '*path.:format' => 'charcoal/cross_origin#preflight', :via => :options - get ':controller/:action' + mount TestEngine => "" + match "/test" => "test#test", :via => [:get, :put] + match "*path.:format" => "charcoal/cross_origin#preflight", :via => :options + get ":controller/:action" end class ActiveSupport::TestCase @@ -52,4 +52,4 @@ def setup end require "action_controller/action_caching" -require 'charcoal' +require "charcoal" diff --git a/test/jsonp_test.rb b/test/jsonp_test.rb index 9fd6c36..2d03ec4 100644 --- a/test/jsonp_test.rb +++ b/test/jsonp_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', File.dirname(__FILE__)) +require File.expand_path("helper", File.dirname(__FILE__)) class JSONPControllerTester < ActionController::Base include Charcoal::JSONP @@ -7,7 +7,7 @@ class JSONPControllerTester < ActionController::Base allow_jsonp :test def test - render :json => { :key => :value } + render json: {key: :value} end end @@ -28,7 +28,7 @@ class JSONPTest < ActionController::TestCase context "a GET to :test" do setup do - get :test, :params => { :callback => "hello" } + get :test, params: {callback: "hello"} end should "return a proper response" do @@ -41,7 +41,7 @@ class JSONPTest < ActionController::TestCase context "a second call" do setup do - get :test, :params => { :callback => "hello" } + get :test, params: {callback: "hello"} end should "properly cache the response" do @@ -70,13 +70,13 @@ class JSONPTest < ActionController::TestCase subject.response = (defined?(ActionDispatch) ? ActionDispatch : ActionController)::Response.new subject.response.body = @response - subject.response.status = '200 OK' + subject.response.status = "200 OK" subject.response.content_type = @content_type end context "with params" do setup do - change_params(:callback => "callback", :action => "test") + change_params(callback: "callback", action: "test") subject.send(:add_jsonp_callback) {} end diff --git a/test/utilities_test.rb b/test/utilities_test.rb index fecd009..eef2a53 100644 --- a/test/utilities_test.rb +++ b/test/utilities_test.rb @@ -1,5 +1,5 @@ -require File.expand_path('helper', File.dirname(__FILE__)) -require 'charcoal/utilities' +require File.expand_path("helper", File.dirname(__FILE__)) +require "charcoal/utilities" class TestCorsController < ActionController::Base include Charcoal::CrossOrigin @@ -17,20 +17,20 @@ def test class TestCorsControllerTest < ActionController::TestCase context TestCorsController do - context '#allowed_methods_for?' do + context "#allowed_methods_for?" do subject { TestCorsController.new } setup do - subject.params = { :action => "test" } + subject.params = {action: "test"} end - should 'return the allowed methods' do + should "return the allowed methods" do get :test parsed_response = JSON.parse(response.body) - refute parsed_response['cors'].empty? - assert parsed_response['others'].empty? + refute parsed_response["cors"].empty? + assert parsed_response["others"].empty? end end end