Skip to content

Commit

Permalink
Moved "remove_account" to subcommand "delete account"
Browse files Browse the repository at this point in the history
  • Loading branch information
autodidacticon committed Oct 30, 2014
1 parent d77998c commit 50074c6
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ doc/*
log/*
pkg/*
tmp/*
.DS_Store
.idea
5 changes: 0 additions & 5 deletions lib/t/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -594,11 +594,6 @@ def reach(tweet_id)
say number_with_delimiter(reach.size)
end

desc 'remove_account SCREEN_NAME', 'remove account from t'
def remove_account(account)
@rcfile.remove_profile(account)
end

desc 'reply TWEET_ID MESSAGE', 'Post your Tweet as a reply directed at another person.'
method_option 'all', :aliases => '-a', :type => :boolean, :desc => 'Reply to all users mentioned in the Tweet.'
method_option 'location', :aliases => '-l', :type => :string, :default => nil, :desc => "Add location information. If the optional 'latitude,longitude' parameter is not supplied, looks up location by IP address."
Expand Down
12 changes: 12 additions & 0 deletions lib/t/delete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ def mute(user, *users)
say "Run `#{File.basename($PROGRAM_NAME)} mute #{unmuted_users.collect { |unmuted_user| "@#{unmuted_user.screen_name}" }.join(' ')}` to mute."
end

desc 'account SCREEN_NAME [CONSUMER_KEY]', 'delete account or consumer key from t'
def account(account, key = nil)
if key && @rcfile.profiles[account].keys.length == 1
continue = ask 'There is only one API key associated with this account, removing it will disable all functionality, are you sure you want to delete it? [y/N]'
return if continue.downcase != 'y'
elsif key
return @rcfile.delete_key(account, key)
else
@rcfile.delete_profile(account)
end
end

desc 'status TWEET_ID [TWEET_ID...]', 'Delete Tweets.'
method_option 'force', :aliases => '-f', :type => :boolean
def status(status_id, *status_ids)
Expand Down
7 changes: 6 additions & 1 deletion lib/t/rcfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,16 @@ def reset
send(:initialize)
end

def remove_profile(profile)
def delete_profile(profile)
profiles.delete(profile)
write
end

def delete_key(profile, key)
profiles[profile].delete(key)
write
end

private

def active_profile?
Expand Down
28 changes: 0 additions & 28 deletions spec/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2510,34 +2510,6 @@
end
end

describe '#remove_account' do
before do
@cli.options = @cli.options.merge('profile' => fixture_path + '/.trc')
delete_cli = {
'delete_cli' => {
'dw123' => {
'consumer_key' => 'abc123',
'secret' => 'epzrjvxtumoc',
'token' => '428004849-cebdct6bwobn',
'username' => 'deletecli',
'consumer_secret' => 'asdfasd223sd2'
}
}
}
rcfile = @cli.instance_variable_get(:@rcfile)
rcfile.profiles.merge!(delete_cli)
rcfile.send(:write)
end
it 'has the correct output' do
@cli.remove_account('delete_cli')
@cli.accounts
expect($stdout.string).to eq <<-eos
testcli
abc123 (active)
eos
end
end

describe '#reply' do
before do
@cli.options = @cli.options.merge('profile' => fixture_path + '/.trc', 'location' => nil)
Expand Down
95 changes: 95 additions & 0 deletions spec/delete_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,101 @@
end
end

describe '#delete_consumer_key_cancel' do
before do
@delete.options = @delete.options.merge('profile' => fixture_path + '/.trc')
delete_cli = {
'delete_cli' => {
'dw123' => {
'consumer_key' => 'abc123',
'secret' => 'epzrjvxtumoc',
'token' => '428004849-cebdct6bwobn',
'username' => 'deletecli',
'consumer_secret' => 'asdfasd223sd2'
}
}
}
rcfile = @delete.instance_variable_get(:@rcfile)
rcfile.profiles.merge!(delete_cli)
rcfile.send(:write)
end

after do
rcfile = @delete.instance_variable_get(:@rcfile)
rcfile.delete_profile('delete_cli')
end

it 'does not delete the key' do
expect(Readline).to receive(:readline).with('There is only one API key associated with this account, removing it will disable all functionality, are you sure you want to delete it? [y/N] ', true).and_return('N')
@delete.account('delete_cli', 'dw1234')
rcfile = @delete.instance_variable_get(:@rcfile)
expect(rcfile.profiles['delete_cli'].keys.include?('dw123')).to eq true
end
end

describe '#delete_key' do
before do
@delete.options = @delete.options.merge('profile' => fixture_path + '/.trc')
delete_cli = {
'delete_cli' => {
'dw123' => {
'consumer_key' => 'abc123',
'secret' => 'epzrjvxtumoc',
'token' => '428004849-cebdct6bwobn',
'username' => 'deletecli',
'consumer_secret' => 'asdfasd223sd2'
},
'dw1234' => {
'consumer_key' => 'abc1234',
'secret' => 'epzrjvxtumoc',
'token' => '428004849-cebdct6bwobn',
'username' => 'deletecli',
'consumer_secret' => 'asdfasd223sd2'
}
}
}
rcfile = @delete.instance_variable_get(:@rcfile)
rcfile.profiles.merge!(delete_cli)
rcfile.send(:write)
end

after do
rcfile = @delete.instance_variable_get(:@rcfile)
rcfile.delete_profile('delete_cli')
end

it 'deletes the key' do
@delete.account('delete_cli', 'dw1234')
rcfile = @delete.instance_variable_get(:@rcfile)
expect(rcfile.profiles['delete_cli'].keys.include?('dw1234')).to eq false
end
end

describe '#delete_account' do
before do
@delete.options = @delete.options.merge('profile' => fixture_path + '/.trc')
delete_cli = {
'delete_cli' => {
'dw123' => {
'consumer_key' => 'abc123',
'secret' => 'epzrjvxtumoc',
'token' => '428004849-cebdct6bwobn',
'username' => 'deletecli',
'consumer_secret' => 'asdfasd223sd2'
}
}
}
rcfile = @delete.instance_variable_get(:@rcfile)
rcfile.profiles.merge!(delete_cli)
rcfile.send(:write)
end
it 'deletes the account' do
@delete.account('delete_cli')
rcfile = @delete.instance_variable_get(:@rcfile)
expect(rcfile.profiles.keys.include?('delete_cli')).to eq false
end
end

describe '#status' do
before do
@delete.options = @delete.options.merge('profile' => fixture_path + '/.trc')
Expand Down

0 comments on commit 50074c6

Please sign in to comment.