exposure 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/exposure/behaviors/flashing.rb +4 -4
- data/spec/builders/nested_builder_spec.rb +47 -0
- data/spec/factories/cannon_factory.rb +3 -0
- data/spec/flashers/flash_with_block_spec.rb +8 -4
- data/spec/flashers/flash_with_method_spec.rb +6 -52
- data/spec/flashers/flash_with_proc_spec.rb +7 -55
- data/spec/flashers/flash_with_string_spec.rb +5 -52
- data/spec/flashers/flashing_behavior.rb +55 -0
- data/spec/responders/respond_with_block_spec.rb +8 -58
- data/spec/responders/respond_with_method_spec.rb +6 -53
- data/spec/responders/respond_with_proc_spec.rb +6 -54
- data/spec/responders/responding_behavior.rb +55 -0
- data/spec/spec_helper.rb +10 -3
- metadata +9 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
@@ -36,11 +36,11 @@ module Exposure
|
|
36
36
|
if flash_message = self.class::FlashMessages["#{action_name}.#{action_status}.html"]
|
37
37
|
case flash_message
|
38
38
|
when String
|
39
|
-
flash[:
|
39
|
+
flash[:notice] = flash_message
|
40
40
|
when Symbol
|
41
|
-
flash[:
|
41
|
+
flash[:notice] = self.send(flash_message)
|
42
42
|
when Proc
|
43
|
-
flash[:
|
43
|
+
flash[:notice] = self.instance_eval(&flash_message)
|
44
44
|
end
|
45
45
|
else
|
46
46
|
false
|
@@ -49,7 +49,7 @@ module Exposure
|
|
49
49
|
|
50
50
|
def default_flash_for(action_name, action_status)
|
51
51
|
if message_proc = self.class::DefaultFlashMessages["#{action_name}.#{action_status}.html"]
|
52
|
-
flash[:
|
52
|
+
flash[:notice] = self.instance_eval(&message_proc)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
@@ -41,4 +41,51 @@ describe "nested builders", :type => :controller do
|
|
41
41
|
it { should assign_to(:ship).with(@ship) }
|
42
42
|
it { should assign_to(:resource).with(@ship) }
|
43
43
|
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "deeply nested builders", :type => :controller do
|
47
|
+
setup = lambda {
|
48
|
+
class CannonsController < ActionController::Base
|
49
|
+
expose_many(:cannons, :nested => [:pirates, :ships])
|
50
|
+
end
|
51
|
+
|
52
|
+
ActionController::Routing::Routes.draw do |map|
|
53
|
+
map.resources :pirates do |pirate|
|
54
|
+
pirate.resources :ships do |ship|
|
55
|
+
ship.resources :cannons
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
}
|
60
|
+
|
61
|
+
setup.call
|
62
|
+
controller_name :cannons
|
63
|
+
Object.remove_class(CannonsController)
|
64
|
+
|
65
|
+
before(:each) do
|
66
|
+
setup.call
|
67
|
+
@controller = CannonsController.new
|
68
|
+
@request = ActionController::TestRequest.new
|
69
|
+
@response = ActionController::TestResponse.new
|
70
|
+
|
71
|
+
@pirate = Factory.create(:pirate)
|
72
|
+
@ship = Factory.create(:ship, :pirate => @pirate)
|
73
|
+
@cannon = Factory.build(:cannon)
|
74
|
+
|
75
|
+
Pirate.stub!(:find).and_return(@pirate)
|
76
|
+
@pirate.ships.stub!(:find).and_return(@ship)
|
77
|
+
@ship.cannons.stub!(:build).and_return(@cannon)
|
78
|
+
|
79
|
+
|
80
|
+
params = {:pirate_id => @pirate.id, :ship_id => @ship.id, :cannon => Factory.attributes_for(:cannon)}
|
81
|
+
|
82
|
+
get(:new, params)
|
83
|
+
end
|
84
|
+
|
85
|
+
after(:each) do
|
86
|
+
Object.remove_class(CannonsController)
|
87
|
+
end
|
88
|
+
|
89
|
+
it { should assign_to(:cannon).with(@cannon) }
|
90
|
+
it { should assign_to(:resource).with(@cannon) }
|
44
91
|
end
|
@@ -1,16 +1,20 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/flashing_behavior'
|
1
2
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
3
|
|
3
4
|
describe "flash messages with blocks", :type => :controller do
|
4
5
|
setup = lambda {
|
5
6
|
class PiratesController < ActionController::Base
|
6
7
|
expose_many(:pirates)
|
7
|
-
PiratesController.flash_for :create do
|
8
|
-
"the flash is set to #{@pirate.title}"
|
9
|
-
end
|
10
8
|
end
|
11
9
|
}
|
12
10
|
setup.call
|
13
11
|
|
12
|
+
def setup_flasher(action, success = nil)
|
13
|
+
PiratesController.flash_for action, :on => success do
|
14
|
+
"the flash is set to #{@pirate.title}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
14
18
|
ActionController::Routing::Routes.draw do |map|
|
15
19
|
map.resources :pirates, :collection => {:test => :any}
|
16
20
|
end
|
@@ -38,5 +42,5 @@ describe "flash messages with blocks", :type => :controller do
|
|
38
42
|
Object.remove_class(PiratesController)
|
39
43
|
end
|
40
44
|
|
41
|
-
|
45
|
+
it_should_behave_like "a flasher"
|
42
46
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/flashing_behavior'
|
1
2
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
3
|
|
3
4
|
describe "flash messages with methods", :type => :controller do
|
@@ -14,6 +15,10 @@ describe "flash messages with methods", :type => :controller do
|
|
14
15
|
map.resources :pirates, :collection => {:test => :any}
|
15
16
|
end
|
16
17
|
}
|
18
|
+
|
19
|
+
def setup_flasher(action, success = nil)
|
20
|
+
PiratesController.flash_for action, :is => :custom_flash_message, :on => success
|
21
|
+
end
|
17
22
|
|
18
23
|
setup.call
|
19
24
|
controller_name :pirates
|
@@ -34,57 +39,6 @@ describe "flash messages with methods", :type => :controller do
|
|
34
39
|
Object.remove_class(PiratesController)
|
35
40
|
end
|
36
41
|
|
37
|
-
|
38
|
-
before(:each) do
|
39
|
-
PiratesController.flash_for :create, :is => :custom_flash_message
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should respond with redirect to test on success" do
|
43
|
-
@pirate.stub(:save => true)
|
44
|
-
post(:create)
|
45
|
-
should set_the_flash.to(@custom_flash_message)
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should respond with redirect to test on failure" do
|
49
|
-
@pirate.stub(:save => false)
|
50
|
-
post(:create)
|
51
|
-
should set_the_flash.to(@custom_flash_message)
|
52
|
-
end
|
53
|
-
end
|
42
|
+
it_should_behave_like "a flasher"
|
54
43
|
|
55
|
-
describe "responding with a method call :on => :success" do
|
56
|
-
before(:each) do
|
57
|
-
PiratesController.flash_for :create, :is => :custom_flash_message, :on => :success
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should respond with custom response on success" do
|
61
|
-
@pirate.stub(:save => true)
|
62
|
-
post(:create)
|
63
|
-
should set_the_flash.to(@custom_flash_message)
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should not respond with custom response on failure" do
|
67
|
-
@pirate.stub(:save => false)
|
68
|
-
post(:create)
|
69
|
-
should_not redirect_to({:action => 'test'})
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe "responding with a method call :on => :failure" do
|
74
|
-
before(:each) do
|
75
|
-
PiratesController.flash_for :create, :is => :custom_flash_message, :on => :failure
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should not respond with custom response on success" do
|
79
|
-
@pirate.stub(:save => true)
|
80
|
-
post(:create)
|
81
|
-
should_not redirect_to({:action => 'test'})
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should respond with custom response on failure" do
|
85
|
-
@pirate.stub(:save => false)
|
86
|
-
post(:create)
|
87
|
-
should set_the_flash.to(@custom_flash_message)
|
88
|
-
end
|
89
|
-
end
|
90
44
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/flashing_behavior'
|
1
2
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
3
|
|
3
4
|
describe "flash messages with procs", :type => :controller do
|
@@ -8,6 +9,10 @@ describe "flash messages with procs", :type => :controller do
|
|
8
9
|
}
|
9
10
|
setup.call
|
10
11
|
|
12
|
+
def setup_flasher(action, success = nil)
|
13
|
+
PiratesController.flash_for :create, :is => Proc.new { 'the flash was set' }, :on => success
|
14
|
+
end
|
15
|
+
|
11
16
|
ActionController::Routing::Routes.draw do |map|
|
12
17
|
map.resources :pirates, :collection => {:test => :any}
|
13
18
|
end
|
@@ -23,8 +28,7 @@ describe "flash messages with procs", :type => :controller do
|
|
23
28
|
@response = ActionController::TestResponse.new
|
24
29
|
|
25
30
|
@custom_flash_message = 'the flash was set'
|
26
|
-
|
27
|
-
|
31
|
+
|
28
32
|
@pirate = Factory.stub(:pirate)
|
29
33
|
Pirate.stub(:new => @pirate)
|
30
34
|
end
|
@@ -33,57 +37,5 @@ describe "flash messages with procs", :type => :controller do
|
|
33
37
|
Object.remove_class(PiratesController)
|
34
38
|
end
|
35
39
|
|
36
|
-
|
37
|
-
before(:each) do
|
38
|
-
PiratesController.flash_for :create, :is => @proc
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should respond with redirect to test on success" do
|
42
|
-
@pirate.stub(:save => true)
|
43
|
-
post(:create)
|
44
|
-
should set_the_flash.to(@custom_flash_message)
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should respond with redirect to test on failure" do
|
48
|
-
@pirate.stub(:save => false)
|
49
|
-
post(:create)
|
50
|
-
should set_the_flash.to(@custom_flash_message)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe "responding with a method call :on => :success" do
|
55
|
-
before(:each) do
|
56
|
-
PiratesController.flash_for :create, :is => @proc, :on => :success
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should respond with custom response on success" do
|
60
|
-
@pirate.stub(:save => true)
|
61
|
-
post(:create)
|
62
|
-
should set_the_flash.to(@custom_flash_message)
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should not respond with custom response on failure" do
|
66
|
-
@pirate.stub(:save => false)
|
67
|
-
post(:create)
|
68
|
-
should_not redirect_to({:action => 'test'})
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
describe "responding with a method call :on => :failure" do
|
73
|
-
before(:each) do
|
74
|
-
PiratesController.flash_for :create, :is => @proc, :on => :failure
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should not respond with custom response on success" do
|
78
|
-
@pirate.stub(:save => true)
|
79
|
-
post(:create)
|
80
|
-
should_not redirect_to({:action => 'test'})
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should respond with custom response on failure" do
|
84
|
-
@pirate.stub(:save => false)
|
85
|
-
post(:create)
|
86
|
-
should set_the_flash.to(@custom_flash_message)
|
87
|
-
end
|
88
|
-
end
|
40
|
+
it_should_behave_like "a flasher"
|
89
41
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/flashing_behavior'
|
1
2
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
3
|
|
3
4
|
describe "flash messages with strings", :type => :controller do
|
@@ -14,6 +15,9 @@ describe "flash messages with strings", :type => :controller do
|
|
14
15
|
controller_name :pirates
|
15
16
|
Object.remove_class(PiratesController)
|
16
17
|
|
18
|
+
def setup_flasher(action, success = nil)
|
19
|
+
PiratesController.flash_for action, :is => 'the flash was set', :on => success
|
20
|
+
end
|
17
21
|
|
18
22
|
before(:each) do
|
19
23
|
setup.call
|
@@ -31,57 +35,6 @@ describe "flash messages with strings", :type => :controller do
|
|
31
35
|
Object.remove_class(PiratesController)
|
32
36
|
end
|
33
37
|
|
34
|
-
|
35
|
-
before(:each) do
|
36
|
-
PiratesController.flash_for :create, :is => @custom_flash_message
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should respond with redirect to test on success" do
|
40
|
-
@pirate.stub(:save => true)
|
41
|
-
post(:create)
|
42
|
-
should set_the_flash.to(@custom_flash_message)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should respond with redirect to test on failure" do
|
46
|
-
@pirate.stub(:save => false)
|
47
|
-
post(:create)
|
48
|
-
should set_the_flash.to(@custom_flash_message)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe "responding with a method call :on => :success" do
|
53
|
-
before(:each) do
|
54
|
-
PiratesController.flash_for :create, :is => @custom_flash_message, :on => :success
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should respond with custom response on success" do
|
58
|
-
@pirate.stub(:save => true)
|
59
|
-
post(:create)
|
60
|
-
should set_the_flash.to(@custom_flash_message)
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should not respond with custom response on failure" do
|
64
|
-
@pirate.stub(:save => false)
|
65
|
-
post(:create)
|
66
|
-
should_not redirect_to({:action => 'test'})
|
67
|
-
end
|
68
|
-
end
|
38
|
+
it_should_behave_like "a flasher"
|
69
39
|
|
70
|
-
describe "responding with a method call :on => :failure" do
|
71
|
-
before(:each) do
|
72
|
-
PiratesController.flash_for :create, :is => @custom_flash_message, :on => :failure
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should not respond with custom response on success" do
|
76
|
-
@pirate.stub(:save => true)
|
77
|
-
post(:create)
|
78
|
-
should_not redirect_to({:action => 'test'})
|
79
|
-
end
|
80
|
-
|
81
|
-
it "should respond with custom response on failure" do
|
82
|
-
@pirate.stub(:save => false)
|
83
|
-
post(:create)
|
84
|
-
should set_the_flash.to(@custom_flash_message)
|
85
|
-
end
|
86
|
-
end
|
87
40
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
shared_examples_for "a flasher" do
|
2
|
+
describe "responding with a method call" do
|
3
|
+
before(:each) do
|
4
|
+
setup_flasher(:create)
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should respond with redirect to test on success" do
|
8
|
+
@pirate.stub(:save => true)
|
9
|
+
post(:create)
|
10
|
+
should set_the_flash.to(@custom_flash_message)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should respond with redirect to test on failure" do
|
14
|
+
@pirate.stub(:save => false)
|
15
|
+
post(:create)
|
16
|
+
should set_the_flash.to(@custom_flash_message)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "responding with a method call :on => :success" do
|
21
|
+
before(:each) do
|
22
|
+
setup_flasher(:create, :success)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should respond with custom response on success" do
|
26
|
+
@pirate.stub(:save => true)
|
27
|
+
post(:create)
|
28
|
+
should set_the_flash.to(@custom_flash_message)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should not respond with custom response on failure" do
|
32
|
+
@pirate.stub(:save => false)
|
33
|
+
post(:create)
|
34
|
+
should_not redirect_to({:action => 'test'})
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "responding with a method call :on => :failure" do
|
39
|
+
before(:each) do
|
40
|
+
setup_flasher(:create, :failure)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should not respond with custom response on success" do
|
44
|
+
@pirate.stub(:save => true)
|
45
|
+
post(:create)
|
46
|
+
should_not redirect_to({:action => 'test'})
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should respond with custom response on failure" do
|
50
|
+
@pirate.stub(:save => false)
|
51
|
+
post(:create)
|
52
|
+
should set_the_flash.to(@custom_flash_message)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/responding_behavior'
|
1
2
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
3
|
|
3
4
|
describe "responders", :type => :controller do
|
@@ -12,6 +13,12 @@ describe "responders", :type => :controller do
|
|
12
13
|
map.resources :pirates, :collection => {:test => :any}
|
13
14
|
end
|
14
15
|
|
16
|
+
def setup_responder(action, success = nil)
|
17
|
+
PiratesController.response_for :create, :on => success do
|
18
|
+
redirect_to({:action => 'test'})
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
15
22
|
controller_name :pirates
|
16
23
|
Object.remove_class(PiratesController)
|
17
24
|
|
@@ -28,63 +35,6 @@ describe "responders", :type => :controller do
|
|
28
35
|
Object.remove_class(PiratesController)
|
29
36
|
end
|
30
37
|
|
31
|
-
|
32
|
-
before(:each) do
|
33
|
-
PiratesController.response_for :create do
|
34
|
-
redirect_to({:action => 'test'})
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should respond with redirect to test on success" do
|
39
|
-
@pirate.stub(:save => true)
|
40
|
-
post(:create)
|
41
|
-
should redirect_to({:action => 'test'})
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should respond with redirect to test on failure" do
|
45
|
-
@pirate.stub(:save => false)
|
46
|
-
post(:create)
|
47
|
-
should redirect_to({:action => 'test'})
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe "responding with a method call :on => :success" do
|
52
|
-
before(:each) do
|
53
|
-
PiratesController.response_for :create, :on => :success do
|
54
|
-
redirect_to({:action => 'test'})
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should respond with custom response on success" do
|
59
|
-
@pirate.stub(:save => true)
|
60
|
-
post(:create)
|
61
|
-
should redirect_to({:action => 'test'})
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should not respond with custom response on failure" do
|
65
|
-
@pirate.stub(:save => false)
|
66
|
-
post(:create)
|
67
|
-
should_not redirect_to({:action => 'test'})
|
68
|
-
end
|
69
|
-
end
|
38
|
+
it_should_behave_like "a responder"
|
70
39
|
|
71
|
-
describe "responding with a method call :on => :failure" do
|
72
|
-
before(:each) do
|
73
|
-
PiratesController.response_for :create, :on => :failure do
|
74
|
-
redirect_to({:action => 'test'})
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should not respond with custom response on success" do
|
79
|
-
@pirate.stub(:save => true)
|
80
|
-
post(:create)
|
81
|
-
should_not redirect_to({:action => 'test'})
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should respond with custom response on failure" do
|
85
|
-
@pirate.stub(:save => false)
|
86
|
-
post(:create)
|
87
|
-
should redirect_to({:action => 'test'})
|
88
|
-
end
|
89
|
-
end
|
90
40
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/responding_behavior'
|
1
2
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
3
|
|
3
4
|
describe "responders", :type => :controller do
|
@@ -13,6 +14,10 @@ describe "responders", :type => :controller do
|
|
13
14
|
}
|
14
15
|
setup.call
|
15
16
|
|
17
|
+
def setup_responder(action, success = nil)
|
18
|
+
PiratesController.response_for action, :is => :example, :on => success
|
19
|
+
end
|
20
|
+
|
16
21
|
ActionController::Routing::Routes.draw do |map|
|
17
22
|
map.resources :pirates, :collection => {:test => :any}
|
18
23
|
end
|
@@ -34,57 +39,5 @@ describe "responders", :type => :controller do
|
|
34
39
|
Object.remove_class(PiratesController)
|
35
40
|
end
|
36
41
|
|
37
|
-
|
38
|
-
before(:each) do
|
39
|
-
PiratesController.response_for :create, :is => :example
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should respond with redirect to test on success" do
|
43
|
-
@pirate.stub(:save => true)
|
44
|
-
post(:create)
|
45
|
-
should redirect_to({:action => 'test'})
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should respond with redirect to test on failure" do
|
49
|
-
@pirate.stub(:save => false)
|
50
|
-
post(:create)
|
51
|
-
should redirect_to({:action => 'test'})
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe "responding with a method call :on => :success" do
|
56
|
-
before(:each) do
|
57
|
-
PiratesController.response_for :create, :is => :example, :on => :success
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should respond with custom response on success" do
|
61
|
-
@pirate.stub(:save => true)
|
62
|
-
post(:create)
|
63
|
-
should redirect_to({:action => 'test'})
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should not respond with custom response on failure" do
|
67
|
-
@pirate.stub(:save => false)
|
68
|
-
post(:create)
|
69
|
-
should_not redirect_to({:action => 'test'})
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe "responding with a method call :on => :failure" do
|
74
|
-
before(:each) do
|
75
|
-
PiratesController.response_for :create, :is => :example, :on => :failure
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should not respond with custom response on success" do
|
79
|
-
@pirate.stub(:save => true)
|
80
|
-
post(:create)
|
81
|
-
should_not redirect_to({:action => 'test'})
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should respond with custom response on failure" do
|
85
|
-
@pirate.stub(:save => false)
|
86
|
-
post(:create)
|
87
|
-
should redirect_to({:action => 'test'})
|
88
|
-
end
|
89
|
-
end
|
42
|
+
it_should_behave_like "a responder"
|
90
43
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/responding_behavior'
|
1
2
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
3
|
|
3
4
|
describe "responders", :type => :controller do
|
@@ -12,6 +13,10 @@ describe "responders", :type => :controller do
|
|
12
13
|
map.resources :pirates, :collection => {:test => :any}
|
13
14
|
end
|
14
15
|
|
16
|
+
def setup_responder(action, success = nil)
|
17
|
+
PiratesController.response_for :create, :is => Proc.new { redirect_to({:action => "test"}) }, :on => success
|
18
|
+
end
|
19
|
+
|
15
20
|
controller_name :pirates
|
16
21
|
Object.remove_class(PiratesController)
|
17
22
|
|
@@ -21,7 +26,6 @@ describe "responders", :type => :controller do
|
|
21
26
|
@request = ActionController::TestRequest.new
|
22
27
|
@response = ActionController::TestResponse.new
|
23
28
|
|
24
|
-
@response_proc = Proc.new { redirect_to({:action => "test"}) }
|
25
29
|
@pirate = Factory.stub(:pirate)
|
26
30
|
Pirate.stub(:new => @pirate)
|
27
31
|
end
|
@@ -30,57 +34,5 @@ describe "responders", :type => :controller do
|
|
30
34
|
Object.remove_class(PiratesController)
|
31
35
|
end
|
32
36
|
|
33
|
-
|
34
|
-
before(:each) do
|
35
|
-
PiratesController.response_for :create, :is => @response_proc
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should respond with redirect to test on success" do
|
39
|
-
@pirate.stub(:save => true)
|
40
|
-
post(:create)
|
41
|
-
should redirect_to({:action => 'test'})
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should respond with redirect to test on failure" do
|
45
|
-
@pirate.stub(:save => false)
|
46
|
-
post(:create)
|
47
|
-
should redirect_to({:action => 'test'})
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe "responding with a method call :on => :success" do
|
52
|
-
before(:each) do
|
53
|
-
PiratesController.response_for :create, :is => @response_proc, :on => :success
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should respond with custom response on success" do
|
57
|
-
@pirate.stub(:save => true)
|
58
|
-
post(:create)
|
59
|
-
should redirect_to({:action => 'test'})
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should not respond with custom response on failure" do
|
63
|
-
@pirate.stub(:save => false)
|
64
|
-
post(:create)
|
65
|
-
should_not redirect_to({:action => 'test'})
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe "responding with a method call :on => :failure" do
|
70
|
-
before(:each) do
|
71
|
-
PiratesController.response_for :create, :is => @response_proc, :on => :failure
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should not respond with custom response on success" do
|
75
|
-
@pirate.stub(:save => true)
|
76
|
-
post(:create)
|
77
|
-
should_not redirect_to({:action => 'test'})
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should respond with custom response on failure" do
|
81
|
-
@pirate.stub(:save => false)
|
82
|
-
post(:create)
|
83
|
-
should redirect_to({:action => 'test'})
|
84
|
-
end
|
85
|
-
end
|
37
|
+
it_should_behave_like "a responder"
|
86
38
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
shared_examples_for "a responder" do
|
2
|
+
describe "responding with a method call" do
|
3
|
+
before(:each) do
|
4
|
+
setup_responder(:create)
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should respond with redirect to test on success" do
|
8
|
+
@pirate.stub(:save => true)
|
9
|
+
post(:create)
|
10
|
+
should redirect_to({:action => 'test'})
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should respond with redirect to test on failure" do
|
14
|
+
@pirate.stub(:save => false)
|
15
|
+
post(:create)
|
16
|
+
should redirect_to({:action => 'test'})
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "responding with a method call :on => :success" do
|
21
|
+
before(:each) do
|
22
|
+
setup_responder(:create, :success)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should respond with custom response on success" do
|
26
|
+
@pirate.stub(:save => true)
|
27
|
+
post(:create)
|
28
|
+
should redirect_to({:action => 'test'})
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should not respond with custom response on failure" do
|
32
|
+
@pirate.stub(:save => false)
|
33
|
+
post(:create)
|
34
|
+
should_not redirect_to({:action => 'test'})
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "responding with a method call :on => :failure" do
|
39
|
+
before(:each) do
|
40
|
+
setup_responder(:create, :failure)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should not respond with custom response on success" do
|
44
|
+
@pirate.stub(:save => true)
|
45
|
+
post(:create)
|
46
|
+
should_not redirect_to({:action => 'test'})
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should respond with custom response on failure" do
|
50
|
+
@pirate.stub(:save => false)
|
51
|
+
post(:create)
|
52
|
+
should redirect_to({:action => 'test'})
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -45,9 +45,9 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
45
45
|
t.column :created_at, :datetime
|
46
46
|
t.column :updated_at, :datetime
|
47
47
|
end
|
48
|
-
create_table :
|
49
|
-
t.column :
|
50
|
-
t.column :
|
48
|
+
create_table :cannons do |t|
|
49
|
+
t.column :name, :string
|
50
|
+
t.column :ship_id, :integer
|
51
51
|
t.column :created_at, :datetime
|
52
52
|
t.column :updated_at, :datetime
|
53
53
|
end
|
@@ -59,6 +59,12 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
+
class Cannon < ActiveRecord::Base
|
63
|
+
belongs_to :ship
|
64
|
+
def validate
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
62
68
|
class Pirate < ActiveRecord::Base
|
63
69
|
has_many :ships
|
64
70
|
validates_length_of :title, :within => 2..100
|
@@ -68,6 +74,7 @@ end
|
|
68
74
|
|
69
75
|
class Ship < ActiveRecord::Base
|
70
76
|
belongs_to :pirate
|
77
|
+
has_many :cannons
|
71
78
|
def validate
|
72
79
|
end
|
73
80
|
validates_associated :pirate
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exposure
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Trek Glowacki
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-24 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -45,6 +45,7 @@ files:
|
|
45
45
|
- spec/configuration_spec.rb
|
46
46
|
- spec/custom_matchers.rb
|
47
47
|
- spec/exposure_spec.rb
|
48
|
+
- spec/factories/cannon_factory.rb
|
48
49
|
- spec/factories/pirate_factory.rb
|
49
50
|
- spec/factories/ship_factory.rb
|
50
51
|
- spec/finders/finder_spec.rb
|
@@ -61,12 +62,14 @@ files:
|
|
61
62
|
- spec/flashers/flash_with_method_spec.rb
|
62
63
|
- spec/flashers/flash_with_proc_spec.rb
|
63
64
|
- spec/flashers/flash_with_string_spec.rb
|
65
|
+
- spec/flashers/flashing_behavior.rb
|
64
66
|
- spec/resources_spec.rb
|
65
67
|
- spec/responder_spec.rb
|
66
68
|
- spec/responders/respond_to_mime_types_spec.rb
|
67
69
|
- spec/responders/respond_with_block_spec.rb
|
68
70
|
- spec/responders/respond_with_method_spec.rb
|
69
71
|
- spec/responders/respond_with_proc_spec.rb
|
72
|
+
- spec/responders/responding_behavior.rb
|
70
73
|
- spec/spec.opts
|
71
74
|
- spec/spec_helper.rb
|
72
75
|
- spec/spec_rails_helper.rb
|
@@ -96,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
99
|
requirements: []
|
97
100
|
|
98
101
|
rubyforge_project:
|
99
|
-
rubygems_version: 1.3.
|
102
|
+
rubygems_version: 1.3.5
|
100
103
|
signing_key:
|
101
104
|
specification_version: 3
|
102
105
|
summary: exposed resources
|
@@ -107,6 +110,7 @@ test_files:
|
|
107
110
|
- spec/configuration_spec.rb
|
108
111
|
- spec/custom_matchers.rb
|
109
112
|
- spec/exposure_spec.rb
|
113
|
+
- spec/factories/cannon_factory.rb
|
110
114
|
- spec/factories/pirate_factory.rb
|
111
115
|
- spec/factories/ship_factory.rb
|
112
116
|
- spec/finders/finder_spec.rb
|
@@ -115,11 +119,13 @@ test_files:
|
|
115
119
|
- spec/flashers/flash_with_method_spec.rb
|
116
120
|
- spec/flashers/flash_with_proc_spec.rb
|
117
121
|
- spec/flashers/flash_with_string_spec.rb
|
122
|
+
- spec/flashers/flashing_behavior.rb
|
118
123
|
- spec/resources_spec.rb
|
119
124
|
- spec/responder_spec.rb
|
120
125
|
- spec/responders/respond_to_mime_types_spec.rb
|
121
126
|
- spec/responders/respond_with_block_spec.rb
|
122
127
|
- spec/responders/respond_with_method_spec.rb
|
123
128
|
- spec/responders/respond_with_proc_spec.rb
|
129
|
+
- spec/responders/responding_behavior.rb
|
124
130
|
- spec/spec_helper.rb
|
125
131
|
- spec/spec_rails_helper.rb
|