diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-11-09 13:42:29 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-11-09 13:42:29 +0400 |
commit | ca196453f000c81d2f476827d718d010a128cf10 (patch) | |
tree | 08430bc1bc4262513eeeee50ed3dd3504979ae74 /spec | |
parent | ea3680ad80e7623e03341a2568e775527bd47fd3 (diff) | |
parent | f64dd1b492952083449dc7f0e226cf7b20e1a1fb (diff) |
Merge branch 'feature/api_create_file' of /home/git/repositories/gitlab/gitlabhq
Diffstat (limited to 'spec')
-rw-r--r-- | spec/requests/api/files_spec.rb | 46 | ||||
-rw-r--r-- | spec/support/test_env.rb | 1 |
2 files changed, 47 insertions, 0 deletions
diff --git a/spec/requests/api/files_spec.rb b/spec/requests/api/files_spec.rb new file mode 100644 index 00000000000..637680672da --- /dev/null +++ b/spec/requests/api/files_spec.rb @@ -0,0 +1,46 @@ +require 'spec_helper' + +describe API::API do + include ApiHelpers + before(:each) { ActiveRecord::Base.observers.enable(:user_observer) } + after(:each) { ActiveRecord::Base.observers.disable(:user_observer) } + + let(:user) { create(:user) } + let!(:project) { create(:project_with_code, namespace: user.namespace ) } + before { project.team << [user, :developer] } + + describe "POST /projects/:id/repository/files" do + it "should create a new file in project repo" do + Gitlab::Satellite::NewFileAction.any_instance.stub( + commit!: true, + ) + + post api("/projects/#{project.id}/repository/files", user), valid_params + response.status.should == 201 + json_response['file_name'].should == 'newfile.rb' + end + + it "should return a 400 bad request if no params given" do + post api("/projects/#{project.id}/repository/files", user) + response.status.should == 400 + end + + it "should return a 400 if satellite fails to create file" do + Gitlab::Satellite::NewFileAction.any_instance.stub( + commit!: false, + ) + + post api("/projects/#{project.id}/repository/files", user), valid_params + response.status.should == 400 + end + end + + def valid_params + { + file_name: 'newfile.rb', + branch_name: 'master', + content: 'puts 8', + commit_message: 'Added newfile' + } + end +end diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb index 16e10b1a62b..5dbdffe4102 100644 --- a/spec/support/test_env.rb +++ b/spec/support/test_env.rb @@ -45,6 +45,7 @@ module TestEnv def disable_mailer NotificationService.any_instance.stub(mailer: double.as_null_object) end + def enable_mailer NotificationService.any_instance.unstub(:mailer) end |