Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of git://github.com/brookr/t into brookr-master

  • Loading branch information...
commit 7f199e0a54ca39a0f97c68cf82079050b4a18c97 2 parents f473c02 + 131bd34
@sferik authored
Showing with 21 additions and 4 deletions.
  1. +6 −1 lib/t/rcfile.rb
  2. +2 −2 lib/t/set.rb
  3. +13 −1 spec/set_spec.rb
View
7 lib/t/rcfile.rb
@@ -12,15 +12,20 @@ def initialize
end
def [](username)
- profiles[username]
+ profiles[username.downcase] || profiles[find(username)] || raise("Account #{username} not found.#{" Did you mean '#{find(username, 3)}'?" if find(username, 3)}")
end
def []=(username, profile)
+ username.downcase!
profiles[username] ||= {}
profiles[username].merge!(profile)
write
end
+ def find(username, comparison_length=99)
+ profiles.keys.detect{|key| key.match(Regexp.new(username.downcase[0..comparison_length], "i"))}
+ end
+
def configuration
@data['configuration']
end
View
4 lib/t/set.rb
@@ -19,8 +19,8 @@ def active(screen_name, consumer_key=nil)
screen_name = screen_name.strip_ats
@rcfile.path = options['profile'] if options['profile']
consumer_key = @rcfile[screen_name].keys.last if consumer_key.nil?
- @rcfile.active_profile = {'username' => screen_name, 'consumer_key' => consumer_key}
- say "Active account has been updated."
+ @rcfile.active_profile = {'username' => @rcfile[screen_name][consumer_key]["username"], 'consumer_key' => consumer_key}
+ say "Active account has been updated to #{@rcfile.active_profile[0]}."
end
map %w(default) => :active
View
14 spec/set_spec.rb
@@ -24,7 +24,19 @@
end
it "should have the correct output" do
@set.active("testcli", "abc123")
- $stdout.string.chomp.should == "Active account has been updated."
+ $stdout.string.chomp.should == "Active account has been updated to testcli."
+ end
+ it "should accept an account name without a consumer key" do
+ @set.active("testcli")
+ $stdout.string.chomp.should == "Active account has been updated to testcli."
+ end
+ it "should be case insensitive" do
+ @set.active("TestCLI")
+ $stdout.string.chomp.should == "Active account has been updated to testcli."
+ end
+ it "should find unambiguous partial matches" do
+ @set.active("TEST")
+ $stdout.string.chomp.should == "Active account has been updated to testcli."
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.