formnestic 1.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/.document +5 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/.watchr +31 -0
- data/Gemfile +27 -0
- data/Gemfile.lock +133 -0
- data/MIT-LICENSE +20 -0
- data/README.markdown +126 -0
- data/Rakefile +44 -0
- data/VERSION +1 -0
- data/app/assets/.DS_Store +0 -0
- data/app/assets/javascripts/formnestic/formnestic.js +139 -0
- data/app/assets/stylesheets/formnestic/entypo.css.scss +327 -0
- data/app/assets/stylesheets/formnestic/entypo.eot +0 -0
- data/app/assets/stylesheets/formnestic/entypo.svg +296 -0
- data/app/assets/stylesheets/formnestic/entypo.ttf +0 -0
- data/app/assets/stylesheets/formnestic/entypo.woff +0 -0
- data/app/assets/stylesheets/formnestic/formnestic.css.scss +167 -0
- data/config/locales/formnestic.en.yml +8 -0
- data/formnestic.gemspec +112 -0
- data/lib/formnestic/form_builder/base_builder.rb +55 -0
- data/lib/formnestic/form_builder/list_form_builder.rb +30 -0
- data/lib/formnestic/form_builder/table_form_builder.rb +94 -0
- data/lib/formnestic/form_builder.rb +13 -0
- data/lib/formnestic/helpers/inputs_helper.rb +82 -0
- data/lib/formnestic/helpers.rb +9 -0
- data/lib/formnestic/inputs/base/labelling.rb +15 -0
- data/lib/formnestic/inputs/base/wrapping.rb +52 -0
- data/lib/formnestic/inputs/base.rb +12 -0
- data/lib/formnestic/inputs.rb +7 -0
- data/lib/formnestic.rb +72 -0
- data/lib/generators/formnestic/install_generator.rb +36 -0
- data/log/development.log +0 -0
- data/rwatchr +1 -0
- data/screenshots/list_form.png +0 -0
- data/screenshots/table_form.png +0 -0
- data/spec/helpers/nested_model_helper_spec.rb +277 -0
- data/spec/helpers/nested_model_list_helper_spec.rb +51 -0
- data/spec/inputs/boolean_input_spec.rb +223 -0
- data/spec/spec_helper.rb +553 -0
- data/spec/support/custom_macros.rb +528 -0
- data/spec/support/deferred_garbage_collection.rb +21 -0
- data/spec/support/deprecation.rb +6 -0
- data/spec/support/test_environment.rb +31 -0
- metadata +271 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,553 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'spork'
|
5
|
+
require 'bundler/setup'
|
6
|
+
require 'active_support'
|
7
|
+
require 'action_pack'
|
8
|
+
require 'action_view'
|
9
|
+
require 'action_controller'
|
10
|
+
require 'action_dispatch'
|
11
|
+
require 'formtastic'
|
12
|
+
|
13
|
+
# require 'ammeter/init'
|
14
|
+
|
15
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/formnestic'))
|
16
|
+
|
17
|
+
#uncomment the following line to use spork with the debugger
|
18
|
+
#require 'spork/ext/ruby-debug'
|
19
|
+
|
20
|
+
Spork.prefork do
|
21
|
+
# Loading more in this block will cause your tests to run faster. However,
|
22
|
+
# if you change any configuration or code from libraries loaded here, you'll
|
23
|
+
# need to restart spork for it take effect.
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
Spork.each_run do
|
28
|
+
# This code will be run each time you run your specs.
|
29
|
+
# Requires supporting files with custom matchers and macros, etc,
|
30
|
+
# in ./support/ and its subdirectories in alphabetic order.
|
31
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each {|f| require f}
|
32
|
+
|
33
|
+
module FakeHelpersModule
|
34
|
+
end
|
35
|
+
|
36
|
+
module FormtasticSpecHelper
|
37
|
+
include ActionPack
|
38
|
+
include ActionView::Context if defined?(ActionView::Context)
|
39
|
+
include ActionController::RecordIdentifier if defined?(ActionController::RecordIdentifier)
|
40
|
+
include ActionView::Helpers::FormHelper
|
41
|
+
include ActionView::Helpers::FormTagHelper
|
42
|
+
include ActionView::Helpers::FormOptionsHelper
|
43
|
+
include ActionView::Helpers::UrlHelper
|
44
|
+
include ActionView::Helpers::TagHelper
|
45
|
+
include ActionView::Helpers::TextHelper
|
46
|
+
include ActionView::Helpers::ActiveRecordHelper if defined?(ActionView::Helpers::ActiveRecordHelper)
|
47
|
+
include ActionView::Helpers::ActiveModelHelper if defined?(ActionView::Helpers::ActiveModelHelper)
|
48
|
+
include ActionView::Helpers::DateHelper
|
49
|
+
include ActionView::Helpers::CaptureHelper
|
50
|
+
include ActionView::Helpers::AssetTagHelper
|
51
|
+
include ActiveSupport
|
52
|
+
include ActionController::PolymorphicRoutes if defined?(ActionController::PolymorphicRoutes)
|
53
|
+
|
54
|
+
include Formtastic::Helpers::FormHelper
|
55
|
+
|
56
|
+
def default_input_type(column_type, column_name = :generic_column_name)
|
57
|
+
@new_post.stub(column_name)
|
58
|
+
@new_post.stub(:column_for_attribute).and_return(double('column', :type => column_type)) unless column_type.nil?
|
59
|
+
|
60
|
+
semantic_form_for(@new_post) do |builder|
|
61
|
+
@default_type = builder.send(:default_input_type, column_name)
|
62
|
+
end
|
63
|
+
|
64
|
+
return @default_type
|
65
|
+
end
|
66
|
+
|
67
|
+
def active_model_validator(kind, attributes, options = {})
|
68
|
+
validator = double("ActiveModel::Validations::#{kind.to_s.titlecase}Validator", :attributes => attributes, :options => options)
|
69
|
+
validator.stub(:kind).and_return(kind)
|
70
|
+
validator
|
71
|
+
end
|
72
|
+
|
73
|
+
def active_model_presence_validator(attributes, options = {})
|
74
|
+
active_model_validator(:presence, attributes, options)
|
75
|
+
end
|
76
|
+
|
77
|
+
def active_model_length_validator(attributes, options = {})
|
78
|
+
active_model_validator(:length, attributes, options)
|
79
|
+
end
|
80
|
+
|
81
|
+
def active_model_inclusion_validator(attributes, options = {})
|
82
|
+
active_model_validator(:inclusion, attributes, options)
|
83
|
+
end
|
84
|
+
|
85
|
+
def active_model_numericality_validator(attributes, options = {})
|
86
|
+
active_model_validator(:numericality, attributes, options)
|
87
|
+
end
|
88
|
+
|
89
|
+
class ::MongoPost
|
90
|
+
include MongoMapper::Document if defined?(MongoMapper::Document)
|
91
|
+
|
92
|
+
def id
|
93
|
+
end
|
94
|
+
|
95
|
+
def persisted?
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
class ::Post
|
101
|
+
extend ActiveModel::Naming if defined?(ActiveModel::Naming)
|
102
|
+
include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
|
103
|
+
|
104
|
+
def id
|
105
|
+
end
|
106
|
+
|
107
|
+
def persisted?
|
108
|
+
end
|
109
|
+
|
110
|
+
def title
|
111
|
+
"sample title"
|
112
|
+
end
|
113
|
+
|
114
|
+
def body
|
115
|
+
"sample body"
|
116
|
+
end
|
117
|
+
|
118
|
+
def post_date
|
119
|
+
Date.today
|
120
|
+
end
|
121
|
+
|
122
|
+
def recent
|
123
|
+
true
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
module ::Namespaced
|
128
|
+
class Post
|
129
|
+
extend ActiveModel::Naming if defined?(ActiveModel::Naming)
|
130
|
+
include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
|
131
|
+
|
132
|
+
def id
|
133
|
+
end
|
134
|
+
|
135
|
+
def persisted?
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
class ::Author
|
141
|
+
extend ActiveModel::Naming if defined?(ActiveModel::Naming)
|
142
|
+
include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
|
143
|
+
|
144
|
+
def to_label
|
145
|
+
end
|
146
|
+
|
147
|
+
def persisted?
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
class ::HashBackedAuthor < Hash
|
152
|
+
extend ActiveModel::Naming if defined?(ActiveModel::Naming)
|
153
|
+
include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
|
154
|
+
def persisted?; false; end
|
155
|
+
def name
|
156
|
+
'hash backed author'
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
class ::Continent
|
161
|
+
extend ActiveModel::Naming if defined?(ActiveModel::Naming)
|
162
|
+
include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
|
163
|
+
end
|
164
|
+
|
165
|
+
class ::PostModel
|
166
|
+
extend ActiveModel::Naming if defined?(ActiveModel::Naming)
|
167
|
+
include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
|
168
|
+
end
|
169
|
+
|
170
|
+
##
|
171
|
+
# We can't mock :respond_to?, so we need a concrete class override
|
172
|
+
class ::MongoidReflectionMock < RSpec::Mocks::Mock
|
173
|
+
def initialize(name=nil, stubs_and_options={})
|
174
|
+
super name, stubs_and_options
|
175
|
+
end
|
176
|
+
|
177
|
+
def respond_to?(sym)
|
178
|
+
sym == :options ? false : super
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
def _routes
|
183
|
+
url_helpers = double('url_helpers')
|
184
|
+
url_helpers.stub(:hash_for_posts_path).and_return({})
|
185
|
+
url_helpers.stub(:hash_for_post_path).and_return({})
|
186
|
+
url_helpers.stub(:hash_for_post_models_path).and_return({})
|
187
|
+
url_helpers.stub(:hash_for_authors_path).and_return({})
|
188
|
+
|
189
|
+
double('_routes',
|
190
|
+
:url_helpers => url_helpers,
|
191
|
+
:url_for => "/mock/path"
|
192
|
+
)
|
193
|
+
end
|
194
|
+
|
195
|
+
def controller
|
196
|
+
env = double('env', :[] => nil)
|
197
|
+
request = double('request', :env => env)
|
198
|
+
double('controller', :controller_path= => '', :params => {}, :request => request)
|
199
|
+
end
|
200
|
+
|
201
|
+
def default_url_options
|
202
|
+
{}
|
203
|
+
end
|
204
|
+
|
205
|
+
def mock_everything
|
206
|
+
|
207
|
+
# Resource-oriented styles like form_for(@post) will expect a path method for the object,
|
208
|
+
# so we're defining some here.
|
209
|
+
def post_models_path(*args); "/postmodels/1"; end
|
210
|
+
|
211
|
+
def post_path(*args); "/posts/1"; end
|
212
|
+
def posts_path(*args); "/posts"; end
|
213
|
+
def new_post_path(*args); "/posts/new"; end
|
214
|
+
|
215
|
+
def author_path(*args); "/authors/1"; end
|
216
|
+
def authors_path(*args); "/authors"; end
|
217
|
+
def new_author_path(*args); "/authors/new"; end
|
218
|
+
|
219
|
+
@fred = ::Author.new
|
220
|
+
@fred.stub(:class).and_return(::Author)
|
221
|
+
@fred.stub(:to_label).and_return('Fred Smith')
|
222
|
+
@fred.stub(:login).and_return('fred_smith')
|
223
|
+
@fred.stub(:age).and_return(27)
|
224
|
+
@fred.stub(:id).and_return(37)
|
225
|
+
@fred.stub(:new_record?).and_return(false)
|
226
|
+
@fred.stub(:errors).and_return(double('errors', :[] => nil))
|
227
|
+
@fred.stub(:to_key).and_return(nil)
|
228
|
+
@fred.stub(:persisted?).and_return(nil)
|
229
|
+
@fred.stub(:name).and_return('Fred')
|
230
|
+
|
231
|
+
@bob = ::Author.new
|
232
|
+
@bob.stub(:to_label).and_return('Bob Rock')
|
233
|
+
@bob.stub(:login).and_return('bob')
|
234
|
+
@bob.stub(:age).and_return(43)
|
235
|
+
@bob.stub(:created_at)
|
236
|
+
@bob.stub(:id).and_return(42)
|
237
|
+
@bob.stub(:posts).and_return([])
|
238
|
+
@bob.stub(:post_ids).and_return([])
|
239
|
+
@bob.stub(:new_record?).and_return(false)
|
240
|
+
@bob.stub(:errors).and_return(double('errors', :[] => nil))
|
241
|
+
@bob.stub(:to_key).and_return(nil)
|
242
|
+
@bob.stub(:persisted?).and_return(nil)
|
243
|
+
@bob.stub(:name).and_return('Bob')
|
244
|
+
|
245
|
+
@james = ::Author.new
|
246
|
+
@james.stub(:to_label).and_return('James Shock')
|
247
|
+
@james.stub(:login).and_return('james')
|
248
|
+
@james.stub(:age).and_return(38)
|
249
|
+
@james.stub(:id).and_return(75)
|
250
|
+
@james.stub(:posts).and_return([])
|
251
|
+
@james.stub(:post_ids).and_return([])
|
252
|
+
@james.stub(:new_record?).and_return(false)
|
253
|
+
@james.stub(:errors).and_return(double('errors', :[] => nil))
|
254
|
+
@james.stub(:to_key).and_return(nil)
|
255
|
+
@james.stub(:persisted?).and_return(nil)
|
256
|
+
@james.stub(:name).and_return('James')
|
257
|
+
|
258
|
+
@alan = ::Author.new
|
259
|
+
@alan.stub(:to_label).and_return('James Shock')
|
260
|
+
@alan.stub(:login).and_return('james')
|
261
|
+
@alan.stub(:age).and_return(38)
|
262
|
+
@alan.stub(:id).and_return(75)
|
263
|
+
@alan.stub(:posts).and_return([])
|
264
|
+
@alan.stub(:post_ids).and_return([])
|
265
|
+
@alan.stub(:new_record?).and_return(false)
|
266
|
+
@alan.stub(:errors).and_return(double('errors', :[] => nil))
|
267
|
+
@alan.stub(:to_key).and_return(nil)
|
268
|
+
@alan.stub(:persisted?).and_return(nil)
|
269
|
+
@alan.stub(:name).and_return('James')
|
270
|
+
|
271
|
+
|
272
|
+
::Author.stub(:scoped).and_return(::Author)
|
273
|
+
::Author.stub(:find).and_return([@fred, @bob])
|
274
|
+
::Author.stub(:all).and_return([@fred, @bob])
|
275
|
+
::Author.stub(:where).and_return([@fred, @bob])
|
276
|
+
::Author.stub(:human_attribute_name).and_return { |column_name| column_name.humanize }
|
277
|
+
::Author.stub(:human_name).and_return('::Author')
|
278
|
+
::Author.stub(:reflect_on_association).and_return { |column_name| double('reflection', :options => {}, :klass => Post, :macro => :has_many) if column_name == :posts }
|
279
|
+
::Author.stub(:content_columns).and_return([double('column', :name => 'login'), double('column', :name => 'created_at')])
|
280
|
+
::Author.stub(:nested_attributes_options).and_return({:posts => {:allow_destroy => true, :update_only => false}})
|
281
|
+
::Author.class_eval do
|
282
|
+
def posts_attributes=(attributes)
|
283
|
+
# do nothing
|
284
|
+
end
|
285
|
+
end
|
286
|
+
::Author.stub(:accepts_nested_attributes_for)
|
287
|
+
::Author.stub(:to_key).and_return(nil)
|
288
|
+
::Author.stub(:persisted?).and_return(nil)
|
289
|
+
|
290
|
+
@hash_backed_author = HashBackedAuthor.new
|
291
|
+
|
292
|
+
# Sometimes we need a mock @post object and some Authors for belongs_to
|
293
|
+
@new_post = double('post')
|
294
|
+
@new_post.stub(:class).and_return(::Post)
|
295
|
+
@new_post.stub(:id).and_return(nil)
|
296
|
+
@new_post.stub(:new_record?).and_return(true)
|
297
|
+
@new_post.stub(:errors).and_return(double('errors', :[] => nil))
|
298
|
+
@new_post.stub(:author).and_return(nil)
|
299
|
+
@new_post.stub(:author_attributes=).and_return(nil)
|
300
|
+
@new_post.stub(:authors).and_return([@fred])
|
301
|
+
@new_post.stub(:authors_attributes=)
|
302
|
+
@new_post.stub(:reviewer).and_return(nil)
|
303
|
+
@new_post.stub(:main_post).and_return(nil)
|
304
|
+
@new_post.stub(:sub_posts).and_return([]) #TODO should be a mock with methods for adding sub posts
|
305
|
+
@new_post.stub(:to_key).and_return(nil)
|
306
|
+
@new_post.stub(:to_model).and_return(@new_post)
|
307
|
+
@new_post.stub(:persisted?).and_return(nil)
|
308
|
+
|
309
|
+
@freds_post = double('post')
|
310
|
+
@freds_post.stub(:to_ary)
|
311
|
+
@freds_post.stub(:class).and_return(::Post)
|
312
|
+
@freds_post.stub(:to_label).and_return('Fred Smith')
|
313
|
+
@freds_post.stub(:id).and_return(19)
|
314
|
+
@freds_post.stub(:title).and_return("Hello World")
|
315
|
+
@freds_post.stub(:author).and_return(@fred)
|
316
|
+
@freds_post.stub(:author_id).and_return(@fred.id)
|
317
|
+
@freds_post.stub(:authors).and_return([@fred])
|
318
|
+
@freds_post.stub(:author_ids).and_return([@fred.id])
|
319
|
+
@freds_post.stub(:new_record?).and_return(false)
|
320
|
+
@freds_post.stub(:errors).and_return(double('errors', :[] => nil))
|
321
|
+
@freds_post.stub(:to_key).and_return(nil)
|
322
|
+
@freds_post.stub(:persisted?).and_return(nil)
|
323
|
+
@fred.stub(:posts).and_return([@freds_post])
|
324
|
+
@fred.stub(:post_ids).and_return([@freds_post.id])
|
325
|
+
|
326
|
+
@alan_post1 = double('post')
|
327
|
+
@alan_post1.stub(:to_ary)
|
328
|
+
@alan_post1.stub(:class).and_return(::Post)
|
329
|
+
@alan_post1.stub(:to_label).and_return('Alan Smith 1')
|
330
|
+
@alan_post1.stub(:id).and_return(19)
|
331
|
+
@alan_post1.stub(:title).and_return("Hello World 1")
|
332
|
+
@alan_post1.stub(:body).and_return("Some Body 1")
|
333
|
+
@alan_post1.stub(:author).and_return(@fred)
|
334
|
+
@alan_post1.stub(:author_id).and_return(@fred.id)
|
335
|
+
@alan_post1.stub(:authors).and_return([@fred])
|
336
|
+
@alan_post1.stub(:author_ids).and_return([@fred.id])
|
337
|
+
@alan_post1.stub(:new_record?).and_return(false)
|
338
|
+
@alan_post1.stub(:errors).and_return(double('errors', :[] => nil))
|
339
|
+
@alan_post1.stub(:to_key).and_return(nil)
|
340
|
+
@alan_post1.stub(:persisted?).and_return(nil)
|
341
|
+
@alan_post1.stub(:recent).and_return(true)
|
342
|
+
|
343
|
+
@alan_post2 = double('post')
|
344
|
+
@alan_post2.stub(:to_ary)
|
345
|
+
@alan_post2.stub(:class).and_return(::Post)
|
346
|
+
@alan_post2.stub(:to_label).and_return('Alan Smith 2')
|
347
|
+
@alan_post2.stub(:id).and_return(19)
|
348
|
+
@alan_post2.stub(:title).and_return("Hello World 2")
|
349
|
+
@alan_post2.stub(:body).and_return("Some Body 2")
|
350
|
+
@alan_post2.stub(:author).and_return(@fred)
|
351
|
+
@alan_post2.stub(:author_id).and_return(@fred.id)
|
352
|
+
@alan_post2.stub(:authors).and_return([@fred])
|
353
|
+
@alan_post2.stub(:author_ids).and_return([@fred.id])
|
354
|
+
@alan_post2.stub(:new_record?).and_return(false)
|
355
|
+
@alan_post2.stub(:errors).and_return(double('errors', :[] => nil))
|
356
|
+
@alan_post2.stub(:to_key).and_return(nil)
|
357
|
+
@alan_post2.stub(:persisted?).and_return(nil)
|
358
|
+
@alan_post2.stub(:recent).and_return(true)
|
359
|
+
|
360
|
+
@alan.stub(:posts).and_return([@alan_post1, @alan_post2])
|
361
|
+
|
362
|
+
::Post.stub(:scoped).and_return(::Post)
|
363
|
+
::Post.stub(:human_attribute_name).and_return { |column_name| column_name.humanize }
|
364
|
+
::Post.stub(:human_name).and_return('Post')
|
365
|
+
::Post.stub(:reflect_on_all_validations).and_return([])
|
366
|
+
::Post.stub(:reflect_on_validations_for).and_return([])
|
367
|
+
::Post.stub(:reflections).and_return({})
|
368
|
+
::Post.stub(:reflect_on_association).and_return do |column_name|
|
369
|
+
case column_name
|
370
|
+
when :author, :author_status
|
371
|
+
mock = double('reflection', :options => {}, :klass => ::Author, :macro => :belongs_to)
|
372
|
+
mock.stub(:[]).with(:class_name).and_return("Author")
|
373
|
+
mock
|
374
|
+
when :reviewer
|
375
|
+
mock = double('reflection', :options => {:class_name => 'Author'}, :klass => ::Author, :macro => :belongs_to)
|
376
|
+
mock.stub(:[]).with(:class_name).and_return("Author")
|
377
|
+
mock
|
378
|
+
when :authors
|
379
|
+
double('reflection', :options => {}, :klass => ::Author, :macro => :has_and_belongs_to_many)
|
380
|
+
when :sub_posts
|
381
|
+
double('reflection', :options => {}, :klass => ::Post, :macro => :has_many)
|
382
|
+
when :main_post
|
383
|
+
double('reflection', :options => {}, :klass => ::Post, :macro => :belongs_to)
|
384
|
+
when :mongoid_reviewer
|
385
|
+
::MongoidReflectionMock.new('reflection',
|
386
|
+
:options => Proc.new { raise NoMethodError, "Mongoid has no reflection.options" },
|
387
|
+
:klass => ::Author, :macro => :referenced_in, :foreign_key => "reviewer_id") # custom id
|
388
|
+
end
|
389
|
+
end
|
390
|
+
::Post.stub(:find).and_return([@freds_post])
|
391
|
+
::Post.stub(:all).and_return([@freds_post])
|
392
|
+
::Post.stub(:where).and_return([@freds_post])
|
393
|
+
::Post.stub(:content_columns).and_return([double('column', :name => 'title'), double('column', :name => 'body'), double('column', :name => 'created_at')])
|
394
|
+
::Post.stub(:to_key).and_return(nil)
|
395
|
+
::Post.stub(:persisted?).and_return(nil)
|
396
|
+
::Post.stub(:to_ary)
|
397
|
+
|
398
|
+
::MongoPost.stub(:human_attribute_name).and_return { |column_name| column_name.humanize }
|
399
|
+
::MongoPost.stub(:human_name).and_return('MongoPost')
|
400
|
+
::MongoPost.stub(:associations).and_return({
|
401
|
+
:sub_posts => double('reflection', :options => {:polymorphic => true}, :klass => ::MongoPost, :macro => :has_many),
|
402
|
+
:options => []
|
403
|
+
})
|
404
|
+
::MongoPost.stub(:find).and_return([@freds_post])
|
405
|
+
::MongoPost.stub(:all).and_return([@freds_post])
|
406
|
+
::MongoPost.stub(:where).and_return([@freds_post])
|
407
|
+
::MongoPost.stub(:to_key).and_return(nil)
|
408
|
+
::MongoPost.stub(:persisted?).and_return(nil)
|
409
|
+
::MongoPost.stub(:to_ary)
|
410
|
+
::MongoPost.stub(:model_name).and_return( double(:model_name_mock, :singular => "post", :plural => "posts", :param_key => "post", :route_key => "posts") )
|
411
|
+
|
412
|
+
@new_mm_post = double('mm_post')
|
413
|
+
@new_mm_post.stub(:class).and_return(::MongoPost)
|
414
|
+
@new_mm_post.stub(:id).and_return(nil)
|
415
|
+
@new_mm_post.stub(:new_record?).and_return(true)
|
416
|
+
@new_mm_post.stub(:errors).and_return(double('errors', :[] => nil))
|
417
|
+
@new_mm_post.stub(:title).and_return("Hello World")
|
418
|
+
@new_mm_post.stub(:sub_posts).and_return([]) #TODO should be a mock with methods for adding sub posts
|
419
|
+
@new_mm_post.stub(:to_key).and_return(nil)
|
420
|
+
@new_mm_post.stub(:to_model).and_return(@new_mm_post)
|
421
|
+
@new_mm_post.stub(:persisted?).and_return(nil)
|
422
|
+
|
423
|
+
@mock_file = double('file')
|
424
|
+
Formtastic::FormBuilder.file_methods.each do |method|
|
425
|
+
@mock_file.stub(method).and_return(true)
|
426
|
+
end
|
427
|
+
|
428
|
+
@new_post.stub(:title)
|
429
|
+
@new_post.stub(:email)
|
430
|
+
@new_post.stub(:url)
|
431
|
+
@new_post.stub(:phone)
|
432
|
+
@new_post.stub(:search)
|
433
|
+
@new_post.stub(:to_ary)
|
434
|
+
@new_post.stub(:body)
|
435
|
+
@new_post.stub(:published)
|
436
|
+
@new_post.stub(:publish_at)
|
437
|
+
@new_post.stub(:created_at)
|
438
|
+
@new_post.stub(:secret).and_return(1)
|
439
|
+
@new_post.stub(:url)
|
440
|
+
@new_post.stub(:email)
|
441
|
+
@new_post.stub(:search)
|
442
|
+
@new_post.stub(:phone)
|
443
|
+
@new_post.stub(:time_zone)
|
444
|
+
@new_post.stub(:category_name)
|
445
|
+
@new_post.stub(:allow_comments).and_return(true)
|
446
|
+
@new_post.stub(:answer_comments)
|
447
|
+
@new_post.stub(:country)
|
448
|
+
@new_post.stub(:country_subdivision)
|
449
|
+
@new_post.stub(:country_code)
|
450
|
+
@new_post.stub(:document).and_return(@mock_file)
|
451
|
+
@new_post.stub(:column_for_attribute).with(:meta_description).and_return(double('column', :type => :string, :limit => 255))
|
452
|
+
@new_post.stub(:column_for_attribute).with(:title).and_return(double('column', :type => :string, :limit => 50))
|
453
|
+
@new_post.stub(:column_for_attribute).with(:body).and_return(double('column', :type => :text))
|
454
|
+
@new_post.stub(:column_for_attribute).with(:published).and_return(double('column', :type => :boolean))
|
455
|
+
@new_post.stub(:column_for_attribute).with(:publish_at).and_return(double('column', :type => :date))
|
456
|
+
@new_post.stub(:column_for_attribute).with(:time_zone).and_return(double('column', :type => :string))
|
457
|
+
@new_post.stub(:column_for_attribute).with(:allow_comments).and_return(double('column', :type => :boolean))
|
458
|
+
@new_post.stub(:column_for_attribute).with(:author).and_return(double('column', :type => :integer))
|
459
|
+
@new_post.stub(:column_for_attribute).with(:country).and_return(double('column', :type => :string, :limit => 255))
|
460
|
+
@new_post.stub(:column_for_attribute).with(:country_subdivision).and_return(double('column', :type => :string, :limit => 255))
|
461
|
+
@new_post.stub(:column_for_attribute).with(:country_code).and_return(double('column', :type => :string, :limit => 255))
|
462
|
+
@new_post.stub(:column_for_attribute).with(:email).and_return(double('column', :type => :string, :limit => 255))
|
463
|
+
@new_post.stub(:column_for_attribute).with(:url).and_return(double('column', :type => :string, :limit => 255))
|
464
|
+
@new_post.stub(:column_for_attribute).with(:phone).and_return(double('column', :type => :string, :limit => 255))
|
465
|
+
@new_post.stub(:column_for_attribute).with(:search).and_return(double('column', :type => :string, :limit => 255))
|
466
|
+
@new_post.stub(:column_for_attribute).with(:document).and_return(nil)
|
467
|
+
|
468
|
+
@new_post.stub(:author).and_return(@bob)
|
469
|
+
@new_post.stub(:author_id).and_return(@bob.id)
|
470
|
+
|
471
|
+
@new_post.stub(:reviewer).and_return(@fred)
|
472
|
+
@new_post.stub(:reviewer_id).and_return(@fred.id)
|
473
|
+
|
474
|
+
@new_post.stub(:publish_at=)
|
475
|
+
@new_post.stub(:title=)
|
476
|
+
@new_post.stub(:main_post_id).and_return(nil)
|
477
|
+
|
478
|
+
end
|
479
|
+
|
480
|
+
def self.included(base)
|
481
|
+
base.class_eval do
|
482
|
+
|
483
|
+
attr_accessor :output_buffer
|
484
|
+
|
485
|
+
def protect_against_forgery?
|
486
|
+
false
|
487
|
+
end
|
488
|
+
|
489
|
+
def _helpers
|
490
|
+
FakeHelpersModule
|
491
|
+
end
|
492
|
+
|
493
|
+
end
|
494
|
+
end
|
495
|
+
|
496
|
+
def with_config(config_method_name, value, &block)
|
497
|
+
old_value = Formtastic::FormBuilder.send(config_method_name)
|
498
|
+
Formtastic::FormBuilder.send(:"#{config_method_name}=", value)
|
499
|
+
yield
|
500
|
+
Formtastic::FormBuilder.send(:"#{config_method_name}=", old_value)
|
501
|
+
end
|
502
|
+
|
503
|
+
end
|
504
|
+
|
505
|
+
::ActiveSupport::Deprecation.silenced = false
|
506
|
+
|
507
|
+
RSpec.configure do |config|
|
508
|
+
config.before(:each) do
|
509
|
+
Formtastic::Localizer.cache.clear!
|
510
|
+
end
|
511
|
+
|
512
|
+
config.before(:all) do
|
513
|
+
DeferredGarbageCollection.start unless ENV["DEFER_GC"] == "false"
|
514
|
+
end
|
515
|
+
config.after(:all) do
|
516
|
+
DeferredGarbageCollection.reconsider unless ENV["DEFER_GC"] == "false"
|
517
|
+
end
|
518
|
+
end
|
519
|
+
|
520
|
+
end
|
521
|
+
|
522
|
+
# --- Instructions ---
|
523
|
+
# Sort the contents of this file into a Spork.prefork and a Spork.each_run
|
524
|
+
# block.
|
525
|
+
#
|
526
|
+
# The Spork.prefork block is run only once when the spork server is started.
|
527
|
+
# You typically want to place most of your (slow) initializer code in here, in
|
528
|
+
# particular, require'ing any 3rd-party gems that you don't normally modify
|
529
|
+
# during development.
|
530
|
+
#
|
531
|
+
# The Spork.each_run block is run each time you run your specs. In case you
|
532
|
+
# need to load files that tend to change during development, require them here.
|
533
|
+
# With Rails, your application modules are loaded automatically, so sometimes
|
534
|
+
# this block can remain empty.
|
535
|
+
#
|
536
|
+
# Note: You can modify files loaded *from* the Spork.each_run block without
|
537
|
+
# restarting the spork server. However, this file itself will not be reloaded,
|
538
|
+
# so if you change any of the code inside the each_run block, you still need to
|
539
|
+
# restart the server. In general, if you have non-trivial code in this file,
|
540
|
+
# it's advisable to move it into a separate file so you can easily edit it
|
541
|
+
# without restarting spork. (For example, with RSpec, you could move
|
542
|
+
# non-trivial code into a file spec/support/my_helper.rb, making sure that the
|
543
|
+
# spec/support/* files are require'd from inside the each_run block.)
|
544
|
+
#
|
545
|
+
# Any code that is left outside the two blocks will be run during preforking
|
546
|
+
# *and* during each_run -- that's probably not what you want.
|
547
|
+
#
|
548
|
+
# These instructions should self-destruct in 10 seconds. If they don't, feel
|
549
|
+
# free to delete them.
|
550
|
+
|
551
|
+
|
552
|
+
|
553
|
+
|