Commit cf09b187af5b8fe4c58967c7e528a70db6cbe1b5
Committed by
Rafael Manzo
1 parent
5ba1c648
Exists in
colab
and in
4 other branches
Unit tests for RepositoriesController edit method
Signed-off-by: Renan Fichberg <rfichberg@gmail.com> Signed-off-by: Diego Araujo <diegoamc90@gmail.com>
Showing
2 changed files
with
14 additions
and
28 deletions
Show diff stats
app/controllers/repositories_controller.rb
| ... | ... | @@ -22,7 +22,7 @@ class RepositoriesController < ApplicationController |
| 22 | 22 | |
| 23 | 23 | # GET /repositories/1/edit |
| 24 | 24 | def edit |
| 25 | - sproject_id = params[:project_id] | |
| 25 | + @project_id = params[:project_id] | |
| 26 | 26 | set_repository #FIXME: this method has been already called on before_action |
| 27 | 27 | @repository_types = Repository.repository_types |
| 28 | 28 | end | ... | ... |
spec/controllers/repositories_controller_spec.rb
| ... | ... | @@ -116,7 +116,7 @@ describe RepositoriesController do |
| 116 | 116 | before :each do |
| 117 | 117 | Repository.expects(:find).at_least_once.with(repository.id).returns(repository) |
| 118 | 118 | |
| 119 | - delete :destroy, :id => repository.id, project_id: project.id.to_s | |
| 119 | + delete :destroy, id: repository.id, project_id: project.id.to_s | |
| 120 | 120 | end |
| 121 | 121 | |
| 122 | 122 | it { should redirect_to(projects_url) } |
| ... | ... | @@ -126,54 +126,41 @@ describe RepositoriesController do |
| 126 | 126 | |
| 127 | 127 | context 'with no User logged in' do |
| 128 | 128 | before :each do |
| 129 | - delete :destroy, :id => repository.id, project_id: project.id.to_s | |
| 129 | + delete :destroy, id: repository.id, project_id: project.id.to_s | |
| 130 | 130 | end |
| 131 | 131 | |
| 132 | 132 | it { should redirect_to new_user_session_path } |
| 133 | 133 | end |
| 134 | 134 | end |
| 135 | 135 | |
| 136 | - pending "Work in progress" do | |
| 137 | 136 | describe 'edit' do |
| 138 | - before do | |
| 139 | - @subject = FactoryGirl.build(:repository) | |
| 140 | - end | |
| 137 | + let(:repository) { FactoryGirl.build(:repository) } | |
| 141 | 138 | |
| 142 | 139 | context 'with an User logged in' do |
| 143 | 140 | before do |
| 144 | - @user = FactoryGirl.create(:user) | |
| 145 | - @ownership = FactoryGirl.build(:repository_ownership) | |
| 146 | - @ownerships = [] | |
| 147 | - | |
| 148 | - User.any_instance.expects(:repository_ownerships).at_least_once.returns(@ownerships) | |
| 149 | - | |
| 150 | - sign_in @user | |
| 141 | + sign_in FactoryGirl.create(:user) | |
| 151 | 142 | end |
| 152 | 143 | |
| 153 | 144 | context 'when the user owns the repository' do |
| 154 | 145 | before :each do |
| 155 | - Repository.expects(:find).with(@subject.id.to_s).returns(@subject) | |
| 156 | - @ownerships.expects(:find_by_repository_id).with("#{@subject.id}").returns(@ownership) | |
| 157 | - | |
| 158 | - get :edit, :id => @subject.id | |
| 146 | + subject.expects(:check_repository_ownership).returns true | |
| 147 | + Repository.expects(:find).at_least_once.with(repository.id).returns(repository) | |
| 148 | + Repository.expects(:repository_types).returns(["SUBVERSION"]) | |
| 149 | + get :edit, id: repository.id, project_id: project.id.to_s | |
| 159 | 150 | end |
| 160 | 151 | |
| 161 | 152 | it { should render_template(:edit) } |
| 162 | - | |
| 163 | - it 'should assign to @repository the @subject' do | |
| 164 | - assigns(:repository).should eq(@subject) | |
| 165 | - end | |
| 166 | 153 | end |
| 167 | 154 | |
| 168 | 155 | context 'when the user does not own the repository' do |
| 169 | 156 | before do |
| 170 | - @subject = FactoryGirl.build(:another_repository) | |
| 171 | - @ownerships.expects(:find_by_repository_id).with("#{@subject.id}").returns(nil) | |
| 157 | + Repository.expects(:find).at_least_once.with(repository.id).returns(repository) | |
| 172 | 158 | |
| 173 | - get :edit, :id => @subject.id | |
| 159 | + get :edit, id: repository.id, project_id: project.id.to_s | |
| 174 | 160 | end |
| 175 | 161 | |
| 176 | - it { should redirect_to(repositories_path) } | |
| 162 | + it { should redirect_to(projects_url) } | |
| 163 | + it { should respond_with(:redirect) } | |
| 177 | 164 | |
| 178 | 165 | it 'should set the flash' do |
| 179 | 166 | pending("This ShouldaMatcher test is not compatible yet with Rails 4") do |
| ... | ... | @@ -185,13 +172,12 @@ describe RepositoriesController do |
| 185 | 172 | |
| 186 | 173 | context 'with no user logged in' do |
| 187 | 174 | before :each do |
| 188 | - get :edit, :id => @subject.id | |
| 175 | + get :edit, id: repository.id, project_id: project.id.to_s | |
| 189 | 176 | end |
| 190 | 177 | |
| 191 | 178 | it { should redirect_to new_user_session_path } |
| 192 | 179 | end |
| 193 | 180 | end |
| 194 | - end | |
| 195 | 181 | |
| 196 | 182 | pending "Work in progress" do |
| 197 | 183 | describe 'update' do | ... | ... |