watirmark 5.14.16
Sign up to get free protection for your applications and to get access to all the features.
- data/app_generators/create_project/create_project_generator.rb +115 -0
- data/app_generators/create_project/templates/features/env.rb.erb +8 -0
- data/app_generators/create_project/templates/features/model_steps.rb.erb +9 -0
- data/app_generators/create_project/templates/features/post_error_steps.rb.erb +15 -0
- data/app_generators/create_project/templates/features/sample.feature.erb +5 -0
- data/app_generators/create_project/templates/features/site_steps.rb.erb +7 -0
- data/app_generators/create_project/templates/generators/controller.rb.erb +9 -0
- data/app_generators/create_project/templates/generators/generate.rb.erb +9 -0
- data/app_generators/create_project/templates/generators/model.rb.erb +7 -0
- data/app_generators/create_project/templates/generators/mvc_generator.rb.erb +100 -0
- data/app_generators/create_project/templates/generators/rbeautify.rb.erb +212 -0
- data/app_generators/create_project/templates/generators/view.rb.erb +16 -0
- data/app_generators/create_project/templates/generators/workflow_loader.rb.erb +1 -0
- data/app_generators/create_project/templates/library/base_controller.rb.erb +9 -0
- data/app_generators/create_project/templates/library/base_view.rb.erb +6 -0
- data/app_generators/create_project/templates/library/configuration.rb.erb +6 -0
- data/app_generators/create_project/templates/library/core_libraries.rb.erb +9 -0
- data/app_generators/create_project/templates/library/loader.rb.erb +23 -0
- data/app_generators/create_project/templates/library/page_load_checker.rb.erb +11 -0
- data/app_generators/create_project/templates/library/post_errors_checker.rb.erb +23 -0
- data/app_generators/create_project/templates/library/project_require_file.rb.erb +8 -0
- data/app_generators/create_project/templates/library/search_controller.rb.erb +12 -0
- data/app_generators/create_project/templates/library/workflows.rb.erb +0 -0
- data/app_generators/create_project/templates/project/config.yml.erb +3 -0
- data/app_generators/create_project/templates/project/gemfile.rb.erb +11 -0
- data/app_generators/create_project/templates/project/rakefile.rb.erb +21 -0
- data/bin/etapestry/Gemfile +11 -0
- data/bin/etapestry/config.yml +3 -0
- data/bin/etapestry/features/etapestry_home.feature +5 -0
- data/bin/etapestry/features/step_definitions/model_steps.rb +9 -0
- data/bin/etapestry/features/step_definitions/post_error_steps.rb +15 -0
- data/bin/etapestry/features/step_definitions/site_steps.rb +7 -0
- data/bin/etapestry/features/support/env.rb +8 -0
- data/bin/etapestry/generators/mvc/mvc_generator.rb +100 -0
- data/bin/etapestry/generators/mvc/rbeautify.rb +212 -0
- data/bin/etapestry/generators/mvc/templates/controller.rb.erb +9 -0
- data/bin/etapestry/generators/mvc/templates/model.rb.erb +7 -0
- data/bin/etapestry/generators/mvc/templates/view.rb.erb +16 -0
- data/bin/etapestry/generators/mvc/templates/workflow_loader.rb.erb +1 -0
- data/bin/etapestry/lib/etapestry.rb +8 -0
- data/bin/etapestry/lib/etapestry/checkers/page_load_checker.rb +11 -0
- data/bin/etapestry/lib/etapestry/checkers/post_errors_checker.rb +23 -0
- data/bin/etapestry/lib/etapestry/configuration.rb +6 -0
- data/bin/etapestry/lib/etapestry/core_libraries.rb +9 -0
- data/bin/etapestry/lib/etapestry/loader.rb +23 -0
- data/bin/etapestry/lib/etapestry/site/base_controller.rb +9 -0
- data/bin/etapestry/lib/etapestry/site/base_view.rb +6 -0
- data/bin/etapestry/lib/etapestry/site/search_controller.rb +12 -0
- data/bin/etapestry/lib/etapestry/workflows.rb +0 -0
- data/bin/etapestry/rakefile.rb +21 -0
- data/bin/etapestry/script/generate.rb +9 -0
- data/bin/twitter/features/hashtag_search.feature +93 -0
- data/bin/twitter/features/step_definitions/hashtag_steps.rb +9 -0
- data/bin/twitter/lib/twitter/workflows/search/result_controller.rb +13 -0
- data/bin/twitter/lib/twitter/workflows/search/result_model.rb +5 -0
- data/bin/twitter/lib/twitter/workflows/search/result_view.rb +19 -0
- data/bin/watirmark +10 -0
- data/lib/watirmark.rb +26 -0
- data/lib/watirmark/at_exit.rb +13 -0
- data/lib/watirmark/configuration.rb +201 -0
- data/lib/watirmark/controller/actions.rb +172 -0
- data/lib/watirmark/controller/assertions.rb +116 -0
- data/lib/watirmark/controller/controller.rb +191 -0
- data/lib/watirmark/controller/dialogs.rb +33 -0
- data/lib/watirmark/controller/matcher.rb +19 -0
- data/lib/watirmark/cucumber/cuke_helper.rb +150 -0
- data/lib/watirmark/cucumber/email_helper.rb +103 -0
- data/lib/watirmark/cucumber/env.rb +9 -0
- data/lib/watirmark/cucumber/hooks.rb +16 -0
- data/lib/watirmark/cucumber/model_helper.rb +34 -0
- data/lib/watirmark/cucumber/transforms.rb +55 -0
- data/lib/watirmark/exceptions.rb +15 -0
- data/lib/watirmark/extensions/ruby_extensions.rb +129 -0
- data/lib/watirmark/extensions/webdriver_extensions.rb +150 -0
- data/lib/watirmark/formatters/snapshot_formatter.rb +23 -0
- data/lib/watirmark/loader.rb +87 -0
- data/lib/watirmark/model.rb +3 -0
- data/lib/watirmark/models/cucumber_helper.rb +49 -0
- data/lib/watirmark/models/debug_methods.rb +21 -0
- data/lib/watirmark/models/default_values.rb +21 -0
- data/lib/watirmark/models/factory.rb +168 -0
- data/lib/watirmark/models/factory_method_generators.rb +84 -0
- data/lib/watirmark/models/factory_methods.rb +72 -0
- data/lib/watirmark/models/trait.rb +35 -0
- data/lib/watirmark/models/upload_csv.rb +24 -0
- data/lib/watirmark/page/keyed_element.rb +63 -0
- data/lib/watirmark/page/page.rb +50 -0
- data/lib/watirmark/page/page_definition.rb +187 -0
- data/lib/watirmark/page/process_page.rb +112 -0
- data/lib/watirmark/page/radio_maps.rb +53 -0
- data/lib/watirmark/profile.rb +22 -0
- data/lib/watirmark/rake/smoketest.rb +17 -0
- data/lib/watirmark/screenshot.rb +127 -0
- data/lib/watirmark/session.rb +115 -0
- data/lib/watirmark/version.rb +5 -0
- data/spec/assertions_spec.rb +95 -0
- data/spec/config_spec.rb +82 -0
- data/spec/controller_actions_spec.rb +91 -0
- data/spec/controller_spec.rb +426 -0
- data/spec/controllers_and_models_spec.rb +52 -0
- data/spec/model_factory_spec.rb +568 -0
- data/spec/model_traits_spec.rb +141 -0
- data/spec/page_spec.rb +127 -0
- data/spec/process_page_spec.rb +163 -0
- data/spec/spec_helper.rb +17 -0
- metadata +238 -0
@@ -0,0 +1,426 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
describe Watirmark::WebPage::Controller do
|
4
|
+
|
5
|
+
class TestView < Page
|
6
|
+
keyword(:text_field) {browser.text_field(:name, 'text_field')}
|
7
|
+
keyword(:select_list) {browser.select_list(:name, 'select_list')}
|
8
|
+
keyword(:another_text_field) {browser.text_field(:id, 'validate1')}
|
9
|
+
end
|
10
|
+
|
11
|
+
class TestController < Watirmark::WebPage::Controller
|
12
|
+
@view = TestView
|
13
|
+
def initialize(*args)
|
14
|
+
super
|
15
|
+
@model.text_field = 'foobar'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class VerifyView < Page
|
20
|
+
keyword(:validate1) {browser.text_field(:id, 'validate1')}
|
21
|
+
keyword(:validate2) {browser.text_field(:id, 'validate2')}
|
22
|
+
keyword(:validate3) {browser.text_field(:id, 'validate3')}
|
23
|
+
keyword(:validate4) {browser.select_list(:id, 'validate3')}
|
24
|
+
keyword(:checkbox) {browser.checkbox(:id, 'checkbox')}
|
25
|
+
|
26
|
+
verify_keyword(:label1) {browser.td(:id, 'label1')}
|
27
|
+
verify_keyword(:value1) {browser.td(:id, 'value1')}
|
28
|
+
populate_keyword(:populate1) {browser.text_field(:id, 'validate4')}
|
29
|
+
populate_keyword(:populate2) {browser.td(:id, 'value1')}
|
30
|
+
|
31
|
+
private_keyword(:private_validate1) {browser.text_field(:id, 'validate1')}
|
32
|
+
navigation_keyword(:click_submit) {browser.button(:id, 'Submit').click}
|
33
|
+
end
|
34
|
+
|
35
|
+
class VerifyController < Watirmark::WebPage::Controller
|
36
|
+
@view = VerifyView
|
37
|
+
end
|
38
|
+
|
39
|
+
class TestControllerSubclass < TestController; end
|
40
|
+
|
41
|
+
class Element
|
42
|
+
attr_accessor :value
|
43
|
+
def initialize(x)
|
44
|
+
@value = x
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class ProcessPageControllerView < Page
|
49
|
+
|
50
|
+
keyword(:a) {Element.new :a}
|
51
|
+
process_page('Page 1') do
|
52
|
+
keyword(:b) {Element.new :b}
|
53
|
+
end
|
54
|
+
process_page('Page 2') do
|
55
|
+
keyword(:c) {Element.new :c}
|
56
|
+
keyword(:d) {Element.new :d}
|
57
|
+
end
|
58
|
+
keyword(:e) {method :e}
|
59
|
+
keyword(:radio_map,
|
60
|
+
['M'] => 'male',
|
61
|
+
[/f/i] => 'female'
|
62
|
+
) {Page.browser.radio(:name, 'sex')}
|
63
|
+
end
|
64
|
+
|
65
|
+
class TestProcessPageController < Watirmark::WebPage::Controller
|
66
|
+
@view = ProcessPageControllerView
|
67
|
+
end
|
68
|
+
|
69
|
+
before :all do
|
70
|
+
@controller = Class.new(TestController) do
|
71
|
+
public :value
|
72
|
+
end.new
|
73
|
+
@keyword = :text_field
|
74
|
+
@keyed_element = Watirmark::KeyedElement.new(@controller, :keyword => @keyword)
|
75
|
+
@html = File.expand_path(File.dirname(__FILE__) + '/html/controller.html')
|
76
|
+
Page.browser.goto "file://#{@html}"
|
77
|
+
end
|
78
|
+
|
79
|
+
before :each do
|
80
|
+
Page.browser.refresh #reset page before each test
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should supportradio maps in controllers' do
|
84
|
+
lambda{
|
85
|
+
TestProcessPageController.new(:radio_map => 'f').populate_data
|
86
|
+
}.should_not raise_error
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should be able to create and use a new keyword' do
|
90
|
+
@keyword.should == :text_field
|
91
|
+
TestView.new.send("#{@keyword}=", 'test')
|
92
|
+
lambda{ @controller.check(@keyword, 'test')}.should_not raise_error(Watirmark::VerificationException)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should be able to populate' do
|
96
|
+
module ControllerTest
|
97
|
+
class PopulateController < Watirmark::WebPage::Controller
|
98
|
+
@view = TestView
|
99
|
+
end
|
100
|
+
end
|
101
|
+
ControllerTest::PopulateController.new(
|
102
|
+
:text_field=>'test',
|
103
|
+
:select_list=>'b',
|
104
|
+
:another_text_field => 'nil'
|
105
|
+
).populate_data
|
106
|
+
v = TestView.new
|
107
|
+
v.text_field.value.should == 'test'
|
108
|
+
v.select_list.value.should == 'b'
|
109
|
+
v.another_text_field.value.should == ''
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'should be be able to interpret use value' do
|
113
|
+
@controller.value(@keyed_element).should == 'foobar'
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'should support override method to value' do
|
117
|
+
class TestController
|
118
|
+
def text_field_value
|
119
|
+
'override'
|
120
|
+
end
|
121
|
+
end
|
122
|
+
@controller.value(Watirmark::KeyedElement.new(TestController.new, :keyword => @keyword)).should == 'override'
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should support override method for verification' do
|
126
|
+
def @controller.verify_text_field; 'verify'; end
|
127
|
+
@controller.expects(:verify_text_field).returns('verify').once
|
128
|
+
@controller.verify_data
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'should support keyword before and after methods' do
|
132
|
+
def @controller.before_text_field; 'before'; end
|
133
|
+
def @controller.after_text_field; 'after'; end
|
134
|
+
@controller.expects(:before_text_field).returns('before').once
|
135
|
+
@controller.expects(:after_text_field).returns('after').once
|
136
|
+
@controller.populate_data {}
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'should propogate page declaration to subclasses' do
|
140
|
+
TestControllerSubclass.view.should == TestView
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'should support before methods for process pages' do
|
144
|
+
c = TestProcessPageController.new({:a=>1, :b=>1, :c=>1, :d=>1})
|
145
|
+
def c.before_process_page_page_1; true; end
|
146
|
+
c.expects(:before_process_page_page_1).returns('true').once
|
147
|
+
c.populate_data
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'should throw a Watirmark::VerificationException when a verification fails' do
|
151
|
+
lambda {
|
152
|
+
VerifyController.new(:validate1 => '2').verify_data
|
153
|
+
}.should raise_error(Watirmark::VerificationException,"validate1: expected '2' (String) got '1' (String)")
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'should not throw an exception when a verification succeeds' do
|
157
|
+
VerifyController.new(:validate2 => 'a').verify_data
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'should not throw an exception when many verifications succeed' do
|
161
|
+
VerifyController.new(:validate1 => '1',:validate2 => 'a',:validate3 => 1.1).verify_data
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'should only throw one validation exception when there are 3 three problems' do
|
165
|
+
lambda {
|
166
|
+
VerifyController.new(:validate1 => 'z',:validate2 => 'y',:validate3 => 'x').verify_data
|
167
|
+
}.should raise_error(Watirmark::VerificationException)
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'should throw an exception when verifying a verify_keyword fails' do
|
171
|
+
lambda {
|
172
|
+
VerifyController.new(:label1 => 'text').verify_data
|
173
|
+
}.should raise_error(Watirmark::VerificationException,"label1: expected 'text' (String) got 'numbers' (String)")
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'should not throw an exception when verifying a verify_keyword succeeds' do
|
177
|
+
VerifyController.new(:label1 => 'numbers', :value1 => 1).verify_data
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'should not throw an exception when populating with a verify_keyword' do
|
181
|
+
VerifyController.new(:label1 => 'string').populate_data
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'should throw an exception when populating a populate_keyword fails' do
|
185
|
+
lambda {
|
186
|
+
VerifyController.new(:populate2 => '32').populate_data
|
187
|
+
}.should raise_error(NoMethodError)
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'should not throw an exception when populating a populate_keyword succeeds' do
|
191
|
+
VerifyController.new(:populate1 => '3.14159').populate_data
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'should not throw an exception when verifying with a populate_keyword' do
|
195
|
+
VerifyController.new(:populate1 => 'void').verify_data
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'should not populate a private_keyword successfully' do
|
199
|
+
c = VerifyController.new(:validate1 => 'hello')
|
200
|
+
c.populate_data
|
201
|
+
VerifyController.new(:private_validate1 => 'goodbye').populate_data
|
202
|
+
c.verify_data
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'should not verify a private_keyword successfully' do
|
206
|
+
c = VerifyController.new(:private_validate1 => 'hello')
|
207
|
+
VerifyController.new(:validate1 => 'goodbye').populate_data
|
208
|
+
c.verify_data
|
209
|
+
end
|
210
|
+
|
211
|
+
it 'should not throw an exception when populating or verifying a private_keyword fails' do
|
212
|
+
c = VerifyController.new(:private_validate1 => 'goodbye')
|
213
|
+
c.populate_data
|
214
|
+
c.model.update(:private_validate1 => 'hello')
|
215
|
+
c.verify_data
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'should not throw an exception when populating or verifying a navigation_keyword fails' do
|
219
|
+
c = VerifyController.new(:button1 => 'Cancel')
|
220
|
+
c.populate_data
|
221
|
+
c.model.update(:button1 => 'Submit')
|
222
|
+
c.verify_data
|
223
|
+
end
|
224
|
+
|
225
|
+
it 'false should be a valid keyword value' do
|
226
|
+
c = VerifyController.new(:checkbox => true)
|
227
|
+
c.populate_data
|
228
|
+
VerifyView.new.checkbox.set?.should be_true
|
229
|
+
c.model.update(:checkbox => false)
|
230
|
+
c.populate_data
|
231
|
+
VerifyView.new.checkbox.set?.should be_false
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
describe "controllers should be able to detect and use embedded models" do
|
236
|
+
before :all do
|
237
|
+
class MyView < Page
|
238
|
+
keyword(:element) {@@element}
|
239
|
+
end
|
240
|
+
@controller = Class.new Watirmark::WebPage::Controller do
|
241
|
+
@view = MyView
|
242
|
+
end
|
243
|
+
class User < Watirmark::Model::Factory
|
244
|
+
keywords :first_name
|
245
|
+
end
|
246
|
+
|
247
|
+
class Login < Watirmark::Model::Factory
|
248
|
+
keywords :first_name
|
249
|
+
end
|
250
|
+
|
251
|
+
class Password < Watirmark::Model::Factory
|
252
|
+
keywords :password
|
253
|
+
end
|
254
|
+
@password = Password.new
|
255
|
+
@login = Login.new
|
256
|
+
@login.add_model @password
|
257
|
+
@model = User.new(:first_name=> 'first')
|
258
|
+
@model.add_model @login
|
259
|
+
end
|
260
|
+
|
261
|
+
it 'should be able to see itself' do
|
262
|
+
@model.find(User).should == @model
|
263
|
+
end
|
264
|
+
|
265
|
+
it 'should be able to see a sub_model' do
|
266
|
+
@model.find(Login).should == @login
|
267
|
+
end
|
268
|
+
|
269
|
+
it 'should be able to see a nested sub_model' do
|
270
|
+
@model.find(Password).should == @password
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
describe "controllers should create a default model if one exists" do
|
275
|
+
before :all do
|
276
|
+
class MyView < Page
|
277
|
+
private_keyword(:element)
|
278
|
+
end
|
279
|
+
class MyModel < Watirmark::Model::Factory
|
280
|
+
keywords :element
|
281
|
+
end
|
282
|
+
@controller = Class.new Watirmark::WebPage::Controller do
|
283
|
+
@view = MyView
|
284
|
+
@model = MyModel
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
it 'should be able to see itself' do
|
289
|
+
c = @controller.new
|
290
|
+
c.model.should be_kind_of(MyModel)
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
|
295
|
+
describe "Similar Models" do
|
296
|
+
|
297
|
+
before :all do
|
298
|
+
class ProcessPageControllerView < Page
|
299
|
+
|
300
|
+
keyword(:a) {Element.new :a}
|
301
|
+
process_page('Page 1') do
|
302
|
+
keyword(:b) {Element.new :b}
|
303
|
+
end
|
304
|
+
process_page('Page 2') do
|
305
|
+
keyword(:c) { Element.new :c }
|
306
|
+
keyword(:d) { Element.new :d }
|
307
|
+
end
|
308
|
+
keyword(:e) { method :e }
|
309
|
+
keyword(:radio_map,
|
310
|
+
['M'] => 'male',
|
311
|
+
[/f/i] => 'female'
|
312
|
+
) { Page.browser.radio(:name, 'sex') }
|
313
|
+
end
|
314
|
+
|
315
|
+
class ModelA < Watirmark::Model::Factory
|
316
|
+
keywords ProcessPageControllerView.keywords
|
317
|
+
defaults do
|
318
|
+
radio_map { 'M' }
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
class ModelC < Watirmark::Model::Factory
|
323
|
+
keywords ProcessPageControllerView.keywords
|
324
|
+
model ModelA
|
325
|
+
end
|
326
|
+
|
327
|
+
class ModelB < Watirmark::Model::Factory
|
328
|
+
keywords ProcessPageControllerView.keywords
|
329
|
+
model_type ModelA
|
330
|
+
defaults do
|
331
|
+
radio_map { 'f' }
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
class ModelD < Watirmark::Model::Factory
|
336
|
+
keywords ProcessPageControllerView.keywords
|
337
|
+
model ModelB
|
338
|
+
end
|
339
|
+
|
340
|
+
class ModelE < Watirmark::Model::Factory
|
341
|
+
keywords ProcessPageControllerView.keywords
|
342
|
+
model ModelD
|
343
|
+
end
|
344
|
+
|
345
|
+
class ModelF < Watirmark::Model::Factory
|
346
|
+
keywords ProcessPageControllerView.keywords
|
347
|
+
model_type ModelA
|
348
|
+
end
|
349
|
+
|
350
|
+
class ModelG < Watirmark::Model::Factory
|
351
|
+
keywords ProcessPageControllerView.keywords
|
352
|
+
model ModelF
|
353
|
+
end
|
354
|
+
|
355
|
+
class ModelH < Watirmark::Model::Factory
|
356
|
+
keywords ProcessPageControllerView.keywords
|
357
|
+
end
|
358
|
+
|
359
|
+
class TestProcessPageController < Watirmark::WebPage::Controller
|
360
|
+
@model = ModelA
|
361
|
+
@view = ProcessPageControllerView
|
362
|
+
public :value
|
363
|
+
end
|
364
|
+
|
365
|
+
class TestNoModelController < Watirmark::WebPage::Controller
|
366
|
+
@view = ProcessPageControllerView
|
367
|
+
end
|
368
|
+
|
369
|
+
|
370
|
+
end
|
371
|
+
|
372
|
+
it 'should use the similar modelA' do
|
373
|
+
@controller = TestProcessPageController.new(ModelD.new)
|
374
|
+
@controller.model.should be_kind_of ModelB
|
375
|
+
@controller.supermodel.should be_kind_of ModelD
|
376
|
+
end
|
377
|
+
|
378
|
+
it 'should use the top model' do
|
379
|
+
@controller = TestProcessPageController.new(ModelB.new)
|
380
|
+
@controller.model.should be_kind_of ModelB
|
381
|
+
@controller.supermodel.should be_kind_of ModelB
|
382
|
+
end
|
383
|
+
|
384
|
+
it 'should use parent model' do
|
385
|
+
@controller = TestProcessPageController.new(ModelC.new)
|
386
|
+
@controller.model.should be_kind_of ModelA
|
387
|
+
@controller.supermodel.should be_kind_of ModelC
|
388
|
+
end
|
389
|
+
|
390
|
+
it 'should call the smallest child similar to the model in controller' do
|
391
|
+
@controller = TestProcessPageController.new(ModelE.new)
|
392
|
+
@controller.model.should be_kind_of ModelB
|
393
|
+
@controller.supermodel.should be_kind_of ModelE
|
394
|
+
|
395
|
+
end
|
396
|
+
|
397
|
+
it 'should select the correct model when base model has 2 similar models' do
|
398
|
+
@controller = TestProcessPageController.new(ModelG.new)
|
399
|
+
@controller.model.should be_kind_of ModelF
|
400
|
+
@controller.supermodel.should be_kind_of ModelG
|
401
|
+
|
402
|
+
@controller = TestProcessPageController.new(ModelF.new)
|
403
|
+
@controller.model.should be_kind_of ModelF
|
404
|
+
@controller.supermodel.should be_kind_of ModelF
|
405
|
+
end
|
406
|
+
|
407
|
+
it 'should use the supermodel as a model if a controller model is not defined' do
|
408
|
+
@controller = TestNoModelController.new(ModelE.new)
|
409
|
+
@controller.model.should be_kind_of ModelE
|
410
|
+
@controller.supermodel.should be_kind_of ModelE
|
411
|
+
end
|
412
|
+
|
413
|
+
it 'should use passed in model as @model when model_type is not defined' do
|
414
|
+
@controller = TestProcessPageController.new(ModelH.new)
|
415
|
+
@controller.model.should be_kind_of ModelH
|
416
|
+
@controller.supermodel.should be_kind_of ModelH
|
417
|
+
end
|
418
|
+
|
419
|
+
it 'should allow us to override the default model' do
|
420
|
+
@controller = TestProcessPageController.new(ModelH.new)
|
421
|
+
@controller.model.should be_kind_of ModelH
|
422
|
+
@controller.model = ModelA.new
|
423
|
+
@controller.model.should be_kind_of ModelA
|
424
|
+
end
|
425
|
+
|
426
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
describe "controllers should be able to detect and use embedded models" do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
class MyView < Page
|
7
|
+
keyword(:element) {}
|
8
|
+
end
|
9
|
+
class CMUser < Watirmark::Model::Factory
|
10
|
+
keywords :first_name
|
11
|
+
end
|
12
|
+
class CMLogin < Watirmark::Model::Factory
|
13
|
+
keywords :username
|
14
|
+
end
|
15
|
+
class CMPassword < Watirmark::Model::Factory
|
16
|
+
keywords :password
|
17
|
+
end
|
18
|
+
@password = CMPassword.new
|
19
|
+
@login = CMLogin.new
|
20
|
+
@login.add_model @password
|
21
|
+
@user = CMUser.new
|
22
|
+
@user.add_model @login
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should be able to see itself' do
|
26
|
+
controller = Class.new Watirmark::WebPage::Controller do
|
27
|
+
@model = CMUser
|
28
|
+
@view = MyView
|
29
|
+
end
|
30
|
+
controller.new(@user).model.should == @user
|
31
|
+
controller.new(@user).model.should_not == @login
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should be able to find a nested model on initialization' do
|
35
|
+
controller = Class.new Watirmark::WebPage::Controller do
|
36
|
+
@model = CMLogin
|
37
|
+
@view = MyView
|
38
|
+
end
|
39
|
+
controller.new(@user).model.should_not == @user
|
40
|
+
controller.new(@user).model.should == @login
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should be able to find a deeply nested model on initialization' do
|
44
|
+
controller = Class.new Watirmark::WebPage::Controller do
|
45
|
+
@model = CMPassword
|
46
|
+
@view = MyView
|
47
|
+
end
|
48
|
+
controller.new(@user).model.should_not == @user
|
49
|
+
controller.new(@user).model.should_not == @login
|
50
|
+
controller.new(@user).model.should == @password
|
51
|
+
end
|
52
|
+
end
|