Commit Graph

5053 Commits

Author SHA1 Message Date
Aaron Patterson
1a0b7ea3c9 adding more tests around database uri parsing 2011-07-21 12:57:05 -07:00
Glenn Gillen
1f427b5341 Add documentation for URL connection strings. 2011-07-20 16:23:31 -07:00
Glenn Gillen
16249feaab Added test for postgres connections as URL. Fixed query param parsing. 2011-07-20 16:23:31 -07:00
Glenn Gillen
89357c8f83 Provide database connection settings as a URL. 2011-07-20 16:23:31 -07:00
Aaron Patterson
22e47279bc no need to sort the values 2011-07-20 15:52:53 -07:00
Franck Verrot
8bc314b3b7 assign_nested_attributes_for_collection_association should work with Ruby 1.9 [Closes #2106]
Children attributes can be either String's or Symbol's, so let's check if the object responds to to_i.
2011-07-20 15:40:01 -07:00
Aaron Patterson
09a488456a bigdecimal should be typecast to a float on sqlite3. fixes #2162 2011-07-20 14:39:01 -07:00
Vijay Dev
02cbaf0593 avoid Symbol#to_proc 2011-07-20 00:28:51 +05:30
Norman Clarke
9db2d10b11 Explicitly require Active Support dependencies
This fixes errors when using Active Record outside of Rails. In Rails,
these files are required by other classes that are always loaded, so
this error does not happen.

Without core_ext/module/delegation, a NoMethodError is raised because
`delegate` remains undefined.

Without core_ext/class/attribute_acessors, an ArgumentError is raised because
`delegate` does not receive a value for its :to option.
2011-07-19 09:56:02 -03:00
Elliot Winkler
0e1d617b8b ActiveRecord: Fix eager loading so that giving a blank order clause generates valid SQL 2011-07-18 14:56:37 -06:00
José Valim
da144894e9 Merge pull request #195 from bigfix/active_model_include_serialization
ActiveModel support for the :include serialization option
2011-07-18 06:50:43 -07:00
Prem Sichanugrist
1ccca1b9cb Refactor the code a bit to reduce the duplication 2011-07-17 18:53:15 -04:00
Prem Sichanugrist
6e6994994d Raise an ArgumentError if user passing less number of argument in the dynamic finder
The previous behavior was unintentional, and some people was relying on it. Now the dynamic finder will always expecting the number of arguments to be equal or greater (so you can still pass the options to it.)

So if you were doing this and expecting the second argument to be nil:

    User.find_by_username_and_group("sikachu")

You'll now get `ArgumentError: wrong number of arguments (1 for 2).` You'll then have to do this:

    User.find_by_username_and_group("sikachu", nil)
2011-07-17 18:44:03 -04:00
John Firebaugh
4860143ee4 ActiveModel support for the :include serialization option
This commit moves support for the :include serialization option for
serializing associated objects out of ActiveRecord in into ActiveModel.
The following methods support the :include option:

  * serializable_hash
  * to_json
  * to_xml

Instances must respond to methods named by the values of the :includes
array (or keys of the :includes hash). If an association method returns
an object that is_a?(Enumerable) (which AR has_many associations do), it
is assumed to be a collection association, and its elements must respond
to :serializable_hash. Otherwise it must respond to :serializable_hash
itself.

While here, fix #858, XmlSerializer should not singularize already
singular association names.
2011-07-17 11:34:07 -07:00
John Firebaugh
0933b6d1ba We already have the record; no need to retrieve it again 2011-07-17 11:34:06 -07:00
Santiago Pastorino
31ea0276a4 Merge pull request #2063 from elight/master
Patch for https://github.com/rails/rails/issues/2059
2011-07-14 11:14:27 -07:00
Evan Light
f13dea8a34 Fix and unit test for https://github.com/rails/rails/issues/2059
Cache key was incorrectly using timezone-dependent record#updated_at when it should be using a timezone-independent value to generate the cache key

Minor refactoring to cache_key timezone test

Closes #2059

Adds a test to validate the format of the cache_key for nil and present updated_at values

Correctly handles updated_at == nil
2011-07-14 14:04:02 -04:00
Santiago Pastorino
d632e927ec Merge pull request #1807 from caius/find_in_batches_id_bug
Bugfix by stopping find_in_batches using the records after yielding.
2011-07-14 07:57:04 -07:00
Santiago Pastorino
8cf45150de Merge pull request #2042 from SAP-Oxygen/master-sqlbypass-patch
Fix for SqlBypass session store (for master)
2011-07-12 15:06:00 -07:00
Joseph Wong
88e6c06242 Fix for SqlBypass session store
Two issues fixed:
1) connection_pool is not defined - needed by SessionStore#drop_table!
and create_table! since c94651f

2) initialization of connection to the default of AR::Base.connection
only occurred at the singleton level - the instance level method defined
by cattr_accessor did not have this logic
2011-07-12 11:10:25 -07:00
Joseph Wong
66dee26930 Fixed session ID fixation for ActiveRecord::SessionStore
I have found that Rails will take an invalid session ID specified by the
client and materialize a session based on that session ID. This means
that it is possible, among other things, for a client to use an
arbitrarily weak session ID or for a client to resurrect a previous used
session ID. In other words, we cannot guarantee that all session IDs are
generated by the server and that they are (statistically) unique through
time.

The fix is to always generate a new session ID in #get_session if an
existing session cannot be found under the incoming session ID.

Also added new tests that make sure that an invalid session ID is never
materialized into a new session, regardless of whether it comes in via a
cookie or a URL parameter (when :cookie_only => false).
2011-07-12 11:09:11 -07:00
Jon Leighton
1712d90050 Fix exception if old and new targets are both nil. Fixes #1471. 2011-07-12 00:14:45 +01:00
Santiago Pastorino
c3732bfed0 Merge pull request #1823 from gnarg/master
Log instrumentation name for exists? queries
2011-07-10 18:02:31 -07:00
Santiago Pastorino
c5448721b5 to_key on a destroyed model should return nil 2011-07-09 15:36:57 -03:00
Akira Matsuda
d1545bcf94 fix AR having() not to raise NoMethodError when the given argument does not respond to empty?
having raises NoMethodError: undefined method `empty?' when a Fixnum or Date/Time were passed via varargs
2011-07-09 20:14:41 +09:00
Jon Leighton
111968d402 Foo.joins(:bar).includes(:bar) should result in a single query with :bar as a join. Related: #1873. 2011-07-09 11:39:04 +01:00
Xavier Noria
b65bd01d55 Merge branch 'master' of git://github.com/lifo/docrails 2011-07-09 12:20:24 +02:00
Tomas D'Stefano
ea4b94a7bf Destroy association habtm record before destroying the record itself. Fixes issue #402. 2011-07-08 22:26:54 +01:00
Jon Leighton
dfec3737b0 Ensure that the foreign key gets set when doing record.create_association or record.create_association. Fixes #1960. 2011-07-08 21:03:54 +01:00
Daniel Schierbeck
9991f0f15a Refactor PostgreSQLAdapter a bit
Move the private method #extract_schema_and_table into a separate
Utils module so that it can be tested without resorting to #send.
2011-07-08 16:05:55 +02:00
Akira Matsuda
49bf8597e6 Use Enumerable#with_index. We're on Ruby > 1.8.7 2011-07-08 21:38:02 +09:00
Akira Matsuda
4d4819fb27 :conditions => where 2011-07-08 06:13:21 +09:00
Akira Matsuda
b2816ae971 :joins => joins 2011-07-08 06:13:21 +09:00
Akira Matsuda
c4bd47778f :include => includes 2011-07-08 06:13:21 +09:00
Akira Matsuda
6c94f69673 find(:first) => first 2011-07-08 06:13:21 +09:00
Akira Matsuda
a3683fd0e4 find(:all) => all 2011-07-08 06:13:21 +09:00
Santiago Pastorino
63861e0c9c Merge pull request #1997 from knapo/master
Make `ActiveRecord::Batches#find_each` to not return `self`.
2011-07-07 09:00:35 -07:00
Dmitriy Kiriyenko
f1553731ed Add require ActiveSupport delegation to ActiveRecord::Relation class. 2011-07-07 17:32:18 +03:00
knapo
2ca9b6dfab Make ActiveRecord::Batches#find_each to not return self.
This caused that `find_each` was producing extra db call taking all the records from db, and was less efficient than `ActiveRecord::Base#all`.
2011-07-07 11:40:11 +02:00
Santiago Pastorino
1bad08f116 Merge pull request #1120 from lysenko/collection_singular_ids
collection_singular_ids ignores association :include option
2011-07-06 20:13:24 -07:00
Santiago Pastorino
c6578d64ca Merge pull request #1989 from simonbaird/master
rake db:test:purge creates mysql database with wrong charset & collation (master branch)
2011-07-06 20:10:14 -07:00
Jon Leighton
86390c3bf3 Don't construct association scope in initializer. This yields a big performance gain for cases where the association is never used to load the target, for example with preloading. Related: #1873. 2011-07-07 01:07:31 +01:00
Simon Baird
ecd37084b2 Fix charset/collate in mysql recreate_database
See new method mysql_creation_options. It is used by both
create_database and recreate_database so they are consistent.

(Cherry pick of 3ba3125b24)
2011-07-07 09:27:51 +10:00
Anatoliy Lysenko
66dd2d3d10 Fix bug in collection_singular_ids on has many through association with conditions and includes,
when condtions references tables from includes.
Test fail because of invalid sql:
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: comments.id:
SELECT "posts".id FROM "posts" INNER JOIN "readers" ON "posts"."id" = "readers"."post_id"
WHERE "readers"."person_id" = 1 AND (comments.id is null)

Bug described in github#925

This commit will revert fix from 3436fdfc12 , but tests is ok.

Bug described in #6569 ticket.
2011-07-06 23:23:34 +03:00
Ernie Miller
2bdad7669c Remove case statement changes from 2e0840d and 56ac32a. Inheritance FTW. 2011-07-06 16:13:57 -04:00
Santiago Pastorino
c713cf9a5d Merge pull request #1273 from jeremyf/feature-association-proxy-send
Addresses an inconsistency in the ActiveRecord::Base.method_missing handl
2011-07-06 13:05:58 -07:00
Jon Leighton
2c72830cd9 Merge pull request #1979 from bogdan/association_sum_array_compatibility
Fixed AR::Relation#sum compatibility with Array#sum
2011-07-06 00:49:05 -07:00
Santiago Pastorino
b27871a66f Merge pull request #1968 from bogdan/associations_find_array_compatibility2
Fixed CollectionAssociation#find to be compatible with Array#find
2011-07-05 09:41:09 -07:00
Bogdan Gusiev
e7bec4e435 Fixed AR::Relation#sum compatibility with Array#sum
In order make Relation behavior closer to Array
Made Relation#sum to accept block and delegate it to Array#sum
2011-07-05 14:36:20 +03:00
Bogdan Gusiev
8ba0c1ac53 Fixed CollectionAssociation#find to be compatible with Array#find
In order to make CollectionAssociation behave closer to Array
Add the ability to pass block to #find method just like Array#find does.
2011-07-05 10:51:40 +03:00