rack-conditional-forms 0.0.1 → 0.0.2

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.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Rack::Conditional::Forms
2
2
 
3
- Rack::ConditionalForms allows forms to override `If-Match` and `If-Unmodified-Since` headers in forms, using `_if_match` and `_if_unmodified_since` keys, respectively,
3
+ Rack::ConditionalForms allows forms to override `If-Match` and `If-Unmodified-Since` headers, using `_if_match` and `_if_unmodified_since` keys, respectively,
4
4
  allowing conditional `POST`, `PUT` and `DELETE` requests from the browser.
5
5
 
6
6
  ## Installation
@@ -25,6 +25,25 @@ Or install it yourself as:
25
25
  To use Rack::SslEnforcer in your Rails application, add the following line to your application config file (config/application.rb for Rails 3, config/environment.rb for Rails 2):
26
26
 
27
27
  config.middleware.use Rack::ConditionalForms
28
+
29
+ Prepend the hidden fields to your form:
30
+
31
+ <form action="/123" method="POST">
32
+ <fieldset>
33
+ <input name="_method" type="hidden" value="PUT" />
34
+ <input name="_if_match" type="hidden" value='"202cb962ac59075b964b07152d234b70"' />
35
+ <input name="_if_unmodified_since" type="hidden" value="Tue, 08 May 2012 00:00:00 GMT" />
36
+ <p>
37
+ <label for="title"></label>
38
+ <input name="title" value="Example form" />
39
+ </p>
40
+ <p>
41
+ <input type="submit" />
42
+ </p>
43
+ </fieldset>
44
+ </form>
45
+
46
+ The request's `HTTP_IF_MATCH` and `HTTP_IF_UNMODIFIED_SINCE` headers will then be set to `"202cb962ac59075b964b07152d234b70"` and `Tue, 08 May 2012 00:00:00 GMT`, respectively.
28
47
 
29
48
  ## Contributing
30
49
 
@@ -14,7 +14,7 @@ module Rack
14
14
  def call(env)
15
15
  if (match = if_match(env)) && !match.empty?
16
16
  env['rack.conditionalforms.original_match'] = env['HTTP_IF_MATCH']
17
- env['HTTP_IF_MATCH'] = if_match(env)
17
+ env['HTTP_IF_MATCH'] = '"%s"' % if_match(env)
18
18
  end
19
19
 
20
20
  if (unmodified_since = if_unmodified_since(env)) && !unmodified_since.empty?
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class ConditionalForms
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -10,7 +10,7 @@ describe Rack::ConditionalForms do
10
10
 
11
11
  it 'must override If-Match on POST' do
12
12
  post '/', _if_match: '123'
13
- JSON.parse(last_response.body)['HTTP_IF_MATCH'].must_equal '123'
13
+ JSON.parse(last_response.body)['HTTP_IF_MATCH'].must_equal '"123"'
14
14
  end
15
15
 
16
16
  it 'wont override If-Match on POST if not present' do
@@ -20,7 +20,7 @@ describe Rack::ConditionalForms do
20
20
 
21
21
  it 'must override If-Match on PUT' do
22
22
  put '/', _if_match: '123'
23
- JSON.parse(last_response.body)['HTTP_IF_MATCH'].must_equal '123'
23
+ JSON.parse(last_response.body)['HTTP_IF_MATCH'].must_equal '"123"'
24
24
  end
25
25
 
26
26
  it 'wont override If-Match on PUT if not present' do
@@ -30,7 +30,7 @@ describe Rack::ConditionalForms do
30
30
 
31
31
  it 'must override If-Match on DELETE' do
32
32
  delete '/', _if_match: '123'
33
- JSON.parse(last_response.body)['HTTP_IF_MATCH'].must_equal '123'
33
+ JSON.parse(last_response.body)['HTTP_IF_MATCH'].must_equal '"123"'
34
34
  end
35
35
 
36
36
  it 'wont override If-Match on DELETE if not present' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-conditional-forms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: