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.
- data/Guardfile +1 -0
- data/lib/shelly/cli/backup.rb +13 -14
- data/lib/shelly/cli/config.rb +43 -55
- data/lib/shelly/cli/deploys.rb +8 -10
- data/lib/shelly/cli/main.rb +80 -93
- data/lib/shelly/cli/user.rb +36 -49
- data/lib/shelly/cloudfile.rb +1 -2
- data/lib/shelly/helpers.rb +11 -3
- data/lib/shelly/version.rb +1 -1
- data/spec/shelly/cli/backup_spec.rb +35 -33
- data/spec/shelly/cli/config_spec.rb +53 -135
- data/spec/shelly/cli/deploys_spec.rb +20 -59
- data/spec/shelly/cli/main_spec.rb +106 -186
- data/spec/shelly/cli/user_spec.rb +23 -27
- metadata +147 -163
data/lib/shelly/cli/user.rb
CHANGED
@@ -7,69 +7,56 @@ module Shelly
|
|
7
7
|
include Helpers
|
8
8
|
|
9
9
|
before_hook :logged_in?, :only => [:list, :add, :delete]
|
10
|
-
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
32
|
-
|
26
|
+
user = Shelly::User.new
|
27
|
+
app = multiple_clouds(options[:cloud], "add")
|
33
28
|
user_email = email || ask_for_email({:guess_email => false})
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
55
|
-
|
45
|
+
user = Shelly::User.new
|
46
|
+
app = multiple_clouds(options[:cloud], "delete")
|
56
47
|
user_email = email || ask_for_email({:guess_email => false})
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|
|
data/lib/shelly/cloudfile.rb
CHANGED
data/lib/shelly/helpers.rb
CHANGED
@@ -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
|
-
|
96
|
-
|
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
|
data/lib/shelly/version.rb
CHANGED
@@ -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
|
-
|
29
|
-
|
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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
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
|
-
|
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-
|
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
|
-
|
33
|
-
|
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
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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-
|
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-
|
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-
|
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
|
131
|
-
hooks(@config, :
|
104
|
+
it "should ensure user has logged in" do
|
105
|
+
hooks(@config, :new).should include(:logged_in?)
|
132
106
|
end
|
133
107
|
|
134
|
-
|
135
|
-
|
136
|
-
|
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-
|
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-
|
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
|
194
|
-
hooks(@config, :
|
152
|
+
it "should ensure user has logged in" do
|
153
|
+
hooks(@config, :update).should include(:logged_in?)
|
195
154
|
end
|
196
155
|
|
197
|
-
|
198
|
-
|
199
|
-
|
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-
|
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-
|
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-
|
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-
|
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-
|
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-
|
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
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
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-
|
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-
|
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-
|
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-
|
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
|