Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a new command for renaming yourself on trunk #92

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

##### Enhancements

* None.
* Adds a `pod trunk me rename NAME` command so that you can change the display name on CocoaPods.org
[Orta Therox](https://github.com/orta)
[Ash Furrow](https://github.com/ashfurrow)
[Ryan C. Payne](https://github.com/paynerc)
[trunk.cocoapods.org#155](https://github.com/CocoaPods/trunk.cocoapods.org/issues/155)

##### Bug Fixes

Expand Down
1 change: 1 addition & 0 deletions lib/pod/command/trunk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Trunk < Command
require 'pod/command/trunk/deprecate'
require 'pod/command/trunk/info'
require 'pod/command/trunk/me'
require 'pod/command/trunk/me_rename'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pod/command/trunk/me/rename

require 'pod/command/trunk/push'
require 'pod/command/trunk/register'
require 'pod/command/trunk/remove_owner'
Expand Down
44 changes: 44 additions & 0 deletions lib/pod/command/trunk/me_rename.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module Pod
class Command
class Trunk
# @CocoaPods 1.2.1+
#
class Rename < Me
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

namespace under Me

self.summary = 'Rename your account'
self.description = <<-DESC
Updates your username for your Trunk account.

Examples:

$ pod trunk me rename 'Eloy Durán'
$ pod trunk me rename 'Orta Therox'
DESC

self.arguments = [
CLAide::Argument.new('NAME', true),
]

def initialize(argv)
@name = argv.shift_argument
super
end

def validate!
super
unless @name
help! 'Please specify a name.'
end
end

def run
email = netrc['trunk.cocoapods.org'] && netrc['trunk.cocoapods.org'].login
body = { 'name' => @name, 'email' => email }.to_json
json(request_path(:post, 'sessions', body, auth_headers))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what will this output on success?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing, good point 👍

rescue REST::Error => e
raise Informative, 'There was an error re-naming your account on trunk: ' \
"#{e.message}"
end
end
end
end
end
36 changes: 36 additions & 0 deletions spec/command/trunk/me_rename_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require File.expand_path('../../../spec_helper', __FILE__)

module Pod
describe Command::Trunk::Register do
describe 'CLAide' do
it 'registers it self' do
Command.parse(%w[trunk me rename]).should.be.instance_of Command::Trunk::Rename
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use %() to delimited the arrays

end
end

it 'should error if name is not supplied' do
command = Command.parse(%w[trunk me rename])
exception = lambda { command.validate! }.should.raise CLAide::Help
exception.message.should.include 'name'
end

it 'should error if name is not supplied' do
Netrc.any_instance.stubs(:[]).returns(nil)
command = Command.parse(%w[trunk me rename orta])
exception = lambda { command.validate! }.should.raise CLAide::Help
exception.message.should.include 'You need to register a session'
end

it 'should send an API call to update the user' do
url = 'https://trunk.cocoapods.org/api/v1/sessions'
WebMock::API.stub_request(:post, url).
with(:body => WebMock::API.hash_including('email' => '[email protected]', 'name' => 'Kyle 2')).
to_return(:status => 200, :body => '{"token": "acct"}')

Netrc.any_instance.stubs(:[]).returns(stub('login' => '[email protected]', 'password' => 'acct'))

command = Command.parse(['trunk', 'me', 'rename', 'Kyle 2'])
lambda { command.run }.should.not.raise
end
end
end