Commit e8bb32e6 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Specs for Create file API

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 0b67606a
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
...@@ -45,6 +45,7 @@ module TestEnv ...@@ -45,6 +45,7 @@ module TestEnv
def disable_mailer def disable_mailer
NotificationService.any_instance.stub(mailer: double.as_null_object) NotificationService.any_instance.stub(mailer: double.as_null_object)
end end
def enable_mailer def enable_mailer
NotificationService.any_instance.unstub(:mailer) NotificationService.any_instance.unstub(:mailer)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment