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,22 @@
1
+ require 'spec/spec_helper'
2
+
3
+ # Ensures that the Extension initializes correctly
4
+ describe LayoutsExtension do
5
+
6
+ context 'activate' do
7
+
8
+ describe 'share layouts' do
9
+ it 'should have a RailsPage class to call' do
10
+ RailsPage.should_not be_nil
11
+ end
12
+ it 'should extend ActionController base methods' do
13
+ ActionController::Base.included_modules.include?(ShareLayouts::Controllers::ActionController).should be_true
14
+ end
15
+ it 'should extend ActionView helper methods' do
16
+ ActionView::Base.included_modules.include?(ShareLayouts::Helpers::ActionView).should be_true
17
+ end
18
+ end
19
+
20
+ end
21
+
22
+ end
File without changes
@@ -0,0 +1,63 @@
1
+ require 'spec/spec_helper'
2
+ require 'ostruct'
3
+
4
+ describe RailsPage do
5
+ test_helper :render, :page
6
+ dataset :layouts_layouts, :layouts_pages
7
+
8
+ before(:each) do
9
+ @page = RailsPage.new(page_params(:class_name => "RailsPage"))
10
+ end
11
+
12
+ it "should redefine_breadcrumbs_tag" do
13
+ @page.should respond_to("tag:old_breadcrumbs")
14
+ @page.should respond_to("tag:breadcrumbs")
15
+
16
+ @page.breadcrumbs = "some breadcrumbs"
17
+ @page.should render("<r:breadcrumbs />").as("some breadcrumbs")
18
+ end
19
+
20
+ it "should use_old_breadcrumbs_tag_if_breadcrumbs_attr_is_nil" do
21
+ @page = pages(:rails)
22
+ @page.breadcrumbs = nil
23
+ @page.should render("<r:breadcrumbs nolinks='true' />").as("parent &gt; App page")
24
+ end
25
+
26
+ it "should build_parts_from_hash" do
27
+ hash = {:body => "body", :sidebar => "sidebar"}
28
+ @page.build_parts_from_hash!(hash)
29
+ @page.parts.size.should == hash.keys.size
30
+ # Make sure we don't save them to the DB
31
+ @page.parts.all?(&:new_record?).should be_true
32
+ end
33
+
34
+ it "should find_rails_page_for_sub_urls_that_do_not_match_an_existing_page" do
35
+ Page.find_by_url('/app/').should == pages(:rails)
36
+ Page.find_by_url('/app/some-other-url/').should == pages(:rails)
37
+ Page.find_by_url('/app/some-other-url/sub-url/').should == pages(:rails)
38
+ end
39
+
40
+ it "should find_page_if_sub_url_matches_one" do
41
+ Page.find_by_url('/app/child-page/').should == pages(:rails_child)
42
+ end
43
+
44
+ it "should find_page_for_non_sub_urls" do
45
+ Page.find_by_url('/other/').should == pages(:other)
46
+ end
47
+
48
+ it "should defer_to_default_url_when_not_initialized" do
49
+ pages(:rails).url.should == '/app/'
50
+ end
51
+
52
+ it "should modify_existing_parts_but_not_save_them" do
53
+ @page = pages(:rails)
54
+ @page.parts.create(:name => "sidebar", :content => "This is the sidebar.")
55
+
56
+ @page.build_parts_from_hash!(:body => "This is the body")
57
+ @page.part(:sidebar).content.should == 'This is the sidebar.'
58
+
59
+ @page.build_parts_from_hash!(:sidebar => "OVERRIDE")
60
+ @page.part(:sidebar).content.should == 'OVERRIDE'
61
+ @page.part(:sidebar).reload.content.should == 'This is the sidebar.'
62
+ end
63
+ end
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --format specdoc
3
+ --loadby mtime
@@ -0,0 +1,22 @@
1
+ unless defined? RADIANT_ROOT
2
+ ENV["RAILS_ENV"] = "test"
3
+ case
4
+ when ENV["RADIANT_ENV_FILE"]
5
+ require ENV["RADIANT_ENV_FILE"]
6
+ when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
7
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../../")}/config/environment"
8
+ else
9
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
10
+ end
11
+ end
12
+ require "#{RADIANT_ROOT}/spec/spec_helper"
13
+
14
+ Dataset::Resolver.default << (File.dirname(__FILE__) + "/datasets")
15
+
16
+ if File.directory?(File.dirname(__FILE__) + "/matchers")
17
+ Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }
18
+ end
19
+
20
+ Spec::Runner.configure do |config|
21
+ config.mock_with :rr
22
+ end
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "trusty-layouts-extension"
4
+ Gem::Specification.new do |s|
5
+ s.name = %q{trusty-layouts-extension}
6
+ s.version = "1.0.0"
7
+
8
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
+ s.authors = ["Eric Sipple", "Michael Klett", "Jim Gay", "William Ross", "Tony Issakov", "Dirk Kelly"]
10
+ s.date = %q{2014-10-06}
11
+ s.description = %q{Extends Trusty CMS Layouts to support nesting, sharing with Rails Controllers and rendering HAML}
12
+ s.email = %q{sipple@trustarts.org}
13
+ s.homepage = %q{https://github.com/pgharts/trusty-share-layouts-extension}
14
+ s.summary = %q{Extends Trusty CMS Layouts to support nesting, sharing with Rails Controllers and rendering HAML}
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ ignores = if File.exist?('.gitignore')
19
+ File.read('.gitignore').split("\n").inject([]) {|a,p| a + Dir[p] }
20
+ else
21
+ []
22
+ end
23
+ s.files = Dir['**/*'] - ignores
24
+ s.test_files = Dir['test/**/*','spec/**/*','features/**/*'] - ignores
25
+ # s.executables = Dir['bin/*'] - ignores
26
+ s.require_paths = ["lib"]
27
+
28
+ s.add_dependency 'trusty-cms', '>= 1.0.0'
29
+
30
+ end
31
+
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Jeremy McAnally
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,26 @@
1
+ = rails-upgrade
2
+
3
+ A simple battery of scripts for upgrading Rails app/checking them for required updates. This application should work on Rails 2.x and 3.0, with a focus on upgrading to 3.0.
4
+
5
+ == Usage
6
+
7
+ You need to install this plugin first:
8
+
9
+ script/plugin install git://github.com/rails/rails_upgrade.git
10
+
11
+ Then you can run its rake tasks to check your application:
12
+
13
+ # Check your app for required upgrades
14
+ rake rails:upgrade:check
15
+
16
+ # Backup your likely modified files that might be overwritten by the generator
17
+ rake rails:upgrade:backup
18
+
19
+ # Generate a new route file
20
+ rake rails:upgrade:routes
21
+
22
+ # Generate a Gemfile from your config.gem directives
23
+ rake rails:upgrade:gems
24
+
25
+ # Generate code for a new config/application.rb from your environment.rb
26
+ rake rails:upgrade:configuration
@@ -0,0 +1,22 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ Rake::TestTask.new do |t|
9
+ t.libs << 'lib'
10
+ t.libs << 'test'
11
+ t.test_files = FileList['test/*_test.rb']
12
+ t.verbose = true
13
+ end
14
+
15
+ desc 'Generate documentation for the rails_upgrade plugin.'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'Rails-upgrade'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
+ rdoc.rdoc_files.include('README')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
@@ -0,0 +1,2 @@
1
+ # Get long stack traces for easier debugging; you'll thank me later.
2
+ Rails.backtrace_cleaner.remove_silencers! if Rails.respond_to?(:backtrace_cleaner)
@@ -0,0 +1,38 @@
1
+ puts "Thanks for installing the Rails upgrade plugin. This is a set of generators and analysis tools to help you upgrade your application to Rails 3. It consists of three tasks...
2
+
3
+ To get a feel for what you'll need to change to get your app running, run the application analysis:
4
+
5
+ rake rails:upgrade:check
6
+
7
+ This should give you an idea of the manual changes that need to be done, but you'll probably want to upgrade some of those automatically. The fastest way to do this is to run 'rails .', which will simply generate a new app on top of your existing code. But this generation also has the effect of replacing some existing files, some of which you might not want to replace. To back those up, first run:
8
+
9
+ rake rails:upgrade:backup
10
+
11
+ That will backup files you've probably edited that will be replaced in the upgrade; if you finish the upgrade and find that you don't need the old copies, just delete them. Otherwise, copy their contents back into the new files or run one of the following upgraders...
12
+
13
+ Routes upgrader
14
+ ===============
15
+
16
+ To generate a new routes file from your existing routes file, simply run the following Rake task:
17
+
18
+ rake rails:upgrade:routes
19
+
20
+ This will output a new routes file that you can copy and paste or pipe into a new, Rails 3 compatible config/routes.rb.
21
+
22
+ Gemfile generator
23
+ =================
24
+
25
+ Creating a new Gemfile is as simple as running:
26
+
27
+ rake rails:upgrade:gems
28
+
29
+ This task will extract your config.gem calls and generate code you can put into a bundler compatible Gemfile.
30
+
31
+ Configuration generator
32
+ =======================
33
+
34
+ Much of the configuration information that lived in environment.rb now belongs in a new file named config/application.rb; use the following task to generate code you can put into config/application.rb from your existing config/environment.rb:
35
+
36
+ rake rails:upgrade:configuration
37
+
38
+ "
@@ -0,0 +1,506 @@
1
+ require 'open3'
2
+
3
+ module Rails
4
+ module Upgrading
5
+ class ApplicationChecker
6
+ def initialize
7
+ @issues = []
8
+
9
+ raise NotInRailsAppError unless in_rails_app?
10
+ end
11
+
12
+ def in_rails_app?
13
+ File.exist?("config/environment.rb")
14
+ end
15
+
16
+ # Run all the check methods
17
+ def run
18
+ # Ruby 1.8 returns method names as strings whereas 1.9 uses symbols
19
+ the_methods = (self.public_methods - Object.methods) - [:run, :initialize, "run", "initialize"]
20
+
21
+ the_methods.each {|m| send m }
22
+ end
23
+
24
+ # Check for deprecated ActiveRecord calls
25
+ def check_ar_methods
26
+ files = []
27
+ ["find(:all", "find(:first", "find.*:conditions =>", ":joins =>"].each do |v|
28
+ lines = grep_for(v, "app/")
29
+ files += extract_filenames(lines) || []
30
+ end
31
+
32
+ unless files.empty?
33
+ alert(
34
+ "Soon-to-be-deprecated ActiveRecord calls",
35
+ "Methods such as find(:all), find(:first), finds with conditions, and the :joins option will soon be deprecated.",
36
+ "http://m.onkey.org/2010/1/22/active-record-query-interface",
37
+ files
38
+ )
39
+ end
40
+
41
+ lines = grep_for("named_scope", "app/models/")
42
+ files = extract_filenames(lines)
43
+
44
+ unless files.empty?
45
+ alert(
46
+ "named_scope is now just scope",
47
+ "The named_scope method has been renamed to just scope.",
48
+ "http://github.com/rails/rails/commit/d60bb0a9e4be2ac0a9de9a69041a4ddc2e0cc914",
49
+ files
50
+ )
51
+ end
52
+ end
53
+
54
+ def check_validation_on_methods
55
+ files = []
56
+
57
+ ["validate_on_create", "validate_on_update"].each do |v|
58
+ lines = grep_for(v, "app/models/")
59
+ files += extract_filenames(lines) || []
60
+ end
61
+
62
+ unless files.empty?
63
+ alert(
64
+ "Updated syntax for validate_on_* methods",
65
+ "Validate-on-callback methods (validate_on_create/validate_on_destroy) have been changed to validate :x, :on => :create",
66
+ "https://rails.lighthouseapp.com/projects/8994/tickets/3880-validate_on_create-and-validate_on_update-no-longer-seem-to-exist",
67
+ files
68
+ )
69
+ end
70
+ end
71
+
72
+ def check_before_validation_on_methods
73
+ files = []
74
+
75
+ %w(before_validation_on_create before_validation_on_update).each do |v|
76
+ lines = grep_for(v, "app/models/")
77
+ files += extract_filenames(lines) || []
78
+ end
79
+
80
+ unless files.empty?
81
+ alert(
82
+ "Updated syntax for before_validation_on_* methods",
83
+ "before_validation_on_* methods have been changed to before_validation(:on => :create/:update) { ... }",
84
+ "https://rails.lighthouseapp.com/projects/8994/tickets/4699-before_validation_on_create-and-before_validation_on_update-doesnt-exist",
85
+ files
86
+ )
87
+ end
88
+ end
89
+
90
+ # Check for deprecated router syntax
91
+ def check_routes
92
+ lines = ["map\\.", "ActionController::Routing::Routes", "\\.resources"].map do |v|
93
+ grep_for(v, "config/routes.rb").empty? ? nil : true
94
+ end.compact
95
+
96
+ unless lines.empty?
97
+ alert(
98
+ "Old router API",
99
+ "The router API has totally changed.",
100
+ "http://yehudakatz.com/2009/12/26/the-rails-3-router-rack-it-up/",
101
+ "config/routes.rb"
102
+ )
103
+ end
104
+ end
105
+
106
+ # Check for deprecated test_help require
107
+ def check_test_help
108
+ files = []
109
+
110
+ # Hate to duplicate code, but we have to double quote this one...
111
+ lines = grep_for("\'test_help\'", "test/", true)
112
+ files += extract_filenames(lines) || []
113
+
114
+ lines = grep_for("\"test_help\"", "test/")
115
+ files += extract_filenames(lines) || []
116
+
117
+ files.uniq!
118
+
119
+ unless files.empty?
120
+ alert(
121
+ "Deprecated test_help path",
122
+ "You now must require 'rails/test_help' not just 'test_help'.",
123
+ "http://weblog.rubyonrails.org/2009/9/1/gem-packaging-best-practices",
124
+ files
125
+ )
126
+ end
127
+ end
128
+
129
+ # Check for old (pre-application.rb) environment.rb file
130
+ def check_environment
131
+ unless File.exist?("config/application.rb")
132
+ alert(
133
+ "New file needed: config/application.rb",
134
+ "You need to add a config/application.rb.",
135
+ "http://omgbloglol.com/post/353978923/the-path-to-rails-3-approaching-the-upgrade",
136
+ "config/application.rb"
137
+ )
138
+ end
139
+
140
+ lines = grep_for("config.", "config/environment.rb")
141
+
142
+ unless lines.empty?
143
+ alert(
144
+ "Old environment.rb",
145
+ "environment.rb doesn't do what it used to; you'll need to move some of that into application.rb.",
146
+ "http://omgbloglol.com/post/353978923/the-path-to-rails-3-approaching-the-upgrade",
147
+ "config/environment.rb"
148
+ )
149
+ end
150
+ end
151
+
152
+ # Check for deprecated constants
153
+ def check_deprecated_constants
154
+ files = []
155
+ ["RAILS_ENV", "RAILS_ROOT", "RAILS_DEFAULT_LOGGER"].each do |v|
156
+ lines = grep_for(v, "app/")
157
+ files += extract_filenames(lines) || []
158
+
159
+ lines = grep_for(v, "lib/")
160
+ files += extract_filenames(lines) || []
161
+ end
162
+
163
+ unless files.empty?
164
+ alert(
165
+ "Deprecated constant(s)",
166
+ "Constants like Rails.env, Rails.root, and RAILS_DEFAULT_LOGGER are now deprecated.",
167
+ "http://litanyagainstfear.com/blog/2010/02/03/the-rails-module/",
168
+ files.uniq
169
+ )
170
+ end
171
+ end
172
+
173
+ # Check for old-style config.gem calls
174
+ def check_gems
175
+ lines = grep_for("config.gem ", "config/*.rb")
176
+ lines += grep_for("config.gem ", "config/**/*.rb")
177
+ files = extract_filenames(lines)
178
+
179
+ unless files.empty?
180
+ alert(
181
+ "Old gem bundling (config.gems)",
182
+ "The old way of bundling is gone now. You need a Gemfile for bundler.",
183
+ "http://omgbloglol.com/post/353978923/the-path-to-rails-3-approaching-the-upgrade",
184
+ files
185
+ )
186
+ end
187
+ end
188
+
189
+ # Checks for old mailer syntax in both mailer classes and those
190
+ # classes utilizing the mailers
191
+ def check_mailers
192
+ lines = grep_for("deliver_", "app/models/ #{base_path}app/controllers/ #{base_path}app/observers/")
193
+ files = extract_filenames(lines)
194
+
195
+ unless files.empty?
196
+ alert(
197
+ "Deprecated ActionMailer API",
198
+ "You're using the old ActionMailer API to send e-mails in a controller, model, or observer.",
199
+ "http://lindsaar.net/2010/1/26/new-actionmailer-api-in-rails-3",
200
+ files
201
+ )
202
+ end
203
+
204
+ files = []
205
+ ["recipients ", "attachment(?!s) ", "(?<!:)subject ", "(?<!:)from "].each do |v|
206
+ lines = grep_for_with_perl_regex(v, "app/models/")
207
+ files += extract_filenames(lines) || []
208
+ end
209
+
210
+ unless files.empty?
211
+ alert(
212
+ "Old ActionMailer class API",
213
+ "You're using the old API in a mailer class.",
214
+ "http://lindsaar.net/2010/1/26/new-actionmailer-api-in-rails-3",
215
+ files
216
+ )
217
+ end
218
+ end
219
+
220
+ # Checks for old-style generators
221
+ def check_generators
222
+ generators = Dir.glob(base_path + "vendor/plugins/**/generators/**/")
223
+
224
+ unless generators.empty?
225
+ files = generators.reject do |g|
226
+ grep_for("def manifest", g).empty?
227
+ end.compact
228
+
229
+ unless files.empty?
230
+ alert(
231
+ "Old Rails generator API",
232
+ "A plugin in the app is using the old generator API (a new one may be available at http://github.com/trydionel/rails3-generators).",
233
+ "http://blog.plataformatec.com.br/2010/01/discovering-rails-3-generators/",
234
+ files
235
+ )
236
+ end
237
+ end
238
+ end
239
+
240
+ # Checks a list of known broken plugins and gems
241
+ def check_plugins
242
+ # This list is off the wiki; will need to be updated often, esp. since RSpec is working on it
243
+ bad_plugins = ["rspec", "rspec-rails", "hoptoad", "authlogic", "nifty-generators",
244
+ "restful_authentication", "searchlogic", "cucumber", "cucumber-rails", "devise",
245
+ "inherited_resources"]
246
+
247
+ bad_plugins = bad_plugins.map do |p|
248
+ p if File.exist?("#{base_path}vendor/plugins/#{p}") || !Dir.glob("#{base_path}vendor/gems/#{p}-*").empty?
249
+ end.compact
250
+
251
+ unless bad_plugins.empty?
252
+ alert(
253
+ "Known broken plugins",
254
+ "At least one plugin in your app is broken (according to the wiki). Most of project maintainers are rapidly working towards compatibility, but do be aware you may encounter issues.",
255
+ "http://wiki.rubyonrails.org/rails/version3/plugins_and_gems",
256
+ bad_plugins
257
+ )
258
+ end
259
+ end
260
+
261
+ # Checks for old-style ERb helpers
262
+ def check_old_helpers
263
+
264
+ lines = grep_for("<% .*content_tag.* do.*%>", "app/views/**/*")
265
+ lines += grep_for("<% .*javascript_tag.* do.*%>", "app/views/**/*")
266
+ lines += grep_for("<% .*form_for.* do.*%>", "app/views/**/*")
267
+ lines += grep_for("<% .*form_tag.* do.*%>", "app/views/**/*")
268
+ lines += grep_for("<% .*fields_for.* do.*%>", "app/views/**/*")
269
+ lines += grep_for("<% .*field_set_tag.* do.*%>", "app/views/**/*")
270
+
271
+ files = extract_filenames(lines)
272
+
273
+ if !files.blank?
274
+ alert(
275
+ "Deprecated ERb helper calls",
276
+ "Block helpers that use concat (e.g., form_for) should use <%= instead of <%. The current form will continue to work for now, but you will get deprecation warnings since this form will go away in the future.",
277
+ "http://weblog.rubyonrails.org/",
278
+ files
279
+ )
280
+ end
281
+ end
282
+
283
+ # Checks for old-style AJAX helpers
284
+ def check_old_ajax_helpers
285
+ files = []
286
+ ['link_to_remote','form_remote_tag','remote_form_for', 'form_remote_for'].each do |type|
287
+ lines = grep_for(type, "app/views/**/*")
288
+ inner_files = extract_filenames(lines)
289
+ files += inner_files unless inner_files.nil?
290
+ end
291
+
292
+ unless files.empty?
293
+ alert(
294
+ "Deprecated AJAX helper calls",
295
+ "AJAX javascript helpers have been switched to be unobtrusive and use :remote => true instead of having a seperate function to handle remote requests.",
296
+ "http://blog.jordanwest.me/modest-rubyist-archive/rails-3-ujs-and-csrf-meta-tags",
297
+ files
298
+ )
299
+ end
300
+ end
301
+
302
+ # Checks for old cookie secret settings
303
+ def check_old_cookie_secret
304
+ lines = grep_for("ActionController::Base.cookie_verifier_secret = ", "config/**/*")
305
+ files = extract_filenames(lines)
306
+
307
+ unless files.empty?
308
+ alert(
309
+ "Deprecated cookie secret setting",
310
+ "Previously, cookie secret was set directly on ActionController::Base; it's now config.secret_token.",
311
+ "http://lindsaar.net/2010/4/7/rails_3_session_secret_and_session_store",
312
+ files
313
+ )
314
+ end
315
+ end
316
+
317
+ def check_old_session_secret
318
+ lines = grep_for("ActionController::Base.session = {", "config/**/*")
319
+ files = extract_filenames(lines)
320
+
321
+ unless files.empty?
322
+ alert(
323
+ "Deprecated session secret setting",
324
+ "Previously, session secret was set directly on ActionController::Base; it's now config.secret_token.",
325
+ "http://lindsaar.net/2010/4/7/rails_3_session_secret_and_session_store",
326
+ files
327
+ )
328
+ end
329
+ end
330
+
331
+ # Checks for old session settings
332
+ def check_old_session_setting
333
+ lines = grep_for("ActionController::Base.session_store", "config/**/*")
334
+ files = extract_filenames(lines)
335
+
336
+ unless files.empty?
337
+ alert(
338
+ "Old session store setting",
339
+ "Previously, session store was set directly on ActionController::Base; it's now config.session_store :whatever.",
340
+ "http://lindsaar.net/2010/4/7/rails_3_session_secret_and_session_store",
341
+ files
342
+ )
343
+ end
344
+ end
345
+
346
+ #Check for old ActionMailer :sent_on attributes
347
+ def check_old_action_mailer_sent_on_setting
348
+ files = []
349
+ lines = grep_for("sent_on", "app/*")
350
+ files += extract_filenames(lines) || []
351
+
352
+ unless files.empty?
353
+ alert(
354
+ "Deprecated ActionMailer attribute :sent_on",
355
+ "Using the new mailer API, you can specify :date to the mail method.",
356
+ "http://stackoverflow.com/questions/7367185/weird-error-when-delivering-mail-undefined-method-index-for-2011-09-09-2215",
357
+ files
358
+ )
359
+ end
360
+ end
361
+ def check_old_filter_parameter
362
+ files = []
363
+ lines = grep_for("filter_parameter_logging", "app/controllers/*")
364
+ files += extract_filenames(lines) || []
365
+
366
+ unless files.empty?
367
+ alert(
368
+ "Deprecated filter_parameter_logging calls",
369
+ "The list of filtered parameters are now stored in /config/application.rb. For example: config.filter_parameters += [:password]",
370
+ "http://asciicasts.com/episodes/224-controllers-in-rails-3",
371
+ files
372
+ )
373
+ end
374
+ end
375
+ private
376
+ def grep_for_with_perl_regex(text, where = "./", double_quote = false)
377
+ grep_for(text, where, double_quote, true)
378
+ end
379
+
380
+ # Find a string in a set of files; calls +find_with_grep+ and +find_with_rak+
381
+ # depending on platform.
382
+ #
383
+ # TODO: Figure out if this works on Windows.
384
+ def grep_for(text, where = "./", double_quote = false, perl_regex = false)
385
+ # If they're on Windows, they probably don't have grep.
386
+ @probably_has_grep ||= (Config::CONFIG['host_os'].downcase =~ /mswin|windows|mingw/).nil?
387
+
388
+ # protect against double root paths in Rails 3
389
+ where.gsub!(Regexp.new(base_path),'')
390
+
391
+ lines = if @probably_has_grep
392
+ find_with_grep(text, base_path + where, double_quote, perl_regex)
393
+ else
394
+ find_with_rak(text, base_path + where, double_quote)
395
+ end
396
+
397
+ # ignore comments
398
+ lines.gsub /^(\/[^:]+:)?\s*#.+$/m, ""
399
+ end
400
+
401
+ # Sets a base path for finding files; mostly for testing
402
+ def base_path
403
+ Dir.pwd + "/"
404
+ end
405
+
406
+ # Use the grep utility to find a string in a set of files
407
+ def find_with_grep(text, where, double_quote, perl_regex = false)
408
+ value = ""
409
+ # Specifically double quote for finding 'test_help'
410
+ command = if double_quote
411
+ "grep -rH #{"-P" if perl_regex} \"#{text}\" #{where} | grep -v \.svn"
412
+ else
413
+ "grep -rH #{"-P" if perl_regex} '#{text}' #{where} | grep -v \.svn"
414
+ end
415
+
416
+ Open3.popen3(command) do |stdin, stdout, stderr|
417
+ value = stdout.read
418
+ end
419
+ value
420
+ end
421
+
422
+ # Use the rak gem to grep the files (not yet implemented)
423
+ def find_with_rak(text, where, double_quote)
424
+ value = ""
425
+ Open3.popen3("rak --nogroup -l '#{Regexp.escape(text)}' #{where}") do |stdin, stdout, stderr|
426
+ value = stdout.read
427
+ end
428
+ value
429
+ end
430
+
431
+ # Extract the filenames from the grep output
432
+ def extract_filenames(output)
433
+ if @probably_has_grep
434
+ filenames = extract_filenames_from_grep(output)
435
+ else
436
+ filenames = extract_filenames_from_rak(output)
437
+ end
438
+
439
+ filenames.compact.map do |f|
440
+ f.gsub(base_path, "")
441
+ end
442
+ end
443
+
444
+ def extract_filenames_from_grep(output)
445
+ return [] if output.empty?
446
+
447
+ output.split("\n").map do |fn|
448
+ if m = fn.match(/^(.+?):/)
449
+ m[1]
450
+ end
451
+ end.compact.uniq
452
+ end
453
+
454
+ def extract_filenames_from_rak(output)
455
+ return [] if output.empty?
456
+
457
+ output.split("\n").uniq
458
+ end
459
+
460
+ # Terminal colors, borrowed from Thor
461
+ CLEAR = "\e[0m"
462
+ BOLD = "\e[1m"
463
+ RED = "\e[31m"
464
+ YELLOW = "\e[33m"
465
+ CYAN = "\e[36m"
466
+ WHITE = "\e[37m"
467
+
468
+ # Show an upgrade alert to the user
469
+ def alert(title, text, more_info_url, culprits)
470
+ if Config::CONFIG['host_os'].downcase =~ /mswin|windows|mingw/
471
+ basic_alert(title, text, more_info_url, culprits)
472
+ else
473
+ color_alert(title, text, more_info_url, culprits)
474
+ end
475
+ end
476
+
477
+ # Show an upgrade alert to the user. If we're on Windows, we can't
478
+ # use terminal colors, hence this method.
479
+ def basic_alert(title, text, more_info_url, culprits)
480
+ puts "** " + title
481
+ puts text
482
+ puts "More information: #{more_info_url}"
483
+ puts
484
+ puts "The culprits: "
485
+ Array(culprits).each do |c|
486
+ puts "\t- #{c}"
487
+ end
488
+ puts
489
+ end
490
+
491
+ # Show a colorful alert to the user
492
+ def color_alert(title, text, more_info_url, culprits)
493
+ puts "#{RED}#{BOLD}#{title}#{CLEAR}"
494
+ puts "#{WHITE}#{text}"
495
+ puts "#{BOLD}More information:#{CLEAR} #{CYAN}#{more_info_url}"
496
+ puts
497
+ puts "#{WHITE}The culprits: "
498
+ Array(culprits).each do |c|
499
+ puts "#{YELLOW}\t- #{c}"
500
+ end
501
+ ensure
502
+ puts "#{CLEAR}"
503
+ end
504
+ end
505
+ end
506
+ end