trusty-layouts-extension 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/MIT-LICENSE +98 -0
  2. data/README.md +115 -0
  3. data/Rakefile +144 -0
  4. data/VERSION +1 -0
  5. data/app/models/haml_filter.rb +5 -0
  6. data/app/models/rails_page.rb +39 -0
  7. data/app/views/layouts/trusty.html.haml +1 -0
  8. data/config/initializers/trusty_config.rb +1 -0
  9. data/config/routes.rb +0 -0
  10. data/layouts_extension.rb +21 -0
  11. data/lib/haml_layouts/models/layout.rb +33 -0
  12. data/lib/haml_layouts/models/page.rb +33 -0
  13. data/lib/layouts/engine.rb +5 -0
  14. data/lib/nested_layouts/tags/core.rb +150 -0
  15. data/lib/share_layouts/controllers/action_controller.rb +26 -0
  16. data/lib/share_layouts/helpers/action_view.rb +48 -0
  17. data/lib/tasks/layouts_extension_tasks.rake +55 -0
  18. data/lib/trusty-layouts-extension.rb +1 -0
  19. data/spec/controllers/share_controller_spec.rb +119 -0
  20. data/spec/datasets/layouts_layouts.rb +36 -0
  21. data/spec/datasets/layouts_pages.rb +43 -0
  22. data/spec/lib/haml_layouts/haml_layouts_extension_spec.rb +22 -0
  23. data/spec/lib/haml_layouts/models/layout_spec.rb +36 -0
  24. data/spec/lib/haml_layouts/models/page_spec.rb +40 -0
  25. data/spec/lib/nested_layouts/nested_layouts_extension_spec.rb +16 -0
  26. data/spec/lib/nested_layouts/tags/core_spec.rb +147 -0
  27. data/spec/lib/share_layouts/controllers/action_controller_spec.rb +44 -0
  28. data/spec/lib/share_layouts/helpers/action_view_spec.rb +171 -0
  29. data/spec/lib/share_layouts/share_layouts_extension_spec.rb +22 -0
  30. data/spec/models/haml_filter_spec.rb +0 -0
  31. data/spec/models/rails_page_spec.rb +63 -0
  32. data/spec/spec.opts +3 -0
  33. data/spec/spec_helper.rb +22 -0
  34. data/trusty-layouts-extension.gemspec +31 -0
  35. data/vendor/plugins/rails_upgrade/MIT-LICENSE +20 -0
  36. data/vendor/plugins/rails_upgrade/README.rdoc +26 -0
  37. data/vendor/plugins/rails_upgrade/Rakefile +22 -0
  38. data/vendor/plugins/rails_upgrade/init.rb +2 -0
  39. data/vendor/plugins/rails_upgrade/install.rb +38 -0
  40. data/vendor/plugins/rails_upgrade/lib/application_checker.rb +506 -0
  41. data/vendor/plugins/rails_upgrade/lib/gemfile_generator.rb +95 -0
  42. data/vendor/plugins/rails_upgrade/lib/new_configuration_generator.rb +59 -0
  43. data/vendor/plugins/rails_upgrade/lib/rails_upgrade.rb +0 -0
  44. data/vendor/plugins/rails_upgrade/lib/routes_upgrader.rb +344 -0
  45. data/vendor/plugins/rails_upgrade/lib/tasks/rails_upgrade_tasks.rake +79 -0
  46. data/vendor/plugins/rails_upgrade/test/application_checker_test.rb +344 -0
  47. data/vendor/plugins/rails_upgrade/test/gemfile_generator_test.rb +72 -0
  48. data/vendor/plugins/rails_upgrade/test/new_configuration_generator_test.rb +63 -0
  49. data/vendor/plugins/rails_upgrade/test/routes_upgrader_test.rb +218 -0
  50. data/vendor/plugins/rails_upgrade/test/test_helper.rb +5 -0
  51. data/vendor/plugins/rails_upgrade/uninstall.rb +1 -0
  52. metadata +134 -0
@@ -0,0 +1,79 @@
1
+ $:.unshift(File.dirname(__FILE__) + "/../../lib")
2
+ require 'routes_upgrader'
3
+ require 'gemfile_generator'
4
+ require 'application_checker'
5
+ require 'new_configuration_generator'
6
+ require "active_support"
7
+
8
+ require 'fileutils'
9
+
10
+ namespace :rails do
11
+ namespace :upgrade do
12
+ desc "Runs a battery of checks on your Rails 2.x app and generates a report on required upgrades for Rails 3"
13
+ task :check do
14
+ checker = Rails::Upgrading::ApplicationChecker.new
15
+ checker.run
16
+ end
17
+
18
+ desc "Generates a Gemfile for your Rails 3 app out of your config.gem directives"
19
+ task :gems do
20
+ generator = Rails::Upgrading::GemfileGenerator.new
21
+ new_gemfile = generator.generate_new_gemfile
22
+
23
+ puts new_gemfile
24
+ end
25
+
26
+ desc "Create a new, upgraded route file from your current routes.rb"
27
+ task :routes do
28
+ upgrader = Rails::Upgrading::RoutesUpgrader.new
29
+ new_routes = upgrader.generate_new_routes
30
+
31
+ puts new_routes
32
+ end
33
+
34
+ desc "Extracts your configuration code so you can create a new config/application.rb"
35
+ task :configuration do
36
+ upgrader = Rails::Upgrading::NewConfigurationGenerator.new
37
+ new_config = upgrader.generate_new_application_rb
38
+
39
+ puts new_config
40
+ end
41
+
42
+ CLEAR = "\e[0m" unless defined? CLEAR
43
+ CYAN = "\e[36m" unless defined? CYAN
44
+ WHITE = "\e[37m" unless defined? WHITE
45
+
46
+ desc "Backs up your likely modified files so you can run the Rails 3 generator on your app with little risk"
47
+ task :backup do
48
+ files = [".gitignore",
49
+ "app/controllers/application_controller.rb",
50
+ "app/helpers/application_helper.rb",
51
+ "config/routes.rb",
52
+ "config/environment.rb",
53
+ "config/environments/development.rb",
54
+ "config/environments/production.rb",
55
+ "config/environments/staging.rb",
56
+ "config/database.yml",
57
+ "config.ru",
58
+ "doc/README_FOR_APP",
59
+ "test/test_helper.rb"]
60
+
61
+ puts
62
+ files.each do |f|
63
+ if File.exist?(f)
64
+ puts "#{CYAN}* #{CLEAR}backing up #{WHITE}#{f}#{CLEAR} to #{WHITE}#{f}.rails2#{CLEAR}"
65
+ FileUtils.cp(f, "#{f}.rails2")
66
+ end
67
+ end
68
+
69
+ puts
70
+ puts "This is a list of the files analyzed and backed up (if they existed);\nyou will probably not want the generator to replace them since\nyou probably modified them (but now they're safe if you accidentally do!)."
71
+ puts
72
+
73
+ files.each do |f|
74
+ puts "#{CYAN}- #{CLEAR}#{f}"
75
+ end
76
+ puts
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,344 @@
1
+ require 'test_helper'
2
+ require 'application_checker'
3
+ require 'fileutils'
4
+
5
+ tmp_dir = File.expand_path("#{File.dirname(__FILE__)}/fixtures/tmp")
6
+
7
+ if defined? BASE_ROOT
8
+ BASE_ROOT.replace tmp_dir
9
+ else
10
+ BASE_ROOT = tmp_dir
11
+ end
12
+ FileUtils.mkdir_p BASE_ROOT
13
+
14
+ # Stub out methods on upgrader class
15
+ module Rails
16
+ module Upgrading
17
+ class ApplicationChecker
18
+ attr_reader :alerts, :culprits
19
+
20
+ def base_path
21
+ BASE_ROOT + "/"
22
+ end
23
+
24
+ def in_rails_app?
25
+ true
26
+ end
27
+
28
+ def initialize
29
+ @alerts = {}
30
+ @culprits = {}
31
+ end
32
+
33
+ def alert(title, text, more_info_url, culprits)
34
+ @alerts[title] = [text, more_info_url]
35
+ @culprits[title] = culprits
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ class ApplicationCheckerTest < ActiveSupport::TestCase
42
+ def setup
43
+ @checker = Rails::Upgrading::ApplicationChecker.new
44
+ @old_dir = Dir.pwd
45
+
46
+ Dir.chdir(BASE_ROOT)
47
+ end
48
+
49
+ def test_check_ar_methods_in_controller
50
+ make_file("app/controllers", "post_controller.rb", "Post.find(:all)")
51
+ @checker.check_ar_methods
52
+
53
+ assert @checker.alerts.has_key?("Soon-to-be-deprecated ActiveRecord calls")
54
+ end
55
+
56
+ def test_check_ar_methods_in_models
57
+ make_file("app/models", "post.rb", "Post.find(:all)")
58
+ @checker.check_ar_methods
59
+
60
+ key = "Soon-to-be-deprecated ActiveRecord calls"
61
+ assert @checker.alerts.has_key?(key)
62
+ assert_equal "app/models/post.rb", @checker.culprits[key].first
63
+ end
64
+
65
+ def test_check_svn_subdirs_are_not_included
66
+ make_file("app/models/.svn/text-base", "foo.rb.tmp", "Post.find(:all)")
67
+ @checker.check_ar_methods
68
+ assert @checker.alerts.empty?
69
+ end
70
+
71
+ def test_check_validation_on_methods
72
+ make_file("app/models", "post.rb", "validate_on_create :comments_valid?")
73
+ @checker.check_validation_on_methods
74
+
75
+ assert @checker.alerts.has_key?("Updated syntax for validate_on_* methods")
76
+ end
77
+
78
+ def test_check_before_validation_on_methods
79
+ make_file("app/models", "post.rb", "before_validation_on_create :comments_valid?")
80
+ @checker.check_before_validation_on_methods
81
+
82
+ assert @checker.alerts.has_key?("Updated syntax for before_validation_on_* methods")
83
+ end
84
+
85
+ def test_named_scope_left_over
86
+ make_file("app/models", "post.rb", "named_scope :failure")
87
+ @checker.check_ar_methods
88
+
89
+ assert @checker.alerts.has_key?("named_scope is now just scope")
90
+ end
91
+
92
+ def test_check_routes
93
+ make_file("config/", "routes.rb", " map.connect 'fail'")
94
+ @checker.check_routes
95
+
96
+ assert @checker.alerts.has_key?("Old router API")
97
+ end
98
+
99
+ def test_check_for_old_test_help
100
+ make_file("test/", "test_helper.rb", " require 'test_help'")
101
+ @checker.check_test_help
102
+
103
+ assert @checker.alerts.has_key?("Deprecated test_help path")
104
+ end
105
+
106
+ def test_check_for_old_test_help_with_double_quotes
107
+ make_file("test/", "test_helper.rb", " require \"test_help\"")
108
+ @checker.check_test_help
109
+
110
+ assert @checker.alerts.has_key?("Deprecated test_help path")
111
+ end
112
+
113
+ def test_check_for_old_test_help_doesnt_see_test_helper
114
+ make_file("test/", "test_helper.rb", " require 'test_helper'")
115
+ @checker.check_test_help
116
+
117
+ assert !@checker.alerts.has_key?("Deprecated test_help path")
118
+ end
119
+
120
+ def test_check_lack_of_app_dot_rb
121
+ @checker.check_environment
122
+
123
+ assert @checker.alerts.has_key?("New file needed: config/application.rb")
124
+ end
125
+
126
+ def test_check_environment_syntax
127
+ make_file("config/", "environment.rb", "config.frameworks = []")
128
+ @checker.check_environment
129
+
130
+ assert @checker.alerts.has_key?("Old environment.rb")
131
+ end
132
+
133
+ def test_check_gems
134
+ make_file("config/", "environment.rb", "config.gem 'rails'")
135
+ @checker.check_gems
136
+
137
+ assert @checker.alerts.has_key?("Old gem bundling (config.gems)")
138
+ end
139
+
140
+ def test_check_gems_finds_nothing
141
+ @checker.check_gems
142
+
143
+ assert_equal false, @checker.alerts.has_key?("Old gem bundling (config.gems)")
144
+ end
145
+
146
+ def test_check_mailer_finds_nothing
147
+ @checker.check_mailers
148
+
149
+ assert_equal false, @checker.alerts.has_key?("Old ActionMailer class API")
150
+ end
151
+
152
+ def test_check_mailer_syntax
153
+ make_file("app/models/", "notifications.rb", "def signup\nrecipients @users\n end")
154
+ @checker.check_mailers
155
+
156
+ assert @checker.alerts.has_key?("Old ActionMailer class API")
157
+ end
158
+
159
+ def test_check_mailer_syntax_from
160
+ make_file("app/models/", "notifications.rb", "def signup\nfrom @user\n end")
161
+ @checker.check_mailers
162
+
163
+ assert @checker.alerts.has_key?("Old ActionMailer class API")
164
+ end
165
+
166
+ def test_check_mailer_syntax_subject
167
+ make_file("app/models/", "notifications.rb", "def signup\nsubject @subject\n end")
168
+ @checker.check_mailers
169
+
170
+ assert @checker.alerts.has_key?("Old ActionMailer class API")
171
+ end
172
+
173
+ def test_check_mailer_syntax_attachment
174
+ make_file("app/models/", "notifications.rb", "def signup\nattachment 'application/pdf' do |a|\n end")
175
+ @checker.check_mailers
176
+
177
+ assert @checker.alerts.has_key?("Old ActionMailer class API")
178
+ end
179
+
180
+ def test_new_check_mailer_syntax_from
181
+ make_file("app/models/", "notifications.rb", "def signup\n:from => @users\n end")
182
+ @checker.check_mailers
183
+
184
+ assert ! @checker.alerts.has_key?("Old ActionMailer class API")
185
+ end
186
+
187
+ def test_new_check_mailer_syntax_subject
188
+ make_file("app/models/", "notifications.rb", "def signup\n:subject => @users\n end")
189
+ @checker.check_mailers
190
+
191
+ assert ! @checker.alerts.has_key?("Old ActionMailer class API")
192
+ end
193
+
194
+ def test_new_check_mailer_syntax_attachments
195
+ make_file("app/models/", "notifications.rb", "def signup\nattachments['an-image.jp'] = File.read('an-image.jpg')\n end")
196
+ @checker.check_mailers
197
+
198
+ assert ! @checker.alerts.has_key?("Old ActionMailer class API")
199
+ end
200
+
201
+ def test_check_mailer_api
202
+ make_file("app/controllers/", "thing_controller.rb", "def signup\n Notifications.deliver_signup\n end")
203
+ @checker.check_mailers
204
+
205
+ assert @checker.alerts.has_key?("Deprecated ActionMailer API")
206
+ end
207
+
208
+ def test_check_generators
209
+ make_file("vendor/plugins/thing/generators/thing/", "thing_generator.rb", "def manifest\n m.whatever\n end")
210
+ @checker.check_generators
211
+
212
+ assert @checker.alerts.has_key?("Old Rails generator API")
213
+ end
214
+
215
+ def test_check_plugins
216
+ make_file("vendor/plugins/rspec-rails/", "whatever.rb", "def rspec; end")
217
+ @checker.check_plugins
218
+
219
+ assert @checker.alerts.has_key?("Known broken plugins")
220
+ end
221
+
222
+ def test_ignoring_comments
223
+ make_file("config/", "routes.rb", "# map.connect 'fail'")
224
+ @checker.check_routes
225
+
226
+ assert !@checker.alerts.has_key?("Old router API")
227
+ end
228
+
229
+ def test_check_deprecated_constants_in_app_code
230
+ make_file("app/controllers/", "thing_controller.rb", "class ThingController; THING = Rails.env; end;")
231
+ @checker.check_deprecated_constants
232
+
233
+ assert @checker.alerts.has_key?("Deprecated constant(s)")
234
+ end
235
+
236
+ def test_check_deprecated_constants_in_lib
237
+ make_file("lib/", "extra_thing.rb", "class ExtraThing; THING = Rails.env; end;")
238
+ @checker.check_deprecated_constants
239
+
240
+ assert @checker.alerts.has_key?("Deprecated constant(s)")
241
+ end
242
+
243
+ def test_check_deprecated_cookie_finds_nothing
244
+ @checker.check_old_cookie_secret
245
+ assert_equal false, @checker.alerts.has_key?("Deprecated cookie secret setting")
246
+ end
247
+
248
+ def test_check_deprecated_cookie_settings
249
+ make_file("config/initializers/", "more_settings.rb", "ActionController::Base.cookie_verifier_secret = 'OMG'")
250
+ @checker.check_old_cookie_secret
251
+
252
+ assert @checker.alerts.has_key?("Deprecated cookie secret setting")
253
+ end
254
+
255
+ def test_check_deprecated_session_finds_nothing
256
+ @checker.check_old_session_secret
257
+ assert_equal false, @checker.alerts.has_key?("Deprecated session secret setting")
258
+ end
259
+
260
+ def test_check_deprecated_session_secret
261
+ make_file("config/initializers/", "more_settings.rb", "ActionController::Base.session = {\n:whatever => 'woot'\n}")
262
+ @checker.check_old_session_secret
263
+
264
+ assert @checker.alerts.has_key?("Deprecated session secret setting")
265
+ end
266
+
267
+ def test_check_old_session_setting_finds_nothing
268
+ @checker.check_old_session_setting
269
+ assert_equal false, @checker.alerts.has_key?("Old session store setting")
270
+ end
271
+
272
+ def test_check_deprecated_session_settings
273
+ make_file("config/initializers/", "more_settings.rb", "ActionController::Base.session_store = :cookie\nthings.awesome(:whatever)")
274
+ @checker.check_old_session_setting
275
+
276
+ assert @checker.alerts.has_key?("Old session store setting")
277
+ end
278
+
279
+ def test_check_helpers
280
+ make_file("app/views/users/", "test.html.erb", "<b>blah blah blah</b><% form_for(:thing) do |f| %> <label>doo dah</label> <%= f.whatever %> <% end %>")
281
+ @checker.check_old_helpers
282
+
283
+ assert @checker.alerts.has_key?("Deprecated ERb helper calls")
284
+
285
+ end
286
+
287
+ def test_check_old_helpers_lets_regular_blocks_pass
288
+ make_file("app/views/users/", "another_test.html.erb", "<b>blah blah blah</b><% @some_items.each do |item| %> <label>doo dah</label> <%= item %> <% end %>")
289
+ @checker.check_old_helpers
290
+
291
+ assert_equal @checker.alerts.has_key?("Deprecated ERb helper calls"), false
292
+ end
293
+
294
+ def test_check_old_helpers_lets_regular_blocks_pass
295
+ make_file("app/views/users/", "another_test.html.erb", "<b>blah blah blah</b><% @some_items.each do |item| %> <label>doo dah</label> <%= item %> <% end %>")
296
+ @checker.check_old_helpers
297
+
298
+ assert_equal false, @checker.alerts.has_key?("Deprecated ERb helper calls")
299
+ end
300
+
301
+ def test_check_old_ajax_helpers
302
+ make_file("app/views/sections", "section.js", "<%= link_to_remote 'section-', :update => 'sections', :url => {:action => :destroy, :controller => 'sections', :id => @section.id } %>")
303
+ @checker.check_old_ajax_helpers
304
+
305
+ assert @checker.alerts.has_key?("Deprecated AJAX helper calls")
306
+ end
307
+
308
+ def test_check_old_ajax_helpers
309
+ make_file("app/controllers", "application_controller.rb", "filter_parameter_logging :password")
310
+ @checker.check_old_filter_parameter
311
+
312
+ assert @checker.alerts.has_key?("Deprecated filter_parameter_logging calls")
313
+ end
314
+
315
+ def test_check_old_ajax_helpers_empty
316
+ @checker.check_old_ajax_helpers
317
+
318
+ assert ! @checker.alerts.has_key?("Deprecated AJAX helper calls")
319
+ end
320
+
321
+ def test_check_old_action_mailer_sent_on_setting
322
+ make_file("app/models", "mailer.rb", "sent_on Time.now")
323
+ @checker.check_old_action_mailer_sent_on_setting
324
+
325
+ assert @checker.alerts.has_key?("Deprecated ActionMailer attribute :sent_on")
326
+ end
327
+
328
+ def teardown
329
+ clear_files
330
+
331
+ Dir.chdir(@old_dir)
332
+ end
333
+
334
+ def make_file(where, name=nil, contents=nil)
335
+ FileUtils.mkdir_p "#{BASE_ROOT}/#{where}"
336
+ File.open("#{BASE_ROOT}/#{where}/#{name}", "w+") do |f|
337
+ f.write(contents)
338
+ end if name
339
+ end
340
+
341
+ def clear_files
342
+ FileUtils.rm_rf(Dir.glob("#{BASE_ROOT}/*"))
343
+ end
344
+ end
@@ -0,0 +1,72 @@
1
+ require 'test_helper'
2
+ require 'gemfile_generator'
3
+
4
+ # Stub out methods on upgrader class
5
+ module Rails
6
+ module Upgrading
7
+ class GemfileGenerator
8
+ attr_writer :environment_code
9
+
10
+ def has_environment?
11
+ true
12
+ end
13
+
14
+ def environment_code
15
+ @environment_code
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ class GemfileGeneratorTest < ActiveSupport::TestCase
22
+ PREAMBLE = <<STR
23
+ # Edit this Gemfile to bundle your application's dependencies.
24
+ # This preamble is the current preamble for Rails 3 apps; edit as needed.
25
+ source 'http://rubygems.org'
26
+
27
+ gem 'rails', '3.0.6'
28
+
29
+ STR
30
+
31
+ def test_generates_with_no_gems
32
+ generator = Rails::Upgrading::GemfileGenerator.new
33
+ generator.environment_code = ""
34
+
35
+ assert_equal PREAMBLE, generator.generate_gemfile
36
+ end
37
+
38
+ def test_generates_with_gem
39
+ generator = Rails::Upgrading::GemfileGenerator.new
40
+ generator.environment_code = "config.gem 'camping'"
41
+
42
+ assert_equal PREAMBLE + "gem 'camping'", generator.generate_gemfile
43
+ end
44
+
45
+ def test_generates_with_version
46
+ generator = Rails::Upgrading::GemfileGenerator.new
47
+ generator.environment_code = "config.gem 'camping', :version => '2.1.1'"
48
+
49
+ assert_equal PREAMBLE + "gem 'camping', '2.1.1'", generator.generate_gemfile
50
+ end
51
+
52
+ def test_can_add_sources
53
+ generator = Rails::Upgrading::GemfileGenerator.new
54
+ generator.environment_code = "config.gem 'camping', :source => 'http://code.whytheluckystiff.net'"
55
+
56
+ assert_equal PREAMBLE + "source 'http://code.whytheluckystiff.net'\ngem 'camping'", generator.generate_gemfile
57
+ end
58
+
59
+ def test_changes_lib_to_new_key
60
+ generator = Rails::Upgrading::GemfileGenerator.new
61
+ generator.environment_code = "config.gem 'camping', :lib => 'kamping'"
62
+
63
+ assert_equal PREAMBLE + "gem 'camping', :require => 'kamping'", generator.generate_gemfile
64
+ end
65
+
66
+ def test_generates_with_all_options
67
+ generator = Rails::Upgrading::GemfileGenerator.new
68
+ generator.environment_code = "config.gem 'camping', :lib => 'kamping', :source => 'http://code.whytheluckystiff.net', :version => '2.1.1'"
69
+
70
+ assert_equal PREAMBLE + "source 'http://code.whytheluckystiff.net'\ngem 'camping', '2.1.1', :require => 'kamping'", generator.generate_gemfile
71
+ end
72
+ end