Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ test/dummy/tmp/
test/dummy/.sass-cache
gemfiles/*.lock
Gemfile.lock
.DS_Store
.ruby-gemset
.ruby-version
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 1 addition & 14 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
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', '~> 5.2.3'
gem 'rails-controller-testing'
end
18 changes: 9 additions & 9 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_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.

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 Expand Up @@ -228,13 +228,13 @@ $ 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
- 2.5.5
- 2.4.6

Rails:
- v3.2.18
- v4.0.5
- v4.1.1
- v4.2.11.1
- v5.2.3

### Other Platforms
As of v0.1.2, *experimental* Mongoid support was added by @joshfrench of [Upworthy](http://www.upworthy.com/).
Expand Down
5 changes: 3 additions & 2 deletions fastly-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ 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.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
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.

17 changes: 4 additions & 13 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 Expand Up @@ -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"
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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__)
4 changes: 2 additions & 2 deletions test/dummy/test/controllers/books_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
8 changes: 4 additions & 4 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
# 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
4 changes: 2 additions & 2 deletions test/dummy/test/integration/fastly_headers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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

Expand Down
10 changes: 5 additions & 5 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
require "minitest/autorun"
require 'database_cleaner'
require 'ffaker'
require 'factory_girl_rails'
require 'factory_bot_rails'
require 'webmock/minitest'

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