simple_form 1.2.0 → 1.4.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.
- data/.gitignore +2 -0
- data/.gitmodules +3 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.rdoc +109 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +82 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +180 -53
- data/Rakefile +27 -0
- data/lib/generators/simple_form/USAGE +1 -1
- data/lib/generators/simple_form/install_generator.rb +5 -6
- data/lib/generators/simple_form/templates/_form.html.erb +2 -12
- data/lib/generators/simple_form/templates/_form.html.haml +10 -0
- data/lib/generators/simple_form/templates/_form.html.slim +10 -0
- data/lib/generators/simple_form/templates/en.yml +14 -0
- data/lib/generators/simple_form/templates/simple_form.rb +66 -12
- data/lib/simple_form/action_view_extensions/builder.rb +99 -40
- data/lib/simple_form/action_view_extensions/form_helper.rb +29 -6
- data/lib/simple_form/components/errors.rb +16 -6
- data/lib/simple_form/components/hints.rb +2 -2
- data/lib/simple_form/components/label_input.rb +13 -0
- data/lib/simple_form/components/labels.rb +5 -7
- data/lib/simple_form/components/placeholders.rb +22 -0
- data/lib/simple_form/components/wrapper.rb +19 -2
- data/lib/simple_form/components.rb +6 -4
- data/lib/simple_form/error_notification.rb +42 -0
- data/lib/simple_form/form_builder.rb +187 -72
- data/lib/simple_form/has_errors.rb +14 -0
- data/lib/simple_form/inputs/base.rb +106 -24
- data/lib/simple_form/inputs/block_input.rb +3 -2
- data/lib/simple_form/inputs/boolean_input.rb +22 -0
- data/lib/simple_form/inputs/collection_input.rb +46 -17
- data/lib/simple_form/inputs/date_time_input.rb +11 -5
- data/lib/simple_form/inputs/hidden_input.rb +11 -2
- data/lib/simple_form/inputs/mapping_input.rb +12 -6
- data/lib/simple_form/inputs/numeric_input.rb +55 -6
- data/lib/simple_form/inputs/priority_input.rb +5 -1
- data/lib/simple_form/inputs/string_input.rb +25 -11
- data/lib/simple_form/inputs.rb +1 -0
- data/lib/simple_form/map_type.rb +9 -6
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form.rb +92 -8
- data/simple_form.gemspec +22 -0
- data/test/action_view_extensions/builder_test.rb +187 -51
- data/test/action_view_extensions/form_helper_test.rb +17 -5
- data/test/components/error_test.rb +23 -12
- data/test/components/hint_test.rb +4 -8
- data/test/components/label_test.rb +79 -11
- data/test/components/wrapper_test.rb +63 -0
- data/test/discovery_inputs.rb +21 -0
- data/test/error_notification_test.rb +62 -0
- data/test/form_builder_test.rb +332 -35
- data/test/inputs_test.rb +516 -53
- data/test/support/misc_helpers.rb +32 -4
- data/test/support/mock_controller.rb +4 -4
- data/test/support/models.rb +75 -11
- data/test/test_helper.rb +28 -12
- metadata +51 -11
|
@@ -8,10 +8,8 @@ module MiscHelpers
|
|
|
8
8
|
end
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
def assert_no_select(
|
|
12
|
-
|
|
13
|
-
assert_select(*args)
|
|
14
|
-
end
|
|
11
|
+
def assert_no_select(selector, value = nil)
|
|
12
|
+
assert_select(selector, :text => value, :count => 0)
|
|
15
13
|
end
|
|
16
14
|
|
|
17
15
|
def swap(object, new_values)
|
|
@@ -26,4 +24,34 @@ module MiscHelpers
|
|
|
26
24
|
object.send :"#{key}=", value
|
|
27
25
|
end
|
|
28
26
|
end
|
|
27
|
+
|
|
28
|
+
def with_concat_form_for(object, &block)
|
|
29
|
+
concat simple_form_for(object, &block)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def with_concat_custom_form_for(object, &block)
|
|
33
|
+
concat custom_form_for(object, &block)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def custom_form_for(object, *args, &block)
|
|
37
|
+
simple_form_for(object, *(args << { :builder => CustomFormBuilder }), &block)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def custom_mapping_form_for(object, *args, &block)
|
|
41
|
+
simple_form_for(object, *(args << { :builder => CustomMapTypeFormBuilder }), &block)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def with_concat_custom_mapping_form_for(object, &block)
|
|
45
|
+
concat custom_mapping_form_for(object, &block)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
class CustomFormBuilder < SimpleForm::FormBuilder
|
|
50
|
+
def input(attribute_name, *args, &block)
|
|
51
|
+
super(attribute_name, *(args << { :input_html => { :class => 'custom' } }), &block)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
class CustomMapTypeFormBuilder < SimpleForm::FormBuilder
|
|
56
|
+
map_type :custom_type, :to => SimpleForm::Inputs::StringInput
|
|
29
57
|
end
|
data/test/support/models.rb
CHANGED
|
@@ -5,6 +5,7 @@ Association = Struct.new(:klass, :name, :macro, :options)
|
|
|
5
5
|
|
|
6
6
|
class Company < Struct.new(:id, :name)
|
|
7
7
|
extend ActiveModel::Naming
|
|
8
|
+
include ActiveModel::Conversion
|
|
8
9
|
|
|
9
10
|
def self.all(options={})
|
|
10
11
|
all = (1..3).map{|i| Company.new(i, "Company #{i}")}
|
|
@@ -26,17 +27,28 @@ end
|
|
|
26
27
|
|
|
27
28
|
class Tag < Company
|
|
28
29
|
extend ActiveModel::Naming
|
|
30
|
+
include ActiveModel::Conversion
|
|
29
31
|
|
|
30
32
|
def self.all(options={})
|
|
31
33
|
(1..3).map{|i| Tag.new(i, "Tag #{i}")}
|
|
32
34
|
end
|
|
33
35
|
end
|
|
34
36
|
|
|
35
|
-
class User
|
|
37
|
+
class User
|
|
36
38
|
extend ActiveModel::Naming
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
include ActiveModel::Conversion
|
|
40
|
+
|
|
41
|
+
attr_accessor :id, :name, :company, :company_id, :time_zone, :active, :age,
|
|
42
|
+
:description, :created_at, :updated_at, :credit_limit, :password, :url,
|
|
43
|
+
:delivery_time, :born_at, :special_company_id, :country, :tags, :tag_ids,
|
|
44
|
+
:avatar, :home_picture, :email, :status, :residence_country, :phone_number,
|
|
45
|
+
:post_count, :lock_version, :amount, :attempts
|
|
46
|
+
|
|
47
|
+
def initialize(options={})
|
|
48
|
+
options.each do |key, value|
|
|
49
|
+
send("#{key}=", value)
|
|
50
|
+
end if options
|
|
51
|
+
end
|
|
40
52
|
|
|
41
53
|
def new_record!
|
|
42
54
|
@new_record = true
|
|
@@ -60,6 +72,10 @@ class User < OpenStruct
|
|
|
60
72
|
when :delivery_time then :time
|
|
61
73
|
when :created_at then :datetime
|
|
62
74
|
when :updated_at then :timestamp
|
|
75
|
+
when :lock_version then :integer
|
|
76
|
+
when :home_picture then :string
|
|
77
|
+
when :amount then :integer
|
|
78
|
+
when :attempts then :integer
|
|
63
79
|
end
|
|
64
80
|
Column.new(attribute, column_type, limit)
|
|
65
81
|
end
|
|
@@ -91,17 +107,65 @@ class User < OpenStruct
|
|
|
91
107
|
end
|
|
92
108
|
|
|
93
109
|
def errors
|
|
94
|
-
@errors ||=
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
110
|
+
@errors ||= begin
|
|
111
|
+
hash = Hash.new { |h,k| h[k] = [] }
|
|
112
|
+
hash.merge!(
|
|
113
|
+
:name => ["can't be blank"],
|
|
114
|
+
:description => ["must be longer than 15 characters"],
|
|
115
|
+
:age => ["is not a number", "must be greater than 18"],
|
|
116
|
+
:company => ["company must be present"],
|
|
117
|
+
:company_id => ["must be valid"]
|
|
118
|
+
)
|
|
119
|
+
end
|
|
101
120
|
end
|
|
102
121
|
end
|
|
103
122
|
|
|
104
123
|
class ValidatingUser < User
|
|
105
124
|
include ActiveModel::Validations
|
|
106
125
|
validates :name, :presence => true
|
|
126
|
+
validates :company, :presence => true
|
|
127
|
+
validates_numericality_of :age,
|
|
128
|
+
:greater_than_or_equal_to => 18,
|
|
129
|
+
:less_than_or_equal_to => 99,
|
|
130
|
+
:only_integer => true
|
|
131
|
+
validates_numericality_of :amount,
|
|
132
|
+
:greater_than => :min_amount,
|
|
133
|
+
:less_than => :max_amount,
|
|
134
|
+
:only_integer => true
|
|
135
|
+
validates_numericality_of :attempts,
|
|
136
|
+
:greater_than_or_equal_to => :min_attempts,
|
|
137
|
+
:less_than_or_equal_to => :max_attempts,
|
|
138
|
+
:only_integer => true
|
|
139
|
+
|
|
140
|
+
def min_amount
|
|
141
|
+
10
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def max_amount
|
|
145
|
+
100
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def min_attempts
|
|
149
|
+
1
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def max_attempts
|
|
153
|
+
100
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
class OtherValidatingUser < User
|
|
158
|
+
include ActiveModel::Validations
|
|
159
|
+
validates_numericality_of :age,
|
|
160
|
+
:greater_than => 17,
|
|
161
|
+
:less_than => 100,
|
|
162
|
+
:only_integer => true
|
|
163
|
+
validates_numericality_of :amount,
|
|
164
|
+
:greater_than => Proc.new { |user| user.age },
|
|
165
|
+
:less_than => Proc.new { |user| user.age + 100},
|
|
166
|
+
:only_integer => true
|
|
167
|
+
validates_numericality_of :attempts,
|
|
168
|
+
:greater_than_or_equal_to => Proc.new { |user| user.age },
|
|
169
|
+
:less_than_or_equal_to => Proc.new { |user| user.age + 100},
|
|
170
|
+
:only_integer => true
|
|
107
171
|
end
|
data/test/test_helper.rb
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
require 'rubygems'
|
|
2
|
+
require 'bundler/setup'
|
|
3
|
+
|
|
2
4
|
require 'test/unit'
|
|
5
|
+
require 'mocha'
|
|
3
6
|
|
|
4
7
|
require 'active_model'
|
|
5
8
|
require 'action_controller'
|
|
6
9
|
require 'action_view'
|
|
7
10
|
require 'action_view/template'
|
|
11
|
+
|
|
12
|
+
# Rails 3.0.4 is missing this "deprecation" require.
|
|
13
|
+
require 'active_support/core_ext/module/deprecation'
|
|
8
14
|
require 'action_view/test_case'
|
|
9
15
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
16
|
+
module Rails
|
|
17
|
+
def self.env
|
|
18
|
+
ActiveSupport::StringInquirer.new("test")
|
|
19
|
+
end
|
|
13
20
|
end
|
|
14
21
|
|
|
15
|
-
$:.unshift File.
|
|
22
|
+
$:.unshift File.expand_path("../../lib", __FILE__)
|
|
16
23
|
require 'simple_form'
|
|
17
24
|
|
|
18
25
|
Dir["#{File.dirname(__FILE__)}/support/*.rb"].each { |f| require f }
|
|
@@ -27,14 +34,9 @@ else
|
|
|
27
34
|
raise "Could not find country_select plugin in test/support. Please execute git submodule update --init."
|
|
28
35
|
end
|
|
29
36
|
|
|
30
|
-
class SimpleForm::FormBuilder
|
|
31
|
-
attr_accessor :attribute_name, :column, :reflection, :input_type, :options
|
|
32
|
-
end
|
|
33
|
-
|
|
34
37
|
class ActionView::TestCase
|
|
35
38
|
include MiscHelpers
|
|
36
|
-
|
|
37
|
-
tests SimpleForm::ActionViewExtensions::FormHelper
|
|
39
|
+
include SimpleForm::ActionViewExtensions::FormHelper
|
|
38
40
|
|
|
39
41
|
setup :set_controller
|
|
40
42
|
setup :set_response
|
|
@@ -55,12 +57,25 @@ class ActionView::TestCase
|
|
|
55
57
|
:description => 'Hello!',
|
|
56
58
|
:created_at => Time.now
|
|
57
59
|
}.merge(options))
|
|
58
|
-
|
|
60
|
+
|
|
59
61
|
@validating_user = ValidatingUser.new({
|
|
60
62
|
:id => 1,
|
|
61
63
|
:name => 'New in Simple Form!',
|
|
62
64
|
:description => 'Hello!',
|
|
63
|
-
:created_at => Time.now
|
|
65
|
+
:created_at => Time.now,
|
|
66
|
+
:age => 19,
|
|
67
|
+
:amount => 15,
|
|
68
|
+
:attempts => 1,
|
|
69
|
+
:company => [1]
|
|
70
|
+
}.merge(options))
|
|
71
|
+
|
|
72
|
+
@other_validating_user = OtherValidatingUser.new({
|
|
73
|
+
:id => 1,
|
|
74
|
+
:name => 'New in Simple Form!',
|
|
75
|
+
:description => 'Hello!',
|
|
76
|
+
:created_at => Time.now,
|
|
77
|
+
:age => 19,
|
|
78
|
+
:company => 1
|
|
64
79
|
}.merge(options))
|
|
65
80
|
end
|
|
66
81
|
|
|
@@ -74,4 +89,5 @@ class ActionView::TestCase
|
|
|
74
89
|
alias :users_path :user_path
|
|
75
90
|
alias :super_user_path :user_path
|
|
76
91
|
alias :validating_user_path :user_path
|
|
92
|
+
alias :other_validating_user_path :user_path
|
|
77
93
|
end
|
metadata
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: simple_form
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
4
|
+
hash: 7
|
|
5
|
+
prerelease:
|
|
5
6
|
segments:
|
|
6
7
|
- 1
|
|
7
|
-
-
|
|
8
|
+
- 4
|
|
8
9
|
- 0
|
|
9
|
-
version: 1.
|
|
10
|
+
version: 1.4.0
|
|
10
11
|
platform: ruby
|
|
11
12
|
authors:
|
|
12
13
|
- "Jos\xC3\xA9 Valim"
|
|
@@ -15,7 +16,7 @@ autorequire:
|
|
|
15
16
|
bindir: bin
|
|
16
17
|
cert_chain: []
|
|
17
18
|
|
|
18
|
-
date:
|
|
19
|
+
date: 2011-05-18 00:00:00 -03:00
|
|
19
20
|
default_executable:
|
|
20
21
|
dependencies: []
|
|
21
22
|
|
|
@@ -25,13 +26,24 @@ executables: []
|
|
|
25
26
|
|
|
26
27
|
extensions: []
|
|
27
28
|
|
|
28
|
-
extra_rdoc_files:
|
|
29
|
-
|
|
29
|
+
extra_rdoc_files: []
|
|
30
|
+
|
|
30
31
|
files:
|
|
32
|
+
- .gitignore
|
|
33
|
+
- .gitmodules
|
|
34
|
+
- .travis.yml
|
|
35
|
+
- CHANGELOG.rdoc
|
|
36
|
+
- Gemfile
|
|
37
|
+
- Gemfile.lock
|
|
38
|
+
- MIT-LICENSE
|
|
39
|
+
- README.rdoc
|
|
40
|
+
- Rakefile
|
|
31
41
|
- init.rb
|
|
32
42
|
- lib/generators/simple_form/USAGE
|
|
33
43
|
- lib/generators/simple_form/install_generator.rb
|
|
34
44
|
- lib/generators/simple_form/templates/_form.html.erb
|
|
45
|
+
- lib/generators/simple_form/templates/_form.html.haml
|
|
46
|
+
- lib/generators/simple_form/templates/_form.html.slim
|
|
35
47
|
- lib/generators/simple_form/templates/en.yml
|
|
36
48
|
- lib/generators/simple_form/templates/simple_form.rb
|
|
37
49
|
- lib/simple_form.rb
|
|
@@ -40,13 +52,18 @@ files:
|
|
|
40
52
|
- lib/simple_form/components.rb
|
|
41
53
|
- lib/simple_form/components/errors.rb
|
|
42
54
|
- lib/simple_form/components/hints.rb
|
|
55
|
+
- lib/simple_form/components/label_input.rb
|
|
43
56
|
- lib/simple_form/components/labels.rb
|
|
57
|
+
- lib/simple_form/components/placeholders.rb
|
|
44
58
|
- lib/simple_form/components/wrapper.rb
|
|
59
|
+
- lib/simple_form/error_notification.rb
|
|
45
60
|
- lib/simple_form/form_builder.rb
|
|
61
|
+
- lib/simple_form/has_errors.rb
|
|
46
62
|
- lib/simple_form/i18n_cache.rb
|
|
47
63
|
- lib/simple_form/inputs.rb
|
|
48
64
|
- lib/simple_form/inputs/base.rb
|
|
49
65
|
- lib/simple_form/inputs/block_input.rb
|
|
66
|
+
- lib/simple_form/inputs/boolean_input.rb
|
|
50
67
|
- lib/simple_form/inputs/collection_input.rb
|
|
51
68
|
- lib/simple_form/inputs/date_time_input.rb
|
|
52
69
|
- lib/simple_form/inputs/hidden_input.rb
|
|
@@ -56,34 +73,54 @@ files:
|
|
|
56
73
|
- lib/simple_form/inputs/string_input.rb
|
|
57
74
|
- lib/simple_form/map_type.rb
|
|
58
75
|
- lib/simple_form/version.rb
|
|
59
|
-
-
|
|
76
|
+
- simple_form.gemspec
|
|
77
|
+
- test/action_view_extensions/builder_test.rb
|
|
78
|
+
- test/action_view_extensions/form_helper_test.rb
|
|
79
|
+
- test/components/error_test.rb
|
|
80
|
+
- test/components/hint_test.rb
|
|
81
|
+
- test/components/label_test.rb
|
|
82
|
+
- test/components/wrapper_test.rb
|
|
83
|
+
- test/discovery_inputs.rb
|
|
84
|
+
- test/error_notification_test.rb
|
|
85
|
+
- test/form_builder_test.rb
|
|
86
|
+
- test/inputs_test.rb
|
|
87
|
+
- test/simple_form_test.rb
|
|
88
|
+
- test/support/misc_helpers.rb
|
|
89
|
+
- test/support/mock_controller.rb
|
|
90
|
+
- test/support/mock_response.rb
|
|
91
|
+
- test/support/models.rb
|
|
92
|
+
- test/test_helper.rb
|
|
60
93
|
has_rdoc: true
|
|
61
94
|
homepage: http://github.com/plataformatec/simple_form
|
|
62
95
|
licenses: []
|
|
63
96
|
|
|
64
97
|
post_install_message:
|
|
65
|
-
rdoc_options:
|
|
66
|
-
|
|
98
|
+
rdoc_options: []
|
|
99
|
+
|
|
67
100
|
require_paths:
|
|
68
101
|
- lib
|
|
69
102
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
103
|
+
none: false
|
|
70
104
|
requirements:
|
|
71
105
|
- - ">="
|
|
72
106
|
- !ruby/object:Gem::Version
|
|
107
|
+
hash: 3
|
|
73
108
|
segments:
|
|
74
109
|
- 0
|
|
75
110
|
version: "0"
|
|
76
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
|
+
none: false
|
|
77
113
|
requirements:
|
|
78
114
|
- - ">="
|
|
79
115
|
- !ruby/object:Gem::Version
|
|
116
|
+
hash: 3
|
|
80
117
|
segments:
|
|
81
118
|
- 0
|
|
82
119
|
version: "0"
|
|
83
120
|
requirements: []
|
|
84
121
|
|
|
85
|
-
rubyforge_project:
|
|
86
|
-
rubygems_version: 1.
|
|
122
|
+
rubyforge_project: simple_form
|
|
123
|
+
rubygems_version: 1.6.2
|
|
87
124
|
signing_key:
|
|
88
125
|
specification_version: 3
|
|
89
126
|
summary: Forms made easy!
|
|
@@ -93,6 +130,9 @@ test_files:
|
|
|
93
130
|
- test/components/error_test.rb
|
|
94
131
|
- test/components/hint_test.rb
|
|
95
132
|
- test/components/label_test.rb
|
|
133
|
+
- test/components/wrapper_test.rb
|
|
134
|
+
- test/discovery_inputs.rb
|
|
135
|
+
- test/error_notification_test.rb
|
|
96
136
|
- test/form_builder_test.rb
|
|
97
137
|
- test/inputs_test.rb
|
|
98
138
|
- test/simple_form_test.rb
|