Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

[#45624497]
  • Loading branch information...
commit 19f2f4aac7a01e11c2425ab33b13c93207c1ad87 1 parent 4850c8e
Eugenia Dellapenna & Ian Baker authored
1  Gemfile
@@ -29,6 +29,5 @@ group :test do
29 29 end
30 30
31 31 group :development do
32   - gem "pry"
33 32 gem "gem-release"
34 33 end
8 Gemfile.lock
@@ -74,24 +74,18 @@ GEM
74 74 multi_json (~> 1.3)
75 75 cf-uaa-lib (1.3.7)
76 76 multi_json
77   - coderay (1.0.9)
78 77 crack (0.3.2)
79 78 diff-lcs (1.1.3)
80 79 fakefs (0.4.2)
81 80 ffaker (1.15.0)
82 81 gem-release (0.4.1)
83 82 json_pure (1.7.7)
84   - method_source (0.8.1)
85 83 mime-types (1.21)
86 84 multi_json (1.6.1)
87 85 multipart-post (1.2.0)
88 86 parallel (0.6.2)
89 87 parallel_tests (0.10.0)
90 88 parallel
91   - pry (0.9.12)
92   - coderay (~> 1.0.5)
93   - method_source (~> 0.8)
94   - slop (~> 3.4)
95 89 rake (10.0.3)
96 90 rest-client (1.6.7)
97 91 mime-types (>= 1.16)
@@ -105,7 +99,6 @@ GEM
105 99 diff-lcs (~> 1.1.3)
106 100 rspec-mocks (2.12.2)
107 101 rubyzip (0.9.9)
108   - slop (3.4.3)
109 102 uuidtools (2.1.3)
110 103 webmock (1.9.3)
111 104 addressable (>= 2.2.7)
@@ -129,7 +122,6 @@ DEPENDENCIES
129 122 mothership!
130 123 multi_json (~> 1.3)
131 124 parallel_tests
132   - pry
133 125 rake
134 126 rr (~> 1.0)
135 127 rspec (~> 2.11)
40 lib/vmc/cli/start/base.rb
@@ -37,32 +37,42 @@ def display_target
37 37 def select_org(input, info)
38 38 if input.has?(:organization) || !org_valid?(info[:organization])
39 39 org = input[:organization]
40   - with_progress("Switching to organization #{c(org.name, :name)}") {} if org
41   - org
  40 + if org
  41 + with_progress("Switching to organization #{c(org.name, :name)}") {}
  42 + client.current_organization = org
  43 + end
  44 + info[:organization] = org ? org.guid : nil
  45 + !!org
42 46 else
43   - client.current_organization
  47 + info[:organization] = nil
  48 + client.current_organization = nil
  49 + false
44 50 end
45 51 end
46 52
47   - def select_space(org, input, info, changed_org)
  53 + def select_space(input, info, changed_org)
48 54 if input.has?(:space) || !space_valid?(info[:space])
49 55 line if changed_org && !quiet?
50   - space = input[:space, org]
51   - with_progress("Switching to space #{c(space.name, :name)}") {} if space
52   - space
  56 + space = input[:space, client.current_organization]
  57 + if space
  58 + with_progress("Switching to space #{c(space.name, :name)}") {}
  59 + client.current_space = space
  60 + end
  61 + info[:space] = space ? space.guid : nil
53 62 else
54   - client.current_space
  63 + info[:space] = nil
  64 + client.current_space = nil
55 65 end
56 66 end
57 67
58 68 def select_org_and_space(input, info)
59   - org = select_org(input, info)
60   - changed_org = client.current_organization != org
61   - space = select_space(org, input, info, changed_org) if org
62   - info.merge!(
63   - :organization => (org ? org.guid : nil),
64   - :space => (space ? space.guid : nil)
65   - )
  69 + changed_org = select_org(input, info)
  70 + if client.current_organization
  71 + select_space(input, info, changed_org)
  72 + else
  73 + info[:space] = nil
  74 + client.current_space = nil
  75 + end
66 76 end
67 77
68 78 def org_valid?(guid, user = client.current_user)
64 spec/features/v2/login_spec.rb
... ... @@ -0,0 +1,64 @@
  1 +require "spec_helper"
  2 +
  3 +if ENV['VMC_V2_TEST_USER'] && ENV['VMC_V2_TEST_PASSWORD'] && ENV['VMC_V2_TEST_TARGET'] && ENV['VMC_V2_OTHER_TEST_USER']
  4 + describe 'A user logs in and switches spaces, after a different user has logged in', :ruby19 => true do
  5 + include ConsoleAppSpeckerMatchers
  6 +
  7 + let(:target) { ENV['VMC_V2_TEST_TARGET'] }
  8 + let(:username) { ENV['VMC_V2_TEST_USER'] }
  9 + let(:password) { ENV['VMC_V2_TEST_PASSWORD'] }
  10 +
  11 + let(:second_username) { ENV['VMC_V2_OTHER_TEST_USER'] }
  12 + let(:second_organization) { ENV['VMC_V2_OTHER_TEST_ORGANIZATION'] }
  13 + let(:second_space) { ENV['VMC_V2_OTHER_TEST_SPACE'] }
  14 + let(:second_password) { ENV['VMC_V2_OTHER_TEST_PASSWORD'] || ENV['VMC_V2_TEST_PASSWORD'] }
  15 +
  16 + before do
  17 + Interact::Progress::Dots.start!
  18 +
  19 + run("#{vmc_bin} target #{target}") do |runner|
  20 + expect(runner).to say "Setting target"
  21 + expect(runner).to say target
  22 + runner.wait_for_exit
  23 + end
  24 +
  25 + run("#{vmc_bin} logout") do |runner|
  26 + runner.wait_for_exit
  27 + end
  28 + end
  29 +
  30 + after do
  31 + Interact::Progress::Dots.stop!
  32 + end
  33 +
  34 + context "when a different user is already logged in" do
  35 + before do
  36 + run("#{vmc_bin} login #{username} --password #{password}") do |runner|
  37 + expect(runner).to say "Authenticating... OK"
  38 +
  39 + expect(runner).to say "Switching to organization"
  40 + expect(runner).to say "OK"
  41 +
  42 + expect(runner).to say "Space"
  43 + runner.send_keys("1")
  44 +
  45 + expect(runner).to say "Switching to space"
  46 + expect(runner).to say "OK"
  47 +
  48 + runner.wait_for_exit
  49 + end
  50 + end
  51 +
  52 + it "can switch spaces on login" do
  53 + run("#{vmc_bin} login #{second_username} --password #{second_password} --organization #{second_organization} --space #{second_space}") do |runner|
  54 + expect(runner).to say "Authenticating... OK"
  55 + expect(runner).to say "Switching to organization #{second_organization}... OK"
  56 + expect(runner).to say "Switching to space #{second_space}... OK"
  57 + runner.wait_for_exit
  58 + end
  59 + end
  60 + end
  61 + end
  62 +else
  63 + $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'
  64 +end
2  spec/features/v2/push_flow_spec.rb
@@ -121,5 +121,5 @@
121 121 end
122 122 end
123 123 else
124   - $stderr.puts 'Skipping integration specs; please provide $VMC_TEST_TARGET, $VMC_TEST_USER, and $VMC_TEST_PASSWORD'
  124 + $stderr.puts 'Skipping v2 integration specs; please provide $VMC_V2_TEST_TARGET, $VMC_V2_TEST_USER, and $VMC_V2_TEST_PASSWORD'
125 125 end
4 spec/features/v2/switching_targets_spec.rb
@@ -16,7 +16,7 @@
16 16
17 17 it "can switch targets, even if a target is invalid" do
18 18 run("#{vmc_bin} target invalid-target") do |runner|
19   - expect(runner).to say "target refused"
  19 + expect(runner).to say /target refused/i
20 20 runner.wait_for_exit
21 21 end
22 22
@@ -29,4 +29,4 @@
29 29 end
30 30 else
31 31 $stderr.puts 'Skipping v2 integration specs; please provide $VMC_V2_TEST_TARGET'
32   -end
  32 +end

0 comments on commit 19f2f4a

Please sign in to comment.
Something went wrong with that request. Please try again.