rack-noncache 0.0.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.pryrc +6 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +15 -0
- data/README.md +36 -52
- data/Rakefile +16 -1
- data/features/cache_control.feature +22 -0
- data/features/step_definitions/steps.rb +46 -0
- data/features/support/continous_integration.rb +47 -0
- data/features/support/coverage.rb +18 -0
- data/features/support/env.rb +9 -0
- data/features/support/helpers.rb +13 -0
- data/features/support/web_app/application.rb +70 -0
- data/features/support/web_app/config_blacklist.ru +13 -0
- data/features/support/web_app/config_whitelist.ru +13 -0
- data/features/support/web_app/public/app/collections/todos.js +17 -0
- data/features/support/web_app/public/app/config.js +18 -0
- data/features/support/web_app/public/app/main.js +21 -0
- data/features/support/web_app/public/app/models/todo.js +33 -0
- data/features/support/web_app/public/app/templates/todo-add.html +3 -0
- data/features/support/web_app/public/app/templates/todo-editor.html +1 -0
- data/features/support/web_app/public/app/templates/todo-item.html +2 -0
- data/features/support/web_app/public/app/templates/todo-list-empty.html +1 -0
- data/features/support/web_app/public/app/templates/todo-stats.html +4 -0
- data/features/support/web_app/public/app/views/stats.js +26 -0
- data/features/support/web_app/public/app/views/todo.js +55 -0
- data/features/support/web_app/public/app/views/todoadd.js +48 -0
- data/features/support/web_app/public/app/views/todoedit.js +70 -0
- data/features/support/web_app/public/app/views/todolist.js +69 -0
- data/features/support/web_app/public/assets/css/bootstrap.css +3990 -0
- data/features/support/web_app/public/assets/css/style.css +82 -0
- data/features/support/web_app/public/assets/js/libs/backbone.js +1428 -0
- data/features/support/web_app/public/assets/js/libs/jquery-1.7.2.js +9404 -0
- data/features/support/web_app/public/assets/js/libs/require.js +2053 -0
- data/features/support/web_app/public/assets/js/libs/underscore.js +1008 -0
- data/features/support/web_app/public/assets/js/plugins/text.js +288 -0
- data/features/support/web_app/public/test/SpecRunner.html +42 -0
- data/features/support/web_app/public/test/lib/jasmine-1.2.0.rc3/MIT.LICENSE +20 -0
- data/features/support/web_app/public/test/lib/jasmine-1.2.0.rc3/jasmine-html.js +616 -0
- data/features/support/web_app/public/test/lib/jasmine-1.2.0.rc3/jasmine.css +81 -0
- data/features/support/web_app/public/test/lib/jasmine-1.2.0.rc3/jasmine.js +2530 -0
- data/features/support/web_app/public/test/lib/jasmine-jquery.js +306 -0
- data/features/support/web_app/public/test/spec/models/todo.coffee +37 -0
- data/features/support/web_app/public/test/spec/models/todo.js +48 -0
- data/features/support/web_app/public/test/spec/spec_helper.coffee +20 -0
- data/features/support/web_app/public/test/spec/spec_helper.js +17 -0
- data/features/support/web_app/public/test/spec/views/stats.coffee +9 -0
- data/features/support/web_app/public/test/spec/views/stats.js +13 -0
- data/features/support/web_app/public/test/spec/views/todo.coffee +22 -0
- data/features/support/web_app/public/test/spec/views/todo.js +26 -0
- data/features/support/web_app/public/test/spec/views/todoadd.coffee +22 -0
- data/features/support/web_app/public/test/spec/views/todoadd.js +29 -0
- data/features/support/web_app/public/test/spec/views/todoedit.coffee +59 -0
- data/features/support/web_app/public/test/spec/views/todoedit.js +72 -0
- data/features/support/web_app/public/test/spec/views/todolist.coffee +28 -0
- data/features/support/web_app/public/test/spec/views/todolist.js +39 -0
- data/features/support/web_app/views/details.erb +14 -0
- data/features/support/web_app/views/index.erb +43 -0
- data/lib/rack/noncache.rb +5 -7
- data/lib/rack/noncache/engine.rb +10 -26
- data/lib/rack/noncache/filters.rb +75 -0
- data/lib/rack/noncache/version.rb +1 -1
- data/rack-noncache.gemspec +32 -10
- metadata +382 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98ee0e056e4c7cc4d17da92940bff448d0847f3e
|
4
|
+
data.tar.gz: 1a3ac367d4d4a519afefa3be1dcf96e2975fc999
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 060c8f8943da2fee141d03619dcf49baf2eed678eab15597dd615ac1d4a389825059ce7b01f762217962fec7511d160910ff698e57fc1003190769109f61f700
|
7
|
+
data.tar.gz: 42fee0365a4308e35761e12c8bd599c455ee259473ef5b014942b2c425afcc2371db100c2d6b28876bfaa7b060ccc76bde396fcd2fabee065a103eecae598a2b
|
data/.gitignore
CHANGED
data/.pryrc
ADDED
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
|
-
|
2
|
-
|
1
|
+
[](http://badge.fury.io/rb/rack-noncache)
|
2
|
+
[](https://travis-ci.org/dsaenztagarro/rack-noncache)
|
3
|
+
[](https://codeclimate.com/github/dsaenztagarro/rack-noncache)
|
4
|
+
[](https://coveralls.io/r/dsaenztagarro/rack-noncache?branch=master)
|
5
|
+
[](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
|
-
|
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
|
-
|
30
|
+
```ruby
|
31
|
+
require 'rack/noncache'
|
27
32
|
|
28
|
-
|
29
|
-
|
33
|
+
use Rack::NonCache,
|
34
|
+
:whitelist => ['/path/to/non/caching/url', ...,
|
35
|
+
Regexp.new(/^\/path\/to\/non\/caching\/url/)]
|
30
36
|
|
31
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
67
|
-
-------
|
54
|
+
# Black list approach (option 2)
|
68
55
|
|
69
|
-
|
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
|
-
|
72
|
-
|
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
|
-
|
79
|
-
all copies or substantial portions of the Software.
|
64
|
+
## Contributing
|
80
65
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
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
|
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,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
|