Commit Graph

3573 Commits

Author SHA1 Message Date
Yves Senn
845cc5c78d use ruby 1.8 Hash syntax [ci skip] 2013-03-22 15:23:57 +01:00
Yves Senn
c8edd4fda4 do not reset associations when preloading twice.
Closes #9806.

As the `through_options` always contained `{:order=>nil}` the second time,
the preloader ran, the association was always reset. This patch only
adds the `:order` to the `through_options` if it is set.
2013-03-22 15:08:09 +01:00
kennyj
dc2bc388bc Wrong exception is occured when raising no translatable exception
Conflicts:
	activerecord/CHANGELOG.md
2013-03-20 10:11:07 +00:00
Carlos Antonio da Silva
167b645a2a Bring back test and changelog entry from #pluck method and select clause 2013-03-18 18:28:07 -03:00
Aaron Patterson
afcd01bf25 Merge branch '3-2-13' into 3-2-stable
* 3-2-13:
  bumping to 3.2.13
  fix protocol checking in sanitization [CVE-2013-1857]
  JDOM XXE Protection [CVE-2013-1856]
  fix incorrect ^$ usage leading to XSS in sanitize_css [CVE-2013-1855]
  stop calling to_sym when building arel nodes [CVE-2013-1854]
  Merge pull request #9616 from exviva/multiple_select_name_double_square_brackets
  bumping to rc2
  Revert "Merge pull request #8209 from senny/backport_8176"
  Freeze columns only once per Result
  Preparing for 3.2.13.rc1 release
  Update CHANGELOGs for 3.2.13 release.

Conflicts:
	actionmailer/CHANGELOG.md
	actionpack/CHANGELOG.md
	activemodel/CHANGELOG.md
	activeresource/CHANGELOG.md
	activesupport/CHANGELOG.md
	railties/CHANGELOG.md
2013-03-18 10:17:04 -07:00
Aaron Patterson
f980289fd2 stop calling to_sym when building arel nodes [CVE-2013-1854] 2013-03-15 17:47:28 -07:00
Andrew White
3d4d7420ae Fix ar:mysql2 build on Ruby 1.8.7
The `skip` method is a no-op on Ruby 1.8.7 so we still need to
force skip by returning early from each test.
2013-03-13 07:24:21 +00:00
Carlos Antonio da Silva
348d693c6a Merge pull request #9613 from arunagw/remove_fixme
Removing FIXME
2013-03-08 07:43:24 -08:00
Arun Agrawal
c8918c6972 Removing FIXME
As we did in master.
2013-03-08 16:08:43 +01:00
Rafael Mendonça França
9bd5c86c3b Merge pull request #9549 from larrylv/reload-stable-target-before-saving
Fix issue #7526. Reload the association target if it's stale.
2013-03-07 08:23:23 -08:00
Yasuo Honda
5d57b821d0 Use shorter prefix and suffix as in Oracle database identifier
cannot be larger than 30 characters
2013-03-07 22:34:54 +09:00
Aaron Patterson
1b699fc8ad Revert "Merge pull request #8209 from senny/backport_8176"
This reverts commit 7240202784, reversing
changes made to e4e2bcce75.

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/lib/active_record/relation/calculations.rb
	activerecord/test/cases/calculations_test.rb
2013-03-05 11:33:16 -08:00
larrylv
939b896a06 Fix issue #7526. Reload the target if it's stale.
* This has been fixed at master via `365b8b6`, but not at 3-2-stable branch.

* @stale_state should be nil when a model isn't saved. via `0f3901e`.

* set @stale_state to nil when reset the target.
2013-03-05 12:43:05 +08:00
Yasuo Honda
c27da1fbcc Revert "Skip test_remove_column_with_array_as_an_argument_is_deprecated with Oracle adapter."
This reverts commit 7544c7a9f2.

Oracle enhanced adapter is supporting remove_column with Array.
2013-02-28 05:46:56 +09:00
Yasuo Honda
97df33d818 Fix ORA-00972 error at test_rename_table_with_prefix_and_suffix
backport pull request#5837 to 3-2-stable
2013-02-28 05:22:08 +09:00
Steve Klabnik
ee291b9b41 Revert "Merge pull request #9208 from dylanahsmith/3-2-mysql-quote-numeric"
This reverts commit 921a296a33.
2013-02-26 16:57:18 -08:00
Hiroshige Umino
55a1765942 Do not override attributes on dup by default scopes 2013-02-26 11:08:50 -08:00
Narihiro Nakamura
905b7df1fa Backported #7072 to 3-2-stable. Use database value for uniqueness validation scope. 2013-02-26 14:39:26 +09:00
Yves Senn
8f6fa345e5 Sqlite preserves primary keys when copying/altering tables.
Backport #2312.
Fixes #9367.

I also added a test-case to make sure that renaming or removing
a column preserves the primary key.
2013-02-23 15:23:28 +01:00
Rafael Mendonça França
a0d84227c2 Use order to get the first record since postgresql returns in the
desired order
2013-02-20 22:31:02 -03:00
Yves Senn
9be7f63db9 keep the build 💚, #first on 1.8.7 and pg is different
The build only failed for ruby-1.8.7 and pg. The problem was that the statement:

```ruby
author = Author.includes(:comments_with_order_and_conditions, :posts).first
```

resulted in Author with ID 2 where on all other rubies / db-engines Author with ID 1
was retunred. Of course this breaks the assertions.
2013-02-19 14:42:45 +01:00
Yves Senn
587f563c40 don't cache invalid subsets when preloading hmt associations.
Backport #9252.

Conflicts:

	activerecord/CHANGELOG.md
	activerecord/test/cases/associations/eager_test.rb

The preloader code on 3-2-stable is not based on relations but on option hashes.
I had to modify the original patch and comparing the option hashes could be more
fuzzy than comparing the relations. All the tests passed though.
2013-02-19 11:11:27 +01:00
Lilibeth De La Cruz
3c5f631caa Fix handling of dirty time zone aware attributes
Previously, when `time_zone_aware_attributes` were enabled, after
changing a datetime or timestamp attribute and then changing it back
to the original value, `changed_attributes` still tracked the
attribute as changed. This caused `[attribute]_changed?` and
`changed?` methods to return true incorrectly.

Example:

    in_time_zone 'Paris' do
      order = Order.new
      original_time = Time.local(2012, 10, 10)
      order.shipped_at = original_time
      order.save
      order.changed? # => false

      # changing value
      order.shipped_at = Time.local(2013, 1, 1)
      order.changed? # => true

      # reverting to original value
      order.shipped_at = original_time
      order.changed? # => false, used to return true
    end

(cherry picked from commit bc982cbcb34129ea2cfe8aa1f8e0b40e444e68db)

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb

Backport of #9073
Fixes #8898
2013-02-17 16:19:09 +00:00
Rafael Mendonça França
7f4975ffc6 Revert "Merge pull request #9252 from senny/8423_hmt_preloading_bug"
This reverts commit c5451777b0.

Conflicts:
	activerecord/CHANGELOG.md
2013-02-15 13:00:53 -02:00
Rafael Mendonça França
c5451777b0 Merge pull request #9252 from senny/8423_hmt_preloading_bug
don't cache invalid subsets when preloading hmt associations
Conflicts:
	activerecord/CHANGELOG.md
	activerecord/test/cases/associations/eager_test.rb
2013-02-14 15:33:30 -02:00
Matthew Robertson
18ffe50581 backport of fix for issue #7630 2013-02-13 16:01:58 -08:00
Aaron Patterson
c35d913524 adding test for CVE 2013-02-09 17:00:59 -08:00
Guillermo Iguaran
b00fe01d6e Merge pull request #9224 from dylanahsmith/bigdecimal-takes-string
[3.2] Fix test failure for ruby 1.8.
2013-02-09 16:58:55 -08:00
Guillermo Iguaran
921a296a33 Merge pull request #9208 from dylanahsmith/3-2-mysql-quote-numeric
[3.2] active_record: Quote numeric values compared to string columns.
Conflicts:
	activerecord/CHANGELOG.md
2013-02-09 16:58:50 -08:00
Dylan Smith
cbdfaf2e29 Fix test failure for ruby 1.8.
BigDecimal.new needs to take a string rather than an integer in ruby 1.8.
2013-02-08 09:44:15 -05:00
Dylan Smith
04c2d2e2e4 active_record: Quote numeric values compared to string columns. 2013-02-07 05:02:38 -05:00
Yasuo Honda
e8357935ac This pull requests addresses ORA-01400 errors and also supports #6115 issue tested.
Issue #6115 has been fixed and tested with
the attribute `:null => false, :default => ""`
However `:null => false` attribute is not necessary to test this issue,
which causes many ORA-01400 errors with Oracle enhanced adapter.
2013-02-03 15:27:49 +04:00
Piotr Sarnacki
6a0a5f3032 Duplicate column_defaults properly
Backport c517602 to fix #6115

Deleted:
    activerecord/lib/active_record/core.rb

Conflicts:
    activerecord/test/cases/base_test.rb
2013-02-03 15:27:42 +04:00
Rafael Mendonça França
bf794bb36f Merge pull request #9078 from senny/6865_ar_count_with_uniq
`#count` in conjunction with `#uniq` performs distinct count.
Conflicts:
	activerecord/CHANGELOG.md
2013-02-02 10:19:23 -02:00
Ian Lesperance
b6d4931292 Fix pluck when columns/tables are reserved words.
Backport #7536 to fix #8968.

Conflicts:

	activerecord/CHANGELOG.md
	activerecord/lib/active_record/relation/calculations.rb
2013-01-23 15:17:33 +01:00
Xavier Noria
29d564add9 Merge pull request #6197 from blakesmith/connection_adapters_without_explain_support
Don't run explain on slow queries for database adapters that don't support it
2013-01-22 19:54:01 -02:00
Andrew White
97a4db91d6 Revert "Merge pull request #6986 from kennyj/fix_6975"
This reverts commit 8905c1fb49.

Closes #8460

Conflicts:
	activerecord/test/cases/dirty_test.rb
2013-01-22 14:24:42 +00:00
Andrew White
7ee76714ab Add failing test case for #8460
Add a test case to ensure that fractional second updates are detected.
2013-01-22 14:20:25 +00:00
Carlos Antonio da Silva
da5e5c5f77 Revert "Merge pull request #7983 from georgebrock/bug7950-squashed"
This reverts commit 88a296dccc, reversing
changes made to 666a7e34f5.

Conflicts:
	activerecord/CHANGELOG.md

Reason: this has been resulting in some hard to track bugs and is
introducing a possible breackage in a stable version.
2013-01-15 13:01:13 -02:00
Ernie Miller
18b9187b56 Revert "Merge pull request #7661 from ernie/build-join-records-on-unsaved-hmt"
This reverts commit ee43989575.

It would appear that #7661 had unintended consequences to the API. Until
we can sort those out, this should not be in 3.2.x, and wait for 4.0.0.
2013-01-11 10:32:36 -05:00
Yasuo Honda
3d1a879f4c Ignore binds payload with nil column in AR log subscriber
Some tests were raising the following error:

    Could not log "sql.active_record" event. NoMethodError: undefined method
    `type' for nil:NilClass`

Due to the way binds were being logged, the column info was considered
always present, but that is not true for some of the tests listed in the
issue.

Closes #8806.

Conflicts:

	activerecord/lib/active_record/log_subscriber.rb
	activerecord/test/cases/log_subscriber_test.rb

Conflict resolution:
- Revert ruby 1.9 style hash to support ruby 1.8
- Do not include 8f59ffce into 3-2-stable
2013-01-09 06:18:14 +09:00
Aaron Patterson
48810a52df Merge branch '3-2-sec' into 3-2-secmerge
* 3-2-sec:
  bumping version
  CVE-2013-0156: Safe XML params parsing. Doesn't allow symbols or yaml.
  * Strip nils from collections on JSON and XML posts. [CVE-2013-0155] * dealing with empty hashes. Thanks Damien Mathieu
  Avoid Rack security warning no secret provided

Conflicts:
	actionpack/CHANGELOG.md
	activerecord/CHANGELOG.md
	activesupport/CHANGELOG.md
2013-01-08 11:37:48 -08:00
Aaron Patterson
d5cd97baa4 * Strip nils from collections on JSON and XML posts. [CVE-2013-0155] * dealing with empty hashes. Thanks Damien Mathieu 2013-01-08 09:08:26 -08:00
Carlos Antonio da Silva
3aebe13b1b Remove not used variable in eager test 2013-01-07 21:37:02 -02:00
Rafael Mendonça França
80343f6f90 Test only with Ruby 1.9+ 2013-01-06 20:30:10 -03:00
Rafael Mendonça França
79456619cf Remove warnings 2013-01-06 18:43:48 -03:00
Tristan Harward
c147dd7ddd Fix error when assigning NaN to an integer column
Also covers any non-castable case by returning nil, which
is in-line with the intention of the former implementation,
but covers the odd cases which respond to to_i but raise
an error when it's called, such as NaN, Infinity and -Infinity.

Fixes #8757

Backport of #8781

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/test/cases/column_test.rb
2013-01-06 18:21:36 -03:00
Jason Stirk
e842dbbdf7 Fix undefined method `to_i' introduced since 3.2.8
This commit fixes a bug introduced in 96a13fc7 which breaks behaviour of
integer fields in 3.2.8.

In 3.2.8, setting the value of an integer field to a non-integer (eg.
Array, Hash, etc.) would default to 1 (true) :

    # 3.2.8
    p = Post.new
    p.category_id = [ 1, 2 ]
    p.category_id # => 1
    p.category_id = { 3 => 4 }
    p.category_id # => 1

In 3.2.9 and above, this will raise a NoMethodError :

    # 3.2.9
    p = Post.new
    p.category_id = [ 1, 2 ]

    NoMethodError: undefined method `to_i' for [1, 2]:Array

Whilst at first blush this appear to be sensible, it combines in bad
ways with scoping.

For example, it is common to use scopes to control access to data :

    @collection = Posts.where(:category_id => [ 1, 2 ])
    @new_post = @collection.new

In 3.2.8, this would work as expected, creating a new Post object
(albeit with @new_post.category_id = 1). However, in 3.2.9 this will
cause the NoMethodError to be raised as above.

It is difficult to avoid triggering this error without descoping before
calling .new, breaking any apps running on 3.2.8 that rely on this
behaviour.

This patch deviates from 3.2.8 in that it does not retain the somewhat
spurious behaviour of setting the attribute to 1. Instead, it explicitly
sets these invalid values to nil :

    p = Post.new
    p.category_id = [ 1, 2 ]
    p.category_id # => nil

This also fixes the situation where a scope using an array will
"pollute" any newly instantiated records.

    @new_post = @collection.new
    @new_post.category_id # => nil

Finally, 3.2.8 exhibited a behaviour where setting an object to an
integer field caused it to be coerced to "1". This has not been
retained, as it is spurious and surprising in the same way that setting
Arrays and Heshes was :

    c = Category.find(6)
    p = Post.new

    # 3.2.8
    p.category_id = c
    p.category_id # => 1

    # This patch
    p.category_id = c
    p.category_id # => nil

This commit includes explicit test cases that expose the original issue
with calling new on a scope that uses an Array. As this is a common
situation, an explicit test case is the best way to prevent regressions
in the future.

It also updates and separates existing tests to be explicit about the
situation that is being tested (eg. AR objects vs. other objects vs.
non-integers)
2013-01-04 10:36:45 +11:00
Aaron Patterson
2aa70bd61a Merge branch '3-2-sec' into 3-2-secmerge
* 3-2-sec:
  CVE-2012-5664 options hashes should only be extracted if there are extra parameters
  updating changelog
  updating the changelogs
  updating the changelog for the CVE
  Add release date of Rails 3.2.9 to documentation

Conflicts:
	actionmailer/CHANGELOG.md
	actionpack/CHANGELOG.md
	activemodel/CHANGELOG.md
	activerecord/CHANGELOG.md
	activeresource/CHANGELOG.md
	activesupport/CHANGELOG.md
	railties/CHANGELOG.md
2012-12-23 11:52:05 -08:00
Aaron Patterson
325669f079 CVE-2012-5664 options hashes should only be extracted if there are extra parameters 2012-12-23 11:07:07 -08:00