ule_page 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a76894846c5bd583de39543deecbb40eae87f4fc
4
- data.tar.gz: 8cbd3f6fdb1bdea531337ee97c34a48db352b353
2
+ SHA256:
3
+ metadata.gz: 98f5e46718aa9e16727ff68419740fece7b75bdcd59c61dc643426676dc4bb28
4
+ data.tar.gz: cacd0c752462cbe6fee4ec0b91985df6a21c1ffc18efb053cb9f5eef0449942f
5
5
  SHA512:
6
- metadata.gz: ed8325b68d9ab0bdee52c1001460d674c7f4d15481fb2c55b767dc0b05031ef65353cb13592b3b08e9c27454ea46be7735841057161080d3526c8d1990b52ca0
7
- data.tar.gz: 94e88249626fd015e6e4ee9ddfe07ae80b137265f646987bf956869b41ff8f3f01d980cf6d56bb0568d5f64d8c370c1b090932bfc8589070ffc1248882c62730
6
+ metadata.gz: 2de80281e8d32e208a10a0365f330fcc69353bf0710ab00b634f7dd4d5f423e232cd01d65836e2f6d0e4f249ad02735e545dd9ff84cd07e6250ecea4a92d753f
7
+ data.tar.gz: c215be5ca5856ac7ba89418a7a7e2aa7e07b33d4fe797ce1a801d94ef76ad33288e0ed29210c92ce034b74631c22c6cf45b66a23ab46999a2868444dee20237f
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ule_page (0.1.0)
4
+ ule_page (0.2.0)
5
5
  activerecord (> 4.0)
6
6
  activesupport (> 4.0)
7
7
  capybara (>= 2.1, < 3.0)
@@ -11,161 +11,220 @@ PATH
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
- actionmailer (4.2.5.1)
15
- actionpack (= 4.2.5.1)
16
- actionview (= 4.2.5.1)
17
- activejob (= 4.2.5.1)
14
+ actioncable (6.1.0)
15
+ actionpack (= 6.1.0)
16
+ activesupport (= 6.1.0)
17
+ nio4r (~> 2.0)
18
+ websocket-driver (>= 0.6.1)
19
+ actionmailbox (6.1.0)
20
+ actionpack (= 6.1.0)
21
+ activejob (= 6.1.0)
22
+ activerecord (= 6.1.0)
23
+ activestorage (= 6.1.0)
24
+ activesupport (= 6.1.0)
25
+ mail (>= 2.7.1)
26
+ actionmailer (6.1.0)
27
+ actionpack (= 6.1.0)
28
+ actionview (= 6.1.0)
29
+ activejob (= 6.1.0)
30
+ activesupport (= 6.1.0)
18
31
  mail (~> 2.5, >= 2.5.4)
19
- rails-dom-testing (~> 1.0, >= 1.0.5)
20
- actionpack (4.2.5.1)
21
- actionview (= 4.2.5.1)
22
- activesupport (= 4.2.5.1)
23
- rack (~> 1.6)
24
- rack-test (~> 0.6.2)
25
- rails-dom-testing (~> 1.0, >= 1.0.5)
26
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
27
- actionview (4.2.5.1)
28
- activesupport (= 4.2.5.1)
32
+ rails-dom-testing (~> 2.0)
33
+ actionpack (6.1.0)
34
+ actionview (= 6.1.0)
35
+ activesupport (= 6.1.0)
36
+ rack (~> 2.0, >= 2.0.9)
37
+ rack-test (>= 0.6.3)
38
+ rails-dom-testing (~> 2.0)
39
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
40
+ actiontext (6.1.0)
41
+ actionpack (= 6.1.0)
42
+ activerecord (= 6.1.0)
43
+ activestorage (= 6.1.0)
44
+ activesupport (= 6.1.0)
45
+ nokogiri (>= 1.8.5)
46
+ actionview (6.1.0)
47
+ activesupport (= 6.1.0)
29
48
  builder (~> 3.1)
30
- erubis (~> 2.7.0)
31
- rails-dom-testing (~> 1.0, >= 1.0.5)
32
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
33
- activejob (4.2.5.1)
34
- activesupport (= 4.2.5.1)
35
- globalid (>= 0.3.0)
36
- activemodel (4.2.5.1)
37
- activesupport (= 4.2.5.1)
38
- builder (~> 3.1)
39
- activerecord (4.2.5.1)
40
- activemodel (= 4.2.5.1)
41
- activesupport (= 4.2.5.1)
42
- arel (~> 6.0)
43
- activesupport (4.2.5.1)
44
- i18n (~> 0.7)
45
- json (~> 1.7, >= 1.7.7)
46
- minitest (~> 5.1)
47
- thread_safe (~> 0.3, >= 0.3.4)
48
- tzinfo (~> 1.1)
49
- addressable (2.4.0)
50
- arel (6.0.3)
51
- builder (3.2.2)
52
- capybara (2.6.2)
49
+ erubi (~> 1.4)
50
+ rails-dom-testing (~> 2.0)
51
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
52
+ activejob (6.1.0)
53
+ activesupport (= 6.1.0)
54
+ globalid (>= 0.3.6)
55
+ activemodel (6.1.0)
56
+ activesupport (= 6.1.0)
57
+ activerecord (6.1.0)
58
+ activemodel (= 6.1.0)
59
+ activesupport (= 6.1.0)
60
+ activestorage (6.1.0)
61
+ actionpack (= 6.1.0)
62
+ activejob (= 6.1.0)
63
+ activerecord (= 6.1.0)
64
+ activesupport (= 6.1.0)
65
+ marcel (~> 0.3.1)
66
+ mimemagic (~> 0.3.2)
67
+ activesupport (6.1.0)
68
+ concurrent-ruby (~> 1.0, >= 1.0.2)
69
+ i18n (>= 1.6, < 2)
70
+ minitest (>= 5.1)
71
+ tzinfo (~> 2.0)
72
+ zeitwerk (~> 2.3)
73
+ addressable (2.7.0)
74
+ public_suffix (>= 2.0.2, < 5.0)
75
+ builder (3.2.4)
76
+ capybara (2.18.0)
53
77
  addressable
54
- mime-types (>= 1.16)
78
+ mini_mime (>= 0.1.3)
55
79
  nokogiri (>= 1.3.3)
56
80
  rack (>= 1.0.0)
57
81
  rack-test (>= 0.5.4)
58
- xpath (~> 2.0)
59
- concurrent-ruby (1.0.0)
60
- coveralls (0.8.13)
61
- json (~> 1.8)
62
- simplecov (~> 0.11.0)
63
- term-ansicolor (~> 1.3)
64
- thor (~> 0.19.1)
65
- tins (~> 1.6.0)
82
+ xpath (>= 2.0, < 4.0)
83
+ concurrent-ruby (1.1.7)
84
+ coveralls (0.7.1)
85
+ multi_json (~> 1.3)
86
+ rest-client
87
+ simplecov (>= 0.7)
88
+ term-ansicolor
89
+ thor
90
+ crass (1.0.6)
66
91
  cucumber (1.3.20)
67
92
  builder (>= 2.1.2)
68
93
  diff-lcs (>= 1.1.3)
69
94
  gherkin (~> 2.12)
70
95
  multi_json (>= 1.7.5, < 2.0)
71
96
  multi_test (>= 0.1.2)
72
- diff-lcs (1.2.5)
73
- docile (1.1.5)
74
- erubis (2.7.0)
97
+ diff-lcs (1.4.4)
98
+ docile (1.3.4)
99
+ domain_name (0.5.20190701)
100
+ unf (>= 0.0.5, < 1.0.0)
101
+ erubi (1.10.0)
75
102
  gherkin (2.12.2)
76
103
  multi_json (~> 1.3)
77
- globalid (0.3.6)
78
- activesupport (>= 4.1.0)
79
- i18n (0.7.0)
80
- json (1.8.3)
81
- loofah (2.0.3)
104
+ globalid (0.4.2)
105
+ activesupport (>= 4.2.0)
106
+ http-accept (1.7.0)
107
+ http-cookie (1.0.3)
108
+ domain_name (~> 0.5)
109
+ i18n (1.8.5)
110
+ concurrent-ruby (~> 1.0)
111
+ loofah (2.8.0)
112
+ crass (~> 1.0.2)
82
113
  nokogiri (>= 1.5.9)
83
- mail (2.6.3)
84
- mime-types (>= 1.16, < 3)
85
- mime-types (2.4.3)
86
- mini_portile2 (2.0.0)
87
- minitest (5.8.4)
88
- multi_json (1.11.2)
114
+ mail (2.7.1)
115
+ mini_mime (>= 0.1.1)
116
+ marcel (0.3.3)
117
+ mimemagic (~> 0.3.2)
118
+ method_source (1.0.0)
119
+ mime-types (3.3.1)
120
+ mime-types-data (~> 3.2015)
121
+ mime-types-data (3.2020.1104)
122
+ mimemagic (0.3.5)
123
+ mini_mime (1.0.2)
124
+ mini_portile2 (2.4.0)
125
+ minitest (5.14.2)
126
+ multi_json (1.15.0)
89
127
  multi_test (0.1.2)
90
- nokogiri (1.6.7.2)
91
- mini_portile2 (~> 2.0.0.rc2)
92
- rack (1.6.4)
93
- rack-test (0.6.3)
94
- rack (>= 1.0)
95
- rails (4.2.5.1)
96
- actionmailer (= 4.2.5.1)
97
- actionpack (= 4.2.5.1)
98
- actionview (= 4.2.5.1)
99
- activejob (= 4.2.5.1)
100
- activemodel (= 4.2.5.1)
101
- activerecord (= 4.2.5.1)
102
- activesupport (= 4.2.5.1)
103
- bundler (>= 1.3.0, < 2.0)
104
- railties (= 4.2.5.1)
105
- sprockets-rails
106
- rails-deprecated_sanitizer (1.0.3)
107
- activesupport (>= 4.2.0.alpha)
108
- rails-dom-testing (1.0.7)
109
- activesupport (>= 4.2.0.beta, < 5.0)
110
- nokogiri (~> 1.6.0)
111
- rails-deprecated_sanitizer (>= 1.0.1)
112
- rails-html-sanitizer (1.0.3)
113
- loofah (~> 2.0)
114
- railties (4.2.5.1)
115
- actionpack (= 4.2.5.1)
116
- activesupport (= 4.2.5.1)
128
+ netrc (0.11.0)
129
+ nio4r (2.5.4)
130
+ nokogiri (1.10.10)
131
+ mini_portile2 (~> 2.4.0)
132
+ public_suffix (4.0.6)
133
+ rack (2.2.3)
134
+ rack-test (1.1.0)
135
+ rack (>= 1.0, < 3)
136
+ rails (6.1.0)
137
+ actioncable (= 6.1.0)
138
+ actionmailbox (= 6.1.0)
139
+ actionmailer (= 6.1.0)
140
+ actionpack (= 6.1.0)
141
+ actiontext (= 6.1.0)
142
+ actionview (= 6.1.0)
143
+ activejob (= 6.1.0)
144
+ activemodel (= 6.1.0)
145
+ activerecord (= 6.1.0)
146
+ activestorage (= 6.1.0)
147
+ activesupport (= 6.1.0)
148
+ bundler (>= 1.15.0)
149
+ railties (= 6.1.0)
150
+ sprockets-rails (>= 2.0.0)
151
+ rails-dom-testing (2.0.3)
152
+ activesupport (>= 4.2.0)
153
+ nokogiri (>= 1.6)
154
+ rails-html-sanitizer (1.3.0)
155
+ loofah (~> 2.3)
156
+ railties (6.1.0)
157
+ actionpack (= 6.1.0)
158
+ activesupport (= 6.1.0)
159
+ method_source
117
160
  rake (>= 0.8.7)
118
- thor (>= 0.18.1, < 2.0)
161
+ thor (~> 1.0)
119
162
  rake (10.5.0)
120
- rspec (3.4.0)
121
- rspec-core (~> 3.4.0)
122
- rspec-expectations (~> 3.4.0)
123
- rspec-mocks (~> 3.4.0)
124
- rspec-core (3.4.2)
125
- rspec-support (~> 3.4.0)
126
- rspec-expectations (3.4.0)
163
+ rest-client (2.1.0)
164
+ http-accept (>= 1.7.0, < 2.0)
165
+ http-cookie (>= 1.0.2, < 2.0)
166
+ mime-types (>= 1.16, < 4.0)
167
+ netrc (~> 0.8)
168
+ rspec (3.10.0)
169
+ rspec-core (~> 3.10.0)
170
+ rspec-expectations (~> 3.10.0)
171
+ rspec-mocks (~> 3.10.0)
172
+ rspec-core (3.10.1)
173
+ rspec-support (~> 3.10.0)
174
+ rspec-expectations (3.10.1)
127
175
  diff-lcs (>= 1.2.0, < 2.0)
128
- rspec-support (~> 3.4.0)
129
- rspec-its (1.2.0)
176
+ rspec-support (~> 3.10.0)
177
+ rspec-its (1.3.0)
130
178
  rspec-core (>= 3.0.0)
131
179
  rspec-expectations (>= 3.0.0)
132
- rspec-mocks (3.4.1)
180
+ rspec-mocks (3.10.1)
133
181
  diff-lcs (>= 1.2.0, < 2.0)
134
- rspec-support (~> 3.4.0)
135
- rspec-rails (3.4.0)
136
- actionpack (>= 3.0, < 4.3)
137
- activesupport (>= 3.0, < 4.3)
138
- railties (>= 3.0, < 4.3)
139
- rspec-core (~> 3.4.0)
140
- rspec-expectations (~> 3.4.0)
141
- rspec-mocks (~> 3.4.0)
142
- rspec-support (~> 3.4.0)
143
- rspec-support (3.4.1)
144
- simplecov (0.11.2)
145
- docile (~> 1.1.0)
146
- json (~> 1.8)
147
- simplecov-html (~> 0.10.0)
148
- simplecov-html (0.10.0)
149
- site_prism (2.8)
150
- addressable (>= 2.3.3, < 3.0)
151
- capybara (>= 2.1, < 3.0)
152
- sprockets (3.5.2)
182
+ rspec-support (~> 3.10.0)
183
+ rspec-rails (4.0.2)
184
+ actionpack (>= 4.2)
185
+ activesupport (>= 4.2)
186
+ railties (>= 4.2)
187
+ rspec-core (~> 3.10)
188
+ rspec-expectations (~> 3.10)
189
+ rspec-mocks (~> 3.10)
190
+ rspec-support (~> 3.10)
191
+ rspec-support (3.10.1)
192
+ simplecov (0.20.0)
193
+ docile (~> 1.1)
194
+ simplecov-html (~> 0.11)
195
+ simplecov_json_formatter (~> 0.1)
196
+ simplecov-html (0.12.3)
197
+ simplecov_json_formatter (0.1.2)
198
+ site_prism (3.5)
199
+ addressable (~> 2.5)
200
+ capybara (<= 3.29)
201
+ site_prism-all_there (>= 0.3.1, < 1.0)
202
+ site_prism-all_there (0.3.2)
203
+ sprockets (4.0.2)
153
204
  concurrent-ruby (~> 1.0)
154
205
  rack (> 1, < 3)
155
- sprockets-rails (3.0.1)
206
+ sprockets-rails (3.2.2)
156
207
  actionpack (>= 4.0)
157
208
  activesupport (>= 4.0)
158
209
  sprockets (>= 3.0.0)
159
- term-ansicolor (1.3.2)
210
+ sync (0.5.0)
211
+ term-ansicolor (1.7.1)
160
212
  tins (~> 1.0)
161
- thor (0.19.1)
162
- thread_safe (0.3.5)
163
- tins (1.6.0)
164
- tzinfo (1.2.2)
165
- thread_safe (~> 0.1)
166
- xpath (2.0.0)
167
- nokogiri (~> 1.3)
168
- yard (0.8.7.6)
213
+ thor (1.0.1)
214
+ tins (1.26.0)
215
+ sync
216
+ tzinfo (2.0.4)
217
+ concurrent-ruby (~> 1.0)
218
+ unf (0.1.4)
219
+ unf_ext
220
+ unf_ext (0.0.7.7)
221
+ websocket-driver (0.7.3)
222
+ websocket-extensions (>= 0.1.0)
223
+ websocket-extensions (0.1.5)
224
+ xpath (3.2.0)
225
+ nokogiri (~> 1.8)
226
+ yard (0.9.26)
227
+ zeitwerk (2.4.2)
169
228
 
170
229
  PLATFORMS
171
230
  ruby
@@ -183,4 +242,4 @@ DEPENDENCIES
183
242
  yard
184
243
 
185
244
  BUNDLED WITH
186
- 1.11.2
245
+ 1.16.4
@@ -1,4 +1,4 @@
1
- require "ule_page/version"
1
+ require 'ule_page/version'
2
2
  require 'rails'
3
3
  require 'active_record'
4
4
  require 'ule_page/page_map'
@@ -14,7 +14,6 @@ module UlePage
14
14
  autoload :Detail, 'ule_page/models/detail'
15
15
  autoload :Index, 'ule_page/models/index'
16
16
 
17
-
18
17
  mattr_accessor :resource_models
19
18
  @@resource_models = []
20
19
 
@@ -28,24 +27,22 @@ module UlePage
28
27
  @@map_initialized = false
29
28
 
30
29
  mattr_accessor :module_name
31
- @@module_name = "Page"
30
+ @@module_name = 'Page'
32
31
 
33
32
  def self.setup
34
33
  UlePage::Page.send(:include, Rails.application.routes.url_helpers) if defined? Rails
35
34
  UlePage::Page.send(:include, ActionView::Helpers::NumberHelper) if defined? ActionView
36
35
 
37
- self.add_models
36
+ add_models
38
37
 
39
38
  yield self
40
39
  end
41
40
 
42
41
  def self.add_models
43
- if(defined? ActiveRecord::Base && defined? Rails)
42
+ if defined? ActiveRecord::Base && defined? Rails
44
43
  @@resource_models = Dir["#{Rails.root}/app/models/**/*.rb"].map do |m|
45
- m.chomp('.rb').camelize.split("::").last
44
+ m.chomp('.rb').camelize.split('::').last
46
45
  end
47
46
  end
48
47
  end
49
48
  end
50
-
51
-
@@ -25,20 +25,20 @@ module UlePage
25
25
  visit_admin_pages
26
26
  browser.manage.delete_all_cookies
27
27
  else
28
- page.driver.set_cookie("remember_token", '')
28
+ page.driver.set_cookie('remember_token', '')
29
29
  end
30
30
  else
31
31
  if browser.respond_to?(:clear_cookies)
32
32
  # Rack::MockSession
33
33
  browser.clear_cookies
34
34
  else
35
- Capybara.current_session.driver.browser.set_cookie("remember_token=")
35
+ Capybara.current_session.driver.browser.set_cookie('remember_token=')
36
36
  end
37
37
  end
38
38
  end
39
39
 
40
40
  def need_run_javascript
41
- Capybara.current_driver == :selenium or Capybara.current_driver == Capybara.javascript_driver
41
+ (Capybara.current_driver == :selenium) || (Capybara.current_driver == Capybara.javascript_driver)
42
42
  end
43
43
 
44
44
  def confirm_alert
@@ -48,7 +48,7 @@ module UlePage
48
48
  sleep 1 # prevent test from failing by waiting for popup
49
49
  page.driver.browser.accept_js_confirms
50
50
  else
51
- p "pressed ok"
51
+ p 'pressed ok'
52
52
  end
53
53
  end
54
54
 
@@ -3,7 +3,6 @@ require 'site_prism'
3
3
 
4
4
  module UlePage
5
5
  module ModelMatch
6
-
7
6
  class << self
8
7
  include Capybara::DSL
9
8
  def get_current_page_with_wait(special_maps = {})
@@ -28,7 +27,7 @@ module UlePage
28
27
  current = get_model map, current_path
29
28
 
30
29
  if current.nil? && current_path.include?('/admin/')
31
- current = get_model map, current_path[6, current_path.length]
30
+ current = get_model map, current_path[6, current_path.length]
32
31
  end
33
32
 
34
33
  current
@@ -60,15 +59,14 @@ module UlePage
60
59
  pattern = k.gsub(/(:\w+)/, '\w+') if k.include?(':')
61
60
 
62
61
  regex = Regexp.new "^#{pattern}$"
63
- if regex.match(path)
64
- return v
65
- end
62
+ return v if regex.match(path)
66
63
  end
67
64
 
68
65
  nil
69
66
  end
70
67
 
71
68
  private
69
+
72
70
  def generate_map_by_convention(map, resources)
73
71
  resources ||= []
74
72
  # => to generate the following
@@ -77,19 +75,34 @@ module UlePage
77
75
  # '/customers/:id' => Page::Customers::Details.new,
78
76
  # '/customers/:id/edit' => Page::Customers::Edit.new,
79
77
  resources.each do |model|
80
-
81
78
  pluralized = model.to_s.underscore.pluralize
82
79
  page_module_name = model.to_s.pluralize.camelize
83
80
 
84
81
  next unless Object.const_defined?("#{UlePage.module_name}::#{page_module_name}")
85
82
 
86
83
  page_module = Object.const_get(UlePage.module_name).const_get(page_module_name)
87
- map["/#{pluralized}"] = page_module.const_get("Index").try(:new) rescue false
88
- map["/#{pluralized}/new"] = page_module.const_get("Create").new rescue false
89
- map["/#{pluralized}/:id"] = page_module.const_get("Details").new rescue false
90
- map["/#{pluralized}/:id/edit"] = page_module.const_get("Edit").new rescue false
84
+ map["/#{pluralized}"] = begin
85
+ page_module.const_get('Index').try(:new)
86
+ rescue StandardError
87
+ false
88
+ end
89
+ map["/#{pluralized}/new"] = begin
90
+ page_module.const_get('Create').new
91
+ rescue StandardError
92
+ false
93
+ end
94
+ map["/#{pluralized}/:id"] = begin
95
+ page_module.const_get('Details').new
96
+ rescue StandardError
97
+ false
98
+ end
99
+ map["/#{pluralized}/:id/edit"] = begin
100
+ page_module.const_get('Edit').new
101
+ rescue StandardError
102
+ false
103
+ end
91
104
  end
92
105
  end
93
106
  end
94
107
  end
95
- end
108
+ end
@@ -5,7 +5,7 @@ module UlePage
5
5
  element :create_button, 'input[type="submit"]'
6
6
 
7
7
  def submit
8
- self.create_button.click
8
+ create_button.click
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -3,28 +3,31 @@ require 'ule_page/page'
3
3
  module UlePage
4
4
  class Index < Page
5
5
  element_collection :rows, 'tbody tr'
6
+ element :table, 'table'
6
7
 
7
8
  def goto_edit
8
9
  click_link_or_button '编辑'
9
10
  end
10
11
 
11
12
  protected
13
+
12
14
  def key_column
13
- ""
15
+ ''
14
16
  end
15
17
 
16
- def get_row key
17
- find_row key, self.rows
18
+ def get_row(key)
19
+ find_row key, rows
18
20
  end
19
21
 
20
- def get_model_row model
21
- find_row(model[key_column], self.rows)
22
+ def get_model_row(model)
23
+ find_row(model[key_column], rows)
22
24
  end
23
25
 
24
- def get_model_row_anchor model, link_text
26
+ def get_model_row_anchor(model, link_text)
25
27
  row = get_model_row(model)
26
28
  raise 'can not find the row' if row.nil?
29
+
27
30
  row.find(:link_or_button, link_text)
28
31
  end
29
32
  end
30
- end
33
+ end
@@ -6,6 +6,7 @@ require 'ule_page/site_prism_extender'
6
6
  require 'ule_page/helper'
7
7
  require 'ule_page/page_map'
8
8
  require 'active_support/inflector'
9
+ require 'active_support/hash_with_indifferent_access'
9
10
 
10
11
  module UlePage
11
12
  class Page < SitePrism::Page
@@ -14,27 +15,27 @@ module UlePage
14
15
  extend UlePage::SitePrismExtender
15
16
  include RSpec::Matchers
16
17
 
17
- @urls = []
18
+ @urls = []
18
19
  def self.set_urls(*urls)
19
20
  @urls = urls
20
21
  add_to_page_map @urls
21
22
  set_first_url
22
23
  end
23
24
 
24
- def self.urls
25
- @urls
25
+ class << self
26
+ attr_reader :urls
26
27
  end
27
28
 
28
29
  # e.g. is_order_detail?
29
30
  def self.inherited(subclass)
30
- method_name = "is_#{subclass.parent.name.demodulize.singularize.underscore}_#{subclass.name.demodulize.singularize.underscore}?"
31
+ method_name = "is_#{subclass.module_parent_name.demodulize.singularize.underscore}_#{subclass.name.demodulize.singularize.underscore}?"
31
32
  subclass.send(:define_method, method_name) do
32
33
  true
33
34
  end
34
35
  end
35
36
 
36
37
  def open(expansion = {})
37
- self.load expansion
38
+ load expansion
38
39
  self
39
40
  end
40
41
 
@@ -44,15 +45,27 @@ module UlePage
44
45
  # fill_form hashtable
45
46
  # if the fields is empty, it will use all the keys of the hashtable
46
47
  def fill_form(hashtable, fields = [], map = {})
47
- fields = hashtable.keys.map { |k| k.to_sym } if fields.empty?
48
+ hashtable = wrapper_hash(hashtable)
49
+ map = wrapper_hash(map)
50
+
51
+ fields = hashtable.keys.map(&:to_sym) if fields.empty?
48
52
 
49
53
  fields.each do |f|
50
54
  key = f
51
- key = map[f] if map.has_key?(f)
52
-
53
- # p "setting #{f} with #{hashtable[key.to_s]}"
54
-
55
- send(f).send(:set, hashtable[key]) or send(f).send(:select, hashtable[key]) if self.respond_to? f.to_sym
55
+ key = map[f] if map.key?(f)
56
+
57
+ el = send(f)
58
+ val = hashtable[key]
59
+ tag = el.send(:tag_name)
60
+ it = el.send(:[], :type)
61
+
62
+ if tag == 'input' && it == 'checkbox' # checkbox
63
+ el.send(:set, val == 'true')
64
+ elsif tag == 'select' # select
65
+ el.send(:select, val)
66
+ else
67
+ el.send(:set, val)
68
+ end
56
69
  end
57
70
  end
58
71
 
@@ -65,44 +78,64 @@ module UlePage
65
78
  # precondition:
66
79
  # there are the elements mapped to the hashtable keys.
67
80
  def check_form(hashtable, fields = [], map = {})
68
- fields = hashtable.keys.map { |k| k.to_sym } if fields.empty?
81
+ hashtable = wrapper_hash(hashtable)
82
+ map = wrapper_hash(map)
83
+
84
+ fields = hashtable.keys.map(&:to_sym) if fields.empty?
69
85
 
70
86
  fields.each do |f|
71
87
  key = f
72
- key = map[f] if map.has_key?(f)
88
+ key = map[f] if map.key?(f)
73
89
 
74
- if self.respond_to? f.to_sym
75
- el_content = send(f).send(:value)
90
+ next unless respond_to? f.to_sym
76
91
 
77
- expect(el_content).to eq hashtable[key.to_s]
78
- end
92
+ el_content = send(f).send(:value)
79
93
 
94
+ expect(el_content).to eq hashtable[key.to_s]
80
95
  end
81
96
  end
82
97
 
83
- def check_have_content(content)
84
- page.should have_content content
98
+ def check_have_content(content, container = nil)
99
+ container ||= page
100
+ if container.respond_to?(:has_text?)
101
+ expect(container.has_text?(content)).to be_truthy
102
+ else
103
+ expect(container).to have_content(content)
104
+ end
85
105
  end
86
106
 
87
- def check_have_not_content(content)
88
- expect(page).to have_no_content(content)
107
+ def check_have_not_content(content, container = nil)
108
+ container ||= page
109
+ if container.respond_to?(:has_no_text?)
110
+ expect(container.has_no_text?(content)).to be_truthy
111
+ else
112
+ expect(container).not_to have_content(content)
113
+ end
89
114
  end
90
115
 
91
116
  # usage: check_have_hashtable_content hashtable
92
117
  # usage: check_have_hashtable_content hashtable, [:id, :name]
93
- def check_have_hashtable_content(hashtable, keys = [])
118
+ def check_have_hashtable_content(hashtable, keys = [], container = nil)
119
+ hashtable = wrapper_hash(hashtable)
94
120
  keys = hashtable.keys if keys.empty?
95
121
 
96
122
  keys.each do |k|
97
- check_have_content hashtable[k.to_s]
123
+ begin
124
+ check_have_content hashtable[k.to_s], container
125
+ rescue RSpec::Expectations::ExpectationNotMetError => e
126
+ puts "The key: '#{k}'' has no matched content!!"
127
+ raise
128
+ end
98
129
  end
99
130
  end
100
131
 
101
- def check_have_no_hashtable_content(hashtable, keys = [])
132
+ def check_have_no_hashtable_content(hashtable, keys = [], container = nil)
133
+ hashtable = wrapper_hash(hashtable)
134
+
102
135
  keys = hashtable.keys if keys.empty?
103
136
 
104
137
  keys.each do |k|
105
- check_have_not_content hashtable[k.to_s]
138
+ check_have_not_content hashtable[k.to_s], container
106
139
  end
107
140
  end
108
141
 
@@ -128,17 +161,23 @@ module UlePage
128
161
  end
129
162
 
130
163
  private
164
+
131
165
  def self.add_to_page_map(urls = [])
132
- urls.each {|x| PageMap.instance.pages[x] = self.new } unless urls.nil?
166
+ urls.each { |x| PageMap.instance.pages[x] = new } unless urls.nil?
133
167
  end
134
168
 
135
- def self.set_first_url
136
- if @urls.any?
137
- first_url = @urls.first
138
- first_url = first_url.gsub /:(\w+)/, '{\1}'
139
- set_url first_url
140
- end
169
+ def wrapper_hash(hash)
170
+ return hash unless hash.is_a?(Hash)
171
+
172
+ ActiveSupport::HashWithIndifferentAccess.new hash
141
173
  end
142
174
 
175
+ def self.set_first_url
176
+ return unless @urls.any?
177
+
178
+ first_url = @urls.first
179
+ first_url = first_url.gsub(/:(\w+)/, '{\1}')
180
+ set_url first_url
181
+ end
143
182
  end
144
183
  end
@@ -12,4 +12,4 @@ module UlePage
12
12
  @map
13
13
  end
14
14
  end
15
- end
15
+ end
@@ -2,7 +2,7 @@ require 'site_prism'
2
2
 
3
3
  module UlePage
4
4
  module SitePrismExtender
5
- include SitePrism::ElementContainer
5
+ include SitePrism::DSL
6
6
  include SitePrism
7
7
 
8
8
  # why define this method?
@@ -10,7 +10,7 @@ module UlePage
10
10
  # I have not found one good method to solve the confliction.
11
11
  def element_collection(collection_name, *find_args)
12
12
  build collection_name, *find_args do
13
- define_method collection_name.to_s do |*runtime_args, &element_block|
13
+ define_method collection_name.to_s do |*_runtime_args, &element_block|
14
14
  self.class.raise_if_block(self, collection_name.to_s, !element_block.nil?)
15
15
  page.all(*find_args)
16
16
  end
@@ -26,15 +26,14 @@ module UlePage
26
26
  attributes = model_class.new.attributes.keys
27
27
 
28
28
  props = attributes if props.empty?
29
- props.map! { |x| x.to_s } unless props.empty?
29
+ props.map!(&:to_s) unless props.empty?
30
30
 
31
31
  attributes.each do |attri|
32
- if props.include? attri
33
- selector = "#"+"#{class_name(model_class)}_#{attri.to_s}"
32
+ next unless props.include? attri
34
33
 
35
- element attri, selector
36
- end
34
+ selector = '#' + "#{class_name(model_class)}_#{attri}"
37
35
 
36
+ element attri, selector
38
37
  end
39
38
  end
40
39
 
@@ -46,14 +45,14 @@ module UlePage
46
45
  attributes = submodel_class.new.attributes.keys
47
46
 
48
47
  props = attributes if props.empty?
49
- props.map! { |x| x.to_s } unless props.empty?
48
+ props.map!(&:to_s) unless props.empty?
50
49
 
51
50
  attributes.each do |attri|
52
- if props.include?(attri)
53
- selector = '#' + "#{class_name(model_class)}_#{class_name(submodel_class)}_attributes_#{attri.to_s}"
51
+ next unless props.include?(attri)
54
52
 
55
- element attri, selector
56
- end
53
+ selector = '#' + "#{class_name(model_class)}_#{class_name(submodel_class)}_attributes_#{attri}"
54
+
55
+ element attri, selector
57
56
  end
58
57
  end
59
58
 
@@ -67,12 +66,11 @@ module UlePage
67
66
  attributes = model_class.new.attributes.keys
68
67
 
69
68
  attributes.each do |attri|
70
- unless excluded_props.include? attri
71
- selector = "#"+attri
72
- # self.class.send "element", attri.to_sym, selector
73
- element attri, selector
74
- end
69
+ next if excluded_props.include? attri
75
70
 
71
+ selector = '#' + attri
72
+ # self.class.send "element", attri.to_sym, selector
73
+ element attri, selector
76
74
  end
77
75
  end
78
76
  end
@@ -1,3 +1,3 @@
1
1
  module UlePage
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,19 +1,17 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'ule_page/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = "ule_page"
6
+ spec.name = 'ule_page'
8
7
  spec.version = UlePage::VERSION
9
- spec.authors = ["Jeremy Cui"]
10
- spec.email = ["tsuijy@gmail.com"]
11
-
12
- spec.summary = %q{ Page model for cucumber test.}
13
- spec.description = %q{ Based on the siteprism gem, add more page methods and looking for page model via current_path.}
14
- spec.homepage = "https://github.com/jerecui/ule_page"
15
- spec.license = "MIT"
8
+ spec.authors = ['Jere Cui']
9
+ spec.email = ['tsuijy@gmail.com']
16
10
 
11
+ spec.summary = ' Page model for cucumber test.'
12
+ spec.description = ' Based on the siteprism gem, add more page methods and looking for page model via current_path.'
13
+ spec.homepage = 'https://github.com/hongshu/ule_page'
14
+ spec.license = 'MIT'
17
15
 
18
16
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
19
17
  # delete this section to allow pushing this gem to any host.
@@ -24,29 +22,27 @@ Gem::Specification.new do |spec|
24
22
  # end
25
23
 
26
24
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
- spec.bindir = "exe"
25
+ spec.bindir = 'exe'
28
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
- spec.require_paths = ["lib"]
30
-
31
- spec.required_ruby_version = '>= 1.9.3'
32
- spec.platform = Gem::Platform::RUBY
33
-
34
- spec.add_development_dependency "bundler", "~> 1.11"
35
- spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.require_paths = ['lib']
36
28
 
29
+ spec.required_ruby_version = '>= 2.5.0'
30
+ spec.platform = Gem::Platform::RUBY
37
31
 
38
- spec.add_dependency "site_prism", "> 2.1"
39
- spec.add_dependency "capybara", ['>= 2.1', '< 3.0']
40
- spec.add_dependency "rspec", "~> 3.0"
41
- spec.add_dependency "activesupport", '> 4.0'
42
- spec.add_dependency "activerecord", '> 4.0'
32
+ spec.add_development_dependency 'bundler', '~> 1.11'
33
+ spec.add_development_dependency 'rake', '~> 10.0'
43
34
 
44
- spec.add_development_dependency "rails"
45
- spec.add_development_dependency "rspec-rails"
35
+ spec.add_dependency 'activerecord', '> 4.0'
36
+ spec.add_dependency 'activesupport', '> 4.0'
37
+ spec.add_dependency 'capybara', ['>= 2.1', '< 3.0']
38
+ spec.add_dependency 'rspec', '~> 3.0'
39
+ spec.add_dependency 'site_prism', '> 2.1'
46
40
 
47
- spec.add_development_dependency "rspec-its", "~> 1.0"
48
- spec.add_development_dependency "cucumber", "~> 1.3.15"
49
- spec.add_development_dependency "simplecov"
50
- spec.add_development_dependency "yard"
41
+ spec.add_development_dependency 'rails'
42
+ spec.add_development_dependency 'rspec-rails'
51
43
 
44
+ spec.add_development_dependency 'cucumber', '~> 1.3.15'
45
+ spec.add_development_dependency 'rspec-its', '~> 1.0'
46
+ spec.add_development_dependency 'simplecov'
47
+ spec.add_development_dependency 'yard'
52
48
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ule_page
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
- - Jeremy Cui
8
- autorequire:
7
+ - Jere Cui
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-24 00:00:00.000000000 Z
11
+ date: 2021-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -39,19 +39,33 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: site_prism
42
+ name: activerecord
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.1'
47
+ version: '4.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">"
53
53
  - !ruby/object:Gem::Version
54
- version: '2.1'
54
+ version: '4.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: capybara
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -87,33 +101,19 @@ dependencies:
87
101
  - !ruby/object:Gem::Version
88
102
  version: '3.0'
89
103
  - !ruby/object:Gem::Dependency
90
- name: activesupport
91
- requirement: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - ">"
94
- - !ruby/object:Gem::Version
95
- version: '4.0'
96
- type: :runtime
97
- prerelease: false
98
- version_requirements: !ruby/object:Gem::Requirement
99
- requirements:
100
- - - ">"
101
- - !ruby/object:Gem::Version
102
- version: '4.0'
103
- - !ruby/object:Gem::Dependency
104
- name: activerecord
104
+ name: site_prism
105
105
  requirement: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - ">"
108
108
  - !ruby/object:Gem::Version
109
- version: '4.0'
109
+ version: '2.1'
110
110
  type: :runtime
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
114
  - - ">"
115
115
  - !ruby/object:Gem::Version
116
- version: '4.0'
116
+ version: '2.1'
117
117
  - !ruby/object:Gem::Dependency
118
118
  name: rails
119
119
  requirement: !ruby/object:Gem::Requirement
@@ -143,33 +143,33 @@ dependencies:
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
145
  - !ruby/object:Gem::Dependency
146
- name: rspec-its
146
+ name: cucumber
147
147
  requirement: !ruby/object:Gem::Requirement
148
148
  requirements:
149
149
  - - "~>"
150
150
  - !ruby/object:Gem::Version
151
- version: '1.0'
151
+ version: 1.3.15
152
152
  type: :development
153
153
  prerelease: false
154
154
  version_requirements: !ruby/object:Gem::Requirement
155
155
  requirements:
156
156
  - - "~>"
157
157
  - !ruby/object:Gem::Version
158
- version: '1.0'
158
+ version: 1.3.15
159
159
  - !ruby/object:Gem::Dependency
160
- name: cucumber
160
+ name: rspec-its
161
161
  requirement: !ruby/object:Gem::Requirement
162
162
  requirements:
163
163
  - - "~>"
164
164
  - !ruby/object:Gem::Version
165
- version: 1.3.15
165
+ version: '1.0'
166
166
  type: :development
167
167
  prerelease: false
168
168
  version_requirements: !ruby/object:Gem::Requirement
169
169
  requirements:
170
170
  - - "~>"
171
171
  - !ruby/object:Gem::Version
172
- version: 1.3.15
172
+ version: '1.0'
173
173
  - !ruby/object:Gem::Dependency
174
174
  name: simplecov
175
175
  requirement: !ruby/object:Gem::Requirement
@@ -230,11 +230,11 @@ files:
230
230
  - lib/ule_page/site_prism_extender.rb
231
231
  - lib/ule_page/version.rb
232
232
  - ule_page.gemspec
233
- homepage: https://github.com/jerecui/ule_page
233
+ homepage: https://github.com/hongshu/ule_page
234
234
  licenses:
235
235
  - MIT
236
236
  metadata: {}
237
- post_install_message:
237
+ post_install_message:
238
238
  rdoc_options: []
239
239
  require_paths:
240
240
  - lib
@@ -242,17 +242,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
242
242
  requirements:
243
243
  - - ">="
244
244
  - !ruby/object:Gem::Version
245
- version: 1.9.3
245
+ version: 2.5.0
246
246
  required_rubygems_version: !ruby/object:Gem::Requirement
247
247
  requirements:
248
248
  - - ">="
249
249
  - !ruby/object:Gem::Version
250
250
  version: '0'
251
251
  requirements: []
252
- rubyforge_project:
253
- rubygems_version: 2.5.1
254
- signing_key:
252
+ rubyforge_project:
253
+ rubygems_version: 2.7.7
254
+ signing_key:
255
255
  specification_version: 4
256
256
  summary: Page model for cucumber test.
257
257
  test_files: []
258
- has_rdoc: