Permalink
Browse files

Fix the bug where you cannot specify both space and org when logging in

[#45624497]
  • Loading branch information...
1 parent 4850c8e commit 19f2f4aac7a01e11c2425ab33b13c93207c1ad87 Eugenia Dellapenna & Ian Baker committed Mar 6, 2013
View
@@ -29,6 +29,5 @@ group :test do
end
group :development do
- gem "pry"
gem "gem-release"
end
View
@@ -74,24 +74,18 @@ GEM
multi_json (~> 1.3)
cf-uaa-lib (1.3.7)
multi_json
- coderay (1.0.9)
crack (0.3.2)
diff-lcs (1.1.3)
fakefs (0.4.2)
ffaker (1.15.0)
gem-release (0.4.1)
json_pure (1.7.7)
- method_source (0.8.1)
mime-types (1.21)
multi_json (1.6.1)
multipart-post (1.2.0)
parallel (0.6.2)
parallel_tests (0.10.0)
parallel
- pry (0.9.12)
- coderay (~> 1.0.5)
- method_source (~> 0.8)
- slop (~> 3.4)
rake (10.0.3)
rest-client (1.6.7)
mime-types (>= 1.16)
@@ -105,7 +99,6 @@ GEM
diff-lcs (~> 1.1.3)
rspec-mocks (2.12.2)
rubyzip (0.9.9)
- slop (3.4.3)
uuidtools (2.1.3)
webmock (1.9.3)
addressable (>= 2.2.7)
@@ -129,7 +122,6 @@ DEPENDENCIES
mothership!
multi_json (~> 1.3)
parallel_tests
- pry
rake
rr (~> 1.0)
rspec (~> 2.11)
View
@@ -37,32 +37,42 @@ def display_target
def select_org(input, info)
if input.has?(:organization) || !org_valid?(info[:organization])
org = input[:organization]
- with_progress("Switching to organization #{c(org.name, :name)}") {} if org
- org
+ if org
+ with_progress("Switching to organization #{c(org.name, :name)}") {}
+ client.current_organization = org
+ end
+ info[:organization] = org ? org.guid : nil
+ !!org
else
- client.current_organization
+ info[:organization] = nil
+ client.current_organization = nil
+ false
end
end
- def select_space(org, input, info, changed_org)
+ def select_space(input, info, changed_org)
if input.has?(:space) || !space_valid?(info[:space])
line if changed_org && !quiet?
- space = input[:space, org]
- with_progress("Switching to space #{c(space.name, :name)}") {} if space
- space
+ space = input[:space, client.current_organization]
+ if space
+ with_progress("Switching to space #{c(space.name, :name)}") {}
+ client.current_space = space
+ end
+ info[:space] = space ? space.guid : nil
else
- client.current_space
+ info[:space] = nil
+ client.current_space = nil
end
end
def select_org_and_space(input, info)
- org = select_org(input, info)
- changed_org = client.current_organization != org
- space = select_space(org, input, info, changed_org) if org
- info.merge!(
- :organization => (org ? org.guid : nil),
- :space => (space ? space.guid : nil)
- )
+ changed_org = select_org(input, info)
+ if client.current_organization
+ select_space(input, info, changed_org)
+ else
+ info[:space] = nil
+ client.current_space = nil
+ end
end
def org_valid?(guid, user = client.current_user)
@@ -0,0 +1,64 @@
+require "spec_helper"
+
+if ENV['VMC_V2_TEST_USER'] && ENV['VMC_V2_TEST_PASSWORD'] && ENV['VMC_V2_TEST_TARGET'] && ENV['VMC_V2_OTHER_TEST_USER']
+ describe 'A user logs in and switches spaces, after a different user has logged in', :ruby19 => true do
+ include ConsoleAppSpeckerMatchers
+
+ let(:target) { ENV['VMC_V2_TEST_TARGET'] }
+ let(:username) { ENV['VMC_V2_TEST_USER'] }
+ let(:password) { ENV['VMC_V2_TEST_PASSWORD'] }
+
+ let(:second_username) { ENV['VMC_V2_OTHER_TEST_USER'] }
+ let(:second_organization) { ENV['VMC_V2_OTHER_TEST_ORGANIZATION'] }
+ let(:second_space) { ENV['VMC_V2_OTHER_TEST_SPACE'] }
+ let(:second_password) { ENV['VMC_V2_OTHER_TEST_PASSWORD'] || ENV['VMC_V2_TEST_PASSWORD'] }
+
+ before do
+ Interact::Progress::Dots.start!
+
+ run("#{vmc_bin} target #{target}") do |runner|
+ expect(runner).to say "Setting target"
+ expect(runner).to say target
+ runner.wait_for_exit
+ end
+
+ run("#{vmc_bin} logout") do |runner|
+ runner.wait_for_exit
+ end
+ end
+
+ after do
+ Interact::Progress::Dots.stop!
+ end
+
+ context "when a different user is already logged in" do
+ before do
+ run("#{vmc_bin} login #{username} --password #{password}") do |runner|
+ expect(runner).to say "Authenticating... OK"
+
+ expect(runner).to say "Switching to organization"
+ expect(runner).to say "OK"
+
+ expect(runner).to say "Space"
+ runner.send_keys("1")
+
+ expect(runner).to say "Switching to space"
+ expect(runner).to say "OK"
+
+ runner.wait_for_exit
+ end
+ end
+
+ it "can switch spaces on login" do
+ run("#{vmc_bin} login #{second_username} --password #{second_password} --organization #{second_organization} --space #{second_space}") do |runner|
+ expect(runner).to say "Authenticating... OK"
+ expect(runner).to say "Switching to organization #{second_organization}... OK"
+ expect(runner).to say "Switching to space #{second_space}... OK"
+ runner.wait_for_exit
+ end
+ end
+ end
+ end
+else
+ $stderr.puts 'Skipping v2 integration specs; please provide $VMC_V2_TEST_TARGET, $VMC_V2_TEST_USER, $VMC_V2_TEST_PASSWORD, and $VMC_V2_OTHER_TEST_USER'
+end
@@ -121,5 +121,5 @@
end
end
else
- $stderr.puts 'Skipping integration specs; please provide $VMC_TEST_TARGET, $VMC_TEST_USER, and $VMC_TEST_PASSWORD'
+ $stderr.puts 'Skipping v2 integration specs; please provide $VMC_V2_TEST_TARGET, $VMC_V2_TEST_USER, and $VMC_V2_TEST_PASSWORD'
end
@@ -16,7 +16,7 @@
it "can switch targets, even if a target is invalid" do
run("#{vmc_bin} target invalid-target") do |runner|
- expect(runner).to say "target refused"
+ expect(runner).to say /target refused/i
runner.wait_for_exit
end
@@ -29,4 +29,4 @@
end
else
$stderr.puts 'Skipping v2 integration specs; please provide $VMC_V2_TEST_TARGET'
-end
+end

0 comments on commit 19f2f4a

Please sign in to comment.