Commit Graph

3508 Commits

Author SHA1 Message Date
Sergey Nartimov
5ca86ac8f9 deprecate String#encoding_aware? and remove its usage 2011-12-24 15:57:54 +03:00
Jon Leighton
b236f081eb Add test to ensure AR::Model initialization works correctly 2011-12-24 11:08:16 +00:00
Jon Leighton
800f0a6eb6 Add deprecation for the change to the active_record load hook 2011-12-24 11:08:16 +00:00
Jon Leighton
0e3e34f0eb Support nested AR::Models 2011-12-24 11:08:16 +00:00
Jon Leighton
13945b06cc Don't include anything else if AR::Model has already been included 2011-12-24 11:08:16 +00:00
Jon Leighton
35202aa691 Make PredicateBuilder recognise AR::Model 2011-12-24 11:08:16 +00:00
Jon Leighton
a1ee3ac654 Ensure attribute methods are included after all the AR stuff 2011-12-24 11:08:16 +00:00
Jon Leighton
1029c511f1 Fix #exists? for AR::Model 2011-12-24 11:08:16 +00:00
Jon Leighton
95795bcb2f Make generated_feature_methods work with ActiveRecord::Model 2011-12-24 11:08:16 +00:00
Jon Leighton
649869557a Fixtures support for ActiveRecord::Model 2011-12-24 11:08:15 +00:00
Jon Leighton
ba7ec73f6a Deal with global config better between AR::Base and AR::Model 2011-12-24 11:08:15 +00:00
Jon Leighton
8c67e709d0 Add test for inheritance from a non-AR superclass 2011-12-24 11:08:15 +00:00
Jon Leighton
7293cac854 Extract common logic into a method 2011-12-24 11:08:15 +00:00
Jon Leighton
6af7192af5 I herd you like modules. 2011-12-24 11:08:15 +00:00
Jon Leighton
e2b6919223 stop test resetting global state 2011-12-23 23:22:24 +00:00
Jon Leighton
f1eb98f0fc Fix #4046. 2011-12-23 18:20:35 +00:00
Alvaro Bautista
30ce084bbf serialize fails on subclass 2011-12-23 18:19:25 +00:00
Jon Leighton
16dbe1db1e Make ActiveRecord::Relation#pluck work with serialized attributes 2011-12-22 19:23:27 +00:00
Jon Leighton
91681c281b Revert "Merge pull request #4114 from alexeymuranov/my_fix_for_prefix_suffix_fixtures_test"
This reverts commit f8e484d0f71114675ed04e987914d3f2815cb868, reversing
changes made to fa5adfb1e884bf21a7071ade634a820e37ac4db4.

Reason: broke the postgres tests.
2011-12-22 17:04:01 +00:00
Jon Leighton
f8e484d0f7 Merge pull request #4114 from alexeymuranov/my_fix_for_prefix_suffix_fixtures_test
Fix a fixtures test case with table prefix/suffix
2011-12-22 08:21:05 -08:00
Alexey Muranov
adb917a0d8 Fix a fixtures test case with table prefix/suffix
Make sure the table name of a model is reset in a test case after assigning ActiveRecord::Base.table_name_prefix and ActiveRecord::Base.table_name_suffix.  This was somebody else's test case, so an independent opinion on the change can be helpful.
2011-12-22 15:07:45 +01:00
José Valim
1634cfa447 Merge pull request #4122 from qoobaa/mass_assignment_with_associated_object
added failing tests for has_many, has_one and belongs_to associations wi...
2011-12-21 12:16:13 -08:00
Jakub Kuźma
1ad0a5363b added failing tests for has_many, has_one and belongs_to associations with strict mass assignment sanitizer, fixed build_record to not merge creation_attributes, removed failing nested attributes tests (that feature was broken anyway) #4051 2011-12-21 21:10:15 +01:00
José Valim
1a358e43d2 Merge pull request #4109 from Karunakar/test1
Changed the old logger to new active support logger
2011-12-21 11:16:42 -08:00
Sergey Nartimov
9add7608f1 remove deprecated set and original methods for table_name, primary_key, etc 2011-12-21 22:00:55 +03:00
Sergey Nartimov
9f7d3c51b3 remove deprecated underscore versions of attribute methods 2011-12-21 21:06:03 +03:00
Karunakar (Ruby)
730209a679 Changed the old logger to new active support logger 2011-12-21 23:00:06 +05:30
lest
4a57d1b0b6 remove requires of core_ext/array/random_access that no longer exists 2011-12-21 19:19:19 +03:00
Arun Agrawal
e3c383cd82 More tests deep including through habtm
fixes #3183
2011-12-21 16:16:55 +05:30
Arun Agrawal
7276fc63be 'with_kcode' removed.
Testing Sandbox removed.
2011-12-21 15:39:50 +05:30
Arun Agrawal
de78c7e8e4 Removed test which works only < 1.9 2011-12-21 15:35:57 +05:30
Arun Agrawal
b4073c9ea9 No Ruby 1.8 stuff. No more checks in code. 2011-12-21 12:20:12 +05:30
Aaron Patterson
0d7ca94727 skip hstore tests on PG databases that do not have hstore 2011-12-20 14:04:51 -06:00
Aaron Patterson
66d8620e3c making sure updates work 2011-12-20 14:04:51 -06:00
Aaron Patterson
8daaff5dac hstores can cycle 2011-12-20 14:04:51 -06:00
Aaron Patterson
96838b5192 can create hstore records via AR API 2011-12-20 14:04:50 -06:00
Aaron Patterson
135b3a0dde multiple key / values work 2011-12-20 14:04:50 -06:00
Aaron Patterson
776af48acb PostgreSQL hstore types are automatically deserialized from the database. 2011-12-20 14:04:50 -06:00
Aaron Patterson
8cb7bc8b55 pg columns should understand the hstore type 2011-12-20 14:04:49 -06:00
Karunakar (Ruby)
c056787d5d remove more uses of deprecated loggers 2011-12-21 00:57:30 +05:30
Aaron Patterson
3ef20aa62c Merge pull request #4035 from lest/date-type-cast
handle not only strings in date type cast
2011-12-20 09:42:17 -08:00
Aaron Patterson
bb106e9aa2 remove more uses of deprecated logger methods 2011-12-19 21:05:28 -08:00
Sergey Nartimov
e2d19d6018 handle not only strings in date type cast 2011-12-19 23:41:09 +03:00
Jon Leighton
de2306f10c Merge pull request #4014 from lest/bypass-preloading-for-ids-reader
bypass preloading for ids_reader
2011-12-18 09:42:15 -08:00
Sergey Nartimov
109db5a550 bypass preloading for ids_reader
when fetching ids for a collection, bypass preloading
to avoid the unnecessary performance overhead
2011-12-18 10:59:24 +03:00
Sergey Nartimov
04cea56d89 call scope within unscoped to prevent duplication of where values 2011-12-17 14:41:17 +03:00
Jon Leighton
f307f4d884 Delete obsolete comment 2011-12-16 14:52:02 +00:00
Jon Leighton
7b1eeea5bc Should clear the primary keys cache also 2011-12-16 13:52:07 +00:00
Jon Leighton
7f20bb995a Don't store defaults in the schema cache 2011-12-16 13:52:07 +00:00
Jon Leighton
0b08ff7d92 Cache columns at the model level.
Allows two models to use the same table but have different primary keys.
2011-12-16 13:52:07 +00:00
Jon Leighton
17ad71e514 Let AttributeMethods do its own including etc 2011-12-15 20:45:42 +00:00
Jon Leighton
ceb33f8493 Split out most of the AR::Base code into separate modules 🍰 2011-12-15 20:45:37 +00:00
Jon Leighton
8dba32f125 Fix #3987. 2011-12-15 13:23:28 +00:00
Andrew Kaspick
774ff18c09 Allow nested attributes in associations to update values in it's owner object. Fixes a regression from 3.0.x 2011-12-14 20:13:03 -06:00
Jon Leighton
8a37970312 Remove that there copy/pasted code 💣 2011-12-14 17:34:35 +00:00
Jon Leighton
909b337da8 Don't try to autosave nested assocs. Fixes #2961. 2011-12-14 17:28:59 +00:00
Jon Leighton
19bea9f1bd Stop the build asploding on 1.8.7 2011-12-14 15:31:12 +00:00
Jon Leighton
665ef116ac Add return for 1.8.7 2011-12-14 11:11:12 +00:00
Jon Leighton
3ab49f87e4 Unfluff the CI.
With transactional fixtures enabled, the session records would end up in
@_current_transaction_records, and at the end of the transaction,
methods would be called on them that would trigger method_missing and
trigger attribute methods to be generated.

However, at this point the sessions table would not exist, and the
columns were not cached, so an exception would be raised because we
can't find the columns to generate attribute methods for.

Not sure exactly why this didn't crop up before but there have been
changes to the schema cache code and perhaps that means that column data
that was cached previously at that point is now uncached.
2011-12-14 11:05:00 +00:00
Jon Leighton
38703ac897 Revert naive O(1) table_exists? implementation.
It was a bad idea to rescue exceptions here. This can interfere with
transaction rollbacks which seems to be the cause of current CI
failure.

Instead, each adapter should implement its own DB-specific O(1)
implementation, and we fall back on the generic, slower, implementation
otherwise.
2011-12-13 23:46:26 +00:00
Aaron Patterson
d09b67cfc0 Errno::ENOENT error makes more sense when a file cannot be found 2011-12-10 16:32:07 -08:00
Piotr Sarnacki
f0b782d060 Allow to filter migrations by passing a block
Example:
  ActiveRecord::Migrator.migrate(path) do |migration|
    migration.name =~ /User/
  end

The above example will migrate only migrations with User in
the name
2011-12-09 21:43:36 +01:00
Aaron Patterson
5b82f50fef Use table_exists? from the schema cache. 2011-12-09 11:23:19 -08:00
Piotr Sarnacki
929b2646b6 Compare migrations for copying only by name and scope 2011-12-09 12:15:54 +01:00
Piotr Sarnacki
ed0b1f6eed Add suffix for migrations copied from engines 2011-12-09 11:45:19 +01:00
Piotr Sarnacki
255d9f5ac1 String#to_a is not available in 1.9 2011-12-09 10:33:37 +01:00
Piotr Sarnacki
1d9de9d758 Run also migrations in subdirectories.
With this commit, ActiveRecord will also look for migrations
in db/migrate subdirectories.
2011-12-09 03:33:06 +01:00
Piotr Sarnacki
62d556424a Ignore origin comment when checking for duplicates on Migration.copy
49ebe51 fixed copying migrations, but existing migrations would still
trigger warnings. The proper way to compare migrations is to ignore
origin lines - if migration is identical it means that we can
silently skip it, regardless where it comes from.
2011-12-09 01:54:20 +01:00
Piotr Sarnacki
652db2fc3e Fix copying migrations from engines
There was a bug in ActiveRecord::Migration.copy method, which
prevented adding special comment about the origin of migration.

Because of that, the check if migration is identical or if it's
not and should be skipped was always saying that migration is
skipped, which was causing additional useless warnings about
skipped migrations.
2011-12-09 01:54:20 +01:00
Jon Leighton
5da90b3483 Fix #3890. (Calling proxy_association in scope chain.) 2011-12-08 20:10:04 +00:00
Aaron Patterson
d80e4ee20e Regexp.union seems to have different results in 1.8 2011-12-08 10:20:14 -08:00
Jon Leighton
188b8c39da Fix broken test_exists_query_logging from the table_exists? change 2011-12-08 09:06:15 +00:00
Aaron Patterson
a505b13774 moving ignored regexp to the instance 2011-12-07 17:42:05 -08:00
Aaron Patterson
38a8f7f8ba speeding up ignored sql testing 2011-12-07 17:32:01 -08:00
Aaron Patterson
9dee540084 avoid deprecated methods 2011-12-06 10:07:47 -08:00
Vasiliy Ermolovich
0968ee3456 add prefix and suffix to renamed tables, closes #1510 2011-12-06 10:02:45 -08:00
José Valim
cf6ccf0ebd Merge pull request #3854 from exviva/validates_associated_marked_for_destruction
Do not validate associated records marked for destruction
2011-12-04 15:57:13 -08:00
Olek Janiszewski
a8134aceb3 Do not validate associated records marked for destruction
The main reason for this change is to fix a bug where
`validates_associated` would prevent `accepts_nested_attributes_for`
with `allow_destroy: true` from destroying invalid associated records.
2011-12-05 00:19:21 +01:00
Jon Leighton
4ded0dd2de Merge pull request #3851 from ebeigarts/fix_sequence_name
Fix sequence name with abstract classes.
2011-12-04 15:19:17 -08:00
Xavier Noria
cfeac38e2b implements a much faster auto EXPLAIN, closes #3843 [José Valim & Xavier Noria]
This commit vastly reduces the impact of auto
explain logging when enabled, while keeping
a negligible cost when disabled.

The first implementation was based on the idea
of subscribing to "sql.active_record" when
needed, and unsubscribing once done. This is
the idea behind AR::Relation#explain. Subscribe,
collect, unsubscribe.

But with the current implementation of notifications
unsubscribing is costly, because it wipes an internal
cache and that puts a penalty on the next event.

So we are switching to an approach where a long-running
subscriber is listening. Instead of collecting the
queries with a closure in a dedicated subscriber, now
we setup a thread local.

If the feature is disabled by setting the threshold
to nil, the subscriber will call a method that does
nothing. That's totally cheap.
2011-12-04 11:52:12 -08:00
Edgars Beigarts
82ae5c40ea Fix sequence name with abstract classes. 2011-12-04 20:10:14 +02:00
Jon Leighton
e9b6659c4c Add missing require 2011-12-03 20:39:49 +00:00
Jon Leighton
51c2ef0b81 Avoid postgres 9.X syntax 2011-12-03 20:06:46 +00:00
Jon Leighton
9c172b2931 Fix #3837.
We also need to time zone convert time zone aware attributes when
accessed via read_attribute, not only when via direct access.
2011-12-03 16:46:46 +00:00
Xavier Noria
de24ed9f2d removes the convenience instance version of AR::Base.silence_auto_explain
Rationale: As discussed with José and Jon, this convenience
shortcut is not clearly justified and it could let the user
thing the disabled EXPLAINs are related to the model instance
rather than being globally disabled.
2011-12-03 14:26:34 +01:00
Jon Leighton
a02691ce09 Merge pull request #3820 from jaylevitt/nested_loading_through_assoc
reintroduce patch from #726 to handle nested eager loading via associations
2011-12-03 04:01:14 -08:00
Xavier Noria
0be5adaedf implements AR::Base(.|#)silence_auto_explain 2011-12-02 11:16:26 -08:00
Xavier Noria
0306f82e0c implements automatic EXPLAIN logging for slow queries 2011-12-02 04:35:43 -08:00
Jon Leighton
9ead4130de Create method with known identifier then alias into place.
This means we never have to rely on define_method (which is slower and
uses more memory), even when we have attributes containing characters
that are not allowed in standard method names.

(I am mainly changing this because the duplication annoys me, though.)
2011-12-01 23:41:51 +00:00
Jon Leighton
e9fb6d04bd Add test for read_attribute(:id) with non-standard PK.
Also make it actually work.

It slows down all read_attribute accesses to map 'id' to whatever the PK
actually is, inside read_attribute. So instead make sure the necessary
methods are defined and that they redirect wherever they need to go.
2011-12-01 23:41:51 +00:00
Jon Leighton
47b97a739d Fix up test altering global state that was causing me grief 2011-12-01 23:41:51 +00:00
Jon Leighton
3a40d38619 Get rid of the underscore versions of attribute methods!
This makes me happy!
2011-12-01 23:41:51 +00:00
Jon Leighton
52eedf5e2b Add hackery to make Syck use encode_with/init_with. Fixes 1.8 after recent changes to attribute serialization. 2011-12-01 01:15:16 +00:00
Jon Leighton
1c783c6040 don't alter global state in test 2011-11-30 23:47:16 +00:00
Julius de Bruijn
4e380828ff If the table behind has no primary key, do not ask again and just return nil. 2011-11-30 23:47:16 +00:00
Jon Leighton
7895182d0f omg computer science!
Implement a mini state machine for serialized attributes. This means we
do not have to deserialize the values upon initialization, which means
that if we never actually access the attribute, we never have to
deserialize it.
2011-11-30 23:18:40 +00:00
Jon Leighton
4f20eb5908 Fix typo 2011-11-30 23:18:40 +00:00
Jon Leighton
61489dc684 Use inheritance to avoid special-case code for the 'id' method 2011-11-30 23:18:40 +00:00
Jay Levitt
24b8814db0 reintroduce patch from #726 to handle nested eager loading via associations 2011-11-30 18:12:24 -05:00
Bogdan Gusiev
a382d60f6a ActiveRecord::Relation#pluck method 2011-11-30 11:03:00 +02:00
Aaron Patterson
0e2477b602 Automatic closure of connections in threads is deprecated. For example
the following code is deprecated:

Thread.new { Post.find(1) }.join

It should be changed to close the database connection at the end of
the thread:

Thread.new {
  Post.find(1)
  Post.connection.close
}.join

Only people who spawn threads in their application code need to worry
about this change.
2011-11-29 15:04:41 -08:00
Aaron Patterson
29d2040b29 AbstractAdapter#close can be called to add the connection back to the
pool.
2011-11-29 14:40:37 -08:00
Aaron Patterson
f866f66b30 expire will set in_use to false 2011-11-29 14:02:58 -08:00
Aaron Patterson
79306de791 last_use is set on connection lease 2011-11-29 14:02:58 -08:00
Aaron Patterson
134cc8f939 Leased connections return false on second lease 2011-11-29 14:02:58 -08:00
Aaron Patterson
9bf8bf82b9 Adapters keep in_use flag when leased 2011-11-29 14:02:58 -08:00
Aaron Patterson
7837574e5b namespace the adapter test 2011-11-29 14:02:58 -08:00
Jon Leighton
8df787d428 Deprecated define_attr_method in ActiveModel::AttributeMethods
This only existed to support methods like `set_table_name` in Active
Record, which are themselves being deprecated.
2011-11-29 20:13:37 +00:00
Jon Leighton
f3c84dc316 Deprecate set_locking_column in favour of self.locking_column= 2011-11-29 20:13:37 +00:00
Jon Leighton
1a474cc8e4 Deprecate set_primary_key in favour of self.primary_key= 2011-11-29 20:13:37 +00:00
Jon Leighton
4aad289428 Make sure the original_foo accessor still works (but deprecated) if we are using self.foo= 2011-11-29 20:13:37 +00:00
Jon Leighton
7af719e81c Deprecate set_sequence_name in favour of self.sequence_name= 2011-11-29 20:13:37 +00:00
Jon Leighton
fd7ca98bb6 Add tests for set_sequence_name etc 2011-11-29 20:13:36 +00:00
Jon Leighton
34609d67b4 Deprecate set_inheritance_column in favour of self.inheritance_column= 2011-11-29 20:13:36 +00:00
Jon Leighton
0b72a04d0c Deprecate set_table_name in favour of self.table_name= or defining your own method. 2011-11-29 20:13:36 +00:00
Aaron Patterson
f73f53455a respond_to? information of AR is not the responsibility of the spec
resolver.
2011-11-29 11:48:55 -08:00
Jon Leighton
2169603385 Merge pull request #3636 from joshsusser/master
association methods are now generated in modules
2011-11-29 10:09:42 -08:00
Josh Susser
c347b3c06c don't change class definition in test case 2011-11-29 09:14:21 -08:00
Jon Leighton
d534c8fbe2 Fix resolver_test.rb on travis (postgresql isn't setup, so it can't load the connection adapter) 2011-11-29 12:47:54 +00:00
Jon Leighton
1defb6adb8 Fix schema_cache_test.rb for sqlite3_mem 2011-11-29 12:29:42 +00:00
Aaron Patterson
dde2113867 Move connection resoluion logic to it's own testable class. 2011-11-28 15:23:25 -08:00
Aaron Patterson
ffb218c750 pools are 1:1 with spec now rather than 1:1 with class 2011-11-28 15:23:25 -08:00
Aaron Patterson
2a9a8ad4df break establish_connection to smaller methods 2011-11-28 15:23:24 -08:00
Aaron Patterson
ba0b3eee14 Merge pull request #3768 from janv/master
Test and fix for Issue 3450
2011-11-28 09:35:43 -08:00
Jan Varwig
cba5a3a367 Test case and fix for rails/rails#3450
Asssigning a parent id to a belongs_to association actually updates the object that is validated when the association has :validates => true
2011-11-27 22:29:56 +01:00
Jon Leighton
b00cf122e2 Merge pull request #3748 from samsonasu/has_many_custom_pk_new_record
New records should load has_many relationships with custom primary keys
2011-11-27 13:05:19 -08:00
Josh Susser
61bcc318c8 use GeneratedFeatureMethods module for associations 2011-11-27 11:22:12 -08:00
Xavier Noria
1be9830d4d add the query to AR::Relation#explain output
Rationale: this is more readable if serveral queries
are involved in one call. Also, it will be possible
to let AR log EXPLAINs automatically in production
mode, where queries are not even around.
2011-11-25 14:29:34 -08:00
Brian Samson
0f5104d720 load has_many associations keyed off a custom primary key if that key is present but the record is unsaved 2011-11-25 08:24:54 -07:00
Aaron Patterson
008abd17dc fixing tests on ruby 1.8 2011-11-20 15:09:03 -08:00
Aaron Patterson
bd2f5c062d pushing caching and visitors down to the connection 2011-11-19 20:19:53 -08:00
Jon Leighton
9c37416a3e Verify that #3690 has been closed by previous changes to the mysql
adapters.

These tests fail on the v3.1.2 tag.

Closes #3690.
2011-11-19 12:34:15 +00:00
Aaron Patterson
a2f14e2344 Revert "Merge pull request #1163 from amatsuda/sexier_migration_31"
This reverts commit 0e407a90413d8a19002b85508d811ccdf2190783, reversing
changes made to 533a9f84b035756eedf9fdccf0c494dc9701ba72.

Conflicts:

	activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
	activerecord/test/cases/migration_test.rb
2011-11-17 10:29:28 -08:00
Aaron Patterson
649f2513a4 Revert "Merge pull request #3603 from vijaydev/change_table_without_block_arg"
This reverts commit 81fad6a270ec3cbbb88553c9f2e8200c34fd4d13, reversing
changes made to 23101de283de13517e30c4c3d1ecc65525264886.

Conflicts:

	activerecord/test/cases/migration_test.rb
2011-11-17 10:29:28 -08:00
James Adam
73cb0f9828 ActiveRecord::Base#becomes should retain the errors of the original object.
This commit contains a simple failing test that demonstrates the behaviour we expect, and a fix. When using `becomes` to transform the type of an object, it should retain any error information that was present on the original instance.
2011-11-16 23:19:58 +00:00
Aaron Patterson
61228e9a0c fixing tests on PG 2011-11-16 13:25:55 -08:00
Josh Susser
9cdf33af0b add test for super-ing to association methods 2011-11-15 23:32:58 -08:00
Josh Susser
7cba6a3784 association methods are now generated in modules
Instead of generating association methods directly in the model
class, they are generated in an anonymous module which
is then included in the model class. There is one such module
for each association. The only subtlety is that the
generated_attributes_methods module (from ActiveModel) must
be forced to be included before association methods are created
so that attribute methods will not shadow association methods.
2011-11-15 23:32:58 -08:00
Ryan Naughton
63a22ca616 Fixes issue #3483, regarding using a mixture of ranges and discrete values in find conditions. Paired with Joey Schoblaska. 2011-11-14 21:43:27 -06:00
Gabriel Sobrinho
e1b79c56be Failing test case for issue #3483 2011-11-14 21:39:03 -06:00
Aaron Patterson
11c9fc9364 Merge pull request #3371 from yahonda/fix_ora_00932_error
Fix ORA-00932 error when trying to insert 0 to DATE type columns.
2011-11-14 04:36:55 -08:00
Vijay Dev
2e5c4717ba change_table bulk test case should check if the connection supports bulk alter 2011-11-11 12:47:03 +05:30
Vijay Dev
6e112e4217 Modify change_table to remove the need for the block argument. 2011-11-11 02:47:27 +05:30
Vijay Dev
b805c71655 Checking the arity of the block passed to create_table
A recent change made to create_table does away with the
need for the block argument. Checking the arity will prevent the
mixing up of the two syntaxes.
2011-11-10 22:55:13 +05:30
Akira Matsuda
74c6e80cab exclude ORDER BY clause when querying Relation#exists? 2011-11-09 04:51:11 +09:00
Xavier Noria
b454601be4 revises EXPLAIN tests for SQLite3
The output in Travis is a bit different. The SQLite
documentation (http://www.sqlite.org/eqp.html) warns
output may change dramatically between releases. I
do not want to mock the result set because I want a
real EXPLAIN to happen. I prefer a test that may fail
in future releases than a test that may give false
positives in future releases.
2011-11-06 22:21:05 -08:00
Aaron Patterson
9b46613780 Merge pull request #3521 from nulogy/fix_postgres_adapter_to_handle_spaces_between_schemas
Fix postgres adapter to handle spaces between schemas
2011-11-06 13:16:07 -03:00
Justin Mazzi
c7d2078596 Update ActiveRecord#attribute_present? to work as documented
"Returns true if the specified attribute has been set by the user or by
a database load and is neither nil nor empty?"

Fixes #1613
2011-11-05 22:36:19 -04:00
Xavier Noria
e7b7b44123 implements AR::Relation#explain
This is a first implementation, EXPLAIN is highly
dependent on the database and I have made some
compromises.

On one hand, the method allows you to run the most
common EXPLAIN and that's it. If you want EXPLAIN
ANALYZE in PostgreSQL you need to do it by hand.

On the other hand, I've tried to construct a string
as close as possible to the ones built by the
respective shells. The rationale is that IMO the
user should feel at home with the output and
recognize it at first sight. Per database.

I don't know whether this implementation is going
to work well. Let's see whether people like it.
2011-11-05 18:30:19 -07:00
Jon Leighton
f575e21025 Merge pull request #3525 from kennyj/fix_3440-1
Fixed an issue id false option is ignored on mysql/mysql2 (fix #3440)
2011-11-05 10:29:18 -07:00
kennyj
fb0bf3c984 Fixed an issue id false option is ignored on mysql/mysql2 (fix #3440) 2011-11-06 02:15:47 +09:00
Jon Leighton
562583c766 Add ActiveRecord::Relation#uniq for toggling DISTINCT in the SQL query 2011-11-05 16:22:18 +00:00
Vlad Jebelev
69dcd45aea AR changes to support creating ordered (asc, desc) indexes 2011-11-04 15:45:24 -05:00
Arun Agrawal
6da558660c Fix test as one more has_many added 2011-11-04 19:30:59 +05:30
Jon Leighton
e6cc2ea201 Allow the :class_name option for associations to take a symbol.
This is to avoid confusing newbies, and to be consistent with the fact
that other options like :foreign_key already allow a symbol or a string.
2011-11-04 11:17:56 +00:00
Aaron Patterson
0e407a9041 Merge pull request #1163 from amatsuda/sexier_migration_31
Sexier migrations
2011-11-04 03:29:59 -07:00
Jeremy Kemper
533a9f84b0 Merge pull request #3507 from jmazzi/issue-3503
Preserve SELECT columns on the COUNT for finder_sql when possible
2011-11-03 21:17:15 -07:00
Jon Leighton
d486103570 Fix #3271.
Building the conditions of a nested through association could
potentially modify the conditions of the through and/or source
association.

This is a Bad Thing.
2011-11-03 15:12:08 +00:00
Jon Leighton
19b2a5f2bd Remove all revelant through records.
If a record is removed from a has_many :through, all of the join records
relating to that record should also be removed from the through
association's target.

(Previously the records were removed in the database, but only one was
removed from the in-memory target array.)
2011-11-03 13:13:13 +00:00
Jon Leighton
71bc921ec8 Fix adding multiple instances of the same record to a has_many :through.
Fixes #3425.
2011-11-03 12:39:05 +00:00
Jon Leighton
b4b178f7e9 Fix #3247.
Fixes creating records in a through association with a polymorphic source
type.
2011-11-03 10:23:42 +00:00
Vijay Dev
1afe269a4a assert_match takes a regexp and a string in that order 2011-10-31 19:01:03 +05:30
Laust Rud Jacobsen
ff9c2799c1 dump_schema_information: explicitly order inserts into schema_migrations table
This change reduces churn in the db/development_structure.sql file when using :sql as
active_record.schema_format, and makes comparing diffs much easier.

Test ensures the output SQL-statements are lexically ordered by version.
2011-10-31 10:36:13 +01:00
Joe Van Dyk
420f7fd507 Added failing test case for changing schema in migration not clearing the prepared statement cache 2011-10-27 10:50:38 -07:00
Arun Agrawal
95d9c120d3 More checks for instance writers. 2011-10-27 16:25:50 +05:30
Arun Agrawal
80fc29f36f Adding more checks for instance_writer false 2011-10-27 15:47:56 +05:30
Arun Agrawal
485b99611b Test fix Allow instances to disable record_timestamps
Removed here 0d0176c4ffe5c58fd1002efbd8f7bd45a8872e33
2011-10-27 15:41:15 +05:30
Pratik Naik
0d0176c4ff Allow instances to disable record_timestamps 2011-10-26 18:20:12 +01:00
David Heinemeier Hansson
1d9ab88ee6 Merge branch 'master' of github.com:rails/rails 2011-10-25 17:22:55 -05:00
David Heinemeier Hansson
5daf07704a Fix that changing a store should mark the store attribute as changed 2011-10-25 17:22:52 -05:00
Greg Reinacker
f092be821d preserve decimal column attributes after migration 2011-10-21 17:30:39 -06:00
Aaron Patterson
ee9d9fb5fa Merge pull request #3258 from ileitch/3-1-stable
Postgres: Do not attempt to deallocate a statement if the connection is no longer active.
2011-10-20 08:45:22 -07:00
Yasuo Honda
5bc23e4fb5 Fix ORA-00932 error when trying to insert 0 to DATE type columns. 2011-10-19 15:56:25 -04:00
Aaron Patterson
c2f3c9bf56 only use now() on pg! 2011-10-18 13:30:01 -07:00
Aaron Patterson
6a28c512e3 reset prepared statement when schema changes imapact statement results. fixes #3335 2011-10-18 11:20:13 -07:00
Aaron Patterson
76af2818a6 use now() for dates in pg 2011-10-18 10:07:40 -07:00
José Valim
7511f9794d Merge pull request #3340 from surfacedamage/exclude_destroy_in_all_blank_check
Exclude _destroy parameter in :all_blank check (issue #2937)
2011-10-17 11:15:58 -07:00
Aaron Christy
8510a0bb5a Exclude _destroy parameter in :all_blank check (issue #2937) 2011-10-17 13:29:11 -04:00
Aaron Patterson
8919a68b96 Merge pull request #3334 from mperham/master
Default timestamps to non-null
2011-10-16 16:14:56 -07:00
Vishnu Atrai
9210458547 fix to remove warning in test cases 2011-10-16 14:29:06 +05:30
Mike Perham
3dbedd2823 Default timestamps to non-null 2011-10-14 21:09:53 -07:00
Christian Bäuerlein
410fa4cf7c Includes stale record in StaleObjectError 2011-10-14 16:28:02 +02:00
Jeremy Kemper
8cbe826958 Rails 4 is just around the corner. Stuck with 1.8 until then. 2011-10-13 16:11:00 -07:00
Jeremy Kemper
0a9b6de4d2 Tests gotta run in 1.8 too 2011-10-13 15:54:53 -07:00
David Heinemeier Hansson
85b64f98d1 Added ActiveRecord::Base.store for declaring simple single-column key/value stores [DHH] 2011-10-13 16:24:22 -05:00
Arun Agrawal
af7eeaafdb ambiguous first argument; put parentheses or even spaces Warning removed! 2011-10-10 14:16:45 +05:30
Jon Leighton
3456ef1119 Use broken YAML that will fail with Syck as well as Psych. Fixes test_broken_yaml_exception in fixtures_test.rb on Ruby 1.8.7.
Cherry-pick from 3-1-stable: b8d46924e70e0847e92e1d2dbaaec8c11381072c
2011-10-09 16:47:53 -07:00
Jeremy Kemper
8dba127188 Remove stray whitespace 2011-10-09 14:21:12 -07:00
Joseph Palermo
c90e5ce779 Only use LOWER for mysql case insensitive uniqueness check when column has a case sensitive collation. 2011-10-09 13:14:07 -07:00
Arun Agrawal
34d950b066 Fixed BodyProxy.new for tests! for wrong argument 2011-10-08 10:01:58 +05:30
Aaron Patterson
3088d23647 Merge pull request #3232 from Juanmcuello/pg_prepared_statements
Use the schema_search_path in prepared statements.
2011-10-06 20:08:05 -07:00
Jeremy Kemper
999b7ed94d Transactional fixtures enlist all active database connections.
You can use multiple databases in your tests without disabling transactional fixtures.
2011-10-05 19:10:18 -07:00
Jon Leighton
2e9e647fee Raise an exception on unknown primary key inside AssociationReflection.
An association between two models cannot be made if a relevant key is
unknown, so fail fast rather than generating invalid SQL. Fixes #3207.
2011-10-05 20:21:21 +01:00
Jon Leighton
64747654ca Revert "Raise error on unknown primary key."
This reverts commit ee2be435b1e5c0e94a4ee93a1a310e0471a77d07.
2011-10-05 20:21:21 +01:00
Juan M. Cuello
ac659b8ed3 refs #3232. Prepared statements and postgreSQL schemas.
Add tests for prepared statements with multiple schemas in
postgreSQL.
2011-10-05 14:44:50 -03:00
Dmitry Polushkin
84eece0a82 Merge branch 'master' of git://github.com/rails/rails 2011-10-05 17:35:59 +01:00
Jon Leighton
ee2be435b1 Raise error on unknown primary key.
If we don't have a primary key when we ask for it, it's better to fail
fast. Fixes GH #2307.
2011-10-05 01:11:40 +01:00
Yasuo Honda
b564ffcad4 To support ActiveRecord unit tests for IBM DB2 2011-10-02 22:51:01 -04:00
Dmitry Polushkin
19965402b2 Merge branch 'master' of git://github.com/rails/rails 2011-10-01 20:49:14 +01:00
Jon Leighton
adb8ac153f Don't call self.class unless necessary. Closes #3171. 2011-09-29 18:00:30 +01:00
Rocky Jaiswal
aefc40324d Fixed failed test under 1.8.7 as map.keys order in indeterminable 2011-09-28 11:57:34 +05:30
Jon Leighton
b3407c86cf Don't require a DB connection when setting primary key.
Closes #2807.
2011-09-26 18:15:09 +01:00
Jon Leighton
89e98e278a Merge pull request #3030 from htanata/fix_habtm_select_query_method
Fix: habtm doesn't respect select query method
2011-09-26 16:52:23 +01:00
Jon Leighton
3b87c38d02 Fix belongs_to polymorphic with custom primary key on target.
Closes #3104.
2011-09-26 15:42:34 +01:00
Jon Leighton
b838059817 CollectionProxy#replace should change the DB records rather than just mutating the array. Fixes #3020. 2011-09-26 10:41:58 +01:00
Arun Agrawal
d589d9f160 fix test error when running with postgresql.
This Sqlite3 should be in if block.
Was giving error because sqlite3 is not loaded
2011-09-18 23:20:09 +05:30
Arun Agrawal
afa78fe327 Fixed test for JRuby.
for Sqlite3 in AR-JDBC.It's Jdbc::SQLite3::VERSION
2011-09-18 00:23:48 +05:30
Dmitry Polushkin
9d54f8994d Merge branch 'master' of git://github.com/rails/rails 2011-09-15 09:39:26 +01:00
Jon Leighton
3b8a7cf2a7 Stop trying to be clever about when to define attribute methods.
There is no meaningful performance penalty in defining attribute
methods, since it only happens once.

There is also no reason *not* to define them, since they get thrown in
an included module, so they will not 'overwrite' anything. In fact, this
is desirable, since it allows us to call super.
2011-09-14 00:00:37 +01:00
Jon Leighton
11870117c6 Rename first_or_new to first_or_initialize.
For consistency with find_or_initialize_by. Also remove first_or_build
alias.
2011-09-13 19:09:01 +01:00
Jon Leighton
1a421ceccb Deprecate using method_missing for attributes that are columns.
This shouldn't ever happen unless people are doing something
particularly weird, but adding a deprecation in case there are bugs not
caught by our tests.
2011-09-13 00:03:09 +01:00
Jon Leighton
ac687ed651 Let Ruby deal with method visibility.
Check respond_to_without_attributes? in method_missing. If there is any
method that responds (even private), let super handle it and raise
NoMethodError if necessary.
2011-09-13 00:01:58 +01:00
Jon Leighton
cf115d2f8e Reset column info when messing with columns.
We are subclassing Session here, but messing with the columns will
affect the attribute methods defined on the Session superclass, and
therefore other tests, unless we properly isolate it by resetting column
info before and after the test run.
2011-09-13 00:01:58 +01:00
Jon Leighton
eecfa84a90 Always generate attribute methods on the base class.
This fixes a situation I encountered where a subclass would cache the
name of a generated attribute method in @_defined_class_methods. Then,
when the superclass has it's attribute methods undefined, the subclass
would always have to dispatch through method_missing, because the
presence of the attribute in @_defined_class_methods would mean that it
is never generated again, even if undefine_attribute_methods is called
on the subclass.

There various other confusing edge cases like this. STI classes share
columns, so let's just keep all the attribute method generation state
isolated to the base class.
2011-09-13 00:01:58 +01:00
Jon Leighton
50d395f96e Raise error when using write_attribute with a non-existent attribute.
Previously we would just silently write the attribute. This can lead to
subtle bugs (for example, see the change in AutosaveAssociation where a
through association would wrongly gain an attribute.

Also, ensuring that we never gain any new attributes after
initialization will allow me to reduce our dependence on method_missing.
2011-09-13 00:01:58 +01:00
Jon Leighton
8667d3aeb6 Make protected method public so we avoid method_missing. 2011-09-13 00:01:58 +01:00
Arun Agrawal
fb73be8469 Not used variables removed. Warnings removed. 2011-09-10 09:38:57 +05:30
Guillermo Iguaran
b7f1735fea Add missing require in base_test.rb, fixes isolated test 2011-09-09 12:46:06 -05:00
Dmitry Polushkin
edd2f21e80 Test polymorphic record with optimistic locking and counter cache should be destoyed without catching the ActiveRecord::StaleObjectError. 2011-09-09 08:31:54 +01:00
Jon Leighton
cbf1dc7842 Merge pull request #2757 from andmej/first_or_create_pull_request
Add first_or_create family of methods to Active Record
2011-09-08 15:07:23 -07:00
Aaron Patterson
e1b500ec96 LRU cache in mysql and sqlite are now per-process caches. 2011-09-07 15:26:47 -07:00
Aaron Patterson
e6adeaa2fa fixing file name 2011-09-07 15:26:47 -07:00
Aaron Patterson
834d429e84 LRU should cache per process in postgresql. fixes #1339 2011-09-07 15:26:47 -07:00
Aaron Patterson
f5ea24b3db Merge commit 'refs/pull/2909/head' of https://github.com/rails/rails into rawr
* https://github.com/rails/rails:
  Postgresql adapter: added current_schema check for table_exists?
  Postgresql adapter: added current_schema check for table_exists?
2011-09-07 10:44:50 -07:00
Yasuo Honda
3937d443d6 Add ROWNUM to test first and last to support Oracle. 2011-09-07 07:40:55 -04:00
Jon Leighton
143769051b Don't include any of includes, preload, joins, eager_load in the through association scope. 2011-09-07 09:27:41 +01:00
Jon Leighton
db8d54ebf5 Merge pull request #2485 from akaspick/exists_fix
fix exists? to return false if passed nil (which may come from a missing
2011-09-07 00:38:51 -07:00
Aaron Patterson
4edf6ea0ea Merge pull request #2897 from rsutphin/ar31-remove_connection
Patch for issue #2820
2011-09-06 17:43:58 -07:00
Jon Leighton
9bde73ff72 Nested through associations: preloads from the default scope of a through model should not be included in the association scope. (We're already excluding includes.) Fixes #2834. 2011-09-06 16:34:32 +01:00
Jon Leighton
b24d668859 Ensure we are not comparing a string with a symbol in HasManyAssociation#inverse_updates_counter_cache?. Fixes #2755, where a counter cache could be decremented twice as far as it was supposed to be. 2011-09-06 15:58:07 +01:00
Jon Leighton
77ff1ce541 Disable active record marshalling tests on Ruby 1.8.7 on Travis CI, as they have been failing intermittently for a long while due to what appears to be a Ruby bug. If anyone has the skills/expertise/time to debug this, please speak to the Travis guys. 2011-09-06 11:45:08 +01:00
Damien Mathieu
e8d5920b74 #first doesn't take an order in this test 2011-09-06 10:01:33 +02:00
Santiago Pastorino
164382003c Merge pull request #2877 from dmathieu/fix_tests_pg_18
Last orders the records by id
2011-09-05 15:41:59 -07:00
Damien Mathieu
51da1e5c65 first and last orders the records by id 2011-09-06 00:30:40 +02:00
Aaron Patterson
6d93f70c58 Merge pull request #2716 from jbbarth/fix_invert_rename_index
Fix bad options order in AR::Migration::CommandRecorder#invert_rename_index
2011-09-05 14:17:55 -07:00
Georg Friedrich
2175012230 Don't find belongs_to target when the foreign_key is NULL. Fixes #2828 2011-09-05 13:49:29 -07:00
Damien Mathieu
5f5527c726 Use LIMIT sql word in last when it's possible 2011-09-05 14:37:37 +02:00
Damien Mathieu
451cdd62ce use LIMIT SQL word in first - Closes #2783 2011-09-05 13:09:52 +02:00
Arun Agrawal
76e94016a4 Sort here to make sure the order is ok. 2011-09-05 12:49:34 +05:30
Arun Agrawal
9066e34025 We need to recorder here. Need to drop the order from default scope.
Fixes #2832
2011-09-05 00:12:57 +05:30
Jon Leighton
ef7e60f008 Revert "Fixes bug in ActiveRecord::QueryMethods, #1697"
This reverts commit 0df27c98d982ec87d2fb48cfda82694eb267993e.

Reverted due to failing test, see #2845.
2011-09-04 09:56:55 +01:00
Xavier Noria
0a38e2a5ce restores the API docs of AR::Fixtures, made a quick pass over them, revises link in fixture template [closes #2840] 2011-09-03 15:20:30 -07:00
Arun Agrawal
bf4117a8b1 Need to add here to pass the test
As in previous commit it's removed.
2011-09-03 14:33:27 +05:30
Aaron Patterson
6f3c6992c5 * Psych errors with poor yaml formatting are proxied. Fixes #2645, #2731 2011-09-01 15:08:19 -07:00
Joshua Wehner
0df27c98d9 Fixes bug in ActiveRecord::QueryMethods, #1697
Replace split on comma with a regexp that will reverse all ASC/DESC specifically
2011-08-31 16:17:28 -04:00
Raimonds Simanovskis
60d8e4ac28 Ensure correct ordering of results in test_update_all_with_joins_and_offset_and_order
Last two asserts in this test assume that all_comments are ordered by posts.id and then by comments.id therefore additional ordering is added. Without it test was failing on Oracle which returned results in different order.
2011-08-30 22:33:49 +01:00
Andrés Mejía
84dad446c6 Adding first_or_create, first_or_create!, first_or_new and first_or_build to Active Record.
This let's you write things like:

    User.where(:first_name => "Scarlett").first_or_create!(:last_name => "Johansson", :hot => true)

Related to #2420.
2011-08-30 16:33:37 -05:00
Jon Leighton
bd4bd3f50a Merge pull request #2750 from rsim/fix_test_column_names_are_escaped_for_oracle
Fix test column names are escaped for oracle
2011-08-30 11:04:01 -07:00
Aaron Patterson
cebff6d0f7 Merge pull request #2021 from dasch/more_postgres_utils
Make #extract_schema_and_table an instance method in Utils
2011-08-29 13:38:10 -07:00
Jon Leighton
735d985b01 The join_nodes must be passed to the JoinDependency initializer and therefore counted by the alias tracker. This is because the association_joins are aliased on initialization and then the tables are cached, so it is no use to alias the join_nodes later. Fixes #2556. 2011-08-29 15:05:47 +01:00