jumpstart 0.1.0

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.
Files changed (168) hide show
  1. data/.bundle/config +2 -0
  2. data/.document +5 -0
  3. data/.gitignore +28 -0
  4. data/Gemfile +8 -0
  5. data/LICENSE +20 -0
  6. data/README.rdoc +19 -0
  7. data/Rakefile +54 -0
  8. data/VERSION +1 -0
  9. data/bin/jumpstart +5 -0
  10. data/config/jumpstart_setup.yml +2 -0
  11. data/jumpstart.gemspec +222 -0
  12. data/jumpstart_templates/i0n_rails_3/.gitignore +11 -0
  13. data/jumpstart_templates/i0n_rails_3/_._Gemfile +5 -0
  14. data/jumpstart_templates/i0n_rails_3/app/views/home/index.haml +4 -0
  15. data/jumpstart_templates/i0n_rails_3/app/views/layouts/application.haml +32 -0
  16. data/jumpstart_templates/i0n_rails_3/config/_2._routes.rb +1 -0
  17. data/jumpstart_templates/i0n_rails_3/config/_L._database.yml +1 -0
  18. data/jumpstart_templates/i0n_rails_3/config/deploy.rb +62 -0
  19. data/jumpstart_templates/i0n_rails_3/config/environments/_18._development.rb +5 -0
  20. data/jumpstart_templates/i0n_rails_3/config/environments/_27._test.rb +1 -0
  21. data/jumpstart_templates/i0n_rails_3/config/environments/_41._production.rb +3 -0
  22. data/jumpstart_templates/i0n_rails_3/config/initializers/setup_mail.rb +14 -0
  23. data/jumpstart_templates/i0n_rails_3/jumpstart_config/i0n_rails_3.yml +40 -0
  24. data/jumpstart_templates/i0n_rails_3/jumpstart_config/nginx.local.conf +11 -0
  25. data/jumpstart_templates/i0n_rails_3/jumpstart_config/nginx.remote.conf +37 -0
  26. data/jumpstart_templates/i0n_rails_3/lib/development_mail_interceptor.rb +8 -0
  27. data/jumpstart_templates/i0n_rails_3/lib/generators/authlogic.rb +11 -0
  28. data/jumpstart_templates/i0n_rails_3/lib/generators/authlogic/session/session_generator.rb +18 -0
  29. data/jumpstart_templates/i0n_rails_3/lib/generators/authlogic/session/templates/session.rb +2 -0
  30. data/jumpstart_templates/i0n_rails_3/lib/generators/datamapper.rb +80 -0
  31. data/jumpstart_templates/i0n_rails_3/lib/generators/datamapper/migration/migration_generator.rb +26 -0
  32. data/jumpstart_templates/i0n_rails_3/lib/generators/datamapper/migration/templates/migration.rb +21 -0
  33. data/jumpstart_templates/i0n_rails_3/lib/generators/datamapper/model/model_generator.rb +29 -0
  34. data/jumpstart_templates/i0n_rails_3/lib/generators/datamapper/model/templates/migration.rb +17 -0
  35. data/jumpstart_templates/i0n_rails_3/lib/generators/datamapper/model/templates/model.rb +10 -0
  36. data/jumpstart_templates/i0n_rails_3/lib/generators/datamapper/observer/observer_generator.rb +15 -0
  37. data/jumpstart_templates/i0n_rails_3/lib/generators/datamapper/observer/templates/observer.rb +5 -0
  38. data/jumpstart_templates/i0n_rails_3/lib/generators/factory_girl.rb +11 -0
  39. data/jumpstart_templates/i0n_rails_3/lib/generators/factory_girl/model/model_generator.rb +14 -0
  40. data/jumpstart_templates/i0n_rails_3/lib/generators/factory_girl/model/templates/fixtures.rb +7 -0
  41. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb.rb +9 -0
  42. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb/USAGE +8 -0
  43. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb/controller/controller_generator.rb +24 -0
  44. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb/controller/templates/view.html.erb +0 -0
  45. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb/scaffold/scaffold_generator.rb +27 -0
  46. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb/scaffold/templates/_form.html.erb +12 -0
  47. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb/scaffold/templates/edit.html.erb +6 -0
  48. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb/scaffold/templates/index.html.erb +27 -0
  49. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb/scaffold/templates/layout.html.erb +16 -0
  50. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb/scaffold/templates/new.html.erb +5 -0
  51. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb/scaffold/templates/show.html.erb +10 -0
  52. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml.rb +9 -0
  53. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/USAGE +8 -0
  54. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/controller/controller_generator.rb +24 -0
  55. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/controller/templates/view.html.haml +0 -0
  56. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/scaffold/scaffold_generator.rb +23 -0
  57. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/scaffold/templates/_form.haml.erb +9 -0
  58. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/scaffold/templates/edit.haml.erb +7 -0
  59. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/scaffold/templates/index.haml.erb +23 -0
  60. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/scaffold/templates/layout.haml.erb +9 -0
  61. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/scaffold/templates/new.haml.erb +5 -0
  62. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/scaffold/templates/show.haml.erb +9 -0
  63. data/jumpstart_templates/i0n_rails_3/lib/generators/haml.rb +9 -0
  64. data/jumpstart_templates/i0n_rails_3/lib/generators/haml/controller/controller_generator.rb +24 -0
  65. data/jumpstart_templates/i0n_rails_3/lib/generators/haml/controller/templates/view.html.haml +0 -0
  66. data/jumpstart_templates/i0n_rails_3/lib/generators/haml/scaffold/scaffold_generator.rb +26 -0
  67. data/jumpstart_templates/i0n_rails_3/lib/generators/haml/scaffold/templates/_form.haml.erb +9 -0
  68. data/jumpstart_templates/i0n_rails_3/lib/generators/haml/scaffold/templates/edit.haml.erb +7 -0
  69. data/jumpstart_templates/i0n_rails_3/lib/generators/haml/scaffold/templates/index.haml.erb +23 -0
  70. data/jumpstart_templates/i0n_rails_3/lib/generators/haml/scaffold/templates/layout.haml.erb +9 -0
  71. data/jumpstart_templates/i0n_rails_3/lib/generators/haml/scaffold/templates/new.haml.erb +5 -0
  72. data/jumpstart_templates/i0n_rails_3/lib/generators/haml/scaffold/templates/show.haml.erb +9 -0
  73. data/jumpstart_templates/i0n_rails_3/lib/generators/machinist.rb +11 -0
  74. data/jumpstart_templates/i0n_rails_3/lib/generators/machinist/model/model_generator.rb +19 -0
  75. data/jumpstart_templates/i0n_rails_3/lib/generators/machinist/model/templates/blueprint.rb +5 -0
  76. data/jumpstart_templates/i0n_rails_3/lib/generators/machinist/model/templates/machinist_initializer.rb +19 -0
  77. data/jumpstart_templates/i0n_rails_3/lib/generators/mongomapper.rb +80 -0
  78. data/jumpstart_templates/i0n_rails_3/lib/generators/mongomapper/model/model_generator.rb +29 -0
  79. data/jumpstart_templates/i0n_rails_3/lib/generators/mongomapper/model/templates/model.rb +24 -0
  80. data/jumpstart_templates/i0n_rails_3/lib/generators/mongomapper/observer/observer_generator.rb +15 -0
  81. data/jumpstart_templates/i0n_rails_3/lib/generators/shoulda.rb +11 -0
  82. data/jumpstart_templates/i0n_rails_3/lib/generators/shoulda/controller/controller_generator.rb +16 -0
  83. data/jumpstart_templates/i0n_rails_3/lib/generators/shoulda/controller/templates/controller.rb +84 -0
  84. data/jumpstart_templates/i0n_rails_3/lib/generators/shoulda/model/model_generator.rb +16 -0
  85. data/jumpstart_templates/i0n_rails_3/lib/generators/shoulda/model/templates/model.rb +7 -0
  86. data/jumpstart_templates/i0n_rails_3/lib/tasks/populate.rake +91 -0
  87. data/jumpstart_templates/i0n_rails_3/public/javascripts/init.js +6 -0
  88. data/jumpstart_templates/i0n_rails_3/public/javascripts/jquery-1.4.2.min.js +154 -0
  89. data/jumpstart_templates/i0n_rails_3/public/javascripts/jquery-ui-1.8.custom.min.js +404 -0
  90. data/jumpstart_templates/i0n_rails_3/public/javascripts/rails.js +126 -0
  91. data/jumpstart_templates/i0n_rails_3/public/stylesheets/sass/_setup.sass +86 -0
  92. data/jumpstart_templates/i0n_rails_3/public/stylesheets/sass/global.sass +58 -0
  93. data/jumpstart_templates/i0n_rails_3/public/stylesheets/sass/handheld.sass +7 -0
  94. data/jumpstart_templates/i0n_rails_3/public/stylesheets/sass/ie.sass +40 -0
  95. data/jumpstart_templates/i0n_rails_3/public/stylesheets/sass/print.sass +57 -0
  96. data/jumpstart_templates/i0n_rails_3/public/stylesheets/sass/screen.sass +170 -0
  97. data/lib/jumpstart.rb +71 -0
  98. data/lib/jumpstart/base.rb +547 -0
  99. data/lib/jumpstart/doc/JumpStart.html +139 -0
  100. data/lib/jumpstart/doc/JumpStart/Base.html +1566 -0
  101. data/lib/jumpstart/doc/base_rb.html +52 -0
  102. data/lib/jumpstart/doc/created.rid +2 -0
  103. data/lib/jumpstart/doc/index.html +101 -0
  104. data/lib/jumpstart/doc/rdoc.css +706 -0
  105. data/lib/jumpstart/filetools.rb +270 -0
  106. data/source_templates/template_config.yml +77 -0
  107. data/test/fake_nginx_path/local_nginx_1.conf +81 -0
  108. data/test/fake_nginx_path/remote_nginx_1.conf +54 -0
  109. data/test/helper.rb +31 -0
  110. data/test/jumpstart/test_base.rb +422 -0
  111. data/test/jumpstart/test_filetools.rb +350 -0
  112. data/test/test_jumpstart.rb +9 -0
  113. data/test/test_jumpstart_templates/test_base/_._test_file.txt +0 -0
  114. data/test/test_jumpstart_templates/test_base/_._test_file_.txt +0 -0
  115. data/test/test_jumpstart_templates/test_base/_1._test_file1.txt +0 -0
  116. data/test/test_jumpstart_templates/test_base/_1._test_file1_.txt +0 -0
  117. data/test/test_jumpstart_templates/test_base/_10._test_file2.txt +0 -0
  118. data/test/test_jumpstart_templates/test_base/_99999._test_file3.txt +0 -0
  119. data/test/test_jumpstart_templates/test_base/_a._test_file4.txt +0 -0
  120. data/test/test_jumpstart_templates/test_base/test_file +0 -0
  121. data/test/test_jumpstart_templates/test_base/test_file5.txt +0 -0
  122. data/test/test_jumpstart_templates/test_base/test_file_.6txt +0 -0
  123. data/test/test_jumpstart_templates/test_fileutils/append_after_line_test.txt +6 -0
  124. data/test/test_jumpstart_templates/test_fileutils/append_to_end_of_file_source.txt +1 -0
  125. data/test/test_jumpstart_templates/test_fileutils/append_to_end_of_file_test.txt +5 -0
  126. data/test/test_jumpstart_templates/test_fileutils/check_source_type +5 -0
  127. data/test/test_jumpstart_templates/test_fileutils/check_source_type.txt +10 -0
  128. data/test/test_jumpstart_templates/test_fileutils/config_capistrano_source.rb +62 -0
  129. data/test/test_jumpstart_templates/test_fileutils/config_capistrano_test.rb +62 -0
  130. data/test/test_jumpstart_templates/test_fileutils/config_nginx_source.txt +1 -0
  131. data/test/test_jumpstart_templates/test_fileutils/config_nginx_test.txt +82 -0
  132. data/test/test_jumpstart_templates/test_fileutils/hosts_test +11 -0
  133. data/test/test_jumpstart_templates/test_fileutils/insert_text_at_line_number_source.txt +1 -0
  134. data/test/test_jumpstart_templates/test_fileutils/insert_text_at_line_number_test.txt +4 -0
  135. data/test/test_jumpstart_templates/test_fileutils/remove_files_test_2.txt +0 -0
  136. data/test/test_jumpstart_templates/test_fileutils/remove_files_test_3.txt +0 -0
  137. data/test/test_jumpstart_templates/test_fileutils/remove_lines_test.txt +10 -0
  138. data/test/test_jumpstart_templates/test_fileutils/replace_strings_test.rb +62 -0
  139. data/test/test_jumpstart_templates/test_template_1/_._test_append_file_with_extension.txt +1 -0
  140. data/test/test_jumpstart_templates/test_template_1/_._test_append_file_without_extension +1 -0
  141. data/test/test_jumpstart_templates/test_template_1/_20._test_line_file_without_extension +1 -0
  142. data/test/test_jumpstart_templates/test_template_1/_5._test_line_file_with_extension.txt +1 -0
  143. data/test/test_jumpstart_templates/test_template_1/_L._test_append_to_end_of_file_remove_last_line_1.txt +1 -0
  144. data/test/test_jumpstart_templates/test_template_1/_l._test_append_to_end_of_file_remove_last_line_2.txt +1 -0
  145. data/test/test_jumpstart_templates/test_template_1/folder with spaces/_._test_append_file_with_extension.txt +1 -0
  146. data/test/test_jumpstart_templates/test_template_1/folder with spaces/_._test_append_file_without_extension +1 -0
  147. data/test/test_jumpstart_templates/test_template_1/folder with spaces/_5._test_line_file_with_extension.txt +1 -0
  148. data/test/test_jumpstart_templates/test_template_1/folder with spaces/_50._test_line_file_without_extension +1 -0
  149. data/test/test_jumpstart_templates/test_template_1/folder with spaces/test_whole_file_with_extension.txt +1 -0
  150. data/test/test_jumpstart_templates/test_template_1/folder with spaces/test_whole_file_without_extension +1 -0
  151. data/test/test_jumpstart_templates/test_template_1/jumpstart_config/test_template_1.yml +31 -0
  152. data/test/test_jumpstart_templates/test_template_1/normal_folder_name/_._test_append_file_with_extension.txt +1 -0
  153. data/test/test_jumpstart_templates/test_template_1/normal_folder_name/_._test_append_file_without_extension +1 -0
  154. data/test/test_jumpstart_templates/test_template_1/normal_folder_name/_5._test_line_file_with_extension.txt +1 -0
  155. data/test/test_jumpstart_templates/test_template_1/normal_folder_name/_50._test_line_file_without_extension +1 -0
  156. data/test/test_jumpstart_templates/test_template_1/normal_folder_name/test_whole_file_with_extension.txt +1 -0
  157. data/test/test_jumpstart_templates/test_template_1/normal_folder_name/test_whole_file_without_extension +1 -0
  158. data/test/test_jumpstart_templates/test_template_1/test_append_to_end_of_file_remove_last_line_1.txt +10 -0
  159. data/test/test_jumpstart_templates/test_template_1/test_append_to_end_of_file_remove_last_line_2.txt +10 -0
  160. data/test/test_jumpstart_templates/test_template_1/test_remove_files/file_with_extension.txt +1 -0
  161. data/test/test_jumpstart_templates/test_template_1/test_remove_files/file_without_extension +1 -0
  162. data/test/test_jumpstart_templates/test_template_1/test_replace_strings/replace_strings_1.rb +62 -0
  163. data/test/test_jumpstart_templates/test_template_1/test_replace_strings/replace_strings_2.txt +23 -0
  164. data/test/test_jumpstart_templates/test_template_1/test_whole_file_with_extension.txt +1 -0
  165. data/test/test_jumpstart_templates/test_template_1/test_whole_file_without_extension +1 -0
  166. data/test/test_jumpstart_templates/test_template_2/jumpstart_config/test_template_2.yml +8 -0
  167. data/test/test_jumpstart_templates/test_template_3/jumpstart_config/test_template_3.yml +22 -0
  168. metadata +254 -0
@@ -0,0 +1,350 @@
1
+ require 'helper'
2
+
3
+ class TestJumpstartFileTools < Test::Unit::TestCase
4
+
5
+ context "Testing JumpStart::FileUtils.append_after_line class method.\n" do
6
+
7
+ setup do
8
+ FileUtils.remove_lines("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/append_after_line_test.txt", :pattern => "Inserted by append_after_line method test.")
9
+ end
10
+
11
+ should "insert specified line at line number 4 of target file" do
12
+ FileUtils.append_after_line("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/append_after_line_test.txt", "Line from check_source_type.txt. Line number: 3", "Inserted by append_after_line method test.")
13
+ file = IO.readlines("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/append_after_line_test.txt")
14
+ assert_equal 4, (file.find_index("Inserted by append_after_line method test.\n").to_i + 1)
15
+ end
16
+
17
+ should "fail because new line is not specified." do
18
+ assert_raises(ArgumentError) {FileUtils.append_after_line("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/append_after_line_test.txt", "Line from check_source_type.txt. Line number: 3")}
19
+ end
20
+
21
+ should "fail because the target file does not exist" do
22
+ assert_raises(Errno::ENOENT) {FileUtils.append_after_line("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/this_file_does_not_exist.txt", "Line from check_source_type.txt. Line number: 3", "Inserted by append_after_line method test.")}
23
+ end
24
+
25
+ end
26
+
27
+ context "Testing JumpStart::FileUtils.append_to_end_of_file class method.\n" do
28
+
29
+ setup do
30
+ @file_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/append_to_end_of_file_test.txt"
31
+ FileUtils.remove_lines(@file_path, :pattern => "TEST LINE INSERTED")
32
+ FileUtils.remove_lines(@file_path, :pattern => "TEST LINE INSERTED FROM FILE")
33
+ end
34
+
35
+ should "add the string passed in the method call to the specified file" do
36
+ FileUtils.append_to_end_of_file("TEST LINE INSERTED", @file_path)
37
+ file = IO.readlines(@file_path)
38
+ assert_equal 6, (file.find_index("TEST LINE INSERTED\n").to_i + 1)
39
+ end
40
+
41
+ should "add the string passed in the method call to the specified file and remove the last line" do
42
+ # Two appended lines so that the file doesn't lose all lines over time.
43
+ FileUtils.append_to_end_of_file("TEST LINE INSERTED", @file_path)
44
+ FileUtils.append_to_end_of_file("TEST LINE INSERTED", @file_path, true)
45
+ file = IO.readlines(@file_path)
46
+ assert_equal "TEST LINE INSERTED\n", file.last
47
+ assert_equal 6, file.count
48
+ end
49
+
50
+ should "add the contents of the file passed in the method call to the specified file" do
51
+ FileUtils.append_to_end_of_file("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/append_to_end_of_file_source.txt", @file_path)
52
+ file = IO.readlines(@file_path)
53
+ assert_equal 6, (file.find_index("TEST LINE INSERTED FROM FILE\n").to_i + 1)
54
+ end
55
+
56
+ should "add the contents of the file passed in the method call to the specified file and remove the last line" do
57
+ # Two appended lines so that the file doesn't lose all lines over time.
58
+ FileUtils.append_to_end_of_file("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/append_to_end_of_file_source.txt", @file_path)
59
+ FileUtils.append_to_end_of_file("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/append_to_end_of_file_source.txt", @file_path, true)
60
+ file = IO.readlines(@file_path)
61
+ assert_equal "TEST LINE INSERTED FROM FILE\n", file.last
62
+ assert_equal 6, file.count
63
+ end
64
+
65
+ should "fail because no target file is specified" do
66
+ assert_raises(ArgumentError) {FileUtils.append_to_end_of_file("TEST LINE INSERTED")}
67
+ end
68
+
69
+ should "fail because target file does not exist" do
70
+ assert_raises(Errno::ENOENT) {FileUtils.append_to_end_of_file("TEST LINE INSERTED", "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/does_not_exist/file.txt")}
71
+ end
72
+
73
+ end
74
+
75
+ context "Testing JumpStart::FileUtils.insert_text_at_line_number class method.\n" do
76
+
77
+ setup do
78
+ @file_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/insert_text_at_line_number_test.txt"
79
+ @source_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/insert_text_at_line_number_source.txt"
80
+ FileUtils.remove_lines(@file_path, :pattern => "TEST LINE INSERTED")
81
+ end
82
+
83
+ should "insert text from string into target file at line 3" do
84
+ FileUtils.insert_text_at_line_number("TEST LINE INSERTED", @file_path, 3)
85
+ file = IO.readlines(@file_path)
86
+ assert_equal "TEST LINE INSERTED\n", file[2]
87
+ assert_equal 5, file.count
88
+ end
89
+
90
+ should "insert text from source file into target file at line 2" do
91
+ FileUtils.insert_text_at_line_number(@source_path, @file_path, 2)
92
+ file = IO.readlines(@file_path)
93
+ assert_equal "TEST LINE INSERTED FROM FILE\n", file[1]
94
+ assert_equal 5, file.count
95
+ end
96
+
97
+ should "raise an exception if a line number is not passed to the method" do
98
+ assert_raises(ArgumentError) {FileUtils.insert_text_at_line_number(@source_path, @file_path)}
99
+ end
100
+
101
+ should "raise an exception if the line number is not 1 or higher" do
102
+ assert_raises(ArgumentError) {FileUtils.insert_text_at_line_number(@source_path, @file_path, 0)}
103
+ assert_raises(ArgumentError) {FileUtils.insert_text_at_line_number(@source_path, @file_path, -10)}
104
+ end
105
+
106
+ end
107
+
108
+ context "Testing JumpStart::FileUtils.remove_files class method.\n" do
109
+
110
+ setup do
111
+ @file_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils"
112
+ FileUtils.touch("#{@file_path}/remove_files_test_1.txt")
113
+ FileUtils.touch("#{@file_path}/remove_files_test_2.txt")
114
+ FileUtils.touch("#{@file_path}/remove_files_test_3.txt")
115
+ @file_array = []
116
+ end
117
+
118
+ should "delete the file remove_files_test_1.txt" do
119
+ file = FileUtils.join_paths(@file_path, "/remove_files_test_1.txt")
120
+ @file_array << file
121
+ FileUtils.remove_files(@file_array)
122
+ refute File.exists?("#{@file_path}/remove_files_test_1.txt")
123
+ end
124
+
125
+ should "delete all three test files" do
126
+ @file_array << "/remove_files_test_1.txt" << "/remove_files_test_2.txt" << "/remove_files_test_3.txt"
127
+ @file_array.map!{|x| FileUtils.join_paths(@file_path, x)}
128
+ FileUtils.remove_files(@file_array)
129
+ refute File.exists?("#{@file_path}/remove_files_test_1.txt")
130
+ refute File.exists?("#{@file_path}/remove_files_test_2.txt")
131
+ refute File.exists?("#{@file_path}/remove_files_test_3.txt")
132
+ end
133
+
134
+ end
135
+
136
+ context "Testing JumpStart::FileUtils.remove_lines class method.\n" do
137
+
138
+ setup do
139
+ @file_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/remove_lines_test.txt"
140
+ end
141
+
142
+ should "remove line 5 from the test file using the :lines argument" do
143
+ FileUtils.remove_lines(@file_path, :lines => [5])
144
+ file = IO.readlines(@file_path)
145
+ assert_equal 9, file.length
146
+ assert_equal "6\n", file.fetch(4)
147
+ FileUtils.insert_text_at_line_number("5", @file_path, 5)
148
+ end
149
+
150
+ should "remove lines 5 & 9 from the test file using the :lines argument" do
151
+ FileUtils.remove_lines(@file_path, :lines => [1,10])
152
+ file = IO.readlines(@file_path)
153
+ assert_equal 8, file.length
154
+ FileUtils.insert_text_at_line_number("1", @file_path, 1)
155
+ FileUtils.insert_text_at_line_number("10", @file_path, 10)
156
+ end
157
+
158
+ should "remove line 5 from the test file using the :line argument" do
159
+ FileUtils.remove_lines(@file_path, :line => 5)
160
+ file = IO.readlines(@file_path)
161
+ assert_equal 9, file.length
162
+ assert_equal "6\n", file.fetch(4)
163
+ FileUtils.insert_text_at_line_number("5", @file_path, 5)
164
+ end
165
+
166
+ should "return an argument error as :lines and :line cannot be specified at the same time." do
167
+ assert_raises(ArgumentError) {FileUtils.remove_lines(@file_path, :line => 5, :lines => [6,7])}
168
+ end
169
+
170
+ should "remove line 5 from the test file using the :pattern argument" do
171
+ FileUtils.remove_lines(@file_path, :pattern => "5")
172
+ file = IO.readlines(@file_path)
173
+ assert_equal 9, file.length
174
+ assert_equal "6\n", file.fetch(4)
175
+ FileUtils.insert_text_at_line_number("5", @file_path, 5)
176
+ end
177
+
178
+ should "remove line 5 from the test file using the pattern argument, and remove line 9 from the file using the :line argument" do
179
+ FileUtils.remove_lines(@file_path, :pattern => "5", :line => 9)
180
+ file = IO.readlines(@file_path)
181
+ assert_equal 8, file.length
182
+ assert_equal "6\n", file.fetch(4)
183
+ assert_equal "10\n", file.fetch(7)
184
+ FileUtils.insert_text_at_line_number("5", @file_path, 5)
185
+ FileUtils.insert_text_at_line_number("9", @file_path, 9)
186
+ end
187
+
188
+ should "remove line 5 from the test file using the pattern argument, and remove line 9 from the file using the :lines argument" do
189
+ FileUtils.remove_lines(@file_path, :pattern => "5", :lines => [8,9])
190
+ file = IO.readlines(@file_path)
191
+ assert_equal 7, file.length
192
+ assert_equal "6\n", file.fetch(4)
193
+ assert_equal "7\n", file.fetch(5)
194
+ assert_equal "10\n", file.fetch(6)
195
+ FileUtils.insert_text_at_line_number("5", @file_path, 5)
196
+ FileUtils.insert_text_at_line_number("8", @file_path, 8)
197
+ FileUtils.insert_text_at_line_number("9", @file_path, 9)
198
+ end
199
+
200
+ end
201
+
202
+ context "Testing JumpStart::FileUtils.config_nginx class method.\n" do
203
+
204
+ setup do
205
+ @source_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/config_nginx_source.txt"
206
+ @target_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/config_nginx_test.txt"
207
+ @project_name = "test_project"
208
+ FileUtils.remove_lines(@target_path, :pattern => "LINE ADDED BY TEST")
209
+ end
210
+
211
+ should "copy nginx source file into target path" do
212
+ FileUtils.config_nginx(@source_path, @target_path, @project_name)
213
+ file = IO.readlines(@target_path)
214
+ assert_equal "LINE ADDED BY TEST\n", file[80]
215
+ end
216
+
217
+ end
218
+
219
+ context "Testing JumpStart::FileUtils.config_hosts class method.\n" do
220
+
221
+ setup do
222
+ @project_name = "test_project"
223
+ @target_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/hosts_test"
224
+ FileUtils.remove_lines(@target_path, :pattern => "127.0.0.1 test_project.local")
225
+ end
226
+
227
+ should "add line for test_project.local to hosts_test file" do
228
+ FileUtils.config_hosts(@target_path, @project_name)
229
+ file = IO.readlines(@target_path)
230
+ assert_equal "127.0.0.1 test_project.local\n", file[10]
231
+ end
232
+
233
+ end
234
+
235
+ context "Testing JumpStart::FileUtils.replace_strings class method.\n" do
236
+
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"
241
+ @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
244
+ end
245
+ end
246
+
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)
250
+ assert_equal "set :application, 'test_app'\n", file[0]
251
+ assert_equal "set :domain, 'remote_box'\n", file[1]
252
+ assert_equal "run \"\#{sudo} nginx_auto_config /usr/local/bin/nginx.remote.conf /opt/nginx/conf/nginx.conf test_app\"\n", file[44]
253
+ end
254
+
255
+ end
256
+
257
+ context "Testing JumpStart::FileUtils.check_source_type class method.\n" do
258
+
259
+ should "return source as a string" do
260
+ assert_equal "source_as_a_string", FileUtils.check_source_type("source_as_a_string")
261
+ end
262
+
263
+ should "return source as an array" do
264
+ assert_equal ["Line from check_source_type.txt. Line number: 1\n",
265
+ "Line from check_source_type.txt. Line number: 2\n",
266
+ "Line from check_source_type.txt. Line number: 3\n",
267
+ "Line from check_source_type.txt. Line number: 4\n",
268
+ "Line from check_source_type.txt. Line number: 5\n",
269
+ "Line from check_source_type.txt. Line number: 6\n",
270
+ "Line from check_source_type.txt. Line number: 7\n",
271
+ "Line from check_source_type.txt. Line number: 8\n",
272
+ "Line from check_source_type.txt. Line number: 9\n",
273
+ "Line from check_source_type.txt. Line number: 10"], FileUtils.check_source_type("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/check_source_type.txt")
274
+ end
275
+
276
+ should "return source as an array, even without a file extension." do
277
+ assert_equal ["Line from check_source_type.txt. Line number: 1\n",
278
+ "Line from check_source_type.txt. Line number: 2\n",
279
+ "Line from check_source_type.txt. Line number: 3\n",
280
+ "Line from check_source_type.txt. Line number: 4\n",
281
+ "Line from check_source_type.txt. Line number: 5"], FileUtils.check_source_type("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/check_source_type")
282
+ end
283
+
284
+ end
285
+
286
+ context "Testing JumpStart::FileUtils.join_paths class method.\n" do
287
+
288
+ should "return the relative path passed to it unaltered." do
289
+ assert_equal "path/to/file.txt", FileUtils.join_paths("path/to/file.txt")
290
+ end
291
+
292
+ should "return the absolute path passed to it unaltered." do
293
+ assert_equal "/path/to/file.txt", FileUtils.join_paths("/path/to/file.txt")
294
+ end
295
+
296
+ should "return the path even if it is passed as a variable" do
297
+ string = "/path/to/file.txt"
298
+ assert_equal string, FileUtils.join_paths(string)
299
+ end
300
+
301
+ should "return a valid path if too many forward slashes are entered as an array" do
302
+ a = %w[this/ //array/// /of/ /paths/ /has// /far/ //too/ ////many/ /forward// /slashes.txt]
303
+ assert_equal "this/array/of/paths/has/far/too/many/forward/slashes.txt", FileUtils.join_paths(a)
304
+ end
305
+
306
+ should "return a valid path if too many forward slashes are entered as strings" do
307
+ a,b,c,d,e,f,g,h,i,j = 'this/', '//array///', '/of/', '/paths/', '/has//', '/far/', '//too/', '////many/', '/forward//', '/slashes.txt'
308
+ assert_equal "this/array/of/paths/has/far/too/many/forward/slashes.txt", FileUtils.join_paths(a,b,c,d,e,f,g,h,i,j)
309
+ end
310
+
311
+ should "return a valid path if paths are missing forward slashes and entered as an array" do
312
+ a = %w[this array of paths has far too many forward slashes.txt]
313
+ assert_equal "this/array/of/paths/has/far/too/many/forward/slashes.txt", FileUtils.join_paths(a)
314
+ end
315
+
316
+ should "return a valid path if paths are passed as strings and have no forward slashes" do
317
+ a,b,c,d,e,f,g,h,i,j = 'this', 'array', 'of', 'paths', 'has', 'far', 'too', 'many', 'forward', 'slashes.txt'
318
+ assert_equal "this/array/of/paths/has/far/too/many/forward/slashes.txt", FileUtils.join_paths(a,b,c,d,e,f,g,h,i,j)
319
+ end
320
+
321
+ should "return a valid path some paths have too many forward slashes and some don't. Some arguments are passed in arrays, some as strings" do
322
+ a,b,c,d,e,f,g = 'this/', '//array///', %w[/of/], '/paths/', %w[/has// /far/], '//too/', %w[////many/ /forward// /slashes.txt]
323
+ assert_equal "this/array/of/paths/has/far/too/many/forward/slashes.txt", FileUtils.join_paths(a,b,c,d,e,f,g)
324
+ end
325
+
326
+ should "return a valid path some paths have too many forward slashes and some don't. Some arguments are passed in arrays, some as strings, mixed with nil values" do
327
+ a,b,c,d,e,f,g,h,i,j = 'this/', '//array///', nil, %w[/of/], '/paths/', %w[/has// /far/], nil, '//too/', nil, %w[////many/ /forward// /slashes.txt]
328
+ assert_equal "this/array/of/paths/has/far/too/many/forward/slashes.txt", FileUtils.join_paths(a,b,c,d,e,f,g,h,i,j)
329
+ end
330
+
331
+ should "return a valid path, even if too many files are specified" do
332
+ a,b,c,d,e,f,g,h,i,j,k = 'this/', '//array///', nil, %w[/of/], '/paths/', %w[/has// /far/], nil, '//too/', nil, %w[////many/ /forward// /slashes.txt], "another_file.rb"
333
+ assert_equal "this/array/of/paths/has/far/too/many/forward/slashes.txt", FileUtils.join_paths(a,b,c,d,e,f,g,h,i,j,k)
334
+ end
335
+
336
+ should "return a valid path, even if too many files are specified and the supplied paths contain whitespace and line breaks" do
337
+ a,b,c,d,e,f,g,h,i,k = "this/\n", ' //array///', nil, %w[/of/], '/paths/ ', %w[/has// /far/], nil, "//too/\n", nil, "another_file.rb"
338
+ j = ["////many/\n", " /forward// ", "\n /slashes.txt\n\n\n"]
339
+ assert_equal "this/array/of/paths/has/far/too/many/forward/slashes.txt", FileUtils.join_paths(a,b,c,d,e,f,g,h,i,j,k)
340
+ end
341
+
342
+ should "return an absolute path" do
343
+ a,b,c,d,e,f,g,h,i,k = "///this/\n", ' //array///', nil, %w[/of/], '/paths/ ', %w[/has// /far/], nil, "//too/\n", nil, "another_file.rb"
344
+ j = ["////many/\n", " /forward// ", "\n /slashes.txt\n\n\n"]
345
+ assert_equal "/this/array/of/paths/has/far/too/many/forward/slashes.txt", FileUtils.join_paths(a,b,c,d,e,f,g,h,i,j,k)
346
+ end
347
+
348
+ end
349
+
350
+ end
@@ -0,0 +1,9 @@
1
+ require 'helper'
2
+
3
+ class TestJumpstart < Test::Unit::TestCase
4
+
5
+ should "be able to find jumpstart_setup.yml" do
6
+ assert(File.exists?("#{JumpStart::CONFIG_PATH}/jumpstart_setup.yml"))
7
+ end
8
+
9
+ end
File without changes
@@ -0,0 +1,6 @@
1
+ Line from check_source_type.txt. Line number: 1
2
+ Line from check_source_type.txt. Line number: 2
3
+ Line from check_source_type.txt. Line number: 3
4
+ Inserted by append_after_line method test.
5
+ Line from check_source_type.txt. Line number: 4
6
+ Line from check_source_type.txt. Line number: 5
@@ -0,0 +1 @@
1
+ TEST LINE INSERTED FROM FILE
@@ -0,0 +1,5 @@
1
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
2
+ lorem
3
+ lorem
4
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
5
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,5 @@
1
+ Line from check_source_type.txt. Line number: 1
2
+ Line from check_source_type.txt. Line number: 2
3
+ Line from check_source_type.txt. Line number: 3
4
+ Line from check_source_type.txt. Line number: 4
5
+ Line from check_source_type.txt. Line number: 5
@@ -0,0 +1,10 @@
1
+ Line from check_source_type.txt. Line number: 1
2
+ Line from check_source_type.txt. Line number: 2
3
+ Line from check_source_type.txt. Line number: 3
4
+ Line from check_source_type.txt. Line number: 4
5
+ Line from check_source_type.txt. Line number: 5
6
+ Line from check_source_type.txt. Line number: 6
7
+ Line from check_source_type.txt. Line number: 7
8
+ Line from check_source_type.txt. Line number: 8
9
+ Line from check_source_type.txt. Line number: 9
10
+ Line from check_source_type.txt. Line number: 10
@@ -0,0 +1,62 @@
1
+ set :application, 'APP_NAME'
2
+ set :domain, 'REMOTE_SERVER'
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 APP_NAME"
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'