Commit Graph

4400 Commits

Author SHA1 Message Date
Yves Senn
4b7a33e142 assigning '0.0' to a nullable numeric column does not make it dirty 2013-03-05 14:00:41 +01:00
Yves Senn
8c7d4018e0 ActiveRecord::Base.include_root_in_json is false by default.
Closes #9459.

The PR #6597 unified the configuration for `include_root_in_json`
in AM and AR to `false`.
Later on with the refactoring commit: e030f26 the value in AR was
set to `true` but I think this was not on purpose.

With this commit both AM and AR will have the same configuration
for `include_root_in_json`, which is `false`.
2013-03-04 21:18:40 +01:00
Yves Senn
eeba679470 rewrite tests to have no side-effects on include_root_in_json. 2013-03-04 21:18:40 +01:00
wangjohn
293875457b Created an unscope method for removing relations from a chain of
relations. Specific where values can be unscoped, and the unscope method
still works when relations are merged or combined.
2013-03-03 20:42:01 -05:00
Andrew White
c09f934dcb Merge pull request #9431 from troyk/patch-2
Fix PostgreSQL TIMESTAMP WITH TIME ZONE to return ActiveSupport::Time
2013-03-02 10:03:04 +00:00
Yves Senn
b9399c470b deal with #append and #prepend on association collections.
Closes #7364.

Collection associations behave similar to Arrays. However there is no
way to prepend records. And to append one should use `<<`. Before this
patch `#append` and `#prepend` did not add the record to the loaded
association.

`#append` now behaves like `<<` and `#prepend` is not defined.
2013-03-01 21:29:46 +01:00
Troy Kruthoff
2cc09441c2 Fix PostgreSQL TIMESTAMP WITH TIME ZONE to return ActiveSupport::Time
In an AR model a timestamptz attribute would return a ruby string and AR
tests did not check for any type casting.  Previous tests would pass
only because an assert_equal was being used on a Time.utc object, which
will parse the right side of the eq to a valid Time instance for
comparision.

switch to test instance of Time instead of ActiveSupport::TimeWithZone
2013-03-01 09:51:23 -08:00
kennyj
e2a4b7a506 Wrong exception is occured when raising no translatable exception 2013-03-01 02:47:57 +09:00
Yves Senn
5d0ca74622 Support PostgreSQL specific column types when using change_table.
Closes #9480.

We use `TableDefinition` for `#create_table` and `Table` for `#change_table`.
The PostgreSQL sepcifc types were only defined on `TableDefinition` so I
also added them to `Table`.
2013-02-28 13:42:30 +01:00
Steve Klabnik
afd4a14332 Revert "Merge pull request #9207 from dylanahsmith/mysql-quote-numeric"
This reverts commit 408227d9c5ed7de26310d72a1a99c1ee02311c63, reversing
changes made to dca0b57d03deffc933763482e615c3cf0b9a1d97.
2013-02-27 08:46:40 -08:00
Erik Peterson
72a4670af1 Fix default output for postgres network address types 2013-02-26 14:26:53 -05:00
Olek Janiszewski
dce4383319 Fix touching an invalid parent record for belongs_to
If the parent of a `belongs_to` record fails to be saved due to
validation errors, `touch` will be called on a new record, which causes
an exception (see https://github.com/rails/rails/pull/9320).

Example:

    class Owner < ActiveRecord::Base
      validates_presence_of :name
    end

    class Pet < ActiveRecord::Base
      belongs_to :owner, touch: true
    end

    pet = Pet.new(owner: Owner.new)

    # Before, this line would raise ActiveRecord::ActiveRecordError
    # "can not touch on a new record object"
    pet.save
2013-02-26 18:46:10 +01:00
Rafael Mendonça França
8bc5e714f4 Merge pull request #9414 from senny/9275_order_with_symbol_and_join
Expand order(:symbol) to "table".symbol to prevent broken queries on PG.
2013-02-26 05:15:14 -08:00
Yves Senn
e035699085 Expand order(:symbol) to "table".symbol to prevent broken queries on PG.
Fixes #9275.

When `#order` is called with a Symbol this patch will prepend the quoted_table_name.
Before the postgresql adapter failed to build queries containg a join and an order
with a symbol.

This expansion happens for all adapters.
2013-02-25 18:00:34 +01:00
Hiroshige Umino
ec9aa3ca89 Do not override attributes on dup by default scopes 2013-02-26 00:30:49 +09:00
Rafael Mendonça França
fa8a78d12e ✂️ 2013-02-25 10:18:55 -03:00
Aaron Patterson
45321a69b3 Merge pull request #9246 from Noemj/update_prepared_statements
Changed update to use prepared statements
2013-02-24 22:16:52 -08:00
wangjohn
e52ff80960 Raising an ActiveRecordError when one tries to use .touch(name) on a new
object that has not yet been persisted. This behavior follows the
precedent set by update_columns.
2013-02-25 00:29:28 -05:00
Rafael Mendonça França
70ec7e0245 Remove warning 2013-02-24 18:22:23 -03:00
Yves Senn
4ef75b63db don't apply invalid ordering when preloading hmt associations.
closes #8663.

When preloading a hmt association there two possible scenarios:

1.) preload with 2 queries: first hm association, then hmt with id IN ()
2.) preload with join: hmt association is loaded with a join on the hm association

The bug was happening in scenario 1.) with a normal order clause on the hmt association.
The ordering was also applied when loading the hm association, which resulted in the error.

This patch only applies the ordering the the hm-relation if we are performing a join (2).
Otherwise the order will only appear in the second query (1).
2013-02-24 20:51:39 +01:00
Xavier Noria
d65376fce4 Merge pull request #9400 from senny/remove_auto_explain_threshold_in_seconds
remove config.auto_explain_threshold_in_seconds
2013-02-24 11:16:35 -08:00
Yves Senn
d3688e02ca remove AR auto-explain (config.auto_explain_threshold_in_seconds)
We discussed that the auto explain feature is rarely used.
This PR removes only the automatic explain. You can still display
the explain output for any given relation using `ActiveRecord::Relation#explain`.

As a side-effect this should also fix the connection problem during
asset compilation (#9385). The auto explain initializer in the `ActiveRecord::Railtie`
forced a connection.
2013-02-24 20:01:04 +01:00
Rafael Mendonça França
d5ec8efdaf Skip connection url test when the machine is using socket configuration.
The connection url parssing don't accept the socket option
2013-02-24 14:36:18 -03:00
Rafael Mendonça França
e54acf1308 Do not type cast all the database url values.
We should only type cast when we need to use.

Related to 4b005fb371c2e7af80df7da63be94509b1db038c
2013-02-24 14:36:18 -03:00
Steve Klabnik
c3d001b048 Merge pull request #9356 from senny/988_multiple_actions_for_after_commit
multiple actions for :on option with `after_commit` and `after_rollback`
2013-02-24 08:30:48 -08:00
Yves Senn
96c1cafd3a test case to prevent duplicated associations with custom PK.
closes #9201
2013-02-24 16:49:47 +01:00
Yasuo Honda
6fad6b5e5c Oracle enhanced adapter shortens its name if it is longer than 30 bytes
because of Oracle database index length spec.
2013-02-24 12:11:34 +09:00
Yves Senn
e7f0716eee also rename the test-case class inside columns_test.rb 2013-02-24 02:26:01 +01:00
Yves Senn
d03928c81a rename_column_test.rb -> columns_test.rb to reveal intent.
I renamed the test to better communicate it's intention. Since it also tests:
  - add_column
  - remove_column
  - change_column
There is no reason to call it rename_column_test.
2013-02-23 15:42:55 +01:00
Yves Senn
2d4e3fecc2 forwardport #9388 rename/remove column preserves custom PK. 2013-02-23 15:40:07 +01:00
Yves Senn
d98763a602 multiple actions for :on option with after_commit and after_rollback
Closes #988.
2013-02-21 15:02:52 +01:00
Rafael Mendonça França
6614471173 Fix warning 2013-02-21 00:51:39 -03:00
Rafael Mendonça França
d3563bd661 Skip failing test and add a FIXME note 2013-02-20 14:32:11 -03:00
Yves Senn
39eef1a565 also rename indexes when a table or column is renamed
When a table or a column is renamed related indexes kept their name. This will lead to confusing names. This patch renames related indexes when a column or a table is renamed. Only indexes with names generated by rails will be renamed. Indexes with custom names will not be renamed.
2013-02-20 18:19:25 +01:00
Yves Senn
cca43528d4 reserve index name chars for internal rails operations
Some adapter (SQLite3) need to perform renaming operations to support
the rails DDL. These rename prefixes operate with prefixes. When an
index name already uses up the full space provieded by
`index_name_length` these internal operations will fail. This patch
introduces `allowed_index_name_length` which respects the amount of
characters used for internal operations. It will always be <=
`index_name_length` and every adapter can define how many characters
need to be reserved.
2013-02-20 17:50:10 +01:00
Rafael Mendonça França
7bae72c69f Merge pull request #9332 from wangjohn/adding_documentation_to_error_raising_in_query_methods
Tests to make sure empty arguments in WhereChain raise errors
2013-02-20 08:38:50 -08:00
wangjohn
d49f862b9a Added comments about the check_empty_arguments method which is called
for query methods in a where_clause. Also, modified the CHANGELOG entry
because it had false information and added tests.
2013-02-20 10:53:25 -05:00
wangjohn
67d8bb963d Reduced memory leak problem in transactions by lazily updating AR objects with new transaction state. If AR object has a callback, the callback will be performed immediately (non-lazily) so the transaction still has to keep records with callbacks. 2013-02-20 10:51:28 -05:00
Rafael Mendonça França
e1456ad95e Whitespace ❤️ and hash syntax change 2013-02-20 10:27:18 -03:00
Yves Senn
0a6b61a5f5 descriptive error message when AR adapter was not found. Closes #7313. 2013-02-20 10:54:58 +01:00
Takehiro Adachi
679777849b delete duplicated tests in AR base_test.rb
These are duplicated with the tests which are in relations_test.rb
2013-02-19 21:38:25 +09:00
Takehiro Adachi
2db91fb546 add tests for ActiveRecord::Base#create 2013-02-18 02:12:08 +09:00
Jon Leighton
c65b076328 Revert "checking in the abstractions for valid type checking:"
This reverts commit c321b309a9a90bbfa0912832c11b3fef52e71840.

Conflicts:
	activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
	activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb

Reason: failing test

  1) Error:
test_valid_column(ActiveRecord::ConnectionAdapters::SQLite3AdapterTest):
NoMethodError: undefined method `column' for
    test/cases/adapters/sqlite3/sqlite3_adapter_test.rb:29:in
`test_valid_column'
2013-02-15 16:23:25 +00:00
Yves Senn
4a4ff50459 don't cache invalid subsets when preloading hmt associations.
closes #8423.
2013-02-14 17:46:07 +01:00
James Miller
caabed6c76 Don't call after_commit when creating through an association and save fails, fixes #5802 2013-02-13 12:27:06 -08:00
Aaron Patterson
f8c8ad56c8 Merge pull request #9204 from ranjaykrishna/col-prob
schema dumper tests now conducted by ActiveRecord::Base.Connection
2013-02-12 13:26:40 -08:00
Ranjay Krishna
c321b309a9 checking in the abstractions for valid type checking: 2013-02-12 02:10:48 -05:00
Aaron Patterson
0268b5d8cd test for regression from a712e08ebe21f6d8653a0e6602df2e0f5d40d9ca 2013-02-11 18:36:46 -08:00
Sergey Nartimov
9dfef5a46b define Active Record Store accessors in a module
Allow store accessors to be overrided like other attribute methods,
e.g.:

    class User < ActiveRecord::Base
      store :settings, accessors: [ :color, :homepage ], coder: JSON

      def color
        super || 'red'
      end
    end
2013-02-11 17:00:55 +03:00
Noemj
a53935dfa0 Changed update_record to use prepared statements. 2013-02-11 15:17:06 +02:00