From 543b998e0758e866f87345717cd9a4efeb0accf4 Mon Sep 17 00:00:00 2001 From: Ty Rauber Date: Wed, 6 Jun 2018 12:38:30 -0700 Subject: [PATCH 1/4] Update fastly-rails to use fastly 2.0 --- fastly-rails.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastly-rails.gemspec b/fastly-rails.gemspec index 6a597c4..c190773 100644 --- a/fastly-rails.gemspec +++ b/fastly-rails.gemspec @@ -15,7 +15,7 @@ Gem::Specification.new do |s| s.test_files = Dir["test/**/*"] s.add_dependency "railties", '> 2', '< 6' - s.add_dependency 'fastly', '~> 1.6' + s.add_dependency 'fastly', '~> 2.0' s.add_development_dependency "sqlite3" s.add_development_dependency "database_cleaner" From 47dd262322ee0c60c8e4ccd4edd473b9ca74132b Mon Sep 17 00:00:00 2001 From: Ty Rauber Date: Sat, 27 Apr 2019 10:22:51 -0700 Subject: [PATCH 2/4] =?UTF-8?q?Update=20fastly-rails=20fastly-rails=20hasn?= =?UTF-8?q?=E2=80=99t=20been=20updated=20in=20over=202=20years.=20With=20t?= =?UTF-8?q?he=20release=20of=20factly-ruby=202.3.0,=20that=20adds=20thread?= =?UTF-8?q?=20safety=20and=20concurrency,=20this=20gem=20needs=20to=20be?= =?UTF-8?q?=20updated=20as=20well.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes: - update factly-ruby to 2.3.0 - factory_girl_rails is deprecated, migrate to factory_bot_rails - remove old appraisals (deprecated ruby and rails versions and conflicts with bundler update to 2.0) - test ruby 2.6.3 and rails 5.2.3 - fix test failures (get :show, params: {}) - fix minitest deprecations (asset_nil) - Rails 5 before_action --- .gitignore | 3 +++ Appraisals | 13 ------------- README.md | 7 ++----- fastly-rails.gemspec | 5 +++-- gemfiles/rails_3.gemfile | 8 -------- gemfiles/rails_4.gemfile | 7 ------- gemfiles/rails_41.gemfile | 7 ------- test/dummy/app/controllers/books_controller.rb | 17 ++++------------- test/dummy/config/application.rb | 1 + test/dummy/config/boot.rb | 2 +- .../test/controllers/books_controller_test.rb | 4 ++-- test/dummy/test/factories/books.rb | 8 ++++---- .../test/integration/fastly_headers_test.rb | 4 ++-- test/fastly-rails_test.rb | 4 ++-- test/test_helper.rb | 10 +++++----- 15 files changed, 29 insertions(+), 71 deletions(-) delete mode 100644 gemfiles/rails_3.gemfile delete mode 100644 gemfiles/rails_4.gemfile delete mode 100644 gemfiles/rails_41.gemfile diff --git a/.gitignore b/.gitignore index 316a815..ae0ed29 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,6 @@ test/dummy/tmp/ test/dummy/.sass-cache gemfiles/*.lock Gemfile.lock +.DS_Store +.ruby-gemset +.ruby-version \ No newline at end of file diff --git a/Appraisals b/Appraisals index dc4de30..d5d1449 100644 --- a/Appraisals +++ b/Appraisals @@ -1,16 +1,3 @@ -appraise 'rails-3' do - gem 'rails', '~> 3.2.18' - gem 'test-unit', '~> 3.0' -end - -appraise 'rails-4' do - gem 'rails', '~> 4.0.5' -end - -appraise 'rails-41' do - gem 'rails', '~> 4.1.1' -end - appraise 'rails-5' do gem 'rails', '~> 5.0' gem 'rails-controller-testing' diff --git a/README.md b/README.md index 70506ce..abab529 100644 --- a/README.md +++ b/README.md @@ -228,13 +228,10 @@ $ appraisal rails-3 rake test # finds a defined version in the Appraisals file c We [run tests](https://travis-ci.org/fastly/fastly-rails) using all combinations of the following versions of Ruby and Rails: Ruby: - - 1.9.3 - - 2.1.1 + - 2.6.3 Rails: - - v3.2.18 - - v4.0.5 - - v4.1.1 + - v5.2.3 ### Other Platforms As of v0.1.2, *experimental* Mongoid support was added by @joshfrench of [Upworthy](http://www.upworthy.com/). diff --git a/fastly-rails.gemspec b/fastly-rails.gemspec index c190773..71e4d60 100644 --- a/fastly-rails.gemspec +++ b/fastly-rails.gemspec @@ -15,14 +15,15 @@ Gem::Specification.new do |s| s.test_files = Dir["test/**/*"] s.add_dependency "railties", '> 2', '< 6' - s.add_dependency 'fastly', '~> 2.0' + s.add_dependency 'fastly', '~> 2.3.0' s.add_development_dependency "sqlite3" s.add_development_dependency "database_cleaner" - s.add_development_dependency "factory_girl_rails" + s.add_development_dependency "factory_bot_rails" s.add_development_dependency "ffaker" s.add_development_dependency "minitest-spec-rails" s.add_development_dependency "appraisal" + s.add_development_dependency "rails-controller-testing" s.add_development_dependency 'webmock', ((RUBY_VERSION <= '1.9.3') ? '2.2.0' : '>= 2.3.0') s.add_development_dependency 'rails' end diff --git a/gemfiles/rails_3.gemfile b/gemfiles/rails_3.gemfile deleted file mode 100644 index bbd9aa2..0000000 --- a/gemfiles/rails_3.gemfile +++ /dev/null @@ -1,8 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "rails", "~> 3.2.18" -gem "test-unit", "~> 3.0" - -gemspec :path => "../" diff --git a/gemfiles/rails_4.gemfile b/gemfiles/rails_4.gemfile deleted file mode 100644 index 39a1bd6..0000000 --- a/gemfiles/rails_4.gemfile +++ /dev/null @@ -1,7 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "rails", "~> 4.0.5" - -gemspec :path => "../" diff --git a/gemfiles/rails_41.gemfile b/gemfiles/rails_41.gemfile deleted file mode 100644 index 8dfe1fe..0000000 --- a/gemfiles/rails_41.gemfile +++ /dev/null @@ -1,7 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "rails", "~> 4.1.1" - -gemspec :path => "../" diff --git a/test/dummy/app/controllers/books_controller.rb b/test/dummy/app/controllers/books_controller.rb index 91aea7f..4a5a272 100644 --- a/test/dummy/app/controllers/books_controller.rb +++ b/test/dummy/app/controllers/books_controller.rb @@ -1,6 +1,6 @@ class BooksController < ApplicationController - before_filter :set_cache_control_headers, only: [:index, :show] - before_filter :find_book, :only => [:show, :edit, :update, :destroy] + before_action :set_cache_control_headers, only: [:index, :show] + before_action :find_book, :only => [:show, :edit, :update, :destroy] def index @books = Book.all @@ -29,12 +29,7 @@ def edit end def update - if rails_4? - method = :update - else - method = :update_attributes - end - if @book.send(method, books_params) + if @book.update(books_params) redirect_to book_path(@book) else flash[:notice] = "failed to update book" @@ -54,11 +49,7 @@ def destroy private def books_params - if rails_4? - params.require(:book).permit! - else - params[:book] - end + params.require(:book).permit! end def find_book diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb index 0d4a600..fd71ea9 100644 --- a/test/dummy/config/application.rb +++ b/test/dummy/config/application.rb @@ -7,6 +7,7 @@ module Dummy class Application < Rails::Application + Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. diff --git a/test/dummy/config/boot.rb b/test/dummy/config/boot.rb index ef36047..6266cfc 100644 --- a/test/dummy/config/boot.rb +++ b/test/dummy/config/boot.rb @@ -1,5 +1,5 @@ # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__) -require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) +require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__) diff --git a/test/dummy/test/controllers/books_controller_test.rb b/test/dummy/test/controllers/books_controller_test.rb index 2374830..b144c3c 100644 --- a/test/dummy/test/controllers/books_controller_test.rb +++ b/test/dummy/test/controllers/books_controller_test.rb @@ -27,7 +27,7 @@ def setup test "show" do expected_id = 1 - get :show, {:id => expected_id} + get :show, params: { id: expected_id} assert_response :success, 'it should return successfully' assert_not_nil assigns(:book), '@book should not be nil' assert_instance_of Book, assigns(:book), 'it should be an instance of a book' @@ -38,7 +38,7 @@ def setup test "create" do expected_name = 'newly-created-book' assert_difference('Book.count') do - post :create, :book => {'name' => expected_name} + post :create, params: { book: {'name' => expected_name}} end end end diff --git a/test/dummy/test/factories/books.rb b/test/dummy/test/factories/books.rb index a64efcc..e0a0cc9 100644 --- a/test/dummy/test/factories/books.rb +++ b/test/dummy/test/factories/books.rb @@ -1,8 +1,8 @@ -# Read about factories at https://github.com/thoughtbot/factory_girl +# Read about factories at https://github.com/thoughtbot/factory_bot -FactoryGirl.define do +FactoryBot.define do factory :book do - name 'some book name' - service_id 'asdf' + name { 'some book name' } + service_id { 'asdf' } end end diff --git a/test/dummy/test/integration/fastly_headers_test.rb b/test/dummy/test/integration/fastly_headers_test.rb index 61a5bac..3f8c166 100644 --- a/test/dummy/test/integration/fastly_headers_test.rb +++ b/test/dummy/test/integration/fastly_headers_test.rb @@ -41,7 +41,7 @@ class FastlyHeadersTest < ActionDispatch::IntegrationTest test 'POST /books should not have fastly headers/ fastly header values' do assert_difference('Book.count') do - post '/books', 'book' => { 'name' => 'some new book' } + post '/books', params: { book: { name: 'some new book' }} end assert_nil request.session_options[:skip] @@ -57,7 +57,7 @@ class FastlyHeadersTest < ActionDispatch::IntegrationTest create :book, :id => 1, :name => 'some new book' - put '/books/1', 'id' => 1, 'book' => { 'name' => 'changed book' } + put '/books/1', params: { id: 1, book: { 'name' => 'changed book' }} assert_equal 'changed book', Book.find(1).name diff --git a/test/fastly-rails_test.rb b/test/fastly-rails_test.rb index 9e9a4c0..69207d8 100644 --- a/test/fastly-rails_test.rb +++ b/test/fastly-rails_test.rb @@ -43,8 +43,8 @@ it 'should have configuration options set up' do assert_equal api_key, configuration.api_key - assert_equal user, configuration.user - assert_equal password, configuration.password + assert_nil user, configuration.user + assert_nil password, configuration.password assert_equal max_age, configuration.max_age assert_equal service_id, configuration.service_id assert_equal true, configuration.purging_enabled? diff --git a/test/test_helper.rb b/test/test_helper.rb index 3fc4ec0..accf9f1 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -6,7 +6,7 @@ require "minitest/autorun" require 'database_cleaner' require 'ffaker' -require 'factory_girl_rails' +require 'factory_bot_rails' require 'webmock/minitest' begin @@ -27,10 +27,10 @@ # ActiveSupport::TestCase.fixtures :all # end -ActiveRecord::Migrator.migrate File.expand_path('../dummy/db/migrate/', __FILE__) +ActiveRecord::MigrationContext.new(File.expand_path('../dummy/db/migrate', __FILE__)).migrate class Minitest::Spec - include FactoryGirl::Syntax::Methods + include FactoryBot::Syntax::Methods before :each do stub_request(:any, "https://api.fastly.com/login"). @@ -55,12 +55,12 @@ class Minitest::Spec end class ActionController::TestCase - include FactoryGirl::Syntax::Methods + include FactoryBot::Syntax::Methods end class ActionDispatch::IntegrationTest include WebMock::API - include FactoryGirl::Syntax::Methods + include FactoryBot::Syntax::Methods def setup stub_request(:any, /.*/). From ff689af1121883f3f67327048741f24a5904f0a7 Mon Sep 17 00:00:00 2001 From: Ty Rauber Date: Tue, 21 May 2019 10:12:10 -0700 Subject: [PATCH 3/4] - Update docs and test re: before_action - Ruby 2.6.3, 2.5.5, 2.4.6 - Rails 4.2.11.1, 5.2.3 - fix assert_equal in fastly-rails.test for user and password --- .travis.yml | 5 +++-- Appraisals | 7 ++++++- README.md | 11 +++++++---- test/fastly-rails_test.rb | 4 ++-- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5458bea..f37125d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,5 +3,6 @@ before_script: 'bundle exec rake test:setup' script: 'bundle exec rake test:all' cache: bundler rvm: - - 2.3.3 - - 2.2.2 + - 2.6.3 + - 2.5.5 + - 2.4.6 diff --git a/Appraisals b/Appraisals index d5d1449..92b8619 100644 --- a/Appraisals +++ b/Appraisals @@ -1,4 +1,9 @@ + +appraise 'rails-41' do + gem 'rails', '~> 4.2.11.1' +end + appraise 'rails-5' do - gem 'rails', '~> 5.0' + gem 'rails', '~> 5.2.3' gem 'rails-controller-testing' end diff --git a/README.md b/README.md index abab529..6acf66b 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ end ### Headers -This plugin adds a `set_cache_control_headers` method to ActionController. You'll need to add this in a `before_filter` or `after_filter` [see note on cookies below](https://github.com/fastly/fastly-rails#sessions-cookies-and-private-data) to any controller action that you wish to edge cache (see example below). The method sets Cache-Control and Surrogate-Control HTTP Headers with a default of 30 days (remember you can configure this, see the initializer setup above). +This plugin adds a `set_cache_control_headers` method to ActionController. You'll need to add this in a `before_action` or `after_action` [see note on cookies below](https://github.com/fastly/fastly-rails#sessions-cookies-and-private-data) to any controller action that you wish to edge cache (see example below). The method sets Cache-Control and Surrogate-Control HTTP Headers with a default of 30 days (remember you can configure this, see the initializer setup above). It's up to you to set Surrogate-Key headers for objects that you want to be able to purge. @@ -82,10 +82,10 @@ To do this use the `set_surrogate_key_header` method on GET actions. ````ruby class BooksController < ApplicationController - # include this before_filter in controller endpoints that you wish to edge cache - before_filter :set_cache_control_headers, only: [:index, :show] + # include this before_action in controller endpoints that you wish to edge cache + before_action :set_cache_control_headers, only: [:index, :show] # This can be used with any customer actions. Set these headers for GETs that you want to cache - # e.g. before_filter :set_cache_control_headers, only: [:index, :show, :my_custom_action] + # e.g. before_action :set_cache_control_headers, only: [:index, :show, :my_custom_action] def index @books = Book.all @@ -229,8 +229,11 @@ We [run tests](https://travis-ci.org/fastly/fastly-rails) using all combinations Ruby: - 2.6.3 + - 2.5.5 + - 2.4.6 Rails: + - v4.2.11.1 - v5.2.3 ### Other Platforms diff --git a/test/fastly-rails_test.rb b/test/fastly-rails_test.rb index 69207d8..9e9a4c0 100644 --- a/test/fastly-rails_test.rb +++ b/test/fastly-rails_test.rb @@ -43,8 +43,8 @@ it 'should have configuration options set up' do assert_equal api_key, configuration.api_key - assert_nil user, configuration.user - assert_nil password, configuration.password + assert_equal user, configuration.user + assert_equal password, configuration.password assert_equal max_age, configuration.max_age assert_equal service_id, configuration.service_id assert_equal true, configuration.purging_enabled? From 6fa2a13f0c54852562187e19777d0d5a76815a64 Mon Sep 17 00:00:00 2001 From: Ty Rauber Date: Tue, 21 May 2019 10:21:38 -0700 Subject: [PATCH 4/4] Drop 4.2.11.1 appraisal due to bundler conflict. Travis wants to use bundler 2.0 and < Rails 5 require < bundler 2.0, and > Rails 5 requires bundler 2.0. --- Appraisals | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Appraisals b/Appraisals index 92b8619..b52e804 100644 --- a/Appraisals +++ b/Appraisals @@ -1,8 +1,3 @@ - -appraise 'rails-41' do - gem 'rails', '~> 4.2.11.1' -end - appraise 'rails-5' do gem 'rails', '~> 5.2.3' gem 'rails-controller-testing'