Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 229 lines (191 sloc) 8.624 kB
4db269b @justinfrench Reverting "rm'ing some encoding comments"
authored
1 # coding: utf-8
281dd18 @xaviershay rspec support - test_helper and rake task
xaviershay authored
2 require 'rubygems'
542d308 @grimen Fixing some issues with the specs to get them to run on Ruby 1.9.x. S…
grimen authored
3
9604949 @justinfrench smart_require is tripping up the CI build, and also tripped me up a f…
authored
4 gem 'activesupport', '2.3.5'
5 gem 'actionpack', '2.3.5'
6 require 'active_support'
7 require 'action_pack'
8 require 'action_view'
9 require 'action_controller'
542d308 @grimen Fixing some issues with the specs to get them to run on Ruby 1.9.x. S…
grimen authored
10
9604949 @justinfrench smart_require is tripping up the CI build, and also tripped me up a f…
authored
11 gem 'rspec', '>= 1.2.6'
12 gem 'rspec-rails', '>= 1.2.6'
13 gem 'hpricot', '>= 0.6.1'
14 gem 'rspec_tag_matchers', '>= 1.0.0'
15 require 'rspec_tag_matchers'
542d308 @grimen Fixing some issues with the specs to get them to run on Ruby 1.9.x. S…
grimen authored
16
4a732fd @justinfrench Spec Refactor:
authored
17 require 'custom_macros'
18
110641b @justinfrench require the rspec_hpricot_matchers gem for the specs, cuz the xpath m…
authored
19 Spec::Runner.configure do |config|
ca12563 @grimen Replacing dependency rspec_hpricot_matchers (Hpricot) with rspec_tag_…
grimen authored
20 config.include(RspecTagMatchers)
4a732fd @justinfrench Spec Refactor:
authored
21 config.include(CustomMacros)
110641b @justinfrench require the rspec_hpricot_matchers gem for the specs, cuz the xpath m…
authored
22 end
281dd18 @xaviershay rspec support - test_helper and rake task
xaviershay authored
23
70846ef @justinfrench fixed an issue where formtastic was being required twice in the specs
authored
24 require File.expand_path(File.join(File.dirname(__FILE__), '../lib/formtastic'))
127a6b9 @justinfrench Added a Formtastic::LayoutHelper with formtastic_stylesheets so that …
authored
25 require File.expand_path(File.join(File.dirname(__FILE__), '../lib/formtastic/layout_helper'))
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
26
27
28 module FormtasticSpecHelper
29 include ActionView::Helpers::FormHelper
30 include ActionView::Helpers::FormTagHelper
31 include ActionView::Helpers::FormOptionsHelper
32 include ActionView::Helpers::UrlHelper
33 include ActionView::Helpers::TagHelper
34 include ActionView::Helpers::TextHelper
35 include ActionView::Helpers::ActiveRecordHelper
36 include ActionView::Helpers::RecordIdentificationHelper
37 include ActionView::Helpers::DateHelper
38 include ActionView::Helpers::CaptureHelper
127a6b9 @justinfrench Added a Formtastic::LayoutHelper with formtastic_stylesheets so that …
authored
39 include ActionView::Helpers::AssetTagHelper
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
40 include ActiveSupport
41 include ActionController::PolymorphicRoutes
42
43 include Formtastic::SemanticFormHelper
44
45 def default_input_type(column_type, column_name = :generic_column_name)
46 @new_post.stub!(column_name)
47 @new_post.stub!(:column_for_attribute).and_return(mock('column', :type => column_type)) unless column_type.nil?
48
49 semantic_form_for(@new_post) do |builder|
50 @default_type = builder.send(:default_input_type, column_name)
51 end
52
53 return @default_type
54 end
55
56 class ::Post
57 def id
58 end
59 end
d33fad4 @akaspick Fix incorrect html class name being generated for namespaced objects.
akaspick authored
60 module ::Namespaced
61 class Post
62 def id
63 end
64 end
65 end
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
66 class ::Author
33a5d23 Added :group_by option to select input (issue #54)
Jeroen van Dijk authored
67 def to_label
68 end
69 end
70 class ::Continent
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
71 end
72
73 def mock_everything
74
75 # Resource-oriented styles like form_for(@post) will expect a path method for the object,
76 # so we're defining some here.
77 def post_path(o); "/posts/1"; end
78 def posts_path; "/posts"; end
79 def new_post_path; "/posts/new"; end
80
81 def author_path(o); "/authors/1"; end
82 def authors_path; "/authors"; end
83 def new_author_path; "/authors/new"; end
84
85 @fred = mock('user')
86 @fred.stub!(:class).and_return(::Author)
87 @fred.stub!(:to_label).and_return('Fred Smith')
88 @fred.stub!(:login).and_return('fred_smith')
89 @fred.stub!(:id).and_return(37)
90 @fred.stub!(:new_record?).and_return(false)
91 @fred.stub!(:errors).and_return(mock('errors', :[] => nil))
92
93 @bob = mock('user')
94 @bob.stub!(:class).and_return(::Author)
95 @bob.stub!(:to_label).and_return('Bob Rock')
96 @bob.stub!(:login).and_return('bob')
b326984 @justinfrench trying to move as much set up as possible into mock_everything
authored
97 @bob.stub!(:created_at)
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
98 @bob.stub!(:id).and_return(42)
99 @bob.stub!(:posts).and_return([])
100 @bob.stub!(:post_ids).and_return([])
101 @bob.stub!(:new_record?).and_return(false)
102 @bob.stub!(:errors).and_return(mock('errors', :[] => nil))
33a5d23 Added :group_by option to select input (issue #54)
Jeroen van Dijk authored
103
104 @james = mock('user')
105 @james.stub!(:class).and_return(::Author)
106 @james.stub!(:to_label).and_return('James Shock')
107 @james.stub!(:login).and_return('james')
108 @james.stub!(:id).and_return(75)
109 @james.stub!(:posts).and_return([])
110 @james.stub!(:post_ids).and_return([])
111 @james.stub!(:new_record?).and_return(false)
112 @james.stub!(:errors).and_return(mock('errors', :[] => nil))
113
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
114
115 ::Author.stub!(:find).and_return([@fred, @bob])
116 ::Author.stub!(:human_attribute_name).and_return { |column_name| column_name.humanize }
117 ::Author.stub!(:human_name).and_return('::Author')
118 ::Author.stub!(:reflect_on_validations_for).and_return([])
119 ::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 440bd2d8da117acdbca57fa199c115caefcd87c0."
authored
120 ::Author.stub!(:content_columns).and_return([mock('column', :name => 'login'), mock('column', :name => 'created_at')])
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
121
122 # Sometimes we need a mock @post object and some Authors for belongs_to
123 @new_post = mock('post')
124 @new_post.stub!(:class).and_return(::Post)
125 @new_post.stub!(:id).and_return(nil)
126 @new_post.stub!(:new_record?).and_return(true)
127 @new_post.stub!(:errors).and_return(mock('errors', :[] => nil))
128 @new_post.stub!(:author).and_return(nil)
a745de3 @gpetrica test case
gpetrica authored
129 @new_post.stub!(:reviewer).and_return(nil)
9c1daba Added regression spec for a belongs_to association with :group_by => …
Jacob Kjeldahl authored
130 @new_post.stub!(:main_post).and_return(nil)
131 @new_post.stub!(:sub_posts).and_return([]) #TODO should be a mock with methods for adding sub posts
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
132
133 @freds_post = mock('post')
134 @freds_post.stub!(:class).and_return(::Post)
135 @freds_post.stub!(:to_label).and_return('Fred Smith')
136 @freds_post.stub!(:id).and_return(19)
137 @freds_post.stub!(:author).and_return(@fred)
138 @freds_post.stub!(:author_id).and_return(@fred.id)
139 @freds_post.stub!(:authors).and_return([@fred])
140 @freds_post.stub!(:author_ids).and_return([@fred.id])
141 @freds_post.stub!(:new_record?).and_return(false)
142 @freds_post.stub!(:errors).and_return(mock('errors', :[] => nil))
143 @fred.stub!(:posts).and_return([@freds_post])
144 @fred.stub!(:post_ids).and_return([@freds_post.id])
145
146 ::Post.stub!(:human_attribute_name).and_return { |column_name| column_name.humanize }
147 ::Post.stub!(:human_name).and_return('Post')
148 ::Post.stub!(:reflect_on_all_validations).and_return([])
149 ::Post.stub!(:reflect_on_validations_for).and_return([])
150 ::Post.stub!(:reflect_on_association).and_return do |column_name|
151 case column_name
74eaf33 @gpetrica added test case for model that has 2 belongs_to fields pointing to sa…
gpetrica authored
152 when :author, :author_status
33a5d23 Added :group_by option to select input (issue #54)
Jeroen van Dijk authored
153 mock = mock('reflection', :options => {}, :klass => ::Author, :macro => :belongs_to)
154 mock.stub!(:[]).with(:class_name).and_return("Author")
155 mock
74eaf33 @gpetrica added test case for model that has 2 belongs_to fields pointing to sa…
gpetrica authored
156 when :reviewer
157 mock = mock('reflection', :options => {:class_name => 'Author'}, :klass => ::Author, :macro => :belongs_to)
158 mock.stub!(:[]).with(:class_name).and_return("Author")
159 mock
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
160 when :authors
161 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
162 when :sub_posts
163 mock('reflection', :options => {}, :klass => ::Post, :macro => :has_many)
164 when :main_post
165 mock('reflection', :options => {}, :klass => ::Post, :macro => :belongs_to)
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
166 end
9c1daba Added regression spec for a belongs_to association with :group_by => …
Jacob Kjeldahl authored
167
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
168 end
169 ::Post.stub!(:find).and_return([@freds_post])
17f6668 @justinfrench Revert "This reverts commit 440bd2d8da117acdbca57fa199c115caefcd87c0."
authored
170 ::Post.stub!(:content_columns).and_return([mock('column', :name => 'title'), mock('column', :name => 'body'), mock('column', :name => 'created_at')])
7466c77 @justinfrench moved the #inputs and #input specs out to their own file, and moved m…
authored
171
172 @new_post.stub!(:title)
173 @new_post.stub!(:body)
174 @new_post.stub!(:published)
b326984 @justinfrench trying to move as much set up as possible into mock_everything
authored
175 @new_post.stub!(:publish_at)
17f6668 @justinfrench Revert "This reverts commit 440bd2d8da117acdbca57fa199c115caefcd87c0."
authored
176 @new_post.stub!(:created_at)
b326984 @justinfrench trying to move as much set up as possible into mock_everything
authored
177 @new_post.stub!(:secret)
178 @new_post.stub!(:time_zone)
179 @new_post.stub!(:category_name)
180 @new_post.stub!(:allow_comments)
7466c77 @justinfrench moved the #inputs and #input specs out to their own file, and moved m…
authored
181 @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
182 @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
183 @new_post.stub!(:column_for_attribute).with(:body).and_return(mock('column', :type => :text))
184 @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
185 @new_post.stub!(:column_for_attribute).with(:publish_at).and_return(mock('column', :type => :date))
186 @new_post.stub!(:column_for_attribute).with(:time_zone).and_return(mock('column', :type => :string))
187 @new_post.stub!(:column_for_attribute).with(:allow_comments).and_return(mock('column', :type => :boolean))
188
189 @new_post.stub!(:author).and_return(@bob)
190 @new_post.stub!(:author_id).and_return(@bob.id)
9c1daba Added regression spec for a belongs_to association with :group_by => …
Jacob Kjeldahl authored
191
a745de3 @gpetrica test case
gpetrica authored
192 @new_post.stub!(:reviewer).and_return(@fred)
193 @new_post.stub!(:reviewer_id).and_return(@fred.id)
194
c453c36 @grimen Failing spec and a "for some reason a non-working solution" for issue…
grimen authored
195 @new_post.should_receive(:publish_at=).any_number_of_times
196 @new_post.should_receive(:title=).any_number_of_times
9c1daba Added regression spec for a belongs_to association with :group_by => …
Jacob Kjeldahl authored
197 @new_post.stub!(:main_post_id).and_return(nil)
198
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
199 end
200
201 def self.included(base)
202 base.class_eval do
203
204 attr_accessor :output_buffer
205
206 def protect_against_forgery?
207 false
208 end
209
210 end
211 end
212
ffa9e37 @justinfrench Added a with_config method for specs.
authored
213 def with_config(config_method_name, value, &block)
214 old_value = ::Formtastic::SemanticFormBuilder.send(config_method_name)
215 ::Formtastic::SemanticFormBuilder.send(:"#{config_method_name}=", value)
216 yield
217 ::Formtastic::SemanticFormBuilder.send(:"#{config_method_name}=", old_value)
218 end
219
b07e2d1 @justinfrench added helper method for testing deprecation warnings in a silenced block
authored
220 def with_deprecation_silenced(&block)
221 ::ActiveSupport::Deprecation.silenced = true
222 yield
223 ::ActiveSupport::Deprecation.silenced = false
224 end
225
9690e9b @justinfrench Start of The Big Spec Refactor:
authored
226 end
227
39a5079 @justinfrench ensure that deprecation errors are always shown in specs... if you wa…
authored
228 ::ActiveSupport::Deprecation.silenced = false
Something went wrong with that request. Please try again.