Skip to content

Commit f170f8a

Browse files
author
root
committed
Add tests for destroy method and actions with unsufficient permissions
1 parent 33d1fac commit f170f8a

File tree

2 files changed

+108
-25
lines changed

2 files changed

+108
-25
lines changed

Diff for: spec/controllers/repository_mirrors_controller_spec.rb

+49-8
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,41 @@ def success_url
113113

114114

115115
describe "GET #edit" do
116-
before do
117-
request.session[:user_id] = @user.id
118-
get :edit, :repository_id => @repository_git.id, :id => @mirror.id
116+
context "with existing mirror" do
117+
before do
118+
request.session[:user_id] = @user.id
119+
get :edit, :repository_id => @repository_git.id, :id => @mirror.id
120+
end
121+
122+
it "assigns the requested mirror to @mirror" do
123+
expect(assigns(:mirror)).to eq @mirror
124+
end
125+
126+
it "renders the :edit template" do
127+
expect(response).to render_template(:edit)
128+
end
119129
end
120130

121-
it "assigns the requested mirror to @mirror" do
122-
expect(assigns(:mirror)).to eq @mirror
131+
context "with non-existing mirror" do
132+
before do
133+
request.session[:user_id] = @user.id
134+
get :edit, :repository_id => @repository_git.id, :id => 100
135+
end
136+
137+
it "renders 404" do
138+
expect(response.status).to eq 404
139+
end
123140
end
124141

125-
it "renders the :edit template" do
126-
expect(response).to render_template(:edit)
142+
context "with unsufficient permissions" do
143+
before do
144+
request.session[:user_id] = FactoryGirl.create(:user).id
145+
get :edit, :repository_id => @repository_git.id, :id => @mirror.id
146+
end
147+
148+
it "renders 403" do
149+
expect(response.status).to eq 403
150+
end
127151
end
128152
end
129153

@@ -171,7 +195,7 @@ def success_url
171195

172196
it "does not change @mirror's attributes" do
173197
@mirror.reload
174-
expect(@mirror.url).to eq 'ssh://host.xz/path/to/repo.git'
198+
expect(@mirror.url).to eq 'ssh://host.xz/path/to/repo1.git'
175199
end
176200

177201
it "re-renders the :edit template" do
@@ -180,4 +204,21 @@ def success_url
180204
end
181205
end
182206

207+
describe 'DELETE destroy' do
208+
before :each do
209+
request.session[:user_id] = @user.id
210+
@mirror = FactoryGirl.create(:repository_mirror, :repository_id => @repository_git.id)
211+
end
212+
213+
it "deletes the mirror" do
214+
expect{
215+
delete :destroy, :repository_id => @repository_git.id, :id => @mirror.id, :format => 'js'
216+
}.to change(RepositoryMirror, :count).by(-1)
217+
end
218+
219+
it "redirects to repositories#edit" do
220+
delete :destroy, :repository_id => @repository_git.id, :id => @mirror.id, :format => 'js'
221+
expect(response.status).to eq 200
222+
end
223+
end
183224
end

Diff for: spec/controllers/repository_post_receive_urls_controller_spec.rb

+59-17
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,17 @@ def success_url
6969
expect{
7070
post :create, :repository_id => @repository_git.id,
7171
:repository_post_receive_url => {
72-
:url => 'http://example.com',
73-
:push_mode => 0
72+
:url => 'http://example.com',
73+
:mode => :github
7474
}
7575
}.to change(RepositoryPostReceiveUrl, :count).by(1)
7676
end
7777

7878
it "redirects to the repository page" do
7979
post :create, :repository_id => @repository_git.id,
8080
:repository_post_receive_url => {
81-
:url => 'http://example2.com',
82-
:push_mode => 0
81+
:url => 'http://example2.com',
82+
:mode => :github
8383
}
8484
expect(response).to redirect_to(success_url)
8585
end
@@ -94,17 +94,17 @@ def success_url
9494
expect{
9595
post :create, :repository_id => @repository_git.id,
9696
:repository_post_receive_url => {
97-
:url => 'example.com',
98-
:push_mode => 0
97+
:url => 'example.com',
98+
:mode => :github
9999
}
100-
}.to_not change(RepositoryMirror, :count)
100+
}.to_not change(RepositoryPostReceiveUrl, :count)
101101
end
102102

103103
it "re-renders the :new template" do
104104
post :create, :repository_id => @repository_git.id,
105105
:repository_post_receive_url => {
106-
:url => 'example.com',
107-
:push_mode => 0
106+
:url => 'example.com',
107+
:mode => :github
108108
}
109109
expect(response).to render_template(:new)
110110
end
@@ -113,17 +113,41 @@ def success_url
113113

114114

115115
describe "GET #edit" do
116-
before do
117-
request.session[:user_id] = @user.id
118-
get :edit, :repository_id => @repository_git.id, :id => @post_receive_url.id
116+
context "with existing post_receive_url" do
117+
before do
118+
request.session[:user_id] = @user.id
119+
get :edit, :repository_id => @repository_git.id, :id => @post_receive_url.id
120+
end
121+
122+
it "assigns the requested post_receive_url to @post_receive_url" do
123+
expect(assigns(:post_receive_url)).to eq @post_receive_url
124+
end
125+
126+
it "renders the :edit template" do
127+
expect(response).to render_template(:edit)
128+
end
119129
end
120130

121-
it "assigns the requested post_receive_url to @post_receive_url" do
122-
expect(assigns(:post_receive_url)).to eq @post_receive_url
131+
context "with non-existing post_receive_url" do
132+
before do
133+
request.session[:user_id] = @user.id
134+
get :edit, :repository_id => @repository_git.id, :id => 100
135+
end
136+
137+
it "renders 404" do
138+
expect(response.status).to eq 404
139+
end
123140
end
124141

125-
it "renders the :edit template" do
126-
expect(response).to render_template(:edit)
142+
context "with unsufficient permissions" do
143+
before do
144+
request.session[:user_id] = FactoryGirl.create(:user).id
145+
get :edit, :repository_id => @repository_git.id, :id => @post_receive_url.id
146+
end
147+
148+
it "renders 403" do
149+
expect(response.status).to eq 403
150+
end
127151
end
128152
end
129153

@@ -171,7 +195,7 @@ def success_url
171195

172196
it "does not change @post_receive_url's attributes" do
173197
@post_receive_url.reload
174-
expect(@post_receive_url.url).to eq 'http://example.com/toto.php'
198+
expect(@post_receive_url.url).to eq 'http://example.com/toto1.php'
175199
end
176200

177201
it "re-renders the :edit template" do
@@ -180,4 +204,22 @@ def success_url
180204
end
181205
end
182206

207+
208+
describe 'DELETE destroy' do
209+
before :each do
210+
request.session[:user_id] = @user.id
211+
@post_receive_url = FactoryGirl.create(:repository_post_receive_url, :repository_id => @repository_git.id)
212+
end
213+
214+
it "deletes the post_receive_url" do
215+
expect{
216+
delete :destroy, :repository_id => @repository_git.id, :id => @post_receive_url.id, :format => 'js'
217+
}.to change(RepositoryPostReceiveUrl, :count).by(-1)
218+
end
219+
220+
it "redirects to repositories#edit" do
221+
delete :destroy, :repository_id => @repository_git.id, :id => @post_receive_url.id, :format => 'js'
222+
expect(response.status).to eq 200
223+
end
224+
end
183225
end

0 commit comments

Comments
 (0)