Commit 3586d72eb09aa840c7440e5b3fb23840619f0838
1 parent
cf09b187
Exists in
colab
and in
4 other branches
RepositoriesController covered with unit tests
Showing
1 changed file
with
18 additions
and
39 deletions
Show diff stats
spec/controllers/repositories_controller_spec.rb
| @@ -179,60 +179,38 @@ describe RepositoriesController do | @@ -179,60 +179,38 @@ describe RepositoriesController do | ||
| 179 | end | 179 | end |
| 180 | end | 180 | end |
| 181 | 181 | ||
| 182 | - pending "Work in progress" do | ||
| 183 | describe 'update' do | 182 | describe 'update' do |
| 184 | - before do | ||
| 185 | - @subject = FactoryGirl.build(:repository) | ||
| 186 | - @subject_params = Hash[FactoryGirl.attributes_for(:repository).map { |k,v| [k.to_s, v.to_s] }] #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with sybols and integers | ||
| 187 | - end | ||
| 188 | - | 183 | + let(:repository) { FactoryGirl.build(:repository) } |
| 184 | + let(:repository_params) { Hash[FactoryGirl.attributes_for(:repository).map { |k,v| [k.to_s, v.to_s] }] } #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with sybols and integers | ||
| 185 | + | ||
| 189 | context 'when the user is logged in' do | 186 | context 'when the user is logged in' do |
| 190 | before do | 187 | before do |
| 191 | sign_in FactoryGirl.create(:user) | 188 | sign_in FactoryGirl.create(:user) |
| 192 | end | 189 | end |
| 193 | 190 | ||
| 194 | context 'when user owns the repository' do | 191 | context 'when user owns the repository' do |
| 195 | - before do | ||
| 196 | - @ownership = FactoryGirl.build(:repository_ownership) | ||
| 197 | - @ownerships = [] | ||
| 198 | - | ||
| 199 | - @ownerships.expects(:find_by_repository_id).with("#{@subject.id}").returns(@ownership) | ||
| 200 | - User.any_instance.expects(:repository_ownerships).at_least_once.returns(@ownerships) | 192 | + before :each do |
| 193 | + subject.expects(:check_repository_ownership).returns true | ||
| 201 | end | 194 | end |
| 202 | 195 | ||
| 203 | context 'with valid fields' do | 196 | context 'with valid fields' do |
| 204 | before :each do | 197 | before :each do |
| 205 | - Repository.expects(:find).with(@subject.id.to_s).returns(@subject) | ||
| 206 | - Repository.any_instance.expects(:update).with(@subject_params).returns(true) | ||
| 207 | - end | ||
| 208 | - | ||
| 209 | - context 'rendering the show' do | ||
| 210 | - before :each do | ||
| 211 | - Repository.expects(:exists?).returns(true) | 198 | + Repository.expects(:find).at_least_once.with(repository.id).returns(repository) |
| 199 | + Repository.any_instance.expects(:update).with(repository_params).returns(true) | ||
| 212 | 200 | ||
| 213 | - post :update, :id => @subject.id, :repository => @subject_params | ||
| 214 | - end | ||
| 215 | - | ||
| 216 | - it 'should redirect to the show view' do | ||
| 217 | - response.should redirect_to repository_path(@subject) | ||
| 218 | - end | 201 | + post :update, project_id: project.id.to_s, :id => repository.id, :repository => repository_params |
| 219 | end | 202 | end |
| 220 | 203 | ||
| 221 | - context 'without rendering the show view' do | ||
| 222 | - before :each do | ||
| 223 | - post :update, :id => @subject.id, :repository => @subject_params | ||
| 224 | - end | ||
| 225 | - | ||
| 226 | - it { should respond_with(:redirect) } | ||
| 227 | - end | 204 | + it { should redirect_to(project_repository_path(repository.project_id, repository.id)) } |
| 205 | + it { should respond_with(:redirect) } | ||
| 228 | end | 206 | end |
| 229 | 207 | ||
| 230 | context 'with an invalid field' do | 208 | context 'with an invalid field' do |
| 231 | before :each do | 209 | before :each do |
| 232 | - Repository.expects(:find).with(@subject.id.to_s).returns(@subject) | ||
| 233 | - Repository.any_instance.expects(:update).with(@subject_params).returns(false) | 210 | + Repository.expects(:find).at_least_once.with(repository.id).returns(repository) |
| 211 | + Repository.any_instance.expects(:update).with(repository_params).returns(false) | ||
| 234 | 212 | ||
| 235 | - post :update, :id => @subject.id, :repository => @subject_params | 213 | + post :update, project_id: project.id.to_s, :id => repository.id, :repository => repository_params |
| 236 | end | 214 | end |
| 237 | 215 | ||
| 238 | it { should render_template(:edit) } | 216 | it { should render_template(:edit) } |
| @@ -241,20 +219,21 @@ describe RepositoriesController do | @@ -241,20 +219,21 @@ describe RepositoriesController do | ||
| 241 | 219 | ||
| 242 | context 'when the user does not own the repository' do | 220 | context 'when the user does not own the repository' do |
| 243 | before :each do | 221 | before :each do |
| 244 | - post :update, :id => @subject.id, :repository => @subject_params | 222 | + Repository.expects(:find).at_least_once.with(repository.id).returns(repository) |
| 223 | + | ||
| 224 | + post :update, project_id: project.id.to_s, :id => repository.id, :repository => repository_params | ||
| 245 | end | 225 | end |
| 246 | 226 | ||
| 247 | - it { should redirect_to repositories_path } | 227 | + it { should redirect_to projects_path } |
| 248 | end | 228 | end |
| 249 | end | 229 | end |
| 250 | 230 | ||
| 251 | context 'with no user logged in' do | 231 | context 'with no user logged in' do |
| 252 | before :each do | 232 | before :each do |
| 253 | - post :update, :id => @subject.id, :repository => @subject_params | 233 | + post :update, project_id: project.id.to_s, :id => repository.id, :repository => repository_params |
| 254 | end | 234 | end |
| 255 | 235 | ||
| 256 | it { should redirect_to new_user_session_path } | 236 | it { should redirect_to new_user_session_path } |
| 257 | end | 237 | end |
| 258 | end | 238 | end |
| 259 | - end | ||
| 260 | end | 239 | end |