Skip to content

Commit

Permalink
Allow filtering account's list by organisation's name
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii Nyzhnyk authored and tddium committed Jan 23, 2015
1 parent 64e808c commit f231f04
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -7,6 +7,7 @@ tmp
coverage

.rvmrc
.tddium*
.solano*
.solano-deploy-key*

Expand Down
5 changes: 3 additions & 2 deletions lib/solano/cli/commands/account.rb
@@ -1,8 +1,9 @@
# Copyright (c) 2011, 2012, 2013, 2014 Solano Labs All Rights Reserved
# Copyright (c) 2011, 2012, 2013, 2014, 2015 Solano Labs All Rights Reserved

module Solano
class SolanoCli < Thor
desc "account", "View account information"
desc "account [--org NAME]", "View account information"
method_option :org, type: :string
def account
user_details = solano_setup({:scm => false})

Expand Down
18 changes: 16 additions & 2 deletions lib/solano/cli/show.rb
@@ -1,4 +1,4 @@
# Copyright (c) 2011, 2012, 2013, 2014 Solano Labs All Rights Reserved
# Copyright (c) 2011, 2012, 2013, 2014, 2015 Solano Labs All Rights Reserved

module Solano
class SolanoCli < Thor
Expand Down Expand Up @@ -78,7 +78,21 @@ def show_user_details(user)

# Use "all_accounts" here instead of "participating_accounts" -- these
# are the accounts the user can administer.
user["all_accounts"].each do |acct|
# Select those accounts that match org param or all if no org param

org = options['org']
regexp = org.nil? ? nil : Regexp.new(org.to_s)
account_list = user['all_accounts']
account_list.select! do |acct|
if regexp.nil? || regexp =~ acct[:account] then
acct
else
nil
end
end
account_list.compact!

account_list.each do |acct|
id = acct['account_id'].to_i

say ERB.new(Text::Status::ACCOUNT_DETAILS).result(binding)
Expand Down
2 changes: 1 addition & 1 deletion lib/solano/util.rb
@@ -1,4 +1,4 @@
# Copyright (c) 2012, 2013, 2014 Solano Labs, Inc. All Rights Reserved
# Copyright (c) 2012, 2013, 2014, 2015 Solano Labs, Inc. All Rights Reserved

require 'stringio'

Expand Down
44 changes: 44 additions & 0 deletions spec/cli/commands/account_spec.rb
@@ -0,0 +1,44 @@
# Copyright (c) 2015 Solano Labs All Rights Reserved

require 'spec_helper'
require 'solano/cli'
require 'solano/cli/commands/account'

describe Solano::SolanoCli do
describe "#account" do
include_context 'solano_api_stubs'

let(:data) do
{ 'all_accounts' => [{
"account_url"=>"http://localhost:3000/organizations/23/edit/profile",
"billing_type"=>"recurly",
"subscribed"=>false,
"trial_remaining"=>0,
"plan"=>"small",
"heroku_needs_activation"=>false,
"account"=>"some_name",
"account_id"=>23,
"account_role"=>"owner",
"account_owner"=>"anyzhnik@solanolabs.com"
},
{ "account_url"=>"http://localhost:3000/organizations/20/edit/profile",
"subscribed"=>false,
"trial_remaining"=>0,
"plan"=>"small",
"heroku_needs_activation"=>false,
"account"=>"some_other_name",
"account_id"=>20,
"account_role"=>"admin",
"account_owner"=>"nyzhnikandrii@gmail.com"
}] }
end

before do
expect(subject).to receive(:solano_setup).with({ scm: false }).and_return(data)
expect(solano_api).to receive(:get_suites).and_return([])
expect(solano_api).to receive(:get_memberships).and_return([])
expect(solano_api).to receive(:get_usage).and_return({})
ERB.any_instance.stub(:result)
end
end
end

0 comments on commit f231f04

Please sign in to comment.