railties 3.0.0.beta4 → 3.0.0.rc

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/CHANGELOG +24 -6
  2. data/README.rdoc +25 -0
  3. data/guides/assets/javascripts/code_highlighter.js +0 -0
  4. data/guides/assets/javascripts/guides.js +0 -0
  5. data/guides/assets/stylesheets/print.css +0 -0
  6. data/guides/assets/stylesheets/reset.css +0 -0
  7. data/guides/assets/stylesheets/style.css +0 -0
  8. data/guides/source/3_0_release_notes.textile +5 -3
  9. data/guides/source/action_controller_overview.textile +19 -0
  10. data/guides/source/active_record_basics.textile +27 -21
  11. data/guides/source/active_record_querying.textile +39 -37
  12. data/guides/source/{activerecord_validations_callbacks.textile → active_record_validations_callbacks.textile} +30 -29
  13. data/guides/source/active_support_core_extensions.textile +232 -107
  14. data/guides/source/api_documentation_guidelines.textile +187 -0
  15. data/guides/source/association_basics.textile +45 -1
  16. data/guides/source/configuring.textile +7 -7
  17. data/guides/source/contributing_to_rails.textile +42 -15
  18. data/guides/source/form_helpers.textile +1 -1
  19. data/guides/source/generators.textile +37 -37
  20. data/guides/source/getting_started.textile +11 -11
  21. data/guides/source/i18n.textile +1 -1
  22. data/guides/source/index.html.erb +14 -6
  23. data/guides/source/initialization.textile +130 -124
  24. data/guides/source/layout.html.erb +5 -2
  25. data/guides/source/layouts_and_rendering.textile +2 -2
  26. data/guides/source/migrations.textile +4 -3
  27. data/guides/source/plugins.textile +15 -15
  28. data/guides/source/rails_application_templates.textile +2 -2
  29. data/guides/source/routing.textile +83 -62
  30. data/guides/source/security.textile +2 -2
  31. data/guides/w3c_validator.rb +30 -6
  32. data/lib/rails.rb +3 -3
  33. data/lib/rails/application.rb +43 -19
  34. data/lib/rails/application/bootstrap.rb +2 -0
  35. data/lib/rails/application/configuration.rb +3 -3
  36. data/lib/rails/application/finisher.rb +6 -6
  37. data/lib/rails/cli.rb +1 -19
  38. data/lib/rails/commands.rb +5 -5
  39. data/lib/rails/commands/application.rb +1 -1
  40. data/lib/rails/commands/console.rb +1 -4
  41. data/lib/rails/commands/generate.rb +0 -0
  42. data/lib/rails/commands/plugin.rb +57 -52
  43. data/lib/rails/commands/runner.rb +2 -1
  44. data/lib/rails/commands/server.rb +6 -2
  45. data/lib/rails/configuration.rb +2 -3
  46. data/lib/rails/console/app.rb +0 -2
  47. data/lib/rails/engine.rb +14 -15
  48. data/lib/rails/engine/configuration.rb +5 -5
  49. data/lib/rails/generators.rb +2 -3
  50. data/lib/rails/generators/actions.rb +4 -4
  51. data/lib/rails/generators/base.rb +1 -1
  52. data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +1 -6
  53. data/lib/rails/generators/erb/scaffold/templates/_form.html.erb +4 -4
  54. data/lib/rails/generators/erb/scaffold/templates/edit.html.erb +3 -3
  55. data/lib/rails/generators/erb/scaffold/templates/index.html.erb +7 -7
  56. data/lib/rails/generators/erb/scaffold/templates/new.html.erb +2 -2
  57. data/lib/rails/generators/erb/scaffold/templates/show.html.erb +3 -3
  58. data/lib/rails/generators/generated_attribute.rb +2 -1
  59. data/lib/rails/generators/named_base.rb +24 -0
  60. data/lib/rails/generators/rails/app/app_generator.rb +10 -9
  61. data/lib/rails/generators/rails/app/templates/Gemfile +4 -3
  62. data/lib/rails/generators/rails/app/templates/README +6 -31
  63. data/lib/rails/generators/rails/app/templates/Rakefile +1 -1
  64. data/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb +0 -1
  65. data/lib/rails/generators/rails/app/templates/app/mailers/.empty_directory +0 -0
  66. data/lib/rails/generators/rails/app/templates/config/application.rb +11 -11
  67. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +36 -24
  68. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +1 -1
  69. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +1 -1
  70. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +3 -0
  71. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +3 -0
  72. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +3 -0
  73. data/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb +1 -1
  74. data/lib/rails/generators/rails/app/templates/config/initializers/secret_token.rb.tt +2 -2
  75. data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +2 -2
  76. data/lib/rails/generators/rails/app/templates/config/routes.rb +1 -1
  77. data/lib/rails/generators/rails/app/templates/public/index.html +0 -17
  78. data/lib/rails/generators/rails/app/templates/public/javascripts/prototype.js +2027 -900
  79. data/lib/rails/generators/rails/app/templates/public/javascripts/rails.js +114 -57
  80. data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +1 -1
  81. data/lib/rails/generators/rails/model/USAGE +1 -1
  82. data/lib/rails/generators/rails/resource/resource_generator.rb +4 -14
  83. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +0 -2
  84. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +28 -30
  85. data/lib/rails/generators/resource_helpers.rb +1 -1
  86. data/lib/rails/generators/test_case.rb +25 -11
  87. data/lib/rails/generators/test_unit/model/model_generator.rb +1 -1
  88. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +0 -1
  89. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +13 -15
  90. data/lib/rails/info.rb +1 -2
  91. data/lib/rails/info_routes.rb +1 -1
  92. data/lib/rails/initializable.rb +3 -16
  93. data/lib/rails/paths.rb +31 -36
  94. data/lib/rails/plugin.rb +10 -6
  95. data/lib/rails/rack/logger.rb +11 -13
  96. data/lib/rails/railtie.rb +14 -42
  97. data/lib/rails/ruby_version_check.rb +19 -5
  98. data/lib/rails/script_rails_loader.rb +29 -0
  99. data/lib/rails/tasks/annotations.rake +2 -2
  100. data/lib/rails/tasks/documentation.rake +47 -16
  101. data/lib/rails/tasks/framework.rake +9 -9
  102. data/lib/rails/tasks/middleware.rake +1 -1
  103. data/lib/rails/tasks/misc.rake +5 -5
  104. data/lib/rails/tasks/routes.rake +1 -1
  105. data/lib/rails/tasks/tmp.rake +5 -5
  106. data/lib/rails/test_unit/testing.rake +38 -14
  107. data/lib/rails/version.rb +1 -1
  108. metadata +29 -17
  109. data/README +0 -281
  110. data/lib/rails/application/routes_reloader.rb +0 -46
  111. data/lib/rails/log_subscriber.rb +0 -115
  112. data/lib/rails/log_subscriber/test_helper.rb +0 -97
  113. data/lib/rails/webrick_server.rb +0 -156
@@ -1,46 +0,0 @@
1
- module Rails
2
- class Application
3
- class RoutesReloader
4
- attr_reader :paths
5
-
6
- def initialize
7
- @paths, @last_change_at = [], nil
8
- end
9
-
10
- def changed_at
11
- routes_changed_at = nil
12
-
13
- paths.each do |path|
14
- config_changed_at = File.stat(path).mtime
15
-
16
- if routes_changed_at.nil? || config_changed_at > routes_changed_at
17
- routes_changed_at = config_changed_at
18
- end
19
- end
20
-
21
- routes_changed_at
22
- end
23
-
24
- def reload!
25
- routes = Rails::Application.routes
26
- routes.disable_clear_and_finalize = true
27
-
28
- routes.clear!
29
- paths.each { |path| load(path) }
30
- ActiveSupport.on_load(:action_controller) { routes.finalize! }
31
-
32
- nil
33
- ensure
34
- routes.disable_clear_and_finalize = false
35
- end
36
-
37
- def reload_if_changed
38
- current_change_at = changed_at
39
- if @last_change_at != current_change_at
40
- @last_change_at = current_change_at
41
- reload!
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,115 +0,0 @@
1
- require 'active_support/core_ext/class/inheritable_attributes'
2
- require 'active_support/notifications'
3
-
4
- module Rails
5
- # Rails::LogSubscriber is an object set to consume ActiveSupport::Notifications
6
- # on initialization with solely purpose of logging. The log subscriber dispatches
7
- # notifications to a regirested object based on its given namespace.
8
- #
9
- # An example would be ActiveRecord log subscriber responsible for logging queries:
10
- #
11
- # module ActiveRecord
12
- # class Railtie
13
- # class LogSubscriber < Rails::LogSubscriber
14
- # def sql(event)
15
- # "#{event.payload[:name]} (#{event.duration}) #{event.payload[:sql]}"
16
- # end
17
- # end
18
- # end
19
- # end
20
- #
21
- # It's finally registed as:
22
- #
23
- # Rails::LogSubscriber.add :active_record, ActiveRecord::Railtie::LogSubscriber.new
24
- #
25
- # So whenever a "sql.active_record" notification arrive to Rails::LogSubscriber,
26
- # it will properly dispatch the event (ActiveSupport::Notifications::Event) to
27
- # the sql method.
28
- #
29
- # This is useful because it avoids spanning several log subscribers just for logging
30
- # purposes(which slows down the main thread). Besides of providing a centralized
31
- # facility on top of Rails.logger.
32
- #
33
- # Log subscriber also has some helpers to deal with logging and automatically flushes
34
- # all logs when the request finishes (via action_dispatch.callback notification).
35
- class LogSubscriber
36
- mattr_accessor :colorize_logging
37
- self.colorize_logging = true
38
-
39
- # Embed in a String to clear all previous ANSI sequences.
40
- CLEAR = "\e[0m"
41
- BOLD = "\e[1m"
42
-
43
- # Colors
44
- BLACK = "\e[30m"
45
- RED = "\e[31m"
46
- GREEN = "\e[32m"
47
- YELLOW = "\e[33m"
48
- BLUE = "\e[34m"
49
- MAGENTA = "\e[35m"
50
- CYAN = "\e[36m"
51
- WHITE = "\e[37m"
52
-
53
- def self.add(namespace, log_subscriber, notifier = ActiveSupport::Notifications)
54
- log_subscribers << log_subscriber
55
- @flushable_loggers = nil
56
-
57
- log_subscriber.public_methods(false).each do |event|
58
- notifier.subscribe("#{event}.#{namespace}") do |*args|
59
- next if log_subscriber.logger.nil?
60
-
61
- begin
62
- log_subscriber.send(event, ActiveSupport::Notifications::Event.new(*args))
63
- rescue Exception => e
64
- Rails.logger.error "Could not log #{args[0].inspect} event. #{e.class}: #{e.message}"
65
- end
66
- end
67
- end
68
- end
69
-
70
- def self.log_subscribers
71
- @log_subscribers ||= []
72
- end
73
-
74
- def self.flushable_loggers
75
- @flushable_loggers ||= begin
76
- loggers = log_subscribers.map(&:logger)
77
- loggers.uniq!
78
- loggers.select { |l| l.respond_to?(:flush) }
79
- end
80
- end
81
-
82
- # Flush all log_subscribers' logger.
83
- def self.flush_all!
84
- flushable_loggers.each(&:flush)
85
- end
86
-
87
- # By default, we use the Rails.logger for logging.
88
- def logger
89
- Rails.logger
90
- end
91
-
92
- protected
93
-
94
- %w(info debug warn error fatal unknown).each do |level|
95
- class_eval <<-METHOD, __FILE__, __LINE__ + 1
96
- def #{level}(*args, &block)
97
- return unless logger
98
- logger.#{level}(*args, &block)
99
- end
100
- METHOD
101
- end
102
-
103
- # Set color by using a string or one of the defined constants. If a third
104
- # option is set to true, it also adds bold to the string. This is based
105
- # on Highline implementation and it automatically appends CLEAR to the end
106
- # of the returned String.
107
- #
108
- def color(text, color, bold=false)
109
- return text unless colorize_logging
110
- color = self.class.const_get(color.to_s.upcase) if color.is_a?(Symbol)
111
- bold = bold ? BOLD : ""
112
- "#{bold}#{color}#{text}#{CLEAR}"
113
- end
114
- end
115
- end
@@ -1,97 +0,0 @@
1
- require 'rails/log_subscriber'
2
-
3
- module Rails
4
- class LogSubscriber
5
- # Provides some helpers to deal with testing log subscribers by setting up
6
- # notifications. Take for instance ActiveRecord subscriber tests:
7
- #
8
- # class SyncLogSubscriberTest < ActiveSupport::TestCase
9
- # include Rails::LogSubscriber::TestHelper
10
- # Rails::LogSubscriber.add(:active_record, ActiveRecord::Railties::LogSubscriber.new)
11
- #
12
- # def test_basic_query_logging
13
- # Developer.all
14
- # wait
15
- # assert_equal 1, @logger.logged(:debug).size
16
- # assert_match /Developer Load/, @logger.logged(:debug).last
17
- # assert_match /SELECT \* FROM "developers"/, @logger.logged(:debug).last
18
- # end
19
- #
20
- # class SyncLogSubscriberTest < ActiveSupport::TestCase
21
- # include Rails::LogSubscriber::SyncTestHelper
22
- # include LogSubscriberTest
23
- # end
24
- #
25
- # class AsyncLogSubscriberTest < ActiveSupport::TestCase
26
- # include Rails::LogSubscriber::AsyncTestHelper
27
- # include LogSubscriberTest
28
- # end
29
- # end
30
- #
31
- # All you need to do is to ensure that your log subscriber is added to Rails::Subscriber,
32
- # as in the second line of the code above. The test helpers is reponsible for setting
33
- # up the queue, subscriptions and turning colors in logs off.
34
- #
35
- # The messages are available in the @logger instance, which is a logger with limited
36
- # powers (it actually do not send anything to your output), and you can collect them
37
- # doing @logger.logged(level), where level is the level used in logging, like info,
38
- # debug, warn and so on.
39
- #
40
- module TestHelper
41
- def setup
42
- @logger = MockLogger.new
43
- @notifier = ActiveSupport::Notifications::Notifier.new(queue)
44
-
45
- Rails::LogSubscriber.colorize_logging = false
46
-
47
- set_logger(@logger)
48
- ActiveSupport::Notifications.notifier = @notifier
49
- end
50
-
51
- def teardown
52
- set_logger(nil)
53
- ActiveSupport::Notifications.notifier = nil
54
- end
55
-
56
- class MockLogger
57
- attr_reader :flush_count
58
-
59
- def initialize
60
- @flush_count = 0
61
- @logged = Hash.new { |h,k| h[k] = [] }
62
- end
63
-
64
- def method_missing(level, message)
65
- @logged[level] << message
66
- end
67
-
68
- def logged(level)
69
- @logged[level].compact.map { |l| l.to_s.strip }
70
- end
71
-
72
- def flush
73
- @flush_count += 1
74
- end
75
- end
76
-
77
- # Wait notifications to be published.
78
- def wait
79
- @notifier.wait
80
- end
81
-
82
- # Overwrite if you use another logger in your log subscriber:
83
- #
84
- # def logger
85
- # ActiveRecord::Base.logger = @logger
86
- # end
87
- #
88
- def set_logger(logger)
89
- Rails.logger = logger
90
- end
91
-
92
- def queue
93
- ActiveSupport::Notifications::Fanout.new
94
- end
95
- end
96
- end
97
- end
@@ -1,156 +0,0 @@
1
- # Donated by Florian Gross
2
-
3
- require 'webrick'
4
- require 'cgi'
5
- require 'stringio'
6
- require 'dispatcher'
7
-
8
- include WEBrick
9
-
10
- class CGI #:nodoc:
11
- def stdinput
12
- @stdin || $stdin
13
- end
14
-
15
- def env_table
16
- @env_table || ENV
17
- end
18
-
19
- def initialize(type = "query", table = nil, stdin = nil)
20
- @env_table, @stdin = table, stdin
21
-
22
- if defined?(MOD_RUBY) && !ENV.key?("GATEWAY_INTERFACE")
23
- Apache.request.setup_cgi_env
24
- end
25
-
26
- extend QueryExtension
27
- @multipart = false
28
- if defined?(CGI_PARAMS)
29
- warn "do not use CGI_PARAMS and CGI_COOKIES"
30
- @params = CGI_PARAMS.dup
31
- @cookies = CGI_COOKIES.dup
32
- else
33
- initialize_query() # set @params, @cookies
34
- end
35
- @output_cookies = nil
36
- @output_hidden = nil
37
- end
38
- end
39
-
40
- # A custom dispatch servlet for use with WEBrick. It dispatches requests
41
- # (using the Rails Dispatcher) to the appropriate controller/action. By default,
42
- # it restricts WEBrick to a managing a single Rails request at a time, but you
43
- # can change this behavior by setting ActionController::Base.allow_concurrency
44
- # to true.
45
- class DispatchServlet < WEBrick::HTTPServlet::AbstractServlet
46
- # Start the WEBrick server with the given options, mounting the
47
- # DispatchServlet at <tt>/</tt>.
48
- def self.dispatch(options = {})
49
- Socket.do_not_reverse_lookup = true # patch for OS X
50
-
51
- params = { :Port => options[:port].to_i,
52
- :ServerType => options[:server_type],
53
- :BindAddress => options[:ip] }
54
- params[:MimeTypes] = options[:mime_types] if options[:mime_types]
55
-
56
- server = WEBrick::HTTPServer.new(params)
57
- server.mount('/', DispatchServlet, options)
58
-
59
- trap("INT") { server.shutdown }
60
- server.start
61
- end
62
-
63
- def initialize(server, options) #:nodoc:
64
- @server_options = options
65
- @file_handler = WEBrick::HTTPServlet::FileHandler.new(server, options[:server_root])
66
- # Change to the Rails.root, since Webrick::Daemon.start does a Dir::cwd("/")
67
- # OPTIONS['working_directory'] is an absolute path of the Rails.root, set in railties/lib/commands/servers/webrick.rb
68
- Dir.chdir(OPTIONS['working_directory']) if defined?(OPTIONS) && File.directory?(OPTIONS['working_directory'])
69
- super
70
- end
71
-
72
- def service(req, res) #:nodoc:
73
- unless handle_file(req, res)
74
- unless handle_dispatch(req, res)
75
- raise WEBrick::HTTPStatus::NotFound, "`#{req.path}' not found."
76
- end
77
- end
78
- end
79
-
80
- def handle_file(req, res) #:nodoc:
81
- begin
82
- req = req.dup
83
- path = req.path.dup
84
-
85
- # Add .html if the last path piece has no . in it
86
- path << '.html' if path != '/' && (%r{(^|/)[^./]+$} =~ path)
87
- path.gsub!('+', ' ') # Unescape + since FileHandler doesn't do so.
88
-
89
- req.instance_variable_set(:@path_info, path) # Set the modified path...
90
-
91
- @file_handler.send(:service, req, res)
92
- return true
93
- rescue HTTPStatus::PartialContent, HTTPStatus::NotModified => err
94
- res.set_error(err)
95
- return true
96
- rescue => err
97
- return false
98
- end
99
- end
100
-
101
- def handle_dispatch(req, res, origin = nil) #:nodoc:
102
- data = StringIO.new
103
- Dispatcher.dispatch(
104
- CGI.new("query", create_env_table(req, origin), StringIO.new(req.body || "")),
105
- ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS,
106
- data
107
- )
108
-
109
- header, body = extract_header_and_body(data)
110
-
111
- set_charset(header)
112
- assign_status(res, header)
113
- res.cookies.concat(header.delete('set-cookie') || [])
114
- header.each { |key, val| res[key] = val.join(", ") }
115
-
116
- res.body = body
117
- return true
118
- rescue => err
119
- p err, err.backtrace
120
- return false
121
- end
122
-
123
- private
124
- def create_env_table(req, origin)
125
- env = req.meta_vars.clone
126
- env.delete "SCRIPT_NAME"
127
- env["QUERY_STRING"] = req.request_uri.query
128
- env["REQUEST_URI"] = origin if origin
129
- return env
130
- end
131
-
132
- def extract_header_and_body(data)
133
- data.rewind
134
- data = data.read
135
-
136
- raw_header, body = *data.split(/^[\xd\xa]{2}/on, 2)
137
- header = WEBrick::HTTPUtils::parse_header(raw_header)
138
-
139
- return header, body
140
- end
141
-
142
- def set_charset(header)
143
- ct = header["content-type"]
144
- if ct.any? { |x| x =~ /^text\// } && ! ct.any? { |x| x =~ /charset=/ }
145
- ch = @server_options[:charset] || "UTF-8"
146
- ct.find { |x| x =~ /^text\// } << ("; charset=" + ch)
147
- end
148
- end
149
-
150
- def assign_status(res, header)
151
- if /^(\d+)/ =~ header['status'][0]
152
- res.status = $1.to_i
153
- header.delete('status')
154
- end
155
- end
156
- end