Commit Graph

4599 Commits

Author SHA1 Message Date
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
Jon Leighton
0920d4fccb Revert "Merge pull request #10183 from jholton/fix_association_auto_save"
This reverts commit e8727d37fc49d5bf9976c3cb5c46badb92cf4ced, reversing
changes made to d098e1c24bc145e0cc14532348436e14dc46d375.

Reason: it broke the mysql build
2013-04-19 16:57:06 +01:00
Johnny Holton
9de28419b1 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-04-19 10:50:56 -04:00
Rafael Mendonça França
d098e1c24b Merge pull request #10264 from cconstantine/master
Postgresql array columns don't properly escape single quote strings when loading fixtures
2013-04-19 07:34:17 -07:00
Rafael Mendonça França
1d9309a5b2 Improve the error message 2013-04-19 11:23:59 -03:00
Rafael Mendonça França
db1594c61c Merge pull request #10217 from mirasrael/make-migrator-run-transactional-4.0
Support transactions in Migrator.run

Conflicts:
	activerecord/CHANGELOG.md
2013-04-19 11:23:56 -03:00
Jon Leighton
77fec1344b Merge pull request #10200 from calebthompson/ct-fix-freeze-freezing-cloned-models
Fix freeze applying to cloned objects
2013-04-19 06:19:06 -07:00
Chris Constantine
0e34a7efa6 Fix loading of fixtures when the column type is a postgres array of strings.
- A string in an array of strings that has a quote char (') needs to have that quote char escaped if the array is getting wrapped in quote chars.
2013-04-18 12:24:49 -07:00
Rafael Mendonça França
63ce8a1112 Revert "Merge pull request #10043 from cconstantine/master"
This reverts commit 521035af530482d6d9ad2dae568eaeb0ab188e1c, reversing
changes made to 222011dbee842bbc60d3aaaa3145356b90a30fd1.

Reason: This broke the tests
2013-04-18 15:45:28 -03:00
Rafael Mendonça França
521035af53 Merge pull request #10043 from cconstantine/master
DB with postgres string array column doesn't load fixtures well
2013-04-18 10:16:58 -07:00
bondarev
2976558bc3 Support transactions in Migrator.run 2013-04-18 18:18:59 +04:00
Xavier Noria
ef7a48df75 let EXPLAIN use a thread locals registry [John J. Wang & Xavier Noria]
Closes #10198.
2013-04-16 22:46:55 +02:00
kennyj
01a2ac12b9 Fix #7619. 0x prefix must be added when assigning hexadecimal string into bit column in Postgresql, because solving ambiguity. 2013-04-17 00:57:53 +09:00
Caleb Thompson
d5867a01a8 Fix freeze applying to cloned objects
Previously, freezing a cloned ActiveRecord object froze the original
too. By cloning `@attributes` before freezing, we prevent cloned objects
(which in Ruby share state of ivars) from being effected by `#freeze`.

Resolves issue #4936, which has further information on this issue, as
well as steps to reproduce.

* Add a test case for `#freeze` not causing `cloned.frozen?` to be true.
* Clone @attributes before freezing in `ActiveRecord::Core`, then
  reassign the cloned, frozen hash to the frozen model's `@attributes`
  ivar.

/cc @steveklabnik
2013-04-15 19:57:28 -04:00
kennyj
0141dd37be Revert "fixing bit string test"
This reverts commit cdd293cb963b895ff580eb20d10f5d56ecb3d447.

Reason: This wasn't properly fix.
2013-04-16 03:17:07 +09:00
Matt Aimonetti
280c5ed1f9 fix for the bytea/binary nil value bug 2013-04-14 16:59:23 -07:00
Matt Aimonetti
0ddfd75bf6 added a test suite for the postgres binary type
this shows a problem with nil values
2013-04-14 16:49:44 -07:00
Xavier Noria
e5ef3abdd2 hides the per thread registry instance, and caches singleton methods
Existing code was delegating to the instance with delegate
macro calls, or invoking the instance method to reach
the object and call its instance methods.

But the point is to have a clean class-level interface where
the thread local instance is hidden in the implementation.

References #11c6973.
References #10198.
2013-04-13 17:09:13 +02:00
Carlos Antonio da Silva
53d6cc04e7 Merge pull request #10177 from yahonda/test_relation_merging_with_merged_joins_oracle
Address ORA-00979: not a GROUP BY expression error
2013-04-11 08:35:09 -07:00
Yasuo Honda
0997a14bae Address ORA-00979: not a GROUP BY expression error 2013-04-11 22:27:07 +09:00
Vipul A M
127a2eea63 cleanup statement cache test 2013-04-11 18:08:46 +05:30
Rafael Mendonça França
0235cdf5ce Merge pull request #10152 from Noemj/statement_cache
Statement cache

Conflicts:
	activerecord/CHANGELOG.md
2013-04-10 16:02:26 -03:00
Rafael Mendonça França
9d2146ac6e Revert "Merge pull request #6226 from gnufied/master"
This reverts commit 9bf1a0db4acbbf9e8e6f707250269185224e7efe, reversing
changes made to fed97091b9546d369a240d10b184793d49247dd3.

Conflicts:
	activerecord/test/cases/transaction_callbacks_test.rb

Reason: This fix introduces another issue described at #8937, so we are
reverting it to restore the behavior of 3-2-stable.

We will fix both issues when we come out with a better solution
2013-04-10 15:21:07 -03:00
Noemj
af1a4bdc56 Added statement cache 2013-04-10 21:20:58 +03:00
Jared Armstrong and Neeraj Singh
dc764fcc34 While merging relations preserve context for joins
Fixes #3002. Also see #5494.

```
class Comment < ActiveRecord::Base
  belongs_to :post
end

class Author < ActiveRecord::Base
  has_many :posts
end

class Post < ActiveRecord::Base
  belongs_to :author
  has_many :comments
end
```

`Comment.joins(:post).merge(Post.joins(:author).merge(Author.where(:name => "Joe Blogs"))).all` would
fail with `ActiveRecord::ConfigurationError: Association named 'author' was not found on Comment`.

It is failing because `all` is being called on relation which looks like this after all the merging:
`{:joins=>[:post, :author], :where=>[#<Arel::Nodes::Equality: ....}`. In this relation all the context that
`Post` was joined with `Author` is lost and hence the error that `author` was not found on `Comment`.

Ths solution is to build JoinAssociation when two relations with join information are being merged. And later
while building the arel use the  previously built `JoinAssociation` record in `JoinDependency#graft` to
build the right from clause.

Thanks to Jared Armstrong (https://github.com/armstrjare) for most of the work. I ported it to make it
compatible with new code base.
2013-04-10 12:19:47 -04:00
wangjohn
e12901e423 Changed the ScopeRegistry and the InstrumentationRegistry to use the
PerThreadRegistry module.
2013-04-09 22:27:32 -04:00
wangjohn
5b945f2685 Grouping thread locals in the ActiveRecord scopes so that the
current_scope and ignore_default_scope locals are brought together under
a registry object.
2013-04-08 13:21:13 -04:00
Chris Constantine
f6c4cded2f Fix loading of string arrays in postgres 2013-04-08 09:55:26 -07:00
Vipul A M
4f5e8af993 each to each_value; remove unused vars 2013-04-07 19:59:07 +05:30
Anupam Choudhury
8ed04e90d2 Removed space and unused class 2013-04-06 02:35:15 +05:30