From e1ae39122caedeff7f2c3841892f187f12847002 Mon Sep 17 00:00:00 2001 From: mhuggins Date: Thu, 5 Nov 2015 23:03:31 -0700 Subject: [PATCH 1/5] Fix failing tests --- test/serialization_test.rb | 2 +- test/serializer_test.rb | 2 ++ test/test_fakes.rb | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/test/serialization_test.rb b/test/serialization_test.rb index a9285820..121e7fd8 100644 --- a/test/serialization_test.rb +++ b/test/serialization_test.rb @@ -242,7 +242,7 @@ class RenderJsonTest < ActionController::TestCase def test_render_json_with_callback get :render_json_hello_world_with_callback - assert_equal 'alert({"hello":"world"})', @response.body + assert_equal '/**/alert({"hello":"world"})', @response.body # For JSONP, Rails 3 uses application/json, but Rails 4 uses text/javascript assert_match %r(application/json|text/javascript), @response.content_type.to_s end diff --git a/test/serializer_test.rb b/test/serializer_test.rb index 2ef49a87..27de686b 100644 --- a/test/serializer_test.rb +++ b/test/serializer_test.rb @@ -1363,6 +1363,7 @@ class SerializerTest < ActiveModel::TestCase def test_inheritance_does_not_used_cached_attributes parent = Class.new(ActiveModel::Serializer) do attributes :title + alias :read_attribute_for_serialization :send end child = Class.new(parent) do @@ -1371,6 +1372,7 @@ class SerializerTest < ActiveModel::TestCase data_class = Class.new do attr_accessor :title, :body + alias :read_attribute_for_serialization :send end item = data_class.new diff --git a/test/test_fakes.rb b/test/test_fakes.rb index dd2039e9..98228ef8 100644 --- a/test/test_fakes.rb +++ b/test/test_fakes.rb @@ -199,6 +199,7 @@ class SomeSerializer < ActiveModel::Serializer end class SomeObject < Struct.new(:some) + alias :read_attribute_for_serialization :send end # Set up some classes for polymorphic testing From 66caef5a0c10b25d81825591f598bd69a3f0ecb0 Mon Sep 17 00:00:00 2001 From: mhuggins Date: Mon, 14 Dec 2015 09:23:58 -0700 Subject: [PATCH 2/5] Remove Ruby 1.8 and 1.9.2 support --- .travis.yml | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index d96b3eed..b4b8d009 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,7 @@ language: ruby rvm: - - 1.8.7 - - 1.9.2 - 1.9.3 - 2.0.0 - - ree - - jruby-18mode - jruby-19mode - rbx-2 gemfile: @@ -14,15 +10,3 @@ gemfile: matrix: allow_failures: - gemfile: Gemfile.edge - exclude: - # Edge Rails is only compatible with 1.9.3 - - gemfile: Gemfile.edge - rvm: 1.8.7 - - gemfile: Gemfile.edge - rvm: 1.9.2 - - gemfile: Gemfile.edge - rvm: ree - - gemfile: Gemfile.edge - rvm: jruby-18mode - - gemfile: Gemfile.edge - rvm: rbx-18mode From b05d9dbd36c74ad23e7792b64e64db3c0359d6b1 Mon Sep 17 00:00:00 2001 From: mhuggins Date: Mon, 14 Dec 2015 11:34:58 -0700 Subject: [PATCH 3/5] Add appveyor.yml --- Rakefile | 3 +++ appveyor.yml | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 appveyor.yml diff --git a/Rakefile b/Rakefile index 23f17c4a..c9dc801b 100644 --- a/Rakefile +++ b/Rakefile @@ -16,3 +16,6 @@ task :bench do end task :default => :test + +desc 'CI test task' +task :ci => :default diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 00000000..6190feab --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,29 @@ +version: '{build}' + +skip_tags: true + +environment: + matrix: + - ruby_version: "193" + - ruby_version: "193-x64" + - ruby_version: "200" + - ruby_version: "200-x64" + - ruby_version: "21" + - ruby_version: "21-x64" + +cache: + - vendor/bundle + +install: + - SET PATH=C:\Ruby%ruby_version%\bin;%PATH% + - ruby --version + - gem --version + - gem install bundler + - bundler --version + - bundle platform + - bundle install --path=vendor/bundle --retry=3 --jobs=3 + +test_script: + - bundle exec rake ci + +build: off From d03b8179f536788fc9f3730657dab9e1c7e954bb Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Mon, 14 Dec 2015 21:36:52 -0600 Subject: [PATCH 4/5] Adjust test for Rails versions that address CVE-2014-4671 Compare https://github.com/rails/rails/blob/3-2-stable/actionpack/lib/action_controller/metal/renderers.rb#L94 to https://github.com/rails/rails/blob/4-0-stable/actionpack/lib/action_controller/metal/renderers.rb#L97 --- test/serialization_test.rb | 10 +++++++--- test/serializer_test.rb | 3 +-- test/test_fakes.rb | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/test/serialization_test.rb b/test/serialization_test.rb index 121e7fd8..1465585d 100644 --- a/test/serialization_test.rb +++ b/test/serialization_test.rb @@ -242,9 +242,13 @@ class RenderJsonTest < ActionController::TestCase def test_render_json_with_callback get :render_json_hello_world_with_callback - assert_equal '/**/alert({"hello":"world"})', @response.body - # For JSONP, Rails 3 uses application/json, but Rails 4 uses text/javascript - assert_match %r(application/json|text/javascript), @response.content_type.to_s + if Rails::VERSION::MAJOR == 3 + assert_equal 'alert({"hello":"world"})', @response.body + assert_match %r(application/json), @response.content_type.to_s + else + assert_equal '/**/alert({"hello":"world"})', @response.body + assert_match %r(text/javascript), @response.content_type.to_s + end end def test_render_json_with_custom_content_type diff --git a/test/serializer_test.rb b/test/serializer_test.rb index 27de686b..7e3e5aff 100644 --- a/test/serializer_test.rb +++ b/test/serializer_test.rb @@ -1363,7 +1363,6 @@ class SerializerTest < ActiveModel::TestCase def test_inheritance_does_not_used_cached_attributes parent = Class.new(ActiveModel::Serializer) do attributes :title - alias :read_attribute_for_serialization :send end child = Class.new(parent) do @@ -1371,8 +1370,8 @@ class SerializerTest < ActiveModel::TestCase end data_class = Class.new do + include ActiveModel::Serializers::JSON attr_accessor :title, :body - alias :read_attribute_for_serialization :send end item = data_class.new diff --git a/test/test_fakes.rb b/test/test_fakes.rb index 98228ef8..366790e0 100644 --- a/test/test_fakes.rb +++ b/test/test_fakes.rb @@ -199,7 +199,7 @@ class SomeSerializer < ActiveModel::Serializer end class SomeObject < Struct.new(:some) - alias :read_attribute_for_serialization :send + include ActiveModel::Serializers::JSON end # Set up some classes for polymorphic testing From 75252a2ef994e08680acb6982591a3a2fad3ffaf Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Mon, 14 Dec 2015 21:44:51 -0600 Subject: [PATCH 5/5] Run CI against Rails >= 4.0, Ruby >= 1.9.3 --- .travis.yml | 48 ++++++++++++++++++++++++++++++++++++++------- Gemfile | 29 +++++++++++++++++++++++++++ Gemfile.edge | 9 --------- Rakefile | 1 + appveyor.yml | 2 -- test/test_helper.rb | 31 +++++++++++++++++++++++++---- 6 files changed, 98 insertions(+), 22 deletions(-) delete mode 100644 Gemfile.edge diff --git a/.travis.yml b/.travis.yml index b4b8d009..b3603cff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,46 @@ language: ruby +sudo: false rvm: - - 1.9.3 - - 2.0.0 + # - 1.8.7 + # - ree + # - jruby-18mode + # - 1.9.2 + # - 1.9.3 - jruby-19mode + - 2.0.0 + - 2.1 + - 2.2 - rbx-2 -gemfile: - - Gemfile - - Gemfile.edge +install: bundle install --path=vendor/bundle --retry=3 --jobs=3 +cache: + directories: + - vendor/bundle +script: + - bundle exec rake ci +env: + # - "RAILS_VERSION=3.0" + # - "RAILS_VERSION=3.1" + # - "RAILS_VERSION=3.2" + - "RAILS_VERSION=4.0" + - "RAILS_VERSION=4.1" + - "RAILS_VERSION=4.2" + - "RAILS_VERSION=master" matrix: - allow_failures: - - gemfile: Gemfile.edge + exclude: + # - rvm: 1.8.7 + # - ree + # - jruby-18mode + # - rvm: 1.9.2 + - rvm: 1.9.3 + env: RAILS_VERSION=master + - rvm: jruby-19mode + env: RAILS_VERSION=master + - rvm: 2.0.0 + env: RAILS_VERSION=master + - rvm: 2.1 + env: RAILS_VERSION=master + - rvm: 2.2 + env: RAILS_VERSION=master + - rvm: rbx-2 + env: RAILS_VERSION=master + fast_finish: true diff --git a/Gemfile b/Gemfile index 5425c9eb..06e858e4 100644 --- a/Gemfile +++ b/Gemfile @@ -2,3 +2,32 @@ source 'https://rubygems.org' # Specify gem dependencies in active_model_serializers.gemspec gemspec + +version = ENV['RAILS_VERSION'] || '4.0' + +if version == 'master' + gem 'rack', github: 'rack/rack' + gem 'arel', github: 'rails/arel' + git 'https://github.com/rails/rails.git' do + gem 'railties' + gem 'activesupport' + gem 'activemodel' + gem 'actionpack' + gem 'activerecord', group: :test + # Rails 5 + gem 'actionview' + end +else + gem_version = "~> #{version}.0" + gem 'railties', gem_version + gem 'activesupport', gem_version + gem 'activemodel', gem_version + gem 'actionpack', gem_version + gem 'activerecord', gem_version, group: :test +end + +# https://github.com/bundler/bundler/blob/89a8778c19269561926cea172acdcda241d26d23/lib/bundler/dependency.rb#L30-L54 +@windows_platforms = [:mswin, :mingw, :x64_mingw] + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem 'tzinfo-data', platforms: (@windows_platforms + [:jruby]) diff --git a/Gemfile.edge b/Gemfile.edge deleted file mode 100644 index d4e1c028..00000000 --- a/Gemfile.edge +++ /dev/null @@ -1,9 +0,0 @@ -source 'http://rubygems.org' - -gemspec - -gem 'rails', github: 'rails/rails' - -# Current dependencies of edge rails -gem 'journey', github: 'rails/journey' -gem 'activerecord-deprecated_finders' , github: 'rails/activerecord-deprecated_finders' diff --git a/Rakefile b/Rakefile index c9dc801b..a13ebb82 100644 --- a/Rakefile +++ b/Rakefile @@ -7,6 +7,7 @@ Rake::TestTask.new(:test) do |t| t.libs << 'lib' t.libs << 'test' t.pattern = 'test/**/*_test.rb' + t.ruby_opts = ['-r./test/test_helper.rb'] t.verbose = true end diff --git a/appveyor.yml b/appveyor.yml index 6190feab..17b387ff 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -4,8 +4,6 @@ skip_tags: true environment: matrix: - - ruby_version: "193" - - ruby_version: "193-x64" - ruby_version: "200" - ruby_version: "200-x64" - ruby_version: "21" diff --git a/test/test_helper.rb b/test/test_helper.rb index e36c3700..b7b3f2e9 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,13 +1,36 @@ require "rubygems" require "bundler/setup" +require 'rails' +require 'action_controller' +require 'action_controller/test_case' +require 'action_controller/railtie' +require 'active_support/json' + +gem 'minitest' +require 'minitest/autorun' +if defined?(Minitest::Test) + $minitest_version = 5 # rubocop:disable Style/GlobalVars + # Minitest 5 + # https://github.com/seattlerb/minitest/blob/e21fdda9d/lib/minitest/autorun.rb + # https://github.com/seattlerb/minitest/blob/e21fdda9d/lib/minitest.rb#L45-L59 +else + $minitest_version = 4 # rubocop:disable Style/GlobalVars + # Minitest 4 + # https://github.com/seattlerb/minitest/blob/644a52fd0/lib/minitest/autorun.rb + # https://github.com/seattlerb/minitest/blob/644a52fd0/lib/minitest/unit.rb#L768-L787 + # Ensure backward compatibility with Minitest 4 + Minitest = MiniTest unless defined?(Minitest) + Minitest::Test = MiniTest::Unit::TestCase + def Minitest.after_run(&block) + MiniTest::Unit.after_tests(&block) + end +end + + require "pry" require "active_model_serializers" -require "active_support/json" -require "minitest/autorun" - -require 'rails' module TestHelper Routes = ActionDispatch::Routing::RouteSet.new