simple_form 2.1.3 → 3.0.0.rc

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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -50
  3. data/README.md +140 -116
  4. data/lib/generators/simple_form/install_generator.rb +4 -4
  5. data/lib/generators/simple_form/templates/README +2 -2
  6. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +13 -13
  7. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +16 -16
  8. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +3 -3
  9. data/lib/simple_form/action_view_extensions/builder.rb +1 -320
  10. data/lib/simple_form/action_view_extensions/form_helper.rb +2 -9
  11. data/lib/simple_form/components/errors.rb +1 -7
  12. data/lib/simple_form/components/hints.rb +2 -7
  13. data/lib/simple_form/components/html5.rb +5 -2
  14. data/lib/simple_form/components/labels.rb +4 -4
  15. data/lib/simple_form/components/maxlength.rb +1 -8
  16. data/lib/simple_form/components/pattern.rb +2 -2
  17. data/lib/simple_form/components.rb +1 -1
  18. data/lib/simple_form/error_notification.rb +2 -2
  19. data/lib/simple_form/form_builder.rb +148 -50
  20. data/lib/simple_form/helpers.rb +1 -1
  21. data/lib/simple_form/inputs/base.rb +3 -10
  22. data/lib/simple_form/inputs/block_input.rb +1 -1
  23. data/lib/simple_form/inputs/boolean_input.rb +6 -6
  24. data/lib/simple_form/inputs/collection_input.rb +7 -7
  25. data/lib/simple_form/inputs/numeric_input.rb +0 -6
  26. data/lib/simple_form/inputs/password_input.rb +0 -1
  27. data/lib/simple_form/inputs/string_input.rb +0 -1
  28. data/lib/simple_form/railtie.rb +7 -0
  29. data/lib/simple_form/tags.rb +61 -0
  30. data/lib/simple_form/version.rb +1 -1
  31. data/lib/simple_form/wrappers/builder.rb +5 -29
  32. data/lib/simple_form/wrappers/many.rb +1 -1
  33. data/lib/simple_form/wrappers/root.rb +1 -1
  34. data/lib/simple_form/wrappers.rb +1 -1
  35. data/lib/simple_form.rb +39 -47
  36. data/test/action_view_extensions/builder_test.rb +75 -95
  37. data/test/action_view_extensions/form_helper_test.rb +25 -16
  38. data/test/components/label_test.rb +46 -46
  39. data/test/form_builder/association_test.rb +39 -29
  40. data/test/form_builder/button_test.rb +4 -4
  41. data/test/form_builder/error_notification_test.rb +8 -8
  42. data/test/form_builder/error_test.rb +18 -65
  43. data/test/form_builder/general_test.rb +60 -74
  44. data/test/form_builder/hint_test.rb +23 -29
  45. data/test/form_builder/input_field_test.rb +12 -12
  46. data/test/form_builder/label_test.rb +6 -16
  47. data/test/form_builder/wrapper_test.rb +21 -21
  48. data/test/inputs/boolean_input_test.rb +23 -35
  49. data/test/inputs/collection_check_boxes_input_test.rb +61 -55
  50. data/test/inputs/collection_radio_buttons_input_test.rb +76 -79
  51. data/test/inputs/collection_select_input_test.rb +70 -51
  52. data/test/inputs/datetime_input_test.rb +17 -11
  53. data/test/inputs/disabled_test.rb +10 -10
  54. data/test/inputs/discovery_test.rb +4 -4
  55. data/test/inputs/file_input_test.rb +1 -1
  56. data/test/inputs/general_test.rb +12 -12
  57. data/test/inputs/grouped_collection_select_input_test.rb +20 -20
  58. data/test/inputs/hidden_input_test.rb +3 -2
  59. data/test/inputs/numeric_input_test.rb +3 -3
  60. data/test/inputs/priority_input_test.rb +9 -3
  61. data/test/inputs/readonly_test.rb +12 -12
  62. data/test/inputs/required_test.rb +5 -5
  63. data/test/inputs/string_input_test.rb +15 -25
  64. data/test/inputs/text_input_test.rb +1 -1
  65. data/test/support/misc_helpers.rb +46 -24
  66. data/test/support/mock_controller.rb +6 -6
  67. data/test/support/models.rb +62 -64
  68. data/test/test_helper.rb +20 -24
  69. metadata +37 -23
  70. data/lib/simple_form/core_ext/hash.rb +0 -16
@@ -1,27 +1,38 @@
1
1
  Association = Struct.new(:klass, :name, :macro, :options)
2
2
 
3
- class Column < Struct.new(:name, :type, :limit)
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
- class Company < Struct.new(:id, :name)
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
- def self.all(options={})
15
- all = (1..3).map{|i| Company.new(i, "Company #{i}")}
16
- return [all.first] if options[:conditions].present?
17
- return [all.last] if options[:order].present?
18
- return all[0..1] if options[:include].present?
19
- return all[1..2] if options[:joins].present?
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.merge_conditions(a, b)
24
- (a || {}).merge(b || {})
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
- class TagGroup < Struct.new(:id, :name, :tags)
39
- end
45
+ TagGroup = Struct.new(:id, :name, :tags)
40
46
 
41
47
  class User
42
48
  extend ActiveModel::Naming
@@ -112,7 +118,7 @@ class User
112
118
  when :first_company
113
119
  Association.new(Company, association, :has_one, {})
114
120
  when :special_company
115
- Association.new(Company, association, :belongs_to, { :conditions => { :id => 1 } })
121
+ Association.new(Company, association, :belongs_to, { conditions: { id: 1 } })
116
122
  end
117
123
  end
118
124
 
@@ -120,11 +126,11 @@ class User
120
126
  @errors ||= begin
121
127
  hash = Hash.new { |h,k| h[k] = [] }
122
128
  hash.merge!(
123
- :name => ["can't be blank"],
124
- :description => ["must be longer than 15 characters"],
125
- :age => ["is not a number", "must be greater than 18"],
126
- :company => ["company must be present"],
127
- :company_id => ["must be valid"]
129
+ name: ["can't be blank"],
130
+ description: ["must be longer than 15 characters"],
131
+ age: ["is not a number", "must be greater than 18"],
132
+ company: ["company must be present"],
133
+ company_id: ["must be valid"]
128
134
  )
129
135
  end
130
136
  end
@@ -136,31 +142,31 @@ end
136
142
 
137
143
  class ValidatingUser < User
138
144
  include ActiveModel::Validations
139
- validates :name, :presence => true
140
- validates :company, :presence => true
141
- validates :age, :presence => true, :if => Proc.new { |user| user.name }
142
- validates :amount, :presence => true, :unless => Proc.new { |user| user.age }
145
+ validates :name, presence: true
146
+ validates :company, presence: true
147
+ validates :age, presence: true, if: Proc.new { |user| user.name }
148
+ validates :amount, presence: true, unless: Proc.new { |user| user.age }
143
149
 
144
- validates :action, :presence => true, :on => :create
145
- validates :credit_limit, :presence => true, :on => :save
146
- validates :phone_number, :presence => true, :on => :update
150
+ validates :action, presence: true, on: :create
151
+ validates :credit_limit, presence: true, on: :save
152
+ validates :phone_number, presence: true, on: :update
147
153
 
148
154
  validates_numericality_of :age,
149
- :greater_than_or_equal_to => 18,
150
- :less_than_or_equal_to => 99,
151
- :only_integer => true
155
+ greater_than_or_equal_to: 18,
156
+ less_than_or_equal_to: 99,
157
+ only_integer: true
152
158
  validates_numericality_of :amount,
153
- :greater_than => :min_amount,
154
- :less_than => :max_amount,
155
- :only_integer => true
159
+ greater_than: :min_amount,
160
+ less_than: :max_amount,
161
+ only_integer: true
156
162
  validates_numericality_of :attempts,
157
- :greater_than_or_equal_to => :min_attempts,
158
- :less_than_or_equal_to => :max_attempts,
159
- :only_integer => true
160
- validates_length_of :name, :maximum => 25
161
- validates_length_of :description, :maximum => 50
162
- validates_length_of :action, :maximum => 10, :tokenizer => lambda { |str| str.scan(/\w+/) }
163
- validates_length_of :home_picture, :is => 12
163
+ greater_than_or_equal_to: :min_attempts,
164
+ less_than_or_equal_to: :max_attempts,
165
+ only_integer: true
166
+ validates_length_of :name, maximum: 25
167
+ validates_length_of :description, maximum: 50
168
+ validates_length_of :action, maximum: 10, tokenizer: lambda { |str| str.scan(/\w+/) }
169
+ validates_length_of :home_picture, is: 12
164
170
 
165
171
  def min_amount
166
172
  10
@@ -182,26 +188,21 @@ end
182
188
  class OtherValidatingUser < User
183
189
  include ActiveModel::Validations
184
190
  validates_numericality_of :age,
185
- :greater_than => 17,
186
- :less_than => 100,
187
- :only_integer => true
191
+ greater_than: 17,
192
+ less_than: 100,
193
+ only_integer: true
188
194
  validates_numericality_of :amount,
189
- :greater_than => Proc.new { |user| user.age },
190
- :less_than => Proc.new { |user| user.age + 100},
191
- :only_integer => true
195
+ greater_than: Proc.new { |user| user.age },
196
+ less_than: Proc.new { |user| user.age + 100 },
197
+ only_integer: true
192
198
  validates_numericality_of :attempts,
193
- :greater_than_or_equal_to => Proc.new { |user| user.age },
194
- :less_than_or_equal_to => Proc.new { |user| user.age + 100},
195
- :only_integer => true
196
-
197
- validates_format_of :country, :with => /\w+/
199
+ greater_than_or_equal_to: Proc.new { |user| user.age },
200
+ less_than_or_equal_to: Proc.new { |user| user.age + 100 },
201
+ only_integer: true
198
202
 
199
- # TODO: Remove this check when we drop Rails 3.0 support
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
203
+ validates_format_of :country, with: /\w+/
204
+ validates_format_of :name, with: Proc.new { /\w+/ }
205
+ validates_format_of :description, without: /\d+/
205
206
  end
206
207
 
207
208
  class HashBackedAuthor < Hash
@@ -214,6 +215,3 @@ class HashBackedAuthor < Hash
214
215
  'hash backed author'
215
216
  end
216
217
  end
217
-
218
- class UserNumber1And2 < User
219
- end
data/test/test_helper.rb CHANGED
@@ -1,16 +1,12 @@
1
- require 'rubygems'
2
1
  require 'bundler/setup'
3
2
 
4
- require 'test/unit'
5
- require 'mocha'
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
@@ -47,31 +43,31 @@ class ActionView::TestCase
47
43
 
48
44
  def setup_new_user(options={})
49
45
  @user = User.new({
50
- :id => 1,
51
- :name => 'New in SimpleForm!',
52
- :description => 'Hello!',
53
- :created_at => Time.now
46
+ id: 1,
47
+ name: 'New in SimpleForm!',
48
+ description: 'Hello!',
49
+ created_at: Time.now
54
50
  }.merge(options))
55
51
 
56
52
  @validating_user = ValidatingUser.new({
57
- :id => 1,
58
- :name => 'New in SimpleForm!',
59
- :description => 'Hello!',
60
- :home_picture => 'Home picture',
61
- :created_at => Time.now,
62
- :age => 19,
63
- :amount => 15,
64
- :attempts => 1,
65
- :company => [1]
53
+ id: 1,
54
+ name: 'New in SimpleForm!',
55
+ description: 'Hello!',
56
+ home_picture: 'Home picture',
57
+ created_at: Time.now,
58
+ age: 19,
59
+ amount: 15,
60
+ attempts: 1,
61
+ company: [1]
66
62
  }.merge(options))
67
63
 
68
64
  @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
65
+ id: 1,
66
+ name: 'New in SimpleForm!',
67
+ description: 'Hello!',
68
+ created_at: Time.now,
69
+ age: 19,
70
+ company: 1
75
71
  }.merge(options))
76
72
  end
77
73
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 3.0.0.rc
5
5
  platform: ruby
6
6
  authors:
7
7
  - José Valim
@@ -10,36 +10,48 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-07-02 00:00:00.000000000 Z
13
+ date: 2013-05-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - "~>"
19
+ - - '>='
20
20
  - !ruby/object:Gem::Version
21
- version: '3.0'
21
+ version: 4.0.0.rc1
22
+ - - <
23
+ - !ruby/object:Gem::Version
24
+ version: '4.1'
22
25
  type: :runtime
23
26
  prerelease: false
24
27
  version_requirements: !ruby/object:Gem::Requirement
25
28
  requirements:
26
- - - "~>"
29
+ - - '>='
30
+ - !ruby/object:Gem::Version
31
+ version: 4.0.0.rc1
32
+ - - <
27
33
  - !ruby/object:Gem::Version
28
- version: '3.0'
34
+ version: '4.1'
29
35
  - !ruby/object:Gem::Dependency
30
36
  name: actionpack
31
37
  requirement: !ruby/object:Gem::Requirement
32
38
  requirements:
33
- - - "~>"
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: 4.0.0.rc1
42
+ - - <
34
43
  - !ruby/object:Gem::Version
35
- version: '3.0'
44
+ version: '4.1'
36
45
  type: :runtime
37
46
  prerelease: false
38
47
  version_requirements: !ruby/object:Gem::Requirement
39
48
  requirements:
40
- - - "~>"
49
+ - - '>='
41
50
  - !ruby/object:Gem::Version
42
- version: '3.0'
51
+ version: 4.0.0.rc1
52
+ - - <
53
+ - !ruby/object:Gem::Version
54
+ version: '4.1'
43
55
  description: Forms made easy!
44
56
  email: contact@plataformatec.com.br
45
57
  executables: []
@@ -49,9 +61,7 @@ files:
49
61
  - CHANGELOG.md
50
62
  - MIT-LICENSE
51
63
  - README.md
52
- - lib/generators/simple_form/USAGE
53
64
  - lib/generators/simple_form/install_generator.rb
54
- - lib/generators/simple_form/templates/README
55
65
  - lib/generators/simple_form/templates/_form.html.erb
56
66
  - lib/generators/simple_form/templates/_form.html.haml
57
67
  - lib/generators/simple_form/templates/_form.html.slim
@@ -59,10 +69,10 @@ files:
59
69
  - lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb
60
70
  - lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb
61
71
  - lib/generators/simple_form/templates/config/locales/simple_form.en.yml
62
- - lib/simple_form.rb
72
+ - lib/generators/simple_form/templates/README
73
+ - lib/generators/simple_form/USAGE
63
74
  - lib/simple_form/action_view_extensions/builder.rb
64
75
  - lib/simple_form/action_view_extensions/form_helper.rb
65
- - lib/simple_form/components.rb
66
76
  - lib/simple_form/components/errors.rb
67
77
  - lib/simple_form/components/hints.rb
68
78
  - lib/simple_form/components/html5.rb
@@ -73,17 +83,16 @@ files:
73
83
  - lib/simple_form/components/pattern.rb
74
84
  - lib/simple_form/components/placeholders.rb
75
85
  - lib/simple_form/components/readonly.rb
76
- - lib/simple_form/core_ext/hash.rb
86
+ - lib/simple_form/components.rb
77
87
  - lib/simple_form/error_notification.rb
78
88
  - lib/simple_form/form_builder.rb
79
- - lib/simple_form/helpers.rb
80
89
  - lib/simple_form/helpers/autofocus.rb
81
90
  - lib/simple_form/helpers/disabled.rb
82
91
  - lib/simple_form/helpers/readonly.rb
83
92
  - lib/simple_form/helpers/required.rb
84
93
  - lib/simple_form/helpers/validators.rb
94
+ - lib/simple_form/helpers.rb
85
95
  - lib/simple_form/i18n_cache.rb
86
- - lib/simple_form/inputs.rb
87
96
  - lib/simple_form/inputs/base.rb
88
97
  - lib/simple_form/inputs/block_input.rb
89
98
  - lib/simple_form/inputs/boolean_input.rb
@@ -101,13 +110,17 @@ files:
101
110
  - lib/simple_form/inputs/range_input.rb
102
111
  - lib/simple_form/inputs/string_input.rb
103
112
  - lib/simple_form/inputs/text_input.rb
113
+ - lib/simple_form/inputs.rb
104
114
  - lib/simple_form/map_type.rb
115
+ - lib/simple_form/railtie.rb
116
+ - lib/simple_form/tags.rb
105
117
  - lib/simple_form/version.rb
106
- - lib/simple_form/wrappers.rb
107
118
  - lib/simple_form/wrappers/builder.rb
108
119
  - lib/simple_form/wrappers/many.rb
109
120
  - lib/simple_form/wrappers/root.rb
110
121
  - lib/simple_form/wrappers/single.rb
122
+ - lib/simple_form/wrappers.rb
123
+ - lib/simple_form.rb
111
124
  - test/action_view_extensions/builder_test.rb
112
125
  - test/action_view_extensions/form_helper_test.rb
113
126
  - test/components/label_test.rb
@@ -145,7 +158,8 @@ files:
145
158
  - test/support/models.rb
146
159
  - test/test_helper.rb
147
160
  homepage: https://github.com/plataformatec/simple_form
148
- licenses: []
161
+ licenses:
162
+ - MIT
149
163
  metadata: {}
150
164
  post_install_message:
151
165
  rdoc_options: []
@@ -153,17 +167,17 @@ require_paths:
153
167
  - lib
154
168
  required_ruby_version: !ruby/object:Gem::Requirement
155
169
  requirements:
156
- - - ">="
170
+ - - '>='
157
171
  - !ruby/object:Gem::Version
158
172
  version: '0'
159
173
  required_rubygems_version: !ruby/object:Gem::Requirement
160
174
  requirements:
161
- - - ">="
175
+ - - '>'
162
176
  - !ruby/object:Gem::Version
163
- version: '0'
177
+ version: 1.3.1
164
178
  requirements: []
165
179
  rubyforge_project: simple_form
166
- rubygems_version: 2.2.3
180
+ rubygems_version: 2.0.3
167
181
  signing_key:
168
182
  specification_version: 4
169
183
  summary: Forms made easy!
@@ -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