diff options
Diffstat (limited to 'railties')
-rw-r--r-- | railties/CHANGELOG | 17 | ||||
-rw-r--r-- | railties/guides/source/active_model_basics.textile | 8 | ||||
-rw-r--r-- | railties/guides/source/active_support_core_extensions.textile | 24 | ||||
-rw-r--r-- | railties/guides/source/asset_pipeline.textile | 17 | ||||
-rw-r--r-- | railties/lib/rails/plugin.rb | 4 | ||||
-rw-r--r-- | railties/test/application/asset_debugging_test.rb | 56 | ||||
-rw-r--r-- | railties/test/application/assets_test.rb | 42 |
7 files changed, 93 insertions, 75 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG index a9b4deb551..6ed76974b4 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,9 @@ *Rails 3.2.0 (unreleased)* +* Added destroy alias to Rails engines. [Guillermo Iguaran] + +* Added destroy alias for Rails command line. This allows the following: `rails d model post`. [Andrey Ognevsky] + * Attributes on scaffold and model generators default to string. This allows the following: "rails g scaffold Post title body:text author" [José Valim] * Removed old plugin generator (`rails generate plugin`) in favor of `rails plugin new` command. [Guillermo Iguaran] @@ -8,6 +12,19 @@ *Rails 3.1.0 (unreleased)* +* The default database schema file is written as UTF-8. [Aaron Patterson] + +* Generated apps with --dev or --edge flags depend on git versions of +sass-rails and coffee-rails. [Santiago Pastorino] + +* Rack::Sendfile middleware is used only if x_sendfile_header is present. [Santiago Pastorino] + +* Add JavaScript Runtime name to the Rails Info properties. [DHH] + +* Make pp enabled by default in Rails console. [Akira Matsuda] + +* Add alias `r` for rails runner. [Jordi Romero] + * Make sprockets/railtie require explicit and add --skip-sprockets to app generator [José Valim] * Added Rails.groups that automatically handles Rails.env and ENV["RAILS_GROUPS"] [José Valim] diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile index 3c19fb5177..0672669dc5 100644 --- a/railties/guides/source/active_model_basics.textile +++ b/railties/guides/source/active_model_basics.textile @@ -183,22 +183,26 @@ Validations module adds the ability to class objects to validate them in Active class Person include ActiveModel::Validations - attr_accessor :name, :email + attr_accessor :name, :email, :token validates :name, :presence => true validates_format_of :email, :with => /^([^\s]+)((?:[-a-z0-9]\.)[a-z]{2,})$/i + validates! :token, :presence => true end -person = Person.new +person = Person.new(:token => "2b1f325") person.valid? #=> false person.name = 'vishnu' person.email = 'me' person.valid? #=> false person.email = 'me@vishnuatrai.com' person.valid? #=> true +person.token = nil +person.valid? #=> raises ActiveModel::StrictValidationFailed </ruby> h3. Changelog +* August 24, 2011: Add strict validation usage example. "Bogdan Gusiev":http://gusiev.com * August 5, 2011: Initial version by "Arun Agrawal":http://github.com/arunagw diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index df863935cf..b2436a2e68 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -452,30 +452,6 @@ Examples of +in?+: NOTE: Defined in +active_support/core_ext/object/inclusion.rb+. -h4. +public_send+ - -This method is available by default in Ruby 1.9, and is backported to Ruby 1.8 by Active Support. Like the regular +send+ method, +public_send+ allows you to call a method when the name is not known until runtime. However, if the method is not public then a +NoMethodError+ exception will be raised. - -<ruby> -class Greeter - def hello(who) - "Hello " + who - end - - private - - def secret - "sauce" - end -end - -greeter = Greeter.new -greeter.public_send(:hello, 'Jim') # => "Hello Jim" -greeter.public_send(:secret) # => NoMethodError -</ruby> - -NOTE: Defined in +active_support/core_ext/object/public_send.rb+. - h3. Extensions to +Module+ h4. +alias_method_chain+ diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 012149c40e..554246acb3 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -29,7 +29,7 @@ It is recommended that you use the defaults for all new apps. h4. Main Features -The first feature of the pipeline is to concatenate assets. This is important in a production environment, as it reduces the number of requests that a browser must make to render a web page. While Rails already has a feature to concatenate these types of assetsi -- by placing +:cache => true+ at the end of tags such as +javascript_include_tag+ and +stylesheet_link_tag+ -- many people do not use it. +The first feature of the pipeline is to concatenate assets. This is important in a production environment, as it reduces the number of requests that a browser must make to render a web page. While Rails already has a feature to concatenate these types of assets -- by placing +:cache => true+ at the end of tags such as +javascript_include_tag+ and +stylesheet_link_tag+ -- many people do not use it. The default behavior in Rails 3.1 and onward is to concatenate all files into one master file each for JS and CSS. However, you can separate files or groups of files if required (see below). In production, an MD5 fingerprint is inserted into each filename so that the file is cached by the web browser but can be invalidated if the fingerprint is altered. @@ -133,7 +133,7 @@ Otherwise, Sprockets looks through the available paths until it finds a file tha If you want to use a "css data URI":http://en.wikipedia.org/wiki/Data_URI_scheme -- a method of embedding the image data directly into the CSS file -- you can use the +asset_data_uri+ helper. <plain> -#logo { background: url(<%= asset_data_uri 'logo.png' %>) +#logo { background: url(<%= asset_data_uri 'logo.png' %>) } </plain> This inserts a correctly-formatted data URI into the CSS source. @@ -143,7 +143,7 @@ h5. CSS and ERB If you add an +erb+ extension to a CSS asset, making it something such as +application.css.erb+, then you can use the +asset_path+ helper in your CSS rules: <plain> -.class{background-image:<%= asset_path 'image.png' %>} +.class { background-image: <%= asset_path 'image.png' %> } </plain> This writes the path to the particular asset being referenced. In this example, it would make sense to have an image in one of the asset load paths, such as +app/assets/images/image.png+, which would be referenced here. If this image is already available in +public/assets+ as a fingerprinted file, then that path is referenced. @@ -247,7 +247,14 @@ When the +debug_assets+ parameter is set, this line is expanded out into three s This allows the individual parts of an asset to be rendered and debugged separately. -NOTE. Assets debugging is turned on by default in development and test environments. +Additionally if the +config.assets.debug+ is set to true you can debug your assets passing the +:debug+ option to the assets tags: + +<erb> +<%= javascript_include_tag :application, :debug => true %> +</erb> + + +NOTE. Assets debugging is turned on by default in development and test environments. You can set +config.assets.allow_debugging+ to false to turn it off. h3. In Production @@ -275,7 +282,7 @@ Rails comes bundled with a rake task to compile the manifests to files on disc. The rake task is: <plain> -rake assets:precompile +bundle exec rake assets:precompile </plain> Capistrano (v2.8.0+) has a recipe to handle this in deployment. Add the following line to +Capfile+: diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index 4988cc3378..3e27688bb9 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -74,8 +74,8 @@ module Rails initializer :load_init_rb, :before => :load_config_initializers do |app| init_rb = File.expand_path("init.rb", root) if File.file?(init_rb) - # FIXME: do we call this for side effects?? - app.config + # This double assignment is to prevent an "unused variable" warning on Ruby 1.9.3. + config = config = app.config # TODO: think about evaling initrb in context of Engine (currently it's # always evaled in context of Rails::Application) eval(File.read(init_rb), binding, init_rb) diff --git a/railties/test/application/asset_debugging_test.rb b/railties/test/application/asset_debugging_test.rb new file mode 100644 index 0000000000..38e1e21d17 --- /dev/null +++ b/railties/test/application/asset_debugging_test.rb @@ -0,0 +1,56 @@ +require 'isolation/abstract_unit' +require 'rack/test' + +module ApplicationTests + class AssetDebuggingTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + include Rack::Test::Methods + + def setup + build_app(:initializers => true) + + app_file "app/assets/javascripts/application.js", "//= require_tree ." + app_file "app/assets/javascripts/xmlhr.js", "function f1() { alert(); }" + app_file "app/views/posts/index.html.erb", "<%= javascript_include_tag 'application' %>" + + app_file "config/routes.rb", <<-RUBY + AppTemplate::Application.routes.draw do + match '/posts', :to => "posts#index" + end + RUBY + + app_file "app/controllers/posts_controller.rb", <<-RUBY + class PostsController < ActionController::Base + end + RUBY + + ENV["RAILS_ENV"] = "production" + + boot_rails + end + + def teardown + teardown_app + end + + test "assets are concatenated when debug is off and allow_debugging is off either if debug_assets param is provided" do + # config.assets.debug and config.assets.allow_debugging are false for production environment + require "#{app_path}/config/environment" + + # the debug_assets params isn't used if allow_debugging is off + get '/posts?debug_assets=true' + assert_match %r{<script src="/assets/application-([0-z]+)\.js" type="text/javascript"></script>}, last_response.body + assert_no_match %r{<script src="/assets/xmlhr-([0-z]+)\.js" type="text/javascript"></script>}, last_response.body + end + + test "assets aren't concatened when allow_debugging is on and debug_assets params is true" do + app_file "config/initializers/allow_debugging.rb", "Rails.application.config.assets.allow_debugging = true" + + require "#{app_path}/config/environment" + + get '/posts?debug_assets=true' + assert_match %r{<script src="/assets/application-([0-z]+)\.js\?body=1" type="text/javascript"></script>}, last_response.body + assert_match %r{<script src="/assets/xmlhr-([0-z]+)\.js\?body=1" type="text/javascript"></script>}, last_response.body + end + end +end diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 1e6a93dbdf..a8d1382e94 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -135,47 +135,5 @@ module ApplicationTests assert_match "alert();", last_response.body assert_equal 200, last_response.status end - - test "assets are concatenated when debug is off and allow_debugging is off either if debug_assets param is provided" do - app_with_assets_in_view - - # config.assets.debug and config.assets.allow_debugging are false for production environment - ENV["RAILS_ENV"] = "production" - require "#{app_path}/config/environment" - - class ::PostsController < ActionController::Base ; end - - # the debug_assets params isn't used if allow_debugging is off - get '/posts?debug_assets=true' - assert_match /<script src="\/assets\/application-([0-z]+)\.js" type="text\/javascript"><\/script>/, last_response.body - assert_not_match /<script src="\/assets\/xmlhr-([0-z]+)\.js" type="text\/javascript"><\/script>/, last_response.body - end - - test "assets aren't concatened when allow_debugging is on and debug_assets params is true" do - app_with_assets_in_view - app_file "config/initializers/allow_debugging.rb", "Rails.application.config.assets.allow_debugging = true" - - ENV["RAILS_ENV"] = "production" - require "#{app_path}/config/environment" - - class ::PostsController < ActionController::Base ; end - - get '/posts?debug_assets=true' - assert_match /<script src="\/assets\/application-([0-z]+)\.js\?body=1" type="text\/javascript"><\/script>/, last_response.body - assert_match /<script src="\/assets\/xmlhr-([0-z]+)\.js\?body=1" type="text\/javascript"><\/script>/, last_response.body - end - - private - def app_with_assets_in_view - app_file "app/assets/javascripts/application.js", "//= require_tree ." - app_file "app/assets/javascripts/xmlhr.js", "function f1() { alert(); }" - app_file "app/views/posts/index.html.erb", "<%= javascript_include_tag 'application' %>" - - app_file "config/routes.rb", <<-RUBY - AppTemplate::Application.routes.draw do - match '/posts', :to => "posts#index" - end - RUBY - end end end |