exposure 0.0.6 → 0.0.7
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.
- data/.gitignore +3 -0
- data/NOTES +57 -0
- data/Rakefile +11 -20
- data/VERSION +1 -0
- data/lib/exposure/behaviors/building.rb +36 -0
- data/lib/exposure/behaviors/callbacks.rb +53 -0
- data/lib/exposure/behaviors/finding.rb +84 -0
- data/lib/exposure/behaviors/flashing.rb +62 -0
- data/lib/exposure/behaviors/responding.rb +80 -0
- data/lib/exposure/configuration.rb +23 -41
- data/lib/exposure/options.rb +55 -0
- data/lib/exposure/patterns/resources.rb +21 -116
- data/lib/exposure.rb +7 -2
- data/spec/callbacks_spec.rb +46 -0
- data/spec/configuration_spec.rb +82 -0
- data/spec/exposure_spec.rb +16 -6
- data/spec/finders/finder_spec.rb +18 -12
- data/spec/finders/nested_resources_finder_spec.rb +19 -9
- data/spec/flashers/flash_with_block_spec.rb +20 -10
- data/spec/flashers/flash_with_method_spec.rb +19 -15
- data/spec/flashers/flash_with_proc_spec.rb +15 -9
- data/spec/flashers/flash_with_string_spec.rb +15 -10
- data/spec/resources_spec.rb +19 -7
- data/spec/responder_spec.rb +41 -0
- data/spec/responders/respond_to_mime_types_spec.rb +16 -10
- data/spec/responders/respond_with_block_spec.rb +14 -8
- data/spec/responders/respond_with_method_spec.rb +20 -14
- data/spec/responders/respond_with_proc_spec.rb +15 -8
- data/spec/spec_helper.rb +2 -5
- metadata +42 -25
- data/Manifest.txt +0 -39
- data/exposure.gemspec +0 -31
- data/lib/exposure/common.rb +0 -143
@@ -5,10 +5,12 @@ module Exposure
|
|
5
5
|
base::const_set(:DefaultResponses, DefaultResponses)
|
6
6
|
base::const_set(:DefaultFlashMessages, DefaultFlashMessages)
|
7
7
|
base::const_set(:Finders, { true => {}, false => {} })
|
8
|
-
base::const_set(:FlashMessages, {
|
8
|
+
base::const_set(:FlashMessages, {})
|
9
9
|
base::const_set(:Responses, {} )
|
10
10
|
end
|
11
11
|
|
12
|
+
DefaultActions = [:index, :show, :new, :create, :edit, :update, :destroy]
|
13
|
+
|
12
14
|
Callbacks = %w(
|
13
15
|
before_find after_find after_find_on_failure after_find_on_success
|
14
16
|
before_find_many after_find_many after_find_many_on_failure after_find_many_on_success
|
@@ -21,12 +23,9 @@ module Exposure
|
|
21
23
|
)
|
22
24
|
|
23
25
|
DefaultFlashMessages = {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
:destroy => Proc.new { "#{resource_name.capitalize} successfully removed" }
|
28
|
-
},
|
29
|
-
false => {}
|
26
|
+
'create.success.html' => Proc.new { "#{resource_name.capitalize} successfully created" },
|
27
|
+
'update.success.html' => Proc.new { "#{resource_name.capitalize} successfully updated" },
|
28
|
+
'destroy.success.html' => Proc.new { "#{resource_name.capitalize} successfully removed" }
|
30
29
|
}
|
31
30
|
|
32
31
|
DefaultResponses = {
|
@@ -86,7 +85,7 @@ module Exposure
|
|
86
85
|
|
87
86
|
def new
|
88
87
|
run_callbacks(:before_assign)
|
89
|
-
|
88
|
+
build_record
|
90
89
|
run_callbacks(:after_assign)
|
91
90
|
run_callbacks(:before_response)
|
92
91
|
run_callbacks(:before_response_on_success)
|
@@ -95,7 +94,7 @@ module Exposure
|
|
95
94
|
|
96
95
|
def create
|
97
96
|
run_callbacks(:before_assign)
|
98
|
-
|
97
|
+
build_record
|
99
98
|
run_callbacks(:after_assign)
|
100
99
|
|
101
100
|
run_callbacks(:before_create)
|
@@ -106,14 +105,14 @@ module Exposure
|
|
106
105
|
run_callbacks(:after_create_on_success)
|
107
106
|
run_callbacks(:before_response)
|
108
107
|
run_callbacks(:before_response_on_success)
|
109
|
-
flash_for(:create,
|
108
|
+
flash_for(:create, :success)
|
110
109
|
response_for(:create, :success, request.format.to_sym)
|
111
110
|
else
|
112
111
|
run_callbacks(:after_save_on_failure)
|
113
112
|
run_callbacks(:after_create_on_failure)
|
114
113
|
run_callbacks(:before_response)
|
115
114
|
run_callbacks(:before_response_on_failure)
|
116
|
-
flash_for(:create,
|
115
|
+
flash_for(:create, :failure)
|
117
116
|
response_for(:create, :failure, request.format.to_sym)
|
118
117
|
end
|
119
118
|
|
@@ -146,14 +145,14 @@ module Exposure
|
|
146
145
|
run_callbacks(:after_update_on_success)
|
147
146
|
run_callbacks(:before_response)
|
148
147
|
run_callbacks(:before_response_on_success)
|
149
|
-
flash_for(:update,
|
148
|
+
flash_for(:update, :success)
|
150
149
|
response_for(:update, :success, request.format.to_sym)
|
151
150
|
else
|
152
151
|
run_callbacks(:after_save_on_failure)
|
153
152
|
run_callbacks(:after_create_on_failure)
|
154
153
|
run_callbacks(:before_response)
|
155
154
|
run_callbacks(:before_response_on_failure)
|
156
|
-
flash_for(:update,
|
155
|
+
flash_for(:update, :failure)
|
157
156
|
response_for(:update, :failure, request.format.to_sym)
|
158
157
|
end
|
159
158
|
else
|
@@ -177,7 +176,7 @@ module Exposure
|
|
177
176
|
run_callbacks(:after_destroy_on_success)
|
178
177
|
run_callbacks(:before_response)
|
179
178
|
run_callbacks(:before_response_on_success)
|
180
|
-
flash_for(:destroy,
|
179
|
+
flash_for(:destroy, :success)
|
181
180
|
response_for(:destroy, :success, request.format.to_sym)
|
182
181
|
|
183
182
|
else
|
@@ -188,104 +187,6 @@ module Exposure
|
|
188
187
|
end
|
189
188
|
|
190
189
|
private
|
191
|
-
def custom_response_for(action_name, action_status, format)
|
192
|
-
if responder = self.class::Responses["#{action_name}.#{action_status}.#{format}"]
|
193
|
-
case responder
|
194
|
-
when Symbol
|
195
|
-
self.send(responder)
|
196
|
-
when Proc
|
197
|
-
self.instance_eval &responder
|
198
|
-
end
|
199
|
-
else
|
200
|
-
false
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
def default_response_for(action_name, action_status, format)
|
205
|
-
if responder = self.class::DefaultResponses["#{action_name}.#{action_status}.#{format}"]
|
206
|
-
self.instance_eval &responder
|
207
|
-
else
|
208
|
-
return false
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
def response_for(action_name, action_status, format = :html)
|
213
|
-
format = :html if format == :all
|
214
|
-
custom_response_for(action_name, action_status, format) || default_response_for(action_name, action_status, format) || head(:not_acceptable)
|
215
|
-
end
|
216
|
-
|
217
|
-
def custom_flash_for(action_name, action_successful)
|
218
|
-
if flash_message = self.class::FlashMessages[action_successful][action_name]
|
219
|
-
case flash_message
|
220
|
-
when String
|
221
|
-
flash[:message] = flash_message
|
222
|
-
when Symbol
|
223
|
-
flash[:message] = self.send(flash_message)
|
224
|
-
when Proc
|
225
|
-
flash[:message] = self.instance_eval(&flash_message)
|
226
|
-
end
|
227
|
-
else
|
228
|
-
false
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
def default_flash_for(action_name, action_successful)
|
233
|
-
if message_proc = self.class::DefaultFlashMessages[action_successful][action_name]
|
234
|
-
flash[:message] = self.instance_eval(&message_proc)
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
def flash_for(action_name, action_successful)
|
239
|
-
custom_flash_for(action_name, action_successful) || default_flash_for(action_name, action_successful)
|
240
|
-
end
|
241
|
-
|
242
|
-
def custom_finder_for(resource_name)
|
243
|
-
if finder = self.class::Finders[resource_name]
|
244
|
-
return finder
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
def default_finder_for(resource_name)
|
249
|
-
if finder = self.class::DefaultFinders[resource_name]
|
250
|
-
return finder
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
|
-
def finder_for(resource_name)
|
255
|
-
custom_finder_for(resource_name) || default_finder_for(resource_name)
|
256
|
-
end
|
257
|
-
|
258
|
-
def call_finder_chain(object, chain, use_associaiton = true)
|
259
|
-
links = chain.shift
|
260
|
-
return object unless links
|
261
|
-
|
262
|
-
message = finder_for(links[0])
|
263
|
-
association = links[1] if use_associaiton
|
264
|
-
|
265
|
-
case message
|
266
|
-
when Symbol
|
267
|
-
value = self.send(message)
|
268
|
-
when Proc
|
269
|
-
value = self.instance_eval(&message)
|
270
|
-
else
|
271
|
-
raise "invalid finder of #{message.inspect}"
|
272
|
-
end
|
273
|
-
|
274
|
-
if value.kind_of?(Array) && !value.respond_to?(:proxy_target)
|
275
|
-
if use_associaiton
|
276
|
-
call_finder_chain(object.send(association).send(*value), chain)
|
277
|
-
else
|
278
|
-
call_finder_chain(object.send(*value), chain)
|
279
|
-
end
|
280
|
-
else
|
281
|
-
call_finder_chain(value, chain)
|
282
|
-
end
|
283
|
-
end
|
284
|
-
|
285
|
-
def builder_for(resource_name)
|
286
|
-
custom_builder_for(resource_name) || default_builder_for(resource_name)
|
287
|
-
end
|
288
|
-
|
289
190
|
def resource_name
|
290
191
|
self.class.resource_name
|
291
192
|
end
|
@@ -294,6 +195,10 @@ module Exposure
|
|
294
195
|
self.class.resources_name
|
295
196
|
end
|
296
197
|
|
198
|
+
def parent_model
|
199
|
+
self.class.parent_model
|
200
|
+
end
|
201
|
+
|
297
202
|
def save_record
|
298
203
|
@resource.save
|
299
204
|
end
|
@@ -302,16 +207,16 @@ module Exposure
|
|
302
207
|
@resource.update_attributes(params[resource_name])
|
303
208
|
end
|
304
209
|
|
305
|
-
def
|
306
|
-
@resource = instance_variable_set("@#{resource_name}",
|
210
|
+
def build_record
|
211
|
+
@resource = instance_variable_set("@#{resource_name}", parent_model.new(params[resource_name]))
|
307
212
|
end
|
308
213
|
|
309
214
|
def find_record
|
310
|
-
@resource = instance_variable_set("@#{resource_name}", call_finder_chain(
|
215
|
+
@resource = instance_variable_set("@#{resource_name}", call_finder_chain(parent_model, self.class.member_nesting.clone, false))
|
311
216
|
end
|
312
217
|
|
313
218
|
def find_records
|
314
|
-
@resources = instance_variable_set("@#{resources_name}", call_finder_chain(
|
219
|
+
@resources = instance_variable_set("@#{resources_name}", call_finder_chain(parent_model, self.class.collection_nesting.clone, false))
|
315
220
|
end
|
316
221
|
|
317
222
|
def delete_record
|
data/lib/exposure.rb
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__)) unless
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
require 'action_controller'
|
4
|
+
require 'exposure/options'
|
4
5
|
require 'exposure/configuration'
|
5
|
-
require 'exposure/
|
6
|
+
require 'exposure/behaviors/building'
|
7
|
+
require 'exposure/behaviors/callbacks'
|
8
|
+
require 'exposure/behaviors/finding'
|
9
|
+
require 'exposure/behaviors/flashing'
|
10
|
+
require 'exposure/behaviors/responding'
|
11
|
+
|
6
12
|
require 'exposure/patterns/resources'
|
7
|
-
require 'exposure/patterns/resource'
|
8
13
|
|
9
14
|
module Exposure
|
10
15
|
VERSION = '0.0.6'
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe "callbacks'", :type => :controller do
|
4
|
+
setup = lambda {
|
5
|
+
class PiratesController < ActionController::Base
|
6
|
+
expose_many(:pirates)
|
7
|
+
private
|
8
|
+
def first_callback_called
|
9
|
+
@callback_called = 1
|
10
|
+
end
|
11
|
+
|
12
|
+
def second_callback_called
|
13
|
+
@callback_called += 1
|
14
|
+
end
|
15
|
+
|
16
|
+
def third_callback_called
|
17
|
+
@callback_called += 1
|
18
|
+
end
|
19
|
+
end
|
20
|
+
}
|
21
|
+
setup.call
|
22
|
+
|
23
|
+
ActionController::Routing::Routes.draw do |map|
|
24
|
+
map.resources :pirates
|
25
|
+
end
|
26
|
+
|
27
|
+
controller_name :pirates
|
28
|
+
Object.remove_class(PiratesController)
|
29
|
+
|
30
|
+
before(:each) do
|
31
|
+
setup.call
|
32
|
+
@controller = PiratesController.new
|
33
|
+
@request = ActionController::TestRequest.new
|
34
|
+
@response = ActionController::TestResponse.new
|
35
|
+
end
|
36
|
+
|
37
|
+
after(:each) do
|
38
|
+
Object.remove_class(PiratesController)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "can call multiple callbacks" do
|
42
|
+
PiratesController.after :assign, :first_callback_called, :second_callback_called, :third_callback_called
|
43
|
+
get(:new)
|
44
|
+
should assign_to(:callback_called).with(3)
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe "included actions" do
|
4
|
+
AllActions = [:index, :show, :new, :create, :edit, :update, :destroy]
|
5
|
+
IncludedActions = [:new, :show]
|
6
|
+
ExcludedActions = AllActions - IncludedActions
|
7
|
+
|
8
|
+
setup = lambda {
|
9
|
+
class ShipTypesController < ActionController::Base
|
10
|
+
expose_many(:ship_types, :only => IncludedActions)
|
11
|
+
end
|
12
|
+
}
|
13
|
+
|
14
|
+
setup.call
|
15
|
+
|
16
|
+
ActionController::Routing::Routes.draw do |map|
|
17
|
+
map.resources :ship_types
|
18
|
+
end
|
19
|
+
|
20
|
+
Object.remove_class(ShipTypesController)
|
21
|
+
|
22
|
+
before(:each) do
|
23
|
+
setup.call
|
24
|
+
@controller = ShipTypesController.new
|
25
|
+
@request = ActionController::TestRequest.new
|
26
|
+
@response = ActionController::TestResponse.new
|
27
|
+
end
|
28
|
+
|
29
|
+
after(:each) do
|
30
|
+
Object.remove_class(ShipTypesController)
|
31
|
+
end
|
32
|
+
|
33
|
+
IncludedActions.each do |action|
|
34
|
+
it "should have action #{action}" do
|
35
|
+
@controller.should respond_to(action)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
ExcludedActions.each do |action|
|
40
|
+
it "should have not action #{action}" do
|
41
|
+
@controller.should_not respond_to(action)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "excluded actions" do
|
47
|
+
setup = lambda {
|
48
|
+
class ShipTypesController < ActionController::Base
|
49
|
+
expose_many(:ship_types, :except => ExcludedActions)
|
50
|
+
end
|
51
|
+
}
|
52
|
+
setup.call
|
53
|
+
|
54
|
+
ActionController::Routing::Routes.draw do |map|
|
55
|
+
map.resources :ship_types
|
56
|
+
end
|
57
|
+
|
58
|
+
Object.remove_class(ShipTypesController)
|
59
|
+
|
60
|
+
before(:each) do
|
61
|
+
setup.call
|
62
|
+
@controller = ShipTypesController.new
|
63
|
+
@request = ActionController::TestRequest.new
|
64
|
+
@response = ActionController::TestResponse.new
|
65
|
+
end
|
66
|
+
|
67
|
+
after(:each) do
|
68
|
+
Object.remove_class(ShipTypesController)
|
69
|
+
end
|
70
|
+
|
71
|
+
IncludedActions.each do |action|
|
72
|
+
it "should have action #{action}" do
|
73
|
+
@controller.should respond_to(action)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
ExcludedActions.each do |action|
|
78
|
+
it "should have not action #{action}" do
|
79
|
+
@controller.should_not respond_to(action)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/spec/exposure_spec.rb
CHANGED
@@ -1,18 +1,28 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
2
|
|
3
3
|
describe "exposure", :type => :controller do
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
setup = lambda {
|
5
|
+
class ShipTypesController < ActionController::Base
|
6
|
+
expose_many(:ship_types)
|
7
|
+
end
|
8
|
+
}
|
9
|
+
setup.call
|
7
10
|
controller_name :ship_types
|
11
|
+
Object.remove_class(ShipTypesController)
|
12
|
+
|
13
|
+
ActionController::Routing::Routes.draw do |map|
|
14
|
+
map.resources :ship_types
|
15
|
+
end
|
8
16
|
|
9
17
|
before(:each) do
|
18
|
+
setup.call
|
10
19
|
@controller = ShipTypesController.new
|
11
20
|
@request = ActionController::TestRequest.new
|
12
21
|
@response = ActionController::TestResponse.new
|
13
|
-
|
14
|
-
|
15
|
-
|
22
|
+
end
|
23
|
+
|
24
|
+
after(:each) do
|
25
|
+
Object.remove_class(ShipTypesController)
|
16
26
|
end
|
17
27
|
|
18
28
|
describe "parent models" do
|
data/spec/finders/finder_spec.rb
CHANGED
@@ -1,30 +1,36 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
|
-
describe "finders", :type => :controller do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
describe "finders", :type => :controller do
|
4
|
+
setup = lambda {
|
5
|
+
class PiratesController < ActionController::Base
|
6
|
+
expose_many(:pirates)
|
7
|
+
private
|
8
|
+
def find_pirate
|
9
|
+
Pirate.find_by_title(params[:id])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
ActionController::Routing::Routes.draw do |map|
|
14
|
+
map.resources :pirates
|
15
|
+
end
|
16
|
+
}
|
11
17
|
|
18
|
+
setup.call
|
12
19
|
controller_name :pirates
|
20
|
+
Object.remove_class(PiratesController)
|
13
21
|
|
14
22
|
before(:each) do
|
23
|
+
setup.call
|
15
24
|
@controller = PiratesController.new
|
16
25
|
@request = ActionController::TestRequest.new
|
17
26
|
@response = ActionController::TestResponse.new
|
18
|
-
ActionController::Routing::Routes.draw do |map|
|
19
|
-
map.resources :pirates
|
20
|
-
end
|
21
27
|
|
22
28
|
@pirate = Factory.stub(:pirate)
|
23
29
|
Pirate.stub(:find_by_title => @pirate)
|
24
30
|
end
|
25
31
|
|
26
32
|
after(:each) do
|
27
|
-
PiratesController
|
33
|
+
Object.remove_class(PiratesController)
|
28
34
|
end
|
29
35
|
|
30
36
|
it "finds with a method name as symbol" do
|
@@ -1,21 +1,27 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
|
-
describe "nested finders", :type => :controller do
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
describe "nested finders", :type => :controller do
|
4
|
+
setup = lambda {
|
5
|
+
class ShipsController < ActionController::Base
|
6
|
+
expose_many(:ships, :nested => [:pirates])
|
7
|
+
end
|
8
|
+
|
9
|
+
ActionController::Routing::Routes.draw do |map|
|
10
|
+
map.resources :pirates do |pirate|
|
11
|
+
pirate.resources :ships
|
12
|
+
end
|
13
|
+
end
|
14
|
+
}
|
7
15
|
|
16
|
+
setup.call
|
8
17
|
controller_name :ships
|
18
|
+
Object.remove_class(ShipsController)
|
9
19
|
|
10
20
|
before(:each) do
|
21
|
+
setup.call
|
11
22
|
@controller = ShipsController.new
|
12
23
|
@request = ActionController::TestRequest.new
|
13
24
|
@response = ActionController::TestResponse.new
|
14
|
-
ActionController::Routing::Routes.draw do |map|
|
15
|
-
map.resources :pirates do |pirate|
|
16
|
-
pirate.resources :ships
|
17
|
-
end
|
18
|
-
end
|
19
25
|
|
20
26
|
@pirate = Factory.create(:pirate_with_ships)
|
21
27
|
Pirate.stub(:find => @pirate)
|
@@ -23,6 +29,10 @@ describe "nested finders", :type => :controller do
|
|
23
29
|
get(:index, {:pirate_id => 1})
|
24
30
|
end
|
25
31
|
|
32
|
+
after(:each) do
|
33
|
+
Object.remove_class(ShipsController)
|
34
|
+
end
|
35
|
+
|
26
36
|
it { should assign_to(:ships) }
|
27
37
|
it { should assign_to(:resources) }
|
28
38
|
|
@@ -1,22 +1,28 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
|
-
describe "flash messages with blocks", :type => :controller do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
describe "flash messages with blocks", :type => :controller do
|
4
|
+
setup = lambda {
|
5
|
+
class PiratesController < ActionController::Base
|
6
|
+
expose_many(:pirates)
|
7
|
+
PiratesController.flash_for :create do
|
8
|
+
"the flash is set to #{@pirate.title}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
}
|
12
|
+
setup.call
|
13
|
+
|
14
|
+
ActionController::Routing::Routes.draw do |map|
|
15
|
+
map.resources :pirates, :collection => {:test => :any}
|
16
|
+
end
|
10
17
|
|
11
18
|
controller_name :pirates
|
19
|
+
Object.remove_class(PiratesController)
|
12
20
|
|
13
21
|
before(:each) do
|
22
|
+
setup.call
|
14
23
|
@controller = PiratesController.new
|
15
24
|
@request = ActionController::TestRequest.new
|
16
25
|
@response = ActionController::TestResponse.new
|
17
|
-
ActionController::Routing::Routes.draw do |map|
|
18
|
-
map.resources :pirates, :collection => {:test => :any}
|
19
|
-
end
|
20
26
|
|
21
27
|
@pirate = Factory.stub(:pirate, {:title => 'Captain'})
|
22
28
|
Pirate.stub(:new => @pirate)
|
@@ -28,5 +34,9 @@ describe "flash messages with blocks", :type => :controller do
|
|
28
34
|
post(:create)
|
29
35
|
end
|
30
36
|
|
37
|
+
after(:each) do
|
38
|
+
Object.remove_class(PiratesController)
|
39
|
+
end
|
40
|
+
|
31
41
|
it { should set_the_flash.to(@custom_flash_message) }
|
32
42
|
end
|
@@ -1,24 +1,29 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
|
-
describe "flash messages with methods", :type => :controller do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
describe "flash messages with methods", :type => :controller do
|
4
|
+
setup = lambda {
|
5
|
+
class PiratesController < ActionController::Base
|
6
|
+
expose_many(:pirates)
|
7
|
+
private
|
8
|
+
def custom_flash_message
|
9
|
+
'the flash was set'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
ActionController::Routing::Routes.draw do |map|
|
14
|
+
map.resources :pirates, :collection => {:test => :any}
|
15
|
+
end
|
16
|
+
}
|
11
17
|
|
18
|
+
setup.call
|
12
19
|
controller_name :pirates
|
20
|
+
Object.remove_class(PiratesController)
|
13
21
|
|
14
22
|
before(:each) do
|
23
|
+
setup.call
|
15
24
|
@controller = PiratesController.new
|
16
25
|
@request = ActionController::TestRequest.new
|
17
26
|
@response = ActionController::TestResponse.new
|
18
|
-
ActionController::Routing::Routes.draw do |map|
|
19
|
-
map.resources :pirates, :collection => {:test => :any}
|
20
|
-
end
|
21
|
-
|
22
27
|
@custom_flash_message = 'the flash was set'
|
23
28
|
|
24
29
|
@pirate = Factory.stub(:pirate)
|
@@ -26,8 +31,7 @@ describe "flash messages with methods", :type => :controller do
|
|
26
31
|
end
|
27
32
|
|
28
33
|
after(:each) do
|
29
|
-
PiratesController
|
30
|
-
PiratesController::FlashMessages[false].clear
|
34
|
+
Object.remove_class(PiratesController)
|
31
35
|
end
|
32
36
|
|
33
37
|
describe "responding with a method call" do
|
@@ -82,5 +86,5 @@ describe "flash messages with methods", :type => :controller do
|
|
82
86
|
post(:create)
|
83
87
|
should set_the_flash.to(@custom_flash_message)
|
84
88
|
end
|
85
|
-
|
89
|
+
end
|
86
90
|
end
|
@@ -1,19 +1,26 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
|
-
describe "flash messages with procs", :type => :controller do
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
describe "flash messages with procs", :type => :controller do
|
4
|
+
setup = lambda {
|
5
|
+
class PiratesController < ActionController::Base
|
6
|
+
expose_many(:pirates)
|
7
|
+
end
|
8
|
+
}
|
9
|
+
setup.call
|
10
|
+
|
11
|
+
ActionController::Routing::Routes.draw do |map|
|
12
|
+
map.resources :pirates, :collection => {:test => :any}
|
13
|
+
end
|
7
14
|
|
8
15
|
controller_name :pirates
|
16
|
+
Object.remove_class(PiratesController)
|
9
17
|
|
10
18
|
before(:each) do
|
19
|
+
setup.call
|
20
|
+
|
11
21
|
@controller = PiratesController.new
|
12
22
|
@request = ActionController::TestRequest.new
|
13
23
|
@response = ActionController::TestResponse.new
|
14
|
-
ActionController::Routing::Routes.draw do |map|
|
15
|
-
map.resources :pirates, :collection => {:test => :any}
|
16
|
-
end
|
17
24
|
|
18
25
|
@custom_flash_message = 'the flash was set'
|
19
26
|
@proc = Proc.new { 'the flash was set' }
|
@@ -23,8 +30,7 @@ describe "flash messages with procs", :type => :controller do
|
|
23
30
|
end
|
24
31
|
|
25
32
|
after(:each) do
|
26
|
-
PiratesController
|
27
|
-
PiratesController::FlashMessages[false].clear
|
33
|
+
Object.remove_class(PiratesController)
|
28
34
|
end
|
29
35
|
|
30
36
|
describe "responding with a method call" do
|