Skip to content

Commit

Permalink
Merge remote branch 'rails/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
fxn committed Jul 31, 2010
2 parents 0e20e3e + d3819da commit 3d70998
Show file tree
Hide file tree
Showing 19 changed files with 99 additions and 56 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Expand Up @@ -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'
Expand All @@ -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
Expand Down
29 changes: 19 additions & 10 deletions README.rdoc
Expand Up @@ -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

Expand Down
Expand Up @@ -22,7 +22,7 @@ def replace(record)
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
Expand Down
14 changes: 7 additions & 7 deletions activerecord/lib/active_record/relation.rb
Expand Up @@ -99,7 +99,7 @@ def many?
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

Expand Down Expand Up @@ -316,12 +316,12 @@ def to_sql

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

Expand Down
30 changes: 12 additions & 18 deletions activerecord/lib/active_record/relation/query_methods.rb
Expand Up @@ -47,8 +47,8 @@ def joins(*args)
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

Expand Down Expand Up @@ -129,7 +129,7 @@ def custom_join_sql(*joins)
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?
Expand All @@ -143,33 +143,27 @@ def build_arel
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)
Expand Down
Expand Up @@ -215,6 +215,10 @@ def test_belongs_to_counter_with_reassigning

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
Expand Down
5 changes: 5 additions & 0 deletions activerecord/test/cases/relations_test.rb
Expand Up @@ -22,6 +22,11 @@ def test_apply_relation_as_where_id
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
Expand Down
7 changes: 1 addition & 6 deletions activesupport/lib/active_support/cache.rb
Expand Up @@ -138,7 +138,7 @@ class Store

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
Expand All @@ -147,11 +147,6 @@ def initialize (options = nil)
@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
Expand Down
@@ -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.
#
Expand Down
7 changes: 6 additions & 1 deletion 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
Expand Down
9 changes: 7 additions & 2 deletions 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
Expand Down Expand Up @@ -80,4 +85,4 @@ def parse(data)
end
end
end
end
end
2 changes: 1 addition & 1 deletion rails.gemspec
Expand Up @@ -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
21 changes: 20 additions & 1 deletion 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'

Expand All @@ -20,7 +27,19 @@
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

Expand Down
2 changes: 1 addition & 1 deletion railties/guides/source/contributing_to_rails.textile
Expand Up @@ -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>

Expand Down
6 changes: 3 additions & 3 deletions railties/guides/source/initialization.textile
Expand Up @@ -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'

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion railties/lib/rails/generators/rails/app/app_generator.rb
Expand Up @@ -216,7 +216,7 @@ def create_root

empty_directory '.'
set_default_accessors!
FileUtils.cd(destination_root)
FileUtils.cd(destination_root) unless options[:pretend]
end

def create_root_files
Expand Down
2 changes: 1 addition & 1 deletion railties/lib/rails/generators/rails/app/templates/Gemfile
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion railties/lib/rails/tasks/documentation.rake
Expand Up @@ -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|
Expand Down
6 changes: 6 additions & 0 deletions railties/test/generators/app_generator_test.rb
Expand Up @@ -58,6 +58,12 @@ def test_application_skeleton_is_created
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/
Expand Down

0 comments on commit 3d70998

Please sign in to comment.