Skip to content

HTTPS clone URL

Subversion checkout URL

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