Skip to content

Commit

Permalink
Merge pull request #282 from CocoaPods/seg-fix-platform-serialization
Browse files Browse the repository at this point in the history
[JSON] Fix platform serialization to handle inheritance
  • Loading branch information
segiddins committed Dec 25, 2015
2 parents 5904729 + af9400f commit 0851a1e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
7 changes: 4 additions & 3 deletions lib/cocoapods-core/specification/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ def to_pretty_json(*a)
#
def to_hash
hash = attributes_hash.dup
platforms = platform_hash
platforms = Hash[DSL::PLATFORMS.map { |p| [p.to_s, nil] }] if platforms.empty?
hash['platforms'] = platforms
if root? || available_platforms != parent.available_platforms
platforms = Hash[available_platforms.map { |p| [p.name.to_s, p.deployment_target && p.deployment_target.to_s] }]
hash['platforms'] = platforms
end
unless subspecs.empty?
hash['subspecs'] = subspecs.map(&:to_hash)
end
Expand Down
31 changes: 27 additions & 4 deletions spec/specification/json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,42 @@ module Pod
end

it 'handles subspecs when converted to a hash' do
hash = @spec.to_hash
hash['subspecs'].should == [{
'name' => 'GreenBanana',
'source_files' => 'GreenBanana',
}]
end

it 'handles subspecs with different platforms' do
subspec = @spec.subspec_by_name('BananaLib/GreenBanana')
subspec.platforms = {
'ios' => '9.0',
'tvos' => '9.0',
}
hash = @spec.to_hash
hash['subspecs'].should == [{
'name' => 'GreenBanana',
'source_files' => 'GreenBanana',
'platforms' => {
'osx' => nil,
'ios' => nil,
'tvos' => nil,
'watchos' => nil,
'ios' => '9.0',
'tvos' => '9.0',
},
}]
end

it 'handles subspecs when the parent spec specifies platforms and the ' \
'subspec inherits' do
@spec.platforms = {
'tvos' => '9.0',
}
hash = @spec.to_hash
hash['subspecs'].should == [{
'name' => 'GreenBanana',
'source_files' => 'GreenBanana',
}]
end

it 'can be loaded from an hash' do
hash = {
'name' => 'BananaLib',
Expand Down

0 comments on commit 0851a1e

Please sign in to comment.