Skip to content
Browse files

Merge branch 'master' into mail

  • Loading branch information...
2 parents 671538c + f8d06e6 commit ada895e8cac855a2f248aafdb92457365f062d07 @jeremy jeremy committed Nov 23, 2009
View
3 Gemfile
@@ -1,6 +1,3 @@
-clear_sources
-source 'http://gemcutter.org'
-
gem "rake", ">= 0.8.7"
gem "mocha", ">= 0.9.8"
View
14 actionpack/test/controller/routing_test.rb
@@ -1419,15 +1419,13 @@ def test_route_requirement_generate_with_ignore_case
:requirements => {:name => /(david|jamis)/i}
end
- pending do
- url = set.generate({:controller => 'pages', :action => 'show', :name => 'david'})
- assert_equal "/page/david", url
- assert_raise ActionController::RoutingError do
- url = set.generate({:controller => 'pages', :action => 'show', :name => 'davidjamis'})
- end
- url = set.generate({:controller => 'pages', :action => 'show', :name => 'JAMIS'})
- assert_equal "/page/JAMIS", url
+ url = set.generate({:controller => 'pages', :action => 'show', :name => 'david'})
+ assert_equal "/page/david", url
+ assert_raise ActionController::RoutingError do
+ url = set.generate({:controller => 'pages', :action => 'show', :name => 'davidjamis'})
end
+ url = set.generate({:controller => 'pages', :action => 'show', :name => 'JAMIS'})
+ assert_equal "/page/JAMIS", url
end
def test_route_requirement_recognize_with_extended_syntax
View
10 activerecord/lib/active_record/associations.rb
@@ -61,6 +61,12 @@ def initialize(owner, reflection)
end
end
+ class HasAndBelongsToManyAssociationWithPrimaryKeyError < ActiveRecordError #:nodoc:
+ def initialize(reflection)
+ super("Primary key is not allowed in a has_and_belongs_to_many join table (#{reflection.options[:join_table]}).")
+ end
+ end
+
class HasAndBelongsToManyAssociationForeignKeyNeeded < ActiveRecordError #:nodoc:
def initialize(reflection)
super("Cannot create self referential has_and_belongs_to_many association on '#{reflection.class_name rescue nil}##{reflection.name rescue nil}'. :association_foreign_key cannot be the same as the :foreign_key.")
@@ -1675,7 +1681,6 @@ def create_belongs_to_reflection(association_id, options)
def create_has_and_belongs_to_many_reflection(association_id, options, &extension)
options.assert_valid_keys(valid_keys_for_has_and_belongs_to_many_association)
-
options[:extend] = create_extension_modules(association_id, extension, options[:extend])
reflection = create_reflection(:has_and_belongs_to_many, association_id, options, self)
@@ -1685,6 +1690,9 @@ def create_has_and_belongs_to_many_reflection(association_id, options, &extensio
end
reflection.options[:join_table] ||= join_table_name(undecorated_table_name(self.to_s), undecorated_table_name(reflection.class_name))
+ if connection.supports_primary_key? && (connection.primary_key(reflection.options[:join_table]) rescue false)
+ raise HasAndBelongsToManyAssociationWithPrimaryKeyError.new(reflection)
+ end
reflection
end
View
14 activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
@@ -1,11 +1,6 @@
module ActiveRecord
module Associations
class HasAndBelongsToManyAssociation < AssociationCollection #:nodoc:
- def initialize(owner, reflection)
- super
- @primary_key_list = {}
- end
-
def create(attributes = {})
create_record(attributes) { |record| insert_record(record) }
end
@@ -23,9 +18,7 @@ def reset_column_information
end
def has_primary_key?
- return @has_primary_key unless @has_primary_key.nil?
- @has_primary_key = (@owner.connection.supports_primary_key? &&
- @owner.connection.primary_key(@reflection.options[:join_table]))
+ @has_primary_key ||= @owner.connection.supports_primary_key? && @owner.connection.primary_key(@reflection.options[:join_table])
end
protected
@@ -40,11 +33,6 @@ def count_records
end
def insert_record(record, force = true, validate = true)
- if has_primary_key?
- raise ActiveRecord::ConfigurationError,
- "Primary key is not allowed in a has_and_belongs_to_many join table (#{@reflection.options[:join_table]})."
- end
-
if record.new_record?
if force
record.save!
View
16 activerecord/test/cases/associations/habtm_join_table_test.rb
@@ -36,21 +36,9 @@ def teardown
uses_transaction :test_should_raise_exception_when_join_table_has_a_primary_key
def test_should_raise_exception_when_join_table_has_a_primary_key
if ActiveRecord::Base.connection.supports_primary_key?
- assert_raise ActiveRecord::ConfigurationError do
- jaime = MyReader.create(:name=>"Jaime")
- jaime.my_books << MyBook.create(:name=>'Great Expectations')
+ assert_raise ActiveRecord::HasAndBelongsToManyAssociationWithPrimaryKeyError do
+ MyReader.has_and_belongs_to_many :my_books
end
end
end
-
- uses_transaction :test_should_cache_result_of_primary_key_check
- def test_should_cache_result_of_primary_key_check
- if ActiveRecord::Base.connection.supports_primary_key?
- ActiveRecord::Base.connection.stubs(:primary_key).with('my_books_my_readers').returns(false).once
- weaz = MyReader.create(:name=>'Weaz')
-
- weaz.my_books << MyBook.create(:name=>'Great Expectations')
- weaz.my_books << MyBook.create(:name=>'Greater Expectations')
- end
- end
end
View
3 activerecord/test/fixtures/edges.yml
@@ -1,6 +1,5 @@
<% (1..4).each do |id| %>
edge_<%= id %>:
- id: <%= id %>
source_id: <%= id %>
sink_id: <%= id + 1 %>
-<% end %>
+<% end %>
View
2 activerecord/test/schema/schema.rb
@@ -160,7 +160,7 @@ def create_table(*args, &block)
t.integer :access_level, :default => 1
end
- create_table :edges, :force => true do |t|
+ create_table :edges, :force => true, :id => false do |t|
t.column :source_id, :integer, :null => false
t.column :sink_id, :integer, :null => false
end
View
4 activesupport/lib/active_support/core_ext/logger.rb
@@ -137,10 +137,10 @@ def format_message(severity, timestamp, msg, progname)
attr_writer :formatter
public :formatter=
- alias old_format_datetime format_datetime
+ alias old_format_datetime format_datetime if method_defined?(:format_datetime)
def format_datetime(datetime) datetime end
- alias old_msg2str msg2str
+ alias old_msg2str msg2str if method_defined?(:msg2str)
def msg2str(msg) msg end
end
end
View
92 activesupport/lib/active_support/notifications.rb
@@ -41,7 +41,7 @@ module ActiveSupport
# to subscribers in a thread. You can use any queue implementation you want.
#
module Notifications
- mattr_accessor :queue
+ mattr_accessor :queue, :listener
class << self
delegate :instrument, :transaction_id, :transaction, :to => :instrumenter
@@ -54,8 +54,13 @@ def publisher
@publisher ||= Publisher.new(queue)
end
- def subscribe(pattern=nil, &block)
- Subscriber.new(queue).bind(pattern).subscribe(&block)
+ def subscriber
+ @subscriber ||= Subscriber.new(queue)
+ end
+
+ def subscribe(pattern=nil, options={}, &block)
+ with = options[:with] || listener
+ subscriber.bind(with, pattern).subscribe(&block)
end
end
@@ -104,13 +109,14 @@ def initialize(queue)
@queue = queue
end
- def bind(pattern)
- @pattern = pattern
+ def bind(listener, pattern)
+ @listener = listener
+ @pattern = pattern
self
end
def subscribe
- @queue.subscribe(@pattern) do |*args|
+ @queue.subscribe(@listener, @pattern) do |*args|
yield(*args)
end
end
@@ -138,6 +144,48 @@ def parent_of?(event)
end
end
+ class AsyncListener
+ def initialize(pattern, &block)
+ @pattern = pattern
+ @subscriber = block
+ @queue = Queue.new
+ Thread.new { consume }
+ end
+
+ def publish(name, *args)
+ if !@pattern || @pattern === name.to_s
+ @queue << args.unshift(name)
+ end
+ end
+
+ def consume
+ while args = @queue.shift
+ @subscriber.call(*args)
+ end
+ end
+
+ def drained?
+ @queue.size.zero?
+ end
+ end
+
+ class SyncListener
+ def initialize(pattern, &block)
+ @pattern = pattern
+ @subscriber = block
+ end
+
+ def publish(name, *args)
+ if !@pattern || @pattern === name.to_s
+ @subscriber.call(*args.unshift(name))
+ end
+ end
+
+ def drained?
+ true
+ end
+ end
+
# This is a default queue implementation that ships with Notifications. It
# consumes events in a thread and publish them to all registered subscribers.
#
@@ -150,40 +198,16 @@ def publish(*args)
@listeners.each { |l| l.publish(*args) }
end
- def subscribe(pattern=nil, &block)
- @listeners << Listener.new(pattern, &block)
+ def subscribe(listener, pattern=nil, &block)
+ @listeners << listener.new(pattern, &block)
end
def drained?
@listeners.all? &:drained?
end
-
- class Listener
- def initialize(pattern, &block)
- @pattern = pattern
- @subscriber = block
- @queue = Queue.new
- Thread.new { consume }
- end
-
- def publish(name, *args)
- if !@pattern || @pattern === name.to_s
- @queue << args.unshift(name)
- end
- end
-
- def consume
- while args = @queue.shift
- @subscriber.call(*args)
- end
- end
-
- def drained?
- @queue.size.zero?
- end
- end
end
end
- Notifications.queue = Notifications::LittleFanout.new
+ Notifications.queue = Notifications::LittleFanout.new
+ Notifications.listener = Notifications::AsyncListener
end
View
17 activesupport/test/notifications_test.rb
@@ -176,6 +176,21 @@ def test_subscriber_with_pattern_as_regexp
assert_equal 1, @another.first.result
end
+ def test_subscriber_allows_sync_listeners
+ @another = []
+ ActiveSupport::Notifications.subscribe(/cache/, :with => ActiveSupport::Notifications::SyncListener) do |*args|
+ @another << ActiveSupport::Notifications::Event.new(*args)
+ end
+
+ Thread.expects(:new).never
+ ActiveSupport::Notifications.instrument(:something){ 0 }
+ ActiveSupport::Notifications.instrument(:cache){ 1 }
+
+ assert_equal 1, @another.size
+ assert_equal :cache, @another.first.name
+ assert_equal 1, @another.first.result
+ end
+
def test_with_several_consumers_and_several_events
@another = []
ActiveSupport::Notifications.subscribe do |*args|
@@ -201,6 +216,6 @@ def test_with_several_consumers_and_several_events
private
def drain
- sleep(0.1) until ActiveSupport::Notifications.queue.drained?
+ sleep(0.05) until ActiveSupport::Notifications.queue.drained?
end
end
View
2 railties/CHANGELOG
@@ -1,5 +1,7 @@
*Edge*
+* Fixed that the debugger wouldn't go into IRB mode because of left-over ARGVs [DHH]
+
* I18n support for plugins. #2325 [Antonio Tapiador, Sven Fuchs]
* Ruby 1.9: use UTF-8 for default internal and external encodings. [Jeremy Kemper]
View
34 railties/lib/rails/generators.rb
@@ -86,28 +86,16 @@ def self.options #:nodoc:
@options ||= DEFAULT_OPTIONS.dup
end
- # We have two scenarios here: when rubygems is loaded and when bundler is
- # being used. If rubygems is loaded, we get all generators paths from loaded
- # specs. Otherwise we just have to look into vendor/gems/gems.
- #
- def self.gems_generators_paths
- paths = []
-
- if defined?(Gem) && Gem.respond_to?(:loaded_specs)
- Gem.loaded_specs.each do |name, spec|
- generator_path = File.join(spec.full_gem_path, "lib/generators")
- paths << generator_path if File.exist?(generator_path)
- end
+ def self.gems_generators_paths #:nodoc:
+ return [] unless defined?(Gem) && Gem.respond_to?(:loaded_specs)
+ Gem.loaded_specs.inject([]) do |paths, (name, spec)|
+ paths += Dir[File.join(spec.full_gem_path, "lib/{generators,rails_generators}")]
end
-
- paths
end
- # Load paths from plugin.
- #
- def self.plugins_generators_paths
+ def self.plugins_generators_paths #:nodoc:
return [] unless Rails.root
- Dir[File.join(Rails.root, "vendor", "plugins", "*", "lib", "generators")]
+ Dir[File.join(Rails.root, "vendor", "plugins", "*", "lib", "{generators,rails_generators}")]
end
# Hold configured generators fallbacks. If a plugin developer wants a
@@ -147,8 +135,8 @@ def self.no_color!
def self.load_paths
@load_paths ||= begin
paths = []
- paths << File.join(Rails.root, "lib", "generators") if Rails.root
- paths << File.join(Thor::Util.user_home, ".rails", "generators")
+ paths += Dir[File.join(Rails.root, "lib", "{generators,rails_generators}")] if Rails.root
+ paths += Dir[File.join(Thor::Util.user_home, ".rails", "{generators,rails_generators}")]
paths += self.plugins_generators_paths
paths += self.gems_generators_paths
paths << File.expand_path(File.join(File.dirname(__FILE__), "generators"))
@@ -210,7 +198,7 @@ def self.find_by_namespace(name, base=nil, context=nil) #:nodoc:
return klass if klass
end
- invoke_fallbacks_for(name, base)
+ invoke_fallbacks_for(name, base) || invoke_fallbacks_for(context, name)
end
# Receives a namespace, arguments and the behavior to invoke the generator.
@@ -278,13 +266,13 @@ def self.builtin #:nodoc:
# By default, Rails strips the generator namespace to make invocations
# easier. This method generaters the both possibilities names.
- def self.generator_names(first, second)
+ def self.generator_names(first, second) #:nodoc:
[ "#{first}:generators:#{second}", "#{first}:#{second}" ]
end
# Try callbacks for the given base.
#
- def self.invoke_fallbacks_for(name, base)
+ def self.invoke_fallbacks_for(name, base) #:nodoc:
return nil unless base && fallbacks[base.to_sym]
invoked_fallbacks = []
View
2 railties/lib/rails/rack/debugger.rb
@@ -4,6 +4,8 @@ class Debugger
def initialize(app)
@app = app
+ ARGV.clear # clear ARGV so that script/server options aren't passed to IRB
+
require_library_or_gem 'ruby-debug'
::Debugger.start
::Debugger.settings[:autoeval] = true if ::Debugger.respond_to?(:settings)
View
0 ...s/mspec/lib/generators/mspec_generator.rb → ...c/lib/rails_generators/mspec_generator.rb
File renamed without changes.
View
7 railties/test/generators_test.rb
@@ -150,6 +150,13 @@ def test_fallbacks_for_generators_on_find_by_namespace
assert_equal "test_unit:generators:plugin", klass.namespace
end
+ def test_fallbacks_for_generators_on_find_by_namespace_with_context
+ Rails::Generators.fallbacks[:remarkable] = :test_unit
+ klass = Rails::Generators.find_by_namespace(:remarkable, :rails, :plugin)
+ assert klass
+ assert_equal "test_unit:generators:plugin", klass.namespace
+ end
+
def test_fallbacks_for_generators_on_invoke
Rails::Generators.fallbacks[:shoulda] = :test_unit
TestUnit::Generators::ModelGenerator.expects(:start).with(["Account"], {})

0 comments on commit ada895e

Please sign in to comment.
Something went wrong with that request. Please try again.