formtastic 2.3.1 → 3.0.0.rc
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.travis.yml +0 -24
- data/Appraisals +0 -8
- data/CHANGELOG +0 -16
- data/README.textile +2 -2
- data/formtastic.gemspec +9 -8
- data/lib/formtastic.rb +1 -2
- data/lib/formtastic/actions/button_action.rb +1 -8
- data/lib/formtastic/helpers/input_helper.rb +2 -0
- data/lib/formtastic/inputs.rb +1 -0
- data/lib/formtastic/inputs/base.rb +1 -9
- data/lib/formtastic/inputs/base/collections.rb +5 -17
- data/lib/formtastic/inputs/base/errors.rb +3 -3
- data/lib/formtastic/inputs/base/hints.rb +1 -1
- data/lib/formtastic/inputs/base/options.rb +1 -1
- data/lib/formtastic/inputs/boolean_input.rb +1 -3
- data/lib/formtastic/inputs/color_input.rb +42 -0
- data/lib/formtastic/inputs/datetime_picker_input.rb +4 -1
- data/lib/formtastic/inputs/hidden_input.rb +2 -6
- data/lib/formtastic/inputs/select_input.rb +1 -25
- data/lib/formtastic/localizer.rb +2 -0
- data/lib/formtastic/util.rb +1 -1
- data/lib/formtastic/version.rb +1 -1
- data/lib/generators/formtastic/install/install_generator.rb +4 -19
- data/spec/actions/generic_action_spec.rb +38 -2
- data/spec/helpers/input_helper_spec.rb +6 -29
- data/spec/inputs/boolean_input_spec.rb +28 -42
- data/spec/inputs/color_input_spec.rb +97 -0
- data/spec/inputs/hidden_input_spec.rb +11 -28
- data/spec/inputs/select_input_spec.rb +6 -107
- data/spec/inputs/string_input_spec.rb +13 -1
- data/spec/localizer_spec.rb +23 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/support/custom_macros.rb +5 -2
- data/spec/util_spec.rb +15 -22
- metadata +32 -32
- data/gemfiles/rails_3.0.gemfile +0 -7
- data/gemfiles/rails_3.1.gemfile +0 -7
- data/lib/formtastic/inputs/base/grouped_collections.rb +0 -77
@@ -110,11 +110,23 @@ describe 'string input' do
|
|
110
110
|
end
|
111
111
|
|
112
112
|
describe 'any conditional validation' do
|
113
|
+
describe 'proc that calls an instance method' do
|
114
|
+
it 'calls the method on the object' do
|
115
|
+
@new_post.should_receive(:something?)
|
116
|
+
@new_post.class.should_receive(:validators_on).with(:title).at_least(1).and_return([
|
117
|
+
active_model_presence_validator([:title], { :unless => -> { something? } })
|
118
|
+
])
|
119
|
+
concat(semantic_form_for(@new_post) do |builder|
|
120
|
+
concat(builder.input(:title))
|
121
|
+
end)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
113
125
|
describe 'proc with arity that calls an instance method' do
|
114
126
|
it 'calls the method on the object' do
|
115
127
|
@new_post.should_receive(:something?)
|
116
128
|
@new_post.class.should_receive(:validators_on).with(:title).at_least(1).and_return([
|
117
|
-
active_model_presence_validator([:title], { :unless =>
|
129
|
+
active_model_presence_validator([:title], { :unless => ->(user) { user.something? } })
|
118
130
|
])
|
119
131
|
concat(semantic_form_for(@new_post) do |builder|
|
120
132
|
concat(builder.input(:title))
|
data/spec/localizer_spec.rb
CHANGED
@@ -101,8 +101,30 @@ describe 'Formtastic::Localizer' do
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
end
|
104
|
+
|
105
|
+
describe "with custom resource name" do
|
106
|
+
before do
|
107
|
+
::I18n.backend.store_translations :en, {:formtastic => {
|
108
|
+
:labels => {
|
109
|
+
:post => { :name => 'POST.NAME' },
|
110
|
+
:message => { :name => 'MESSAGE.NAME' }
|
111
|
+
}
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
115
|
+
with_config :i18n_lookups_by_default, true do
|
116
|
+
semantic_form_for(@new_post, :as => :message) do |builder|
|
117
|
+
@localizer = Formtastic::Localizer.new(builder)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should translate custom key with i18n" do
|
123
|
+
@localizer.localize(:name, :name, :label).should == 'MESSAGE.NAME'
|
124
|
+
end
|
125
|
+
end
|
104
126
|
end
|
105
127
|
|
106
128
|
end
|
107
129
|
|
108
|
-
end
|
130
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -422,6 +422,7 @@ module FormtasticSpecHelper
|
|
422
422
|
@new_post.stub(:secret).and_return(1)
|
423
423
|
@new_post.stub(:url)
|
424
424
|
@new_post.stub(:email)
|
425
|
+
@new_post.stub(:color)
|
425
426
|
@new_post.stub(:search)
|
426
427
|
@new_post.stub(:phone)
|
427
428
|
@new_post.stub(:time_zone)
|
@@ -444,6 +445,7 @@ module FormtasticSpecHelper
|
|
444
445
|
@new_post.stub(:column_for_attribute).with(:country_subdivision).and_return(double('column', :type => :string, :limit => 255))
|
445
446
|
@new_post.stub(:column_for_attribute).with(:country_code).and_return(double('column', :type => :string, :limit => 255))
|
446
447
|
@new_post.stub(:column_for_attribute).with(:email).and_return(double('column', :type => :string, :limit => 255))
|
448
|
+
@new_post.stub(:column_for_attribute).with(:color).and_return(double('column', :type => :string, :limit => 255))
|
447
449
|
@new_post.stub(:column_for_attribute).with(:url).and_return(double('column', :type => :string, :limit => 255))
|
448
450
|
@new_post.stub(:column_for_attribute).with(:phone).and_return(double('column', :type => :string, :limit => 255))
|
449
451
|
@new_post.stub(:column_for_attribute).with(:search).and_return(double('column', :type => :string, :limit => 255))
|
@@ -258,8 +258,11 @@ module CustomMacros
|
|
258
258
|
|
259
259
|
def it_should_call_find_on_association_class_when_no_collection_is_provided(as)
|
260
260
|
it "should call find on the association class when no collection is provided" do
|
261
|
-
::
|
262
|
-
|
261
|
+
if Formtastic::Util.rails3?
|
262
|
+
::Author.should_receive(:scoped)
|
263
|
+
else
|
264
|
+
::Author.should_receive(:where)
|
265
|
+
end
|
263
266
|
concat(semantic_form_for(@new_post) do |builder|
|
264
267
|
concat(builder.input(:author, :as => as))
|
265
268
|
end)
|
data/spec/util_spec.rb
CHANGED
@@ -7,50 +7,43 @@ describe 'Formtastic::Util' do
|
|
7
7
|
|
8
8
|
subject { Formtastic::Util.deprecated_version_of_rails? }
|
9
9
|
|
10
|
-
context '
|
11
|
-
before { allow(Formtastic::Util).to receive(:rails_version) { Gem::Version.new("
|
12
|
-
it 'should be true' do
|
13
|
-
expect(subject).to be_true
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context '3.1.0' do
|
18
|
-
before { allow(Formtastic::Util).to receive(:rails_version) { Gem::Version.new("3.1.0") } }
|
10
|
+
context '4.0.0' do
|
11
|
+
before { allow(Formtastic::Util).to receive(:rails_version) { Gem::Version.new("4.0.0") } }
|
19
12
|
it 'should be true' do
|
20
13
|
expect(subject).to be_true
|
21
14
|
end
|
22
15
|
end
|
23
16
|
|
24
|
-
context '
|
25
|
-
before { allow(Formtastic::Util).to receive(:rails_version) { Gem::Version.new("
|
17
|
+
context '4.0.3' do
|
18
|
+
before { allow(Formtastic::Util).to receive(:rails_version) { Gem::Version.new("4.0.3") } }
|
26
19
|
it 'should be true' do
|
27
20
|
expect(subject).to be_true
|
28
21
|
end
|
29
22
|
end
|
30
23
|
|
31
|
-
context '
|
32
|
-
before { allow(Formtastic::Util).to receive(:rails_version) { Gem::Version.new("
|
33
|
-
it 'should be
|
24
|
+
context '4.0.4' do
|
25
|
+
before { allow(Formtastic::Util).to receive(:rails_version) { Gem::Version.new("4.0.4") } }
|
26
|
+
it 'should be false' do
|
34
27
|
expect(subject).to be_false
|
35
28
|
end
|
36
29
|
end
|
37
30
|
|
38
|
-
context '
|
39
|
-
before { allow(Formtastic::Util).to receive(:rails_version) { Gem::Version.new("
|
40
|
-
it 'should be
|
31
|
+
context '4.0.5' do
|
32
|
+
before { allow(Formtastic::Util).to receive(:rails_version) { Gem::Version.new("4.0.5") } }
|
33
|
+
it 'should be false' do
|
41
34
|
expect(subject).to be_false
|
42
35
|
end
|
43
36
|
end
|
44
37
|
|
45
|
-
context '
|
46
|
-
before { allow(Formtastic::Util).to receive(:rails_version) { Gem::Version.new("
|
47
|
-
it 'should be
|
38
|
+
context '4.1.1' do
|
39
|
+
before { allow(Formtastic::Util).to receive(:rails_version) { Gem::Version.new("4.1.1") } }
|
40
|
+
it 'should be false' do
|
48
41
|
expect(subject).to be_false
|
49
42
|
end
|
50
43
|
end
|
51
44
|
|
52
|
-
context '
|
53
|
-
before { allow(Formtastic::Util).to receive(:rails_version) { Gem::Version.new("
|
45
|
+
context '5.0.0' do
|
46
|
+
before { allow(Formtastic::Util).to receive(:rails_version) { Gem::Version.new("5.0.0") } }
|
54
47
|
it 'should be true' do
|
55
48
|
expect(subject).to be_false
|
56
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: formtastic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0.rc
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin French
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ! '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 3.2.13
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ! '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 3.2.13
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: nokogiri
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,28 +44,28 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 2.14
|
47
|
+
version: '2.14'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 2.14
|
54
|
+
version: '2.14'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec_tag_matchers
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.0
|
61
|
+
version: '1.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 1.0
|
68
|
+
version: '1.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: hpricot
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,16 +84,16 @@ dependencies:
|
|
84
84
|
name: BlueCloth
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ~>
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
89
|
+
version: '1.0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ~>
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
96
|
+
version: '1.0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: yard
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,30 +112,30 @@ dependencies:
|
|
112
112
|
name: colored
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - ~>
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
117
|
+
version: '1.2'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- -
|
122
|
+
- - ~>
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
124
|
+
version: '1.2'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: tzinfo
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- -
|
129
|
+
- - ~>
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
131
|
+
version: '1.1'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- -
|
136
|
+
- - ~>
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
138
|
+
version: '1.1'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: ammeter
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -154,16 +154,16 @@ dependencies:
|
|
154
154
|
name: appraisal
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
|
-
- -
|
157
|
+
- - ~>
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: 1.0
|
159
|
+
version: '1.0'
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
|
-
- -
|
164
|
+
- - ~>
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: 1.0
|
166
|
+
version: '1.0'
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: rake
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -184,14 +184,14 @@ dependencies:
|
|
184
184
|
requirements:
|
185
185
|
- - ! '>='
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
version:
|
187
|
+
version: 3.2.13
|
188
188
|
type: :development
|
189
189
|
prerelease: false
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
192
|
- - ! '>='
|
193
193
|
- !ruby/object:Gem::Version
|
194
|
-
version:
|
194
|
+
version: 3.2.13
|
195
195
|
description: A Rails form builder plugin/gem with semantically rich and accessible
|
196
196
|
markup
|
197
197
|
email:
|
@@ -216,8 +216,6 @@ files:
|
|
216
216
|
- app/assets/stylesheets/formtastic_ie6.css
|
217
217
|
- app/assets/stylesheets/formtastic_ie7.css
|
218
218
|
- formtastic.gemspec
|
219
|
-
- gemfiles/rails_3.0.gemfile
|
220
|
-
- gemfiles/rails_3.1.gemfile
|
221
219
|
- gemfiles/rails_3.2.gemfile
|
222
220
|
- gemfiles/rails_4.0.4.gemfile
|
223
221
|
- gemfiles/rails_4.gemfile
|
@@ -252,7 +250,6 @@ files:
|
|
252
250
|
- lib/formtastic/inputs/base/datetime_pickerish.rb
|
253
251
|
- lib/formtastic/inputs/base/errors.rb
|
254
252
|
- lib/formtastic/inputs/base/fileish.rb
|
255
|
-
- lib/formtastic/inputs/base/grouped_collections.rb
|
256
253
|
- lib/formtastic/inputs/base/hints.rb
|
257
254
|
- lib/formtastic/inputs/base/html.rb
|
258
255
|
- lib/formtastic/inputs/base/labelling.rb
|
@@ -266,6 +263,7 @@ files:
|
|
266
263
|
- lib/formtastic/inputs/base/wrapping.rb
|
267
264
|
- lib/formtastic/inputs/boolean_input.rb
|
268
265
|
- lib/formtastic/inputs/check_boxes_input.rb
|
266
|
+
- lib/formtastic/inputs/color_input.rb
|
269
267
|
- lib/formtastic/inputs/country_input.rb
|
270
268
|
- lib/formtastic/inputs/date_picker_input.rb
|
271
269
|
- lib/formtastic/inputs/date_select_input.rb
|
@@ -320,6 +318,7 @@ files:
|
|
320
318
|
- spec/i18n_spec.rb
|
321
319
|
- spec/inputs/boolean_input_spec.rb
|
322
320
|
- spec/inputs/check_boxes_input_spec.rb
|
321
|
+
- spec/inputs/color_input_spec.rb
|
323
322
|
- spec/inputs/country_input_spec.rb
|
324
323
|
- spec/inputs/custom_input_spec.rb
|
325
324
|
- spec/inputs/date_picker_input_spec.rb
|
@@ -367,7 +366,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
367
366
|
requirements:
|
368
367
|
- - ! '>='
|
369
368
|
- !ruby/object:Gem::Version
|
370
|
-
version:
|
369
|
+
version: 1.9.3
|
371
370
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
372
371
|
requirements:
|
373
372
|
- - ! '>='
|
@@ -399,6 +398,7 @@ test_files:
|
|
399
398
|
- spec/i18n_spec.rb
|
400
399
|
- spec/inputs/boolean_input_spec.rb
|
401
400
|
- spec/inputs/check_boxes_input_spec.rb
|
401
|
+
- spec/inputs/color_input_spec.rb
|
402
402
|
- spec/inputs/country_input_spec.rb
|
403
403
|
- spec/inputs/custom_input_spec.rb
|
404
404
|
- spec/inputs/date_picker_input_spec.rb
|
data/gemfiles/rails_3.0.gemfile
DELETED
data/gemfiles/rails_3.1.gemfile
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
module Formtastic
|
2
|
-
module Inputs
|
3
|
-
module Base
|
4
|
-
module GroupedCollections
|
5
|
-
|
6
|
-
def raw_grouped_collection
|
7
|
-
@raw_grouped_collection ||= raw_collection.map { |option| option.send(options[:group_by]) }.uniq
|
8
|
-
end
|
9
|
-
|
10
|
-
def grouped_collection
|
11
|
-
@grouped_collection ||= raw_grouped_collection.sort_by { |group_item| group_item.send(group_label_method) }
|
12
|
-
end
|
13
|
-
|
14
|
-
def group_label_method
|
15
|
-
@group_label_method ||= (group_label_method_from_options || group_label_method_from_grouped_collection)
|
16
|
-
end
|
17
|
-
|
18
|
-
def group_label_method_from_options
|
19
|
-
options[:group_label]
|
20
|
-
end
|
21
|
-
|
22
|
-
def group_label_method_from_grouped_collection
|
23
|
-
label_and_value_method_from_collection(raw_grouped_collection).first
|
24
|
-
end
|
25
|
-
|
26
|
-
def group_association
|
27
|
-
@group_association ||= (group_association_from_options || group_association_from_reflection)
|
28
|
-
end
|
29
|
-
|
30
|
-
def group_association_from_options
|
31
|
-
options[:group_association]
|
32
|
-
end
|
33
|
-
|
34
|
-
def group_by
|
35
|
-
options[:group_by]
|
36
|
-
end
|
37
|
-
|
38
|
-
def group_association_from_reflection
|
39
|
-
method_to_group_association_by = reflection.klass.reflect_on_association(group_by)
|
40
|
-
group_class = method_to_group_association_by.klass
|
41
|
-
|
42
|
-
# This will return in the normal case
|
43
|
-
return method.to_s.pluralize.to_sym if group_class.reflect_on_association(method.to_s.pluralize)
|
44
|
-
|
45
|
-
# This is for belongs_to associations named differently than their class
|
46
|
-
# form.input :parent, :group_by => :customer
|
47
|
-
# eg.
|
48
|
-
# class Project
|
49
|
-
# belongs_to :parent, :class_name => 'Project', :foreign_key => 'parent_id'
|
50
|
-
# belongs_to :customer
|
51
|
-
# end
|
52
|
-
# class Customer
|
53
|
-
# has_many :projects
|
54
|
-
# end
|
55
|
-
group_method = group_class.to_s.underscore.pluralize.to_sym
|
56
|
-
return group_method if group_class.reflect_on_association(group_method) # :projects
|
57
|
-
|
58
|
-
# This is for has_many associations named differently than their class
|
59
|
-
# eg.
|
60
|
-
# class Project
|
61
|
-
# belongs_to :parent, :class_name => 'Project', :foreign_key => 'parent_id'
|
62
|
-
# belongs_to :customer
|
63
|
-
# end
|
64
|
-
# class Customer
|
65
|
-
# has_many :tasks, :class_name => 'Project', :foreign_key => 'customer_id'
|
66
|
-
# end
|
67
|
-
possible_associations = group_class.reflect_on_all_associations(:has_many).find_all {|assoc| assoc.klass == reflection.klass }
|
68
|
-
return possible_associations.first.name.to_sym if possible_associations.count == 1
|
69
|
-
|
70
|
-
raise "Cannot infer group association for #{method} grouped by #{group_by}, there were #{possible_associations.empty? ? 'no' : possible_associations.size} possible associations. Please specify using :group_association"
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|