shelly 0.0.57 → 0.0.58

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,69 +7,56 @@ module Shelly
7
7
  include Helpers
8
8
 
9
9
  before_hook :logged_in?, :only => [:list, :add, :delete]
10
- before_hook :cloudfile_present?, :only => [:list, :add, :delete]
10
+ class_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
11
11
 
12
12
  desc "list", "List users with access to clouds defined in Cloudfile"
13
13
  def list
14
- @cloudfile = Cloudfile.new
15
- @cloudfile.clouds.each do |cloud|
16
- begin
17
- @app = App.new(cloud)
18
- say "Cloud #{cloud}:"
19
- @app.active_collaborations.each { |c| say " #{c["email"]}" }
20
- @app.inactive_collaborations.each { |c|
21
- say " #{c["email"]} (invited)" }
22
- rescue Client::NotFoundException => e
23
- raise unless e.resource == :cloud
24
- say_error "You have no access to '#{cloud}' cloud defined in Cloudfile"
25
- end
26
- end
14
+ app = multiple_clouds(options[:cloud], "list")
15
+ say "Cloud #{app}:"
16
+ app.active_collaborations.each { |c| say " #{c["email"]}" }
17
+ app.inactive_collaborations.each { |c|
18
+ say " #{c["email"]} (invited)" }
19
+ rescue Client::NotFoundException => e
20
+ raise unless e.resource == :cloud
21
+ say_error "You have no access to '#{app}' cloud defined in Cloudfile"
27
22
  end
28
23
 
29
24
  desc "add [EMAIL]", "Add new developer to clouds defined in Cloudfile"
30
25
  def add(email = nil)
31
- @cloudfile = Cloudfile.new
32
- @user = Shelly::User.new
26
+ user = Shelly::User.new
27
+ app = multiple_clouds(options[:cloud], "add")
33
28
  user_email = email || ask_for_email({:guess_email => false})
34
- @cloudfile.clouds.each do |cloud|
35
- begin
36
- @user.send_invitation(cloud, user_email)
37
- say "Sending invitation to #{user_email} to work on #{cloud}", :green
38
- rescue Client::ValidationException => e
39
- if e.errors.include?(["email", "#{email} has already been taken"])
40
- say_error "User #{email} is already in the cloud #{cloud}", :with_exit => false
41
- else
42
- e.each_error { |error| say_error error, :with_exit => false }
43
- exit 1
44
- end
45
- rescue Client::NotFoundException => e
46
- raise unless e.resource == :cloud
47
- say_error "You have no access to '#{cloud}' cloud defined in Cloudfile"
48
- end
29
+ user.send_invitation(app.to_s, user_email)
30
+ say "Sending invitation to #{user_email} to work on #{app}", :green
31
+ rescue Client::ValidationException => e
32
+ if e.errors.include?(["email", "#{email} has already been taken"])
33
+ say_error "User #{email} is already in the cloud #{app}", :with_exit => false
34
+ else
35
+ e.each_error { |error| say_error error, :with_exit => false }
36
+ exit 1
49
37
  end
38
+ rescue Client::NotFoundException => e
39
+ raise unless e.resource == :cloud
40
+ say_error "You have no access to '#{app}' cloud defined in Cloudfile"
50
41
  end
51
42
 
52
43
  desc "delete [EMAIL]", "Remove developer from clouds defined in Cloudfile"
53
44
  def delete(email = nil)
54
- @cloudfile = Cloudfile.new
55
- @user = Shelly::User.new
45
+ user = Shelly::User.new
46
+ app = multiple_clouds(options[:cloud], "delete")
56
47
  user_email = email || ask_for_email({:guess_email => false})
57
- @cloudfile.clouds.each do |cloud|
58
- begin
59
- @user.delete_collaboration(cloud, user_email)
60
- say "User #{user_email} deleted from cloud #{cloud}"
61
- rescue Client::ConflictException => e
62
- say_error e[:message]
63
- rescue Client::NotFoundException => e
64
- case e.resource
65
- when :cloud
66
- say_error "You have no access to '#{cloud}' cloud defined in Cloudfile"
67
- when :user
68
- say_error "User '#{user_email}' not found", :with_exit => false
69
- say_error "You can list users with `shelly user list`"
70
- else raise
71
- end
72
- end
48
+ user.delete_collaboration(app.to_s, user_email)
49
+ say "User #{user_email} deleted from cloud #{app}"
50
+ rescue Client::ConflictException => e
51
+ say_error e[:message]
52
+ rescue Client::NotFoundException => e
53
+ case e.resource
54
+ when :cloud
55
+ say_error "You have no access to '#{app}' cloud defined in Cloudfile"
56
+ when :user
57
+ say_error "User '#{user_email}' not found", :with_exit => false
58
+ say_error "You can list users with `shelly user list`"
59
+ else raise
73
60
  end
74
61
  end
75
62
 
@@ -27,9 +27,8 @@ module Shelly
27
27
  end
28
28
  end
29
29
 
30
- # FIXME: this should return instances of App
31
30
  def clouds
32
- @content.keys.sort
31
+ @content.keys.sort if @content
33
32
  end
34
33
 
35
34
  def yaml(hash)
@@ -83,7 +83,7 @@ module Shelly
83
83
 
84
84
  def multiple_clouds(cloud, action)
85
85
  clouds = Cloudfile.new.clouds
86
- if clouds.count > 1 && cloud.nil?
86
+ if clouds && clouds.count > 1 && cloud.nil?
87
87
  say_error "You have multiple clouds in Cloudfile.", :with_exit => false
88
88
  say "Select cloud using `shelly #{action} --cloud #{clouds.first}`"
89
89
  say "Available clouds:"
@@ -92,8 +92,16 @@ module Shelly
92
92
  end
93
93
  exit 1
94
94
  end
95
- @app = Shelly::App.new
96
- @app.code_name = cloud || clouds.first
95
+ unless Cloudfile.present? || cloud
96
+ say_error "You have to specify cloud.", :with_exit => false
97
+ say "Select cloud using `shelly #{action} --cloud CLOUD_NAME`"
98
+ invoke :list
99
+ exit 1
100
+ end
101
+
102
+ app = Shelly::App.new
103
+ app.code_name = cloud || clouds.first
104
+ app
97
105
  end
98
106
  end
99
107
  end
@@ -1,3 +1,3 @@
1
1
  module Shelly
2
- VERSION = "0.0.57"
2
+ VERSION = "0.0.58"
3
3
  end
@@ -12,6 +12,8 @@ describe Shelly::CLI::Backup do
12
12
  FileUtils.mkdir_p("/projects/foo")
13
13
  Dir.chdir("/projects/foo")
14
14
  File.open("Cloudfile", 'w') {|f| f.write("foo-staging:\n") }
15
+ @app = Shelly::App.new("foo-staging")
16
+ Shelly::App.stub(:new).and_return(@app)
15
17
  end
16
18
 
17
19
  describe "#list" do
@@ -25,8 +27,11 @@ describe Shelly::CLI::Backup do
25
27
  hooks(@backup, :list).should include(:logged_in?)
26
28
  end
27
29
 
28
- it "should ensure that Cloudfile is present" do
29
- hooks(@backup, :list).should include(:cloudfile_present?)
30
+ # multiple_clouds is tested in main_spec.rb in describe "#start" block
31
+ it "should ensure multiple_clouds check" do
32
+ @client.should_receive(:database_backups).with("foo-staging").and_return([{"filename" => "backup.postgre.tar.gz", "human_size" => "10kb", "size" => 12345}])
33
+ @backup.should_receive(:multiple_clouds).and_return(@app)
34
+ invoke(@backup, :list)
30
35
  end
31
36
 
32
37
  it "should exit if user doesn't have access to cloud in Cloudfile" do
@@ -36,30 +41,15 @@ describe Shelly::CLI::Backup do
36
41
  lambda { invoke(@backup, :list) }.should raise_error(SystemExit)
37
42
  end
38
43
 
39
- context "multiple clouds" do
40
- before do
41
- File.open("Cloudfile", 'w') {|f| f.write("foo-staging:\nfoo-production:\n") }
42
- end
43
-
44
- it "should show information to select specific cloud and exit" do
45
- $stdout.should_receive(:puts).with(red "You have multiple clouds in Cloudfile.")
46
- $stdout.should_receive(:puts).with("Select cloud using `shelly backup list --cloud foo-production`")
47
- $stdout.should_receive(:puts).with("Available clouds:")
48
- $stdout.should_receive(:puts).with(" * foo-production")
49
- $stdout.should_receive(:puts).with(" * foo-staging")
50
- lambda { invoke(@backup, :list) }.should raise_error(SystemExit)
51
- end
52
-
53
- it "should take cloud from command line for which to show backups" do
54
- @client.should_receive(:database_backups).with("foo-staging").and_return([{"filename" => "backup.postgre.tar.gz", "human_size" => "10kb", "size" => 12345},{"filename" => "backup.mongo.tar.gz", "human_size" => "22kb", "size" => 333}])
55
- $stdout.should_receive(:puts).with(green "Available backups:")
56
- $stdout.should_receive(:puts).with("\n")
57
- $stdout.should_receive(:puts).with(" Filename | Size")
58
- $stdout.should_receive(:puts).with(" backup.postgre.tar.gz | 10kb")
59
- $stdout.should_receive(:puts).with(" backup.mongo.tar.gz | 22kb")
60
- @backup.options = {:cloud => "foo-staging"}
61
- invoke(@backup, :list)
62
- end
44
+ it "should take cloud from command line for which to show backups" do
45
+ @client.should_receive(:database_backups).with("foo-staging").and_return([{"filename" => "backup.postgre.tar.gz", "human_size" => "10kb", "size" => 12345},{"filename" => "backup.mongo.tar.gz", "human_size" => "22kb", "size" => 333}])
46
+ $stdout.should_receive(:puts).with(green "Available backups:")
47
+ $stdout.should_receive(:puts).with("\n")
48
+ $stdout.should_receive(:puts).with(" Filename | Size")
49
+ $stdout.should_receive(:puts).with(" backup.postgre.tar.gz | 10kb")
50
+ $stdout.should_receive(:puts).with(" backup.mongo.tar.gz | 22kb")
51
+ @backup.options = {:cloud => "foo-staging"}
52
+ invoke(@backup, :list)
63
53
  end
64
54
 
65
55
  describe "#get" do
@@ -75,14 +65,10 @@ describe Shelly::CLI::Backup do
75
65
  hooks(@backup, :get).should include(:logged_in?)
76
66
  end
77
67
 
78
- it "should make sure that cloud is choosen" do
68
+ # multiple_clouds is tested in main_spec.rb in describe "#start" block
69
+ it "should ensure multiple_clouds check" do
79
70
  @client.should_receive(:database_backup).with("foo-staging", "last")
80
- invoke(@backup, :get)
81
- end
82
-
83
- it "should make sure that cloud is choosen" do
84
- @client.should_receive(:database_backup).with("other", "last")
85
- @backup.options = {:cloud => "other"}
71
+ @backup.should_receive(:multiple_clouds).and_return(@app)
86
72
  invoke(@backup, :get)
87
73
  end
88
74
 
@@ -140,6 +126,13 @@ describe Shelly::CLI::Backup do
140
126
  hooks(@backup, :create).should include(:logged_in?)
141
127
  end
142
128
 
129
+ # multiple_clouds is tested in main_spec.rb in describe "#start" block
130
+ it "should ensure multiple_clouds check" do
131
+ @client.stub(:request_backup)
132
+ @backup.should_receive(:multiple_clouds).and_return(@app)
133
+ invoke(@backup, :create)
134
+ end
135
+
143
136
  it "should exit if user doesn't have access to cloud in Cloudfile" do
144
137
  exception = Shelly::Client::NotFoundException.new({"resource" => "cloud"})
145
138
  @client.stub(:request_backup).and_raise(exception)
@@ -174,6 +167,15 @@ describe Shelly::CLI::Backup do
174
167
  hooks(@backup, :restore).should include(:logged_in?)
175
168
  end
176
169
 
170
+ # multiple_clouds is tested in main_spec.rb in describe "#start" block
171
+ it "should ensure multiple_clouds check" do
172
+ @client.stub(:restore_backup)
173
+ @backup.should_receive(:multiple_clouds).and_return(@app)
174
+ fake_stdin(["yes"]) do
175
+ invoke(@backup, :restore, "better.tar.gz")
176
+ end
177
+ end
178
+
177
179
  it "should restore database" do
178
180
  $stdout.should_receive(:puts).with("You are about restore database postgre for cloud foo-staging to state from better.tar.gz")
179
181
  $stdout.should_receive(:print).with("I want to restore the database (yes/no): ")
@@ -14,23 +14,23 @@ describe Shelly::CLI::Config do
14
14
  FileUtils.mkdir_p("/projects/foo")
15
15
  Dir.chdir("/projects/foo")
16
16
  @client.stub(:token).and_return("abc")
17
- File.open("Cloudfile", 'w') {|f| f.write("foo-staging:\n") }
17
+ File.open("Cloudfile", 'w') {|f| f.write("foo-production:\n") }
18
18
  FileUtils.mkdir_p("/tmp")
19
19
  Dir.stub(:tmpdir).and_return("/tmp")
20
20
  ENV["EDITOR"] = "vim"
21
+ @app = Shelly::App.new("foo-production")
21
22
  end
22
23
 
23
24
  describe "#list" do
24
- before do
25
- File.open("Cloudfile", 'w') {|f| f.write("foo-staging:\nfoo-production:\n") }
26
- end
27
-
28
25
  it "should ensure user has logged in" do
29
26
  hooks(@config, :list).should include(:logged_in?)
30
27
  end
31
28
 
32
- it "should ensure that Cloudfile is present" do
33
- hooks(@config, :list).should include(:cloudfile_present?)
29
+ # multiple_clouds is tested in main_spec.rb in describe "#start" block
30
+ it "should ensure multiple_clouds check" do
31
+ @client.should_receive(:app_configs).with("foo-production").and_return([{"created_by_user" => false, "path" => "config/app.yml"}])
32
+ @config.should_receive(:multiple_clouds).and_return(@app)
33
+ invoke(@config, :list)
34
34
  end
35
35
 
36
36
  it "should exit if user doesn't have access to cloud in Cloudfile" do
@@ -41,38 +41,30 @@ describe Shelly::CLI::Config do
41
41
  end
42
42
 
43
43
  it "should list available configuration files for clouds" do
44
- @client.should_receive(:app_configs).with("foo-staging").and_return([{"created_by_user" => true, "path" => "config/settings.yml"}])
45
44
  @client.should_receive(:app_configs).with("foo-production").and_return([{"created_by_user" => false, "path" => "config/app.yml"}])
46
45
  $stdout.should_receive(:puts).with(green "Configuration files for foo-production")
47
46
  $stdout.should_receive(:puts).with("You have no custom configuration files.")
48
47
  $stdout.should_receive(:puts).with("Following files are created by Shelly Cloud:")
49
48
  $stdout.should_receive(:puts).with(/ * \s+config\/app.yml/)
50
- $stdout.should_receive(:puts).with(green "Configuration files for foo-staging")
51
- $stdout.should_receive(:puts).with("Custom configuration files:")
52
- $stdout.should_receive(:puts).with(/ * \s+config\/settings.yml/)
53
49
 
54
50
  invoke(@config, :list)
55
51
  end
56
-
57
52
  end
58
53
 
59
54
  describe "#show" do
60
-
61
55
  it "should ensure user has logged in" do
62
56
  hooks(@config, :show).should include(:logged_in?)
63
57
  end
64
58
 
65
- it "should ensure that Cloudfile is present" do
66
- hooks(@config, :show).should include(:cloudfile_present?)
67
- end
68
-
69
- it "should exit if no path was specified" do
70
- $stdout.should_receive(:puts).with(red "No configuration file specified")
71
- lambda { invoke(@config, :show) }.should raise_error(SystemExit)
59
+ # multiple_clouds is tested in main_spec.rb in describe "#start" block
60
+ it "should ensure multiple_clouds check" do
61
+ @client.should_receive(:app_config).with("foo-production", "path").and_return({"path" => "test.rb", "content" => "example content"})
62
+ @config.should_receive(:multiple_clouds).and_return(@app)
63
+ invoke(@config, :show, "path")
72
64
  end
73
65
 
74
66
  it "should show config" do
75
- @client.should_receive(:app_config).with("foo-staging", "path").and_return({"path" => "test.rb", "content" => "example content"})
67
+ @client.should_receive(:app_config).with("foo-production", "path").and_return({"path" => "test.rb", "content" => "example content"})
76
68
  $stdout.should_receive(:puts).with(green "Content of test.rb:")
77
69
  $stdout.should_receive(:puts).with("example content")
78
70
  invoke(@config, :show, "path")
@@ -84,7 +76,7 @@ describe Shelly::CLI::Config do
84
76
  exception = Shelly::Client::NotFoundException.new("resource" => "config")
85
77
  @client.should_receive(:app_config).and_raise(exception)
86
78
  $stdout.should_receive(:puts).with(red "Config 'config/app.yml' not found")
87
- $stdout.should_receive(:puts).with(red "You can list available config files with `shelly config list --cloud foo-staging`")
79
+ $stdout.should_receive(:puts).with(red "You can list available config files with `shelly config list --cloud foo-production`")
88
80
  lambda {
89
81
  invoke(@config, :show, "config/app.yml")
90
82
  }.should raise_error(SystemExit)
@@ -95,31 +87,13 @@ describe Shelly::CLI::Config do
95
87
  it "should display error message and exit with 1" do
96
88
  exception = Shelly::Client::NotFoundException.new("resource" => "cloud")
97
89
  @client.should_receive(:app_config).and_raise(exception)
98
- $stdout.should_receive(:puts).with(red "You have no access to 'foo-staging' cloud defined in Cloudfile")
90
+ $stdout.should_receive(:puts).with(red "You have no access to 'foo-production' cloud defined in Cloudfile")
99
91
  lambda {
100
92
  invoke(@config, :show, "config/app.yml")
101
93
  }.should raise_error(SystemExit)
102
94
  end
103
95
  end
104
96
  end
105
-
106
- context "multiple clouds" do
107
- before do
108
- File.open("Cloudfile", 'w') {|f| f.write("foo-staging:\nfoo-production:\n") }
109
- end
110
-
111
- it "should show info to select cloud and exit" do
112
- $stdout.should_receive(:puts).with(red "You have multiple clouds in Cloudfile.")
113
- $stdout.should_receive(:puts).with("Select cloud using `shelly show path --cloud foo-production`")
114
- lambda { invoke(@config, :show, "path") }.should raise_error(SystemExit)
115
- end
116
-
117
- it "should use cloud specified by parameter" do
118
- @client.should_receive(:app_config).with("foo-production", "path").and_return({"path" => "test.rb", "content" => "example content"})
119
- @config.options = {:cloud => "foo-production"}
120
- invoke(@config, :show, "path")
121
- end
122
- end
123
97
  end
124
98
 
125
99
  describe "#create" do
@@ -127,13 +101,18 @@ describe Shelly::CLI::Config do
127
101
  hooks(@config, :create).should include(:logged_in?)
128
102
  end
129
103
 
130
- it "should ensure that Cloudfile is present" do
131
- hooks(@config, :create).should include(:cloudfile_present?)
104
+ it "should ensure user has logged in" do
105
+ hooks(@config, :new).should include(:logged_in?)
132
106
  end
133
107
 
134
- it "should exit if no path was specified" do
135
- $stdout.should_receive(:puts).with(red "No path specified")
136
- lambda { invoke(@config, :create) }.should raise_error(SystemExit)
108
+ # multiple_clouds is tested in main_spec.rb in describe "#start" block
109
+ it "should ensure multiple_clouds check" do
110
+ @config.should_receive(:system).with(/vim \/tmp\/shelly-edit/).and_return(true)
111
+ @app = Shelly::App.new("foo-production")
112
+ Shelly::App.stub(:new).and_return(@app)
113
+ @client.should_receive(:app_create_config).with("foo-production", "path", "\n").and_return({})
114
+ @config.should_receive(:multiple_clouds).and_return(@app)
115
+ invoke(@config, :create, "path")
137
116
  end
138
117
 
139
118
  it "should ask to set EDITOR environment variable if not set" do
@@ -144,10 +123,10 @@ describe Shelly::CLI::Config do
144
123
 
145
124
  it "should create file" do
146
125
  @config.should_receive(:system).with(/vim \/tmp\/shelly-edit/).and_return(true)
147
- @client.should_receive(:app_create_config).with("foo-staging", "path", "\n").and_return({})
126
+ @client.should_receive(:app_create_config).with("foo-production", "path", "\n").and_return({})
148
127
  $stdout.should_receive(:puts).with(green "File 'path' created.")
149
128
  $stdout.should_receive(:puts).with("To make changes to running application redeploy it using:")
150
- $stdout.should_receive(:puts).with("`shelly redeploy --cloud foo-staging`")
129
+ $stdout.should_receive(:puts).with("`shelly redeploy --cloud foo-production`")
151
130
  invoke(@config, :create, "path")
152
131
  end
153
132
 
@@ -162,26 +141,6 @@ describe Shelly::CLI::Config do
162
141
  }.should raise_error(SystemExit)
163
142
  end
164
143
  end
165
-
166
- context "multiple clouds" do
167
- before do
168
- File.open("Cloudfile", 'w') {|f| f.write("foo-staging:\nfoo-production:\n") }
169
- end
170
-
171
- it "should show info to select cloud and exit" do
172
- @config.stub(:system) {true}
173
- $stdout.should_receive(:puts).with(red "You have multiple clouds in Cloudfile.")
174
- $stdout.should_receive(:puts).with("Select cloud using `shelly create path --cloud foo-production`")
175
- lambda { @config.create("path") }.should raise_error(SystemExit)
176
- end
177
-
178
- it "should use cloud specified by parameter" do
179
- @config.should_receive(:system).with(/vim \/tmp\/shelly-edit/).and_return(true)
180
- @client.should_receive(:app_create_config).with("foo-production", "path", "\n").and_return({})
181
- @config.options = {:cloud => "foo-production"}
182
- invoke(@config, :create, "path")
183
- end
184
- end
185
144
  end
186
145
 
187
146
 
@@ -190,29 +149,33 @@ describe Shelly::CLI::Config do
190
149
  hooks(@config, :edit).should include(:logged_in?)
191
150
  end
192
151
 
193
- it "should ensure that Cloudfile is present" do
194
- hooks(@config, :edit).should include(:cloudfile_present?)
152
+ it "should ensure user has logged in" do
153
+ hooks(@config, :update).should include(:logged_in?)
195
154
  end
196
155
 
197
- it "should exit if no path was specified" do
198
- $stdout.should_receive(:puts).with(red "No configuration file specified")
199
- lambda { invoke(@config, :edit) }.should raise_error(SystemExit)
156
+ # multiple_clouds is tested in main_spec.rb in describe "#start" block
157
+ it "should ensure multiple_clouds check" do
158
+ @config.should_receive(:system).with(/vim \/tmp\/shelly-edit/).and_return(true)
159
+ @client.should_receive(:app_config).with("foo-production", "path").and_return({"path" => "test.rb", "content" => "example content"})
160
+ @client.should_receive(:app_update_config).with("foo-production", "path", "example content\n").and_return({"path" => "test.rb", "content" => "example content"})
161
+ @config.should_receive(:multiple_clouds).and_return(@app)
162
+ invoke(@config, :edit, "path")
200
163
  end
201
164
 
202
165
  it "should ask to set EDITOR environment variable if not set" do
203
- @client.should_receive(:app_config).with("foo-staging", "path").and_return({"path" => "test.rb", "content" => "example content"})
166
+ @client.should_receive(:app_config).with("foo-production", "path").and_return({"path" => "test.rb", "content" => "example content"})
204
167
  @config.stub(:system) {false}
205
168
  $stdout.should_receive(:puts).with(red "Please set EDITOR environment variable")
206
169
  lambda { invoke(@config, :edit, "path") }.should raise_error(SystemExit)
207
170
  end
208
171
 
209
172
  it "should create file" do
210
- @client.should_receive(:app_config).with("foo-staging", "path").and_return({"path" => "test.rb", "content" => "example content"})
173
+ @client.should_receive(:app_config).with("foo-production", "path").and_return({"path" => "test.rb", "content" => "example content"})
211
174
  @config.should_receive(:system).with(/vim \/tmp\/shelly-edit/).and_return(true)
212
- @client.should_receive(:app_update_config).with("foo-staging", "path", "example content\n").and_return({"path" => "test.rb", "content" => "example content"})
175
+ @client.should_receive(:app_update_config).with("foo-production", "path", "example content\n").and_return({"path" => "test.rb", "content" => "example content"})
213
176
  $stdout.should_receive(:puts).with(green "File 'test.rb' updated.")
214
177
  $stdout.should_receive(:puts).with("To make changes to running application redeploy it using:")
215
- $stdout.should_receive(:puts).with("`shelly redeploy --cloud foo-staging`")
178
+ $stdout.should_receive(:puts).with("`shelly redeploy --cloud foo-production`")
216
179
  invoke(@config, :edit, "path")
217
180
  end
218
181
 
@@ -222,7 +185,7 @@ describe Shelly::CLI::Config do
222
185
  exception = Shelly::Client::NotFoundException.new("resource" => "config")
223
186
  @client.should_receive(:app_config).and_raise(exception)
224
187
  $stdout.should_receive(:puts).with(red "Config 'config/app.yml' not found")
225
- $stdout.should_receive(:puts).with(red "You can list available config files with `shelly config list --cloud foo-staging`")
188
+ $stdout.should_receive(:puts).with(red "You can list available config files with `shelly config list --cloud foo-production`")
226
189
  lambda {
227
190
  invoke(@config, :edit, "config/app.yml")
228
191
  }.should raise_error(SystemExit)
@@ -233,7 +196,7 @@ describe Shelly::CLI::Config do
233
196
  it "should display error message and exit with 1" do
234
197
  exception = Shelly::Client::NotFoundException.new("resource" => "cloud")
235
198
  @client.should_receive(:app_config).and_raise(exception)
236
- $stdout.should_receive(:puts).with(red "You have no access to 'foo-staging' cloud defined in Cloudfile")
199
+ $stdout.should_receive(:puts).with(red "You have no access to 'foo-production' cloud defined in Cloudfile")
237
200
  lambda {
238
201
  invoke(@config, :edit, "config/app.yml")
239
202
  }.should raise_error(SystemExit)
@@ -251,27 +214,6 @@ describe Shelly::CLI::Config do
251
214
  end
252
215
  end
253
216
  end
254
-
255
- context "multiple clouds" do
256
- before do
257
- File.open("Cloudfile", 'w') {|f| f.write("foo-staging:\nfoo-production:\n") }
258
- end
259
-
260
- it "should show info to select cloud and exit" do
261
- @config.stub(:system) {true}
262
- $stdout.should_receive(:puts).with(red "You have multiple clouds in Cloudfile.")
263
- $stdout.should_receive(:puts).with("Select cloud using `shelly edit path --cloud foo-production`")
264
- lambda { invoke(@config, :edit, "path") }.should raise_error(SystemExit)
265
- end
266
-
267
- it "should use cloud specified by parameter" do
268
- @client.should_receive(:app_config).with("foo-production", "path").and_return({"path" => "test.rb", "content" => "example content"})
269
- @config.should_receive(:system).with(/vim \/tmp\/shelly-edit/).and_return(true)
270
- @client.should_receive(:app_update_config).with("foo-production", "path", "example content\n").and_return({"path" => "test.rb", "content" => "example content"})
271
- @config.options = {:cloud => "foo-production"}
272
- invoke(@config, :edit, "path")
273
- end
274
- end
275
217
  end
276
218
 
277
219
  describe "#delete" do
@@ -279,20 +221,20 @@ describe Shelly::CLI::Config do
279
221
  hooks(@config, :delete).should include(:logged_in?)
280
222
  end
281
223
 
282
- it "should ensure that Cloudfile is present" do
283
- hooks(@config, :delete).should include(:cloudfile_present?)
284
- end
285
-
286
- it "should exit if no path was specified" do
287
- $stdout.should_receive(:puts).with(red "No configuration file specified")
288
- lambda { invoke(@config, :delete) }.should raise_error(SystemExit)
224
+ # multiple_clouds is tested in main_spec.rb in describe "#start" block
225
+ it "should ensure multiple_clouds check" do
226
+ @client.should_receive(:app_delete_config).with("foo-production", "path").and_return({})
227
+ @config.should_receive(:multiple_clouds).and_return(@app)
228
+ fake_stdin(["y"]) do
229
+ invoke(@config, :delete, "path")
230
+ end
289
231
  end
290
232
 
291
233
  it "should delete configuration file" do
292
- @client.should_receive(:app_delete_config).with("foo-staging", "path").and_return({})
234
+ @client.should_receive(:app_delete_config).with("foo-production", "path").and_return({})
293
235
  $stdout.should_receive(:puts).with(green "File 'path' deleted.")
294
236
  $stdout.should_receive(:puts).with("To make changes to running application redeploy it using:")
295
- $stdout.should_receive(:puts).with("`shelly redeploy --cloud foo-staging`")
237
+ $stdout.should_receive(:puts).with("`shelly redeploy --cloud foo-production`")
296
238
  fake_stdin(["y"]) do
297
239
  invoke(@config, :delete, "path")
298
240
  end
@@ -306,36 +248,13 @@ describe Shelly::CLI::Config do
306
248
  end
307
249
  end
308
250
 
309
- context "multiple clouds" do
310
- before do
311
- File.open("Cloudfile", 'w') {|f| f.write("foo-staging:\nfoo-production:\n") }
312
- end
313
-
314
- it "should show info to select cloud and exit" do
315
- $stdout.should_receive(:puts).with(red "You have multiple clouds in Cloudfile.")
316
- $stdout.should_receive(:puts).with("Select cloud using `shelly delete path --cloud foo-production`")
317
- lambda { invoke(@config, :delete, "path") }.should raise_error(SystemExit)
318
- end
319
-
320
- it "should use cloud specified by parameter" do
321
- @client.should_receive(:app_delete_config).with("foo-production", "path").and_return({})
322
- $stdout.should_receive(:puts).with(green "File 'path' deleted.")
323
- $stdout.should_receive(:puts).with("To make changes to running application redeploy it using:")
324
- $stdout.should_receive(:puts).with("`shelly redeploy --cloud foo-production`")
325
- @config.options = {:cloud => "foo-production"}
326
- fake_stdin(["y"]) do
327
- invoke(@config, :delete, "path")
328
- end
329
- end
330
- end
331
-
332
251
  describe "on failure" do
333
252
  context "when config doesn't exist" do
334
253
  it "should display error message and exit with 1" do
335
254
  exception = Shelly::Client::NotFoundException.new("resource" => "config")
336
255
  @client.should_receive(:app_delete_config).and_raise(exception)
337
256
  $stdout.should_receive(:puts).with(red "Config 'config/app.yml' not found")
338
- $stdout.should_receive(:puts).with(red "You can list available config files with `shelly config list --cloud foo-staging`")
257
+ $stdout.should_receive(:puts).with(red "You can list available config files with `shelly config list --cloud foo-production`")
339
258
  fake_stdin(["y"]) do
340
259
  lambda {
341
260
  invoke(@config, :delete, "config/app.yml")
@@ -348,7 +267,7 @@ describe Shelly::CLI::Config do
348
267
  it "should display error message and exit with 1" do
349
268
  exception = Shelly::Client::NotFoundException.new("resource" => "cloud")
350
269
  @client.should_receive(:app_delete_config).and_raise(exception)
351
- $stdout.should_receive(:puts).with(red "You have no access to 'foo-staging' cloud defined in Cloudfile")
270
+ $stdout.should_receive(:puts).with(red "You have no access to 'foo-production' cloud defined in Cloudfile")
352
271
  fake_stdin(["y"]) do
353
272
  lambda {
354
273
  invoke(@config, :delete, "config/app.yml")
@@ -357,6 +276,5 @@ describe Shelly::CLI::Config do
357
276
  end
358
277
  end
359
278
  end
360
-
361
279
  end
362
280
  end