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,172 @@
|
|
1
|
+
module Watirmark
|
2
|
+
module Actions
|
3
|
+
|
4
|
+
attr_accessor :records
|
5
|
+
|
6
|
+
def run(*actions)
|
7
|
+
begin
|
8
|
+
run_callback_method :before_all
|
9
|
+
record_list.each do |record|
|
10
|
+
create_model_if_hash(record)
|
11
|
+
execute_actions(actions)
|
12
|
+
end
|
13
|
+
run_callback_method :after_all
|
14
|
+
ensure
|
15
|
+
clear_record_list
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def search_for_record
|
20
|
+
if @search
|
21
|
+
search_controller = @search.new(@supermodel)
|
22
|
+
if search_controller.respond_to?(:current_record_visible?)
|
23
|
+
return if search_controller.current_record_visible?
|
24
|
+
end
|
25
|
+
search_controller.create
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Navigate to the View's edit page and for every value in
|
30
|
+
# the models hash, verify that the html element has
|
31
|
+
# the proper value for each keyword
|
32
|
+
def verify
|
33
|
+
search_for_record
|
34
|
+
@view.edit @model
|
35
|
+
verify_data
|
36
|
+
end
|
37
|
+
|
38
|
+
# Navigate to the View's edit page and
|
39
|
+
# verify all values in the models hash
|
40
|
+
def edit
|
41
|
+
search_for_record
|
42
|
+
@view.edit @model
|
43
|
+
populate_data
|
44
|
+
end
|
45
|
+
|
46
|
+
# Navigate to the View's create page and
|
47
|
+
# populate with values from the models hash
|
48
|
+
def create
|
49
|
+
@view.create @model
|
50
|
+
populate_data
|
51
|
+
end
|
52
|
+
|
53
|
+
def verify_until(&block)
|
54
|
+
run_with_stop_condition(:verify, block)
|
55
|
+
end
|
56
|
+
|
57
|
+
def edit_until(&block)
|
58
|
+
run_with_stop_condition(:edit, block)
|
59
|
+
end
|
60
|
+
|
61
|
+
def create_until(&block)
|
62
|
+
run_with_stop_condition(:create, block)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Navigate to the View's create page and
|
66
|
+
# populate with values from the models hash
|
67
|
+
def get
|
68
|
+
unless @view.exists? @model
|
69
|
+
@view.create @model
|
70
|
+
populate_data
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def delete
|
75
|
+
@view.delete @model
|
76
|
+
end
|
77
|
+
|
78
|
+
def copy
|
79
|
+
@view.copy @model
|
80
|
+
end
|
81
|
+
|
82
|
+
def restore
|
83
|
+
@view.restore @model
|
84
|
+
end
|
85
|
+
|
86
|
+
def archive
|
87
|
+
@view.archive @model
|
88
|
+
end
|
89
|
+
|
90
|
+
def publish
|
91
|
+
@view.publish @model
|
92
|
+
end
|
93
|
+
|
94
|
+
def unpublish
|
95
|
+
@view.unpublish @model
|
96
|
+
end
|
97
|
+
|
98
|
+
def activate
|
99
|
+
@view.activate @model
|
100
|
+
end
|
101
|
+
|
102
|
+
def deactivate
|
103
|
+
@view.deactivate @model
|
104
|
+
end
|
105
|
+
|
106
|
+
def locate_record
|
107
|
+
@view.locate_record @model
|
108
|
+
end
|
109
|
+
|
110
|
+
# Navigate to the View's create page and verify
|
111
|
+
# against the models hash. This is useful for making
|
112
|
+
# sure that the create page has the proper default
|
113
|
+
# values and contains the proper elements
|
114
|
+
def check_defaults
|
115
|
+
@view.create @model
|
116
|
+
verify_data
|
117
|
+
end
|
118
|
+
alias :check_create_defaults :check_defaults
|
119
|
+
|
120
|
+
|
121
|
+
# A helper function for translating a string into a
|
122
|
+
# pattern match for the beginning of a string
|
123
|
+
def starts_with(x)
|
124
|
+
/^#{Regexp.escape(x)}/
|
125
|
+
end
|
126
|
+
|
127
|
+
# Stubs so converted XLS->RSPEC files don't fail
|
128
|
+
def before_all; end
|
129
|
+
def before_each; end
|
130
|
+
def after_all; end
|
131
|
+
def after_each; end
|
132
|
+
|
133
|
+
private
|
134
|
+
|
135
|
+
def run_with_stop_condition(method, block)
|
136
|
+
catch :stop_condition_met do
|
137
|
+
begin
|
138
|
+
Watirmark::Session.instance.stop_condition_block = block
|
139
|
+
send(method)
|
140
|
+
ensure
|
141
|
+
Watirmark::Session.instance.stop_condition_block = Proc.new{}
|
142
|
+
end
|
143
|
+
raise Watirmark::TestError, "Expected a stop condition but no stop conditon met!"
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def record_list
|
148
|
+
@records << @model if records.empty?
|
149
|
+
@records
|
150
|
+
end
|
151
|
+
|
152
|
+
def clear_record_list
|
153
|
+
@records = []
|
154
|
+
end
|
155
|
+
|
156
|
+
def run_callback_method name
|
157
|
+
send name if respond_to?(name)
|
158
|
+
end
|
159
|
+
|
160
|
+
def execute_actions(actions)
|
161
|
+
actions.each do |action|
|
162
|
+
run_callback_method :before_each
|
163
|
+
send(action)
|
164
|
+
run_callback_method :after_each
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def create_model_if_hash(model)
|
169
|
+
@model = hash_to_model(model) if model.kind_of?(Hash)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
module Watirmark
|
2
|
+
module Assertions
|
3
|
+
|
4
|
+
private
|
5
|
+
|
6
|
+
def assert_equal(element, expected)
|
7
|
+
return if expected.nil?
|
8
|
+
|
9
|
+
element.extend KeywordMethods
|
10
|
+
if map = element.radio_map
|
11
|
+
expected = map.lookup(expected)
|
12
|
+
end
|
13
|
+
|
14
|
+
actual = actual_value element, expected
|
15
|
+
compare_values(element, expected, actual)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns the user visible value of the element.
|
19
|
+
def actual_value element, expected=nil
|
20
|
+
case element
|
21
|
+
when Watir::Select
|
22
|
+
element.selected_options.first.text
|
23
|
+
when Watir::CheckBox
|
24
|
+
element.set?
|
25
|
+
when Watir::Radio
|
26
|
+
if element.set?(expected)
|
27
|
+
expected
|
28
|
+
else
|
29
|
+
element.value
|
30
|
+
end
|
31
|
+
when Watir::TextField
|
32
|
+
element.value
|
33
|
+
else
|
34
|
+
if element.respond_to?(:value) && element.value != ''
|
35
|
+
element.value
|
36
|
+
else
|
37
|
+
element.text
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def assert(result)
|
43
|
+
unless result
|
44
|
+
raise Watirmark::VerificationException, "Expected true got #{result}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def compare_values(element, expected, actual)
|
49
|
+
if Matcher.exists?(expected)
|
50
|
+
fail(element, expected, actual) unless Matcher.matches?(element, expected, actual)
|
51
|
+
else
|
52
|
+
fail(element, expected, actual) unless matches?(expected, actual)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def fail(element, expected, actual)
|
57
|
+
error = Watirmark::VerificationException.new(error_message(element, expected, actual))
|
58
|
+
error.actual = actual
|
59
|
+
error.expected = expected
|
60
|
+
raise error
|
61
|
+
end
|
62
|
+
|
63
|
+
def error_message(element, expected, actual)
|
64
|
+
kwd = element.keyword if element.respond_to?(:keyword)
|
65
|
+
message = "#{ kwd || element.class}: expected '#{expected.to_s}' (#{expected.class})"
|
66
|
+
message += " got '#{actual.to_s}' (#{actual.class})"
|
67
|
+
end
|
68
|
+
|
69
|
+
def is_number?(object)
|
70
|
+
true if Float(object) rescue false
|
71
|
+
end
|
72
|
+
|
73
|
+
def matches?(expected, actual)
|
74
|
+
expected = expected.to_f if is_number?(expected)
|
75
|
+
case expected
|
76
|
+
when Regexp
|
77
|
+
should_match_regexp(expected, actual)
|
78
|
+
when Float, Fixnum, Bignum, Integer, Rational
|
79
|
+
should_match_number(expected, actual)
|
80
|
+
else
|
81
|
+
if normalize_value(expected.to_s) == normalize_value(actual.to_s)
|
82
|
+
true
|
83
|
+
else
|
84
|
+
false
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def normalize_value(x)
|
90
|
+
result = x.dup
|
91
|
+
if result.strip != ''
|
92
|
+
result.gsub!("\r\n","\n")
|
93
|
+
result.strip!
|
94
|
+
end
|
95
|
+
|
96
|
+
# handle dates
|
97
|
+
if result =~ /^[0-9]{1,2}[-\/][0-9]{1,2}[-\/][0-9]{2,4}$/ || result =~ /^[0-9]{2,4}[-\/][0-9]{1,2}[-\/][0-9]{1,2}$/ # translate dates to a Date object
|
98
|
+
result = Date.parse(result)
|
99
|
+
end
|
100
|
+
|
101
|
+
# strip sign from dollar amounts
|
102
|
+
if result =~ /^\$([\d\.]+)/
|
103
|
+
result = $1
|
104
|
+
end
|
105
|
+
result
|
106
|
+
end
|
107
|
+
|
108
|
+
def should_match_regexp(expected, actual)
|
109
|
+
expected.matches(actual.to_s)
|
110
|
+
end
|
111
|
+
|
112
|
+
def should_match_number(expected, actual)
|
113
|
+
expected == actual.to_s.gsub(/[,$]/,'').to_f
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,191 @@
|
|
1
|
+
require 'watirmark/controller/actions'
|
2
|
+
require 'watirmark/controller/dialogs'
|
3
|
+
require 'watirmark/controller/assertions'
|
4
|
+
require 'watirmark/controller/matcher'
|
5
|
+
|
6
|
+
module Watirmark
|
7
|
+
module WebPage
|
8
|
+
|
9
|
+
class Controller
|
10
|
+
attr_reader :model, :supermodel
|
11
|
+
include Watirmark::Assertions
|
12
|
+
include Watirmark::Dialogs
|
13
|
+
include Watirmark::Actions
|
14
|
+
|
15
|
+
class << self
|
16
|
+
attr_accessor :view, :model, :search
|
17
|
+
|
18
|
+
def inherited(klass)
|
19
|
+
klass.view ||= @view if @view
|
20
|
+
klass.model ||= @model if @model
|
21
|
+
klass.search ||= @search if @search
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(data = {})
|
26
|
+
initialize_model(data)
|
27
|
+
@records ||= []
|
28
|
+
@cache = {}
|
29
|
+
@view = self.class.view.new browser if self.class.view
|
30
|
+
@search = self.class.search
|
31
|
+
end
|
32
|
+
|
33
|
+
def browser
|
34
|
+
Page.browser
|
35
|
+
end
|
36
|
+
|
37
|
+
def model=(data)
|
38
|
+
initialize_model(data)
|
39
|
+
end
|
40
|
+
|
41
|
+
def populate_data
|
42
|
+
submit_process_page(@last_process_page.underscored_name) {submit} if populate_values
|
43
|
+
end
|
44
|
+
|
45
|
+
def populate_values
|
46
|
+
@seen_value = false
|
47
|
+
@last_process_page = nil
|
48
|
+
keyed_elements.each do |k|
|
49
|
+
next unless k.populate_allowed?
|
50
|
+
submit_process_page_when_page_changes(k)
|
51
|
+
before_process_page(k)
|
52
|
+
populate_keyword(k)
|
53
|
+
end
|
54
|
+
@seen_value
|
55
|
+
end
|
56
|
+
|
57
|
+
def verify_data
|
58
|
+
@verification_errors = []
|
59
|
+
keyed_elements.each { |k| verify_keyword(k) if k.verify_allowed? }
|
60
|
+
raise Watirmark::VerificationException, @verification_errors.join("\n ") unless @verification_errors.empty?
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def initialize_model(x)
|
66
|
+
@supermodel = x
|
67
|
+
@model = locate_model @supermodel
|
68
|
+
end
|
69
|
+
|
70
|
+
def populate_keyword(keyed_element)
|
71
|
+
begin
|
72
|
+
@seen_value = true
|
73
|
+
before_keyword(keyed_element)
|
74
|
+
populate_keyword_value(keyed_element)
|
75
|
+
after_keyword(keyed_element)
|
76
|
+
rescue => e
|
77
|
+
Watirmark.logger.warn "Unable to populate '#{keyed_element.keyword}'"
|
78
|
+
raise e
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def verify_keyword(keyed_element)
|
83
|
+
begin
|
84
|
+
verify_keyword_value(keyed_element)
|
85
|
+
rescue Watirmark::VerificationException => e
|
86
|
+
@verification_errors.push e.to_s
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def submit_process_page_when_page_changes(keyed_element)
|
91
|
+
return unless process_page_changed?(keyed_element) && @seen_value
|
92
|
+
if @last_process_page
|
93
|
+
submit_process_page(@last_process_page.underscored_name) {@view.process_page(@last_process_page.name).submit}
|
94
|
+
else
|
95
|
+
@view.process_page(@view.to_s).submit
|
96
|
+
end
|
97
|
+
@seen_value = false
|
98
|
+
end
|
99
|
+
|
100
|
+
def call_method_if_exists(override, &block)
|
101
|
+
if respond_to?(override)
|
102
|
+
send(override)
|
103
|
+
else
|
104
|
+
block.call if block
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def process_page_defined?(keyed_element)
|
109
|
+
!keyed_element.process_page.underscored_name.empty?
|
110
|
+
end
|
111
|
+
|
112
|
+
def process_page_changed?(keyed_element)
|
113
|
+
!!(@last_process_page && @last_process_page.underscored_name != keyed_element.process_page.underscored_name)
|
114
|
+
end
|
115
|
+
|
116
|
+
def before_keyword(keyed_element)
|
117
|
+
call_method_if_exists("before_#{keyed_element.keyword}")
|
118
|
+
end
|
119
|
+
|
120
|
+
def after_keyword(keyed_element)
|
121
|
+
call_method_if_exists("after_#{keyed_element.keyword}")
|
122
|
+
end
|
123
|
+
|
124
|
+
def populate_keyword_value(keyed_element)
|
125
|
+
call_method_if_exists("populate_#{keyed_element.keyword}") {@view.send("#{keyed_element.keyword}=", value(keyed_element))}
|
126
|
+
end
|
127
|
+
|
128
|
+
def verify_keyword_value(keyed_element)
|
129
|
+
call_method_if_exists("verify_#{keyed_element.keyword}") {assert_equal(keyed_element.get, value(keyed_element))}
|
130
|
+
end
|
131
|
+
|
132
|
+
def keyword_value(keyed_element)
|
133
|
+
call_method_if_exists("#{keyed_element.keyword}_value") {@model.send(keyed_element.keyword)}
|
134
|
+
end
|
135
|
+
|
136
|
+
def before_process_page(keyed_element)
|
137
|
+
if process_page_defined?(keyed_element) && (@last_process_page.nil? || process_page_changed?(keyed_element))
|
138
|
+
call_method_if_exists("before_process_page_#{keyed_element.process_page.underscored_name}")
|
139
|
+
end
|
140
|
+
@last_process_page = keyed_element.process_page
|
141
|
+
end
|
142
|
+
|
143
|
+
def submit_process_page(name, &block)
|
144
|
+
call_method_if_exists("submit_process_page_#{name}", &block)
|
145
|
+
end
|
146
|
+
|
147
|
+
def value(keyed_element)
|
148
|
+
@cache[keyed_element] ||= keyword_value(keyed_element)
|
149
|
+
end
|
150
|
+
|
151
|
+
def keyed_elements
|
152
|
+
@cache = {}
|
153
|
+
@view.keyed_elements.select{|e| !value(e).nil?}
|
154
|
+
end
|
155
|
+
|
156
|
+
def locate_model(supermodel)
|
157
|
+
case supermodel
|
158
|
+
when Hash
|
159
|
+
if self.class.model
|
160
|
+
self.class.model.new supermodel
|
161
|
+
else
|
162
|
+
hash_to_model supermodel
|
163
|
+
end
|
164
|
+
else
|
165
|
+
if self.class.model
|
166
|
+
if supermodel.model_type == self.class.model
|
167
|
+
supermodel
|
168
|
+
else
|
169
|
+
supermodel.find(self.class.model) || supermodel
|
170
|
+
end
|
171
|
+
else
|
172
|
+
supermodel
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
# This is for legacy tests that still pass in a hash. We
|
178
|
+
# convert these to models fo now
|
179
|
+
def hash_to_model(hash)
|
180
|
+
model = ModelOpenStruct.new
|
181
|
+
hash.each_pair { |key, value| model.send "#{key}=", value }
|
182
|
+
model
|
183
|
+
end
|
184
|
+
|
185
|
+
def submit
|
186
|
+
Watirmark.logger.warn "Unable to automatically post form. Please defined a submit method in your controller"
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
191
|
+
end
|