From 13867a3f5f3e2248660a942956985a4eacacb283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 30 Apr 2010 18:40:24 +0200 Subject: Use %{} syntax in I18n (faster) instead of {{}}. --- activerecord/lib/active_record/locale/en.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/locale/en.yml b/activerecord/lib/active_record/locale/en.yml index 810359fef3..9d5cb54180 100644 --- a/activerecord/lib/active_record/locale/en.yml +++ b/activerecord/lib/active_record/locale/en.yml @@ -9,7 +9,7 @@ en: errors: messages: taken: "has already been taken" - record_invalid: "Validation failed: {{errors}}" + record_invalid: "Validation failed: %{errors}" # Append your own errors here or at the model/attributes scope. # You can define own errors for models or model attributes. @@ -18,7 +18,7 @@ en: # For example, # models: # user: - # blank: "This is a custom blank message for {{model}}: {{attribute}}" + # blank: "This is a custom blank message for %{model}: %{attribute}" # attributes: # login: # blank: "This is a custom blank message for User login" -- cgit v1.2.3 From 8b1b273c21a2f1a6eeccca5fbe0303679c2d707d Mon Sep 17 00:00:00 2001 From: Cezary Baginski Date: Sat, 1 May 2010 19:21:31 +0200 Subject: AR: fixed postgres transaction tests [#4519 state:commited] Signed-off-by: Jeremy Kemper --- .../lib/active_record/connection_adapters/postgresql_adapter.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 74fed4ad62..6389094b8a 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -490,12 +490,8 @@ module ActiveRecord execute "ROLLBACK" end - if defined?(PGconn::PQTRANS_IDLE) - # The ruby-pg driver supports inspecting the transaction status, - # while the ruby-postgres driver does not. - def outside_transaction? - @connection.transaction_status == PGconn::PQTRANS_IDLE - end + def outside_transaction? + @connection.transaction_status == PGconn::PQTRANS_IDLE end def create_savepoint -- cgit v1.2.3 From 6433c939c1314ddf92c9986bb8664e568ca22d11 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 2 May 2010 00:40:31 +0200 Subject: edit pass in the transactions preamble rdoc --- activerecord/lib/active_record/transactions.rb | 55 +++++++++++++++----------- 1 file changed, 31 insertions(+), 24 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/transactions.rb b/activerecord/lib/active_record/transactions.rb index 796dd99f02..1a195fbb81 100644 --- a/activerecord/lib/active_record/transactions.rb +++ b/activerecord/lib/active_record/transactions.rb @@ -31,10 +31,10 @@ module ActiveRecord # mary.deposit(100) # end # - # This example will only take money from David and give to Mary if neither - # +withdrawal+ nor +deposit+ raises an exception. Exceptions will force a - # ROLLBACK that returns the database to the state before the transaction was - # begun. Be aware, though, that the objects will _not_ have their instance + # This example will only take money from David and give it to Mary if neither + # +withdrawal+ nor +deposit+ raise an exception. Exceptions will force a + # ROLLBACK that returns the database to the state before the transaction + # began. Be aware, though, that the objects will _not_ have their instance # data returned to their pre-transactional state. # # == Different Active Record classes in a single transaction @@ -44,16 +44,16 @@ module ActiveRecord # that class. This is because transactions are per-database connection, not # per-model. # - # In this example a Balance record is transactionally saved even - # though transaction is called on the Account class: + # In this example a +balance+ record is transactionally saved even + # though +transaction+ is called on the +Account+ class: # # Account.transaction do # balance.save! # account.save! # end # - # Note that the +transaction+ method is also available as a model instance - # method. For example, you can also do this: + # The +transaction+ method is also available as a model instance method. + # For example, you can also do this: # # balance.transaction do # balance.save! @@ -62,9 +62,9 @@ module ActiveRecord # # == Transactions are not distributed across database connections # - # A transaction acts on a single database connection. If you have + # A transaction acts on a single database connection. If you have # multiple class-specific databases, the transaction will not protect - # interaction among them. One workaround is to begin a transaction + # interaction among them. One workaround is to begin a transaction # on each class whose models you alter: # # Student.transaction do @@ -74,16 +74,22 @@ module ActiveRecord # end # end # - # This is a poor solution, but full distributed transactions are beyond + # This is a poor solution, but fully distributed transactions are beyond # the scope of Active Record. # - # == Save and destroy are automatically wrapped in a transaction + # == +save+ and +destroy+ are automatically wrapped in a transaction # - # Both Base#save and Base#destroy come wrapped in a transaction that ensures - # that whatever you do in validations or callbacks will happen under the - # protected cover of a transaction. So you can use validations to check for - # values that the transaction depends on or you can raise exceptions in the - # callbacks to rollback, including after_* callbacks. + # Both +save+ and +destroy+ come wrapped in a transaction that ensures + # that whatever you do in validations or callbacks will happen under its + # protected cover. So you can use validations to check for values that + # the transaction depends on or you can raise exceptions in the callbacks + # to rollback, including after_* callbacks. + # + # As a consequence changes to the database are not seen outside your connection + # until the operation is complete. For example, if you try to update the index + # of a search engine in +after_save+ the indexer won't see the updated record. + # The +after_commit+ callback is the only one that is triggered once the update + # is committed. See below. # # == Exception handling and rolling back # @@ -91,14 +97,14 @@ module ActiveRecord # be propagated (after triggering the ROLLBACK), so you should be ready to # catch those in your application code. # - # One exception is the ActiveRecord::Rollback exception, which will trigger + # One exception is the ActiveRecord::Rollback exception, which will trigger # a ROLLBACK when raised, but not be re-raised by the transaction block. # - # *Warning*: one should not catch ActiveRecord::StatementInvalid exceptions - # inside a transaction block. StatementInvalid exceptions indicate that an + # *Warning*: one should not catch ActiveRecord::StatementInvalid exceptions + # inside a transaction block. ActiveRecord::StatementInvalid exceptions indicate that an # error occurred at the database level, for example when a unique constraint # is violated. On some database systems, such as PostgreSQL, database errors - # inside a transaction causes the entire transaction to become unusable + # inside a transaction cause the entire transaction to become unusable # until it's restarted from the beginning. Here is an example which # demonstrates the problem: # @@ -120,11 +126,12 @@ module ActiveRecord # # ignored until end of transaction block" # end # - # One should restart the entire transaction if a StatementError occurred. + # One should restart the entire transaction if an + # ActiveRecord::StatementInvalid occurred. # # == Nested transactions # - # #transaction calls can be nested. By default, this makes all database + # +transaction+ calls can be nested. By default, this makes all database # statements in the nested transaction block become part of the parent # transaction. For example: # @@ -139,7 +146,7 @@ module ActiveRecord # User.find(:all) # => empty # # It is also possible to requires a sub-transaction by passing - # :requires_new => true. If anything goes wrong, the + # :requires_new => true. If anything goes wrong, the # database rolls back to the beginning of the sub-transaction # without rolling back the parent transaction. For example: # -- cgit v1.2.3 From 1b898cc946f69808d5fa0db922ba100fb8ffcfe3 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 2 May 2010 00:47:09 +0200 Subject: say something about after_(commit|rollback) in callbacks.rb, the fact that their implementation is elsewhere is not important for rdoc purposes --- activerecord/lib/active_record/callbacks.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/callbacks.rb b/activerecord/lib/active_record/callbacks.rb index 98c14e6eb0..7ebeb6079e 100644 --- a/activerecord/lib/active_record/callbacks.rb +++ b/activerecord/lib/active_record/callbacks.rb @@ -17,8 +17,13 @@ module ActiveRecord # * (-) create # * (5) after_create # * (6) after_save + # * (7) after_commit # - # That's a total of eight callbacks, which gives you immense power to react and prepare for each state in the + # Also, an after_rollback callback can be configured to be triggered whenever a rollback is issued. + # Check out ActiveRecord::Transactions for more details about after_commit and + # after_rollback. + # + # That's a total of ten callbacks, which gives you immense power to react and prepare for each state in the # Active Record lifecycle. The sequence for calling Base#save for an existing record is similar, except that each # _on_create callback is replaced by the corresponding _on_update callback. # -- cgit v1.2.3 From 256a15c23581865559cc758c2e377cd395cc05b3 Mon Sep 17 00:00:00 2001 From: Cezary Baginski Date: Sat, 1 May 2010 23:33:36 +0200 Subject: AR: fixed postgres fixture tests [#4519 state:resolved] Signed-off-by: Jeremy Kemper --- activerecord/lib/active_record/fixtures.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index 0bc49c1daa..4bf33c3856 100644 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -516,7 +516,7 @@ class Fixtures < (RUBY_VERSION < '1.9' ? YAML::Omap : Hash) # Cap primary key sequences to max(pk). if connection.respond_to?(:reset_pk_sequence!) table_names.each do |table_name| - connection.reset_pk_sequence!(table_name) + connection.reset_pk_sequence!(table_name.tr('/', '_')) end end end -- cgit v1.2.3 From 731d4392e478ff5526b595074d9caa999da8bd0c Mon Sep 17 00:00:00 2001 From: Justin George Date: Tue, 27 Apr 2010 21:16:06 -0700 Subject: Change event namespace ordering to most-significant first [#4504 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit More work still needs to be done on some of these names (render_template.action_view and render_template!.action_view particularly) but this allows (for example) /^sql/ to subscribe to all the various ORMs without further modification Signed-off-by: José Valim --- .../lib/active_record/connection_adapters/abstract/query_cache.rb | 2 +- activerecord/lib/active_record/connection_adapters/abstract_adapter.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb b/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb index 3c560903f7..533a7bb8e6 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb @@ -76,7 +76,7 @@ module ActiveRecord def cache_sql(sql) result = if @query_cache.has_key?(sql) - ActiveSupport::Notifications.instrument("active_record.sql", + ActiveSupport::Notifications.instrument("sql.active_record", :sql => sql, :name => "CACHE", :connection_id => self.object_id) @query_cache[sql] else diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index 578297029b..28a59c1e62 100755 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -197,7 +197,7 @@ module ActiveRecord def log(sql, name) name ||= "SQL" result = nil - ActiveSupport::Notifications.instrument("active_record.sql", + ActiveSupport::Notifications.instrument("sql.active_record", :sql => sql, :name => name, :connection_id => self.object_id) do @runtime += Benchmark.ms { result = yield } end -- cgit v1.2.3 From 9bd91b00b85c77bc294ae2a99beae203cc163227 Mon Sep 17 00:00:00 2001 From: Lawrence Pit Date: Mon, 3 May 2010 16:44:32 +1000 Subject: Favor %{} in all code instead of (deprecated) {{}} as interpolation syntax for I18n MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- .../test/cases/validations/i18n_generate_message_validation_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activerecord') diff --git a/activerecord/test/cases/validations/i18n_generate_message_validation_test.rb b/activerecord/test/cases/validations/i18n_generate_message_validation_test.rb index 15730c2a87..8ee2a5868c 100644 --- a/activerecord/test/cases/validations/i18n_generate_message_validation_test.rb +++ b/activerecord/test/cases/validations/i18n_generate_message_validation_test.rb @@ -15,7 +15,7 @@ class I18nGenerateMessageValidationTest < ActiveRecord::TestCase end def test_generate_message_invalid_with_custom_message - assert_equal 'custom message title', @topic.errors.generate_message(:title, :invalid, :default => 'custom message {{value}}', :value => 'title') + assert_equal 'custom message title', @topic.errors.generate_message(:title, :invalid, :default => 'custom message %{value}', :value => 'title') end # validates_uniqueness_of: generate_message(attr_name, :taken, :default => configuration[:message]) @@ -24,7 +24,7 @@ class I18nGenerateMessageValidationTest < ActiveRecord::TestCase end def test_generate_message_taken_with_custom_message - assert_equal 'custom message title', @topic.errors.generate_message(:title, :taken, :default => 'custom message {{value}}', :value => 'title') + assert_equal 'custom message title', @topic.errors.generate_message(:title, :taken, :default => 'custom message %{value}', :value => 'title') end # ActiveRecord#RecordInvalid exception -- cgit v1.2.3 From 841c01fa0fa92aa6e3c2e5029444a9cbb4f161f3 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Tue, 4 May 2010 17:51:22 +0100 Subject: Use class_inheritable_accessor for connection_handler --- .../connection_adapters/abstract/connection_specification.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb index 2f36bec764..2493095a04 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb @@ -10,8 +10,8 @@ module ActiveRecord ## # :singleton-method: # The connection handler - cattr_accessor :connection_handler, :instance_writer => false - @@connection_handler = ConnectionAdapters::ConnectionHandler.new + class_inheritable_accessor :connection_handler, :instance_writer => false + self.connection_handler = ConnectionAdapters::ConnectionHandler.new # Returns the connection currently associated with the class. This can # also be used to "borrow" the connection to do database work that isn't @@ -54,7 +54,7 @@ module ActiveRecord raise AdapterNotSpecified unless defined?(Rails.env) establish_connection(Rails.env) when ConnectionSpecification - @@connection_handler.establish_connection(name, spec) + self.connection_handler.establish_connection(name, spec) when Symbol, String if configuration = configurations[spec.to_s] establish_connection(configuration) -- cgit v1.2.3