Skip to content
Newer
Older
100644 273 lines (231 sloc) 10.8 KB
4db269b @justinfrench Reverting "rm'ing some encoding comments"
authored Oct 15, 2009
1 # coding: utf-8
281dd18 @xaviershay rspec support - test_helper and rake task
xaviershay authored Jul 5, 2008
2 require 'rubygems'
9604949 @justinfrench smart_require is tripping up the CI build, and also tripped me up a f…
authored Feb 7, 2010
3 require 'active_support'
4 require 'action_pack'
5 require 'action_view'
6 require 'action_controller'
542d308 @grimen Fixing some issues with the specs to get them to run on Ruby 1.9.x. S…
grimen authored Sep 1, 2009
7
fe63045 @yabawock Use HTML safe strings in tests
yabawock authored May 24, 2010
8 require File.expand_path(File.join(File.dirname(__FILE__), '../lib/formtastic/util'))
b86266e @yabawock Separate test environment setup and misc setup blocks into spec/suppo…
yabawock authored Jun 17, 2010
9 require File.expand_path(File.join(File.dirname(__FILE__), '../lib/formtastic'))
127a6b9 @justinfrench Added a Formtastic::LayoutHelper with formtastic_stylesheets so that …
authored Jan 10, 2010
10 require File.expand_path(File.join(File.dirname(__FILE__), '../lib/formtastic/layout_helper'))
9690e9b @justinfrench Start of The Big Spec Refactor:
authored Oct 21, 2009
11
b86266e @yabawock Separate test environment setup and misc setup blocks into spec/suppo…
yabawock authored Jun 17, 2010
12 # Requires supporting files with custom matchers and macros, etc,
13 # in ./support/ and its subdirectories.
14 Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9690e9b @justinfrench Start of The Big Spec Refactor:
authored Oct 21, 2009
15
16 module FormtasticSpecHelper
82f6c8d @justinfrench Fixes deprecation warnings with form_for(:name, @resource) in rails3 (#…
authored Apr 20, 2010
17 include ActionPack
b88bd5b @yabawock Changed spec_helper to allow for Rails 3 / Rspec 2 environment
yabawock authored Apr 15, 2010
18 include ActionView::Context if defined?(ActionView::Context)
9690e9b @justinfrench Start of The Big Spec Refactor:
authored Oct 21, 2009
19 include ActionView::Helpers::FormHelper
20 include ActionView::Helpers::FormTagHelper
21 include ActionView::Helpers::FormOptionsHelper
22 include ActionView::Helpers::UrlHelper
23 include ActionView::Helpers::TagHelper
24 include ActionView::Helpers::TextHelper
b88bd5b @yabawock Changed spec_helper to allow for Rails 3 / Rspec 2 environment
yabawock authored Apr 15, 2010
25 include ActionView::Helpers::ActiveRecordHelper if defined?(ActionView::Helpers::ActiveRecordHelper)
26 include ActionView::Helpers::ActiveModelHelper if defined?(ActionView::Helpers::ActiveModelHelper)
9690e9b @justinfrench Start of The Big Spec Refactor:
authored Oct 21, 2009
27 include ActionView::Helpers::RecordIdentificationHelper
28 include ActionView::Helpers::DateHelper
29 include ActionView::Helpers::CaptureHelper
127a6b9 @justinfrench Added a Formtastic::LayoutHelper with formtastic_stylesheets so that …
authored Jan 10, 2010
30 include ActionView::Helpers::AssetTagHelper
9690e9b @justinfrench Start of The Big Spec Refactor:
authored Oct 21, 2009
31 include ActiveSupport
32 include ActionController::PolymorphicRoutes
33
34 include Formtastic::SemanticFormHelper
35
82f6c8d @justinfrench Fixes deprecation warnings with form_for(:name, @resource) in rails3 (#…
authored Apr 19, 2010
36 def rails3?
37 ActionPack::VERSION::MAJOR > 2
38 end
39
40 def rails2?
41 ActionPack::VERSION::MAJOR == 2
42 end
43
9690e9b @justinfrench Start of The Big Spec Refactor:
authored Oct 21, 2009
44 def default_input_type(column_type, column_name = :generic_column_name)
45 @new_post.stub!(column_name)
46 @new_post.stub!(:column_for_attribute).and_return(mock('column', :type => column_type)) unless column_type.nil?
47
48 semantic_form_for(@new_post) do |builder|
49 @default_type = builder.send(:default_input_type, column_name)
50 end
51
52 return @default_type
53 end
54
2769784 @tetsuo692 add active_model_presence_validator helper and clean up test
tetsuo692 authored Apr 21, 2010
55 def active_model_presence_validator(attributes, options = {})
56 presence_validator = mock('ActiveModel::Validations::PresenceValidator', :attributes => attributes, :options => options)
57 presence_validator.stub!(:kind).and_return(:presence)
58 presence_validator
59 end
60
9690e9b @justinfrench Start of The Big Spec Refactor:
authored Oct 21, 2009
61 class ::Post
b88bd5b @yabawock Changed spec_helper to allow for Rails 3 / Rspec 2 environment
yabawock authored Apr 15, 2010
62 extend ActiveModel::Naming if defined?(ActiveModel::Naming)
63 include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
64
9690e9b @justinfrench Start of The Big Spec Refactor:
authored Oct 21, 2009
65 def id
66 end
b88bd5b @yabawock Changed spec_helper to allow for Rails 3 / Rspec 2 environment
yabawock authored Apr 15, 2010
67
68 def persisted?
69 end
9690e9b @justinfrench Start of The Big Spec Refactor:
authored Oct 21, 2009
70 end
d33fad4 @akaspick Fix incorrect html class name being generated for namespaced objects.
akaspick authored Dec 30, 2009
71 module ::Namespaced
72 class Post
b88bd5b @yabawock Changed spec_helper to allow for Rails 3 / Rspec 2 environment
yabawock authored Apr 15, 2010
73 extend ActiveModel::Naming if defined?(ActiveModel::Naming)
74 include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
75
d33fad4 @akaspick Fix incorrect html class name being generated for namespaced objects.
akaspick authored Dec 30, 2009
76 def id
77 end
b88bd5b @yabawock Changed spec_helper to allow for Rails 3 / Rspec 2 environment
yabawock authored Apr 15, 2010
78
79 def persisted?
80 end
d33fad4 @akaspick Fix incorrect html class name being generated for namespaced objects.
akaspick authored Dec 30, 2009
81 end
82 end
9690e9b @justinfrench Start of The Big Spec Refactor:
authored Oct 21, 2009
83 class ::Author
b88bd5b @yabawock Changed spec_helper to allow for Rails 3 / Rspec 2 environment
yabawock authored Apr 15, 2010
84 extend ActiveModel::Naming if defined?(ActiveModel::Naming)
85 include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
86
33a5d23 Added :group_by option to select input (issue #54)
Jeroen van Dijk authored Nov 11, 2009
87 def to_label
88 end
89 end
90 class ::Continent
b88bd5b @yabawock Changed spec_helper to allow for Rails 3 / Rspec 2 environment
yabawock authored Apr 15, 2010
91 extend ActiveModel::Naming if defined?(ActiveModel::Naming)
92 include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
9690e9b @justinfrench Start of The Big Spec Refactor:
authored Oct 21, 2009
93 end
94
95 def mock_everything
96
97 # Resource-oriented styles like form_for(@post) will expect a path method for the object,
98 # so we're defining some here.
99 def post_path(o); "/posts/1"; end
100 def posts_path; "/posts"; end
101 def new_post_path; "/posts/new"; end
102
103 def author_path(o); "/authors/1"; end
104 def authors_path; "/authors"; end
105 def new_author_path; "/authors/new"; end
106
107 @fred = mock('user')
108 @fred.stub!(:class).and_return(::Author)
109 @fred.stub!(:to_label).and_return('Fred Smith')
110 @fred.stub!(:login).and_return('fred_smith')
111 @fred.stub!(:id).and_return(37)
112 @fred.stub!(:new_record?).and_return(false)
113 @fred.stub!(:errors).and_return(mock('errors', :[] => nil))
b88bd5b @yabawock Changed spec_helper to allow for Rails 3 / Rspec 2 environment
yabawock authored Apr 15, 2010
114 @fred.stub!(:to_key).and_return(nil)
115 @fred.stub!(:persisted?).and_return(nil)
9690e9b @justinfrench Start of The Big Spec Refactor:
authored Oct 21, 2009
116
117 @bob = mock('user')
118 @bob.stub!(:class).and_return(::Author)
119 @bob.stub!(:to_label).and_return('Bob Rock')
120 @bob.stub!(:login).and_return('bob')
b326984 @justinfrench trying to move as much set up as possible into mock_everything
authored Nov 12, 2009
121 @bob.stub!(:created_at)
9690e9b @justinfrench Start of The Big Spec Refactor:
authored Oct 21, 2009
122 @bob.stub!(:id).and_return(42)
123 @bob.stub!(:posts).and_return([])
124 @bob.stub!(:post_ids).and_return([])
125 @bob.stub!(:new_record?).and_return(false)
126 @bob.stub!(:errors).and_return(mock('errors', :[] => nil))
b88bd5b @yabawock Changed spec_helper to allow for Rails 3 / Rspec 2 environment
yabawock authored Apr 15, 2010
127 @bob.stub!(:to_key).and_return(nil)
128 @bob.stub!(:persisted?).and_return(nil)
33a5d23 Added :group_by option to select input (issue #54)
Jeroen van Dijk authored Nov 11, 2009
129
130 @james = mock('user')
b88bd5b @yabawock Changed spec_helper to allow for Rails 3 / Rspec 2 environment
yabawock authored Apr 15, 2010
131 @james.stub!(:class).and_return(::Author)
132 @james.stub!(:to_label).and_return('James Shock')
133 @james.stub!(:login).and_return('james')
134 @james.stub!(:id).and_return(75)
135 @james.stub!(:posts).and_return([])
136 @james.stub!(:post_ids).and_return([])
137 @james.stub!(:new_record?).and_return(false)
138 @james.stub!(:errors).and_return(mock('errors', :[] => nil))
139 @james.stub!(:to_key).and_return(nil)
140 @james.stub!(:persisted?).and_return(nil)
33a5d23 Added :group_by option to select input (issue #54)
Jeroen van Dijk authored Nov 11, 2009
141
9690e9b @justinfrench Start of The Big Spec Refactor:
authored Oct 21, 2009
142
143 ::Author.stub!(:find).and_return([@fred, @bob])
144 ::Author.stub!(:human_attribute_name).and_return { |column_name| column_name.humanize }
145 ::Author.stub!(:human_name).and_return('::Author')
146 ::Author.stub!(:reflect_on_association).and_return { |column_name| mock('reflection', :options => {}, :klass => Post, :macro => :has_many) if column_name == :posts }
17f6668 @justinfrench Revert "This reverts commit 440bd2d."
authored Nov 21, 2009
147 ::Author.stub!(:content_columns).and_return([mock('column', :name => 'login'), mock('column', :name => 'created_at')])
b88bd5b @yabawock Changed spec_helper to allow for Rails 3 / Rspec 2 environment
yabawock authored Apr 15, 2010
148 ::Author.stub!(:to_key).and_return(nil)
149 ::Author.stub!(:persisted?).and_return(nil)
9690e9b @justinfrench Start of The Big Spec Refactor:
authored Oct 21, 2009
150
151 # Sometimes we need a mock @post object and some Authors for belongs_to
152 @new_post = mock('post')
153 @new_post.stub!(:class).and_return(::Post)
154 @new_post.stub!(:id).and_return(nil)
155 @new_post.stub!(:new_record?).and_return(true)
156 @new_post.stub!(:errors).and_return(mock('errors', :[] => nil))
157 @new_post.stub!(:author).and_return(nil)
2814011 @yabawock Merge branch 'master' into rails3
yabawock authored May 4, 2010
158 @new_post.stub!(:reviewer).and_return(nil)
9c1daba Added regression spec for a belongs_to association with :group_by => …
Jacob Kjeldahl authored Nov 25, 2009
159 @new_post.stub!(:main_post).and_return(nil)
160 @new_post.stub!(:sub_posts).and_return([]) #TODO should be a mock with methods for adding sub posts
b88bd5b @yabawock Changed spec_helper to allow for Rails 3 / Rspec 2 environment
yabawock authored Apr 15, 2010
161 @new_post.stub!(:to_key).and_return(nil)
162 @new_post.stub!(:to_model).and_return(@new_post)
163 @new_post.stub!(:persisted?).and_return(nil)
9690e9b @justinfrench Start of The Big Spec Refactor:
authored Oct 21, 2009
164
165 @freds_post = mock('post')
166 @freds_post.stub!(:class).and_return(::Post)
167 @freds_post.stub!(:to_label).and_return('Fred Smith')
168 @freds_post.stub!(:id).and_return(19)
169 @freds_post.stub!(:author).and_return(@fred)
170 @freds_post.stub!(:author_id).and_return(@fred.id)
171 @freds_post.stub!(:authors).and_return([@fred])
172 @freds_post.stub!(:author_ids).and_return([@fred.id])
173 @freds_post.stub!(:new_record?).and_return(false)
174 @freds_post.stub!(:errors).and_return(mock('errors', :[] => nil))
b88bd5b @yabawock Changed spec_helper to allow for Rails 3 / Rspec 2 environment
yabawock authored Apr 15, 2010
175 @freds_post.stub!(:to_key).and_return(nil)
176 @freds_post.stub!(:persisted?).and_return(nil)
9690e9b @justinfrench Start of The Big Spec Refactor:
authored Oct 21, 2009
177 @fred.stub!(:posts).and_return([@freds_post])
178 @fred.stub!(:post_ids).and_return([@freds_post.id])
179
180 ::Post.stub!(:human_attribute_name).and_return { |column_name| column_name.humanize }
181 ::Post.stub!(:human_name).and_return('Post')
182 ::Post.stub!(:reflect_on_all_validations).and_return([])
4b3bb60 @yabawock Rspec renamed to RSpec (since 2.0.0.beta.9)
yabawock authored May 29, 2010
183 ::Post.stub!(:reflect_on_validations_for).and_return([]) if defined?(RSpec)
1bd9545 @justinfrench belongs_to associations will now render errors attached to the associ…
authored Apr 21, 2010
184 ::Post.stub!(:reflections).and_return({})
9690e9b @justinfrench Start of The Big Spec Refactor:
authored Oct 21, 2009
185 ::Post.stub!(:reflect_on_association).and_return do |column_name|
186 case column_name
187 when :author, :author_status
33a5d23 Added :group_by option to select input (issue #54)
Jeroen van Dijk authored Nov 11, 2009
188 mock = mock('reflection', :options => {}, :klass => ::Author, :macro => :belongs_to)
189 mock.stub!(:[]).with(:class_name).and_return("Author")
190 mock
2814011 @yabawock Merge branch 'master' into rails3
yabawock authored May 4, 2010
191 when :reviewer
192 mock = mock('reflection', :options => {:class_name => 'Author'}, :klass => ::Author, :macro => :belongs_to)
74eaf33 @gpetrica added test case for model that has 2 belongs_to fields pointing to sa…
gpetrica authored Apr 26, 2010
193 mock.stub!(:[]).with(:class_name).and_return("Author")
194 mock
9690e9b @justinfrench Start of The Big Spec Refactor:
authored Oct 21, 2009
195 when :authors
196 mock('reflection', :options => {}, :klass => ::Author, :macro => :has_and_belongs_to_many)
9c1daba Added regression spec for a belongs_to association with :group_by => …
Jacob Kjeldahl authored Nov 25, 2009
197 when :sub_posts
198 mock('reflection', :options => {}, :klass => ::Post, :macro => :has_many)
199 when :main_post
200 mock('reflection', :options => {}, :klass => ::Post, :macro => :belongs_to)
9690e9b @justinfrench Start of The Big Spec Refactor:
authored Oct 21, 2009
201 end
9c1daba Added regression spec for a belongs_to association with :group_by => …
Jacob Kjeldahl authored Nov 25, 2009
202
9690e9b @justinfrench Start of The Big Spec Refactor:
authored Oct 21, 2009
203 end
204 ::Post.stub!(:find).and_return([@freds_post])
17f6668 @justinfrench Revert "This reverts commit 440bd2d."
authored Nov 21, 2009
205 ::Post.stub!(:content_columns).and_return([mock('column', :name => 'title'), mock('column', :name => 'body'), mock('column', :name => 'created_at')])
b88bd5b @yabawock Changed spec_helper to allow for Rails 3 / Rspec 2 environment
yabawock authored Apr 15, 2010
206 ::Post.stub!(:to_key).and_return(nil)
207 ::Post.stub!(:persisted?).and_return(nil)
7466c77 @justinfrench moved the #inputs and #input specs out to their own file, and moved m…
authored Oct 22, 2009
208
209 @new_post.stub!(:title)
210 @new_post.stub!(:body)
211 @new_post.stub!(:published)
b326984 @justinfrench trying to move as much set up as possible into mock_everything
authored Nov 12, 2009
212 @new_post.stub!(:publish_at)
17f6668 @justinfrench Revert "This reverts commit 440bd2d."
authored Nov 21, 2009
213 @new_post.stub!(:created_at)
b326984 @justinfrench trying to move as much set up as possible into mock_everything
authored Nov 12, 2009
214 @new_post.stub!(:secret)
215 @new_post.stub!(:time_zone)
216 @new_post.stub!(:category_name)
217 @new_post.stub!(:allow_comments)
3ae6b20 @justinfrench An input without an :as option will only route to country_input if th…
authored May 4, 2010
218 @new_post.stub!(:country)
219 @new_post.stub!(:country_subdivision)
220 @new_post.stub!(:country_code)
7466c77 @justinfrench moved the #inputs and #input specs out to their own file, and moved m…
authored Oct 22, 2009
221 @new_post.stub!(:column_for_attribute).with(:meta_description).and_return(mock('column', :type => :string, :limit => 255))
b326984 @justinfrench trying to move as much set up as possible into mock_everything
authored Nov 12, 2009
222 @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :string, :limit => 50))
7466c77 @justinfrench moved the #inputs and #input specs out to their own file, and moved m…
authored Oct 22, 2009
223 @new_post.stub!(:column_for_attribute).with(:body).and_return(mock('column', :type => :text))
224 @new_post.stub!(:column_for_attribute).with(:published).and_return(mock('column', :type => :boolean))
b326984 @justinfrench trying to move as much set up as possible into mock_everything
authored Nov 12, 2009
225 @new_post.stub!(:column_for_attribute).with(:publish_at).and_return(mock('column', :type => :date))
226 @new_post.stub!(:column_for_attribute).with(:time_zone).and_return(mock('column', :type => :string))
227 @new_post.stub!(:column_for_attribute).with(:allow_comments).and_return(mock('column', :type => :boolean))
1bd9545 @justinfrench belongs_to associations will now render errors attached to the associ…
authored Apr 20, 2010
228 @new_post.stub!(:column_for_attribute).with(:author).and_return(mock('column', :type => :integer))
3ae6b20 @justinfrench An input without an :as option will only route to country_input if th…
authored May 3, 2010
229 @new_post.stub!(:column_for_attribute).with(:country).and_return(mock('column', :type => :string, :limit => 255))
230 @new_post.stub!(:column_for_attribute).with(:country_subdivision).and_return(mock('column', :type => :string, :limit => 255))
231 @new_post.stub!(:column_for_attribute).with(:country_code).and_return(mock('column', :type => :string, :limit => 255))
b326984 @justinfrench trying to move as much set up as possible into mock_everything
authored Nov 12, 2009
232
233 @new_post.stub!(:author).and_return(@bob)
234 @new_post.stub!(:author_id).and_return(@bob.id)
9c1daba Added regression spec for a belongs_to association with :group_by => …
Jacob Kjeldahl authored Nov 25, 2009
235
2814011 @yabawock Merge branch 'master' into rails3
yabawock authored May 4, 2010
236 @new_post.stub!(:reviewer).and_return(@fred)
237 @new_post.stub!(:reviewer_id).and_return(@fred.id)
a745de3 @gpetrica test case
gpetrica authored Apr 26, 2010
238
c453c36 @grimen Failing spec and a "for some reason a non-working solution" for issue #…
grimen authored Nov 24, 2009
239 @new_post.should_receive(:publish_at=).any_number_of_times
240 @new_post.should_receive(:title=).any_number_of_times
9c1daba Added regression spec for a belongs_to association with :group_by => …
Jacob Kjeldahl authored Nov 25, 2009
241 @new_post.stub!(:main_post_id).and_return(nil)
242
9690e9b @justinfrench Start of The Big Spec Refactor:
authored Oct 21, 2009
243 end
244
245 def self.included(base)
246 base.class_eval do
247
248 attr_accessor :output_buffer
249
250 def protect_against_forgery?
251 false
252 end
253
254 end
255 end
256
ffa9e37 @justinfrench Added a with_config method for specs.
authored Dec 3, 2009
257 def with_config(config_method_name, value, &block)
258 old_value = ::Formtastic::SemanticFormBuilder.send(config_method_name)
259 ::Formtastic::SemanticFormBuilder.send(:"#{config_method_name}=", value)
260 yield
261 ::Formtastic::SemanticFormBuilder.send(:"#{config_method_name}=", old_value)
262 end
263
b07e2d1 @justinfrench added helper method for testing deprecation warnings in a silenced block
authored Jan 8, 2010
264 def with_deprecation_silenced(&block)
265 ::ActiveSupport::Deprecation.silenced = true
266 yield
267 ::ActiveSupport::Deprecation.silenced = false
268 end
269
9690e9b @justinfrench Start of The Big Spec Refactor:
authored Oct 21, 2009
270 end
271
39a5079 @justinfrench ensure that deprecation errors are always shown in specs... if you wa…
authored Nov 16, 2009
272 ::ActiveSupport::Deprecation.silenced = false
Something went wrong with that request. Please try again.