diff options
author | Xavier Noria <fxn@hashref.com> | 2010-07-31 11:55:24 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-07-31 11:55:24 +0200 |
commit | 3d7099891f07395ed889e7da9e13b3ff9244d539 (patch) | |
tree | 6a988362ec4a6b58c90a12e6b715cd6926a111ce | |
parent | 0e20e3ebc20250174867f33e0ad3972f7e7c76d0 (diff) | |
parent | d3819daaac0d2f730f2b34af31700c914e697375 (diff) | |
download | rails-3d7099891f07395ed889e7da9e13b3ff9244d539.tar.gz rails-3d7099891f07395ed889e7da9e13b3ff9244d539.tar.bz2 rails-3d7099891f07395ed889e7da9e13b3ff9244d539.zip |
Merge remote branch 'rails/master'
19 files changed, 99 insertions, 56 deletions
@@ -27,7 +27,7 @@ end platforms :ruby do gem 'json' gem 'yajl-ruby' - gem "nokogiri", ">= 1.4.2" + gem "nokogiri", ">= 1.4.3.1" # AR gem "sqlite3-ruby", "~> 1.3.1", :require => 'sqlite3' @@ -50,7 +50,7 @@ platforms :jruby do end env 'CI' do - gem "nokogiri", ">= 1.4.2" + gem "nokogiri", ">= 1.4.3.1" platforms :ruby_18 do # fcgi gem doesn't compile on 1.9 diff --git a/README.rdoc b/README.rdoc index 6198000279..41ba12fa42 100644 --- a/README.rdoc +++ b/README.rdoc @@ -29,29 +29,38 @@ link:files/vendor/rails/actionpack/README.html. == Getting Started 1. Install Rails at the command prompt if you haven't yet: - <tt>gem install rails</tt> + + gem install rails 2. At the command prompt, create a new Rails application: - <tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name) -3. Change directory to <tt>myapp</tt> and start the web server: - <tt>cd myapp; rails server</tt> (run with --help for options) + rails new myapp + + where "myapp" is the application name. + +3. Change directory to +myapp+ and start the web server: + + cd myapp; rails server + + Run with <tt>--help</tt> for options. 4. Go to http://localhost:3000/ and you'll see: - "Welcome aboard: You're riding Ruby on Rails!" + + "Welcome aboard: You're riding Ruby on Rails!" 5. Follow the guidelines to start developing your application. You can find the following resources handy: -* The README file created within your application -* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html -* Ruby on Rails Tutorial Book: http://www.railstutorial.org/ +* The README file created within your application. +* The {Getting Started Guide}[http://guides.rubyonrails.org/getting_started.html]. +* The {Ruby on Rails Tutorial Book}[http://railstutorial.org/book]. == Contributing -Check out the contributing guide at http://edgeguides.rubyonrails.org/contributing_to_rails.html - +We encourage you to contribute to Ruby on Raills! Please check out the {Contributing to Rails +guide}[http://edgeguides.rubyonrails.org/contributing_to_rails.html] for guidelines about how +to proceed. {Join us}[http://contributors.rubyonrails.org]! == License diff --git a/activerecord/lib/active_record/associations/belongs_to_association.rb b/activerecord/lib/active_record/associations/belongs_to_association.rb index c2a6495db5..4558872a2b 100644 --- a/activerecord/lib/active_record/associations/belongs_to_association.rb +++ b/activerecord/lib/active_record/associations/belongs_to_association.rb @@ -22,7 +22,7 @@ module ActiveRecord else raise_on_type_mismatch(record) - if counter_cache_name && !@owner.new_record? + if counter_cache_name && !@owner.new_record? && record.id != @owner[@reflection.primary_key_name] @reflection.klass.increment_counter(counter_cache_name, record.id) @reflection.klass.decrement_counter(counter_cache_name, @owner[@reflection.primary_key_name]) if @owner[@reflection.primary_key_name] end diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index a8cea44c78..7962f52738 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -99,7 +99,7 @@ module ActiveRecord if block_given? to_a.many? { |*block_args| yield(*block_args) } else - @limit_value.present? ? to_a.many? : size > 1 + @limit_value ? to_a.many? : size > 1 end end @@ -316,12 +316,12 @@ module ActiveRecord def scope_for_create @scope_for_create ||= begin - @create_with_value || @where_values.inject({}) do |hash, where| - if where.is_a?(Arel::Predicates::Equality) - hash[where.operand1.name] = where.operand2.respond_to?(:value) ? where.operand2.value : where.operand2 - end - hash - end + @create_with_value || Hash[ + @where_values.grep(Arel::Predicates::Equality).map { |where| + [where.operand1.name, + where.operand2.respond_to?(:value) ? + where.operand2.value : where.operand2] + }] end end diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 716e7275a5..a92d180442 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -47,8 +47,8 @@ module ActiveRecord clone.tap {|r| r.joins_values += args if args.present? } end - def where(opts, other = nil) - value = build_where(opts, other) + def where(opts, *rest) + value = build_where(opts, rest) value ? clone.tap {|r| r.where_values += Array.wrap(value) } : clone end @@ -129,7 +129,7 @@ module ActiveRecord def build_arel arel = table - arel = build_joins(arel, @joins_values) if @joins_values.present? + arel = build_joins(arel, @joins_values) unless @joins_values.empty? @where_values.uniq.each do |where| next if where.blank? @@ -143,33 +143,27 @@ module ActiveRecord end end - arel = arel.having(*@having_values.uniq.select{|h| h.present?}) if @having_values.present? + arel = arel.having(*@having_values.uniq.select{|h| h.present?}) unless @having_values.empty? - arel = arel.take(@limit_value) if @limit_value.present? - arel = arel.skip(@offset_value) if @offset_value.present? + arel = arel.take(@limit_value) if @limit_value + arel = arel.skip(@offset_value) if @offset_value - arel = arel.group(*@group_values.uniq.select{|g| g.present?}) if @group_values.present? + arel = arel.group(*@group_values.uniq.select{|g| g.present?}) unless @group_values.empty? - arel = arel.order(*@order_values.uniq.select{|o| o.present?}) if @order_values.present? + arel = arel.order(*@order_values.uniq.select{|o| o.present?}) unless @order_values.empty? arel = build_select(arel, @select_values.uniq) - arel = arel.from(@from_value) if @from_value.present? - - case @lock_value - when TrueClass - arel = arel.lock - when String - arel = arel.lock(@lock_value) - end if @lock_value.present? + arel = arel.from(@from_value) if @from_value + arel = arel.lock(@lock_value) if @lock_value arel end - def build_where(opts, other = nil) + def build_where(opts, other = []) case opts when String, Array - @klass.send(:sanitize_sql, other ? [opts, other] : opts) + @klass.send(:sanitize_sql, other.empty? ? opts : ([opts] + other)) when Hash attributes = @klass.send(:expand_hash_conditions_for_aggregates, opts) PredicateBuilder.new(table.engine).build_from_hash(attributes, table) diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index 4d5769d173..046433820d 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -215,6 +215,10 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase r1.topic = Topic.find(t2.id) + assert_no_queries do + r1.topic = t2 + end + assert r1.save assert_equal 0, Topic.find(t1.id).replies.size assert_equal 1, Topic.find(t2.id).replies.size diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index cb252d56fe..c9313fe7b6 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -22,6 +22,11 @@ class RelationTest < ActiveRecord::TestCase assert_equal 5, Post.where(:id => post_authors).size end + def test_multivalue_where + posts = Post.where('author_id = ? AND id = ?', 1, 1) + assert_equal 1, posts.to_a.size + end + def test_scoped topics = Topic.scoped assert_kind_of ActiveRecord::Relation, topics diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index 8e90de110a..30195bdea5 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -138,7 +138,7 @@ module ActiveSupport cattr_accessor :logger, :instance_writer => true - attr_reader :silence + attr_reader :silence, :options alias :silence? :silence # Create a new cache. The options will be passed to any write method calls except @@ -147,11 +147,6 @@ module ActiveSupport @options = options ? options.dup : {} end - # Get the default options set when the cache was created. - def options - @options ||= {} - end - # Silence the logger. def silence! @silence = true diff --git a/activesupport/lib/active_support/core_ext/string/inflections.rb b/activesupport/lib/active_support/core_ext/string/inflections.rb index f33e4959f9..32913a06ad 100644 --- a/activesupport/lib/active_support/core_ext/string/inflections.rb +++ b/activesupport/lib/active_support/core_ext/string/inflections.rb @@ -1,4 +1,5 @@ require 'active_support/inflector/methods' +require 'active_support/inflector/inflections' # String inflections define new methods on the String class to transform names for different purposes. # For instance, you can figure out the name of a database from the name of a class. # diff --git a/activesupport/lib/active_support/xml_mini/nokogiri.rb b/activesupport/lib/active_support/xml_mini/nokogiri.rb index eb61a7fc22..e03a744257 100644 --- a/activesupport/lib/active_support/xml_mini/nokogiri.rb +++ b/activesupport/lib/active_support/xml_mini/nokogiri.rb @@ -1,4 +1,9 @@ -require 'nokogiri' +begin + require 'nokogiri' +rescue LoadError => e + $stderr.puts "You don't have nokogiri installed in your application. Please add it to your Gemfile and run bundle install" + raise e +end require 'active_support/core_ext/object/blank' # = XmlMini Nokogiri implementation diff --git a/activesupport/lib/active_support/xml_mini/nokogirisax.rb b/activesupport/lib/active_support/xml_mini/nokogirisax.rb index 8af7b5e565..38c8685390 100644 --- a/activesupport/lib/active_support/xml_mini/nokogirisax.rb +++ b/activesupport/lib/active_support/xml_mini/nokogirisax.rb @@ -1,4 +1,9 @@ -require 'nokogiri' +begin + require 'nokogiri' +rescue LoadError => e + $stderr.puts "You don't have nokogiri installed in your application. Please add it to your Gemfile and run bundle install" + raise e +end require 'active_support/core_ext/object/blank' # = XmlMini Nokogiri implementation using a SAX-based parser @@ -80,4 +85,4 @@ module ActiveSupport end end end -end
\ No newline at end of file +end diff --git a/rails.gemspec b/rails.gemspec index 00dde1934d..8c90584470 100644 --- a/rails.gemspec +++ b/rails.gemspec @@ -25,5 +25,5 @@ Gem::Specification.new do |s| s.add_dependency('activeresource', version) s.add_dependency('actionmailer', version) s.add_dependency('railties', version) - s.add_dependency('bundler', '>= 1.0.0.rc.1') + s.add_dependency('bundler', '>= 1.0.0.rc.2') end diff --git a/railties/guides/rails_guides.rb b/railties/guides/rails_guides.rb index e6f0b694a6..dfbb06cc76 100644 --- a/railties/guides/rails_guides.rb +++ b/railties/guides/rails_guides.rb @@ -1,6 +1,13 @@ pwd = File.dirname(__FILE__) $:.unshift pwd +# This is a predicate useful for the doc:guides task of applications. +def bundler? + # Note that rake sets the cwd to the one that contains the Rakefile + # being executed. + File.exists?('Gemfile') +end + # Loading Action Pack requires rack and erubis. require 'rubygems' @@ -20,7 +27,19 @@ begin gem 'RedCloth', '>= 4.1.1' require 'redcloth' rescue Gem::LoadError - $stderr.puts %(Generating Guides requires RedCloth 4.1.1+) + $stderr.puts('Generating guides requires RedCloth 4.1.1+.') + $stderr.puts(<<ERROR) if bundler? +Please add + + gem 'RedCloth', '>= 4.1.1' + +to the Gemfile, run + + bundle install + +and try again. +ERROR + exit 1 end diff --git a/railties/guides/source/contributing_to_rails.textile b/railties/guides/source/contributing_to_rails.textile index 094a4ef1a9..fb81bab98d 100644 --- a/railties/guides/source/contributing_to_rails.textile +++ b/railties/guides/source/contributing_to_rails.textile @@ -69,7 +69,7 @@ All of the Rails tests must pass with any code you submit, otherwise you have no NOTE: Ensure you install bundler v1.0 <shell> -gem install -v=1.0.0.rc.1 bundler +gem install -v=1.0.0.rc.2 bundler bundle install --without db </shell> diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index 28afdb3bd0..f80c00b280 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -118,7 +118,7 @@ Now with Rails 3 we have a Gemfile which defines the basics our application need # Bundle the extra gems: # gem 'bj' - # gem 'nokogiri', '1.4.1' + # gem 'nokogiri' # gem 'sqlite3-ruby', :require => 'sqlite3' # gem 'aws-s3', :require => 'aws/s3' @@ -141,13 +141,13 @@ Here the only two gems we need are +rails+ and +sqlite3-ruby+, so it seems. This * activesupport-3.0.0.beta4.gem * arel-0.4.0.gem * builder-2.1.2.gem -* bundler-1.0.0.beta.5.gem +* bundler-1.0.0.rc.2.gem * erubis-2.6.6.gem * i18n-0.4.1.gem * mail-2.2.5.gem * memcache-client-1.8.5.gem * mime-types-1.16.gem -* nokogiri-1.4.2.gem +* nokogiri-1.4.3.1.gem * polyglot-0.3.1.gem * rack-1.2.1.gem * rack-mount-0.6.9.gem diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 1324cc1f67..96c49a81bb 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -216,7 +216,7 @@ module Rails empty_directory '.' set_default_accessors! - FileUtils.cd(destination_root) + FileUtils.cd(destination_root) unless options[:pretend] end def create_root_files diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index a108968b97..1980684a94 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -28,7 +28,7 @@ gem '<%= gem_for_database %>'<% if require_for_database %>, :require => '<%= req # Bundle the extra gems: # gem 'bj' -# gem 'nokogiri', '1.4.1' +# gem 'nokogiri' # gem 'sqlite3-ruby', :require => 'sqlite3' # gem 'aws-s3', :require => 'aws/s3' diff --git a/railties/lib/rails/tasks/documentation.rake b/railties/lib/rails/tasks/documentation.rake index 843d2b4e82..c1b1a41d48 100644 --- a/railties/lib/rails/tasks/documentation.rake +++ b/railties/lib/rails/tasks/documentation.rake @@ -55,7 +55,7 @@ namespace :doc do rdoc.template = "#{ENV['template']}.rb" if ENV['template'] rdoc.title = "Rails Framework Documentation" rdoc.options << '--line-numbers' << '--inline-source' - rdoc.rdoc_files.include('README.rdoc') + rdoc.rdoc_files.include('README') gem_path('actionmailer') do |actionmailer| %w(README.rdoc CHANGELOG MIT-LICENSE lib/action_mailer/base.rb).each do |file| diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 67a878e926..1e0b3bf4c7 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -58,6 +58,12 @@ class AppGeneratorTest < Rails::Generators::TestCase DEFAULT_APP_FILES.each{ |path| assert_file path } end + def test_application_generate_pretend + run_generator ["testapp", "--pretend"] + + DEFAULT_APP_FILES.each{ |path| assert_no_file path } + end + def test_application_controller_and_layout_files run_generator assert_file "app/views/layouts/application.html.erb", /stylesheet_link_tag :all/ |