formtastic 2.0.0.rc5 → 2.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.
- data/README.textile +11 -35
- data/lib/formtastic/helpers/buttons_helper.rb +35 -15
- data/lib/formtastic/inputs/base/collections.rb +23 -24
- data/lib/formtastic/inputs/check_boxes_input.rb +1 -7
- data/lib/formtastic/version.rb +1 -1
- data/lib/generators/templates/_form.html.slim +8 -0
- data/spec/helpers/commit_button_helper_spec.rb +1 -1
- data/spec/inputs/check_boxes_input_spec.rb +4 -0
- data/spec/inputs/select_input_spec.rb +6 -5
- data/spec/spec_helper.rb +21 -20
- metadata +8 -7
data/README.textile
CHANGED
@@ -7,9 +7,8 @@ Formtastic is a Rails FormBuilder DSL (with some other goodies) to make it far e
|
|
7
7
|
|
8
8
|
h2. Compatibility
|
9
9
|
|
10
|
-
* Formtastic
|
11
|
-
* Formtastic
|
12
|
-
* If you're bundling Formtastic from edge/master, get ready for a bumpy ride. Try the "1.2-stable branch":https://github.com/justinfrench/formtastic/tree/1.2-stable.
|
10
|
+
* Formtastic 2.0 is Rails 3.x compatible only
|
11
|
+
* Formtastic 1.x is compatible with both Rails 2 and 3, and is being maintained for bug fixes in the the "1.2-stable branch":https://github.com/justinfrench/formtastic/tree/1.2-stable. View the README in that branch for installation instructions, etc.
|
13
12
|
* Formtastic, much like Rails, is very ActiveRecord-centric. Many are successfully using other ActiveModel-like ORMs and objects (DataMapper, MongoMapper, Mongoid, Authlogic, Devise...) but we're not guaranteeing full compatibility at this stage. Patches are welcome!
|
14
13
|
|
15
14
|
|
@@ -51,7 +50,7 @@ One day, I finally had enough, so I opened up my text editor, and wrote a DSL fo
|
|
51
50
|
I also wrote the accompanying HTML output I expected, favoring something very similar to the fieldsets, lists and other semantic elements Aaron Gustafson presented in "Learning to Love Forms":http://www.slideshare.net/AaronGustafson/learning-to-love-forms-web-directions-south-07, hacking together enough Ruby to prove it could be done.
|
52
51
|
|
53
52
|
|
54
|
-
h2. It's
|
53
|
+
h2. It's awesome because...
|
55
54
|
|
56
55
|
* it can handle @belongs_to@ associations (like Post belongs_to :author), rendering a select or set of radio inputs with choices from the parent model.
|
57
56
|
* it can handle @has_many@ and @has_and_belongs_to_many@ associations (like: Post has_many :tags), rendering a multi-select with choices from the child models.
|
@@ -66,22 +65,12 @@ h2. It's better than _SomeOtherFormBuilder_ because...
|
|
66
65
|
* it has growing HTML5 support (new inputs like email/phone/search, new attributes like required/min/max/step/placeholder)
|
67
66
|
|
68
67
|
|
69
|
-
h2. Why?
|
70
|
-
|
71
|
-
* web apps = lots of forms.
|
72
|
-
* forms are so friggin' boring to code.
|
73
|
-
* semantically rich & accessible forms really are possible.
|
74
|
-
* the "V" is way behind the "M" and "C" in Rails' MVC – it's the ugly sibling.
|
75
|
-
* best practices and common patterns have to start somewhere.
|
76
|
-
* i need a challenge.
|
77
|
-
|
78
|
-
|
79
68
|
h2. Opinions
|
80
69
|
|
81
70
|
* it should be easier to do things the right way than the wrong way.
|
82
71
|
* sometimes _more mark-up_ is better.
|
83
72
|
* elements and attribute hooks are _gold_ for stylesheet authors.
|
84
|
-
* make the common things we do easy, yet
|
73
|
+
* make the common things we do easy, yet ensure uncommon things are still possible.
|
85
74
|
|
86
75
|
|
87
76
|
h2. Documentation
|
@@ -94,16 +83,10 @@ h2. Installation
|
|
94
83
|
Simply add Formtastic to your Gemfile and bundle it up:
|
95
84
|
|
96
85
|
<pre>
|
97
|
-
gem 'formtastic'
|
86
|
+
gem 'formtastic'
|
98
87
|
</pre>
|
99
88
|
|
100
|
-
|
101
|
-
|
102
|
-
<pre>
|
103
|
-
gem 'formtastic', '2.0.0.rc1'
|
104
|
-
</pre>
|
105
|
-
|
106
|
-
Run the installation generator to copy a stylesheet (Rails 3.0.x only) and a configuration initializer into your application:
|
89
|
+
Run the installation generator:
|
107
90
|
|
108
91
|
<pre>
|
109
92
|
$ rails generate formtastic:install
|
@@ -165,9 +148,9 @@ This renders a set of inputs (one for _most_ columns in the database table, and
|
|
165
148
|
<% end %>
|
166
149
|
</pre>
|
167
150
|
|
168
|
-
This is a great way to get something up fast, but like scaffolding, it's not recommended for production
|
151
|
+
This is a great way to get something up fast, but like scaffolding, it's *not recommended for production*. Don't be so lazy!
|
169
152
|
|
170
|
-
|
153
|
+
To specify the order of the fields, skip some of the fields or even add in fields that Formtastic couldn't infer. You can pass in a list of field names to @inputs@ and list of button names to @buttons@:
|
171
154
|
|
172
155
|
<pre>
|
173
156
|
<%= semantic_form_for @user do |form| %>
|
@@ -176,7 +159,7 @@ You probably want to specify the order of the fields, skip some of the fields or
|
|
176
159
|
<% end %>
|
177
160
|
</pre>
|
178
161
|
|
179
|
-
You probably want control over the input type Formtastic uses for each field
|
162
|
+
You probably want control over the input type Formtastic uses for each field. You can expand the @inputs@ and @buttons@ to block helper format and use the @:as@ option to specify an exact input type:
|
180
163
|
|
181
164
|
<pre>
|
182
165
|
<%= semantic_form_for @post do |form| %>
|
@@ -419,8 +402,6 @@ Formtastic supports localized *labels*, *hints*, *legends*, *actions* using the
|
|
419
402
|
dummie: "Launch!"
|
420
403
|
</pre>
|
421
404
|
|
422
|
-
*Note:* We are using English here still, but you get the point.
|
423
|
-
|
424
405
|
*3. ...and now you'll get:*
|
425
406
|
|
426
407
|
<pre>
|
@@ -531,11 +512,6 @@ You can show errors on base (by default) and any other attribute just passing it
|
|
531
512
|
</pre>
|
532
513
|
|
533
514
|
|
534
|
-
h2. Configuration
|
535
|
-
|
536
|
-
Run @rails generate formtastic:install@ to copy a commented out config file into @config/initializers/formtastic.rb@. You can "view the configuration file on GitHub":http://github.com/justinfrench/formtastic/blob/master/lib/generators/templates/formtastic.rb
|
537
|
-
|
538
|
-
|
539
515
|
h2. Modified & Custom Inputs
|
540
516
|
|
541
517
|
If you want to change the behaviour of an input, you can subclass it in your app. For example, to tweak @StringInput@, create a new file @app/inputs/string_input.rb@:
|
@@ -572,12 +548,12 @@ To create your own new types of inputs from scratch:
|
|
572
548
|
end
|
573
549
|
</pre>
|
574
550
|
|
575
|
-
It was previously
|
551
|
+
It was previously recommended in Formtastic 1.x to subclass Formtastic::FormBuilder to add your own inputs. This is no longer recommended in Formtastic 2, and will not work as expected.
|
576
552
|
|
577
553
|
|
578
554
|
h2. Security
|
579
555
|
|
580
|
-
By default
|
556
|
+
By default Formtastic escapes html entities in both labels and hints unless a string is marked as html_safe. If you are using an older rails version which doesn't know html_safe, or you want to globally turn this feature off, you can set the following in your initializer:
|
581
557
|
|
582
558
|
Formtastic::FormBuilder.escape_html_entities_in_hints_and_labels = false
|
583
559
|
|
@@ -238,9 +238,23 @@ module Formtastic
|
|
238
238
|
options = args.extract_options!
|
239
239
|
text = options.delete(:label) || args.shift
|
240
240
|
|
241
|
-
|
242
|
-
|
241
|
+
text = (localized_string(commit_button_i18n_key, text, :action, :model => commit_button_object_name) ||
|
242
|
+
Formtastic::I18n.t(commit_button_i18n_key, :model => commit_button_object_name)) unless text.is_a?(::String)
|
243
|
+
|
244
|
+
button_html = options.delete(:button_html) || {}
|
245
|
+
button_html.merge!(:class => [button_html[:class], commit_button_i18n_key].compact.join(' '))
|
243
246
|
|
247
|
+
wrapper_html = options.delete(:wrapper_html) || {}
|
248
|
+
wrapper_html[:class] = (commit_button_wrapper_html_class << wrapper_html[:class]).flatten.compact.join(' ')
|
249
|
+
|
250
|
+
accesskey = (options.delete(:accesskey) || default_commit_button_accesskey) unless button_html.has_key?(:accesskey)
|
251
|
+
button_html = button_html.merge(:accesskey => accesskey) if accesskey
|
252
|
+
|
253
|
+
template.content_tag(:li, Formtastic::Util.html_safe(submit(text, button_html)), wrapper_html)
|
254
|
+
end
|
255
|
+
|
256
|
+
def commit_button_object_name
|
257
|
+
if new_or_persisted_object?
|
244
258
|
# Deal with some complications with ActiveRecord::Base.human_name and two name models (eg UserPost)
|
245
259
|
# ActiveRecord::Base.human_name falls back to ActiveRecord::Base.name.humanize ("Userpost")
|
246
260
|
# if there's no i18n, which is pretty crappy. In this circumstance we want to detect this
|
@@ -254,24 +268,30 @@ module Formtastic
|
|
254
268
|
object_name = (object_human_name == crappy_human_name) ? decent_human_name : object_human_name
|
255
269
|
end
|
256
270
|
else
|
257
|
-
key = :submit
|
258
271
|
object_name = @object_name.to_s.send(label_str_method)
|
259
272
|
end
|
273
|
+
|
274
|
+
object_name
|
275
|
+
end
|
276
|
+
|
277
|
+
def commit_button_i18n_key
|
278
|
+
if new_or_persisted_object?
|
279
|
+
key = @object.persisted? ? :update : :create
|
280
|
+
else
|
281
|
+
key = :submit
|
282
|
+
end
|
260
283
|
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
button_html = options.delete(:button_html) || {}
|
265
|
-
button_html.merge!(:class => [button_html[:class], key].compact.join(' '))
|
266
|
-
|
267
|
-
wrapper_html_class = ['commit', 'button'] # TODO: Add class reflecting on form action.
|
268
|
-
wrapper_html = options.delete(:wrapper_html) || {}
|
269
|
-
wrapper_html[:class] = (wrapper_html_class << wrapper_html[:class]).flatten.compact.join(' ')
|
284
|
+
key
|
285
|
+
end
|
270
286
|
|
271
|
-
|
272
|
-
|
273
|
-
|
287
|
+
def commit_button_wrapper_html_class
|
288
|
+
['commit', 'button'] # TODO: Add class reflecting on form action.
|
289
|
+
end
|
290
|
+
|
291
|
+
def new_or_persisted_object?
|
292
|
+
@object && (@object.respond_to?(:persisted?) || @object.respond_to?(:new_record?))
|
274
293
|
end
|
294
|
+
|
275
295
|
end
|
276
296
|
end
|
277
297
|
end
|
@@ -2,18 +2,18 @@ module Formtastic
|
|
2
2
|
module Inputs
|
3
3
|
module Base
|
4
4
|
module Collections
|
5
|
-
|
5
|
+
|
6
6
|
def label_method
|
7
7
|
label_and_value_method(raw_collection).first
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def value_method
|
11
11
|
label_and_value_method(raw_collection).last
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def label_and_value_method(_collection, grouped=false)
|
15
15
|
sample = _collection.first || _collection.last
|
16
|
-
|
16
|
+
|
17
17
|
case sample
|
18
18
|
when Array
|
19
19
|
label, value = :first, :last
|
@@ -22,36 +22,36 @@ module Formtastic
|
|
22
22
|
when String, NilClass
|
23
23
|
label, value = :to_s, :to_s
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
# Order of preference: user supplied method, class defaults, auto-detect
|
27
27
|
label = (grouped ? options[:grouped_label_method] : options[:member_label]) || label || builder.collection_label_methods.find { |m| sample.respond_to?(m) }
|
28
28
|
value = (grouped ? options[:grouped_value_method] : options[:member_value]) || value || builder.collection_value_methods.find { |m| sample.respond_to?(m) }
|
29
|
-
|
29
|
+
|
30
30
|
[label, value]
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def raw_collection
|
34
34
|
@raw_collection ||= (collection_from_options || collection_from_association || collection_for_boolean)
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def collection
|
38
38
|
# Return if we have a plain string
|
39
39
|
return raw_collection if raw_collection.instance_of?(String) || raw_collection.instance_of?(ActiveSupport::SafeBuffer)
|
40
|
-
|
40
|
+
|
41
41
|
# Return if we have an Array of strings, fixnums or arrays
|
42
42
|
return raw_collection if (raw_collection.instance_of?(Array) || raw_collection.instance_of?(Range)) &&
|
43
43
|
[Array, Fixnum, String, Symbol].include?(raw_collection.first.class) &&
|
44
44
|
!(options.include?(:member_label) || options.include?(:member_value))
|
45
|
-
|
45
|
+
|
46
46
|
raw_collection.map { |o| [send_or_call(label_method, o), send_or_call(value_method, o)] }
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
def collection_from_options
|
50
50
|
items = options[:collection]
|
51
51
|
items = items.to_a if items.is_a?(Hash)
|
52
52
|
items
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
def collection_from_association
|
56
56
|
if reflection
|
57
57
|
raise PolymorphicInputWithoutCollectionError.new("A collection must be supplied for #{method} input. Collections cannot be guessed for polymorphic associations.") if reflection.options && reflection.options[:polymorphic] == true
|
@@ -59,42 +59,41 @@ module Formtastic
|
|
59
59
|
find_options_from_options = options[:find_options] || {}
|
60
60
|
conditions_from_options = find_options_from_options[:conditions] || {}
|
61
61
|
conditions_from_reflection = reflection.options && reflection.options[:conditions] || {}
|
62
|
-
|
62
|
+
conditions_from_reflection = conditions_from_reflection.call if conditions_from_reflection.is_a?(Proc)
|
63
|
+
|
63
64
|
if conditions_from_options.any?
|
64
|
-
reflection.klass.where(
|
65
|
-
conditions_from_reflection.merge(conditions_from_options)
|
66
|
-
)
|
65
|
+
reflection.klass.scoped(:conditions => conditions_from_reflection).where(conditions_from_options)
|
67
66
|
else
|
68
67
|
find_options_from_options.merge!(:include => group_by) if self.respond_to?(:group_by) && group_by
|
69
|
-
reflection.klass.
|
68
|
+
reflection.klass.scoped(:conditions => conditions_from_reflection).where(find_options_from_options)
|
70
69
|
end
|
71
70
|
end
|
72
71
|
end
|
73
|
-
|
72
|
+
|
74
73
|
def collection_for_boolean
|
75
74
|
true_text = options[:true] || Formtastic::I18n.t(:yes)
|
76
75
|
false_text = options[:false] || Formtastic::I18n.t(:no)
|
77
|
-
|
76
|
+
|
78
77
|
# TODO options[:value_as_class] = true unless options.key?(:value_as_class)
|
79
|
-
|
78
|
+
|
80
79
|
[ [true_text, true], [false_text, false] ]
|
81
80
|
end
|
82
|
-
|
81
|
+
|
83
82
|
def send_or_call(duck, object)
|
84
83
|
if duck.respond_to?(:call)
|
85
84
|
duck.call(object)
|
86
|
-
|
85
|
+
elsif object.respond_to? duck.to_sym
|
87
86
|
object.send(duck)
|
88
87
|
end
|
89
88
|
end
|
90
|
-
|
89
|
+
|
91
90
|
# Avoids an issue where `send_or_call` can be a String and duck can be something simple like
|
92
91
|
# `:first`, which obviously String responds to.
|
93
92
|
def send_or_call_or_object(duck, object)
|
94
93
|
return object if object.is_a?(String) # TODO what about other classes etc?
|
95
94
|
send_or_call(duck, object)
|
96
95
|
end
|
97
|
-
|
96
|
+
|
98
97
|
end
|
99
98
|
end
|
100
99
|
end
|
@@ -153,13 +153,7 @@ module Formtastic
|
|
153
153
|
|
154
154
|
def selected_values
|
155
155
|
if object.respond_to?(method)
|
156
|
-
|
157
|
-
options[:collection].flatten.all? {|i| i.is_a?(String) or i.is_a?(Integer)}
|
158
|
-
|
159
|
-
selected_items = options[:collection]
|
160
|
-
else
|
161
|
-
selected_items = [object.send(method)].compact.flatten
|
162
|
-
end
|
156
|
+
selected_items = [object.send(method)].compact.flatten
|
163
157
|
|
164
158
|
[*selected_items.map { |o| send_or_call_or_object(value_method, o) }].compact
|
165
159
|
else
|
data/lib/formtastic/version.rb
CHANGED
@@ -461,7 +461,7 @@ describe 'Formtastic::FormBuilder#commit_button' do
|
|
461
461
|
concat(semantic_form_for(@new_post) do |builder|
|
462
462
|
concat(builder.commit_button('text'))
|
463
463
|
end)
|
464
|
-
output_buffer.should have_tag("form li.commit")
|
464
|
+
output_buffer.should have_tag("form li.commit.button")
|
465
465
|
end
|
466
466
|
end
|
467
467
|
|
@@ -410,6 +410,10 @@ describe 'check_boxes input' do
|
|
410
410
|
output_buffer.should have_tag("form li fieldset ol li label[@for='author_post_ids_#{post.last}']")
|
411
411
|
end
|
412
412
|
end
|
413
|
+
|
414
|
+
it "should not check any items" do
|
415
|
+
output_buffer.should have_tag('form li input[@checked]', :count => 0)
|
416
|
+
end
|
413
417
|
end
|
414
418
|
|
415
419
|
end
|
@@ -208,7 +208,7 @@ describe 'select input' do
|
|
208
208
|
end
|
209
209
|
|
210
210
|
it "should call author.find with association conditions" do
|
211
|
-
::Author.should_receive(:
|
211
|
+
::Author.should_receive(:scoped).with(:conditions => {:active => true})
|
212
212
|
|
213
213
|
semantic_form_for(@new_post) do |builder|
|
214
214
|
concat(builder.input(:author, :as => :select))
|
@@ -216,7 +216,8 @@ describe 'select input' do
|
|
216
216
|
end
|
217
217
|
|
218
218
|
it "should call author.find with association conditions and find_options conditions" do
|
219
|
-
::Author.should_receive(:
|
219
|
+
::Author.should_receive(:scoped).with(:conditions => {:active => true})
|
220
|
+
::Author.should_receive(:where).with({:publisher => true})
|
220
221
|
|
221
222
|
semantic_form_for(@new_post) do |builder|
|
222
223
|
concat(builder.input(:author, :as => :select, :find_options => {:conditions => {:publisher => true}}))
|
@@ -316,11 +317,11 @@ describe 'select input' do
|
|
316
317
|
it 'should have a multi-select select' do
|
317
318
|
output_buffer.should have_tag('form li select[@multiple="multiple"]')
|
318
319
|
end
|
319
|
-
|
320
|
+
|
320
321
|
it 'should append [] to the name attribute for multiple select' do
|
321
322
|
output_buffer.should have_tag('form li select[@multiple="multiple"][@name="author[post_ids][]"]')
|
322
323
|
end
|
323
|
-
|
324
|
+
|
324
325
|
it 'should have a select option for each Post' do
|
325
326
|
output_buffer.should have_tag('form li select option', :count => ::Post.all.size)
|
326
327
|
::Post.all.each do |post|
|
@@ -535,7 +536,7 @@ describe 'select input' do
|
|
535
536
|
|
536
537
|
context "when required" do
|
537
538
|
it "should add the required attribute to the select's html options" do
|
538
|
-
with_config :use_required_attribute, true do
|
539
|
+
with_config :use_required_attribute, true do
|
539
540
|
concat(semantic_form_for(@new_post) do |builder|
|
540
541
|
concat(builder.input(:author, :as => :select, :required => true))
|
541
542
|
end)
|
data/spec/spec_helper.rb
CHANGED
@@ -67,7 +67,7 @@ module FormtasticSpecHelper
|
|
67
67
|
def active_model_inclusion_validator(attributes, options = {})
|
68
68
|
active_model_validator(:inclusion, attributes, options)
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
def active_model_numericality_validator(attributes, options = {})
|
72
72
|
active_model_validator(:numericality, attributes, options)
|
73
73
|
end
|
@@ -93,7 +93,7 @@ module FormtasticSpecHelper
|
|
93
93
|
def persisted?
|
94
94
|
end
|
95
95
|
end
|
96
|
-
|
96
|
+
|
97
97
|
module ::Namespaced
|
98
98
|
class Post
|
99
99
|
extend ActiveModel::Naming if defined?(ActiveModel::Naming)
|
@@ -106,18 +106,18 @@ module FormtasticSpecHelper
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|
109
|
-
|
109
|
+
|
110
110
|
class ::Author
|
111
111
|
extend ActiveModel::Naming if defined?(ActiveModel::Naming)
|
112
112
|
include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
|
113
113
|
|
114
114
|
def to_label
|
115
115
|
end
|
116
|
-
|
116
|
+
|
117
117
|
def persisted?
|
118
118
|
end
|
119
119
|
end
|
120
|
-
|
120
|
+
|
121
121
|
class ::HashBackedAuthor < Hash
|
122
122
|
extend ActiveModel::Naming if defined?(ActiveModel::Naming)
|
123
123
|
include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
|
@@ -126,34 +126,34 @@ module FormtasticSpecHelper
|
|
126
126
|
'hash backed author'
|
127
127
|
end
|
128
128
|
end
|
129
|
-
|
129
|
+
|
130
130
|
class ::Continent
|
131
131
|
extend ActiveModel::Naming if defined?(ActiveModel::Naming)
|
132
132
|
include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
|
133
133
|
end
|
134
|
-
|
134
|
+
|
135
135
|
class ::PostModel
|
136
136
|
extend ActiveModel::Naming if defined?(ActiveModel::Naming)
|
137
137
|
include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
|
138
138
|
end
|
139
|
-
|
139
|
+
|
140
140
|
def _routes
|
141
141
|
url_helpers = mock('url_helpers')
|
142
142
|
url_helpers.stub!(:hash_for_posts_path).and_return({})
|
143
143
|
url_helpers.stub!(:hash_for_post_path).and_return({})
|
144
144
|
url_helpers.stub!(:hash_for_post_models_path).and_return({})
|
145
145
|
url_helpers.stub!(:hash_for_authors_path).and_return({})
|
146
|
-
|
147
|
-
mock('_routes',
|
146
|
+
|
147
|
+
mock('_routes',
|
148
148
|
:url_helpers => url_helpers,
|
149
149
|
:url_for => "/mock/path"
|
150
150
|
)
|
151
151
|
end
|
152
|
-
|
152
|
+
|
153
153
|
def controller
|
154
154
|
mock('controller', :controller_path= => '', :params => {})
|
155
155
|
end
|
156
|
-
|
156
|
+
|
157
157
|
def default_url_options
|
158
158
|
{}
|
159
159
|
end
|
@@ -171,7 +171,7 @@ module FormtasticSpecHelper
|
|
171
171
|
def author_path(*args); "/authors/1"; end
|
172
172
|
def authors_path(*args); "/authors"; end
|
173
173
|
def new_author_path(*args); "/authors/new"; end
|
174
|
-
|
174
|
+
|
175
175
|
@fred = ::Author.new
|
176
176
|
@fred.stub!(:class).and_return(::Author)
|
177
177
|
@fred.stub!(:to_label).and_return('Fred Smith')
|
@@ -212,6 +212,7 @@ module FormtasticSpecHelper
|
|
212
212
|
@james.stub!(:name).and_return('James')
|
213
213
|
|
214
214
|
|
215
|
+
::Author.stub!(:scoped).and_return(::Author)
|
215
216
|
::Author.stub!(:find).and_return([@fred, @bob])
|
216
217
|
::Author.stub!(:all).and_return([@fred, @bob])
|
217
218
|
::Author.stub!(:where).and_return([@fred, @bob])
|
@@ -223,7 +224,7 @@ module FormtasticSpecHelper
|
|
223
224
|
::Author.stub!(:persisted?).and_return(nil)
|
224
225
|
|
225
226
|
@hash_backed_author = HashBackedAuthor.new
|
226
|
-
|
227
|
+
|
227
228
|
# Sometimes we need a mock @post object and some Authors for belongs_to
|
228
229
|
@new_post = mock('post')
|
229
230
|
@new_post.stub!(:class).and_return(::Post)
|
@@ -240,7 +241,7 @@ module FormtasticSpecHelper
|
|
240
241
|
@new_post.stub!(:to_key).and_return(nil)
|
241
242
|
@new_post.stub!(:to_model).and_return(@new_post)
|
242
243
|
@new_post.stub!(:persisted?).and_return(nil)
|
243
|
-
|
244
|
+
|
244
245
|
@freds_post = mock('post')
|
245
246
|
@freds_post.stub!(:to_ary)
|
246
247
|
@freds_post.stub!(:class).and_return(::Post)
|
@@ -258,6 +259,7 @@ module FormtasticSpecHelper
|
|
258
259
|
@fred.stub!(:posts).and_return([@freds_post])
|
259
260
|
@fred.stub!(:post_ids).and_return([@freds_post.id])
|
260
261
|
|
262
|
+
::Post.stub!(:scoped).and_return(::Post)
|
261
263
|
::Post.stub!(:human_attribute_name).and_return { |column_name| column_name.humanize }
|
262
264
|
::Post.stub!(:human_name).and_return('Post')
|
263
265
|
::Post.stub!(:reflect_on_all_validations).and_return([])
|
@@ -291,7 +293,6 @@ module FormtasticSpecHelper
|
|
291
293
|
::Post.stub!(:persisted?).and_return(nil)
|
292
294
|
::Post.stub!(:to_ary)
|
293
295
|
|
294
|
-
|
295
296
|
::MongoPost.stub!(:human_attribute_name).and_return { |column_name| column_name.humanize }
|
296
297
|
::MongoPost.stub!(:human_name).and_return('MongoPost')
|
297
298
|
::MongoPost.stub!(:associations).and_return do |column_name|
|
@@ -306,14 +307,14 @@ module FormtasticSpecHelper
|
|
306
307
|
::MongoPost.stub!(:to_key).and_return(nil)
|
307
308
|
::MongoPost.stub!(:persisted?).and_return(nil)
|
308
309
|
::MongoPost.stub!(:to_ary)
|
309
|
-
::MongoPost.stub!(:model_name).and_return( mock(:model_name_mock, :singular => "post", :plural => "posts", :param_key => "post", :route_key => "posts") )
|
310
|
+
::MongoPost.stub!(:model_name).and_return( mock(:model_name_mock, :singular => "post", :plural => "posts", :param_key => "post", :route_key => "posts") )
|
310
311
|
|
311
312
|
@new_mm_post = mock('mm_post')
|
312
313
|
@new_mm_post.stub!(:class).and_return(::MongoPost)
|
313
314
|
@new_mm_post.stub!(:id).and_return(nil)
|
314
315
|
@new_mm_post.stub!(:new_record?).and_return(true)
|
315
316
|
@new_mm_post.stub!(:errors).and_return(mock('errors', :[] => nil))
|
316
|
-
@new_mm_post.stub!(:title).and_return("Hello World")
|
317
|
+
@new_mm_post.stub!(:title).and_return("Hello World")
|
317
318
|
@new_mm_post.stub!(:sub_posts).and_return([]) #TODO should be a mock with methods for adding sub posts
|
318
319
|
@new_mm_post.stub!(:to_key).and_return(nil)
|
319
320
|
@new_mm_post.stub!(:to_model).and_return(@new_mm_post)
|
@@ -384,11 +385,11 @@ module FormtasticSpecHelper
|
|
384
385
|
def protect_against_forgery?
|
385
386
|
false
|
386
387
|
end
|
387
|
-
|
388
|
+
|
388
389
|
def _helpers
|
389
390
|
FakeHelpersModule
|
390
391
|
end
|
391
|
-
|
392
|
+
|
392
393
|
end
|
393
394
|
end
|
394
395
|
|
metadata
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: formtastic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 15
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 0
|
9
9
|
- 0
|
10
|
-
|
11
|
-
- 5
|
12
|
-
version: 2.0.0.rc5
|
10
|
+
version: 2.0.0
|
13
11
|
platform: ruby
|
14
12
|
authors:
|
15
13
|
- Justin French
|
@@ -17,7 +15,8 @@ autorequire:
|
|
17
15
|
bindir: bin
|
18
16
|
cert_chain: []
|
19
17
|
|
20
|
-
date: 2011-09-
|
18
|
+
date: 2011-09-23 00:00:00 +10:00
|
19
|
+
default_executable:
|
21
20
|
dependencies:
|
22
21
|
- !ruby/object:Gem::Dependency
|
23
22
|
name: rails
|
@@ -226,6 +225,7 @@ files:
|
|
226
225
|
- lib/generators/formtastic/install/install_generator.rb
|
227
226
|
- lib/generators/templates/_form.html.erb
|
228
227
|
- lib/generators/templates/_form.html.haml
|
228
|
+
- lib/generators/templates/_form.html.slim
|
229
229
|
- lib/generators/templates/formtastic.rb
|
230
230
|
- lib/locale/en.yml
|
231
231
|
- lib/tasks/verify_rcov.rb
|
@@ -275,6 +275,7 @@ files:
|
|
275
275
|
- spec/support/deferred_garbage_collection.rb
|
276
276
|
- spec/support/deprecation.rb
|
277
277
|
- spec/support/test_environment.rb
|
278
|
+
has_rdoc: true
|
278
279
|
homepage: http://github.com/justinfrench/formtastic
|
279
280
|
licenses: []
|
280
281
|
|
@@ -304,7 +305,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
304
305
|
requirements: []
|
305
306
|
|
306
307
|
rubyforge_project:
|
307
|
-
rubygems_version: 1.
|
308
|
+
rubygems_version: 1.4.2
|
308
309
|
signing_key:
|
309
310
|
specification_version: 3
|
310
311
|
summary: A Rails form builder plugin/gem with semantically rich and accessible markup
|