Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 554 lines (466 sloc) 20.253 kb
0a59e0c @yabawock Always use # encoding: utf-8 declaration
yabawock authored
1 # encoding: utf-8
281dd18 @xaviershay rspec support - test_helper and rake task
xaviershay authored
2 require 'rubygems'
152f04e @sobrinho Use `require 'bundler/setup'` instead of calling Bundler.setup manually
sobrinho authored
3 require 'bundler/setup'
9604949 @justinfrench smart_require is tripping up the CI build, and also tripped me up a few ...
authored
4 require 'active_support'
5 require 'action_pack'
6 require 'action_view'
7 require 'action_controller'
f7d9cfd @justinfrench A bunch of Rails 3.1 compatability stuff for #564
authored
8 require 'action_dispatch'
542d308 @grimen Fixing some issues with the specs to get them to run on Ruby 1.9.x. Spec...
grimen authored
9
fe63045 @yabawock Use HTML safe strings in tests
yabawock authored
10 require File.expand_path(File.join(File.dirname(__FILE__), '../lib/formtastic/util'))
b86266e @yabawock Separate test environment setup and misc setup blocks into spec/support ...
yabawock authored
11 require File.expand_path(File.join(File.dirname(__FILE__), '../lib/formtastic'))
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
12
bdc68e1 @twalpole update to rspec-rails 2.14
twalpole authored
13 #rspec-rails 2-14 assumes a full rails install
14 module Rails
15 module VERSION
16 include ActionPack::VERSION
17 end
18 end
19
392cdfa @alexrothenberg added generator specs using ammeter gem
alexrothenberg authored
20 require 'ammeter/init'
21
b86266e @yabawock Separate test environment setup and misc setup blocks into spec/support ...
yabawock authored
22 # Requires supporting files with custom matchers and macros, etc,
2c68cd3 @huerlisi Sort list of files to require in spec helper.
huerlisi authored
23 # in ./support/ and its subdirectories in alphabetic order.
24 Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each {|f| require f}
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
25
99ba14f @justinfrench only config I18n if the method is defined (unsure why this came up here)
authored
26 I18n.enforce_available_locales = false if I18n.respond_to?(:enforce_available_locales)
60d763a @justinfrench Set I18n.enforce_available_locales = false:
authored
27
f7d9cfd @justinfrench A bunch of Rails 3.1 compatability stuff for #564
authored
28 module FakeHelpersModule
29 end
30
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
31 module FormtasticSpecHelper
82f6c8d @justinfrench Fixes deprecation warnings with form_for(:name, @resource) in rails3 (#2...
authored
32 include ActionPack
b88bd5b @yabawock Changed spec_helper to allow for Rails 3 / Rspec 2 environment
yabawock authored
33 include ActionView::Context if defined?(ActionView::Context)
e411fe1 @twalpole enable tests to pass on rails edge
twalpole authored
34 include ActionController::RecordIdentifier if defined?(ActionController::RecordIdentifier)
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
35 include ActionView::Helpers::FormHelper
36 include ActionView::Helpers::FormTagHelper
37 include ActionView::Helpers::FormOptionsHelper
38 include ActionView::Helpers::UrlHelper
39 include ActionView::Helpers::TagHelper
40 include ActionView::Helpers::TextHelper
b88bd5b @yabawock Changed spec_helper to allow for Rails 3 / Rspec 2 environment
yabawock authored
41 include ActionView::Helpers::ActiveRecordHelper if defined?(ActionView::Helpers::ActiveRecordHelper)
42 include ActionView::Helpers::ActiveModelHelper if defined?(ActionView::Helpers::ActiveModelHelper)
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
43 include ActionView::Helpers::DateHelper
44 include ActionView::Helpers::CaptureHelper
127a6b9 @justinfrench Added a Formtastic::LayoutHelper with formtastic_stylesheets so that we ...
authored
45 include ActionView::Helpers::AssetTagHelper
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
46 include ActiveSupport
229eb53 @yabawock Make testsuite work with Rails 3.0.0.rc and RSpec 2.0.0.beta19
yabawock authored
47 include ActionController::PolymorphicRoutes if defined?(ActionController::PolymorphicRoutes)
a22b424 @twalpole updates for rails 4 compatability
twalpole authored
48 include ActionDispatch::Routing::PolymorphicRoutes
49 include AbstractController::UrlFor if defined?(AbstractController::UrlFor)
50 include ActionView::RecordIdentifier if defined?(ActionView::RecordIdentifier)
51
549ef7a @justinfrench Renamed all instances of Formtastic::SemanticFormBuilder to Formtastic::...
authored
52 include Formtastic::Helpers::FormHelper
433dae2 @yabawock Whitespace Cleanup
yabawock authored
53
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
54 def default_input_type(column_type, column_name = :generic_column_name)
bdc68e1 @twalpole update to rspec-rails 2.14
twalpole authored
55 @new_post.stub(column_name)
56 @new_post.stub(:column_for_attribute).and_return(double('column', :type => column_type)) unless column_type.nil?
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
57
58 semantic_form_for(@new_post) do |builder|
59 @default_type = builder.send(:default_input_type, column_name)
60 end
61
62 return @default_type
63 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
64
98ceff5 @koppen Automatically set maxlength if object is an ActiveModel and the fields m...
koppen authored
65 def active_model_validator(kind, attributes, options = {})
bdc68e1 @twalpole update to rspec-rails 2.14
twalpole authored
66 validator = double("ActiveModel::Validations::#{kind.to_s.titlecase}Validator", :attributes => attributes, :options => options)
67 validator.stub(:kind).and_return(kind)
98ceff5 @koppen Automatically set maxlength if object is an ActiveModel and the fields m...
koppen authored
68 validator
69 end
70
2769784 @tetsuo692 add active_model_presence_validator helper and clean up test
tetsuo692 authored
71 def active_model_presence_validator(attributes, options = {})
98ceff5 @koppen Automatically set maxlength if object is an ActiveModel and the fields m...
koppen authored
72 active_model_validator(:presence, attributes, options)
2769784 @tetsuo692 add active_model_presence_validator helper and clean up test
tetsuo692 authored
73 end
98ceff5 @koppen Automatically set maxlength if object is an ActiveModel and the fields m...
koppen authored
74
75 def active_model_length_validator(attributes, options = {})
76 active_model_validator(:length, attributes, options)
77 end
78
e38a068 @sobrinho Spec for last commit
sobrinho authored
79 def active_model_inclusion_validator(attributes, options = {})
80 active_model_validator(:inclusion, attributes, options)
d6e6265 @justinfrench NumericInput now provides default min, max and step attributes by reflec...
authored
81 end
70986a2 @eneagoe collection_from_association now works with Proc conditions for the assoc...
eneagoe authored
82
d6e6265 @justinfrench NumericInput now provides default min, max and step attributes by reflec...
authored
83 def active_model_numericality_validator(attributes, options = {})
84 active_model_validator(:numericality, attributes, options)
e38a068 @sobrinho Spec for last commit
sobrinho authored
85 end
86
c6c6d2b @ijonas specs for support of polymorphic association checking on top of MongoMap...
ijonas authored
87 class ::MongoPost
88 include MongoMapper::Document if defined?(MongoMapper::Document)
89
90 def id
91 end
92
93 def persisted?
94 end
95 end
96
97
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
98 class ::Post
b88bd5b @yabawock Changed spec_helper to allow for Rails 3 / Rspec 2 environment
yabawock authored
99 extend ActiveModel::Naming if defined?(ActiveModel::Naming)
100 include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
101
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
102 def id
103 end
b88bd5b @yabawock Changed spec_helper to allow for Rails 3 / Rspec 2 environment
yabawock authored
104
105 def persisted?
106 end
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
107 end
70986a2 @eneagoe collection_from_association now works with Proc conditions for the assoc...
eneagoe authored
108
d33fad4 @akaspick Fix incorrect html class name being generated for namespaced objects.
akaspick authored
109 module ::Namespaced
110 class Post
b88bd5b @yabawock Changed spec_helper to allow for Rails 3 / Rspec 2 environment
yabawock authored
111 extend ActiveModel::Naming if defined?(ActiveModel::Naming)
112 include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
113
d33fad4 @akaspick Fix incorrect html class name being generated for namespaced objects.
akaspick authored
114 def id
115 end
b88bd5b @yabawock Changed spec_helper to allow for Rails 3 / Rspec 2 environment
yabawock authored
116
117 def persisted?
118 end
d33fad4 @akaspick Fix incorrect html class name being generated for namespaced objects.
akaspick authored
119 end
120 end
70986a2 @eneagoe collection_from_association now works with Proc conditions for the assoc...
eneagoe authored
121
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
122 class ::Author
b88bd5b @yabawock Changed spec_helper to allow for Rails 3 / Rspec 2 environment
yabawock authored
123 extend ActiveModel::Naming if defined?(ActiveModel::Naming)
124 include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
125
33a5d23 Added :group_by option to select input (issue #54)
Jeroen van Dijk authored
126 def to_label
127 end
70986a2 @eneagoe collection_from_association now works with Proc conditions for the assoc...
eneagoe authored
128
f7d9cfd @justinfrench A bunch of Rails 3.1 compatability stuff for #564
authored
129 def persisted?
130 end
33a5d23 Added :group_by option to select input (issue #54)
Jeroen van Dijk authored
131 end
70986a2 @eneagoe collection_from_association now works with Proc conditions for the assoc...
eneagoe authored
132
131f350 @justinfrench Fix bug when simple_fields_for is used with a hask like model
authored
133 class ::HashBackedAuthor < Hash
134 extend ActiveModel::Naming if defined?(ActiveModel::Naming)
135 include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
136 def persisted?; false; end
137 def name
138 'hash backed author'
139 end
140 end
70986a2 @eneagoe collection_from_association now works with Proc conditions for the assoc...
eneagoe authored
141
33a5d23 Added :group_by option to select input (issue #54)
Jeroen van Dijk authored
142 class ::Continent
b88bd5b @yabawock Changed spec_helper to allow for Rails 3 / Rspec 2 environment
yabawock authored
143 extend ActiveModel::Naming if defined?(ActiveModel::Naming)
144 include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
145 end
70986a2 @eneagoe collection_from_association now works with Proc conditions for the assoc...
eneagoe authored
146
506182b @yabawock Make ActiveModel Tests work without relying on RSpec unstub!
yabawock authored
147 class ::PostModel
148 extend ActiveModel::Naming if defined?(ActiveModel::Naming)
149 include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
150 end
70986a2 @eneagoe collection_from_association now works with Proc conditions for the assoc...
eneagoe authored
151
a09a6db @rgarner Fix for #740 - Mongoid belongs_to select raises NoMethodError and always...
rgarner authored
152 ##
153 # We can't mock :respond_to?, so we need a concrete class override
699ec26 @justinfrench address rspec deprecation warnings fixes #1076
authored
154 class ::MongoidReflectionMock < RSpec::Mocks::Double
a09a6db @rgarner Fix for #740 - Mongoid belongs_to select raises NoMethodError and always...
rgarner authored
155 def initialize(name=nil, stubs_and_options={})
156 super name, stubs_and_options
157 end
158
159 def respond_to?(sym)
160 sym == :options ? false : super
161 end
162 end
25131db @justinfrench Model.all spec changes for Rails 4
authored
163
164 # In Rails 3 Model.all returns an array. In Rails 4, it returns an
165 # association proxy, which quacks a lot like an array. We use this in stubs
166 # or mocks where we need to return the later.
167 #
168 # TODO try delegate?
169 # delegate :map, :size, :length, :first, :to_ary, :each, :include?, :to => :array
170 class MockScope
171 attr_reader :array
172
173 def initialize(the_array)
174 @array = the_array
175 end
176
5380f8f @twalpole Pass block through MockScope#each and #map
twalpole authored
177 def map(&block)
178 array.map(&block)
25131db @justinfrench Model.all spec changes for Rails 4
authored
179 end
180
181 def where(*args)
3f0e4f8 @twalpole include not supported as parameter to where for rails 4
twalpole authored
182 # array
183 self
184 end
185
186 def includes(*args)
187 self
25131db @justinfrench Model.all spec changes for Rails 4
authored
188 end
189
190 def size
191 array.size
192 end
193 alias_method :length, :size
194
195 def first
196 array.first
197 end
198
199 def to_ary
200 array
201 end
202
5380f8f @twalpole Pass block through MockScope#each and #map
twalpole authored
203 def each(&block)
204 array.each(&block)
25131db @justinfrench Model.all spec changes for Rails 4
authored
205 end
206
207 def include?(*args)
208 array.include?(*args)
209 end
210 end
a09a6db @rgarner Fix for #740 - Mongoid belongs_to select raises NoMethodError and always...
rgarner authored
211
f7d9cfd @justinfrench A bunch of Rails 3.1 compatability stuff for #564
authored
212 def _routes
bdc68e1 @twalpole update to rspec-rails 2.14
twalpole authored
213 url_helpers = double('url_helpers')
214 url_helpers.stub(:hash_for_posts_path).and_return({})
215 url_helpers.stub(:hash_for_post_path).and_return({})
216 url_helpers.stub(:hash_for_post_models_path).and_return({})
217 url_helpers.stub(:hash_for_authors_path).and_return({})
70986a2 @eneagoe collection_from_association now works with Proc conditions for the assoc...
eneagoe authored
218
bdc68e1 @twalpole update to rspec-rails 2.14
twalpole authored
219 double('_routes',
f7d9cfd @justinfrench A bunch of Rails 3.1 compatability stuff for #564
authored
220 :url_helpers => url_helpers,
221 :url_for => "/mock/path"
222 )
223 end
70986a2 @eneagoe collection_from_association now works with Proc conditions for the assoc...
eneagoe authored
224
f7d9cfd @justinfrench A bunch of Rails 3.1 compatability stuff for #564
authored
225 def controller
bdc68e1 @twalpole update to rspec-rails 2.14
twalpole authored
226 env = double('env', :[] => nil)
227 request = double('request', :env => env)
228 double('controller', :controller_path= => '', :params => {}, :request => request)
f7d9cfd @justinfrench A bunch of Rails 3.1 compatability stuff for #564
authored
229 end
70986a2 @eneagoe collection_from_association now works with Proc conditions for the assoc...
eneagoe authored
230
f7d9cfd @justinfrench A bunch of Rails 3.1 compatability stuff for #564
authored
231 def default_url_options
232 {}
233 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
234
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
235 def mock_everything
433dae2 @yabawock Whitespace Cleanup
yabawock authored
236
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
237 # Resource-oriented styles like form_for(@post) will expect a path method for the object,
238 # so we're defining some here.
8b8e86c @justinfrench fix epic failing tests under Rails 3.1.0.rc5 due to our fake URL helpers...
authored
239 def post_models_path(*args); "/postmodels/1"; end
506182b @yabawock Make ActiveModel Tests work without relying on RSpec unstub!
yabawock authored
240
8b8e86c @justinfrench fix epic failing tests under Rails 3.1.0.rc5 due to our fake URL helpers...
authored
241 def post_path(*args); "/posts/1"; end
242 def posts_path(*args); "/posts"; end
243 def new_post_path(*args); "/posts/new"; end
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
244
8b8e86c @justinfrench fix epic failing tests under Rails 3.1.0.rc5 due to our fake URL helpers...
authored
245 def author_path(*args); "/authors/1"; end
246 def authors_path(*args); "/authors"; end
247 def new_author_path(*args); "/authors/new"; end
25131db @justinfrench Model.all spec changes for Rails 4
authored
248
249 # Returns the array for Rails 3 and a thing that looks looks like an
250 # association proxy for Rails 4+
251 def author_array_or_scope(the_array = [@fred, @bob])
252 if ::Formtastic::Util.rails3?
253 the_array
254 else
255 MockScope.new(the_array)
256 end
257 end
258
4fcd1e8 @lardawge Use real object to get specs passing in ruby 192
lardawge authored
259 @fred = ::Author.new
bdc68e1 @twalpole update to rspec-rails 2.14
twalpole authored
260 @fred.stub(:class).and_return(::Author)
261 @fred.stub(:to_label).and_return('Fred Smith')
262 @fred.stub(:login).and_return('fred_smith')
263 @fred.stub(:age).and_return(27)
264 @fred.stub(:id).and_return(37)
265 @fred.stub(:new_record?).and_return(false)
266 @fred.stub(:errors).and_return(double('errors', :[] => nil))
267 @fred.stub(:to_key).and_return(nil)
268 @fred.stub(:persisted?).and_return(nil)
269 @fred.stub(:name).and_return('Fred')
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
270
4fcd1e8 @lardawge Use real object to get specs passing in ruby 192
lardawge authored
271 @bob = ::Author.new
bdc68e1 @twalpole update to rspec-rails 2.14
twalpole authored
272 @bob.stub(:to_label).and_return('Bob Rock')
273 @bob.stub(:login).and_return('bob')
274 @bob.stub(:age).and_return(43)
275 @bob.stub(:created_at)
276 @bob.stub(:id).and_return(42)
277 @bob.stub(:posts).and_return([])
278 @bob.stub(:post_ids).and_return([])
279 @bob.stub(:new_record?).and_return(false)
280 @bob.stub(:errors).and_return(double('errors', :[] => nil))
281 @bob.stub(:to_key).and_return(nil)
282 @bob.stub(:persisted?).and_return(nil)
283 @bob.stub(:name).and_return('Bob')
433dae2 @yabawock Whitespace Cleanup
yabawock authored
284
4fcd1e8 @lardawge Use real object to get specs passing in ruby 192
lardawge authored
285 @james = ::Author.new
bdc68e1 @twalpole update to rspec-rails 2.14
twalpole authored
286 @james.stub(:to_label).and_return('James Shock')
287 @james.stub(:login).and_return('james')
288 @james.stub(:age).and_return(38)
289 @james.stub(:id).and_return(75)
290 @james.stub(:posts).and_return([])
291 @james.stub(:post_ids).and_return([])
292 @james.stub(:new_record?).and_return(false)
293 @james.stub(:errors).and_return(double('errors', :[] => nil))
294 @james.stub(:to_key).and_return(nil)
295 @james.stub(:persisted?).and_return(nil)
296 @james.stub(:name).and_return('James')
297
298
299 ::Author.stub(:scoped).and_return(::Author)
300 ::Author.stub(:find).and_return(author_array_or_scope)
301 ::Author.stub(:all).and_return(author_array_or_scope)
302 ::Author.stub(:where).and_return(author_array_or_scope)
699ec26 @justinfrench address rspec deprecation warnings fixes #1076
authored
303 ::Author.stub(:human_attribute_name) { |column_name| column_name.humanize }
bdc68e1 @twalpole update to rspec-rails 2.14
twalpole authored
304 ::Author.stub(:human_name).and_return('::Author')
699ec26 @justinfrench address rspec deprecation warnings fixes #1076
authored
305 ::Author.stub(:reflect_on_association) { |column_name| double('reflection', :options => {}, :klass => Post, :macro => :has_many) if column_name == :posts }
bdc68e1 @twalpole update to rspec-rails 2.14
twalpole authored
306 ::Author.stub(:content_columns).and_return([double('column', :name => 'login'), double('column', :name => 'created_at')])
307 ::Author.stub(:to_key).and_return(nil)
308 ::Author.stub(:persisted?).and_return(nil)
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
309
131f350 @justinfrench Fix bug when simple_fields_for is used with a hask like model
authored
310 @hash_backed_author = HashBackedAuthor.new
70986a2 @eneagoe collection_from_association now works with Proc conditions for the assoc...
eneagoe authored
311
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
312 # Sometimes we need a mock @post object and some Authors for belongs_to
bdc68e1 @twalpole update to rspec-rails 2.14
twalpole authored
313 @new_post = double('post')
314 @new_post.stub(:class).and_return(::Post)
315 @new_post.stub(:id).and_return(nil)
316 @new_post.stub(:new_record?).and_return(true)
317 @new_post.stub(:errors).and_return(double('errors', :[] => nil))
318 @new_post.stub(:author).and_return(nil)
319 @new_post.stub(:author_attributes=).and_return(nil)
320 @new_post.stub(:authors).and_return(author_array_or_scope([@fred]))
321 @new_post.stub(:authors_attributes=)
322 @new_post.stub(:reviewer).and_return(nil)
323 @new_post.stub(:main_post).and_return(nil)
324 @new_post.stub(:sub_posts).and_return([]) #TODO should be a mock with methods for adding sub posts
325 @new_post.stub(:to_key).and_return(nil)
326 @new_post.stub(:to_model).and_return(@new_post)
327 @new_post.stub(:persisted?).and_return(nil)
d488bb1 @twalpole gem updates and mock additions needed to get the tests to pass on edge r...
twalpole authored
328 @new_post.stub(:model_name){ @new_post.class.model_name}
bdc68e1 @twalpole update to rspec-rails 2.14
twalpole authored
329
330 @freds_post = double('post')
331 @freds_post.stub(:to_ary)
332 @freds_post.stub(:class).and_return(::Post)
333 @freds_post.stub(:to_label).and_return('Fred Smith')
334 @freds_post.stub(:id).and_return(19)
335 @freds_post.stub(:title).and_return("Hello World")
336 @freds_post.stub(:author).and_return(@fred)
337 @freds_post.stub(:author_id).and_return(@fred.id)
338 @freds_post.stub(:authors).and_return([@fred])
339 @freds_post.stub(:author_ids).and_return([@fred.id])
340 @freds_post.stub(:new_record?).and_return(false)
341 @freds_post.stub(:errors).and_return(double('errors', :[] => nil))
342 @freds_post.stub(:to_key).and_return(nil)
343 @freds_post.stub(:persisted?).and_return(nil)
d488bb1 @twalpole gem updates and mock additions needed to get the tests to pass on edge r...
twalpole authored
344 @freds_post.stub(:model_name){ @freds_post.class.model_name}
345 @freds_post.stub(:to_model).and_return(@freds_post)
bdc68e1 @twalpole update to rspec-rails 2.14
twalpole authored
346 @fred.stub(:posts).and_return(author_array_or_scope([@freds_post]))
347 @fred.stub(:post_ids).and_return([@freds_post.id])
348
349 ::Post.stub(:scoped).and_return(::Post)
699ec26 @justinfrench address rspec deprecation warnings fixes #1076
authored
350 ::Post.stub(:human_attribute_name) { |column_name| column_name.humanize }
bdc68e1 @twalpole update to rspec-rails 2.14
twalpole authored
351 ::Post.stub(:human_name).and_return('Post')
352 ::Post.stub(:reflect_on_all_validations).and_return([])
353 ::Post.stub(:reflect_on_validations_for).and_return([])
354 ::Post.stub(:reflections).and_return({})
699ec26 @justinfrench address rspec deprecation warnings fixes #1076
authored
355 ::Post.stub(:reflect_on_association) { |column_name|
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
356 case column_name
357 when :author, :author_status
bdc68e1 @twalpole update to rspec-rails 2.14
twalpole authored
358 mock = double('reflection', :options => {}, :klass => ::Author, :macro => :belongs_to)
359 mock.stub(:[]).with(:class_name).and_return("Author")
33a5d23 Added :group_by option to select input (issue #54)
Jeroen van Dijk authored
360 mock
2814011 @yabawock Merge branch 'master' into rails3
yabawock authored
361 when :reviewer
bdc68e1 @twalpole update to rspec-rails 2.14
twalpole authored
362 mock = double('reflection', :options => {:class_name => 'Author'}, :klass => ::Author, :macro => :belongs_to)
363 mock.stub(:[]).with(:class_name).and_return("Author")
74eaf33 @gpetrica added test case for model that has 2 belongs_to fields pointing to same ...
gpetrica authored
364 mock
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
365 when :authors
bdc68e1 @twalpole update to rspec-rails 2.14
twalpole authored
366 double('reflection', :options => {}, :klass => ::Author, :macro => :has_and_belongs_to_many)
9c1daba Added regression spec for a belongs_to association with :group_by => :au...
Jacob Kjeldahl authored
367 when :sub_posts
bdc68e1 @twalpole update to rspec-rails 2.14
twalpole authored
368 double('reflection', :options => {}, :klass => ::Post, :macro => :has_many)
9c1daba Added regression spec for a belongs_to association with :group_by => :au...
Jacob Kjeldahl authored
369 when :main_post
bdc68e1 @twalpole update to rspec-rails 2.14
twalpole authored
370 double('reflection', :options => {}, :klass => ::Post, :macro => :belongs_to)
fb643c7 spec for mongoid references fix
smix authored
371 when :mongoid_reviewer
a09a6db @rgarner Fix for #740 - Mongoid belongs_to select raises NoMethodError and always...
rgarner authored
372 ::MongoidReflectionMock.new('reflection',
373 :options => Proc.new { raise NoMethodError, "Mongoid has no reflection.options" },
374 :klass => ::Author, :macro => :referenced_in, :foreign_key => "reviewer_id") # custom id
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
375 end
699ec26 @justinfrench address rspec deprecation warnings fixes #1076
authored
376 }
bdc68e1 @twalpole update to rspec-rails 2.14
twalpole authored
377 ::Post.stub(:find).and_return(author_array_or_scope([@freds_post]))
378 ::Post.stub(:all).and_return(author_array_or_scope([@freds_post]))
379 ::Post.stub(:where).and_return(author_array_or_scope([@freds_post]))
380 ::Post.stub(:content_columns).and_return([double('column', :name => 'title'), double('column', :name => 'body'), double('column', :name => 'created_at')])
381 ::Post.stub(:to_key).and_return(nil)
382 ::Post.stub(:persisted?).and_return(nil)
383 ::Post.stub(:to_ary)
384
699ec26 @justinfrench address rspec deprecation warnings fixes #1076
authored
385 ::MongoPost.stub(:human_attribute_name) { |column_name| column_name.humanize }
bdc68e1 @twalpole update to rspec-rails 2.14
twalpole authored
386 ::MongoPost.stub(:human_name).and_return('MongoPost')
387 ::MongoPost.stub(:associations).and_return({
388 :sub_posts => double('reflection', :options => {:polymorphic => true}, :klass => ::MongoPost, :macro => :has_many),
6034e77 @hypomodern this should fix the remaining problems.
hypomodern authored
389 :options => []
390 })
bdc68e1 @twalpole update to rspec-rails 2.14
twalpole authored
391 ::MongoPost.stub(:find).and_return(author_array_or_scope([@freds_post]))
392 ::MongoPost.stub(:all).and_return(author_array_or_scope([@freds_post]))
393 ::MongoPost.stub(:where).and_return(author_array_or_scope([@freds_post]))
394 ::MongoPost.stub(:to_key).and_return(nil)
395 ::MongoPost.stub(:persisted?).and_return(nil)
396 ::MongoPost.stub(:to_ary)
397 ::MongoPost.stub(:model_name).and_return( double(:model_name_mock, :singular => "post", :plural => "posts", :param_key => "post", :route_key => "posts") )
398
399 @new_mm_post = double('mm_post')
400 @new_mm_post.stub(:class).and_return(::MongoPost)
401 @new_mm_post.stub(:id).and_return(nil)
402 @new_mm_post.stub(:new_record?).and_return(true)
403 @new_mm_post.stub(:errors).and_return(double('errors', :[] => nil))
404 @new_mm_post.stub(:title).and_return("Hello World")
405 @new_mm_post.stub(:sub_posts).and_return([]) #TODO should be a mock with methods for adding sub posts
406 @new_mm_post.stub(:to_key).and_return(nil)
407 @new_mm_post.stub(:to_model).and_return(@new_mm_post)
408 @new_mm_post.stub(:persisted?).and_return(nil)
d488bb1 @twalpole gem updates and mock additions needed to get the tests to pass on edge r...
twalpole authored
409 @new_mm_post.stub(:model_name).and_return(::MongoPost.model_name)
bdc68e1 @twalpole update to rspec-rails 2.14
twalpole authored
410
411 @mock_file = double('file')
549ef7a @justinfrench Renamed all instances of Formtastic::SemanticFormBuilder to Formtastic::...
authored
412 Formtastic::FormBuilder.file_methods.each do |method|
bdc68e1 @twalpole update to rspec-rails 2.14
twalpole authored
413 @mock_file.stub(method).and_return(true)
deb9f9b @asanghi automatic deduction of errors related to file type fields
asanghi authored
414 end
415
bdc68e1 @twalpole update to rspec-rails 2.14
twalpole authored
416 @new_post.stub(:title)
417 @new_post.stub(:email)
418 @new_post.stub(:url)
419 @new_post.stub(:phone)
420 @new_post.stub(:search)
421 @new_post.stub(:to_ary)
422 @new_post.stub(:body)
423 @new_post.stub(:published)
424 @new_post.stub(:publish_at)
425 @new_post.stub(:created_at)
426 @new_post.stub(:secret).and_return(1)
427 @new_post.stub(:url)
428 @new_post.stub(:email)
102f58d @pipt Add support for :as => :color to input fields.
pipt authored
429 @new_post.stub(:color)
bdc68e1 @twalpole update to rspec-rails 2.14
twalpole authored
430 @new_post.stub(:search)
431 @new_post.stub(:phone)
432 @new_post.stub(:time_zone)
433 @new_post.stub(:category_name)
434 @new_post.stub(:allow_comments).and_return(true)
435 @new_post.stub(:answer_comments)
436 @new_post.stub(:country)
437 @new_post.stub(:country_subdivision)
438 @new_post.stub(:country_code)
439 @new_post.stub(:document).and_return(@mock_file)
440 @new_post.stub(:column_for_attribute).with(:meta_description).and_return(double('column', :type => :string, :limit => 255))
441 @new_post.stub(:column_for_attribute).with(:title).and_return(double('column', :type => :string, :limit => 50))
442 @new_post.stub(:column_for_attribute).with(:body).and_return(double('column', :type => :text))
443 @new_post.stub(:column_for_attribute).with(:published).and_return(double('column', :type => :boolean))
444 @new_post.stub(:column_for_attribute).with(:publish_at).and_return(double('column', :type => :date))
445 @new_post.stub(:column_for_attribute).with(:time_zone).and_return(double('column', :type => :string))
446 @new_post.stub(:column_for_attribute).with(:allow_comments).and_return(double('column', :type => :boolean))
447 @new_post.stub(:column_for_attribute).with(:author).and_return(double('column', :type => :integer))
448 @new_post.stub(:column_for_attribute).with(:country).and_return(double('column', :type => :string, :limit => 255))
449 @new_post.stub(:column_for_attribute).with(:country_subdivision).and_return(double('column', :type => :string, :limit => 255))
450 @new_post.stub(:column_for_attribute).with(:country_code).and_return(double('column', :type => :string, :limit => 255))
451 @new_post.stub(:column_for_attribute).with(:email).and_return(double('column', :type => :string, :limit => 255))
102f58d @pipt Add support for :as => :color to input fields.
pipt authored
452 @new_post.stub(:column_for_attribute).with(:color).and_return(double('column', :type => :string, :limit => 255))
bdc68e1 @twalpole update to rspec-rails 2.14
twalpole authored
453 @new_post.stub(:column_for_attribute).with(:url).and_return(double('column', :type => :string, :limit => 255))
454 @new_post.stub(:column_for_attribute).with(:phone).and_return(double('column', :type => :string, :limit => 255))
455 @new_post.stub(:column_for_attribute).with(:search).and_return(double('column', :type => :string, :limit => 255))
456 @new_post.stub(:column_for_attribute).with(:document).and_return(nil)
457
458 @new_post.stub(:author).and_return(@bob)
459 @new_post.stub(:author_id).and_return(@bob.id)
460
461 @new_post.stub(:reviewer).and_return(@fred)
462 @new_post.stub(:reviewer_id).and_return(@fred.id)
463
464 # @new_post.should_receive(:publish_at=).at_least(:once)
465 @new_post.stub(:publish_at=)
466 # @new_post.should_receive(:title=).at_least(:once)
467 @new_post.stub(:title=)
468 @new_post.stub(:main_post_id).and_return(nil)
433dae2 @yabawock Whitespace Cleanup
yabawock authored
469
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
470 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
471
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
472 def self.included(base)
473 base.class_eval do
433dae2 @yabawock Whitespace Cleanup
yabawock authored
474
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
475 attr_accessor :output_buffer
433dae2 @yabawock Whitespace Cleanup
yabawock authored
476
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
477 def protect_against_forgery?
478 false
479 end
70986a2 @eneagoe collection_from_association now works with Proc conditions for the assoc...
eneagoe authored
480
f7d9cfd @justinfrench A bunch of Rails 3.1 compatability stuff for #564
authored
481 def _helpers
482 FakeHelpersModule
483 end
70986a2 @eneagoe collection_from_association now works with Proc conditions for the assoc...
eneagoe authored
484
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
485 end
486 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
487
ffa9e37 @justinfrench Added a with_config method for specs.
authored
488 def with_config(config_method_name, value, &block)
549ef7a @justinfrench Renamed all instances of Formtastic::SemanticFormBuilder to Formtastic::...
authored
489 old_value = Formtastic::FormBuilder.send(config_method_name)
490 Formtastic::FormBuilder.send(:"#{config_method_name}=", value)
ffa9e37 @justinfrench Added a with_config method for specs.
authored
491 yield
549ef7a @justinfrench Renamed all instances of Formtastic::SemanticFormBuilder to Formtastic::...
authored
492 Formtastic::FormBuilder.send(:"#{config_method_name}=", old_value)
ffa9e37 @justinfrench Added a with_config method for specs.
authored
493 end
f39d1bd @twalpole Revert "Revert "Merge pull request #820 from twalpole/rails4""
twalpole authored
494
495 class ToSMatcher
496 def initialize(str)
497 @str=str.to_s
498 end
499
500 def matches?(value)
501 value.to_s==@str
502 end
503
504 def failure_message_for_should
505 "Expected argument that converted to #{@str}"
506 end
507 end
508
509 def errors_matcher(method)
510 # In edge rails (Rails 4) tags store method_name as a string and index the errors object using a string
511 # therefore allow stubs to match on either string or symbol. The errors object calls to_sym on all index
512 # accesses so @object.errors[:abc] is equivalent to @object.errors["abc"]
513 if Rails::VERSION::MAJOR == 4
514 ToSMatcher.new(method)
515 else
516 method
517 end
518 end
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
519 end
520
cf05c63 @tokland fix: avoid clobbering of ActionView::Base.field_error_proc=
tokland authored
521 class ::ActionView::Base
522 include Formtastic::Helpers::FormHelper
523 end
524
39a5079 @justinfrench ensure that deprecation errors are always shown in specs... if you want ...
authored
525 ::ActiveSupport::Deprecation.silenced = false
2787d87 @justinfrench Deferring garbage collection cuts the time to run the test suite down (#...
authored
526
a0d6092 @justinfrench Rspec => RSpec in spec_helper
authored
527 RSpec.configure do |config|
699ec26 @justinfrench address rspec deprecation warnings fixes #1076
authored
528 config.infer_spec_type_from_file_location!
529
5d9dc22 @timoschilling config rspec filters
timoschilling authored
530 config.filter_run focus: true
531 config.filter_run_excluding skip: true
532 config.run_all_when_everything_filtered = true
533
a6dad77 Cache I18n lookups in Formtastic::Localizer
Sascha Konietzke authored
534 config.before(:each) do
535 Formtastic::Localizer.cache.clear!
536 end
498e730 @mikz silence expected deprecation warnings
mikz authored
537
538 config.before(:each) do
539 allow(Formtastic.deprecation).to receive(:deprecation_warning).and_call_original
540 # TODO: Remove this in Formtastic 4
541 [ :action_class, :standard_action_class_name, :custom_action_class_name,
542 :input_class, :standard_input_class_name, :custom_input_class_name ].each do |method|
543 allow(Formtastic.deprecation).to receive(:deprecation_warning).with(method, instance_of(String), instance_of(Array))
544 end
545 end
546
2787d87 @justinfrench Deferring garbage collection cuts the time to run the test suite down (#...
authored
547 config.before(:all) do
0baec94 @justinfrench check ENV['DEFER_GC'] isn't 'false' before doing the the DeferredGarbage...
authored
548 DeferredGarbageCollection.start unless ENV["DEFER_GC"] == "false"
2787d87 @justinfrench Deferring garbage collection cuts the time to run the test suite down (#...
authored
549 end
550 config.after(:all) do
a6dad77 Cache I18n lookups in Formtastic::Localizer
Sascha Konietzke authored
551 DeferredGarbageCollection.reconsider unless ENV["DEFER_GC"] == "false"
2787d87 @justinfrench Deferring garbage collection cuts the time to run the test suite down (#...
authored
552 end
152f04e @sobrinho Use `require 'bundler/setup'` instead of calling Bundler.setup manually
sobrinho authored
553 end
Something went wrong with that request. Please try again.