ule_page 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/Gemfile.lock +2 -2
- data/README.md +36 -10
- data/lib/ule_page/helper.rb +3 -0
- data/lib/ule_page/model_match.rb +41 -29
- data/lib/ule_page/page.rb +25 -1
- data/lib/ule_page/page_map.rb +15 -0
- data/lib/ule_page/version.rb +1 -1
- data/lib/ule_page.rb +1 -0
- data/ule_page.gemspec +5 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84e8d3bd9a14c739a5d257450127c8ca81910e04
|
4
|
+
data.tar.gz: b467022839fe9088bb302dc613da08752aec8c9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 490ce1aefc7e129cbbf98c9d2717a4694e41136f4d72b895aa7b5068a31051a79c42abf77dbdf387be1dcda9d67ca3eb2c0bfa8242da33771f6d9aa6f6813f6d
|
7
|
+
data.tar.gz: a2063f05613e356affcad38e177f5d1daa46ad9add5a7f8373b6d54c010df4ab530d608ad0688c3ff8fa2c54147afb20cca6a0198d6f8865a5dbf033346e9c79
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ule_page (0.0.
|
4
|
+
ule_page (0.0.3)
|
5
5
|
activerecord (> 4.0)
|
6
6
|
activesupport (> 4.0)
|
7
7
|
capybara (>= 2.1, < 3.0)
|
@@ -9,7 +9,7 @@ PATH
|
|
9
9
|
site_prism (> 2.1)
|
10
10
|
|
11
11
|
GEM
|
12
|
-
remote: https://
|
12
|
+
remote: https://rubygems.org/
|
13
13
|
specs:
|
14
14
|
actionmailer (4.2.5.1)
|
15
15
|
actionpack (= 4.2.5.1)
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Welcome to UlePage gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ule_page`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
4
|
|
5
|
-
Using UlePage, you can define page model object easily. e.g.
|
5
|
+
Using UlePage, you can define page model object easily and the gem can match the current url to the specific page model with 'pg' method. e.g.
|
6
6
|
```ruby
|
7
7
|
module Page
|
8
8
|
module Customers
|
@@ -15,9 +15,25 @@ module Page
|
|
15
15
|
submit
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
19
|
+
class Index < UlePage::Index
|
20
|
+
set_urls '/customers', '/organization/:organization_id/customers'
|
21
|
+
|
22
|
+
def has_customer?(customer)
|
23
|
+
check_have_hashtable_content customer, [ :name, :phone, :address ]
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
18
27
|
end
|
19
28
|
end
|
20
29
|
|
30
|
+
Given(/^home page has something$/) do |table|
|
31
|
+
visit '/'
|
32
|
+
click_link 'customers' # goto customer index pages.
|
33
|
+
|
34
|
+
pg.has_customer? table.hashes[0] # called customer index page method.
|
35
|
+
end
|
36
|
+
|
21
37
|
```
|
22
38
|
|
23
39
|
## Installation
|
@@ -44,7 +60,7 @@ UlePage.setup do |config|
|
|
44
60
|
#add customised content
|
45
61
|
end
|
46
62
|
```
|
47
|
-
|
63
|
+
### Important:
|
48
64
|
Make sure the above lines in front of the screenshot requiring, or you can not get screenshot when you get errors.
|
49
65
|
```ruby
|
50
66
|
require 'capybara-screenshot/cucumber'
|
@@ -53,14 +69,6 @@ And in features/support/helper.rb, add lines:
|
|
53
69
|
```ruby
|
54
70
|
include UlePage::Helper
|
55
71
|
|
56
|
-
def pg
|
57
|
-
special_maps = {
|
58
|
-
'/' => Page::Homes::Index.new # or something else, based on your page model
|
59
|
-
}
|
60
|
-
|
61
|
-
return UlePage::ModelMatch.get_current_page_with_wait special_maps
|
62
|
-
end
|
63
|
-
|
64
72
|
```
|
65
73
|
After that, you can define your page model.
|
66
74
|
|
@@ -73,8 +81,26 @@ UlePage will map crud page model automatically, say, if you have a model custome
|
|
73
81
|
'/customers/:id/edit' => Page::Customers::Edit
|
74
82
|
}
|
75
83
|
```
|
84
|
+
If the page model is not the CRUD with simple, you can set urls manually on the page model.
|
85
|
+
```ruby
|
86
|
+
class Index < UlePage::Index
|
87
|
+
set_urls '/orders', '/customer/:customer_id/orders'
|
88
|
+
|
89
|
+
# ...
|
90
|
+
end
|
91
|
+
|
92
|
+
```
|
93
|
+
|
94
|
+
|
76
95
|
In cucumber step files, you can use pg.xxx, pg will get your defined model automatically via current_url.
|
77
96
|
|
97
|
+
```ruby
|
98
|
+
Given(/^home page has something$/) do
|
99
|
+
visit '/'
|
100
|
+
pg.has_something # you need to implement has_something method in the home_page page model.
|
101
|
+
end
|
102
|
+
```
|
103
|
+
|
78
104
|
## Development
|
79
105
|
|
80
106
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/ule_page/helper.rb
CHANGED
data/lib/ule_page/model_match.rb
CHANGED
@@ -12,7 +12,7 @@ module UlePage
|
|
12
12
|
current = get_current_page special_maps
|
13
13
|
|
14
14
|
if !current_path.nil? && current.nil?
|
15
|
-
p "current path is #{current_path}, we can not get the page model, please
|
15
|
+
p "current path is #{current_path}, we can not get the page model, please define the set_urls for the page model."
|
16
16
|
|
17
17
|
raise
|
18
18
|
end
|
@@ -21,35 +21,8 @@ module UlePage
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def get_current_page(special_maps = {})
|
24
|
-
|
24
|
+
map = prepare_maps special_maps
|
25
25
|
|
26
|
-
if !UlePage.map_initialized || UlePage.special_maps.empty?
|
27
|
-
UlePage.special_maps = special_maps
|
28
|
-
UlePage.map = UlePage.special_maps
|
29
|
-
|
30
|
-
# => to generate the following
|
31
|
-
# '/customers' => Page::Customers::Index.new,
|
32
|
-
# '/customers/new' => Page::Customers::Create.new,
|
33
|
-
# '/customers/:id' => Page::Customers::Details.new,
|
34
|
-
# '/customers/:id/edit' => Page::Customers::Edit.new,
|
35
|
-
resources.each do |model|
|
36
|
-
|
37
|
-
pluralized = model.to_s.underscore.pluralize
|
38
|
-
page_module_name = model.to_s.pluralize.camelize
|
39
|
-
|
40
|
-
next unless Object.const_defined?("#{UlePage.module_name}::#{page_module_name}")
|
41
|
-
|
42
|
-
page_module = Object.const_get(UlePage.module_name).const_get(page_module_name)
|
43
|
-
UlePage.map["/#{pluralized}"] = page_module.const_get("Index").try(:new) rescue false
|
44
|
-
UlePage.map["/#{pluralized}/new"] = page_module.const_get("Create").new rescue false
|
45
|
-
UlePage.map["/#{pluralized}/:id"] = page_module.const_get("Details").new rescue false
|
46
|
-
UlePage.map["/#{pluralized}/:id/edit"] = page_module.const_get("Edit").new rescue false
|
47
|
-
end
|
48
|
-
|
49
|
-
UlePage.map_initialized = true
|
50
|
-
end
|
51
|
-
|
52
|
-
map = UlePage.map
|
53
26
|
return nil unless current_path
|
54
27
|
|
55
28
|
current = get_model map, current_path
|
@@ -61,6 +34,22 @@ module UlePage
|
|
61
34
|
current
|
62
35
|
end
|
63
36
|
|
37
|
+
def prepare_maps(special_maps)
|
38
|
+
if !UlePage.map_initialized || UlePage.special_maps.empty?
|
39
|
+
UlePage.special_maps = special_maps
|
40
|
+
UlePage.map = {}
|
41
|
+
|
42
|
+
generate_map_by_convention UlePage.map, UlePage.resource_models
|
43
|
+
|
44
|
+
UlePage.map.merge! UlePage.special_maps if UlePage.special_maps.any?
|
45
|
+
UlePage.map.merge! UlePage::PageMap.instance.pages
|
46
|
+
|
47
|
+
UlePage.map_initialized = true
|
48
|
+
end
|
49
|
+
|
50
|
+
UlePage.map
|
51
|
+
end
|
52
|
+
|
64
53
|
def get_model(map, path)
|
65
54
|
map[path] || try_regex_match(map, path)
|
66
55
|
end
|
@@ -78,6 +67,29 @@ module UlePage
|
|
78
67
|
|
79
68
|
nil
|
80
69
|
end
|
70
|
+
|
71
|
+
private
|
72
|
+
def generate_map_by_convention(map, resources)
|
73
|
+
resources ||= []
|
74
|
+
# => to generate the following
|
75
|
+
# '/customers' => Page::Customers::Index.new,
|
76
|
+
# '/customers/new' => Page::Customers::Create.new,
|
77
|
+
# '/customers/:id' => Page::Customers::Details.new,
|
78
|
+
# '/customers/:id/edit' => Page::Customers::Edit.new,
|
79
|
+
resources.each do |model|
|
80
|
+
|
81
|
+
pluralized = model.to_s.underscore.pluralize
|
82
|
+
page_module_name = model.to_s.pluralize.camelize
|
83
|
+
|
84
|
+
next unless Object.const_defined?("#{UlePage.module_name}::#{page_module_name}")
|
85
|
+
|
86
|
+
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
|
91
|
+
end
|
92
|
+
end
|
81
93
|
end
|
82
94
|
end
|
83
95
|
end
|
data/lib/ule_page/page.rb
CHANGED
@@ -4,6 +4,7 @@ require 'rspec/expectations'
|
|
4
4
|
require 'capybara'
|
5
5
|
require 'ule_page/site_prism_extender'
|
6
6
|
require 'ule_page/helper'
|
7
|
+
require 'ule_page/page_map'
|
7
8
|
require 'active_support/inflector'
|
8
9
|
|
9
10
|
module UlePage
|
@@ -13,6 +14,17 @@ module UlePage
|
|
13
14
|
extend UlePage::SitePrismExtender
|
14
15
|
include RSpec::Matchers
|
15
16
|
|
17
|
+
@urls = []
|
18
|
+
def self.set_urls(*urls)
|
19
|
+
@urls = urls
|
20
|
+
add_to_page_map @urls
|
21
|
+
set_first_url
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.urls
|
25
|
+
@urls
|
26
|
+
end
|
27
|
+
|
16
28
|
# e.g. is_order_detail?
|
17
29
|
def self.inherited(subclass)
|
18
30
|
method_name = "is_#{subclass.parent.name.demodulize.singularize.underscore}_#{subclass.name.demodulize.singularize.underscore}?"
|
@@ -114,7 +126,19 @@ module UlePage
|
|
114
126
|
def go_back
|
115
127
|
click_link_or_button '返回'
|
116
128
|
end
|
117
|
-
end
|
118
129
|
|
130
|
+
private
|
131
|
+
def self.add_to_page_map(urls = [])
|
132
|
+
urls.each {|x| PageMap.instance.pages[x] = self.new } unless urls.nil?
|
133
|
+
end
|
119
134
|
|
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
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
120
144
|
end
|
data/lib/ule_page/version.rb
CHANGED
data/lib/ule_page.rb
CHANGED
data/ule_page.gemspec
CHANGED
@@ -10,10 +10,11 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["tsuijy@gmail.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{ Page model for cucumber test.}
|
13
|
-
spec.description = %q{ Based on the siteprism gem, add more page methods.}
|
13
|
+
spec.description = %q{ Based on the siteprism gem, add more page methods and looking for page model via current_path.}
|
14
14
|
spec.homepage = "https://github.com/jerecui/ule_page"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
|
+
|
17
18
|
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
19
|
# delete this section to allow pushing this gem to any host.
|
19
20
|
# if spec.respond_to?(:metadata)
|
@@ -27,6 +28,9 @@ Gem::Specification.new do |spec|
|
|
27
28
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
29
|
spec.require_paths = ["lib"]
|
29
30
|
|
31
|
+
spec.required_ruby_version = '>= 1.9.3'
|
32
|
+
spec.platform = Gem::Platform::RUBY
|
33
|
+
|
30
34
|
spec.add_development_dependency "bundler", "~> 1.11"
|
31
35
|
spec.add_development_dependency "rake", "~> 10.0"
|
32
36
|
spec.add_development_dependency("activesupport")
|
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.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Cui
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -226,7 +226,8 @@ dependencies:
|
|
226
226
|
- - ">="
|
227
227
|
- !ruby/object:Gem::Version
|
228
228
|
version: '0'
|
229
|
-
description: " Based on the siteprism gem, add more page methods
|
229
|
+
description: " Based on the siteprism gem, add more page methods and looking for page
|
230
|
+
model via current_path."
|
230
231
|
email:
|
231
232
|
- tsuijy@gmail.com
|
232
233
|
executables: []
|
@@ -252,6 +253,7 @@ files:
|
|
252
253
|
- lib/ule_page/models/detail.rb
|
253
254
|
- lib/ule_page/models/index.rb
|
254
255
|
- lib/ule_page/page.rb
|
256
|
+
- lib/ule_page/page_map.rb
|
255
257
|
- lib/ule_page/site_prism_extender.rb
|
256
258
|
- lib/ule_page/version.rb
|
257
259
|
- ule_page.gemspec
|
@@ -267,7 +269,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
267
269
|
requirements:
|
268
270
|
- - ">="
|
269
271
|
- !ruby/object:Gem::Version
|
270
|
-
version:
|
272
|
+
version: 1.9.3
|
271
273
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
272
274
|
requirements:
|
273
275
|
- - ">="
|