rack-noncache 0.0.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.pryrc +6 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +15 -0
  7. data/README.md +36 -52
  8. data/Rakefile +16 -1
  9. data/features/cache_control.feature +22 -0
  10. data/features/step_definitions/steps.rb +46 -0
  11. data/features/support/continous_integration.rb +47 -0
  12. data/features/support/coverage.rb +18 -0
  13. data/features/support/env.rb +9 -0
  14. data/features/support/helpers.rb +13 -0
  15. data/features/support/web_app/application.rb +70 -0
  16. data/features/support/web_app/config_blacklist.ru +13 -0
  17. data/features/support/web_app/config_whitelist.ru +13 -0
  18. data/features/support/web_app/public/app/collections/todos.js +17 -0
  19. data/features/support/web_app/public/app/config.js +18 -0
  20. data/features/support/web_app/public/app/main.js +21 -0
  21. data/features/support/web_app/public/app/models/todo.js +33 -0
  22. data/features/support/web_app/public/app/templates/todo-add.html +3 -0
  23. data/features/support/web_app/public/app/templates/todo-editor.html +1 -0
  24. data/features/support/web_app/public/app/templates/todo-item.html +2 -0
  25. data/features/support/web_app/public/app/templates/todo-list-empty.html +1 -0
  26. data/features/support/web_app/public/app/templates/todo-stats.html +4 -0
  27. data/features/support/web_app/public/app/views/stats.js +26 -0
  28. data/features/support/web_app/public/app/views/todo.js +55 -0
  29. data/features/support/web_app/public/app/views/todoadd.js +48 -0
  30. data/features/support/web_app/public/app/views/todoedit.js +70 -0
  31. data/features/support/web_app/public/app/views/todolist.js +69 -0
  32. data/features/support/web_app/public/assets/css/bootstrap.css +3990 -0
  33. data/features/support/web_app/public/assets/css/style.css +82 -0
  34. data/features/support/web_app/public/assets/js/libs/backbone.js +1428 -0
  35. data/features/support/web_app/public/assets/js/libs/jquery-1.7.2.js +9404 -0
  36. data/features/support/web_app/public/assets/js/libs/require.js +2053 -0
  37. data/features/support/web_app/public/assets/js/libs/underscore.js +1008 -0
  38. data/features/support/web_app/public/assets/js/plugins/text.js +288 -0
  39. data/features/support/web_app/public/test/SpecRunner.html +42 -0
  40. data/features/support/web_app/public/test/lib/jasmine-1.2.0.rc3/MIT.LICENSE +20 -0
  41. data/features/support/web_app/public/test/lib/jasmine-1.2.0.rc3/jasmine-html.js +616 -0
  42. data/features/support/web_app/public/test/lib/jasmine-1.2.0.rc3/jasmine.css +81 -0
  43. data/features/support/web_app/public/test/lib/jasmine-1.2.0.rc3/jasmine.js +2530 -0
  44. data/features/support/web_app/public/test/lib/jasmine-jquery.js +306 -0
  45. data/features/support/web_app/public/test/spec/models/todo.coffee +37 -0
  46. data/features/support/web_app/public/test/spec/models/todo.js +48 -0
  47. data/features/support/web_app/public/test/spec/spec_helper.coffee +20 -0
  48. data/features/support/web_app/public/test/spec/spec_helper.js +17 -0
  49. data/features/support/web_app/public/test/spec/views/stats.coffee +9 -0
  50. data/features/support/web_app/public/test/spec/views/stats.js +13 -0
  51. data/features/support/web_app/public/test/spec/views/todo.coffee +22 -0
  52. data/features/support/web_app/public/test/spec/views/todo.js +26 -0
  53. data/features/support/web_app/public/test/spec/views/todoadd.coffee +22 -0
  54. data/features/support/web_app/public/test/spec/views/todoadd.js +29 -0
  55. data/features/support/web_app/public/test/spec/views/todoedit.coffee +59 -0
  56. data/features/support/web_app/public/test/spec/views/todoedit.js +72 -0
  57. data/features/support/web_app/public/test/spec/views/todolist.coffee +28 -0
  58. data/features/support/web_app/public/test/spec/views/todolist.js +39 -0
  59. data/features/support/web_app/views/details.erb +14 -0
  60. data/features/support/web_app/views/index.erb +43 -0
  61. data/lib/rack/noncache.rb +5 -7
  62. data/lib/rack/noncache/engine.rb +10 -26
  63. data/lib/rack/noncache/filters.rb +75 -0
  64. data/lib/rack/noncache/version.rb +1 -1
  65. data/rack-noncache.gemspec +32 -10
  66. metadata +382 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90e77c300227a2e4546e97d8f0ef905fcae0244b
4
- data.tar.gz: 067fcb81574f903d880228d639f3b425c1be6efb
3
+ metadata.gz: 98ee0e056e4c7cc4d17da92940bff448d0847f3e
4
+ data.tar.gz: 1a3ac367d4d4a519afefa3be1dcf96e2975fc999
5
5
  SHA512:
6
- metadata.gz: 3f31abdcc6fdeffa4b490782250182ea4d0fc3faa9666864931d9ffbbad1007715acd07d082f88f36060ba294dbf75fa9d0b1c9cd7918603bbf84098e0dc9183
7
- data.tar.gz: 9ecd519bab72dee6f1b930c69f821db8394d3310a9b196aaf48eded9a7d2f62f0505cb439c525281e33502bba7194335e994f8e7db435074e441f4f2e3f0305d
6
+ metadata.gz: 060c8f8943da2fee141d03619dcf49baf2eed678eab15597dd615ac1d4a389825059ce7b01f762217962fec7511d160910ff698e57fc1003190769109f61f700
7
+ data.tar.gz: 42fee0365a4308e35761e12c8bd599c455ee259473ef5b014942b2c425afcc2371db100c2d6b28876bfaa7b060ccc76bde396fcd2fabee065a103eecae598a2b
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ data.db
data/.pryrc ADDED
@@ -0,0 +1,6 @@
1
+ if defined?(PryByebug)
2
+ Pry.commands.alias_command 'c', 'continue'
3
+ Pry.commands.alias_command 's', 'step'
4
+ Pry.commands.alias_command 'n', 'next'
5
+ Pry.commands.alias_command 'f', 'finish'
6
+ end
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ rack-noncache
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.5
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ before_install:
5
+ - gem update --system
6
+ - gem --version
7
+ script:
8
+ - export TRAVIS=true
9
+ - bundle exec rake
10
+ after_success:
11
+ coveralls
12
+ addons:
13
+ sauce_connect: true
14
+ code_climate:
15
+ repo_token: f6d5a24aa8a0c85d8bc0f2d622f0056918b56c764fb812b711d68469bdb8356a
data/README.md CHANGED
@@ -1,10 +1,15 @@
1
- Rack::NonCache
2
- ==============
1
+ [![Gem Version](https://badge.fury.io/rb/rack-noncache.svg)](http://badge.fury.io/rb/rack-noncache)
2
+ [![Build Status](https://travis-ci.org/dsaenztagarro/rack-noncache.png)](https://travis-ci.org/dsaenztagarro/rack-noncache)
3
+ [![Code Climate](https://codeclimate.com/github/dsaenztagarro/rack-noncache/badges/gpa.svg)](https://codeclimate.com/github/dsaenztagarro/rack-noncache)
4
+ [![Coverage Status](https://coveralls.io/repos/dsaenztagarro/rack-noncache/badge.png?branch=master)](https://coveralls.io/r/dsaenztagarro/rack-noncache?branch=master)
5
+ [![Dependency Status](https://gemnasium.com/dsaenztagarro/rack-noncache.svg)](https://gemnasium.com/dsaenztagarro/rack-noncache)
6
+
7
+ # Rack::NonCache
3
8
 
4
9
  Rack::NonCache is a rack middleware that disables HTTP browser caching.
5
10
 
6
- Installation
7
- ------------
11
+
12
+ ## Installation
8
13
 
9
14
  From Gem:
10
15
 
@@ -15,72 +20,51 @@ With a local working copy:
15
20
  $ git clone git://github.com/dsaenztagarro/rack-noncache.git
16
21
  $ rake package && sudo rake install
17
22
 
18
- Basic Usage
19
- -----------
23
+ ## Basic Usage
20
24
 
21
25
  Rack::NonCache is implemented as a piece of Rack middleware and can be used with
22
26
  any Rack-based application. If your application includes a rackup (`.ru`) file
23
27
  or uses Rack::Builder to construct the application pipeline, simply require
24
28
  and use as follows:
25
29
 
26
- require 'rack/noncache'
30
+ ```ruby
31
+ require 'rack/noncache'
27
32
 
28
- use Rack::NonCache,
29
- :metastore => 'file:/var/cache/rack/meta',
33
+ use Rack::NonCache,
34
+ :whitelist => ['/path/to/non/caching/url', ...,
35
+ Regexp.new(/^\/path\/to\/non\/caching\/url/)]
30
36
 
31
- run app
37
+ run app
38
+ ```
32
39
 
33
40
  Assuming you've designed your backend application to take advantage of HTTP's
34
41
  caching features, no further code or configuration is required for basic
35
42
  caching.
36
43
 
37
- Using with Rails
38
- ----------------
44
+ ## Using with Rails
39
45
 
40
46
  Add this to your `config/environment.rb`:
41
47
 
42
- config.middleware.use Rack::NonCache,
43
- :whitelist => ['/path/to/non/caching/url', ...,
44
- Regexp.new(/^\/path\/to\/non\/caching\/url/)]
45
- or:
46
-
47
- config.middleware.use Rack::NonCache,
48
- :blacklist => ['/path/to/non/caching/url', ...,
49
- Regexp.new(/^\/path\/to\/non\/caching\/url/)],
50
-
51
- You should now see `Rack::NonCache` listed in the middleware pipeline:
52
-
53
- rake middleware
54
-
55
- See the following for more information:
56
-
57
- http://snippets.aktagon.com/snippets/302
58
-
59
-
60
- Links
61
- -----
62
-
63
- GitHub:
64
- http://github.com/dsaenztagarro/rack-noncache/
48
+ ```ruby
49
+ # White list approach (option 1)
50
+ config.middleware.use Rack::NonCache,
51
+ :whitelist => ['/path/to/non/caching/url', ...,
52
+ Regexp.new(/^\/path\/to\/non\/caching\/url/)]
65
53
 
66
- License
67
- -------
54
+ # Black list approach (option 2)
68
55
 
69
- Copyright (c) 2014 David Saenz Tagarro
56
+ config.middleware.use Rack::NonCache,
57
+ :blacklist => ['/path/to/non/caching/url', ...,
58
+ Regexp.new(/^\/path\/to\/non\/caching\/url/)],
59
+ ```
70
60
 
71
- Permission is hereby granted, free of charge, to any person obtaining a copy
72
- of this software and associated documentation files (the "Software"), to
73
- deal in the Software without restriction, including without limitation the
74
- rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
75
- sell copies of the Software, and to permit persons to whom the Software is
76
- furnished to do so, subject to the following conditions:
61
+ You should now see `Rack::NonCache` listed in the middleware pipeline:
62
+ `rake middleware`
77
63
 
78
- The above copyright notice and this permission notice shall be included in
79
- all copies or substantial portions of the Software.
64
+ ## Contributing
80
65
 
81
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
82
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
83
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
84
- THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
85
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
86
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
66
+ 1. Fork it ( https://github.com/dsaenztagarro/rack-noncache/fork )
67
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
68
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
69
+ 4. Push to the branch (`git push origin my-new-feature`)
70
+ 5. Create a new Pull Request
data/Rakefile CHANGED
@@ -1 +1,16 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'cucumber'
3
+ require 'cucumber/rake/task'
4
+ require 'rubocop/rake_task'
5
+
6
+ Dir.glob('lib/tasks/*.rake').each { |path| load path }
7
+
8
+ RuboCop::RakeTask.new do |task|
9
+ task.requires << 'rubocop-rspec'
10
+ end
11
+
12
+ Cucumber::Rake::Task.new(:features) do |t|
13
+ t.cucumber_opts = 'features --format pretty'
14
+ end
15
+
16
+ task default: ['features']
@@ -0,0 +1,22 @@
1
+ Feature: Disable cache in browser navigation
2
+
3
+ Scenario Outline: Pressing back browser button
4
+ Given a <Strategy> for no caching my web application
5
+ And I am a <Platform> user
6
+ And I open a '<Browser>' <Version>
7
+ And I visit the home page
8
+ And I store 3 todo tasks in session
9
+ When I click on Show details
10
+ And I press the back browser button
11
+ Then I see the 3 todo tasks in todo list
12
+
13
+ Examples:
14
+ | Browser | Version | Strategy | Platform |
15
+ | firefox | 34 | whitelist | Linux |
16
+ | firefox | 34 | blacklist | Linux |
17
+ # | chrome | 38 | whitelist | Linux |
18
+ # | opera | 12 | whitelist | Linux |
19
+ # | safari | 8 | whitelist | OS X 10.10 |
20
+ # | internet explorer | 11 | whitelist | Windows 7 |
21
+ # | internet explorer | 10 | whitelist | Windows 7 |
22
+ # | internet explorer | 9 | whitelist | Windows 7 |
@@ -0,0 +1,46 @@
1
+ Given(/^a (\w+) for no caching my web application$/) do |strategy|
2
+ @strategy = strategy
3
+ DataMapper.auto_upgrade!
4
+ end
5
+
6
+ Given(/^I am a (\w+) user$/) do |platform|
7
+ @platform = platform
8
+ end
9
+
10
+ Given(/^I open a '(.+)' (\w+)$/) do |browser_name, browser_version|
11
+ TestSettings.configure(browser_name: browser_name, version: browser_version,
12
+ strategy: @strategy, platform: @platform)
13
+ end
14
+
15
+ Given(/^I visit the (\w+) page$/) do |page_name|
16
+ url = case page_name
17
+ when 'home' then '/index'
18
+ else
19
+ '/details'
20
+ end
21
+ visit url
22
+ end
23
+
24
+ Given(/^I store (\d) todo tasks in session$/) do |number|
25
+ div_xpath = "//div[@class='input-append']"
26
+ input_el = browser.find_element xpath: "#{div_xpath}/input"
27
+ add_btn_el = browser.find_element xpath: "//div[@class='input-append']/button"
28
+
29
+ number.to_i.times.each do |n|
30
+ input_el.send_keys("Task #{n}")
31
+ add_btn_el.click
32
+ wait_js_inactive
33
+ end
34
+ end
35
+
36
+ When(/^I click on (.*)$/) do |text|
37
+ browser.find_element(link_text: text).click
38
+ end
39
+
40
+ When(/^I press the (next|back) browser button$/) do |direction|
41
+ browser.navigate.send(direction)
42
+ end
43
+
44
+ Then(/^I see the (\d) todo tasks in todo list$/) do |number|
45
+ expect(browser.find_elements(xpath: '//ul/li').size).to eql(number.to_i)
46
+ end
@@ -0,0 +1,47 @@
1
+ require 'capybara_selenium'
2
+ require_relative 'coverage'
3
+
4
+ Dir[File.join(__FILE__, '../../lib/**/*.rb')].each { |f| require f }
5
+
6
+ # Helpers for continous integration
7
+ module TestSettings
8
+ APP_SERVER_HOST = ENV['CI_APP_SERVER_HOST'] || '127.0.0.1'
9
+ APP_SERVER_PORT = ENV['CI_APP_SERVER_PORT'] || 8080
10
+ SELENIUM_SERVER_URL = ENV['CI_SELENIUM_SERVER_URL'] ||
11
+ 'http://127.0.0.1:4444/wd/hub'
12
+
13
+ class << self
14
+ # @param [Hash] opts The options for browser
15
+ # @option opts [String] :browser_name The name of the browser. Valid values:
16
+ # firefox|chrome|internet explorer|safari|opera
17
+ # @option opts [Integer] :version The version of the browser
18
+ # @option opts [String] :strategy The strategy to configure the
19
+ # Rack::NonCache middleware
20
+ def configure(opts = {})
21
+ CapybaraSelenium.configure do |config|
22
+ config.app_server.host = APP_SERVER_HOST
23
+ config.app_server.port = APP_SERVER_PORT.to_i + port_counter
24
+ config.app_server.config_ru_path = File.expand_path(File.join(
25
+ __FILE__, "../web_app/config_#{opts[:strategy] || :whitelist}.ru"))
26
+
27
+ config.selenium_server.server_url = SELENIUM_SERVER_URL
28
+ config.selenium_server.capabilities = {
29
+ 'browser' => opts[:browser_name] || :firefox,
30
+ 'browserName' => opts[:browser_name] || :firefox,
31
+ 'version' => opts[:version] || 'ANY',
32
+ 'tunnel-identifier' => ENV['TRAVIS_JOB_NUMBER'],
33
+ 'build' => ENV['TRAVIS_BUILD_NUMBER']
34
+ }
35
+ end
36
+ end
37
+
38
+ def port_counter
39
+ @port_counter ||= 0
40
+ @port_counter += 1
41
+ end
42
+ end
43
+ end
44
+
45
+ TestSettings.configure
46
+
47
+ World(TestSettings)
@@ -0,0 +1,18 @@
1
+ if ENV['TRAVIS']
2
+ require 'codeclimate-test-reporter'
3
+ require 'simplecov'
4
+ require 'coveralls'
5
+ Coveralls.wear!
6
+
7
+ formatters = [SimpleCov::Formatter::HTMLFormatter]
8
+ formatters << Coveralls::SimpleCov::Formatter
9
+ if ENV['CODECLIMATE_REPO_TOKEN']
10
+ formatters << CodeClimate::TestReporter::Formatter
11
+ end
12
+
13
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[*formatters]
14
+ SimpleCov.start do
15
+ add_filter '/features/'
16
+ add_group 'Libraries', 'lib'
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ require 'capybara'
2
+ require 'capybara/cucumber'
3
+ require 'selenium-webdriver'
4
+
5
+ Before do
6
+ DataMapper.auto_migrate!
7
+ end
8
+
9
+ World(Capybara)
@@ -0,0 +1,13 @@
1
+ module CucumberHelpers
2
+ def browser
3
+ page.driver.browser
4
+ end
5
+
6
+ def wait_js_inactive
7
+ Selenium::WebDriver::Wait.new.until do
8
+ browser.execute_script('return jQuery.active') == 0
9
+ end
10
+ end
11
+ end
12
+
13
+ World(CucumberHelpers)
@@ -0,0 +1,70 @@
1
+ require 'sinatra/base'
2
+ require 'sinatra/json'
3
+ require 'data_mapper'
4
+
5
+ # If you want the logs displayed you have to do this before the call to setup
6
+ DataMapper::Logger.new($stdout, :warn)
7
+
8
+ # A Sqlite3 connection:
9
+ DataMapper.setup(:default, 'sqlite:data.db')
10
+
11
+ class Todo
12
+ include DataMapper::Resource
13
+
14
+ property :id, Serial
15
+ property :text, Text
16
+ # property :created_at, DateTime, :default => lambda { |r,p| Time.now }
17
+ property :done, Boolean, default: false
18
+ end
19
+
20
+ DataMapper.finalize
21
+ DataMapper.auto_upgrade!
22
+
23
+ # Rack application to work with RackNonCache middleware
24
+ class DummyApp < Sinatra::Base
25
+ helpers Sinatra::JSON
26
+ helpers do
27
+ def json_data
28
+ JSON.parse request.body.read
29
+ end
30
+ end
31
+
32
+ before '/todos*' do
33
+ content_type 'application/json'
34
+ end
35
+
36
+ get '/index' do
37
+ @todos = Todo.all
38
+ erb :index
39
+ end
40
+
41
+ get '/details' do
42
+ erb :details
43
+ end
44
+
45
+ get '/todos' do
46
+ session[:todos].t
47
+ Todo.all.to_json
48
+ end
49
+
50
+ get '/todos/:id' do
51
+ todo = Todo.get(params[:id])
52
+ todo.to_json
53
+ end
54
+
55
+ put '/todos/:id' do
56
+ todo = Todo.get(params[:id])
57
+ todo.update(json_data)
58
+ todo.to_json
59
+ end
60
+
61
+ post '/todos' do
62
+ todo = Todo.create(json_data)
63
+ todo.to_json
64
+ end
65
+
66
+ delete '/todos/:id' do
67
+ todo = Todo.get(params[:id])
68
+ todo.destroy
69
+ end
70
+ end
@@ -0,0 +1,13 @@
1
+ require 'rack'
2
+
3
+ require_relative 'application'
4
+ require_relative '../../../lib/rack/noncache'
5
+
6
+ app = Rack::Builder.new do
7
+ use Rack::NonCache, blacklist: []
8
+ map '/' do
9
+ run DummyApp
10
+ end
11
+ end
12
+
13
+ run app
@@ -0,0 +1,13 @@
1
+ require 'rack'
2
+
3
+ require_relative 'application'
4
+ require_relative '../../../lib/rack/noncache'
5
+
6
+ app = Rack::Builder.new do
7
+ use Rack::NonCache, whitelist: [Regexp.new(/index|details$/)]
8
+ map '/' do
9
+ run DummyApp
10
+ end
11
+ end
12
+
13
+ run app