Skip to content

Commit

Permalink
Upgraded to ruby 3.3.0 rails 7.0 fastly-ruby 3.0.0
Browse files Browse the repository at this point in the history
Add github workflows test
  • Loading branch information
masayukioguni committed Jan 20, 2024
1 parent 651256c commit 63d1b20
Show file tree
Hide file tree
Showing 22 changed files with 59 additions and 85 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ test/dummy/tmp/
test/dummy/.sass-cache
gemfiles/*.lock
Gemfile.lock
gemfiles/vendor/
vendor
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 5 additions & 13 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,18 @@ 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.

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
Expand Down
7 changes: 3 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -41,5 +41,4 @@ Rake::TestTask.new(:test) do |t|
t.verbose = false
end


task default: :test
7 changes: 3 additions & 4 deletions fastly-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 0 additions & 8 deletions gemfiles/rails_3.gemfile

This file was deleted.

7 changes: 0 additions & 7 deletions gemfiles/rails_4.gemfile

This file was deleted.

7 changes: 0 additions & 7 deletions gemfiles/rails_41.gemfile

This file was deleted.

4 changes: 2 additions & 2 deletions gemfiles/rails_5.gemfile → gemfiles/rails_7.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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: "../"
8 changes: 8 additions & 0 deletions gemfiles/rails_7_1.gemfile
Original file line number Diff line number Diff line change
@@ -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: "../"
4 changes: 2 additions & 2 deletions test/dummy/app/controllers/books_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/dummy/config/boot.rb
Original file line number Diff line number Diff line change
@@ -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__)
Binary file added test/dummy/db/test.sqlite3-shm
Binary file not shown.
Binary file added test/dummy/db/test.sqlite3-wal
Binary file not shown.
7 changes: 4 additions & 3 deletions test/dummy/test/controllers/books_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand All @@ -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
6 changes: 3 additions & 3 deletions test/dummy/test/factories/books.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 2 additions & 3 deletions test/dummy/test/integration/fastly_headers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions test/dummy/test/lib/remove_set_cookie_header_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
5 changes: 3 additions & 2 deletions test/dummy/test/models/book_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 8 additions & 12 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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").
Expand All @@ -44,7 +40,7 @@ class Minitest::Spec
)

WebMock.disable_net_connect!

DatabaseCleaner.strategy = :truncation
DatabaseCleaner.start
end

Expand All @@ -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, /.*/).
Expand Down

0 comments on commit 63d1b20

Please sign in to comment.