monkey_forms 0.0.17 → 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +9 -0
- data/lib/monkey_forms/serializers/gzip_cookie.rb +10 -4
- data/lib/monkey_forms/version.rb +1 -1
- data/lib/monkey_forms.rb +13 -1
- data/test/test_monkey_forms.rb +14 -0
- metadata +22 -23
data/.travis.yml
ADDED
@@ -4,10 +4,11 @@ require 'zlib'
|
|
4
4
|
# Saves form as cookie as json+gzip
|
5
5
|
class MonkeyForms::Serializers::GzipCookie
|
6
6
|
def initialize options={}
|
7
|
-
@cookie_name = options[:name]
|
8
|
-
@domain = options[:domain]
|
7
|
+
@cookie_name = options[:name].to_s
|
8
|
+
@domain = options[:domain].to_s
|
9
9
|
@secure = options[:secure]
|
10
10
|
@httponly = options[:httponly]
|
11
|
+
@path = (options[:path] || '/').to_s
|
11
12
|
end
|
12
13
|
|
13
14
|
def load options={}
|
@@ -16,7 +17,11 @@ class MonkeyForms::Serializers::GzipCookie
|
|
16
17
|
return result if request.blank?
|
17
18
|
cookie = request.cookies[@cookie_name]
|
18
19
|
return result if cookie.nil? or cookie.empty?
|
19
|
-
|
20
|
+
begin
|
21
|
+
result.merge!(ActiveSupport::JSON.decode(Zlib::Inflate.inflate(cookie)).stringify_keys)
|
22
|
+
rescue Zlib::DataError
|
23
|
+
return result
|
24
|
+
end
|
20
25
|
end
|
21
26
|
|
22
27
|
def save options = {}
|
@@ -28,7 +33,8 @@ class MonkeyForms::Serializers::GzipCookie
|
|
28
33
|
cookie_hash = { :value => cookie_json,
|
29
34
|
:httponly => @httponly,
|
30
35
|
:secure => @secure,
|
31
|
-
:domain => @domain
|
36
|
+
:domain => @domain,
|
37
|
+
:path => @path }
|
32
38
|
response.set_cookie(@cookie_name, cookie_hash)
|
33
39
|
end
|
34
40
|
end
|
data/lib/monkey_forms/version.rb
CHANGED
data/lib/monkey_forms.rb
CHANGED
@@ -68,6 +68,9 @@ module MonkeyForms
|
|
68
68
|
|
69
69
|
self.class.attributes.each do |a|
|
70
70
|
@attributes[a] ||= ""
|
71
|
+
if self.class.strip_attributes?
|
72
|
+
@attributes[a].strip! if @attributes[a].class == String
|
73
|
+
end
|
71
74
|
end
|
72
75
|
end
|
73
76
|
end
|
@@ -93,7 +96,7 @@ module MonkeyForms
|
|
93
96
|
@_model_name = (@_form_name.try(:to_s) ||
|
94
97
|
superclass.instance_variable_get(:@_form_name).try(:to_s) ||
|
95
98
|
name.underscore).try(:underscore)
|
96
|
-
%w( singular human i18n_key partial_path plural ).each do |method|
|
99
|
+
%w( singular human i18n_key partial_path plural param_key).each do |method|
|
97
100
|
@_model_name.class_eval do
|
98
101
|
define_method method do
|
99
102
|
self
|
@@ -112,6 +115,15 @@ module MonkeyForms
|
|
112
115
|
@form_storage = storage_object
|
113
116
|
end
|
114
117
|
|
118
|
+
def dont_strip_form_attributes!
|
119
|
+
@_strip_attributes = false
|
120
|
+
end
|
121
|
+
|
122
|
+
def strip_attributes?
|
123
|
+
return true if !defined?(@_strip_attributes)
|
124
|
+
return @_strip_attributes
|
125
|
+
end
|
126
|
+
|
115
127
|
def set_form_attribute_human_names options
|
116
128
|
@_form_attribute_names ||= {}
|
117
129
|
@_form_attribute_names.merge!(options)
|
data/test/test_monkey_forms.rb
CHANGED
@@ -24,6 +24,14 @@ class TestMonkeyForms < MiniTest::Unit::TestCase
|
|
24
24
|
assert_equal "Joe <joe@tanga.com>", last_response.body
|
25
25
|
end
|
26
26
|
|
27
|
+
def test_form_post_with_bad_cookie
|
28
|
+
post "https://test.domain.com/form", :form => { :name => "Joe" }
|
29
|
+
set_cookie "order_cookie=bad_value; path=/; domain=test.domain.com; secure"
|
30
|
+
post "https://test.domain.com/form", :form => { :name => "Joe" }
|
31
|
+
assert_equal 200, last_response.status
|
32
|
+
skip "i can't get this test to fail. :("
|
33
|
+
end
|
34
|
+
|
27
35
|
def test_attribute_name
|
28
36
|
o = OrderForm.new
|
29
37
|
o.valid?
|
@@ -42,6 +50,7 @@ class TestMonkeyForms < MiniTest::Unit::TestCase
|
|
42
50
|
assert last_response.headers["Set-Cookie"].include?("HttpOnly")
|
43
51
|
assert last_response.headers["Set-Cookie"].include?("secure")
|
44
52
|
assert last_response.headers["Set-Cookie"].include?("test.domain.com")
|
53
|
+
assert last_response.headers["Set-Cookie"].include?("path=/;")
|
45
54
|
end
|
46
55
|
|
47
56
|
def test_setters_from_inside_form
|
@@ -117,6 +126,11 @@ class TestMonkeyForms < MiniTest::Unit::TestCase
|
|
117
126
|
assert_equal "Joe <joe@tanga.com>", o.person
|
118
127
|
end
|
119
128
|
|
129
|
+
def test_can_access_attributes_stripped
|
130
|
+
o = OrderForm.new :form => { :email => "joe@tanga.com" , :name => " Joe " }
|
131
|
+
assert_equal "Joe <joe@tanga.com>", o.person
|
132
|
+
end
|
133
|
+
|
120
134
|
def test_array
|
121
135
|
submit_form(:line_items => [ {:id => "previous"}])
|
122
136
|
attributes = submit_form(:line_items => [ {:id => "new"}])
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monkey_forms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.18
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
13
|
-
default_executable:
|
12
|
+
date: 2011-09-14 00:00:00.000000000Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: activemodel
|
17
|
-
requirement: &
|
16
|
+
requirement: &70272335220300 !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
18
|
requirements:
|
20
19
|
- - ! '>='
|
@@ -22,10 +21,10 @@ dependencies:
|
|
22
21
|
version: '0'
|
23
22
|
type: :runtime
|
24
23
|
prerelease: false
|
25
|
-
version_requirements: *
|
24
|
+
version_requirements: *70272335220300
|
26
25
|
- !ruby/object:Gem::Dependency
|
27
26
|
name: minitest
|
28
|
-
requirement: &
|
27
|
+
requirement: &70272335219740 !ruby/object:Gem::Requirement
|
29
28
|
none: false
|
30
29
|
requirements:
|
31
30
|
- - ! '>='
|
@@ -33,10 +32,10 @@ dependencies:
|
|
33
32
|
version: '0'
|
34
33
|
type: :development
|
35
34
|
prerelease: false
|
36
|
-
version_requirements: *
|
35
|
+
version_requirements: *70272335219740
|
37
36
|
- !ruby/object:Gem::Dependency
|
38
37
|
name: rake
|
39
|
-
requirement: &
|
38
|
+
requirement: &70272335219240 !ruby/object:Gem::Requirement
|
40
39
|
none: false
|
41
40
|
requirements:
|
42
41
|
- - ! '>='
|
@@ -44,10 +43,10 @@ dependencies:
|
|
44
43
|
version: '0'
|
45
44
|
type: :development
|
46
45
|
prerelease: false
|
47
|
-
version_requirements: *
|
46
|
+
version_requirements: *70272335219240
|
48
47
|
- !ruby/object:Gem::Dependency
|
49
48
|
name: sinatra
|
50
|
-
requirement: &
|
49
|
+
requirement: &70272335218620 !ruby/object:Gem::Requirement
|
51
50
|
none: false
|
52
51
|
requirements:
|
53
52
|
- - ! '>='
|
@@ -55,10 +54,10 @@ dependencies:
|
|
55
54
|
version: '0'
|
56
55
|
type: :development
|
57
56
|
prerelease: false
|
58
|
-
version_requirements: *
|
57
|
+
version_requirements: *70272335218620
|
59
58
|
- !ruby/object:Gem::Dependency
|
60
59
|
name: rack-test
|
61
|
-
requirement: &
|
60
|
+
requirement: &70272335217960 !ruby/object:Gem::Requirement
|
62
61
|
none: false
|
63
62
|
requirements:
|
64
63
|
- - ! '>='
|
@@ -66,10 +65,10 @@ dependencies:
|
|
66
65
|
version: '0'
|
67
66
|
type: :development
|
68
67
|
prerelease: false
|
69
|
-
version_requirements: *
|
68
|
+
version_requirements: *70272335217960
|
70
69
|
- !ruby/object:Gem::Dependency
|
71
70
|
name: shotgun
|
72
|
-
requirement: &
|
71
|
+
requirement: &70272335217120 !ruby/object:Gem::Requirement
|
73
72
|
none: false
|
74
73
|
requirements:
|
75
74
|
- - ! '>='
|
@@ -77,10 +76,10 @@ dependencies:
|
|
77
76
|
version: '0'
|
78
77
|
type: :development
|
79
78
|
prerelease: false
|
80
|
-
version_requirements: *
|
79
|
+
version_requirements: *70272335217120
|
81
80
|
- !ruby/object:Gem::Dependency
|
82
81
|
name: haml
|
83
|
-
requirement: &
|
82
|
+
requirement: &70272335216360 !ruby/object:Gem::Requirement
|
84
83
|
none: false
|
85
84
|
requirements:
|
86
85
|
- - ! '>='
|
@@ -88,10 +87,10 @@ dependencies:
|
|
88
87
|
version: '0'
|
89
88
|
type: :development
|
90
89
|
prerelease: false
|
91
|
-
version_requirements: *
|
90
|
+
version_requirements: *70272335216360
|
92
91
|
- !ruby/object:Gem::Dependency
|
93
92
|
name: msgpack
|
94
|
-
requirement: &
|
93
|
+
requirement: &70272335215640 !ruby/object:Gem::Requirement
|
95
94
|
none: false
|
96
95
|
requirements:
|
97
96
|
- - ! '>='
|
@@ -99,7 +98,7 @@ dependencies:
|
|
99
98
|
version: '0'
|
100
99
|
type: :development
|
101
100
|
prerelease: false
|
102
|
-
version_requirements: *
|
101
|
+
version_requirements: *70272335215640
|
103
102
|
description: Helps make complex forms
|
104
103
|
email:
|
105
104
|
- joe@tanga.com
|
@@ -108,6 +107,7 @@ extensions: []
|
|
108
107
|
extra_rdoc_files: []
|
109
108
|
files:
|
110
109
|
- .gitignore
|
110
|
+
- .travis.yml
|
111
111
|
- BUGS
|
112
112
|
- Gemfile
|
113
113
|
- NOTES
|
@@ -150,7 +150,6 @@ files:
|
|
150
150
|
- test/sinatra/sample_sinatra.rb
|
151
151
|
- test/sinatra/views/form.haml
|
152
152
|
- test/test_monkey_forms.rb
|
153
|
-
has_rdoc: true
|
154
153
|
homepage: https://github.com/joevandyk/monkey_forms
|
155
154
|
licenses: []
|
156
155
|
post_install_message:
|
@@ -165,7 +164,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
165
164
|
version: '0'
|
166
165
|
segments:
|
167
166
|
- 0
|
168
|
-
hash:
|
167
|
+
hash: 1638740973580231578
|
169
168
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
169
|
none: false
|
171
170
|
requirements:
|
@@ -174,10 +173,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
174
173
|
version: '0'
|
175
174
|
segments:
|
176
175
|
- 0
|
177
|
-
hash:
|
176
|
+
hash: 1638740973580231578
|
178
177
|
requirements: []
|
179
178
|
rubyforge_project: monkey_forms
|
180
|
-
rubygems_version: 1.
|
179
|
+
rubygems_version: 1.8.10
|
181
180
|
signing_key:
|
182
181
|
specification_version: 3
|
183
182
|
summary: Helps make complex forms
|