railties 4.1.0.beta2 → 4.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +65 -4
  3. data/lib/rails/app_rails_loader.rb +1 -1
  4. data/lib/rails/application.rb +11 -9
  5. data/lib/rails/application/bootstrap.rb +5 -1
  6. data/lib/rails/application/configuration.rb +13 -5
  7. data/lib/rails/commands/dbconsole.rb +11 -5
  8. data/lib/rails/commands/runner.rb +14 -5
  9. data/lib/rails/engine.rb +0 -1
  10. data/lib/rails/generators/actions.rb +8 -8
  11. data/lib/rails/generators/actions/create_migration.rb +68 -0
  12. data/lib/rails/generators/app_base.rb +7 -67
  13. data/lib/rails/generators/base.rb +1 -1
  14. data/lib/rails/generators/erb.rb +5 -1
  15. data/lib/rails/generators/erb/controller/controller_generator.rb +4 -2
  16. data/lib/rails/generators/erb/mailer/mailer_generator.rb +2 -2
  17. data/lib/rails/generators/erb/mailer/templates/view.html.erb +5 -0
  18. data/lib/rails/generators/erb/mailer/templates/view.text.erb +1 -1
  19. data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +4 -2
  20. data/lib/rails/generators/migration.rb +22 -16
  21. data/lib/rails/generators/rails/app/app_generator.rb +5 -7
  22. data/lib/rails/generators/rails/app/templates/Gemfile +2 -4
  23. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +6 -6
  24. data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml +3 -2
  25. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +3 -2
  26. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml +3 -2
  27. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +3 -3
  28. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +12 -4
  29. data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +3 -2
  30. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +8 -3
  31. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +3 -2
  32. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +16 -4
  33. data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml +7 -2
  34. data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml +3 -2
  35. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +8 -0
  36. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +7 -2
  37. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +4 -1
  38. data/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb +3 -0
  39. data/lib/rails/generators/rails/app/templates/config/secrets.yml +3 -1
  40. data/lib/rails/generators/rails/app/templates/test/test_helper.rb +1 -3
  41. data/lib/rails/generators/rails/controller/controller_generator.rb +3 -3
  42. data/lib/rails/generators/rails/plugin/plugin_generator.rb +1 -4
  43. data/lib/rails/generators/rails/plugin/templates/Gemfile +2 -4
  44. data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +4 -0
  45. data/lib/rails/generators/rails/resource_route/resource_route_generator.rb +1 -1
  46. data/lib/rails/generators/resource_helpers.rb +1 -3
  47. data/lib/rails/generators/test_unit/mailer/templates/preview.rb +2 -0
  48. data/lib/rails/paths.rb +1 -1
  49. data/lib/rails/railtie.rb +3 -3
  50. data/lib/rails/test_help.rb +3 -1
  51. data/lib/rails/test_unit/testing.rake +0 -1
  52. data/lib/rails/version.rb +1 -1
  53. metadata +10 -7
@@ -296,7 +296,7 @@ module Rails
296
296
  end
297
297
  end
298
298
 
299
- # Return the default value for the option name given doing a lookup in
299
+ # Returns the default value for the option name given doing a lookup in
300
300
  # Rails::Generators.options.
301
301
  def self.default_value_for_option(name, options)
302
302
  default_for_option(Rails::Generators.options, name, options, options[:default])
@@ -5,6 +5,10 @@ module Erb # :nodoc:
5
5
  class Base < Rails::Generators::NamedBase #:nodoc:
6
6
  protected
7
7
 
8
+ def formats
9
+ format
10
+ end
11
+
8
12
  def format
9
13
  :html
10
14
  end
@@ -13,7 +17,7 @@ module Erb # :nodoc:
13
17
  :erb
14
18
  end
15
19
 
16
- def filename_with_extensions(name)
20
+ def filename_with_extensions(name, format)
17
21
  [name, format, handler].compact.join(".")
18
22
  end
19
23
  end
@@ -11,8 +11,10 @@ module Erb # :nodoc:
11
11
 
12
12
  actions.each do |action|
13
13
  @action = action
14
- @path = File.join(base_path, filename_with_extensions(action))
15
- template filename_with_extensions(:view), @path
14
+ Array(formats).each do |format|
15
+ @path = File.join(base_path, filename_with_extensions(action, format))
16
+ template filename_with_extensions(:view, format), @path
17
+ end
16
18
  end
17
19
  end
18
20
  end
@@ -5,8 +5,8 @@ module Erb # :nodoc:
5
5
  class MailerGenerator < ControllerGenerator # :nodoc:
6
6
  protected
7
7
 
8
- def format
9
- :text
8
+ def formats
9
+ [:text, :html]
10
10
  end
11
11
  end
12
12
  end
@@ -0,0 +1,5 @@
1
+ <h1><%= class_name %>#<%= @action %></h1>
2
+
3
+ <p>
4
+ <%%= @greeting %>, find me in <%= @path %>
5
+ </p>
@@ -1,3 +1,3 @@
1
1
  <%= class_name %>#<%= @action %>
2
2
 
3
- <%%= @greeting %>, find me in app/views/<%= @path %>
3
+ <%%= @greeting %>, find me in <%= @path %>
@@ -14,8 +14,10 @@ module Erb # :nodoc:
14
14
 
15
15
  def copy_view_files
16
16
  available_views.each do |view|
17
- filename = filename_with_extensions(view)
18
- template filename, File.join("app/views", controller_file_path, filename)
17
+ Array(formats).each do |format|
18
+ filename = filename_with_extensions(view, format)
19
+ template filename, File.join("app/views", controller_file_path, filename)
20
+ end
19
21
  end
20
22
  end
21
23
 
@@ -1,4 +1,5 @@
1
1
  require 'active_support/concern'
2
+ require 'rails/generators/actions/create_migration'
2
3
 
3
4
  module Rails
4
5
  module Generators
@@ -29,6 +30,19 @@ module Rails
29
30
  end
30
31
  end
31
32
 
33
+ def create_migration(destination, data, config = {}, &block)
34
+ action Rails::Generators::Actions::CreateMigration.new(self, destination, block || data.to_s, config)
35
+ end
36
+
37
+ def set_migration_assigns!(destination)
38
+ destination = File.expand_path(destination, self.destination_root)
39
+
40
+ migration_dir = File.dirname(destination)
41
+ @migration_number = self.class.next_migration_number(migration_dir)
42
+ @migration_file_name = File.basename(destination, '.rb')
43
+ @migration_class_name = @migration_file_name.camelize
44
+ end
45
+
32
46
  # Creates a migration template at the given destination. The difference
33
47
  # to the default template method is that the migration version is appended
34
48
  # to the destination file name.
@@ -37,26 +51,18 @@ module Rails
37
51
  # available as instance variables in the template to be rendered.
38
52
  #
39
53
  # migration_template "migration.rb", "db/migrate/add_foo_to_bar.rb"
40
- def migration_template(source, destination=nil, config={})
41
- destination = File.expand_path(destination || source, self.destination_root)
54
+ def migration_template(source, destination, config = {})
55
+ source = File.expand_path(find_in_source_paths(source.to_s))
42
56
 
43
- migration_dir = File.dirname(destination)
44
- @migration_number = self.class.next_migration_number(migration_dir)
45
- @migration_file_name = File.basename(destination).sub(/\.rb$/, '')
46
- @migration_class_name = @migration_file_name.camelize
57
+ set_migration_assigns!(destination)
58
+ context = instance_eval('binding')
47
59
 
48
- destination = self.class.migration_exists?(migration_dir, @migration_file_name)
60
+ dir, base = File.split(destination)
61
+ numbered_destination = File.join(dir, ["%migration_number%", base].join('_'))
49
62
 
50
- if !(destination && options[:skip]) && behavior == :invoke
51
- if destination && options.force?
52
- remove_file(destination)
53
- elsif destination
54
- raise Error, "Another migration is already named #{@migration_file_name}: #{destination}. Use --force to remove the old migration file and replace it."
55
- end
56
- destination = File.join(migration_dir, "#{@migration_number}_#{@migration_file_name}.rb")
63
+ create_migration numbered_destination, nil, config do
64
+ ERB.new(::File.binread(source), nil, '-', '@output_buffer').result(context)
57
65
  end
58
-
59
- template(source, destination, config)
60
66
  end
61
67
  end
62
68
  end
@@ -166,7 +166,6 @@ module Rails
166
166
  end
167
167
 
168
168
  public_task :set_default_accessors!
169
- public_task :apply_rails_template
170
169
  public_task :create_root
171
170
 
172
171
  def create_root_files
@@ -226,18 +225,17 @@ module Rails
226
225
  build(:vendor)
227
226
  end
228
227
 
229
- def finish_template
230
- build(:leftovers)
231
- end
232
-
233
228
  def delete_js_folder_skipping_javascript
234
229
  if options[:skip_javascript]
235
230
  remove_dir 'app/assets/javascripts'
236
231
  end
237
232
  end
238
233
 
239
- public_task :run_bundle
240
- public_task :replay_template
234
+ def finish_template
235
+ build(:leftovers)
236
+ end
237
+
238
+ public_task :apply_rails_template, :run_bundle
241
239
  public_task :generate_spring_binstubs
242
240
 
243
241
  protected
@@ -6,12 +6,10 @@ source 'https://rubygems.org'
6
6
 
7
7
  # <%= gem.comment %>
8
8
  <% end -%>
9
- <%= gem.commented_out ? '# ' : '' %>gem '<%= gem.name %>'<% if gem.version -%>
10
- , '<%= gem.version %>'
11
- <% elsif gem.options.any? -%>
9
+ <%= gem.commented_out ? '# ' : '' %>gem '<%= gem.name %>'<%= %(, '#{gem.version}') if gem.version -%>
10
+ <% if gem.options.any? -%>
12
11
  ,<%= gem.padding(max_width) %><%= gem.options.map { |k,v|
13
12
  "#{k}: #{v.inspect}" }.join(', ') %>
14
- <% else %>
15
13
  <% end -%>
16
14
  <% end -%>
17
15
 
@@ -3,14 +3,14 @@
3
3
  <head>
4
4
  <title><%= camelized %></title>
5
5
  <%- if options[:skip_javascript] -%>
6
- <%%= stylesheet_link_tag "application", media: "all" %>
6
+ <%%= stylesheet_link_tag 'application', media: 'all' %>
7
7
  <%- else -%>
8
- <%- if gemfile_entries.any? { |m| m.name == "turbolinks" } -%>
9
- <%%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
10
- <%%= javascript_include_tag "application", "data-turbolinks-track" => true %>
8
+ <%- if gemfile_entries.any? { |m| m.name == 'turbolinks' } -%>
9
+ <%%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
10
+ <%%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
11
11
  <%- else -%>
12
- <%%= stylesheet_link_tag "application", media: "all" %>
13
- <%%= javascript_include_tag "application" %>
12
+ <%%= stylesheet_link_tag 'application', media: 'all' %>
13
+ <%%= javascript_include_tag 'application' %>
14
14
  <%- end -%>
15
15
  <%- end -%>
16
16
  <%%= csrf_meta_tags %>
@@ -23,6 +23,7 @@ test:
23
23
  <<: *default
24
24
  database: <%= app_name %>_test
25
25
 
26
+ # Do not keep production credentials in the repository,
27
+ # instead read the configuration from the environment.
26
28
  production:
27
- <<: *default
28
- database: <%= app_name %>_production
29
+ url: <%%= ENV["DATABASE_URL"] %>
@@ -61,6 +61,7 @@ test:
61
61
  <<: *default
62
62
  database: <%= app_name[0,4] %>_tst
63
63
 
64
+ # Do not keep production credentials in the repository,
65
+ # instead read the configuration from the environment.
64
66
  production:
65
- <<: *default
66
- database: <%= app_name[0,8] %>
67
+ url: <%%= ENV["DATABASE_URL"] %>
@@ -53,6 +53,7 @@ test:
53
53
  <<: *default
54
54
  url: jdbc:db://localhost/<%= app_name %>_test
55
55
 
56
+ # Do not keep production credentials in the repository,
57
+ # instead read the configuration from the environment.
56
58
  production:
57
- <<: *default
58
- url: jdbc:db://localhost/<%= app_name %>_production
59
+ url: <%%= ENV["DATABASE_URL"] %>
@@ -26,6 +26,6 @@ test:
26
26
  <<: *default
27
27
  database: <%= app_name %>_test
28
28
 
29
- production:
30
- <<: *default
31
- database: <%= app_name %>_production
29
+ # Do not keep production credentials in the repository,
30
+ # instead read the configuration from the environment.
31
+ production: <%%= ENV["DATABASE_URL"] %>
@@ -6,13 +6,20 @@
6
6
  default: &default
7
7
  adapter: postgresql
8
8
  encoding: unicode
9
- username: <%= app_name %>
10
- password:
11
9
 
12
10
  development:
13
11
  <<: *default
14
12
  database: <%= app_name %>_development
15
13
 
14
+ # The specified database role being used to connect to postgres.
15
+ # To create additional roles in postgres see `$ createuser --help`.
16
+ # When left blank, postgres will use the default role. This is
17
+ # the same name as the operating system user that initialized the database.
18
+ #username: <%= app_name %>
19
+
20
+ # The password associated with the postgres role (username).
21
+ #password:
22
+
16
23
  # Connect on a TCP socket. Omitted by default since the client uses a
17
24
  # domain socket that doesn't need configuration. Windows does not have
18
25
  # domain sockets, so uncomment these lines.
@@ -35,6 +42,7 @@ test:
35
42
  <<: *default
36
43
  database: <%= app_name %>_test
37
44
 
45
+ # Do not keep production credentials in the repository,
46
+ # instead read the configuration from the environment.
38
47
  production:
39
- <<: *default
40
- database: <%= app_name %>_production
48
+ url: <%%= ENV["DATABASE_URL"] %>
@@ -18,6 +18,7 @@ test:
18
18
  <<: *default
19
19
  database: db/test.sqlite3
20
20
 
21
+ # Do not keep production credentials in the repository,
22
+ # instead read the configuration from the environment.
21
23
  production:
22
- <<: *default
23
- database: db/production.sqlite3
24
+ url: <%%= ENV["DATABASE_URL"] %>
@@ -1,4 +1,4 @@
1
- # MySQL. Versions 4.1 and 5.0 are recommended.
1
+ # MySQL. Versions 5.0+ are recommended.
2
2
  #
3
3
  # Install the MYSQL driver
4
4
  # gem install mysql2
@@ -32,6 +32,11 @@ test:
32
32
  <<: *default
33
33
  database: <%= app_name %>_test
34
34
 
35
+ # Avoid production credentials in the repository,
36
+ # instead read the configuration from the environment.
37
+ #
38
+ # Example:
39
+ # mysql2://myuser:mypass@localhost/somedatabase
40
+ #
35
41
  production:
36
- <<: *default
37
- database: <%= app_name %>_production
42
+ url: <%%= ENV["DATABASE_URL"] %>
@@ -32,6 +32,7 @@ test:
32
32
  <<: *default
33
33
  database: <%= app_name %>_test
34
34
 
35
+ # Do not keep production credentials in the repository,
36
+ # instead read the configuration from the environment.
35
37
  production:
36
- <<: *default
37
- database: <%= app_name %>_production
38
+ url: <%%= ENV["DATABASE_URL"] %>
@@ -20,13 +20,20 @@ default: &default
20
20
  # For details on connection pooling, see rails configuration guide
21
21
  # http://guides.rubyonrails.org/configuring.html#database-pooling
22
22
  pool: 5
23
- username: <%= app_name %>
24
- password:
25
23
 
26
24
  development:
27
25
  <<: *default
28
26
  database: <%= app_name %>_development
29
27
 
28
+ # The specified database role being used to connect to postgres.
29
+ # To create additional roles in postgres see `$ createuser --help`.
30
+ # When left blank, postgres will use the default role. This is
31
+ # the same name as the operating system user that initialized the database.
32
+ #username: <%= app_name %>
33
+
34
+ # The password associated with the postgres role (username).
35
+ #password:
36
+
30
37
  # Connect on a TCP socket. Omitted by default since the client uses a
31
38
  # domain socket that doesn't need configuration. Windows does not have
32
39
  # domain sockets, so uncomment these lines.
@@ -52,6 +59,11 @@ test:
52
59
  <<: *default
53
60
  database: <%= app_name %>_test
54
61
 
62
+ # Do not keep production credentials in the repository,
63
+ # instead read the configuration from the environment.
64
+ #
65
+ # Example:
66
+ # postgres://myuser:mypass@localhost/somedatabase
67
+ #
55
68
  production:
56
- <<: *default
57
- database: <%= app_name %>_production
69
+ url: <%%= ENV["DATABASE_URL"] %>
@@ -20,6 +20,11 @@ test:
20
20
  <<: *default
21
21
  database: db/test.sqlite3
22
22
 
23
+ # Do not keep production credentials in the repository,
24
+ # instead read the configuration from the environment.
25
+ #
26
+ # Example:
27
+ # sqlite3://myuser:mypass@localhost/full/path/to/somedatabase
28
+ #
23
29
  production:
24
- <<: *default
25
- database: db/production.sqlite3
30
+ url: <%%= ENV["DATABASE_URL"] %>
@@ -42,6 +42,7 @@ test:
42
42
  <<: *default
43
43
  database: <%= app_name %>_test
44
44
 
45
+ # Do not keep production credentials in the repository,
46
+ # instead read the configuration from the environment.
45
47
  production:
46
- <<: *default
47
- database: <%= app_name %>_production
48
+ url: <%%= ENV["DATABASE_URL"] %>
@@ -29,5 +29,13 @@ Rails.application.configure do
29
29
  # This option may cause significant delays in view rendering with a large
30
30
  # number of complex assets.
31
31
  config.assets.debug = true
32
+
33
+ # Adds additional error checking when serving assets at runtime.
34
+ # Checks for improperly declared sprockets dependencies.
35
+ # Raises helpful error messages.
36
+ config.assets.raise_runtime_errors = true
32
37
  <%- end -%>
38
+
39
+ # Raises error for missing translations
40
+ # config.action_view.raise_on_missing_translations = true
33
41
  end
@@ -5,7 +5,7 @@ Rails.application.configure do
5
5
  config.cache_classes = true
6
6
 
7
7
  # Eager load code on boot. This eager loads most of Rails and
8
- # your application in memory, allowing both thread web servers
8
+ # your application in memory, allowing both threaded web servers
9
9
  # and those relying on copy on write to perform better.
10
10
  # Rake tasks automatically ignore this option for performance.
11
11
  config.eager_load = true
@@ -70,7 +70,7 @@ Rails.application.configure do
70
70
  # config.action_mailer.raise_delivery_errors = false
71
71
 
72
72
  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
73
- # the I18n.default_locale when a translation can not be found).
73
+ # the I18n.default_locale when a translation cannot be found).
74
74
  config.i18n.fallbacks = true
75
75
 
76
76
  # Send deprecation notices to registered listeners.
@@ -81,4 +81,9 @@ Rails.application.configure do
81
81
 
82
82
  # Use default logging formatter so that PID and timestamp are not suppressed.
83
83
  config.log_formatter = ::Logger::Formatter.new
84
+ <%- unless options.skip_active_record? -%>
85
+
86
+ # Do not dump schema after migrations.
87
+ config.active_record.dump_schema_after_migration = false
88
+ <%- end -%>
84
89
  end
@@ -14,7 +14,7 @@ Rails.application.configure do
14
14
 
15
15
  # Configure static asset server for tests with Cache-Control for performance.
16
16
  config.serve_static_assets = true
17
- config.static_cache_control = "public, max-age=3600"
17
+ config.static_cache_control = 'public, max-age=3600'
18
18
 
19
19
  # Show full error reports and disable caching.
20
20
  config.consider_all_requests_local = true
@@ -33,4 +33,7 @@ Rails.application.configure do
33
33
 
34
34
  # Print deprecation notices to the stderr.
35
35
  config.active_support.deprecation = :stderr
36
+
37
+ # Raises error for missing translations
38
+ # config.action_view.raise_on_missing_translations = true
36
39
  end