Commit Graph

4628 Commits

Author SHA1 Message Date
Vipul A M
e9177816ff Make test name descriptive and add reference to original regression commit 2013-06-15 18:39:06 +05:30
Rafael Mendonça França
d4de2c34c5 Merge pull request #10521 from yahonda/sanitize_oracle
Remove current_adapter? from test_sanitize_sql_hash_handles_associations
2013-05-08 10:44:16 -07:00
wangjohn
26d19b4661 Created a method to automatically find inverse associations and cache
the results. Added tests to check to make sure that inverse associations are
automatically found when has_many, has_one, or belongs_to associations
are defined.
2013-05-07 23:24:43 -04:00
Yasuo Honda
798cf2b9ef Remove current_adapter? from test_sanitize_sql_hash_handles_associations
Because of each adapter implementation differences,
`expected_value` string needed to be handled by each adapter.
This commit removes current_adapter
by using ActiveRecord::ConnectionAdapters::Quoting methods.
2013-05-08 06:40:15 +09:00
Aaron Patterson
2b5e4f7f98 Revert "Merge pull request #10455 from patricksrobertson/bigserial_id_not_identifying_pk"
This reverts commit 3043d45eefc3776d5f3a9e7d212a01f99d869ef8, reversing
changes made to ca0275d36b395631725c4583db5a45c06443fdb9.
2013-05-07 10:39:41 -07:00
Patrick Robertson
0e00c6b296 Handle other pk types in PostgreSQL gracefully.
In #10410 it was noted that you can no longer create PK's with the
type of bigserial in PostgreSQL in 4.0.0.rc1. This is mostly
because the newer adapter is checking for column type with the
id column instead of just letting it pass through like it did
before.

Side effects:
You may just create a PK column of a type that you really don't
want to be your PK. As far as I can tell this was allowed in 3.2.X
and perhaps an exception should be raised if you try and do
something extremely dumb.
2013-05-07 08:21:41 -04:00
Rafael Mendonça França
19d32e89af Merge pull request #10489 from greenriver/ar_counter_cache_multiple_destroy
Confirm a record has not already been destroyed before decrementing counter cache

Conflicts:
	activerecord/CHANGELOG.md
2013-05-06 22:22:07 -03:00
Ben Tucker
228720ef19 Confirm a record has not already been destroyed before decrementing
counter cache

At present, calling destroy multiple times on the same record results
in the belongs_to counter cache being decremented multiple times. With
this change the record is checked for whether it is already destroyed
prior to decrementing the counter cache.
2013-05-06 21:09:14 -04:00
Rafael Mendonça França
0f97ac6647 Fix test asserting the sanitized SQL hash differently to some adapters 2013-05-06 22:02:34 -03:00
Rafael Mendonça França
9073400253 Merge pull request #10352 from zohlgren/fix_activerecord_sanitization_sanitize_sql_hash
Fix bug in ActiveRecord::Sanitization#sanitize_sql_hash_for_conditions
2013-05-06 17:05:20 -07:00
Zach Ohlgren
a6bc35c82c Fix bug in ActiveRecord::Sanitization#sanitize_sql_hash_for_conditions
Fixing CHANGLOG description

Remove extra line.

Remove blank lines.
2013-05-06 17:03:18 -07:00
Neeraj Singh
86ac1d9bb2 fix failing test caused by 3771e4d511 2013-05-06 16:49:06 -04:00
Neeraj Singh
3771e4d511 raise IrreversibleMigration if no column given
fixes #10419

Following code should raise  IrreversibleMigration. But the code was
failing since options is an array and not a hash.

def change
  change_table :users do |t|
    t.remove_index [:name, :email]
  end
end

Fix was to check if the options is a Hash before operating on it.
2013-05-06 15:16:42 -04:00
Akshay Khole
b79c1314a9 fix to remove warning on postgres adapter test.
Warning was: "/vagrant/rails/activerecord/test/cases/adapters/postgresql/uuid_test.rb:63:
warning: ambiguous first argument; put parentheses or even spaces"
2013-05-05 00:54:45 +05:30
Rafael Mendonça França
903a2c2d33 Merge pull request #10458 from bwbuchanan/issue-10451
Make SchemaDumper emit "id: :uuid" when using UUID primary keys
2013-05-04 05:49:59 -07:00
Brian Buchanan
fa87e3166f Make SchemaDumper emit "id: :uuid" when appropriate. Fixes #10451. 2013-05-03 16:05:55 -07:00
Aaron Patterson
4c242e6d33 Squashed commit of the following:
commit 2683de5da85135e8d9fe48593ff6167db9d64b18
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Fri May 3 11:29:20 2013 -0700

    cannot support infinite ranges right now

commit cebb6acef2c3957f975f6db4afd849e535126253
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Fri May 3 11:26:12 2013 -0700

    reverting infinity comparison

commit 385f7e6b4efd1bf9b89e8d607fcb13e5b03737ea
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Fri May 3 11:23:28 2013 -0700

    Revert "Added ability to compare date/time with infinity"

    This reverts commit 38f28dca3aa16efd6cc3af6453f2e6b9e9655ec1.

    Conflicts:
    	activesupport/CHANGELOG.md
    	activesupport/lib/active_support/core_ext/numeric/infinite_comparable.rb
    	activesupport/test/core_ext/date_ext_test.rb
    	activesupport/test/core_ext/date_time_ext_test.rb
    	activesupport/test/core_ext/numeric_ext_test.rb
    	activesupport/test/core_ext/time_ext_test.rb
    	activesupport/test/core_ext/time_with_zone_test.rb

commit 0d799a188dc12b18267fc8421675729917610047
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Fri May 3 11:18:53 2013 -0700

    Revert "Refactor infinite comparable definition a bit"

    This reverts commit dd3360e05e4909f2f0c74a624cccc2def688f828.

commit 42dec90e49745bbfae546f0560b8783f6b48b074
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Fri May 3 11:18:47 2013 -0700

    Revert "Require 'active_support/core_ext/module/aliasing' in the infinite_comparable module"

    This reverts commit 7003e71c13c53ec3d34250560fbf80b8381df693.
2013-05-03 11:29:35 -07:00
Olek Janiszewski
534030cf83 Do not overwrite manually built records during one-to-one nested attribute assignment
For one-to-one nested associations, if you build the new (in-memory)
child object yourself before assignment, then the NestedAttributes
module will not overwrite it, e.g.:

    class Member < ActiveRecord::Base
      has_one :avatar
      accepts_nested_attributes_for :avatar

      def avatar
        super || build_avatar(width: 200)
      end
    end

    member = Member.new
    member.avatar_attributes = {icon: 'sad'}
    member.avatar.width # => 200
2013-05-03 16:18:37 +02:00
Jon Leighton
6023a50491 Merge pull request #10417 from jholton/fix_association_auto_save
autosave_association issue that occurs when table has unique index (resubmission)
2013-05-03 05:13:14 -07:00
Jon Leighton
66982772b7 Fix broken mysql test
test_mysql_integer_not_null_defaults in test/cases/defaults_test.rb was
failing. This test relies on the connection being in strict mode. By
default a new connection is not in strict mode, but Active Record
automatically places it in strict mode.

ActiveSchemaTest overwrites the connection's #execute method in order to
prevent SQL statements from actually being executed. One of the
operations which is performed in ActiveSchema test is a #recreate_database.

Since 2088bf27981137a2c6c8b2f718f33b417b4045af, recreate_database on
mysql or mysql2 will trigger a reconnect.

Due to the implementation of the hacking of #execute in
ActiveSchemaTest, this reconnect would take place, but the connection
would *not* be placed in strict mode because #execute had been
overridden to prevent SQL queries hitting the database.

Therefore, after ActiveSchemaTest, the connection would no longer be in
strict mode, causing test_mysql_integer_not_null_defaults to fail.

I don't think that the way that ActiveSchemaTest is implemented is
particularly nice or clean, but I have taken steps to make its hacks
more isolated - it now create a separate connection object which is
thrown away after the test, and the hacks are applied on the singleton
class of this object.
2013-05-03 11:36:02 +01:00
Takehiro Adachi
ec0566cc91 Add test for AR::Base#to_param
According to the doc of `AR::Base#to_param`(
https://github.com/rails/rails/blob/04cda1848cb847c2bdad0bfc12160dc8d554
7775/activerecord/lib/active_record/integration.rb#L18 ), it returns
`nil` if the record is not persisted.
2013-05-02 22:16:51 +09:00
Johnny Holton
483c301e0a destroys association records before saving/inserting new association records
fixes bug introduced by  #3329
These are the conditions necessary to reproduce the bug:
- For an association, autosave => true.
- An association record is being destroyed
- A new association record is being created.
- There is a unique index one of the association's fields.
- The record being created has the same value as the record being
destroyed on the indexed field.

Before, the deletion of records was postponed until after all
insertions/saves.  Therefore the new record with the identical value in
the indexed field caused a non-unique value error to be thrown at the database
level.

With this fix, the deletions happen first, before the insertions/saves.
Therefore the record with the duplicate value is gone from the database
before the new record is created, thereby avoiding the non-uniuqe value
error.
2013-05-02 03:27:06 -04:00
Carlos Antonio da Silva
730408fee2 Merge pull request #10396 from tkhr/extract-test-code-from-base_test.rb
Extract tests code out from AR's base_test.rb to integration_test.rb
2013-05-01 19:12:20 -07:00
Takehiro Adachi
a160c88172 Extract tests code out from AR's base_test.rb to integration_test.rb
`AR::Base#to_param` and `AR::Base#cache_key` is defined at
active_record/integration.rb, so tests for those methods should be at
integration_test.rb
2013-05-02 11:01:12 +09:00
Aaron Patterson
dd1f36078e Merge pull request #7839 from chancancode/handle_aliased_attributes_in_ar_relation
Handle aliased attributes in AR::Relation
2013-05-01 17:59:24 -07:00
Carlos Antonio da Silva
14a75a54a8 Improve docs for postgresql with uuid primary keys [ci skip]
Introduced in 09ac1776abc0d3482f491f2d49f47bcb3d9a4ad7.
2013-05-01 21:24:56 -03:00
Godfrey Chan
54122067ac Handle aliased attributes in ActiveRecord::Relation.
When using symbol keys, ActiveRecord will now translate aliased attribute names to the actual column name used in the database:

With the model

  class Topic
    alias_attribute :heading, :title
  end

The call

  Topic.where(heading: 'The First Topic')

should yield the same result as

  Topic.where(title: 'The First Topic')

This also applies to ActiveRecord::Relation::Calculations calls such as `Model.sum(:aliased)` and `Model.pluck(:aliased)`.

This will not work with SQL fragment strings like `Model.sum('DISTINCT aliased')`.

Github #7839

*Godfrey Chan*
2013-05-01 16:36:01 -07:00
Chad Moone
55c40c0ece allow override of uuid_generate_v4() default by passing default: nil
without this, it's not possible to use UUID primary keys without uuid-ossp installed and activated
2013-05-01 19:07:17 -04:00
Godfrey Chan
2496bd9a98 Mute psql output when running rake db:schema:load 2013-04-30 17:24:29 -07:00
Chris Thompson
ebd7cc6f45 Fix #8856 Ensure has_one association=(associate) triggers save.
activerecord/lib/active_record/associations.rb states:

    # [association=(associate)]
    #   Assigns the associate object, extracts the primary key, sets it as the foreign key,
    #   and saves the associate object.

Since commit 42dd5d9f2976677a4bf22347f2dde1a8135dfbb4 to fix #7191, this
is no longer the case if the associate has changed, but is the same
object. For example:

    # Pirate has_one :ship
    pirate = Pirate.create!(catchphrase: "A Pirate")
    ship = pirate.build_ship(name: 'old name')
    ship.save!

    ship.name = 'new name'
    pirate.ship = ship

That last line should trigger a save. Although we are not changing the
association, the associate (ship) has changed.
2013-04-30 16:14:16 -07:00
kennyj
253ccbc0ac Abort a rake task when missing db/structure.sql like db:schema:load task. 2013-05-01 02:37:09 +09:00
Carlos Antonio da Silva
85a56ff01d Delegate #unscope query method 2013-04-28 23:00:35 -03:00
Guillermo Iguaran
778692be3d Merge pull request #10368 from demands/fix-typo
Fix typo in serialized_attribute_test. [ci skip]
2013-04-28 08:54:05 -07:00
Max Edmands
c3b46d63b9 Fix typo in serialized_attribute_test. [ci skip] 2013-04-28 08:47:55 -07:00
Xavier Noria
607f136d52 fixes a test, and explains why AR::AttributeMethods checks defined?(@attributes) in some places 2013-04-28 12:03:59 +02:00
Aaron Patterson
7c8caf930d adding test for the symbol refs 2013-04-26 16:46:27 -07:00
Ivan Kataitsev
df0cb9e34c Move method used only in the test to the test code itself 2013-04-25 01:43:28 +04:00
kennyj
8c8d34fa55 Added testcase for #10067 and a CHANGELOG entry about this change. 2013-04-25 03:01:19 +09:00
Andrew White
07e489c9a2 Removed unused associations 2013-04-24 15:07:39 +01:00
Andrew White
2d211c459d Reset the primary key for other tests 2013-04-24 15:07:39 +01:00
Adam Gamble
697e346cd2 added test cases for #10197 2013-04-24 15:07:39 +01:00
Andrew White
1a30cfec2f Revert "Revert "belongs_to :touch behavior now touches old association when transitioning to new association" until a proper fix is found for #10197"
This reverts commit 7389df139a35436f00876c96d20e81ba23c93f0a.

Conflicts:
	activerecord/test/cases/timestamp_test.rb
2013-04-24 15:07:39 +01:00
David Heinemeier Hansson
e58f116830 Remove test case also related to the belongs_to touch feature 2013-04-23 09:48:46 -07:00
David Heinemeier Hansson
7389df139a Revert "belongs_to :touch behavior now touches old association when transitioning to new association" until a proper fix is found for #10197 2013-04-23 09:23:57 -07:00
Fyodor
746a9992f0 When empty options passed to having clause having_values was [nil] but should be empty. 2013-04-23 17:07:49 +04:00
Carlos Antonio da Silva
a429993742 Merge pull request #10295 from senny/10237_dirty_with_nullable_datetime
Also assign nil in dirty nullable_datetime test. Closes #10237
2013-04-22 05:24:00 -07:00
Yves Senn
fb2d62d0cd also assign nil in dirty nullable_datetime test. #10237 2013-04-22 09:46:57 +02:00
Matthew Robertson
1e27f1c5d5 Update counter cache when pushing into association
This commit fixes a regression bug in which counter_cache columns
were not being updated correctly when newly created records were
being pushed into an assocation. EG:

    # this was fine
    @post.comment.create!

    # this was fine
    @comment = Comment.first
    @post.comments << @comment

    # this would not update counters
    @post.comments << Comment.create!
2013-04-21 18:34:11 -07:00
Xavier Noria
0400a7ff57 if singletons belong to the contract, test them
Object#respond_to? returns singletons and thus we inherit that contract.
The implementation of the predicate is good, but the test is only
checking boolean semantics, which in this case is not enough.
2013-04-20 09:26:11 +02:00
Neeraj Singh
66001f3606 fix respond_to? for non selected column
fixes #4208

If a query selects only a few columns and gives custom names to
those columns then respond_to? was returning true for the non
selected columns. However calling those non selected columns
raises exception.

    post = Post.select("'title' as post_title").first

In the above case when `post.body` is invoked then an exception is
raised since `body` attribute is not selected. Howevere `respond_to?`
did not behave correctly.

    pos.respond_to?(:body) #=> true

Reason was that Active Record calls `super` to pass the call to
Active Model and all the columns are defined on Active Model.

Fix is to actually check if the data returned from the db contains
the data for column in question.
2013-04-19 14:09:16 -04:00