Commit e8bb32e62355542e2fe3c17c06a433f355694788
1 parent
0b67606a
Exists in
master
and in
4 other branches
Specs for Create file API
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
2 changed files
with
47 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,46 @@ | @@ -0,0 +1,46 @@ | ||
1 | +require 'spec_helper' | ||
2 | + | ||
3 | +describe API::API do | ||
4 | + include ApiHelpers | ||
5 | + before(:each) { ActiveRecord::Base.observers.enable(:user_observer) } | ||
6 | + after(:each) { ActiveRecord::Base.observers.disable(:user_observer) } | ||
7 | + | ||
8 | + let(:user) { create(:user) } | ||
9 | + let!(:project) { create(:project_with_code, namespace: user.namespace ) } | ||
10 | + before { project.team << [user, :developer] } | ||
11 | + | ||
12 | + describe "POST /projects/:id/repository/files" do | ||
13 | + it "should create a new file in project repo" do | ||
14 | + Gitlab::Satellite::NewFileAction.any_instance.stub( | ||
15 | + commit!: true, | ||
16 | + ) | ||
17 | + | ||
18 | + post api("/projects/#{project.id}/repository/files", user), valid_params | ||
19 | + response.status.should == 201 | ||
20 | + json_response['file_name'].should == 'newfile.rb' | ||
21 | + end | ||
22 | + | ||
23 | + it "should return a 400 bad request if no params given" do | ||
24 | + post api("/projects/#{project.id}/repository/files", user) | ||
25 | + response.status.should == 400 | ||
26 | + end | ||
27 | + | ||
28 | + it "should return a 400 if satellite fails to create file" do | ||
29 | + Gitlab::Satellite::NewFileAction.any_instance.stub( | ||
30 | + commit!: false, | ||
31 | + ) | ||
32 | + | ||
33 | + post api("/projects/#{project.id}/repository/files", user), valid_params | ||
34 | + response.status.should == 400 | ||
35 | + end | ||
36 | + end | ||
37 | + | ||
38 | + def valid_params | ||
39 | + { | ||
40 | + file_name: 'newfile.rb', | ||
41 | + branch_name: 'master', | ||
42 | + content: 'puts 8', | ||
43 | + commit_message: 'Added newfile' | ||
44 | + } | ||
45 | + end | ||
46 | +end |
spec/support/test_env.rb
@@ -45,6 +45,7 @@ module TestEnv | @@ -45,6 +45,7 @@ module TestEnv | ||
45 | def disable_mailer | 45 | def disable_mailer |
46 | NotificationService.any_instance.stub(mailer: double.as_null_object) | 46 | NotificationService.any_instance.stub(mailer: double.as_null_object) |
47 | end | 47 | end |
48 | + | ||
48 | def enable_mailer | 49 | def enable_mailer |
49 | NotificationService.any_instance.unstub(:mailer) | 50 | NotificationService.any_instance.unstub(:mailer) |
50 | end | 51 | end |