Commit Graph

4709 Commits

Author SHA1 Message Date
Yves Senn
951bde4557 test-case to prevent regressions on Association#build with an Array.
Closes #11026
2013-06-22 14:11:12 +02:00
Neeraj Singh
32420bd4bc flatten merged join_values before building the joins
fixes #10669

While joining_values special treatment is given to string values.
By flattening the array it ensures that string values are detected
as strings and not arrays.
2013-06-22 08:33:03 +05:30
Neeraj Singh
82882d4162 do not load all child records for inverse case
currently `post.comments.find(Comment.first.id)` would load all
comments for the given post to set the inverse association.

This has a huge performance penalty. Because if post has 100k
records and all these 100k records would be loaded in memory
even though the comment id was supplied.

Fix is to use in-memory records only if loaded? is true. Otherwise
load the records using full sql.

Fixes #10509
2013-06-21 23:35:12 +05:30
Neeraj Singh
6741a0a187 fix bad test by making number that fits for integer
PR https://github.com/rails/rails/pull/10566 had to be reverted
because after applying the fix test
"test_raise_record_not_found_error_when_invalid_ids_are_passed"
started failing.

In this test invalid_id is being assigned a really large number
which was causing following failure when PR #10566 was applied.

```
RangeError: bignum too big to convert into `long long'
SELECT  `interests`.* FROM `interests`
WHERE `interests`.`man_id` = ? AND `interests`.`id` = ?
LIMIT 1  [["man_id", 970345987], ["id", 2394823094892348920348523452345]]
```

This test is not failing in master because when test code
`man.interests.find(invalid_id)` is executed then interests
are fully loaded in memory and no database query is executed.

After PR #10566 was merged then test code
`man.interests.find(invalid_id)` started executing sql query
and hence the error.

In case someone is wondering why the second part of query is not
failing, then that's because the actual query does not require
any variable substituation where the number is large. In that
case the sql generate is following.

```
SELECT `interests`.* FROM `interests`
WHERE `interests`.`man_id` = ? AND `interests`.`id`
IN (8432342, 2390102913, 2453245234523452)  [["man_id", 970345987]]
```
2013-06-21 23:27:28 +05:30
Yves Senn
0f3aadae3b inspect for AR model classes does not initiate a new connection. 2013-06-20 07:21:04 +02:00
Yves Senn
12e1817835 Merge pull request #10884 from dmarkow/pg_fix_default_quotes
Handle single quotes in PostgreSQL default column values
2013-06-19 09:11:07 -07:00
Dylan Markow
78f6268977 Handle single quotes in PostgreSQL default column values
PostgreSQL escapes single quotes by using an additional single quote.
When Rails queries the column information, PostgreSQL returns the
default values with the escaped single quotes.

#extract_value_from_default now converts these to one single quote each.

Fixes #10881.
2013-06-19 11:03:40 -05:00
Jon Leighton
e47b6dee85 Revert "Merge pull request #10566 from neerajdotname/10509d"
This reverts commit 2b817a5e89ac0e7aeb894a40ae7151a0cf3cef16, reversing
changes made to 353a398bee68c5ea99d76ac7601de0a5fef6f4a5.

Conflicts:
	activerecord/CHANGELOG.md

Reason: the build broke
2013-06-19 14:22:02 +01:00
Neeraj Singh
6fb5f6f3d6 log the sql that is actually sent to the database
If I have a query that produces sql
`WHERE "users"."name" = 'a         b'` then in the log all the
whitespace is being squeezed. So the sql that is printed in the
log is `WHERE "users"."name" = 'a b'`.

This can be confusing. This commit fixes it by ensuring that
whitespace is not squeezed.

fixes #10982
2013-06-19 17:37:27 +05:30
Neeraj Singh
2b73f780ff do not load all child records for inverse case
currently `post.comments.find(Comment.first.id)` would load all
comments for the given post to set the inverse association.

This has a huge performance penalty. Because if post has 100k
records and all these 100k records would be loaded in memory
even though the comment id was supplied.

Fix is to use in-memory records only if loaded? is true. Otherwise
load the records using full sql.

Fixes #10509
2013-06-19 04:09:43 +05:30
Xavier Noria
7324624f74 Merge pull request #10987 from senny/10979_association_include_returns_true
`CollectionProxy#include?` returns `true` and `false` as documented.
2013-06-18 00:01:22 -07:00
Yves Senn
394cc6047d CollectionProxy#include? returns true and false as documented. 2013-06-18 08:53:36 +02:00
Aaron Patterson
e086ff5635 just construct real objects rather than mock and stub 2013-06-17 10:50:11 -07:00
Aaron Patterson
252d11321f Merge branch 'master' into mrbrdo-fixserialization
* master: (142 commits)
  Use Colspan in th Tags
  Added test for link_to_unless to make sure the result consistency.
  Escape the string even when the condition of link_to_unless is not satisfied.
  Add CHANGELOG entry for #10969
  Use a case insensitive URI Regexp for #asset_path
  collection tags accept html attributes as the last element of collection
  Rewind StringIO instances before be parsed again
  Use xml instead already parsed xml
  Updated the doc for const_regexp [ci skip]
  Make test name descriptive and add reference to original regression commit
  fixture setup does not rely on `AR::Base.configurations`.
  regression test + mysql2 adapter raises correct error if conn is closed.
  cleanup, remove trailing whitespace from AR changelog
  'json' gem is no more required under JRuby
  fix typos
  Fix AS changelog [ci skip]
  Update the HTML boolean attributes per the HTML 5.1 spec
  Changing const_regexp to check for constant name.
  valid_app_const? -> valid_const?
  Add CHANGELOG entry for #10740
  ...
2013-06-17 10:47:08 -07:00
Rafael Mendonça França
fe01752418 Merge pull request #10533 from vipulnsward/fix_test
Fix test, addresss => address
2013-06-15 06:27:19 -07:00
Vipul A M
e9177816ff Make test name descriptive and add reference to original regression commit 2013-06-15 18:39:06 +05:30
Yves Senn
6d10d64cba fixture setup does not rely on AR::Base.configurations.
As you can also configure your database connection using `ENV["DATABASE_URL"]`,
the fixture setup can't reply on the `.configurations` Hash.

As the fixtures are only loaded when ActiveRecord is actually used
(`rails/test_help.rb`) it should be safe to drop the check for an existing configuration.
2013-06-15 14:58:38 +02:00
Yves Senn
36bc4f5a02 regression test + mysql2 adapter raises correct error if conn is closed. 2013-06-15 14:35:14 +02:00
Yves Senn
c3adb313aa Merge pull request #10953 from acapilleri/fix_typos
fix typos
2013-06-15 03:24:38 -07:00
Angelo Capilleri
f7b9a9a836 fix typos 2013-06-15 09:14:28 +02:00
Aaron Patterson
8f37ba81ab This test does not test anything that happens in the real world. If you
recreate the models without mucking with internal caches of the relation
objects, then the test fails.

For example:

class Man < ActiveRecord::Base
  has_many :interests
end

class Interest < ActiveRecord::Base
  belongs_to :man
end

Then do this test:

def test_validate_presence_of_parent_fails_without_inverse_of
  repair_validations(Interest) do
    Interest.validates_presence_of(:man)
    assert_no_difference ['Man.count', 'Interest.count'] do
      man = Man.create(:name => 'John',
                       :interests_attributes => [{:topic=>'Cars'}, {:topic=>'Sports'}])
      assert_not_predicate man.errors[:"interests.man"], :empty?
    end
  end
end

The test will fail.  This is a bad test, so I am removing it.
2013-06-13 15:36:50 -07:00
Aaron Patterson
9abcb131f9 refute the predicate for better failure messages 2013-06-13 10:50:53 -07:00
Aaron Patterson
b483a0d2a7 Ambiguous reflections are on :through relationships are no longer supported.
For example, you need to change this:

  class Author < ActiveRecord::Base
    has_many :posts
    has_many :taggings, :through => :posts
  end

  class Post < ActiveRecord::Base
    has_one :tagging
    has_many :taggings
  end

  class Tagging < ActiveRecord::Base
  end

To this:

  class Author < ActiveRecord::Base
    has_many :posts
    has_many :taggings, :through => :posts, :source => :tagging
  end

  class Post < ActiveRecord::Base
    has_one :tagging
    has_many :taggings
  end

  class Tagging < ActiveRecord::Base
  end
2013-06-13 09:46:42 -07:00
Aaron Patterson
4909337a1f indentation 2013-06-11 11:24:16 -07:00
Yves Senn
da9b5d4a84 Remove fall back and column restrictions for count. 2013-06-09 12:53:04 +02:00
wangjohn
d6b03a3767 Getting rid of the +automatic_inverse_of: false+ option in associations in favor
of using +inverse_of: false+ option. Changing the documentation and
adding a CHANGELOG entry for the automatic inverse detection feature.
2013-06-08 10:16:51 -07:00
Jon Leighton
a68c6cccf0 Merge pull request #10561 from Empact/nix-throwresult
Rather than raising ThrowResult when construct_limited_ids_conditions comes up empty, set the relation to NullRelation and rely on its results.
2013-06-07 03:03:18 -07:00
Jan Berdajs
89c9ff8d8b add test for 9041454def79d8e61cabe49e7c5cb72cef29138b 2013-06-05 19:53:17 +02:00
Aaron Patterson
9d728cd708 Merge pull request #10482 from scudco/10432-fix-add-column-with-array
Fixes #10432 add_column not creating array columns in PostgreSQL
2013-06-05 01:58:08 -07:00
kennyj
8ae73f1146 Fix #10789. Now at last ::Logger doesn't support #silence method . 2013-06-05 17:55:53 +09:00
Aaron Patterson
0434754051 the typecast value should be passed to the serializer. fixes #10830 2013-06-05 17:30:11 +09:00
Aaron Patterson
00ce4b4aa1 adding a test for #10830
Conflicts:
	activerecord/test/cases/adapters/postgresql/bytea_test.rb
2013-06-05 17:15:53 +09:00
Adam Anderson
e4fe4973cf Fixes #10432 add_column not creating array columns in PostgreSQL
When then PostgreSQL visitor was [added](6b7fdf3bf3)
`add_column` was no longer receiving the column options directly. This
caused the options to be lost along the way.
2013-06-04 00:18:59 -04:00
José Valim
75135a9790 Revert "Merge pull request #4490 from EmmanuelOga/master"
This behaviour doesn't actually make sense, the context of
the child should not be affected by the parent. See #10492.

This reverts commit 5f8274efe128ffeec8fa3179460f5167a078f007, reversing
changes made to 81e837e810460d066a2e5fc5a795366ec8ab2313.
2013-06-04 00:33:50 +09:00
Guillermo Iguaran
bd096d5fb8 Merge pull request #10824 from vipulnsward/wonderful
wonderfull => wonderful
2013-06-02 13:26:54 -07:00
Vipul A M
743ee7b218 wonderfull => wonderful 2013-06-02 23:52:33 +05:30
kennyj
825a212ee2 Remove unnecessary testcase for instance level stored_attributes. 2013-06-02 10:33:36 +09:00
kennyj
6c74825beb Remove instance level serialized_attributes setting was deprecated. 2013-06-02 10:26:04 +09:00
kennyj
0a88c10e54 Remove instance level attr_readonly setting was deprecated. 2013-06-02 10:25:41 +09:00
kennyj
e185ba24c8 Remove behavior that deals with a string as third argument of add_index, because this was deprecated.
Some testcases is failed, so I replaced nil to empty hash in add_reference.
2013-06-02 08:44:31 +09:00
kennyj
5d75579eec Remove #sum with a block was deprecated. 2013-06-01 23:22:12 +09:00
kennyj
f8f30c88ad Remove ActiveSupport::Benchmarkable#silence was deprecated. 2013-06-01 21:23:19 +09:00
Rafael Mendonça França
6ecc360d88 Merge pull request #10495 from senny/postgres_test_cleanup
PostgreSQL specific test cleanup
2013-05-28 08:21:18 -07:00
Yves Senn
1c998a7f13 test cleanup, replace define_method and remove_method with stubs. 2013-05-28 09:19:00 +02:00
Yves Senn
aff928bacf implicit_readonly is being removed in favor of calling readonly explicitly 2013-05-27 21:07:39 +02:00
Yves Senn
ef99c11475 Fix the :primary_key option for has_many associations.
When removing records from a `has_many` association it used
the `primary_key` defined on the association.

Our test suite didn't fail because on all occurences of `:primary_key`,
the specified column was available in both tables. This prevented the
code from raising an exception but it still behaved badly.

I added a test-case to prevent regressions that failed with:

```
  1) Error:
HasManyAssociationsTest#test_has_many_assignment_with_custom_primary_key:
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: essays.first_name: UPDATE "essays" SET "writer_id" = NULL WHERE "essays"."writer_id" = ? AND "essays"."first_name" IS NULL
```
2013-05-23 07:38:33 +02:00
Carlos Antonio da Silva
b9bbc7f81a Merge pull request #10714 from tkhr/extract_test_from_base_test.rb_in_AR
Extract tests code out from AR's base_test.rb
2013-05-22 05:41:21 -07:00
Takehiro Adachi
5e3de2f50d Extract AR::Persistence#becomes's test code out from base_test.rb
The method got extracted out from AR::Base in commit
d916c62cfc7c59ab6411407a05b946d3dd7535e9, but the tests never did.
2013-05-22 12:30:35 +09:00
Aaron Patterson
ac70ec6413 Merge branch 'bindwhere'
* bindwhere:
  avoid creating a set if no where values are removed
  remove bind values for where clauses that were removed
  push partitioning up so bind elimination can get the removed wheres
  push partion logic down and initialization logic up
  partition the where values so we can access the removed ones
2013-05-21 11:01:25 -07:00
Aaron Patterson
f3ebbeae6e avoid creating a set if no where values are removed 2013-05-21 11:01:19 -07:00