jumpstart 0.3.9 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :jumpstart_version_major: 0
3
- :jumpstart_version_minor: 3
4
- :jumpstart_version_patch: 9
3
+ :jumpstart_version_minor: 4
4
+ :jumpstart_version_patch: 0
@@ -119,13 +119,22 @@ module JumpStart::FileTools
119
119
  # e.g. You might call the method with something like: FileUtils.replace_strings(target_file, :name => "Ian", :country => "England")
120
120
  # ... and in the template it would look like this:
121
121
  # Hello there NAME from COUNTRY
122
+ # Will also replace strings present in the target_file path. so if the method call looked like: FileUtils.replace_strings(target_file, :name => "Ian", :country => "England")
123
+ # and target_file was: /Users/name/Sites/country the strings matching NAME and COUNTRY inside the file would be swapped out and then a new file at the path: /Users/Ian/Sites/England would be created and populated with the contents. The file at the previous path would be deleted.
122
124
  def replace_strings(target_file, args)
123
- txt = IO.read(target_file)
124
- args.each do |x, y|
125
- txt.gsub!(/#{x.to_s.upcase}/, y)
126
- end
127
- File.open(target_file, "w") do |file|
128
- file.puts txt
125
+ if File.file?(target_file)
126
+ txt = IO.read(target_file)
127
+ new_file = target_file.dup
128
+ args.each do |x, y|
129
+ txt.gsub!(/#{x.to_s.upcase}/, y)
130
+ new_file.gsub!(/#{x.to_s.downcase}/, y)
131
+ end
132
+ dir = new_file.sub(/\/\w+\.*\w*$/, '')
133
+ FileUtils.mkdir_p(dir)
134
+ FileUtils.rm(target_file)
135
+ File.open(new_file, "w") do |file|
136
+ file.puts txt
137
+ end
129
138
  end
130
139
  end
131
140
 
@@ -233,25 +233,68 @@ class TestJumpstartFileTools < Test::Unit::TestCase
233
233
  end
234
234
 
235
235
  context "Testing JumpStart::FileUtils#replace_strings class method.\n" do
236
-
236
+
237
237
  setup do
238
- @target_file = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/config_capistrano_test.rb"
239
- @app_name = "test_project"
240
- @remote_server = "my_test_remote_server"
238
+ @target_file_1 = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/config_capistrano_test.rb"
239
+ @target_file_2 = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/replace_strings_test_app_name.rb"
240
+ @target_file_3 = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/app_name/app_name_replace_strings_test.txt"
241
+ @new_file_2 = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/replace_strings_test_bungle.rb"
242
+ @new_file_3 = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/bungle/bungle_replace_strings_test.txt"
243
+ @target_files = []
244
+ @target_files << @target_file_1 << @target_file_2 << @target_file_3
241
245
  @source_file = IO.readlines("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/config_capistrano_source.rb")
242
- File.open(@target_file, 'w+') do |file|
243
- file.puts @source_file
246
+ @target_files.each do |x|
247
+ File.open(x, 'w+') do |file|
248
+ file.puts @source_file
249
+ end
250
+ end
251
+ end
252
+
253
+ teardown do
254
+ FileUtils.remove_files(@target_files)
255
+ if File.exists?(@new_file_2)
256
+ FileUtils.remove_file(@new_file_2)
257
+ end
258
+ if File.directory?("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/bungle")
259
+ FileUtils.remove_dir("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/bungle")
244
260
  end
245
261
  end
246
262
 
247
- should "replace strings with replace_strings method" do
248
- FileUtils.replace_strings(@target_file, :app_name => 'test_app', :REMOTE_SERVER => 'remote_box')
249
- file = IO.readlines(@target_file)
263
+ should "replace strings with replace_strings method if the path does not contain the replacement strings and only one replacement string is provided" do
264
+ FileUtils.replace_strings(@target_file_1, :app_name => 'test_app')
265
+ file = IO.readlines(@target_file_1)
266
+ assert_equal "set :application, 'test_app'\n", file[0]
267
+ assert_equal "run \"\#{sudo} nginx_auto_config /usr/local/bin/nginx.remote.conf /opt/nginx/conf/nginx.conf test_app\"\n", file[44]
268
+ end
269
+
270
+ should "replace strings with replace_strings method if the path does not contain the replacement strings and more than one replacement string is provided" do
271
+ FileUtils.replace_strings(@target_file_1, :app_name => 'test_app', :REMOTE_SERVER => 'remote_box')
272
+ file = IO.readlines(@target_file_1)
250
273
  assert_equal "set :application, 'test_app'\n", file[0]
251
274
  assert_equal "set :domain, 'remote_box'\n", file[1]
252
275
  assert_equal "run \"\#{sudo} nginx_auto_config /usr/local/bin/nginx.remote.conf /opt/nginx/conf/nginx.conf test_app\"\n", file[44]
253
276
  end
254
-
277
+
278
+ should "replace strings inside the target path if the target is a file and there is more than one argument." do
279
+ FileUtils.replace_strings(@target_file_2, :app_name => 'bungle', :remote_server => 'boxy')
280
+ file = IO.readlines(@new_file_2)
281
+ assert_equal "set :application, 'bungle'\n", file[0]
282
+ assert_equal "set :domain, 'boxy'\n", file[1]
283
+ assert_equal "run \"\#{sudo} nginx_auto_config /usr/local/bin/nginx.remote.conf /opt/nginx/conf/nginx.conf bungle\"\n", file[44]
284
+ assert File.exists?(@new_file_2)
285
+ assert !File.exists?(@target_file_2)
286
+ end
287
+
288
+ should "replace strings inside the target path if the target is a file and there is more than one argument and the replacement string is found in the directory structure." do
289
+ FileUtils.replace_strings(@target_file_3, :app_name => 'bungle', :remote_server => 'boxy')
290
+ file = IO.readlines(@new_file_3)
291
+ assert_equal "set :application, 'bungle'\n", file[0]
292
+ assert_equal "set :domain, 'boxy'\n", file[1]
293
+ assert_equal "run \"\#{sudo} nginx_auto_config /usr/local/bin/nginx.remote.conf /opt/nginx/conf/nginx.conf bungle\"\n", file[44]
294
+ assert File.exists?(@new_file_3)
295
+ assert !File.exists?(@target_file_3)
296
+ end
297
+
255
298
  end
256
299
 
257
300
  context "Testing JumpStart::FileUtils#check_source_type class method.\n" do
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 3
8
- - 9
9
- version: 0.3.9
7
+ - 4
8
+ - 0
9
+ version: 0.4.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ian Alexander Wood (i0n)
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-02 00:00:00 +01:00
17
+ date: 2010-06-03 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -88,7 +88,6 @@ files:
88
88
  - test/test_jumpstart_templates/test_fileutils/check_source_type
89
89
  - test/test_jumpstart_templates/test_fileutils/check_source_type.txt
90
90
  - test/test_jumpstart_templates/test_fileutils/config_capistrano_source.rb
91
- - test/test_jumpstart_templates/test_fileutils/config_capistrano_test.rb
92
91
  - test/test_jumpstart_templates/test_fileutils/config_nginx_source.txt
93
92
  - test/test_jumpstart_templates/test_fileutils/config_nginx_test.txt
94
93
  - test/test_jumpstart_templates/test_fileutils/hosts_test
@@ -1,62 +0,0 @@
1
- set :application, 'test_app'
2
- set :domain, 'remote_box'
3
- set :user, 'i0n'
4
-
5
- set :repository, "#{user}@#{domain}:/home/#{user}/git/#{application}.git"
6
-
7
- role :app, domain # This may be the same as the `Web` server
8
- role :web, domain # Your HTTP server, Apache/etc
9
- role :db, domain , :primary => true # This is where Rails migrations will run
10
-
11
- set :scm_verbose, true
12
-
13
- set :scm, :git
14
- set :scm_username, user
15
- set :runner, user
16
- set :use_sudo, false
17
- set :branch, "master"
18
- set :deploy_via, :checkout
19
- set :git_shallow_clone, 1
20
- set :deploy_to, "/home/#{user}/sites/#{application}"
21
- default_run_options[:pty] = true
22
-
23
- namespace :deploy do
24
- #task which causes Passenger to initiate a restart
25
- task :restart do
26
- run "mkdir -p #{release_path}/tmp && touch #{release_path}/tmp/restart.txt"
27
- end
28
-
29
- namespace :db do
30
-
31
- desc "Create database for the production environment using the servers rake db:setup task.\n Loads the schema, and initializes with the seed data"
32
- task :setup do
33
- run "cd #{current_path}; rake db:setup RAILS_ENV=production"
34
- end
35
-
36
- desc "Populates the production database using lib/tasks/populate which I will use as my own internal convention for this process"
37
- task :populate do
38
- run "cd #{current_path}; rake db:populate RAILS_ENV=production"
39
- end
40
-
41
- end
42
-
43
- desc "Task to set up the remote Nginx server for app deployment"
44
- task :nginx do
45
- run "#{sudo} nginx_auto_config /usr/local/bin/nginx.remote.conf /opt/nginx/conf/nginx.conf test_app"
46
- end
47
-
48
- desc "Create bare remote git repo then add remote origin to local git repo and push to remote"
49
- task :git do
50
- run "cd /home/#{user}/git; mkdir #{application}.git; cd #{application}.git; git init --bare"
51
- `git remote add origin ssh://#{user}@#{domain}/~/git/#{application}.git`
52
- `git push origin master`
53
- end
54
-
55
- end
56
-
57
- # Reminder of default actions for cap deploy:
58
- # deploy:update_code
59
- # deploy:symlink
60
- # deploy:restart
61
-
62
- # eg: after 'deploy:symlink', 'deploy:restart'