-
Notifications
You must be signed in to change notification settings - Fork 20
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. namespace under |
||
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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what will this output on success? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
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 |
There was a problem hiding this comment.
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