devise-better_routes 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -75,6 +75,11 @@ Do you like this one?
75
75
 
76
76
  ## Changes
77
77
 
78
+ ### 0.0.4
79
+
80
+ * __Add password routes__
81
+ * Add URL helpers for session & password
82
+
78
83
  ### 0.0.3
79
84
 
80
85
  * __Add session routes__
@@ -6,6 +6,25 @@ require 'devise/better_routes/version'
6
6
  module Devise
7
7
  module Controllers
8
8
  module UrlHelpers
9
+ def self.override_current_resource_helpers!(routes = {})
10
+ routes.each do |module_name, actions|
11
+ [:path, :url].each do |path_or_url|
12
+ actions.each do |action|
13
+ action = action ? "#{action}_" : ""
14
+ method = "#{action}#{module_name}_#{path_or_url}"
15
+
16
+ class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1
17
+ def #{method}(resource_or_scope, *args)
18
+ scope = Devise::Mapping.find_scope!(resource_or_scope)
19
+ current_resource_name = _devise_path_name(scope, "current_\#{scope}")
20
+ _devise_route_context.send("#{action}\#{current_resource_name}_#{module_name}_#{path_or_url}", *args)
21
+ end
22
+ URL_HELPERS
23
+ end
24
+ end
25
+ end
26
+ end
27
+
9
28
  def self.override_registration_helpers!(registration_routes = nil)
10
29
  helper_mappings = {
11
30
  new_registration: 'new_#{scope}',
@@ -19,9 +38,9 @@ module Devise
19
38
  scope = Devise::Mapping.find_scope!(resource_or_scope)
20
39
  current_resource_name = _devise_path_name(scope, "current_\#{scope}")
21
40
  if respond_to?(:controller_name) && controller_name == _devise_registration_controller(scope, current_resource_name)
22
- send("\#{current_resource_name}_#{path_or_url}", *args)
41
+ _devise_route_context.send("\#{current_resource_name}_#{path_or_url}", *args)
23
42
  else
24
- send("\#{scope.to_s.pluralize}_#{path_or_url}", *args)
43
+ _devise_route_context.send("\#{scope.to_s.pluralize}_#{path_or_url}", *args)
25
44
  end
26
45
  end
27
46
  URL_HELPERS
@@ -31,17 +50,18 @@ module Devise
31
50
  def #{method}(resource_or_scope, *args)
32
51
  scope = Devise::Mapping.find_scope!(resource_or_scope)
33
52
  current_resource_name = _devise_path_name(scope, "current_\#{scope}")
34
- send("#{new_name}_#{path_or_url}", *args)
53
+ _devise_route_context.send("#{new_name}_#{path_or_url}", *args)
35
54
  end
36
55
  URL_HELPERS
37
56
  end
38
57
  end
39
58
  end
40
- override_registration_helpers!(Devise::URL_HELPERS[:registration])
41
59
 
42
60
  def self.run_generate_hooks!
61
+ self.override_current_resource_helpers!(Devise::URL_HELPERS.slice(:session, :password))
43
62
  self.override_registration_helpers!(Devise::URL_HELPERS[:registration])
44
63
  end
64
+ run_generate_hooks!
45
65
 
46
66
  def _devise_path_name(scope, name)
47
67
  Devise.mappings[scope].path_names[name.to_sym]
@@ -84,6 +104,17 @@ module ActionDispatch
84
104
  @scope[:path], @scope[:as] = path, as
85
105
  end
86
106
 
107
+ def devise_password(mapping, controllers)
108
+ current_resource_name = mapping.path_names["current_#{mapping.singular}".to_sym]
109
+ path, as, @scope[:path], @scope[:as] = @scope[:path], @scope[:as], nil, nil
110
+ resource current_resource_name, only: [] do
111
+ resource :password, :only => [:new, :create, :edit, :update],
112
+ :path => mapping.path_names[:password], :controller => controllers[:passwords]
113
+ end
114
+ ensure
115
+ @scope[:path], @scope[:as] = path, as
116
+ end
117
+
87
118
  def devise_registration(mapping, controllers)
88
119
  path, as, @scope[:path], @scope[:as] = @scope[:path], @scope[:as], nil, nil
89
120
  current_resource_name = mapping.path_names["current_#{mapping.name}".to_sym]
@@ -1,5 +1,5 @@
1
1
  module Devise
2
2
  module BetterRoutes
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
@@ -0,0 +1,215 @@
1
+ require 'spec_helper'
2
+
3
+ describe Devise::BetterRoutes, 'helpers', type: :helper do
4
+ describe %|devise_for :users| do
5
+ context 'registration' do
6
+ specify { expect(users_path).to eq '/users' }
7
+ specify { expect(new_user_path).to eq '/users/new' }
8
+ specify { expect(cancel_current_user_path).to eq '/current_user/cancel' }
9
+ specify { expect(edit_current_user_path).to eq '/current_user/edit' }
10
+ specify { expect(current_user_path).to eq '/current_user' }
11
+ it 'registration_path is delegated to users_path' do
12
+ expect(registration_path(:user)).to eq users_path
13
+ end
14
+ it 'registration_path is delegated to current_user_path on current_users' do
15
+ instance_eval { def controller_name; 'current_users' end }
16
+ expect(registration_path(:user)).to eq current_user_path
17
+ instance_eval { undef controller_name }
18
+ end
19
+ it 'new_registration_path is delegated to new_user_path' do
20
+ expect(new_registration_path(:user)).to eq new_user_path
21
+ end
22
+ it 'cancel_registration_path is delegated to cancel_current_user_path' do
23
+ expect(cancel_registration_path(:user)).to eq cancel_current_user_path
24
+ end
25
+ it 'edit_registration_path is delegated to edit_current_user_path' do
26
+ expect(edit_registration_path(:user)).to eq edit_current_user_path
27
+ end
28
+ end
29
+
30
+ context 'session' do
31
+ specify { expect(current_user_session_path).to eq '/current_user/session' }
32
+ specify { expect(new_current_user_session_path).to eq '/current_user/session/new' }
33
+ it 'session_path is delegated to current_user_session_path' do
34
+ expect(session_path(:user)).to eq current_user_session_path
35
+ end
36
+ it 'new_session_path is delegated to new_current_user_session_path' do
37
+ expect(new_session_path(:user)).to eq new_current_user_session_path
38
+ end
39
+ end
40
+
41
+ context 'password' do
42
+ specify { expect(current_user_password_path).to eq '/current_user/password' }
43
+ specify { expect(new_current_user_password_path).to eq '/current_user/password/new' }
44
+ specify { expect(edit_current_user_password_path).to eq '/current_user/password/edit' }
45
+ it 'password_path is delegated to current_user_password_path' do
46
+ expect(password_path(:user)).to eq current_user_password_path
47
+ end
48
+ it 'new_password_path is delegated to new_current_user_password_path' do
49
+ expect(new_password_path(:user)).to eq new_current_user_password_path
50
+ end
51
+ it 'edit_password_path is delegated to edit_current_user_password_path' do
52
+ expect(edit_password_path(:user)).to eq edit_current_user_password_path
53
+ end
54
+ end
55
+ end
56
+
57
+ describe %|devise_for :rails_programmers, path_names: {current_rails_programmer: 'me'}| do
58
+ context 'registration' do
59
+ specify { expect(rails_programmers_path).to eq '/rails_programmers' }
60
+ specify { expect(new_rails_programmer_path).to eq '/rails_programmers/new' }
61
+ specify { expect(cancel_me_path).to eq '/me/cancel' }
62
+ specify { expect(edit_me_path).to eq '/me/edit' }
63
+ specify { expect(me_path).to eq '/me' }
64
+ it 'registration_path is delegated to rails_programmers_path' do
65
+ expect(registration_path(:rails_programmer)).to eq rails_programmers_path
66
+ end
67
+ it 'registration_path is delegated to me_path on me' do
68
+ instance_eval { def controller_name; 'me' end }
69
+ expect(registration_path(:rails_programmer)).to eq me_path
70
+ instance_eval { undef controller_name }
71
+ end
72
+ it 'new_registration_path is delegated to new_rails_programmer_path' do
73
+ expect(new_registration_path(:rails_programmer)).to eq new_rails_programmer_path
74
+ end
75
+ it 'cancel_registration_path is delegated to cancel_me_path' do
76
+ expect(cancel_registration_path(:rails_programmer)).to eq cancel_me_path
77
+ end
78
+ it 'edit_registration_path is delegated to edit_me_path' do
79
+ expect(edit_registration_path(:rails_programmer)).to eq edit_me_path
80
+ end
81
+ end
82
+
83
+ context 'session' do
84
+ specify { expect(me_session_path).to eq '/me/session' }
85
+ specify { expect(new_me_session_path).to eq '/me/session/new' }
86
+ it 'session_path is delegated to me_session_path' do
87
+ expect(session_path(:rails_programmer)).to eq me_session_path
88
+ end
89
+ it 'new_session_path is delegated to new_me_session_path' do
90
+ expect(new_session_path(:rails_programmer)).to eq new_me_session_path
91
+ end
92
+ end
93
+
94
+ context 'password' do
95
+ specify { expect(me_password_path).to eq '/me/password' }
96
+ specify { expect(new_me_password_path).to eq '/me/password/new' }
97
+ specify { expect(edit_me_password_path).to eq '/me/password/edit' }
98
+ it 'password_path is delegated to me_password_path' do
99
+ expect(password_path(:rails_programmer)).to eq me_password_path
100
+ end
101
+ it 'new_password_path is delegated to new_user_password_path' do
102
+ expect(new_password_path(:rails_programmer)).to eq new_me_password_path
103
+ end
104
+ it 'edit_password_path is delegated to edit_me_password_path' do
105
+ expect(edit_password_path(:rails_programmer)).to eq edit_me_password_path
106
+ end
107
+ end
108
+ end
109
+
110
+ describe %|devise_for :programmers, controllers: {programmers: 'rails_programmers', current_programmer: 'me'}| do
111
+ context 'registration' do
112
+ specify { expect(programmers_path).to eq '/programmers' }
113
+ specify { expect(new_programmer_path).to eq '/programmers/new' }
114
+ specify { expect(cancel_current_programmer_path).to eq '/current_programmer/cancel' }
115
+ specify { expect(edit_current_programmer_path).to eq '/current_programmer/edit' }
116
+ specify { expect(current_programmer_path).to eq '/current_programmer' }
117
+ it 'registration_path is delegated to programmers_path' do
118
+ expect(registration_path(:programmer)).to eq programmers_path
119
+ end
120
+ it 'registration_path is delegated to current_programmer_path on me' do
121
+ instance_eval { def controller_name; 'me' end }
122
+ expect(registration_path(:programmer)).to eq current_programmer_path
123
+ instance_eval { undef controller_name }
124
+ end
125
+ it 'new_registration_path is delegated to new_programmer_path' do
126
+ expect(new_registration_path(:programmer)).to eq new_programmer_path
127
+ end
128
+ it 'cancel_registration_path is delegated to cancel_current_programmer_path' do
129
+ expect(cancel_registration_path(:programmer)).to eq cancel_current_programmer_path
130
+ end
131
+ it 'edit_registration_path is delegated to edit_current_programmer_path' do
132
+ expect(edit_registration_path(:programmer)).to eq edit_current_programmer_path
133
+ end
134
+ end
135
+
136
+ context 'session' do
137
+ specify { expect(current_programmer_session_path).to eq '/current_programmer/session' }
138
+ specify { expect(new_current_programmer_session_path).to eq '/current_programmer/session/new' }
139
+ it 'session_path is delegated to current_programmer_session_path' do
140
+ expect(session_path(:programmer)).to eq current_programmer_session_path
141
+ end
142
+ it 'new_session_path is delegated to new_current_programmer_session_path' do
143
+ expect(new_session_path(:programmer)).to eq new_current_programmer_session_path
144
+ end
145
+ end
146
+
147
+ context 'password' do
148
+ specify { expect(current_programmer_password_path).to eq '/current_programmer/password' }
149
+ specify { expect(new_current_programmer_password_path).to eq '/current_programmer/password/new' }
150
+ specify { expect(edit_current_programmer_password_path).to eq '/current_programmer/password/edit' }
151
+ it 'password_path is delegated to current_programmer_password_path' do
152
+ expect(password_path(:programmer)).to eq current_programmer_password_path
153
+ end
154
+ it 'new_password_path is delegated to new_current_programmer_password_path' do
155
+ expect(new_password_path(:programmer)).to eq new_current_programmer_password_path
156
+ end
157
+ it 'edit_password_path is delegated to edit_current_programmer_password_path' do
158
+ expect(edit_password_path(:programmer)).to eq edit_current_programmer_password_path
159
+ end
160
+ end
161
+ end
162
+
163
+ describe %|devise_for :engineers, controllers: {registrations: 'rails_programmers'}| do
164
+ context 'registration' do
165
+ specify { expect(engineers_path).to eq '/engineers' }
166
+ specify { expect(new_engineer_path).to eq '/engineers/new' }
167
+ specify { expect(cancel_current_engineer_path).to eq '/current_engineer/cancel' }
168
+ specify { expect(edit_current_engineer_path).to eq '/current_engineer/edit' }
169
+ specify { expect(current_engineer_path).to eq '/current_engineer' }
170
+ it 'registration_path is delegated to engineers_path' do
171
+ expect(registration_path(:engineer)).to eq engineers_path
172
+ end
173
+ it 'registration_path is delegated to current_engineer_path on me' do
174
+ instance_eval { def controller_name; 'rails_programmers' end }
175
+ expect(registration_path(:engineer)).to eq current_engineer_path
176
+ instance_eval { undef controller_name }
177
+ end
178
+ it 'new_registration_path is delegated to new_engineer_path' do
179
+ expect(new_registration_path(:engineer)).to eq new_engineer_path
180
+ end
181
+ it 'cancel_registration_path is delegated to cancel_current_engineer_path' do
182
+ expect(cancel_registration_path(:engineer)).to eq cancel_current_engineer_path
183
+ end
184
+ it 'edit_registration_path is delegated to edit_current_engineer_path' do
185
+ expect(edit_registration_path(:engineer)).to eq edit_current_engineer_path
186
+ end
187
+ end
188
+
189
+ context 'session' do
190
+ specify { expect(current_engineer_session_path).to eq '/current_engineer/session' }
191
+ specify { expect(new_current_engineer_session_path).to eq '/current_engineer/session/new' }
192
+ it 'session_path is delegated to current_engineer_session_path' do
193
+ expect(session_path(:engineer)).to eq current_engineer_session_path
194
+ end
195
+ it 'new_session_path is delegated to new_current_engineer_session_path' do
196
+ expect(new_session_path(:engineer)).to eq new_current_engineer_session_path
197
+ end
198
+ end
199
+
200
+ context 'password' do
201
+ specify { expect(current_engineer_password_path).to eq '/current_engineer/password' }
202
+ specify { expect(new_current_engineer_password_path).to eq '/current_engineer/password/new' }
203
+ specify { expect(edit_current_engineer_password_path).to eq '/current_engineer/password/edit' }
204
+ it 'password_path is delegated to current_engineer_password_path' do
205
+ expect(password_path(:engineer)).to eq current_engineer_password_path
206
+ end
207
+ it 'new_password_path is delegated to new_current_engineer_password_path' do
208
+ expect(new_password_path(:engineer)).to eq new_current_engineer_password_path
209
+ end
210
+ it 'edit_password_path is delegated to edit_current_engineer_password_path' do
211
+ expect(edit_password_path(:engineer)).to eq edit_current_engineer_password_path
212
+ end
213
+ end
214
+ end
215
+ end
@@ -0,0 +1,207 @@
1
+ require 'spec_helper'
2
+
3
+ describe Devise::BetterRoutes, 'routing', type: :routing do
4
+ describe %|devise_for :users| do
5
+ context 'registration' do
6
+ it 'routes to users#create' do
7
+ expect(post('/users')).to route_to('users#create')
8
+ end
9
+ it 'routes to users#new' do
10
+ expect(get('/users/new')).to route_to('users#new')
11
+ end
12
+ it 'routes to current_users#cancel' do
13
+ expect(get('/current_user/cancel')).to route_to('current_users#cancel')
14
+ end
15
+ it 'routes to current_users#edit' do
16
+ expect(get('/current_user/edit')).to route_to('current_users#edit')
17
+ end
18
+ it 'routes to current_users#update' do
19
+ expect(put('/current_user')).to route_to('current_users#update')
20
+ #expect(patch('/current_user')).to route_to('current_users#update')
21
+ end
22
+ it 'routes to current_users#destroy' do
23
+ expect(delete('/current_user')).to route_to('current_users#destroy')
24
+ end
25
+ end
26
+
27
+ context 'session' do
28
+ it 'routes to devise/sessions#create' do
29
+ expect(post('/current_user/session')).to route_to('devise/sessions#create')
30
+ end
31
+ it 'routes to devise/sessions#destroy' do
32
+ expect(delete('/current_user/session')).to route_to('devise/sessions#destroy')
33
+ end
34
+ it 'routes to devise/sessions#new' do
35
+ expect(get('/current_user/session/new')).to route_to('devise/sessions#new')
36
+ end
37
+ end
38
+
39
+ context 'password' do
40
+ it 'routes to devise/passwords#create' do
41
+ expect(post('/current_user/password')).to route_to('devise/passwords#create')
42
+ end
43
+ it 'routes to devise/passwords#update' do
44
+ expect(put('/current_user/password')).to route_to('devise/passwords#update')
45
+ end
46
+ it 'routes to devise/passwords#new' do
47
+ expect(get('/current_user/password/new')).to route_to('devise/passwords#new')
48
+ end
49
+ it 'routes to devise/passwords#edit' do
50
+ expect(get('/current_user/password/edit')).to route_to('devise/passwords#edit')
51
+ end
52
+ end
53
+ end
54
+
55
+ describe %|devise_for :rails_programmers, path_names: {current_rails_programmer: 'me'}| do
56
+ context 'registration' do
57
+ it 'routes to rails_programmers#create' do
58
+ expect(post('/rails_programmers')).to route_to('rails_programmers#create')
59
+ end
60
+ it 'routes to rails_programmers#new' do
61
+ expect(get('/rails_programmers/new')).to route_to('rails_programmers#new')
62
+ end
63
+ it 'routes to me#cancel' do
64
+ expect(get('/me/cancel')).to route_to('me#cancel')
65
+ end
66
+ it 'routes to me#edit' do
67
+ expect(get('/me/edit')).to route_to('me#edit')
68
+ end
69
+ it 'routes to me#update' do
70
+ expect(put('/me')).to route_to('me#update')
71
+ #expect(patch('/me')).to route_to('me#update')
72
+ end
73
+ it 'routes to me#destroy' do
74
+ expect(delete('/me')).to route_to('me#destroy')
75
+ end
76
+ end
77
+
78
+ context 'session' do
79
+ it 'routes to devise/sessions#create' do
80
+ expect(post('/me/session')).to route_to('devise/sessions#create')
81
+ end
82
+ it 'routes to devise/sessions#destroy' do
83
+ expect(delete('/me/session')).to route_to('devise/sessions#destroy')
84
+ end
85
+ it 'routes to devise/sessions#new' do
86
+ expect(get('/me/session/new')).to route_to('devise/sessions#new')
87
+ end
88
+ end
89
+
90
+ context 'password' do
91
+ it 'routes to devise/passwords#create' do
92
+ expect(post('/me/password')).to route_to('devise/passwords#create')
93
+ end
94
+ it 'routes to devise/passwords#update' do
95
+ expect(put('/me/password')).to route_to('devise/passwords#update')
96
+ end
97
+ it 'routes to devise/passwords#new' do
98
+ expect(get('/me/password/new')).to route_to('devise/passwords#new')
99
+ end
100
+ it 'routes to devise/passwords#edit' do
101
+ expect(get('/me/password/edit')).to route_to('devise/passwords#edit')
102
+ end
103
+ end
104
+ end
105
+
106
+ describe %|devise_for :programmers, controllers: {programmers: 'rails_programmers', current_programmer: 'me'}| do
107
+ context 'registration' do
108
+ it 'routes to rails_programmers#create' do
109
+ expect(post('/programmers')).to route_to('rails_programmers#create')
110
+ end
111
+ it 'routes to rails_programmers#new' do
112
+ expect(get('/programmers/new')).to route_to('rails_programmers#new')
113
+ end
114
+ it 'routes to me#cancel' do
115
+ expect(get('/current_programmer/cancel')).to route_to('me#cancel')
116
+ end
117
+ it 'routes to me#edit' do
118
+ expect(get('/current_programmer/edit')).to route_to('me#edit')
119
+ end
120
+ it 'routes to me#update' do
121
+ expect(put('/current_programmer')).to route_to('me#update')
122
+ #expect(patch('/current_programmer')).to route_to('me#update')
123
+ end
124
+ it 'routes to me#destroy' do
125
+ expect(delete('/current_programmer')).to route_to('me#destroy')
126
+ end
127
+ end
128
+
129
+ context 'session' do
130
+ it 'routes to devise/sessions#create' do
131
+ expect(post('/current_programmer/session')).to route_to('devise/sessions#create')
132
+ end
133
+ it 'routes to devise/sessions#destroy' do
134
+ expect(delete('/current_programmer/session')).to route_to('devise/sessions#destroy')
135
+ end
136
+ it 'routes to devise/sessions#new' do
137
+ expect(get('/current_programmer/session/new')).to route_to('devise/sessions#new')
138
+ end
139
+ end
140
+
141
+ context 'password' do
142
+ it 'routes to devise/passwords#create' do
143
+ expect(post('/current_programmer/password')).to route_to('devise/passwords#create')
144
+ end
145
+ it 'routes to devise/passwords#update' do
146
+ expect(put('/current_programmer/password')).to route_to('devise/passwords#update')
147
+ end
148
+ it 'routes to devise/passwords#new' do
149
+ expect(get('/current_programmer/password/new')).to route_to('devise/passwords#new')
150
+ end
151
+ it 'routes to devise/passwords#edit' do
152
+ expect(get('/current_programmer/password/edit')).to route_to('devise/passwords#edit')
153
+ end
154
+ end
155
+ end
156
+
157
+ describe %|devise_for :engineers, controllers: {registrations: 'rails_programmers'}| do
158
+ context 'registration' do
159
+ it 'routes to rails_programmers#create' do
160
+ expect(post('/engineers')).to route_to('rails_programmers#create')
161
+ end
162
+ it 'routes to rails_programmers#new' do
163
+ expect(get('/engineers/new')).to route_to('rails_programmers#new')
164
+ end
165
+ it 'routes to rails_programmers#cancel' do
166
+ expect(get('/current_engineer/cancel')).to route_to('rails_programmers#cancel')
167
+ end
168
+ it 'routes to rails_programmers#edit' do
169
+ expect(get('/current_engineer/edit')).to route_to('rails_programmers#edit')
170
+ end
171
+ it 'routes to rails_programmers#update' do
172
+ expect(put('/current_engineer')).to route_to('rails_programmers#update')
173
+ #expect(patch('/current_engineer')).to route_to('rails_programmers#update')
174
+ end
175
+ it 'routes to rails_programmers#destroy' do
176
+ expect(delete('/current_engineer')).to route_to('rails_programmers#destroy')
177
+ end
178
+ end
179
+
180
+ context 'session' do
181
+ it 'routes to devise/sessions#create' do
182
+ expect(post('/current_engineer/session')).to route_to('devise/sessions#create')
183
+ end
184
+ it 'routes to devise/sessions#destroy' do
185
+ expect(delete('/current_engineer/session')).to route_to('devise/sessions#destroy')
186
+ end
187
+ it 'routes to devise/sessions#new' do
188
+ expect(get('/current_engineer/session/new')).to route_to('devise/sessions#new')
189
+ end
190
+ end
191
+
192
+ context 'password' do
193
+ it 'routes to devise/passwords#create' do
194
+ expect(post('/current_engineer/password')).to route_to('devise/passwords#create')
195
+ end
196
+ it 'routes to devise/passwords#update' do
197
+ expect(put('/current_engineer/password')).to route_to('devise/passwords#update')
198
+ end
199
+ it 'routes to devise/passwords#new' do
200
+ expect(get('/current_engineer/password/new')).to route_to('devise/passwords#new')
201
+ end
202
+ it 'routes to devise/passwords#edit' do
203
+ expect(get('/current_engineer/password/edit')).to route_to('devise/passwords#edit')
204
+ end
205
+ end
206
+ end
207
+ end
@@ -4,283 +4,4 @@ describe Devise::BetterRoutes do
4
4
  it 'expect to have a version number' do
5
5
  expect(Devise::BetterRoutes::VERSION).not_to be_nil
6
6
  end
7
-
8
- context 'routing' do
9
- include RSpec::Rails::RoutingExampleGroup
10
- describe 'users' do
11
- context 'registration' do
12
- it 'routes to users#create' do
13
- expect(post('/users')).to route_to('users#create')
14
- end
15
- it 'routes to users#new' do
16
- expect(get('/users/new')).to route_to('users#new')
17
- end
18
- it 'routes to current_users#cancel' do
19
- expect(get('/current_user/cancel')).to route_to('current_users#cancel')
20
- end
21
- it 'routes to current_users#edit' do
22
- expect(get('/current_user/edit')).to route_to('current_users#edit')
23
- end
24
- it 'routes to current_users#update' do
25
- expect(put('/current_user')).to route_to('current_users#update')
26
- #expect(patch('/current_user')).to route_to('current_users#update')
27
- end
28
- it 'routes to current_users#destroy' do
29
- expect(delete('/current_user')).to route_to('current_users#destroy')
30
- end
31
- end
32
-
33
- context 'session' do
34
- it 'routes to devise/sessions#create' do
35
- expect(post('/current_user/session')).to route_to('devise/sessions#create')
36
- end
37
- it 'routes to devise/sessions#destroy' do
38
- expect(delete('/current_user/session')).to route_to('devise/sessions#destroy')
39
- end
40
- it 'routes to devise/sessions#new' do
41
- expect(get('/current_user/session/new')).to route_to('devise/sessions#new')
42
- end
43
- end
44
- end
45
-
46
- describe 'rails_programmers' do
47
- context 'registration' do
48
- it 'routes to rails_programmers#create' do
49
- expect(post('/rails_programmers')).to route_to('rails_programmers#create')
50
- end
51
- it 'routes to rails_programmers#new' do
52
- expect(get('/rails_programmers/new')).to route_to('rails_programmers#new')
53
- end
54
- it 'routes to me#cancel' do
55
- expect(get('/me/cancel')).to route_to('me#cancel')
56
- end
57
- it 'routes to me#edit' do
58
- expect(get('/me/edit')).to route_to('me#edit')
59
- end
60
- it 'routes to me#update' do
61
- expect(put('/me')).to route_to('me#update')
62
- #expect(patch('/me')).to route_to('me#update')
63
- end
64
- it 'routes to me#destroy' do
65
- expect(delete('/me')).to route_to('me#destroy')
66
- end
67
- end
68
-
69
- context 'session' do
70
- it 'routes to devise/sessions#create' do
71
- expect(post('/me/session')).to route_to('devise/sessions#create')
72
- end
73
- it 'routes to devise/sessions#destroy' do
74
- expect(delete('/me/session')).to route_to('devise/sessions#destroy')
75
- end
76
- it 'routes to devise/sessions#new' do
77
- expect(get('/me/session/new')).to route_to('devise/sessions#new')
78
- end
79
- end
80
- end
81
-
82
- describe 'programmers' do
83
- context 'registration' do
84
- it 'routes to rails_programmers#create' do
85
- expect(post('/programmers')).to route_to('rails_programmers#create')
86
- end
87
- it 'routes to rails_programmers#new' do
88
- expect(get('/programmers/new')).to route_to('rails_programmers#new')
89
- end
90
- it 'routes to me#cancel' do
91
- expect(get('/current_programmer/cancel')).to route_to('me#cancel')
92
- end
93
- it 'routes to me#edit' do
94
- expect(get('/current_programmer/edit')).to route_to('me#edit')
95
- end
96
- it 'routes to me#update' do
97
- expect(put('/current_programmer')).to route_to('me#update')
98
- #expect(patch('/current_programmer')).to route_to('me#update')
99
- end
100
- it 'routes to me#destroy' do
101
- expect(delete('/current_programmer')).to route_to('me#destroy')
102
- end
103
- end
104
-
105
- context 'session' do
106
- it 'routes to devise/sessions#create' do
107
- expect(post('/current_programmer/session')).to route_to('devise/sessions#create')
108
- end
109
- it 'routes to devise/sessions#destroy' do
110
- expect(delete('/current_programmer/session')).to route_to('devise/sessions#destroy')
111
- end
112
- it 'routes to devise/sessions#new' do
113
- expect(get('/current_programmer/session/new')).to route_to('devise/sessions#new')
114
- end
115
- end
116
- end
117
-
118
- describe 'engineers' do
119
- context 'registration' do
120
- it 'routes to rails_programmers#create' do
121
- expect(post('/engineers')).to route_to('rails_programmers#create')
122
- end
123
- it 'routes to rails_programmers#new' do
124
- expect(get('/engineers/new')).to route_to('rails_programmers#new')
125
- end
126
- it 'routes to rails_programmers#cancel' do
127
- expect(get('/current_engineer/cancel')).to route_to('rails_programmers#cancel')
128
- end
129
- it 'routes to rails_programmers#edit' do
130
- expect(get('/current_engineer/edit')).to route_to('rails_programmers#edit')
131
- end
132
- it 'routes to rails_programmers#update' do
133
- expect(put('/current_engineer')).to route_to('rails_programmers#update')
134
- #expect(patch('/current_engineer')).to route_to('rails_programmers#update')
135
- end
136
- it 'routes to rails_programmers#destroy' do
137
- expect(delete('/current_engineer')).to route_to('rails_programmers#destroy')
138
- end
139
- end
140
-
141
- context 'session' do
142
- it 'routes to devise/sessions#create' do
143
- expect(post('/current_engineer/session')).to route_to('devise/sessions#create')
144
- end
145
- it 'routes to devise/sessions#destroy' do
146
- expect(delete('/current_engineer/session')).to route_to('devise/sessions#destroy')
147
- end
148
- it 'routes to devise/sessions#new' do
149
- expect(get('/current_engineer/session/new')).to route_to('devise/sessions#new')
150
- end
151
- end
152
- end
153
- end
154
-
155
- context 'URL helpers' do
156
- include Rails.application.routes.url_helpers
157
- include Devise::Controllers::UrlHelpers
158
- describe 'users' do
159
- context 'registration' do
160
- specify { expect(users_path).to eq '/users' }
161
- specify { expect(new_user_path).to eq '/users/new' }
162
- specify { expect(cancel_current_user_path).to eq '/current_user/cancel' }
163
- specify { expect(edit_current_user_path).to eq '/current_user/edit' }
164
- specify { expect(current_user_path).to eq '/current_user' }
165
- it 'registration_path is delegated to users_path' do
166
- expect(registration_path(:user)).to eq users_path
167
- end
168
- it 'registration_path is delegated to current_user_path on current_users' do
169
- instance_eval { def controller_name; 'current_users' end }
170
- expect(registration_path(:user)).to eq current_user_path
171
- instance_eval { undef controller_name }
172
- end
173
- it 'new_registration_path is delegated to new_user_path' do
174
- expect(new_registration_path(:user)).to eq new_user_path
175
- end
176
- it 'cancel_registration_path is delegated to cancel_current_user_path' do
177
- expect(cancel_registration_path(:user)).to eq cancel_current_user_path
178
- end
179
- it 'edit_registration_path is delegated to edit_current_user_path' do
180
- expect(edit_registration_path(:user)).to eq edit_current_user_path
181
- end
182
- end
183
-
184
- context 'session' do
185
- specify { expect(current_user_session_path).to eq '/current_user/session' }
186
- specify { expect(new_current_user_session_path).to eq '/current_user/session/new' }
187
- end
188
- end
189
-
190
- describe 'rails_programmers' do
191
- context 'registration' do
192
- specify { expect(rails_programmers_path).to eq '/rails_programmers' }
193
- specify { expect(new_rails_programmer_path).to eq '/rails_programmers/new' }
194
- specify { expect(cancel_me_path).to eq '/me/cancel' }
195
- specify { expect(edit_me_path).to eq '/me/edit' }
196
- specify { expect(me_path).to eq '/me' }
197
- it 'registration_path is delegated to rails_programmers_path' do
198
- expect(registration_path(:rails_programmer)).to eq rails_programmers_path
199
- end
200
- it 'registration_path is delegated to me_path on me' do
201
- instance_eval { def controller_name; 'me' end }
202
- expect(registration_path(:rails_programmer)).to eq me_path
203
- instance_eval { undef controller_name }
204
- end
205
- it 'new_registration_path is delegated to new_rails_programmer_path' do
206
- expect(new_registration_path(:rails_programmer)).to eq new_rails_programmer_path
207
- end
208
- it 'cancel_registration_path is delegated to cancel_me_path' do
209
- expect(cancel_registration_path(:rails_programmer)).to eq cancel_me_path
210
- end
211
- it 'edit_registration_path is delegated to edit_me_path' do
212
- expect(edit_registration_path(:rails_programmer)).to eq edit_me_path
213
- end
214
- end
215
-
216
- context 'session' do
217
- specify { expect(me_session_path).to eq '/me/session' }
218
- specify { expect(new_me_session_path).to eq '/me/session/new' }
219
- end
220
- end
221
-
222
- describe 'programmers' do
223
- context 'registration' do
224
- specify { expect(programmers_path).to eq '/programmers' }
225
- specify { expect(new_programmer_path).to eq '/programmers/new' }
226
- specify { expect(cancel_current_programmer_path).to eq '/current_programmer/cancel' }
227
- specify { expect(edit_current_programmer_path).to eq '/current_programmer/edit' }
228
- specify { expect(current_programmer_path).to eq '/current_programmer' }
229
- it 'registration_path is delegated to programmers_path' do
230
- expect(registration_path(:programmer)).to eq programmers_path
231
- end
232
- it 'registration_path is delegated to current_programmer_path on me' do
233
- instance_eval { def controller_name; 'me' end }
234
- expect(registration_path(:programmer)).to eq current_programmer_path
235
- instance_eval { undef controller_name }
236
- end
237
- it 'new_registration_path is delegated to new_programmer_path' do
238
- expect(new_registration_path(:programmer)).to eq new_programmer_path
239
- end
240
- it 'cancel_registration_path is delegated to cancel_current_programmer_path' do
241
- expect(cancel_registration_path(:programmer)).to eq cancel_current_programmer_path
242
- end
243
- it 'edit_registration_path is delegated to edit_current_programmer_path' do
244
- expect(edit_registration_path(:programmer)).to eq edit_current_programmer_path
245
- end
246
- end
247
-
248
- context 'session' do
249
- specify { expect(current_programmer_session_path).to eq '/current_programmer/session' }
250
- specify { expect(new_current_programmer_session_path).to eq '/current_programmer/session/new' }
251
- end
252
- end
253
-
254
- describe 'engineers' do
255
- context 'registration' do
256
- specify { expect(engineers_path).to eq '/engineers' }
257
- specify { expect(new_engineer_path).to eq '/engineers/new' }
258
- specify { expect(cancel_current_engineer_path).to eq '/current_engineer/cancel' }
259
- specify { expect(edit_current_engineer_path).to eq '/current_engineer/edit' }
260
- specify { expect(current_engineer_path).to eq '/current_engineer' }
261
- it 'registration_path is delegated to engineers_path' do
262
- expect(registration_path(:engineer)).to eq engineers_path
263
- end
264
- it 'registration_path is delegated to current_engineer_path on me' do
265
- instance_eval { def controller_name; 'rails_programmers' end }
266
- expect(registration_path(:engineer)).to eq current_engineer_path
267
- instance_eval { undef controller_name }
268
- end
269
- it 'new_registration_path is delegated to new_engineer_path' do
270
- expect(new_registration_path(:engineer)).to eq new_engineer_path
271
- end
272
- it 'cancel_registration_path is delegated to cancel_current_engineer_path' do
273
- expect(cancel_registration_path(:engineer)).to eq cancel_current_engineer_path
274
- end
275
- it 'edit_registration_path is delegated to edit_current_engineer_path' do
276
- expect(edit_registration_path(:engineer)).to eq edit_current_engineer_path
277
- end
278
- end
279
-
280
- context 'session' do
281
- specify { expect(current_engineer_session_path).to eq '/current_engineer/session' }
282
- specify { expect(new_current_engineer_session_path).to eq '/current_engineer/session/new' }
283
- end
284
- end
285
- end
286
7
  end
@@ -1,5 +1,5 @@
1
1
  class User < ActiveRecord::Base
2
- devise :database_authenticatable, :registerable
2
+ devise :database_authenticatable, :registerable, :recoverable
3
3
  end
4
4
  class RailsProgrammer < User; end
5
5
  class Programmer < User; end
@@ -6,5 +6,6 @@ require 'rspec/rails'
6
6
  require 'rspec/autorun'
7
7
 
8
8
  RSpec.configure do |config|
9
- # some config ...
9
+ config.include Rails.application.routes.url_helpers, type: :helper
10
+ config.include Devise::Controllers::UrlHelpers, type: :helper
10
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise-better_routes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-12 00:00:00.000000000 Z
12
+ date: 2013-07-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: devise
@@ -140,6 +140,8 @@ files:
140
140
  - devise-better_routes.gemspec
141
141
  - lib/devise/better_routes.rb
142
142
  - lib/devise/better_routes/version.rb
143
+ - spec/devise/better_routes_helpers_spec.rb
144
+ - spec/devise/better_routes_routing_spec.rb
143
145
  - spec/devise/better_routes_spec.rb
144
146
  - spec/rails_app/Rakefile
145
147
  - spec/rails_app/app/assets/images/.keep
@@ -198,7 +200,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
198
200
  version: '0'
199
201
  segments:
200
202
  - 0
201
- hash: -574275781529839639
203
+ hash: -4129266091696730390
202
204
  required_rubygems_version: !ruby/object:Gem::Requirement
203
205
  none: false
204
206
  requirements:
@@ -207,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
207
209
  version: '0'
208
210
  segments:
209
211
  - 0
210
- hash: -574275781529839639
212
+ hash: -4129266091696730390
211
213
  requirements: []
212
214
  rubyforge_project:
213
215
  rubygems_version: 1.8.24
@@ -215,6 +217,8 @@ signing_key:
215
217
  specification_version: 3
216
218
  summary: Better routes patch for Devise
217
219
  test_files:
220
+ - spec/devise/better_routes_helpers_spec.rb
221
+ - spec/devise/better_routes_routing_spec.rb
218
222
  - spec/devise/better_routes_spec.rb
219
223
  - spec/rails_app/Rakefile
220
224
  - spec/rails_app/app/assets/images/.keep