diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 20dafd3..a660de7 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -9,28 +9,28 @@ name: Ruby on: push: - branches: [ "master" ] pull_request: - branches: [ "master" ] + types: + - opened + - synchronize + - reopened permissions: contents: read jobs: test: - runs-on: ubuntu-latest strategy: matrix: - ruby-version: ['2.6', '2.7', '3.0'] + ruby-version: ['3.2', '3.3'] steps: - uses: actions/checkout@v3 - name: Set up Ruby # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby, # change this to (see https://github.com/ruby/setup-ruby#versioning): - # uses: ruby/setup-ruby@v1 - uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0 + uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby-version }} bundler-cache: true # runs 'bundle install' and caches installed gems automatically diff --git a/.gitignore b/.gitignore index 316a815..75bf929 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ test/dummy/tmp/ test/dummy/.sass-cache gemfiles/*.lock Gemfile.lock +gemfiles/vendor/ +vendor diff --git a/.travis.yml b/.travis.yml index 5458bea..68d7601 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,5 +3,4 @@ before_script: 'bundle exec rake test:setup' script: 'bundle exec rake test:all' cache: bundler rvm: - - 2.3.3 - - 2.2.2 + - 3.3.0 diff --git a/Appraisals b/Appraisals index dc4de30..e04d285 100644 --- a/Appraisals +++ b/Appraisals @@ -1,17 +1,9 @@ -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' +appraise 'rails-7' do + gem 'rails', '~> 7.0.0' + gem 'rails-controller-testing' end -appraise 'rails-5' do - gem 'rails', '~> 5.0' +appraise 'rails-7_1' do + gem 'rails', '~> 7.1.0' gem 'rails-controller-testing' end diff --git a/README.md b/README.md index 70506ce..6d49497 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_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). 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 diff --git a/Rakefile b/Rakefile index d032fe9..d04190d 100644 --- a/Rakefile +++ b/Rakefile @@ -22,13 +22,13 @@ Bundler::GemHelper.install_tasks namespace :test do desc 'Install dependencies for all tests with appraisal' task :setup do - sh 'bin/rails db:environment:set RAILS_ENV=test 2>&1 >/dev/null || exit 0' - sh 'appraisal install' + sh 'bundle exec appraisal install' end desc 'Run all tests with appraisal' task :all do - sh 'appraisal rake test' + sh 'bundle exec appraisal install' + sh 'bundle exec appraisal rake test' end end @@ -41,5 +41,4 @@ Rake::TestTask.new(:test) do |t| t.verbose = false end - task default: :test diff --git a/fastly-rails.gemspec b/fastly-rails.gemspec index 47c8bb8..e2f4e66 100644 --- a/fastly-rails.gemspec +++ b/fastly-rails.gemspec @@ -15,14 +15,13 @@ Gem::Specification.new do |s| s.test_files = Dir["test/**/*"] s.add_dependency "railties", '> 2', '< 8' - s.add_dependency 'fastly', '~> 1.6' + s.add_dependency 'fastly', '~> 3.0.0' s.add_development_dependency "sqlite3" - s.add_development_dependency "database_cleaner" - s.add_development_dependency "factory_girl_rails" + s.add_development_dependency "database_cleaner-active_record" + s.add_development_dependency "factory_bot" s.add_development_dependency "ffaker" s.add_development_dependency "minitest-spec-rails" s.add_development_dependency "appraisal" 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/gemfiles/rails_5.gemfile b/gemfiles/rails_7.gemfile similarity index 69% rename from gemfiles/rails_5.gemfile rename to gemfiles/rails_7.gemfile index 265a9a1..2be2eae 100644 --- a/gemfiles/rails_5.gemfile +++ b/gemfiles/rails_7.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "rails", "~> 5.0" +gem "rails", "~> 7.0.0" gem "rails-controller-testing" -gemspec :path => "../" +gemspec path: "../" diff --git a/gemfiles/rails_7_1.gemfile b/gemfiles/rails_7_1.gemfile new file mode 100644 index 0000000..45820b6 --- /dev/null +++ b/gemfiles/rails_7_1.gemfile @@ -0,0 +1,8 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "~> 7.1.0" +gem "rails-controller-testing" + +gemspec path: "../" diff --git a/test/dummy/app/controllers/books_controller.rb b/test/dummy/app/controllers/books_controller.rb index 91aea7f..b527103 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 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/db/test.sqlite3-shm b/test/dummy/db/test.sqlite3-shm new file mode 100644 index 0000000..2011f03 Binary files /dev/null and b/test/dummy/db/test.sqlite3-shm differ diff --git a/test/dummy/db/test.sqlite3-wal b/test/dummy/db/test.sqlite3-wal new file mode 100644 index 0000000..1213024 Binary files /dev/null and b/test/dummy/db/test.sqlite3-wal differ diff --git a/test/dummy/test/controllers/books_controller_test.rb b/test/dummy/test/controllers/books_controller_test.rb index 2374830..b6d0903 100644 --- a/test/dummy/test/controllers/books_controller_test.rb +++ b/test/dummy/test/controllers/books_controller_test.rb @@ -9,7 +9,8 @@ def setup :body => "{}" ) @no_of_books = 5 - create_list :book, @no_of_books + + FactoryBot.create_list(:book, @no_of_books) end test "index" do @@ -27,7 +28,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 +39,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..2d1f9e6 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 -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..73631e5 100644 --- a/test/dummy/test/integration/fastly_headers_test.rb +++ b/test/dummy/test/integration/fastly_headers_test.rb @@ -39,9 +39,8 @@ class FastlyHeadersTest < ActionDispatch::IntegrationTest end 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 +56,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: { book: { id: 1, name: 'changed book'}} assert_equal 'changed book', Book.find(1).name diff --git a/test/dummy/test/lib/remove_set_cookie_header_test.rb b/test/dummy/test/lib/remove_set_cookie_header_test.rb index bf8bf19..a007b46 100644 --- a/test/dummy/test/lib/remove_set_cookie_header_test.rb +++ b/test/dummy/test/lib/remove_set_cookie_header_test.rb @@ -28,7 +28,7 @@ end it "keeps 'set-cookie' if no 'surrogate-control' or 'surrogate-key'" do - headers = { "Set-Cookie" => "yes!!" } + headers = { "Set-Cookie" => "yes=!!" } app = Rack::Builder.new do use FastlyRails::Rack::RemoveSetCookieHeader @@ -38,6 +38,6 @@ env = Rack::MockRequest.env_for('/') response = Rack::MockResponse.new(*app.call(env)) - assert_equal response.headers['Set-Cookie'], "yes!!" + assert_equal response.headers['Set-Cookie'], "yes=!!" end end diff --git a/test/dummy/test/models/book_test.rb b/test/dummy/test/models/book_test.rb index 400385c..f929913 100644 --- a/test/dummy/test/models/book_test.rb +++ b/test/dummy/test/models/book_test.rb @@ -8,10 +8,11 @@ describe Book do - let (:book) { create :book, id: 1 } + let (:book) { + FactoryBot.create(:book, id: 1) + } it "should have Fastly::SurrogateKey instance methods" do - [:record_key, :table_key, :purge, :purge_all, :soft_purge, :soft_purge_all].each do |method| assert_respond_to book, method end diff --git a/test/test_helper.rb b/test/test_helper.rb index 3fc4ec0..d3adbb5 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -3,17 +3,13 @@ require File.expand_path("../dummy/config/environment.rb", __FILE__) require "rails/test_help" +require "minitest/unit" require "minitest/autorun" -require 'database_cleaner' +require 'database_cleaner/active_record' require 'ffaker' -require 'factory_girl_rails' +require 'factory_bot' require 'webmock/minitest' -begin - require 'rails-controller-testing' -rescue LoadError -end - Rails.backtrace_cleaner.remove_silencers! #include factories @@ -27,10 +23,10 @@ # ActiveSupport::TestCase.fixtures :all # end -ActiveRecord::Migrator.migrate File.expand_path('../dummy/db/migrate/', __FILE__) +ActiveRecord::MigrationContext.new("db/migrate/", ActiveRecord::SchemaMigration).migrate class Minitest::Spec - include FactoryGirl::Syntax::Methods + include FactoryBot::Syntax::Methods before :each do stub_request(:any, "https://api.fastly.com/login"). @@ -44,7 +40,7 @@ class Minitest::Spec ) WebMock.disable_net_connect! - + DatabaseCleaner.strategy = :truncation DatabaseCleaner.start end @@ -55,12 +51,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, /.*/).