simple_form 2.1.0 → 3.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.
Potentially problematic release.
This version of simple_form might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/CHANGELOG.md +22 -32
- data/README.md +161 -119
- data/lib/generators/simple_form/install_generator.rb +3 -3
- data/lib/generators/simple_form/templates/README +1 -1
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +16 -13
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +14 -14
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +3 -3
- data/lib/simple_form/action_view_extensions/builder.rb +1 -319
- data/lib/simple_form/action_view_extensions/form_helper.rb +2 -9
- data/lib/simple_form/components/html5.rb +5 -2
- data/lib/simple_form/components/labels.rb +3 -3
- data/lib/simple_form/components/maxlength.rb +1 -8
- data/lib/simple_form/components/pattern.rb +2 -2
- data/lib/simple_form/components.rb +1 -1
- data/lib/simple_form/error_notification.rb +2 -2
- data/lib/simple_form/form_builder.rb +155 -51
- data/lib/simple_form/helpers.rb +1 -1
- data/lib/simple_form/inputs/base.rb +6 -6
- data/lib/simple_form/inputs/block_input.rb +1 -1
- data/lib/simple_form/inputs/boolean_input.rb +6 -4
- data/lib/simple_form/inputs/collection_input.rb +6 -6
- data/lib/simple_form/inputs/date_time_input.rb +1 -1
- data/lib/simple_form/inputs/numeric_input.rb +0 -6
- data/lib/simple_form/inputs/password_input.rb +0 -1
- data/lib/simple_form/inputs/string_input.rb +0 -1
- data/lib/simple_form/railtie.rb +7 -0
- data/lib/simple_form/tags.rb +62 -0
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers/builder.rb +5 -29
- data/lib/simple_form/wrappers/many.rb +1 -1
- data/lib/simple_form/wrappers/root.rb +1 -1
- data/lib/simple_form/wrappers.rb +1 -1
- data/lib/simple_form.rb +43 -47
- data/test/action_view_extensions/builder_test.rb +78 -92
- data/test/action_view_extensions/form_helper_test.rb +25 -16
- data/test/components/label_test.rb +46 -46
- data/test/form_builder/association_test.rb +47 -29
- data/test/form_builder/button_test.rb +4 -4
- data/test/form_builder/error_notification_test.rb +8 -8
- data/test/form_builder/error_test.rb +12 -12
- data/test/form_builder/general_test.rb +71 -52
- data/test/form_builder/hint_test.rb +22 -22
- data/test/form_builder/input_field_test.rb +29 -12
- data/test/form_builder/label_test.rb +7 -7
- data/test/form_builder/wrapper_test.rb +21 -21
- data/test/inputs/boolean_input_test.rb +35 -23
- data/test/inputs/collection_check_boxes_input_test.rb +66 -55
- data/test/inputs/collection_radio_buttons_input_test.rb +81 -79
- data/test/inputs/collection_select_input_test.rb +76 -45
- data/test/inputs/datetime_input_test.rb +17 -11
- data/test/inputs/disabled_test.rb +10 -10
- data/test/inputs/discovery_test.rb +4 -4
- data/test/inputs/file_input_test.rb +1 -1
- data/test/inputs/general_test.rb +28 -12
- data/test/inputs/grouped_collection_select_input_test.rb +33 -20
- data/test/inputs/hidden_input_test.rb +3 -2
- data/test/inputs/numeric_input_test.rb +3 -3
- data/test/inputs/priority_input_test.rb +9 -3
- data/test/inputs/readonly_test.rb +12 -12
- data/test/inputs/required_test.rb +5 -5
- data/test/inputs/string_input_test.rb +15 -25
- data/test/inputs/text_input_test.rb +1 -1
- data/test/support/misc_helpers.rb +46 -24
- data/test/support/mock_controller.rb +6 -6
- data/test/support/models.rb +80 -62
- data/test/test_helper.rb +17 -34
- metadata +31 -29
- data/lib/simple_form/core_ext/hash.rb +0 -16
data/test/support/models.rb
CHANGED
@@ -1,27 +1,38 @@
|
|
1
1
|
Association = Struct.new(:klass, :name, :macro, :options)
|
2
2
|
|
3
|
-
|
3
|
+
Column = Struct.new(:name, :type, :limit) do
|
4
4
|
# Returns +true+ if the column is either of type integer, float or decimal.
|
5
5
|
def number?
|
6
6
|
type == :integer || type == :float || type == :decimal
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
Relation = Struct.new(:all) do
|
11
|
+
def where(conditions = nil)
|
12
|
+
self.class.new conditions ? all.first : all
|
13
|
+
end
|
14
|
+
|
15
|
+
def order(conditions = nil)
|
16
|
+
self.class.new conditions ? all.last : all
|
17
|
+
end
|
18
|
+
|
19
|
+
alias_method :to_a, :all
|
20
|
+
end
|
21
|
+
|
22
|
+
Company = Struct.new(:id, :name) do
|
11
23
|
extend ActiveModel::Naming
|
12
24
|
include ActiveModel::Conversion
|
13
25
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
all
|
26
|
+
class << self
|
27
|
+
delegate :order, :where, to: :_relation
|
28
|
+
end
|
29
|
+
|
30
|
+
def self._relation
|
31
|
+
Relation.new(all)
|
21
32
|
end
|
22
33
|
|
23
|
-
def self.
|
24
|
-
(
|
34
|
+
def self.all
|
35
|
+
(1..3).map { |i| new(i, "#{name} #{i}") }
|
25
36
|
end
|
26
37
|
|
27
38
|
def persisted?
|
@@ -29,14 +40,9 @@ class Company < Struct.new(:id, :name)
|
|
29
40
|
end
|
30
41
|
end
|
31
42
|
|
32
|
-
class Tag < Company
|
33
|
-
def self.all(options={})
|
34
|
-
(1..3).map{|i| Tag.new(i, "Tag #{i}")}
|
35
|
-
end
|
36
|
-
end
|
43
|
+
class Tag < Company; end
|
37
44
|
|
38
|
-
|
39
|
-
end
|
45
|
+
TagGroup = Struct.new(:id, :name, :tags)
|
40
46
|
|
41
47
|
class User
|
42
48
|
extend ActiveModel::Naming
|
@@ -46,7 +52,19 @@ class User
|
|
46
52
|
:description, :created_at, :updated_at, :credit_limit, :password, :url,
|
47
53
|
:delivery_time, :born_at, :special_company_id, :country, :tags, :tag_ids,
|
48
54
|
:avatar, :home_picture, :email, :status, :residence_country, :phone_number,
|
49
|
-
:post_count, :lock_version, :amount, :attempts, :action, :credit_card, :gender
|
55
|
+
:post_count, :lock_version, :amount, :attempts, :action, :credit_card, :gender,
|
56
|
+
:extra_special_company_id
|
57
|
+
|
58
|
+
def self.build(extra_attributes = {})
|
59
|
+
attributes = {
|
60
|
+
id: 1,
|
61
|
+
name: 'New in SimpleForm!',
|
62
|
+
description: 'Hello!',
|
63
|
+
created_at: Time.now
|
64
|
+
}.merge! extra_attributes
|
65
|
+
|
66
|
+
new attributes
|
67
|
+
end
|
50
68
|
|
51
69
|
def initialize(options={})
|
52
70
|
@new_record = false
|
@@ -112,7 +130,9 @@ class User
|
|
112
130
|
when :first_company
|
113
131
|
Association.new(Company, association, :has_one, {})
|
114
132
|
when :special_company
|
115
|
-
Association.new(Company, association, :belongs_to, { :
|
133
|
+
Association.new(Company, association, :belongs_to, { conditions: { id: 1 } })
|
134
|
+
when :extra_special_company
|
135
|
+
Association.new(Company, association, :belongs_to, { conditions: proc { { id: 1 } } })
|
116
136
|
end
|
117
137
|
end
|
118
138
|
|
@@ -120,11 +140,11 @@ class User
|
|
120
140
|
@errors ||= begin
|
121
141
|
hash = Hash.new { |h,k| h[k] = [] }
|
122
142
|
hash.merge!(
|
123
|
-
:
|
124
|
-
:
|
125
|
-
:
|
126
|
-
:
|
127
|
-
:
|
143
|
+
name: ["can't be blank"],
|
144
|
+
description: ["must be longer than 15 characters"],
|
145
|
+
age: ["is not a number", "must be greater than 18"],
|
146
|
+
company: ["company must be present"],
|
147
|
+
company_id: ["must be valid"]
|
128
148
|
)
|
129
149
|
end
|
130
150
|
end
|
@@ -136,31 +156,31 @@ end
|
|
136
156
|
|
137
157
|
class ValidatingUser < User
|
138
158
|
include ActiveModel::Validations
|
139
|
-
validates :name, :
|
140
|
-
validates :company, :
|
141
|
-
validates :age, :
|
142
|
-
validates :amount, :
|
159
|
+
validates :name, presence: true
|
160
|
+
validates :company, presence: true
|
161
|
+
validates :age, presence: true, if: Proc.new { |user| user.name }
|
162
|
+
validates :amount, presence: true, unless: Proc.new { |user| user.age }
|
143
163
|
|
144
|
-
validates :action, :
|
145
|
-
validates :credit_limit, :
|
146
|
-
validates :phone_number, :
|
164
|
+
validates :action, presence: true, on: :create
|
165
|
+
validates :credit_limit, presence: true, on: :save
|
166
|
+
validates :phone_number, presence: true, on: :update
|
147
167
|
|
148
168
|
validates_numericality_of :age,
|
149
|
-
:
|
150
|
-
:
|
151
|
-
:
|
169
|
+
greater_than_or_equal_to: 18,
|
170
|
+
less_than_or_equal_to: 99,
|
171
|
+
only_integer: true
|
152
172
|
validates_numericality_of :amount,
|
153
|
-
:
|
154
|
-
:
|
155
|
-
:
|
173
|
+
greater_than: :min_amount,
|
174
|
+
less_than: :max_amount,
|
175
|
+
only_integer: true
|
156
176
|
validates_numericality_of :attempts,
|
157
|
-
:
|
158
|
-
:
|
159
|
-
:
|
160
|
-
validates_length_of :name, :
|
161
|
-
validates_length_of :description, :
|
162
|
-
validates_length_of :action, :
|
163
|
-
validates_length_of :home_picture, :
|
177
|
+
greater_than_or_equal_to: :min_attempts,
|
178
|
+
less_than_or_equal_to: :max_attempts,
|
179
|
+
only_integer: true
|
180
|
+
validates_length_of :name, maximum: 25
|
181
|
+
validates_length_of :description, maximum: 50
|
182
|
+
validates_length_of :action, maximum: 10, tokenizer: lambda { |str| str.scan(/\w+/) }
|
183
|
+
validates_length_of :home_picture, is: 12
|
164
184
|
|
165
185
|
def min_amount
|
166
186
|
10
|
@@ -182,26 +202,21 @@ end
|
|
182
202
|
class OtherValidatingUser < User
|
183
203
|
include ActiveModel::Validations
|
184
204
|
validates_numericality_of :age,
|
185
|
-
:
|
186
|
-
:
|
187
|
-
:
|
205
|
+
greater_than: 17,
|
206
|
+
less_than: 100,
|
207
|
+
only_integer: true
|
188
208
|
validates_numericality_of :amount,
|
189
|
-
:
|
190
|
-
:
|
191
|
-
:
|
209
|
+
greater_than: Proc.new { |user| user.age },
|
210
|
+
less_than: Proc.new { |user| user.age + 100 },
|
211
|
+
only_integer: true
|
192
212
|
validates_numericality_of :attempts,
|
193
|
-
:
|
194
|
-
:
|
195
|
-
:
|
213
|
+
greater_than_or_equal_to: Proc.new { |user| user.age },
|
214
|
+
less_than_or_equal_to: Proc.new { |user| user.age + 100 },
|
215
|
+
only_integer: true
|
196
216
|
|
197
|
-
validates_format_of :country, :
|
198
|
-
|
199
|
-
|
200
|
-
if ActiveModel::VERSION::MAJOR == 3 && ActiveModel::VERSION::MINOR >= 1
|
201
|
-
validates_format_of :name, :with => Proc.new { /\w+/ }
|
202
|
-
else
|
203
|
-
validates_format_of :name, :with => /\w+/
|
204
|
-
end
|
217
|
+
validates_format_of :country, with: /\w+/
|
218
|
+
validates_format_of :name, with: Proc.new { /\w+/ }
|
219
|
+
validates_format_of :description, without: /\d+/
|
205
220
|
end
|
206
221
|
|
207
222
|
class HashBackedAuthor < Hash
|
@@ -214,3 +229,6 @@ class HashBackedAuthor < Hash
|
|
214
229
|
'hash backed author'
|
215
230
|
end
|
216
231
|
end
|
232
|
+
|
233
|
+
class UserNumber1And2 < User
|
234
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,16 +1,12 @@
|
|
1
|
-
require 'rubygems'
|
2
1
|
require 'bundler/setup'
|
3
2
|
|
4
|
-
require '
|
5
|
-
require 'mocha/setup'
|
3
|
+
require 'minitest/autorun'
|
6
4
|
|
7
5
|
require 'active_model'
|
8
6
|
require 'action_controller'
|
9
7
|
require 'action_view'
|
10
8
|
require 'action_view/template'
|
11
9
|
|
12
|
-
# Rails 3.0.4 is missing this "deprecation" require.
|
13
|
-
require 'active_support/core_ext/module/deprecation'
|
14
10
|
require 'action_view/test_case'
|
15
11
|
|
16
12
|
module Rails
|
@@ -39,40 +35,27 @@ class ActionView::TestCase
|
|
39
35
|
include SimpleForm::ActionViewExtensions::FormHelper
|
40
36
|
|
41
37
|
setup :set_controller
|
42
|
-
setup :
|
38
|
+
setup :setup_users
|
43
39
|
|
44
40
|
def set_controller
|
45
41
|
@controller = MockController.new
|
46
42
|
end
|
47
43
|
|
48
|
-
def
|
49
|
-
@user = User.
|
50
|
-
|
51
|
-
|
52
|
-
:
|
53
|
-
:
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
:
|
61
|
-
:
|
62
|
-
|
63
|
-
:amount => 15,
|
64
|
-
:attempts => 1,
|
65
|
-
:company => [1]
|
66
|
-
}.merge(options))
|
67
|
-
|
68
|
-
@other_validating_user = OtherValidatingUser.new({
|
69
|
-
:id => 1,
|
70
|
-
:name => 'New in SimpleForm!',
|
71
|
-
:description => 'Hello!',
|
72
|
-
:created_at => Time.now,
|
73
|
-
:age => 19,
|
74
|
-
:company => 1
|
75
|
-
}.merge(options))
|
44
|
+
def setup_users(extra_attributes = {})
|
45
|
+
@user = User.build(extra_attributes)
|
46
|
+
|
47
|
+
@validating_user = ValidatingUser.build({
|
48
|
+
home_picture: 'Home picture',
|
49
|
+
age: 19,
|
50
|
+
amount: 15,
|
51
|
+
attempts: 1,
|
52
|
+
company: [1]
|
53
|
+
}.merge!(extra_attributes))
|
54
|
+
|
55
|
+
@other_validating_user = OtherValidatingUser.build({
|
56
|
+
age: 19,
|
57
|
+
company: 1
|
58
|
+
}.merge!(extra_attributes))
|
76
59
|
end
|
77
60
|
|
78
61
|
def protect_against_forgery?
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 3.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- José Valim
|
@@ -11,40 +10,48 @@ authors:
|
|
11
10
|
autorequire:
|
12
11
|
bindir: bin
|
13
12
|
cert_chain: []
|
14
|
-
date: 2013-
|
13
|
+
date: 2013-09-21 00:00:00.000000000 Z
|
15
14
|
dependencies:
|
16
15
|
- !ruby/object:Gem::Dependency
|
17
16
|
name: activemodel
|
18
17
|
requirement: !ruby/object:Gem::Requirement
|
19
|
-
none: false
|
20
18
|
requirements:
|
21
|
-
- -
|
19
|
+
- - '>='
|
22
20
|
- !ruby/object:Gem::Version
|
23
|
-
version:
|
21
|
+
version: 4.0.0
|
22
|
+
- - <
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '4.1'
|
24
25
|
type: :runtime
|
25
26
|
prerelease: false
|
26
27
|
version_requirements: !ruby/object:Gem::Requirement
|
27
|
-
none: false
|
28
28
|
requirements:
|
29
|
-
- -
|
29
|
+
- - '>='
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 4.0.0
|
32
|
+
- - <
|
30
33
|
- !ruby/object:Gem::Version
|
31
|
-
version: '
|
34
|
+
version: '4.1'
|
32
35
|
- !ruby/object:Gem::Dependency
|
33
36
|
name: actionpack
|
34
37
|
requirement: !ruby/object:Gem::Requirement
|
35
|
-
none: false
|
36
38
|
requirements:
|
37
|
-
- -
|
39
|
+
- - '>='
|
38
40
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
41
|
+
version: 4.0.0
|
42
|
+
- - <
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '4.1'
|
40
45
|
type: :runtime
|
41
46
|
prerelease: false
|
42
47
|
version_requirements: !ruby/object:Gem::Requirement
|
43
|
-
none: false
|
44
48
|
requirements:
|
45
|
-
- -
|
49
|
+
- - '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: 4.0.0
|
52
|
+
- - <
|
46
53
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
54
|
+
version: '4.1'
|
48
55
|
description: Forms made easy!
|
49
56
|
email: contact@plataformatec.com.br
|
50
57
|
executables: []
|
@@ -78,7 +85,6 @@ files:
|
|
78
85
|
- lib/simple_form/components/placeholders.rb
|
79
86
|
- lib/simple_form/components/readonly.rb
|
80
87
|
- lib/simple_form/components.rb
|
81
|
-
- lib/simple_form/core_ext/hash.rb
|
82
88
|
- lib/simple_form/error_notification.rb
|
83
89
|
- lib/simple_form/form_builder.rb
|
84
90
|
- lib/simple_form/form_builder.rb.orig
|
@@ -108,6 +114,8 @@ files:
|
|
108
114
|
- lib/simple_form/inputs/text_input.rb
|
109
115
|
- lib/simple_form/inputs.rb
|
110
116
|
- lib/simple_form/map_type.rb
|
117
|
+
- lib/simple_form/railtie.rb
|
118
|
+
- lib/simple_form/tags.rb
|
111
119
|
- lib/simple_form/version.rb
|
112
120
|
- lib/simple_form/version.rb.orig
|
113
121
|
- lib/simple_form/wrappers/builder.rb
|
@@ -153,34 +161,28 @@ files:
|
|
153
161
|
- test/support/models.rb
|
154
162
|
- test/test_helper.rb
|
155
163
|
homepage: https://github.com/plataformatec/simple_form
|
156
|
-
licenses:
|
164
|
+
licenses:
|
165
|
+
- MIT
|
166
|
+
metadata: {}
|
157
167
|
post_install_message:
|
158
168
|
rdoc_options: []
|
159
169
|
require_paths:
|
160
170
|
- lib
|
161
171
|
required_ruby_version: !ruby/object:Gem::Requirement
|
162
|
-
none: false
|
163
172
|
requirements:
|
164
|
-
- -
|
173
|
+
- - '>='
|
165
174
|
- !ruby/object:Gem::Version
|
166
175
|
version: '0'
|
167
|
-
segments:
|
168
|
-
- 0
|
169
|
-
hash: -389428450847468473
|
170
176
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
|
-
none: false
|
172
177
|
requirements:
|
173
|
-
- -
|
178
|
+
- - '>='
|
174
179
|
- !ruby/object:Gem::Version
|
175
180
|
version: '0'
|
176
|
-
segments:
|
177
|
-
- 0
|
178
|
-
hash: -389428450847468473
|
179
181
|
requirements: []
|
180
182
|
rubyforge_project: simple_form
|
181
|
-
rubygems_version:
|
183
|
+
rubygems_version: 2.0.6
|
182
184
|
signing_key:
|
183
|
-
specification_version:
|
185
|
+
specification_version: 4
|
184
186
|
summary: Forms made easy!
|
185
187
|
test_files:
|
186
188
|
- test/action_view_extensions/builder_test.rb
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# TODO: Delete this file when we drop support for Rails 3.0
|
2
|
-
# This method is already implemented in active_support 3.1
|
3
|
-
|
4
|
-
unless Hash.new.respond_to?(:deep_dup)
|
5
|
-
class Hash
|
6
|
-
# Returns a deep copy of hash.
|
7
|
-
def deep_dup
|
8
|
-
duplicate = self.dup
|
9
|
-
duplicate.each_pair do |k,v|
|
10
|
-
tv = duplicate[k]
|
11
|
-
duplicate[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? tv.deep_dup : v
|
12
|
-
end
|
13
|
-
duplicate
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|