Skip to content

Commit

Permalink
Merge pull request #143 from CocoaPods/seg-push-allow-warnings
Browse files Browse the repository at this point in the history
[PodsController] Add option to allow warnings when pushing a spec
  • Loading branch information
alloy committed Aug 2, 2015
2 parents ea1df96 + fcaa9b1 commit e0be3b3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
5 changes: 3 additions & 2 deletions app/controllers/api/pods_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ class PodsController < APIController
' CocoaPods Trunk. Is it a private repo or behind a username/password on http?')
end

unless specification.valid?
allow_warnings = params['allow_warnings'] == 'true'
unless specification.valid?(:allow_warnings => allow_warnings)
message = 'The Pod Specification did not pass validation.'
data = specification.validation_errors
data = specification.validation_errors(:allow_warnings => allow_warnings)
error(422, { 'error' => message, 'data' => data }.to_json)
end

Expand Down
7 changes: 4 additions & 3 deletions app/models/specification_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ def to_pretty_json(*a)
@specification.to_pretty_json(*a)
end

def valid?
def valid?(allow_warnings: false)
linter.lint
allow_warnings ? linter.errors.empty? : linter.results.empty?
end

def validation_errors
def validation_errors(allow_warnings: false)
results = {}
results['warnings'] = remove_prefixes(linter.warnings) unless linter.warnings.empty?
results['warnings'] = remove_prefixes(linter.warnings) unless allow_warnings || linter.warnings.empty?
results['errors'] = remove_prefixes(linter.errors) unless linter.errors.empty?
results
end
Expand Down
13 changes: 13 additions & 0 deletions spec/functional/api/pods_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,19 @@ module Pod::TrunkApp
}
end

it 'succeeds with a spec that has warnings when allow warnings has been specified' do
spec.license = nil

lambda do
lambda do
post '/?allow_warnings=true', spec.to_json
end.should.change { Pod.count }
end.should.change { PodVersion.count }
last_response.status.should == 302
last_response.location.should == 'https://example.org/AFNetworking/versions/1.2.0'
Pod.first(:name => spec.name).versions.map(&:name).should == [spec.version.to_s]
end

it 'does not allow a push for an existing pod with different case' do
@owner.add_pod(:name => spec.name.upcase)
lambda do
Expand Down

0 comments on commit e0be3b3

Please sign in to comment.