Commit Graph

3106 Commits

Author SHA1 Message Date
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
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
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 0df27c98d9.

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
Jon Leighton
5766539342 Create an AbstractMysqlAdapter to abstract the common code between MysqlAdapter and Mysql2Adapter. 2011-08-29 12:43:39 +01:00