aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
Diffstat (limited to 'railties')
-rw-r--r--railties/guides/source/active_model_basics.textile8
-rw-r--r--railties/guides/source/active_support_core_extensions.textile24
-rw-r--r--railties/lib/rails/plugin.rb4
-rw-r--r--railties/test/application/asset_debugging_test.rb56
-rw-r--r--railties/test/application/assets_test.rb42
5 files changed, 64 insertions, 70 deletions
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/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..0be591a1b9
--- /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_not_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