ae_page_objects 1.3.0 → 1.4.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
2
  SHA1:
3
- metadata.gz: bccdd111c15cbfc24c720ab0ecb2df6615d817af
4
- data.tar.gz: 640432edfc7bae3b61ab33c37cb878344a6fdb66
3
+ metadata.gz: 20c13f38ceabdcf27ecc3f89d9de3553c5787945
4
+ data.tar.gz: dcd428213ed6c1424727b40e0cd1583d4b6d2cc2
5
5
  SHA512:
6
- metadata.gz: 9eccb45c332ac93f9b87c04065d834595d864b5eab6116d8d9cb469fac270a134baf4671c2c2087f7b1df6de22907807d93bad6347cef0e6758d3c293ca72adc
7
- data.tar.gz: 9782f24bbc2f0eea7fdf7e9cef46b4bc2554ab15ed7c578aa247b55b8f4d1a0e6333c194e960672cede92e4f46ececea2d590ee97dd6414e80c12daa337c75f8
6
+ metadata.gz: b13c1d548b49b516dc2a8d71efb0676850fc04301044fe02118bd4f0ed899ad6d81850a3021181a104f5ba79cecba6af36fdbd0aa4d84400333bccb3ac1657ce
7
+ data.tar.gz: 5f390f9a20b9f5d459021cfb5bceef6c96c0dd08de671ba79baa9629329253e073ce8307482b37f96e87537bea86fe7b41f89d2dc3c22450a1d33375224d4b19
@@ -11,20 +11,55 @@ module AePageObjects
11
11
  routes.send("#{named_route}_path", *args)
12
12
  end
13
13
  end
14
- end
15
14
 
16
- class Rails23 < Base
17
- def recognizes?(path, url)
18
- ["GET", "PUT", "POST", "DELETE", "PATCH"].map(&:downcase).map(&:to_sym).each do |method|
19
- route = ActionController::Routing::Routes.named_routes[path]
20
- route.recognize(url, {:method => method})
15
+ def recognizes?(named_route, url)
16
+ url = normalize_url(url)
17
+
18
+ resolved_named_route = resolve_named_route(named_route)
21
19
 
22
- return true if route && route.recognize(url, {:method => method})
20
+ [:get, :post, :put, :delete, :patch].each do |method|
21
+ resolved_route_from_url = resolve_url(url, method)
22
+
23
+ # The first resolved route matching named route is returned as
24
+ # Rails' routes are in priority order.
25
+ if resolved_named_route == resolved_route_from_url
26
+ return true
27
+ end
23
28
  end
24
29
 
25
30
  false
26
31
  end
27
32
 
33
+ private
34
+
35
+ def routes
36
+ raise NotImplementedError, "You must implement routes"
37
+ end
38
+
39
+ def normalize_url(url)
40
+ raise NotImplementedError, "You must implement normalize_url"
41
+ end
42
+
43
+ def router
44
+ raise NotImplementedError, "You must implement router"
45
+ end
46
+
47
+ def resolve_named_route(named_route)
48
+ requirements = router.named_routes[named_route].requirements
49
+ ResolvedRoute.new(requirements[:controller], requirements[:action])
50
+ end
51
+
52
+ def resolve_url(url, method)
53
+ recognized_path = router.recognize_path(url, {:method => method})
54
+ ResolvedRoute.new(recognized_path[:controller], recognized_path[:action])
55
+ rescue ActionController::RoutingError, ActionController::MethodNotAllowed
56
+ end
57
+
58
+ ResolvedRoute = Struct.new(:controller, :action)
59
+ end
60
+
61
+ class Rails23 < Base
62
+
28
63
  private
29
64
 
30
65
  def routes
@@ -36,21 +71,17 @@ module AePageObjects
36
71
  routes_class.new
37
72
  end
38
73
  end
39
- end
40
74
 
41
- class Rails3 < Base
42
- def recognizes?(path, url)
43
- url, router = url_and_router(url)
44
-
45
- ["GET", "PUT", "POST", "DELETE", "PATCH"].each do |method|
46
- router.recognize(request_for(url, method)) do |route, matches, params|
47
- return true if route.name.to_s == path.to_s
48
- end
49
- end
75
+ def normalize_url(url)
76
+ url
77
+ end
50
78
 
51
- false
79
+ def router
80
+ ActionController::Routing::Routes
52
81
  end
82
+ end
53
83
 
84
+ class Rails3 < Base
54
85
 
55
86
  private
56
87
 
@@ -66,11 +97,12 @@ module AePageObjects
66
97
  end
67
98
  end
68
99
 
69
- def url_and_router(url)
70
- url = Rack::Mount::Utils.normalize_path(url) unless url =~ %r{://}
71
- router = ::Rails.application.routes.set
100
+ def normalize_url(url)
101
+ Rack::Mount::Utils.normalize_path(url) unless url =~ %r{://}
102
+ end
72
103
 
73
- [url, router]
104
+ def router
105
+ ::Rails.application.routes
74
106
  end
75
107
 
76
108
  def routes
@@ -86,26 +118,21 @@ module AePageObjects
86
118
  class Rails32 < Rails3
87
119
 
88
120
  private
89
- def url_and_router(url)
90
- url = Journey::Router::Utils.normalize_path(url) unless url =~ %r{://}
91
- router = ::Rails.application.routes.router
92
121
 
93
- [url, router]
122
+ def normalize_url(url)
123
+ Journey::Router::Utils.normalize_path(url) unless url =~ %r{://}
94
124
  end
95
125
  end
96
126
 
97
127
  class Rails4 < Rails32
98
128
 
99
- private
100
- def url_and_router(url)
101
- require 'action_dispatch/journey'
102
- url = ActionDispatch::Journey::Router::Utils.normalize_path(url) unless url =~ %r{://}
103
- router = ::Rails.application.routes.router
129
+ private
104
130
 
105
- [url, router]
131
+ def normalize_url(url)
132
+ require 'action_dispatch/journey'
133
+ ActionDispatch::Journey::Router::Utils.normalize_path(url) unless url =~ %r{://}
106
134
  end
107
135
  end
108
-
109
136
  end
110
137
 
111
138
  def path_recognizes_url?(path, url)
@@ -134,7 +161,7 @@ module AePageObjects
134
161
  Recognizer::Rails3.new
135
162
  elsif ::Rails.version =~ /\A3\.2/
136
163
  Recognizer::Rails32.new
137
- elsif ::Rails.version =~ /\A4\.[01]/
164
+ elsif ::Rails.version =~ /\A4\.[012]/
138
165
  Recognizer::Rails4.new
139
166
  else
140
167
  warn "[WARNING]: AePageObjects is not tested against Rails #{::Rails.version} and may behave in an undefined manner."
@@ -42,4 +42,7 @@ module AePageObjects
42
42
 
43
43
  class WaitTimeoutError < Error
44
44
  end
45
+
46
+ class FrozenInTime < Error
47
+ end
45
48
  end
@@ -12,6 +12,7 @@ module AePageObjects
12
12
  end
13
13
 
14
14
  sleep(0.05)
15
+ raise FrozenInTime, "Time appears to be frozen" if Time.now == start_time
15
16
  end
16
17
 
17
18
  result
@@ -1,3 +1,3 @@
1
1
  module AePageObjects
2
- VERSION = '1.3.0'.freeze
2
+ VERSION = '1.4.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ae_page_objects
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Donnie Tognazzini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-07 00:00:00.000000000 Z
11
+ date: 2015-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  version: '0'
96
96
  requirements: []
97
97
  rubyforge_project:
98
- rubygems_version: 2.2.2
98
+ rubygems_version: 2.4.3
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: Capybara Page Objects pattern