webbynode 0.2.5.beta1 → 0.2.5.beta2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of webbynode might be problematic. Click here for more details.
- data/Manifest +15 -0
- data/Rakefile +1 -1
- data/lib/webbynode/attribute_accessors.rb +67 -0
- data/lib/webbynode/commands/init.rb +41 -70
- data/lib/webbynode/engines/all.rb +16 -0
- data/lib/webbynode/engines/django.rb +35 -0
- data/lib/webbynode/engines/engine.rb +67 -0
- data/lib/webbynode/engines/php.rb +6 -0
- data/lib/webbynode/engines/rack.rb +10 -0
- data/lib/webbynode/engines/rails.rb +12 -0
- data/lib/webbynode/engines/rails3.rb +61 -0
- data/lib/webbynode/io.rb +12 -1
- data/lib/webbynode.rb +9 -2
- data/spec/fixtures/settings.py +94 -0
- data/spec/webbynode/commands/init_spec.rb +213 -119
- data/spec/webbynode/engines/django_spec.rb +65 -0
- data/spec/webbynode/engines/engine_spec.rb +52 -0
- data/spec/webbynode/engines/php_spec.rb +12 -0
- data/spec/webbynode/engines/rack_spec.rb +34 -0
- data/spec/webbynode/engines/rails3_spec.rb +46 -0
- data/spec/webbynode/engines/rails_spec.rb +38 -0
- data/spec/webbynode/io_spec.rb +28 -0
- data/webbynode.gemspec +4 -4
- metadata +27 -4
@@ -5,6 +5,7 @@ describe Webbynode::Commands::Init do
|
|
5
5
|
let(:git_handler) { double("git").as_null_object }
|
6
6
|
let(:io_handler) { double("io").as_null_object }
|
7
7
|
let(:gemfile) { double("gemfile").as_null_object.tap { |g| g.stub!(:present?).and_return(false) } }
|
8
|
+
let(:api) { double("api").as_null_object }
|
8
9
|
|
9
10
|
def create_init(ip="4.3.2.1", host=nil, extra=[])
|
10
11
|
host = "--dns=#{host}" if host
|
@@ -20,44 +21,184 @@ describe Webbynode::Commands::Init do
|
|
20
21
|
git_handler.stub!(:remote_exists?).and_return(false)
|
21
22
|
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
subject do
|
25
|
+
Webbynode::Commands::Init.new.tap do |cmd|
|
26
|
+
webbies = {
|
27
|
+
'sandbox' => {
|
28
|
+
:ip => "201.81.121.201",
|
29
|
+
:status => "on",
|
30
|
+
:name => "sandbox",
|
31
|
+
:notes => "",
|
32
|
+
:plan => "Webbybeta",
|
33
|
+
:node => "miami-b15"
|
34
|
+
}
|
35
|
+
}
|
36
|
+
api.stub!(:webbies).and_return(webbies)
|
37
|
+
|
38
|
+
cmd.stub!(:git).and_return(git_handler)
|
39
|
+
cmd.stub!(:io).and_return(io_handler)
|
40
|
+
cmd.stub!(:api).and_return(api)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#detect_engine' do
|
45
|
+
before(:each) do
|
46
|
+
subject.stub!(:io).and_return(io_handler)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "calls prepare once engine is detected" do
|
50
|
+
subject.stub!(:option).with(:engine).and_return('rails')
|
51
|
+
io_handler.should_receive(:add_setting).with('engine', 'rails')
|
52
|
+
|
53
|
+
rails = double('Rails')
|
54
|
+
rails.should_receive(:prepare)
|
55
|
+
|
56
|
+
Webbynode::Engines::Rails.should_receive(:new).and_return(rails)
|
57
|
+
subject.send(:detect_engine)
|
29
58
|
end
|
30
59
|
|
60
|
+
context 'when --engine is passed' do
|
61
|
+
it "adds an engine setting" do
|
62
|
+
io_handler.should_receive(:add_setting).with('engine', 'rails')
|
63
|
+
io_handler.stub!(:add_to_git_ignore)
|
64
|
+
|
65
|
+
Webbynode::Git.stub(:new).and_return(git_handler)
|
66
|
+
|
67
|
+
subject.stub!(:option).with(:engine).and_return('rails')
|
68
|
+
subject.send(:detect_engine)
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'with invalid engine' do
|
72
|
+
it "reports the error and show engines for user to choose" do
|
73
|
+
subject.stub!(:option).with(:engine).and_return('kawaboonga')
|
74
|
+
|
75
|
+
io_handler.should_receive(:add_setting).with('engine', 'django')
|
76
|
+
io_handler.should_receive(:log).with("Engine 'kawaboonga' is invalid.")
|
77
|
+
|
78
|
+
django = stub('Django').as_null_object
|
79
|
+
django.should_receive(:engine_id).and_return('django')
|
80
|
+
|
81
|
+
subject.should_receive(:choose_engine).and_return(django)
|
82
|
+
|
83
|
+
subject.send(:detect_engine)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'Checking prerequisites' do
|
31
90
|
it "raises an error if git is not found" do
|
32
91
|
io_handler.should_receive(:exec_in_path?).with('git').and_return(false)
|
92
|
+
subject.stub!(:detect_engine).and_return(Webbynode::Engines::Rails)
|
33
93
|
lambda { subject.execute }.should raise_error(Webbynode::Command::CommandError)
|
34
94
|
end
|
35
95
|
end
|
36
96
|
|
37
|
-
context "
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
97
|
+
context "Engine validation" do
|
98
|
+
context "when there is a validation error" do
|
99
|
+
it "displays the error and exits" do
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "Engine detection" do
|
106
|
+
context "when no engine was detected" do
|
107
|
+
it "prompts for the engine" do
|
108
|
+
io_handler.should_receive(:log).with("Supported engines:")
|
109
|
+
io_handler.should_receive(:log).with(" 1. Django")
|
110
|
+
io_handler.should_receive(:log).with(" 2. PHP")
|
111
|
+
io_handler.should_receive(:log).with(" 3. Rack")
|
112
|
+
io_handler.should_receive(:log).with(" 4. Rails 2")
|
113
|
+
io_handler.should_receive(:log).with(" 5. Rails 3")
|
114
|
+
|
115
|
+
subject.should_receive(:ask).with('Select the engine your app uses:', Integer).and_return(1)
|
116
|
+
|
117
|
+
io_handler.should_receive(:add_setting).with("engine", "django")
|
118
|
+
io_handler.should_receive(:log).with("Initializing with Django engine...")
|
119
|
+
Webbynode::Engines::Django.stub!(:new).and_return(double('Django').as_null_object)
|
120
|
+
subject.run
|
121
|
+
end
|
45
122
|
end
|
46
123
|
|
124
|
+
context "when --engine is passed" do
|
125
|
+
subject do
|
126
|
+
Webbynode::Commands::Init.new("--engine=php").tap do |cmd|
|
127
|
+
webbies = {
|
128
|
+
'sandbox' => {
|
129
|
+
:ip => "201.81.121.201",
|
130
|
+
:status => "on",
|
131
|
+
:name => "sandbox",
|
132
|
+
:notes => "",
|
133
|
+
:plan => "Webbybeta",
|
134
|
+
:node => "miami-b15"
|
135
|
+
}
|
136
|
+
}
|
137
|
+
api.stub!(:webbies).and_return(webbies)
|
138
|
+
|
139
|
+
cmd.stub!(:git).and_return(git_handler)
|
140
|
+
cmd.stub!(:io).and_return(io_handler)
|
141
|
+
cmd.stub!(:api).and_return(api)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
it "overrides detection" do
|
146
|
+
io_handler.should_receive(:log).with(/Engine '.*' is invalid/).never
|
147
|
+
io_handler.should_receive(:file_exists?).with("script/rails").never
|
148
|
+
io_handler.should_receive(:add_setting).with("engine", "php")
|
149
|
+
|
150
|
+
subject.run
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
it "detects Rails 3 when script/rails is present" do
|
155
|
+
io = double("Io").as_null_object
|
156
|
+
io.stub!(:file_exists?).with("script/rails").and_return(true)
|
157
|
+
|
158
|
+
gemfile = double("Gemfile").as_null_object
|
159
|
+
gemfile.stub!(:present?).and_return(false)
|
160
|
+
|
161
|
+
Webbynode::Gemfile.stub(:new).and_return(gemfile)
|
162
|
+
|
163
|
+
Webbynode::Io.stub(:new).and_return(io)
|
164
|
+
io_handler.should_receive(:add_setting).with("engine", "rails3")
|
165
|
+
|
166
|
+
subject.run
|
167
|
+
end
|
168
|
+
|
169
|
+
it "detects Rails 2 when app app/controllers and config/environent.rb are found" do
|
170
|
+
io = double("Io").as_null_object
|
171
|
+
io.stub(:file_exists?).with("script/rails").and_return(false)
|
172
|
+
io.stub(:directory?).with('app').and_return(true)
|
173
|
+
io.stub(:directory?).with('app/controllers').and_return(true)
|
174
|
+
io.stub(:file_exists?).with('config/environent.rb').and_return(true)
|
175
|
+
|
176
|
+
Webbynode::Io.stub(:new).and_return(io)
|
177
|
+
Webbynode::Git.stub(:new).and_return(git_handler)
|
178
|
+
io_handler.should_receive(:add_setting).with("engine", "rails")
|
179
|
+
|
180
|
+
subject.run
|
181
|
+
end
|
182
|
+
|
183
|
+
it "detects Rack when config.ru is found" do
|
184
|
+
io = double("Io")
|
185
|
+
io.stub!(:file_exists?).with("script/rails").and_return(false)
|
186
|
+
io.stub!(:directory?).with('app').and_return(false)
|
187
|
+
io.stub!(:file_exists?).with('config.ru').and_return(true)
|
188
|
+
|
189
|
+
Webbynode::Io.stub!(:new).and_return(io)
|
190
|
+
|
191
|
+
io_handler.should_receive(:add_setting).with("engine", "rack")
|
192
|
+
|
193
|
+
subject.run
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
context "Deployment webby" do
|
47
198
|
it "is detected automatically if user only have one Webby" do
|
48
|
-
webbies = {
|
49
|
-
'sandbox' => {
|
50
|
-
:ip => "201.81.121.201",
|
51
|
-
:status => "on",
|
52
|
-
:name => "sandbox",
|
53
|
-
:notes => "",
|
54
|
-
:plan => "Webbybeta",
|
55
|
-
:node => "miami-b15"
|
56
|
-
}
|
57
|
-
}
|
58
|
-
api.should_receive(:webbies).and_return(webbies)
|
59
199
|
git_handler.should_receive(:add_remote).with("webbynode", "201.81.121.201", anything())
|
60
200
|
|
201
|
+
subject.stub!(:detect_engine).and_return(Webbynode::Engines::Rails)
|
61
202
|
subject.run
|
62
203
|
end
|
63
204
|
|
@@ -89,66 +230,45 @@ describe Webbynode::Commands::Init do
|
|
89
230
|
}
|
90
231
|
}
|
91
232
|
api.should_receive(:webbies).and_return(webbies)
|
92
|
-
io_handler.should_receive(:log).with("Current Webbies in your account:"
|
93
|
-
io_handler.should_receive(:log).with(" 1. sandbox (201.81.121.201)"
|
94
|
-
io_handler.should_receive(:log).with(" 2. webby2 (67.53.31.2)"
|
95
|
-
io_handler.should_receive(:log).with(" 3. webby3 (67.53.31.3)"
|
233
|
+
io_handler.should_receive(:log).with("Current Webbies in your account:")
|
234
|
+
io_handler.should_receive(:log).with(" 1. sandbox (201.81.121.201)")
|
235
|
+
io_handler.should_receive(:log).with(" 2. webby2 (67.53.31.2)")
|
236
|
+
io_handler.should_receive(:log).with(" 3. webby3 (67.53.31.3)")
|
96
237
|
subject.should_receive(:ask).with("Which Webby do you want to deploy to:", Integer).and_return(2)
|
97
238
|
|
98
|
-
io_handler.should_receive(:log).with("Set deployment Webby to webby2."
|
239
|
+
io_handler.should_receive(:log).with("Set deployment Webby to webby2.")
|
99
240
|
git_handler.should_receive(:add_remote).with("webbynode", "67.53.31.2", anything())
|
100
241
|
|
242
|
+
subject.stub!(:detect_engine).and_return(Webbynode::Engines::Rails)
|
101
243
|
subject.run
|
102
244
|
end
|
103
245
|
end
|
104
246
|
|
105
|
-
context "
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
lambda { @command.execute }.should raise_error(Webbynode::Command::CommandError)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
context "Rails3 auto detection" do
|
117
|
-
context "when script/rails is present" do
|
118
|
-
it "makes engine=rails3 implicitly" do
|
119
|
-
io_handler.stub!(:file_exists?).with("script/rails").and_return(true)
|
120
|
-
io_handler.should_receive(:add_setting).with("engine", "rails3")
|
121
|
-
|
122
|
-
@command.run
|
247
|
+
context "when already initialized" do
|
248
|
+
subject do
|
249
|
+
Webbynode::Commands::Init.new("10.0.1.1").tap do |cmd|
|
250
|
+
cmd.stub!(:gemfile).and_return(gemfile)
|
251
|
+
cmd.stub!(:detect_engine).and_return(Webbynode::Engines::Rails)
|
252
|
+
cmd.stub!(:git).and_return(git_handler)
|
123
253
|
end
|
124
254
|
end
|
125
|
-
|
126
|
-
|
127
|
-
context "when already initialized" do
|
255
|
+
|
128
256
|
it "keep the same remotes when answer is no to overwriting" do
|
129
|
-
command = Webbynode::Commands::Init.new("10.0.1.1")
|
130
|
-
command.stub!(:gemfile).and_return(gemfile)
|
131
|
-
command.should_receive(:git).any_number_of_times.and_return(git_handler)
|
132
|
-
command.should_receive(:ask).with("Do you want to overwrite the current settings (y/n)?").once.ordered.and_return("n")
|
133
|
-
|
134
257
|
git_handler.should_receive(:present?).and_return(true)
|
135
258
|
git_handler.should_receive(:remote_exists?).with("webbynode").and_return(true)
|
136
259
|
git_handler.should_receive(:delete_remote).with("webbynode").never
|
137
260
|
|
138
|
-
|
261
|
+
subject.should_receive(:ask).with("Do you want to overwrite the current settings (y/n)?").once.ordered.and_return("n")
|
262
|
+
subject.run
|
139
263
|
end
|
140
264
|
|
141
265
|
it "delete webbynode remote when answer is yes to overwriting" do
|
142
|
-
command = Webbynode::Commands::Init.new("10.0.1.1")
|
143
|
-
command.stub!(:gemfile).and_return(gemfile)
|
144
|
-
command.should_receive(:git).any_number_of_times.and_return(git_handler)
|
145
|
-
command.should_receive(:ask).with("Do you want to overwrite the current settings (y/n)?").once.ordered.and_return("y")
|
146
|
-
|
147
266
|
git_handler.should_receive(:present?).and_return(true)
|
148
267
|
git_handler.should_receive(:remote_exists?).with("webbynode").and_return(true)
|
149
268
|
git_handler.should_receive(:delete_remote).with("webbynode")
|
150
269
|
|
151
|
-
|
270
|
+
subject.should_receive(:ask).with("Do you want to overwrite the current settings (y/n)?").once.ordered.and_return("y")
|
271
|
+
subject.run
|
152
272
|
end
|
153
273
|
end
|
154
274
|
|
@@ -171,9 +291,10 @@ describe Webbynode::Commands::Init do
|
|
171
291
|
def create_init(ip="4.3.2.1", host=nil, extra=[])
|
172
292
|
@command = Webbynode::Commands::Init.new(ip, "--dns=#{host}", *extra)
|
173
293
|
@command.stub!(:gemfile).and_return(gemfile)
|
174
|
-
@command.
|
294
|
+
@command.stub!(:git).and_return(git_handler)
|
295
|
+
@command.stub!(:detect_engine).and_return(Webbynode::Engines::Rails)
|
175
296
|
end
|
176
|
-
|
297
|
+
|
177
298
|
it "should setup DNS using Webbynode API" do
|
178
299
|
create_init("10.0.1.1", "new.rubyista.info", "--adddns")
|
179
300
|
|
@@ -267,6 +388,7 @@ describe Webbynode::Commands::Init do
|
|
267
388
|
props.stub(:save)
|
268
389
|
|
269
390
|
create_init("my_webby_name")
|
391
|
+
@command.stub!(:detect_engine).and_return(Webbynode::Engines::Rails)
|
270
392
|
@command.api.should_receive(:io).any_number_of_times.and_return(io_handler)
|
271
393
|
@command.api.should_receive(:ask).with("API token: ").and_return("234def")
|
272
394
|
@command.api.should_receive(:ask).with("Login email: ").and_return("abc123")
|
@@ -289,6 +411,7 @@ describe Webbynode::Commands::Init do
|
|
289
411
|
create_init("my_webby_name")
|
290
412
|
|
291
413
|
@command.api.should_receive(:ip_for).and_raise(Webbynode::ApiClient::Unauthorized)
|
414
|
+
@command.stub!(:detect_engine).and_return(Webbynode::Engines::Rails)
|
292
415
|
@command.run
|
293
416
|
|
294
417
|
stdout.should =~ /Your credentials didn't match any Webbynode account./
|
@@ -306,6 +429,7 @@ describe Webbynode::Commands::Init do
|
|
306
429
|
|
307
430
|
create_init("my_webby_name")
|
308
431
|
@command.should_receive(:api).any_number_of_times.and_return(api)
|
432
|
+
@command.stub!(:detect_engine).and_return(Webbynode::Engines::Rails)
|
309
433
|
@command.run
|
310
434
|
|
311
435
|
stdout.should =~ /Couldn't find Webby 'my_webby_name' on your account. Your Webbies are/
|
@@ -323,6 +447,7 @@ describe Webbynode::Commands::Init do
|
|
323
447
|
|
324
448
|
create_init("my_webby_name")
|
325
449
|
@command.should_receive(:api).any_number_of_times.and_return(api)
|
450
|
+
@command.stub!(:detect_engine).and_return(Webbynode::Engines::Rails)
|
326
451
|
@command.run
|
327
452
|
|
328
453
|
stdout.should =~ /You don't have any active Webbies on your account./
|
@@ -339,6 +464,7 @@ describe Webbynode::Commands::Init do
|
|
339
464
|
|
340
465
|
create_init("my_webby_name")
|
341
466
|
@command.stub!(:api).and_return(api)
|
467
|
+
@command.stub!(:detect_engine).and_return(Webbynode::Engines::Rails)
|
342
468
|
@command.run
|
343
469
|
end
|
344
470
|
|
@@ -348,6 +474,7 @@ describe Webbynode::Commands::Init do
|
|
348
474
|
io_handler.should_receive(:app_name).any_number_of_times.and_return("application_name")
|
349
475
|
io_handler.should_receive(:create_file).with(".pushand", "#! /bin/bash\nphd $0 application_name application_name\n", true)
|
350
476
|
|
477
|
+
@command.stub!(:detect_engine).and_return(Webbynode::Engines::Rails)
|
351
478
|
@command.run
|
352
479
|
end
|
353
480
|
|
@@ -358,65 +485,16 @@ describe Webbynode::Commands::Init do
|
|
358
485
|
io_handler.should_receive(:app_name).any_number_of_times.and_return("application_name")
|
359
486
|
io_handler.should_receive(:create_file).with(".pushand", "#! /bin/bash\nphd $0 application_name my.com.br\n", true)
|
360
487
|
|
361
|
-
@command.
|
362
|
-
end
|
363
|
-
end
|
364
|
-
|
365
|
-
context "when .gitignore is not present" do
|
366
|
-
it "should create the standard .gitignore" do
|
367
|
-
io_handler.should_receive(:file_exists?).with(".gitignore").and_return(false)
|
368
|
-
git_handler.should_receive(:add_git_ignore)
|
369
|
-
|
370
|
-
@command.run
|
371
|
-
end
|
372
|
-
end
|
373
|
-
|
374
|
-
context "when .gitignore is present" do
|
375
|
-
context "when config/database.yml is already tracked by git" do
|
376
|
-
it "stops tracking config/database.yml" do
|
377
|
-
git_handler.should_receive(:tracks?).with("config/database.yml").and_return(true)
|
378
|
-
git_handler.should_receive(:remove).with("config/database.yml")
|
379
|
-
|
380
|
-
@command.run
|
381
|
-
end
|
382
|
-
end
|
383
|
-
|
384
|
-
context "when config/database.yml is not tracked by git" do
|
385
|
-
it "doesn't stop tracking config/database.yml" do
|
386
|
-
git_handler.should_receive(:tracks?).with("config/database.yml").and_return(false)
|
387
|
-
git_handler.should_receive(:remove).with("config/database.yml").never
|
388
|
-
|
389
|
-
@command.run
|
390
|
-
end
|
391
|
-
end
|
392
|
-
|
393
|
-
context "when db/schema.rb is already tracked by git" do
|
394
|
-
it "stops tracking db/schema.rb" do
|
395
|
-
git_handler.should_receive(:tracks?).with("db/schema.rb").and_return(true)
|
396
|
-
git_handler.should_receive(:remove).with("db/schema.rb")
|
397
|
-
|
398
|
-
@command.run
|
399
|
-
end
|
400
|
-
end
|
401
|
-
|
402
|
-
context "when db/schema.rb is not tracked by git" do
|
403
|
-
it "doesn't stop tracking db/schema.rb" do
|
404
|
-
git_handler.should_receive(:tracks?).with("db/schema.rb").and_return(false)
|
405
|
-
git_handler.should_receive(:remove).with("db/schema.rb").never
|
406
|
-
|
407
|
-
@command.run
|
408
|
-
end
|
409
|
-
end
|
410
|
-
|
411
|
-
it "adds config/database.yml to .gitconfig" do
|
412
|
-
io_handler.should_receive(:file_exists?).with(".gitignore").and_return(true)
|
413
|
-
git_handler.should_receive(:add_to_git_ignore).with("config/database.yml", "db/schema.rb")
|
414
|
-
|
488
|
+
@command.stub!(:detect_engine).and_return(Webbynode::Engines::Rails)
|
415
489
|
@command.run
|
416
490
|
end
|
417
491
|
end
|
418
492
|
|
419
493
|
context "when .webbynode is not present" do
|
494
|
+
before(:each) do
|
495
|
+
@command.stub!(:detect_engine).and_return(Webbynode::Engines::Rails)
|
496
|
+
end
|
497
|
+
|
420
498
|
it "should create the .webbynode system folder and stub files" do
|
421
499
|
io_handler.should_receive(:directory?).with(".webbynode").and_return(false)
|
422
500
|
io_handler.should_receive(:mkdir).with(".webbynode/tasks")
|
@@ -429,6 +507,10 @@ describe Webbynode::Commands::Init do
|
|
429
507
|
end
|
430
508
|
|
431
509
|
context "when .pushand is not present" do
|
510
|
+
before(:each) do
|
511
|
+
@command.stub!(:detect_engine).and_return(Webbynode::Engines::Rails)
|
512
|
+
end
|
513
|
+
|
432
514
|
it "should be created and made an executable" do
|
433
515
|
io_handler.should_receive(:file_exists?).with(".pushand").and_return(false)
|
434
516
|
io_handler.should_receive(:app_name).any_number_of_times.and_return("mah_app")
|
@@ -439,6 +521,10 @@ describe Webbynode::Commands::Init do
|
|
439
521
|
end
|
440
522
|
|
441
523
|
context "when .pushand is present" do
|
524
|
+
before(:each) do
|
525
|
+
@command.stub!(:detect_engine).and_return(Webbynode::Engines::Rails)
|
526
|
+
end
|
527
|
+
|
442
528
|
it "should not be created" do
|
443
529
|
io_handler.should_receive(:file_exists?).with(".pushand").and_return(true)
|
444
530
|
io_handler.should_receive(:create_file).never
|
@@ -448,6 +534,10 @@ describe Webbynode::Commands::Init do
|
|
448
534
|
end
|
449
535
|
|
450
536
|
context "when git repo doesn't exist yet" do
|
537
|
+
before(:each) do
|
538
|
+
@command.stub!(:detect_engine).and_return(Webbynode::Engines::Rails)
|
539
|
+
end
|
540
|
+
|
451
541
|
it "should create a new git repo" do
|
452
542
|
git_handler.should_receive(:present?).and_return(false)
|
453
543
|
git_handler.should_receive(:init)
|
@@ -486,6 +576,10 @@ describe Webbynode::Commands::Init do
|
|
486
576
|
end
|
487
577
|
|
488
578
|
context "when git repo is initialized" do
|
579
|
+
before(:each) do
|
580
|
+
@command.stub!(:detect_engine).and_return(Webbynode::Engines::Rails)
|
581
|
+
end
|
582
|
+
|
489
583
|
it "complains if git is in a dirty state" do
|
490
584
|
git_handler.should_receive(:present?).and_return(true)
|
491
585
|
git_handler.should_receive(:clean?).and_return(false)
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# Load Spec Helper
|
2
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), '../..', 'spec_helper')
|
3
|
+
|
4
|
+
describe Webbynode::Engines::Django do
|
5
|
+
describe 'class methods' do
|
6
|
+
subject { Webbynode::Engines::Django }
|
7
|
+
|
8
|
+
its(:engine_id) { should == 'django' }
|
9
|
+
its(:engine_name) { should == 'Django' }
|
10
|
+
its(:git_excluded) { should == ['settings.py', '*.pyc', '*.pyo', 'docs/_build'] }
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:io) { double('Io') }
|
14
|
+
before(:each) { subject.stub!(:io).and_return(io) }
|
15
|
+
|
16
|
+
describe '#change_settings' do
|
17
|
+
it "calls sed to change" do
|
18
|
+
io.should_receive(:sed).with('settings.template.py', /'ENGINE': '[^ ,]*'/, "'ENGINE': 'engine'")
|
19
|
+
io.should_receive(:sed).with('settings.template.py', /'NAME': '[^ ,]*'/, "'NAME': 'name'")
|
20
|
+
subject.change_settings({
|
21
|
+
'NAME' => 'name',
|
22
|
+
'ENGINE' => 'engine'
|
23
|
+
})
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#change_templates' do
|
28
|
+
it "calls sed to change" do
|
29
|
+
io.should_receive(:sed).with('settings.template.py', /TEMPLATE_DIRS = \(/, "TEMPLATE_DIRS = (\n '@app_dir@/templates'")
|
30
|
+
subject.change_templates
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#prepare' do
|
35
|
+
context "when settings.template.py doesn't exist" do
|
36
|
+
it "creates settings.template.py based on settings.py" do
|
37
|
+
io.should_receive(:file_exists?).with('settings.template.py').and_return(false)
|
38
|
+
io.should_receive(:copy_file).with('settings.py', 'settings.template.py')
|
39
|
+
io.should_receive(:log).with('Creating settings.template.py from your settings.py...')
|
40
|
+
|
41
|
+
subject.should_receive(:change_templates)
|
42
|
+
subject.should_receive(:change_settings).with({
|
43
|
+
'ENGINE' => '@app_engine@',
|
44
|
+
'NAME' => '@app_name@',
|
45
|
+
'USER' => '@app_name@',
|
46
|
+
'PASSWORD' => '@app_pwd@',
|
47
|
+
'HOST' => '@db_host@',
|
48
|
+
'PORT' => '@db_port@',
|
49
|
+
})
|
50
|
+
subject.prepare
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "when settings.template.py exists" do
|
55
|
+
it "doesn't do anything" do
|
56
|
+
io.should_receive(:log).never
|
57
|
+
io.should_receive(:file_exists?).with('settings.template.py').and_return(true)
|
58
|
+
io.should_receive(:copy_file).never
|
59
|
+
subject.should_receive(:change_settings).never
|
60
|
+
subject.should_receive(:change_templates).never
|
61
|
+
subject.prepare
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# Load Spec Helper
|
2
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), '../..', 'spec_helper')
|
3
|
+
|
4
|
+
describe Webbynode::Engines do
|
5
|
+
subject { Webbynode::Engines }
|
6
|
+
describe '#find' do
|
7
|
+
it "returns the proper engine, by engine_name" do
|
8
|
+
subject.find('rails').should == Webbynode::Engines::Rails
|
9
|
+
subject.find('rails3').should == Webbynode::Engines::Rails3
|
10
|
+
subject.find('django').should == Webbynode::Engines::Django
|
11
|
+
subject.find('rack').should == Webbynode::Engines::Rack
|
12
|
+
subject.find('php').should == Webbynode::Engines::Php
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe Webbynode::Engines::Engine do
|
18
|
+
let(:git) { double("Git") }
|
19
|
+
subject do
|
20
|
+
Class.new.tap do |c|
|
21
|
+
c.send(:include, Webbynode::Engines::Engine)
|
22
|
+
c.git_excludes "config/database.yml", "db/schema.rb"
|
23
|
+
end.new.tap do |obj|
|
24
|
+
obj.stub!(:git).and_return(git)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#prepare' do
|
29
|
+
it "add nontracked entries to .gitingore" do
|
30
|
+
git.should_receive(:remove).never
|
31
|
+
git.should_receive(:add_to_git_ignore).with("config/database.yml")
|
32
|
+
git.should_receive(:add_to_git_ignore).with("db/schema.rb")
|
33
|
+
|
34
|
+
git.stub!(:tracks?).with("config/database.yml").and_return(false)
|
35
|
+
git.stub!(:tracks?).with("db/schema.rb").and_return(false)
|
36
|
+
|
37
|
+
subject.prepare
|
38
|
+
end
|
39
|
+
|
40
|
+
it "remove tracked entries and add them to .gitingore" do
|
41
|
+
git.should_receive(:remove).with('config/database.yml')
|
42
|
+
git.should_receive(:remove).with('db/schema.rb').never
|
43
|
+
git.should_receive(:add_to_git_ignore).with("config/database.yml")
|
44
|
+
git.should_receive(:add_to_git_ignore).with("db/schema.rb")
|
45
|
+
|
46
|
+
git.stub!(:tracks?).with("config/database.yml").and_return(true)
|
47
|
+
git.stub!(:tracks?).with("db/schema.rb").and_return(false)
|
48
|
+
|
49
|
+
subject.prepare
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# Load Spec Helper
|
2
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), '../..', 'spec_helper')
|
3
|
+
|
4
|
+
describe Webbynode::Engines::Php do
|
5
|
+
describe 'class methods' do
|
6
|
+
subject { Webbynode::Engines::Php }
|
7
|
+
|
8
|
+
its(:engine_id) { should == 'php' }
|
9
|
+
its(:engine_name) { should == 'PHP' }
|
10
|
+
its(:git_excluded) { should be_empty }
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Load Spec Helper
|
2
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), '../..', 'spec_helper')
|
3
|
+
|
4
|
+
describe Webbynode::Engines::Rack do
|
5
|
+
let(:io) { double("io").as_null_object }
|
6
|
+
|
7
|
+
subject do
|
8
|
+
Webbynode::Engines::Rack.new.tap do |engine|
|
9
|
+
engine.stub!(:io).and_return(io)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'class methods' do
|
14
|
+
subject { Webbynode::Engines::Rack }
|
15
|
+
|
16
|
+
its(:engine_id) { should == 'rack' }
|
17
|
+
its(:engine_name) { should == 'Rack' }
|
18
|
+
its(:git_excluded) { should be_empty }
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#detect' do
|
22
|
+
it "if script/rails exists" do
|
23
|
+
io.stub!(:file_exists?).with('config.ru').and_return(true)
|
24
|
+
|
25
|
+
subject.should be_detected
|
26
|
+
end
|
27
|
+
|
28
|
+
it "fails if script/rails doesn't exist" do
|
29
|
+
io.stub!(:file_exists?).with('config.ru').and_return(false)
|
30
|
+
|
31
|
+
subject.should_not be_detected
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Load Spec Helper
|
2
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), '../..', 'spec_helper')
|
3
|
+
|
4
|
+
describe Webbynode::Engines::Rails3 do
|
5
|
+
let(:io) { double("io").as_null_object }
|
6
|
+
|
7
|
+
subject do
|
8
|
+
Webbynode::Engines::Rails3.new.tap do |engine|
|
9
|
+
engine.stub!(:io).and_return(io)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'class methods' do
|
14
|
+
subject { Webbynode::Engines::Rails3 }
|
15
|
+
|
16
|
+
its(:engine_id) { should == 'rails3' }
|
17
|
+
its(:engine_name) { should == 'Rails 3' }
|
18
|
+
its(:git_excluded) { should == ["config/database.yml", "db/schema.rb"] }
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#prepare' do
|
22
|
+
let(:gemfile) { double('gemfile').as_null_object }
|
23
|
+
|
24
|
+
it "complains if there is a sqlite3-ruby dependency outside of development and test groups in Gemspec" do
|
25
|
+
gemfile.should_receive(:present?).and_return(true)
|
26
|
+
gemfile.should_receive(:dependencies).and_return(['sqlite3-ruby', 'mysql'])
|
27
|
+
|
28
|
+
subject.stub!(:gemfile).and_return(gemfile)
|
29
|
+
lambda { subject.prepare }.should raise_error(Webbynode::Command::CommandError)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#detect' do
|
34
|
+
it "if script/rails exists" do
|
35
|
+
io.stub!(:file_exists?).with('script/rails').and_return(true)
|
36
|
+
|
37
|
+
subject.should be_detected
|
38
|
+
end
|
39
|
+
|
40
|
+
it "fails if script/rails doesn't exist" do
|
41
|
+
io.stub!(:file_exists?).with('script/rails').and_return(false)
|
42
|
+
|
43
|
+
subject.should_not be_detected
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|