exposure 0.0.4
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/Manifest.txt +41 -0
- data/README.mdown +39 -0
- data/Rakefile +26 -0
- data/exposure.gemspec +31 -0
- data/lib/exposure/common.rb +127 -0
- data/lib/exposure/configuration.rb +63 -0
- data/lib/exposure/patterns/resource.rb +226 -0
- data/lib/exposure/patterns/resources.rb +323 -0
- data/lib/exposure.rb +14 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/custom_matchers.rb +41 -0
- data/spec/exposure_spec.rb +4 -0
- data/spec/factories/pirate_factory.rb +8 -0
- data/spec/factories/ship_factory.rb +3 -0
- data/spec/finders/finder_spec.rb +53 -0
- data/spec/finders/nested_resources_finder_spec.rb +29 -0
- data/spec/fixtures/pirates/edit.erb +0 -0
- data/spec/fixtures/pirates/index.erb +0 -0
- data/spec/fixtures/pirates/new.erb +0 -0
- data/spec/fixtures/pirates/show.erb +0 -0
- data/spec/fixtures/ships/edit.erb +0 -0
- data/spec/fixtures/ships/index.erb +0 -0
- data/spec/fixtures/ships/new.erb +0 -0
- data/spec/fixtures/ships/show.erb +0 -0
- data/spec/flashers/flash_with_block_spec.rb +32 -0
- data/spec/flashers/flash_with_method_spec.rb +86 -0
- data/spec/flashers/flash_with_proc_spec.rb +83 -0
- data/spec/flashers/flash_with_string_spec.rb +82 -0
- data/spec/resource_spec.rb +192 -0
- data/spec/resources_spec.rb +204 -0
- data/spec/responders/respond_to_mime_types_spec.rb +44 -0
- data/spec/responders/respond_with_block_spec.rb +84 -0
- data/spec/responders/respond_with_method_spec.rb +84 -0
- data/spec/responders/respond_with_proc_spec.rb +79 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +71 -0
- data/spec/spec_rails_helper.rb +22 -0
- data/tasks/rspec.rake +21 -0
- data/tasks/shoulda.rake +15 -0
- metadata +106 -0
@@ -0,0 +1,83 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe "flash messages with procs", :type => :controller do
|
4
|
+
class PiratesController < ActionController::Base
|
5
|
+
expose_many(:pirates)
|
6
|
+
end
|
7
|
+
|
8
|
+
controller_name :pirates
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
@controller = PiratesController.new
|
12
|
+
@request = ActionController::TestRequest.new
|
13
|
+
@response = ActionController::TestResponse.new
|
14
|
+
ActionController::Routing::Routes.draw do |map|
|
15
|
+
map.resources :pirates, :collection => {:test => :any}
|
16
|
+
end
|
17
|
+
|
18
|
+
@custom_flash_message = 'the flash was set'
|
19
|
+
@proc = Proc.new { 'the flash was set' }
|
20
|
+
|
21
|
+
@pirate = Factory.stub(:pirate)
|
22
|
+
Pirate.stub(:new => @pirate)
|
23
|
+
end
|
24
|
+
|
25
|
+
after(:each) do
|
26
|
+
PiratesController::FlashMessages[true].clear
|
27
|
+
PiratesController::FlashMessages[false].clear
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "responding with a method call" do
|
31
|
+
before(:each) do
|
32
|
+
PiratesController.flash_for :create, :is => @proc
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should respond with redirect to test on success" do
|
36
|
+
@pirate.stub(:save => true)
|
37
|
+
post(:create)
|
38
|
+
should set_the_flash.to(@custom_flash_message)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should respond with redirect to test on failure" do
|
42
|
+
@pirate.stub(:save => false)
|
43
|
+
post(:create)
|
44
|
+
should set_the_flash.to(@custom_flash_message)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "responding with a method call :on => :success" do
|
49
|
+
before(:each) do
|
50
|
+
PiratesController.flash_for :create, :is => @proc, :on => :success
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should respond with custom response on success" do
|
54
|
+
@pirate.stub(:save => true)
|
55
|
+
post(:create)
|
56
|
+
should set_the_flash.to(@custom_flash_message)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should not respond with custom response on failure" do
|
60
|
+
@pirate.stub(:save => false)
|
61
|
+
post(:create)
|
62
|
+
should_not redirect_to({:action => 'test'})
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "responding with a method call :on => :failure" do
|
67
|
+
before(:each) do
|
68
|
+
PiratesController.flash_for :create, :is => @proc, :on => :failure
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should not respond with custom response on success" do
|
72
|
+
@pirate.stub(:save => true)
|
73
|
+
post(:create)
|
74
|
+
should_not redirect_to({:action => 'test'})
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should respond with custom response on failure" do
|
78
|
+
@pirate.stub(:save => false)
|
79
|
+
post(:create)
|
80
|
+
should set_the_flash.to(@custom_flash_message)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe "flash messages with strings", :type => :controller do
|
4
|
+
class PiratesController < ActionController::Base
|
5
|
+
expose_many(:pirates)
|
6
|
+
end
|
7
|
+
|
8
|
+
controller_name :pirates
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
@controller = PiratesController.new
|
12
|
+
@request = ActionController::TestRequest.new
|
13
|
+
@response = ActionController::TestResponse.new
|
14
|
+
ActionController::Routing::Routes.draw do |map|
|
15
|
+
map.resources :pirates, :collection => {:test => :any}
|
16
|
+
end
|
17
|
+
|
18
|
+
@custom_flash_message = 'the flash was set'
|
19
|
+
|
20
|
+
@pirate = Factory.stub(:pirate)
|
21
|
+
Pirate.stub(:new => @pirate)
|
22
|
+
end
|
23
|
+
|
24
|
+
after(:each) do
|
25
|
+
PiratesController::FlashMessages[true].clear
|
26
|
+
PiratesController::FlashMessages[false].clear
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "responding with a method call" do
|
30
|
+
before(:each) do
|
31
|
+
PiratesController.flash_for :create, :is => @custom_flash_message
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should respond with redirect to test on success" do
|
35
|
+
@pirate.stub(:save => true)
|
36
|
+
post(:create)
|
37
|
+
should set_the_flash.to(@custom_flash_message)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should respond with redirect to test on failure" do
|
41
|
+
@pirate.stub(:save => false)
|
42
|
+
post(:create)
|
43
|
+
should set_the_flash.to(@custom_flash_message)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "responding with a method call :on => :success" do
|
48
|
+
before(:each) do
|
49
|
+
PiratesController.flash_for :create, :is => @custom_flash_message, :on => :success
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should respond with custom response on success" do
|
53
|
+
@pirate.stub(:save => true)
|
54
|
+
post(:create)
|
55
|
+
should set_the_flash.to(@custom_flash_message)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should not respond with custom response on failure" do
|
59
|
+
@pirate.stub(:save => false)
|
60
|
+
post(:create)
|
61
|
+
should_not redirect_to({:action => 'test'})
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "responding with a method call :on => :failure" do
|
66
|
+
before(:each) do
|
67
|
+
PiratesController.flash_for :create, :is => @custom_flash_message, :on => :failure
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should not respond with custom response on success" do
|
71
|
+
@pirate.stub(:save => true)
|
72
|
+
post(:create)
|
73
|
+
should_not redirect_to({:action => 'test'})
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should respond with custom response on failure" do
|
77
|
+
@pirate.stub(:save => false)
|
78
|
+
post(:create)
|
79
|
+
should set_the_flash.to(@custom_flash_message)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
# require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
#
|
3
|
+
# describe "a REST patterned resource of 'post'", :type => :controller do
|
4
|
+
# class ShipController < ActionController::Base
|
5
|
+
# expose_one :ship
|
6
|
+
# end
|
7
|
+
# controller_name :ship
|
8
|
+
#
|
9
|
+
# before(:each) do
|
10
|
+
# @controller = ShipController.new
|
11
|
+
# @request = ActionController::TestRequest.new
|
12
|
+
# @response = ActionController::TestResponse.new
|
13
|
+
# ActionController::Routing::Routes.draw do |map|
|
14
|
+
# map.resource :ship
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# describe 'configuration' do
|
19
|
+
# it "has a resource name of 'post'" do
|
20
|
+
# @controller.send(:resource_name).should == 'ship'
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# %w(show new create edit update destroy).each do |action|
|
24
|
+
# it "has the REST action #{action}" do
|
25
|
+
# @controller.should respond_to(action)
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# describe 'show' do
|
31
|
+
# describe 'with found resource' do
|
32
|
+
# before(:each) do
|
33
|
+
# Ship.should_receive(:find).with('1').and_return(Factory.stub(:ship))
|
34
|
+
# get :show, {:id => 1}
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# it { should assign_to(:ship) }
|
38
|
+
# it { should assign_to(:resource) }
|
39
|
+
# it { should respond_with(:success) }
|
40
|
+
# it { should render_template(:show) }
|
41
|
+
# it { should_not set_the_flash }
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# describe 'with missing resource' do
|
45
|
+
# before(:each) do
|
46
|
+
# rescue_action_in_public!
|
47
|
+
# Ship.should_receive(:find).with('1').and_raise(ActiveRecord::RecordNotFound)
|
48
|
+
# get :show, {:id => 1}
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# it { should_not assign_to(:ship) }
|
52
|
+
# it { should_not assign_to(:resource) }
|
53
|
+
# it { should respond_with(:not_found) }
|
54
|
+
# it { should_not render_template(:show) }
|
55
|
+
# it { should_not set_the_flash }
|
56
|
+
# end
|
57
|
+
# end
|
58
|
+
#
|
59
|
+
# describe 'new' do
|
60
|
+
# before(:each) do
|
61
|
+
# get :new
|
62
|
+
# end
|
63
|
+
#
|
64
|
+
# it { should assign_to(:ship) }
|
65
|
+
# it { should assign_to(:resource) }
|
66
|
+
# it { should respond_with(:success) }
|
67
|
+
# it { should render_template(:new) }
|
68
|
+
# it { should_not set_the_flash }
|
69
|
+
#
|
70
|
+
# end
|
71
|
+
#
|
72
|
+
# describe 'create' do
|
73
|
+
# describe 'with valid data' do
|
74
|
+
# before(:each) do
|
75
|
+
# params = {
|
76
|
+
# :ship => {}
|
77
|
+
# }
|
78
|
+
# post_before_saving = Factory.build(:ship)
|
79
|
+
# Ship.should_receive(:new).with(params[:ship]).and_return(post_before_saving)
|
80
|
+
# post_before_saving.should_receive(:save).and_return(true)
|
81
|
+
# post(:create, params)
|
82
|
+
# end
|
83
|
+
#
|
84
|
+
# it { should assign_to(:ship) }
|
85
|
+
# it { should assign_to(:resource) }
|
86
|
+
# it { should respond_with(:redirect).to(:show) }
|
87
|
+
# it { should set_the_flash.to('Ship successfully created') }
|
88
|
+
# end
|
89
|
+
#
|
90
|
+
# describe 'with invalid data' do
|
91
|
+
# before(:each) do
|
92
|
+
# params = {
|
93
|
+
# :ship => {}
|
94
|
+
# }
|
95
|
+
# post_before_saving = Factory.build(:ship)
|
96
|
+
# Ship.should_receive(:new).with(params[:ship]).and_return(post_before_saving)
|
97
|
+
# post_before_saving.should_receive(:save).and_return(false)
|
98
|
+
# post(:create, params)
|
99
|
+
# end
|
100
|
+
#
|
101
|
+
# it { should assign_to(:ship) }
|
102
|
+
# it { should assign_to(:resource) }
|
103
|
+
# it { should respond_with(:success) }
|
104
|
+
# it { should render_template(:new) }
|
105
|
+
# it { should_not set_the_flash }
|
106
|
+
# end
|
107
|
+
# end
|
108
|
+
#
|
109
|
+
# describe 'edit' do
|
110
|
+
# describe 'with found resource' do
|
111
|
+
# before(:each) do
|
112
|
+
# Ship.should_receive(:find).with('1').and_return(Factory.stub(:ship))
|
113
|
+
# get :edit, {:id => 1}
|
114
|
+
# end
|
115
|
+
#
|
116
|
+
# it { should assign_to(:ship) }
|
117
|
+
# it { should assign_to(:resource) }
|
118
|
+
# it { should respond_with(:success) }
|
119
|
+
# it { should render_template(:edit) }
|
120
|
+
# it { should_not set_the_flash }
|
121
|
+
# end
|
122
|
+
#
|
123
|
+
# describe 'with missing resource' do
|
124
|
+
# before(:each) do
|
125
|
+
# rescue_action_in_public!
|
126
|
+
# Ship.should_receive(:find).with('1').and_raise(ActiveRecord::RecordNotFound)
|
127
|
+
# get :edit, {:id => 1}
|
128
|
+
# end
|
129
|
+
#
|
130
|
+
# it { should_not assign_to(:ship) }
|
131
|
+
# it { should_not assign_to(:resource) }
|
132
|
+
# it { should respond_with(:not_found) }
|
133
|
+
# it { should_not render_template(:edit) }
|
134
|
+
# it { should_not set_the_flash }
|
135
|
+
# end
|
136
|
+
# end
|
137
|
+
#
|
138
|
+
# describe 'update' do
|
139
|
+
# describe 'with valid data' do
|
140
|
+
# before(:each) do
|
141
|
+
# params = {
|
142
|
+
# :id => 1,
|
143
|
+
# :ship => {}
|
144
|
+
# }
|
145
|
+
# post_before_saving = Factory.build(:ship)
|
146
|
+
# Ship.should_receive(:find).with("1").and_return(post_before_saving)
|
147
|
+
# post_before_saving.should_receive(:update_attributes).with(params[:ship]).and_return(true)
|
148
|
+
# put(:update, params)
|
149
|
+
# end
|
150
|
+
#
|
151
|
+
# it { should assign_to(:ship) }
|
152
|
+
# it { should assign_to(:resource) }
|
153
|
+
# it { should respond_with(:redirect).to(:show) }
|
154
|
+
# it { should set_the_flash.to('Ship successfully updated') }
|
155
|
+
#
|
156
|
+
# end
|
157
|
+
#
|
158
|
+
# describe 'with invalid data' do
|
159
|
+
# before(:each) do
|
160
|
+
# params = {
|
161
|
+
# :id => 1,
|
162
|
+
# :ship => {}
|
163
|
+
# }
|
164
|
+
# post_before_saving = Factory.build(:ship)
|
165
|
+
# Ship.should_receive(:find).with("1").and_return(post_before_saving)
|
166
|
+
# post_before_saving.should_receive(:update_attributes).with(params[:ship]).and_return(false)
|
167
|
+
# put(:update, params)
|
168
|
+
# end
|
169
|
+
#
|
170
|
+
# it { should assign_to(:ship) }
|
171
|
+
# it { should assign_to(:resource) }
|
172
|
+
# it { should respond_with(:success) }
|
173
|
+
# it { should render_template(:edit) }
|
174
|
+
# it { should_not set_the_flash }
|
175
|
+
# end
|
176
|
+
# end
|
177
|
+
#
|
178
|
+
# describe 'destroy' do
|
179
|
+
# before(:each) do
|
180
|
+
# params = {
|
181
|
+
# :id => 1,
|
182
|
+
# }
|
183
|
+
# post_before_saving = Factory.build(:ship)
|
184
|
+
# Ship.should_receive(:find).with("1").and_return(post_before_saving)
|
185
|
+
# post_before_saving.should_receive(:destroy)
|
186
|
+
# delete(:destroy, params)
|
187
|
+
# end
|
188
|
+
#
|
189
|
+
# it { should respond_with(:redirect).to(:new) }
|
190
|
+
# it { should set_the_flash.to('Ship successfully removed') }
|
191
|
+
# end
|
192
|
+
# end
|
@@ -0,0 +1,204 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "a REST patterned resource of 'pirates'", :type => :controller do
|
4
|
+
class PiratesController < ActionController::Base
|
5
|
+
expose_many(:pirates)
|
6
|
+
end
|
7
|
+
controller_name :pirates
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
@controller = PiratesController.new
|
11
|
+
@request = ActionController::TestRequest.new
|
12
|
+
@response = ActionController::TestResponse.new
|
13
|
+
ActionController::Routing::Routes.draw do |map|
|
14
|
+
map.resources :pirates
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'configuration' do
|
19
|
+
it "has a resource name of 'post'" do
|
20
|
+
@controller.send(:resource_name).should == 'pirate'
|
21
|
+
end
|
22
|
+
|
23
|
+
%w(index show new create edit update destroy).each do |action|
|
24
|
+
it "has the REST action #{action}" do
|
25
|
+
@controller.should respond_to(action)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'index' do
|
31
|
+
before do
|
32
|
+
get :index
|
33
|
+
end
|
34
|
+
|
35
|
+
it { should assign_to(:pirates) }
|
36
|
+
it { should assign_to(:resources) }
|
37
|
+
it { should respond_with(:success) }
|
38
|
+
it { should render_template(:index) }
|
39
|
+
it { should_not set_the_flash }
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'show' do
|
43
|
+
describe 'with found resource' do
|
44
|
+
before(:each) do
|
45
|
+
Pirate.should_receive(:find).with('1').and_return(Factory.stub(:pirate))
|
46
|
+
get :show, {:id => 1}
|
47
|
+
end
|
48
|
+
|
49
|
+
it { should assign_to(:pirate) }
|
50
|
+
it { should assign_to(:resource) }
|
51
|
+
it { should respond_with(:success) }
|
52
|
+
it { should render_template(:show) }
|
53
|
+
it { should_not set_the_flash }
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'with missing resource' do
|
57
|
+
before(:each) do
|
58
|
+
rescue_action_in_public!
|
59
|
+
Pirate.should_receive(:find).with('1').and_raise(ActiveRecord::RecordNotFound)
|
60
|
+
get :show, {:id => 1}
|
61
|
+
end
|
62
|
+
|
63
|
+
it { should_not assign_to(:pirate) }
|
64
|
+
it { should_not assign_to(:resource) }
|
65
|
+
it { should respond_with(:not_found) }
|
66
|
+
it { should_not render_template(:show) }
|
67
|
+
it { should_not set_the_flash }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe 'new' do
|
72
|
+
before(:each) do
|
73
|
+
get :new
|
74
|
+
end
|
75
|
+
|
76
|
+
it { should assign_to(:pirate) }
|
77
|
+
it { should assign_to(:resource) }
|
78
|
+
it { should respond_with(:success) }
|
79
|
+
it { should render_template(:new) }
|
80
|
+
it { should_not set_the_flash }
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
describe 'create' do
|
85
|
+
describe 'with valid data' do
|
86
|
+
before(:each) do
|
87
|
+
params = {
|
88
|
+
:pirate => {}
|
89
|
+
}
|
90
|
+
post_before_saving = Factory.build(:pirate)
|
91
|
+
Pirate.should_receive(:new).with(params[:pirate]).and_return(post_before_saving)
|
92
|
+
post_before_saving.should_receive(:save).and_return(true)
|
93
|
+
post(:create, params)
|
94
|
+
end
|
95
|
+
|
96
|
+
it { should assign_to(:pirate) }
|
97
|
+
it { should assign_to(:resource) }
|
98
|
+
it { should respond_with(:redirect).to(:index) }
|
99
|
+
it { should set_the_flash.to('Pirate successfully created') }
|
100
|
+
end
|
101
|
+
|
102
|
+
describe 'with invalid data' do
|
103
|
+
before(:each) do
|
104
|
+
params = {
|
105
|
+
:pirate => {}
|
106
|
+
}
|
107
|
+
post_before_saving = Factory.build(:pirate)
|
108
|
+
Pirate.should_receive(:new).with(params[:pirate]).and_return(post_before_saving)
|
109
|
+
post_before_saving.should_receive(:save).and_return(false)
|
110
|
+
post(:create, params)
|
111
|
+
end
|
112
|
+
|
113
|
+
it { should assign_to(:pirate) }
|
114
|
+
it { should assign_to(:resource) }
|
115
|
+
it { should respond_with(:success) }
|
116
|
+
it { should render_template(:new) }
|
117
|
+
it { should_not set_the_flash }
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe 'edit' do
|
122
|
+
describe 'with found resource' do
|
123
|
+
before(:each) do
|
124
|
+
Pirate.should_receive(:find).with('1').and_return(Factory.stub(:pirate))
|
125
|
+
get :edit, {:id => 1}
|
126
|
+
end
|
127
|
+
|
128
|
+
it { should assign_to(:pirate) }
|
129
|
+
it { should assign_to(:resource) }
|
130
|
+
it { should respond_with(:success) }
|
131
|
+
it { should render_template(:edit) }
|
132
|
+
it { should_not set_the_flash }
|
133
|
+
end
|
134
|
+
|
135
|
+
describe 'with missing resource' do
|
136
|
+
before(:each) do
|
137
|
+
rescue_action_in_public!
|
138
|
+
Pirate.should_receive(:find).with('1').and_raise(ActiveRecord::RecordNotFound)
|
139
|
+
get :edit, {:id => 1}
|
140
|
+
end
|
141
|
+
|
142
|
+
it { should_not assign_to(:pirate) }
|
143
|
+
it { should_not assign_to(:resource) }
|
144
|
+
it { should respond_with(:not_found) }
|
145
|
+
it { should_not render_template(:edit) }
|
146
|
+
it { should_not set_the_flash }
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe 'update' do
|
151
|
+
describe 'with valid data' do
|
152
|
+
before(:each) do
|
153
|
+
params = {
|
154
|
+
:id => 1,
|
155
|
+
:pirate => {}
|
156
|
+
}
|
157
|
+
post_before_saving = Factory.build(:pirate)
|
158
|
+
Pirate.should_receive(:find).with("1").and_return(post_before_saving)
|
159
|
+
post_before_saving.should_receive(:update_attributes).with(params[:pirate]).and_return(true)
|
160
|
+
put(:update, params)
|
161
|
+
end
|
162
|
+
|
163
|
+
it { should assign_to(:pirate) }
|
164
|
+
it { should assign_to(:resource) }
|
165
|
+
it { should respond_with(:redirect).to(:show) }
|
166
|
+
it { should set_the_flash.to('Pirate successfully updated') }
|
167
|
+
|
168
|
+
end
|
169
|
+
|
170
|
+
describe 'with invalid data' do
|
171
|
+
before(:each) do
|
172
|
+
params = {
|
173
|
+
:id => 1,
|
174
|
+
:pirate => {}
|
175
|
+
}
|
176
|
+
post_before_saving = Factory.build(:pirate)
|
177
|
+
Pirate.should_receive(:find).with("1").and_return(post_before_saving)
|
178
|
+
post_before_saving.should_receive(:update_attributes).with(params[:pirate]).and_return(false)
|
179
|
+
put(:update, params)
|
180
|
+
end
|
181
|
+
|
182
|
+
it { should assign_to(:pirate) }
|
183
|
+
it { should assign_to(:resource) }
|
184
|
+
it { should respond_with(:success) }
|
185
|
+
it { should render_template(:edit) }
|
186
|
+
it { should_not set_the_flash }
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe 'destroy' do
|
191
|
+
before(:each) do
|
192
|
+
params = {
|
193
|
+
:id => 1,
|
194
|
+
}
|
195
|
+
post_before_saving = Factory.build(:pirate)
|
196
|
+
Pirate.should_receive(:find).with("1").and_return(post_before_saving)
|
197
|
+
post_before_saving.should_receive(:destroy)
|
198
|
+
delete(:destroy, params)
|
199
|
+
end
|
200
|
+
|
201
|
+
it { should respond_with(:redirect).to(:index) }
|
202
|
+
it { should set_the_flash.to('Pirate successfully removed') }
|
203
|
+
end
|
204
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe "mime type responders", :type => :controller do
|
4
|
+
class PiratesController < ActionController::Base
|
5
|
+
expose_many(:pirates)
|
6
|
+
end
|
7
|
+
|
8
|
+
controller_name :pirates
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
@controller = PiratesController.new
|
12
|
+
@request = ActionController::TestRequest.new
|
13
|
+
@response = ActionController::TestResponse.new
|
14
|
+
ActionController::Routing::Routes.draw do |map|
|
15
|
+
map.resources :pirates, :collection => {:test => :any}
|
16
|
+
end
|
17
|
+
@pirate = Factory.stub(:pirate)
|
18
|
+
Pirate.stub(:new => @pirate)
|
19
|
+
end
|
20
|
+
|
21
|
+
after(:each) do
|
22
|
+
PiratesController::Responses.clear
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should respond with not acceptable if no acceptable mime type is not found" do
|
26
|
+
@request.accept = "application/x-yaml"
|
27
|
+
@pirate.stub(:save => true)
|
28
|
+
post(:create)
|
29
|
+
should respond_with(:not_acceptable)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should respond with mime type when header is set" do
|
33
|
+
@request.accept = 'application/xml'
|
34
|
+
@pirate.stub(:save => true)
|
35
|
+
post(:create)
|
36
|
+
should respond_with_content_type(:xml)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should respond with mime type when params[:format] is set" do
|
40
|
+
@pirate.stub(:save => true)
|
41
|
+
post(:create, {:format => 'xml'})
|
42
|
+
should respond_with_content_type(:xml)
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe "responders", :type => :controller do
|
4
|
+
class PiratesController < ActionController::Base
|
5
|
+
expose_many(:pirates)
|
6
|
+
end
|
7
|
+
|
8
|
+
controller_name :pirates
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
@controller = PiratesController.new
|
12
|
+
@request = ActionController::TestRequest.new
|
13
|
+
@response = ActionController::TestResponse.new
|
14
|
+
ActionController::Routing::Routes.draw do |map|
|
15
|
+
map.resources :pirates, :collection => {:test => :any}
|
16
|
+
end
|
17
|
+
@pirate = Factory.stub(:pirate)
|
18
|
+
Pirate.stub(:new => @pirate)
|
19
|
+
end
|
20
|
+
|
21
|
+
after(:each) do
|
22
|
+
PiratesController::Responses.clear
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "responding with a method call" do
|
26
|
+
before(:each) do
|
27
|
+
PiratesController.response_for :create do
|
28
|
+
redirect_to({:action => 'test'})
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should respond with redirect to test on success" do
|
33
|
+
@pirate.stub(:save => true)
|
34
|
+
post(:create)
|
35
|
+
should redirect_to({:action => 'test'})
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should respond with redirect to test on failure" do
|
39
|
+
@pirate.stub(:save => false)
|
40
|
+
post(:create)
|
41
|
+
should redirect_to({:action => 'test'})
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "responding with a method call :on => :success" do
|
46
|
+
before(:each) do
|
47
|
+
PiratesController.response_for :create, :on => :success do
|
48
|
+
redirect_to({:action => 'test'})
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should respond with custom response on success" do
|
53
|
+
@pirate.stub(:save => true)
|
54
|
+
post(:create)
|
55
|
+
should redirect_to({:action => 'test'})
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should not respond with custom response on failure" do
|
59
|
+
@pirate.stub(:save => false)
|
60
|
+
post(:create)
|
61
|
+
should_not redirect_to({:action => 'test'})
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "responding with a method call :on => :failure" do
|
66
|
+
before(:each) do
|
67
|
+
PiratesController.response_for :create, :on => :failure do
|
68
|
+
redirect_to({:action => 'test'})
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should not respond with custom response on success" do
|
73
|
+
@pirate.stub(:save => true)
|
74
|
+
post(:create)
|
75
|
+
should_not redirect_to({:action => 'test'})
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should respond with custom response on failure" do
|
79
|
+
@pirate.stub(:save => false)
|
80
|
+
post(:create)
|
81
|
+
should redirect_to({:action => 'test'})
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|