Commit Graph

9857 Commits

Author SHA1 Message Date
kennyj
8ae73f1146 Fix #10789. Now at last ::Logger doesn't support #silence method . 2013-06-05 17:55:53 +09:00
Aaron Patterson
0434754051 the typecast value should be passed to the serializer. fixes #10830 2013-06-05 17:30:11 +09:00
Aaron Patterson
00ce4b4aa1 adding a test for #10830
Conflicts:
	activerecord/test/cases/adapters/postgresql/bytea_test.rb
2013-06-05 17:15:53 +09:00
Adam Anderson
e4fe4973cf Fixes #10432 add_column not creating array columns in PostgreSQL
When then PostgreSQL visitor was [added](6b7fdf3bf3)
`add_column` was no longer receiving the column options directly. This
caused the options to be lost along the way.
2013-06-04 00:18:59 -04:00
José Valim
75135a9790 Revert "Merge pull request #4490 from EmmanuelOga/master"
This behaviour doesn't actually make sense, the context of
the child should not be affected by the parent. See #10492.

This reverts commit 5f8274efe128ffeec8fa3179460f5167a078f007, reversing
changes made to 81e837e810460d066a2e5fc5a795366ec8ab2313.
2013-06-04 00:33:50 +09:00
Guillermo Iguaran
17a113289d Merge pull request #10825 from arunagw/remove-rake-packagetask-load
No need to load 'rake/packagetask' as it's already in 'rubygems/package_task'
2013-06-02 13:27:34 -07:00
Guillermo Iguaran
bd096d5fb8 Merge pull request #10824 from vipulnsward/wonderful
wonderfull => wonderful
2013-06-02 13:26:54 -07:00
Arun Agrawal
a84a08ecea No need to load 'rake/packagetask' as it's already
in 'rubygems/package_task'
2013-06-02 20:41:21 +02:00
Vipul A M
743ee7b218 wonderfull => wonderful 2013-06-02 23:52:33 +05:30
kennyj
825a212ee2 Remove unnecessary testcase for instance level stored_attributes. 2013-06-02 10:33:36 +09:00
kennyj
6c74825beb Remove instance level serialized_attributes setting was deprecated. 2013-06-02 10:26:04 +09:00
kennyj
0a88c10e54 Remove instance level attr_readonly setting was deprecated. 2013-06-02 10:25:41 +09:00
kennyj
e185ba24c8 Remove behavior that deals with a string as third argument of add_index, because this was deprecated.
Some testcases is failed, so I replaced nil to empty hash in add_reference.
2013-06-02 08:44:31 +09:00
kennyj
5d75579eec Remove #sum with a block was deprecated. 2013-06-01 23:22:12 +09:00
kennyj
f8f30c88ad Remove ActiveSupport::Benchmarkable#silence was deprecated. 2013-06-01 21:23:19 +09:00
Xavier Noria
f2855f6ef1 revises the documentation of ActiveRecord::Relation#find_or_create_by [ci skip]
* Inspect uses double quotes.

* Inspect puts a hash as in #<User ...>.

* Documents the return value, and makes explicit it can be an invalid record.

* Documents the method is not atomic.

* Documents a way to handle UNIQUE contraint violations in the event of a race condition.

* Removes the "Examples" header according to our guidelines.
2013-06-01 10:23:08 +02:00
Xavier Noria
8ac8eb66c1 rewrites AR's reload documentation
* It is no longer true that options are passed to find.

* Documents that ActiveRecord::RecordNotFound may be raised.

* Documents that the reload happens in-place.

* Documents that caches are wiped.

* Documents that the method returns self.

* Documents a couple of use cases.
2013-05-31 13:02:40 +02:00
Pedro Fayolle
1489e4f208 Fix word order in documentation for with_lock 2013-05-30 17:38:55 -03:00
Carlos Antonio da Silva
c2f3efffd9 Merge pull request #10767 from jmondo/master
Use grep instead of select with === in QueryMethods
2013-05-29 05:05:54 -07:00
John Gesimondo
c3ec0dbdd4 use grep over select for consistency and efficiency
pass block directly to grep
2013-05-28 22:15:55 -07:00
Rafael Mendonça França
059e4fb594 Merge pull request #10766 from kylerippey/minor_schema_migration_refactor
Minor refactor of ActiveRecord::SchemaMigration
2013-05-28 09:30:54 -07:00
Rafael Mendonça França
6ecc360d88 Merge pull request #10495 from senny/postgres_test_cleanup
PostgreSQL specific test cleanup
2013-05-28 08:21:18 -07:00
Sunny Ripert
606c09b8db Consistent use of one space only after punctuation 2013-05-28 14:38:02 +02:00
Yves Senn
1c998a7f13 test cleanup, replace define_method and remove_method with stubs. 2013-05-28 09:19:00 +02:00
Yves Senn
aff928bacf implicit_readonly is being removed in favor of calling readonly explicitly 2013-05-27 21:07:39 +02:00
Neeraj Singh
04f00c6217 minor comments cleanup 2013-05-27 14:58:43 -04:00
Yves Senn
95ce5062ca cleanup whitespace in active_record/relation.rb. 2013-05-27 20:54:33 +02:00
Kyle Rippey
aef9a4bfbd Minor refactor of ActiveRecord::SchemaMigration to remove references to Base, override table_exists method, and switch to preferred style for class method definitions. 2013-05-26 15:31:49 -07:00
Neeraj Singh
14f70dfae1 enhanced comments for foreign_key_present? method 2013-05-23 10:59:41 -04:00
Rafael Mendonça França
030d30d64c Merge pull request #10713 from senny/10693_fix_primary_key_option_on_has_many
Fix the `:primary_key` option for `has_many` associations.
2013-05-23 06:58:10 -07:00
Nick Sutterer
7d84c3a2f7 deprecate Validator#setup (to get rid of a respond_to call). validators do their setup in their constructor now. 2013-05-23 10:00:44 -03:00
Yves Senn
ef99c11475 Fix the :primary_key option for has_many associations.
When removing records from a `has_many` association it used
the `primary_key` defined on the association.

Our test suite didn't fail because on all occurences of `:primary_key`,
the specified column was available in both tables. This prevented the
code from raising an exception but it still behaved badly.

I added a test-case to prevent regressions that failed with:

```
  1) Error:
HasManyAssociationsTest#test_has_many_assignment_with_custom_primary_key:
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: essays.first_name: UPDATE "essays" SET "writer_id" = NULL WHERE "essays"."writer_id" = ? AND "essays"."first_name" IS NULL
```
2013-05-23 07:38:33 +02:00
Rafael Mendonça França
30d28b1958 Add CHANGELOG entry for 99860582b2b1c0fc42bf84c52aac57b243d42678 2013-05-22 14:41:46 -03:00
Takehiro Adachi
805bad746e Refactor AR's counter_cache_test.rb test 2013-05-23 01:28:04 +09:00
Takehiro Adachi
60c839cb1a Add test for AR::CounterCache.update_counters 2013-05-23 01:28:00 +09:00
Neeraj Singh
d226929e5c remove code duplication 2013-05-22 08:47:48 -04:00
Carlos Antonio da Silva
b9bbc7f81a Merge pull request #10714 from tkhr/extract_test_from_base_test.rb_in_AR
Extract tests code out from AR's base_test.rb
2013-05-22 05:41:21 -07:00
Takehiro Adachi
5e3de2f50d Extract AR::Persistence#becomes's test code out from base_test.rb
The method got extracted out from AR::Base in commit
d916c62cfc7c59ab6411407a05b946d3dd7535e9, but the tests never did.
2013-05-22 12:30:35 +09:00
Aaron Patterson
d6d6376779 reverse comparison because of strange AS behavior
http://tenderlovemaking.com/2013/05/21/one-danger-of-freedom-patches.html
2013-05-21 20:16:21 -07:00
Aaron Patterson
26fd5f0cd5 just set the default argument, a nil parent should be an error 2013-05-21 20:13:29 -07:00
Aaron Patterson
220f1a0cfb fold the collection rather than multiple assigments 2013-05-21 20:06:42 -07:00
Aaron Patterson
d440fa07dc use drop rather than calculate the array length 2013-05-21 14:19:28 -07:00
Aaron Patterson
ac70ec6413 Merge branch 'bindwhere'
* bindwhere:
  avoid creating a set if no where values are removed
  remove bind values for where clauses that were removed
  push partitioning up so bind elimination can get the removed wheres
  push partion logic down and initialization logic up
  partition the where values so we can access the removed ones
2013-05-21 11:01:25 -07:00
Aaron Patterson
f3ebbeae6e avoid creating a set if no where values are removed 2013-05-21 11:01:19 -07:00
Aaron Patterson
50823452f7 remove bind values for where clauses that were removed 2013-05-21 10:55:56 -07:00
Aaron Patterson
d2d5f15f07 push partitioning up so bind elimination can get the removed wheres 2013-05-21 10:38:51 -07:00
Aaron Patterson
a483ae6477 push partion logic down and initialization logic up 2013-05-21 10:35:35 -07:00
Takehiro Adachi
43168bd1a1 Extract AR::AttributeMethods#attribute_for_inspect's test code out from base_test.rb
The method itself got extracted out from ActiveRecored::Base in commit
ceb33f84933639d3b61aac62e5e71fd087ab65ed, but the test code never did.
2013-05-22 02:32:37 +09:00
Takehiro Adachi
24f0099ec3 Extract AR::Core#inspect and AR::Core.inspect's test code from base_test.rb
The methods got moved to core.rb in commit
b2c9ce341a1c907041f55461aefebb0321280cb5, but the tests never did.
2013-05-22 02:24:37 +09:00
Rafael Mendonça França
f47b4236e0 Merge pull request #10711 from senny/10660_rake_db_test_prepare_needs_config
the rake task `db:test:prepare` needs to load the configuration
2013-05-21 07:13:13 -07:00
Yves Senn
78903731e4 the rake task db:test:prepare needs to load the configuration
Without loading the configuration the task will not perform any work.
2013-05-21 15:47:57 +02:00
Alexander Balashov
4a4a566b12 In batches test @total was assigned but not used. Use it in tests instead of Post.count 2013-05-21 12:26:13 +04:00
Michael Kozono
928a58b2b8 update_counters accepts a hash, not an array of hashes 2013-05-21 00:32:34 -06:00
Aaron Patterson
847752a295 partition the where values so we can access the removed ones 2013-05-20 18:02:46 -07:00
Aaron Patterson
bff89a2022 eliminate some conditionals 2013-05-20 17:49:16 -07:00
Aaron Patterson
52ed881fa2 change method name to reflect what it actually does. 2013-05-20 17:39:29 -07:00
Aaron Patterson
3f4f56aed8 save the where values in variables so we don't need to look them up all
the time
2013-05-20 17:38:05 -07:00
Aaron Patterson
658e9e0f35 pass where values to the helper function rather than rely on internal state 2013-05-20 17:35:17 -07:00
José Valim
6c2fc9a5c7 Merge pull request #10692 from vipulnsward/fix_test_3
Fix wrong `case_sensitive` in uniqueness validity test
2013-05-19 22:23:22 -07:00
Vipul A M
2243ce3c97 Fix wrong case_sensitive in uniqueness validity test 2013-05-20 10:40:05 +05:30
Vipul A M
4237d74213 Fix typo in test name and documentation 2013-05-20 10:35:43 +05:30
Vijay Dev
d71b0935a9 Merge branch 'master' of github.com:lifo/docrails 2013-05-19 21:40:12 +05:30
Vijay Dev
7f24d3d695 copy edits[ci skip] 2013-05-19 21:38:23 +05:30
Prathamesh Sonpatki
f8a3dda6ce Fxied some typos 2013-05-18 19:23:30 +05:30
Rafael Mendonça França
056acbd0c6 Merge pull request #10676 from tkhr/add-test-to-counter_cache_test.rb
Add test to counter cache test.rb
2013-05-18 05:58:57 -07:00
Takehiro Adachi
2dbb346ffe Fix tests which started to fail due to commit 0123c39f41e2062311b2197e6e230ef8ad67e20e
Due to commit 0123c39f41e2062311b2197e6e230ef8ad67e20e, column
topic.unique_replies_count has been added, and these test started to
fail since the tests depends on the topic tables column info.
2013-05-18 18:22:21 +09:00
Takehiro Adachi
0123c39f41 Add test to AR's counter_cache_test.rb
According to
https://github.com/rails/rails/blob/b601399b72ab56cc01368f02615af99f45d1
4f02/activerecord/lib/active_record/counter_cache.rb#L14, u can pass
more then one association to the `reset_counters` method.
2013-05-18 17:12:46 +09:00
Aaron Patterson
1ff5341385 stop swallowing exceptions in assert_queries. Methods that raise an
exception are unlikely to pass this assertion, but since the assertions
raise an exception, the original exception is lost.
2013-05-17 20:46:41 -07:00
Aaron Patterson
18fe96cc16 stop doing assingments in an iterator 2013-05-17 15:39:39 -07:00
Aaron Patterson
2eecc0d8dc include bind values from the default scope 2013-05-17 14:59:48 -07:00
Aaron Patterson
6062e42f98 let Ruby do the is_a check for us 2013-05-16 16:06:52 -07:00
Aaron Patterson
28574961fb test refactor 2013-05-16 13:33:35 -07:00
Bogdan Gusiev
711097e6a5 Add more data to AR::UnknownAttributeError
begin
  Topic.new("hello" => "world")
rescue ActiveRecord::UnknownAttributeError => e
  e.record # => #<Topic ... >
  e.attribute # => "hello"
end
2013-05-16 13:31:35 -07:00
Aaron Patterson
7816b9852b Merge pull request #10619 from alno/top_level_array_in_postgres_json
Support array as root element in Postgresql JSON columns
2013-05-16 11:38:24 -07:00
Piotr Sarnacki
89f558c8c6 Check if APP_RAKEFILE is defined 2013-05-16 15:52:12 +02:00
Joel Cogen
2583e8ade8 Fix detection of engine in rake db:load_config
Broken by d1d7c86d0c8dcb7e75a87644b330c4e9e7d6c1c1
2013-05-16 12:06:08 +02:00
Aaron Patterson
99860582b2 tiny types should only be integers when the length is <= 1. fixes #10620 2013-05-15 18:03:10 -07:00
phinze
09a16ef178 add failing test exposing mysql adapter tinyint bug
in myself, a column with type TINYINT(N) where N > 1 can be used to
represent an integer, but the rails mysql adapter refuses to interpret
as anything but a boolean.
2013-05-15 17:50:55 -07:00
Aaron Patterson
dcc1267fee require things we need 2013-05-15 10:14:37 -07:00
Rafael Mendonça França
f22dbc62bd Merge pull request #10504 from kennyj/support_pg_91
Also should supports PostgreSQL 9.1 about extensions.
2013-05-15 10:14:04 -07:00
Rafael Mendonça França
5db56659f3 Merge pull request #10601 from Ichimonji10/fix-docs
Rewrite  `activerecord/RUNNING_UNIT_TESTS.rdoc`
2013-05-15 08:30:32 -07:00
Jeremy Audet
87ac19ebbe Rewrite activerecord/RUNNING_UNIT_TESTS
`RUNNING_UNIT_TESTS` is written in an unclear and confusing manner. This commit
attempts to correct that.

Thanks to zzak and vipulnsward for feedback.
2013-05-15 11:07:47 -04:00
aditya-kapoor
90e60aa469 Added some more documentation for define_readers and define_writer of the Association and its inherited classes 2013-05-15 15:31:53 +05:30
aditya-kapoor
da8fff528d Added some more documentation for ActiveRecord::Associations::Builder::Association class 2013-05-15 15:07:55 +05:30
aditya-kapoor
0fbf31b200 Added documentation for ActiveRecord::Associations::Builder::Association class 2013-05-15 12:28:08 +05:30
kennyj
91c4d0b1e7 Remove unnecessary code, because this extension is created on demand in hstore_test.rb. 2013-05-15 12:47:49 +09:00
kennyj
349fc90996 Also support extensions in PostgreSQL 9.1, because this has been supported since 9.1. 2013-05-15 12:46:54 +09:00
Aaron Patterson
ba55276434 deprecating string based terminators 2013-05-14 16:03:09 -07:00
Alexey Noskov
9b66187622 Support array as root element in JSON 2013-05-14 17:44:32 +04:00
Anton Kalyaev
ddf07d2183 improved doc for ActiveRecord#find_by_sql method (Refs #10599) [ci skip] 2013-05-14 10:16:56 +04:00
aditya-kapoor
87d71b02b8 Added documentation for model migration generation 2013-05-14 00:27:52 +05:30
Aaron Patterson
d53b5f0739 Merge branch 'master' into normalizecb
* master: (61 commits)
  add tests for reset_calbacks
  Fixing build broken by this change
  Extract variable out of loop
  Updated comment to Rails 4
  Fixes NoMethodError: `alias_method_chain` when requiring just active_support/core_ext
  better error message when app name is not passed in `rails new`
  Code cleanup for ActionDispatch::Flash#call
  Fix typo: require -> requires
  Add CHANGELOG entry for #10576
  Merge pull request #10556 from Empact/deprecate-schema-statements-distinct
  Some editorial changes on the documentation.
  respond_to -> respond to in a message from AM::Lint
  specify that dom_(id|class) are deprecated in controllers, views are fine
  copy edits [ci skip]
  Fix class and method name typos
  Replace multi_json with json
  ruby -> Ruby
  Adding documentation to the automatic inverse_of finder.
  Improve CHANGELOG entry [ci kip]
  Call assume_migrated_upto_version on connection
  ...

Conflicts:
	activesupport/lib/active_support/callbacks.rb
2013-05-13 11:51:10 -07:00
Neeraj Singh
7b24cf0391 emphasize that callbacks are called in destroy_all
Cleaned up rdoc a bit emphasizing that callbacks are called. Also
removed the stress on the fact that records are always removed.

If callbacks return false then records will not be deleted.
2013-05-13 11:39:09 -04:00
Rafael Mendonça França
2519fb0e6d Merge pull request #10577 from vipulnsward/fix_method_typos
Fix class and method name typos
2013-05-12 11:29:17 -07:00
Rafael Mendonça França
8d3c67fbc4 Merge pull request #10556 from Empact/deprecate-schema-statements-distinct
Deprecate SchemaStatements#distinct, and make SchemaStatements#columns_for_distinct nodoc.
Conflicts:
	activerecord/CHANGELOG.md
2013-05-12 14:50:28 -03:00
Rafael Mendonça França
33062ee0f1 Some editorial changes on the documentation.
* Remove some autolinks
* Fix the rendered result
* Change sql to SQL

[ci skip]
2013-05-12 14:48:11 -03:00
Vijay Dev
d8b8c0ef87 Merge branch 'master' of github.com:lifo/docrails
Conflicts:
	activesupport/lib/active_support/callbacks.rb
2013-05-12 15:57:14 +05:30
Vijay Dev
1a9766f128 copy edits [ci skip] 2013-05-12 15:52:09 +05:30
Vipul A M
7493e0f78a Fix class and method name typos 2013-05-12 15:03:14 +05:30
wangjohn
346cda4f34 Adding documentation to the automatic inverse_of finder. 2013-05-11 23:05:36 -04:00
Rafael Mendonça França
d9e8ec61a4 Improve CHANGELOG entry [ci kip] 2013-05-11 23:51:27 -03:00
Kyle Stevens
443f8dd5cd Call assume_migrated_upto_version on connection
Call assume_migrated_upto_version on connection to prevent it from first
being picked up in method_missing. In the base class, Migration,
method_missing expects the argument to be a table name, and calls
proper_table_name on the arguments before sending to connection. If
table_name_prefix or table_name_suffix is used, the schema version changes
to prefix_version_suffix, breaking `rake test:prepare`.

Fixes #10411.
2013-05-11 22:39:39 -04:00
Rafael Mendonça França
51157c9b46 Merge pull request #10567 from neerajdotname/read_attribute_before_type_cast_should_accept_symbol
read_attribute_before_type_cast should accept symbol
2013-05-11 14:36:06 -07:00
Rafael Mendonça França
0215faf472 Merge pull request #10572 from nertzy/dont-modify-options-hash-in-primary-key
Don't modify args in TableDefinition#primary_key
2013-05-11 16:52:33 -03:00
Neeraj Singh
3e0c06d8ab read_attribute_before_type_cast should accept symbol 2013-05-11 03:12:38 -04:00
Ben Woosley
118147af53 Rather than raising ThrowResult when construct_limited_ids_conditions comes up empty, set the relation to NullRelation and rely on its results.
This will help avoid errors like 2fcafee250ee2, because in most cases NullRelation will do the right thing. Minor bonus is avoiding the use of exceptions for flow control.
2013-05-10 21:11:03 +02:00
Ben Woosley
a2e607e105 Make NullRelation a bit more like a real relation by returning 0 for #calculate(:count) 2013-05-10 20:45:09 +02:00
Ben Woosley
86cc141ed5 No point in memoizing a simple literal string. 2013-05-10 20:35:59 +02:00
Ben Woosley
48783ee7fc Add coverage for the fact that pluck without an argument returns all the table's columns. 2013-05-10 19:33:34 +02:00
Ben Woosley
2fcafee250 Fix that #pluck wasn't rescuing ThrowResult, meaning it would blow up when failing to construct_limited_ids_condition. 2013-05-10 19:27:12 +02:00
Aaron Patterson
23122ab2d4 callbacks are wrapped with lambdas 2013-05-10 10:13:21 -07:00
Ben Woosley
fba18f1994 Extract JoinDependency#join_relation to DRY the repeated application of the #join_associations. 2013-05-10 17:46:04 +02:00
Ben Woosley
35c198ca9b In #apply_join_dependency, we can apply the #where in-place because relation is always a new object.
Thanks to the #except we call at the top of the method.
2013-05-10 17:46:04 +02:00
Ben Woosley
75fe7434a8 DRY-up join dependency creation by extracting construct_join_depdency 2013-05-10 17:46:04 +02:00
Ben Woosley
88219cc88a Pull the excepts into apply_join_dependency, for the sake of DRY. 2013-05-10 17:46:04 +02:00
Ben Woosley
1dcb1ccc9d Simplify conditions within apply_join_dependency 2013-05-10 17:46:04 +02:00
Ben Woosley
cd04a99ba4 Move the except(:select) inside the construct_limited_ids_condition method to pair it closely with its motivation. 2013-05-10 17:46:04 +02:00
Ben Woosley
ec75ff3451 Reject blank order_values within #columns_for_distinct, as the orders aren't used at all on non-postgres adapters. 2013-05-10 17:45:38 +02:00
Jon Leighton
32a5cad1e4 Move #proxy_association method to AssociationRelation 2013-05-10 16:39:27 +02:00
Jon Leighton
1b022990c7 Merge pull request #6792 from Empact/postgres-distinct
Fix that #exists? can produce invalid SQL: "SELECT DISTINCT DISTINCT"
2013-05-10 07:36:11 -07:00
Daniel Schierbeck
1cc63e94db Don't try to EXPLAIN select_db calls 2013-05-10 16:21:59 +02:00
Ben Woosley
15d6e4dce7 Fix that #exists? can produce invalid SQL: "SELECT DISTINCT DISTINCT"
The combination of a :uniq => true association and the #distinct call
in #construct_limited_ids_condition combine to create invalid SQL, because
we're explicitly selecting DISTINCT, and also sending #distinct on to AREL,
via the relation#distinct_value.

Rather than build a select distinct clause in #construct_limited_ids_condition,
I set #distinct! and pass just the columns into the select statement.
This requires introducing a #columns_for_distinct method to return the
select columns but not the statement itself.
2013-05-10 16:13:46 +02:00
Jon Leighton
d7abe91cc7 Set the inverse when association queries are refined
Suppose Man has_many interests, and inverse_of is used.

Man.first.interests.first.man will correctly execute two queries,
avoiding the need for a third query when Interest#man is called. This is
because CollectionAssociation#first calls set_inverse_instance.

However Man.first.interests.where("1=1").first.man will execute three
queries, even though this is obviously a subset of the records in the
association.

This is because calling where("1=1") spawns a new Relation object from
the CollectionProxy object, and the Relation has no knowledge of the
association, so it cannot set the inverse instance.

This commit solves the problem by making relations spawned from
CollectionProxies return a new Relation subclass called
AssociationRelation, which does know about associations. Records loaded
from this class will get the inverse instance set properly.

Fixes #5717.

Live commit from La Conf! 
2013-05-10 10:36:26 +02:00
aditya-kapoor
ff34afc202 Added documentation for ActiveRecord::Generators::MigrationGenerator.next_migration_number 2013-05-10 00:03:29 +05:30
aditya-kapoor
fe7cf89193 Added documentation for ActiveRecord::Base#next_migration_number 2013-05-09 23:50:05 +05:30
Neeraj Singh
d9490631d2 minor rdoc cleanup for reflection methods 2013-05-09 02:06:03 -04:00
Neeraj Singh
fdba949b47 extracted piece of code into a method
In order to fix #10421 I need to enable merge to take an option
so that relations could be merged without making the last where
condition to win.

That fix would forever reside in 4-0-stable branch and would not be
merged to master since using scope without lambda has been deprecated.

In this commit I have extracted code into a method and I think it
makes code look better. Hence the request to merge it in both
master and 4-0-stable.

If there is any concern then this code can be merged only in
4-0-stable and that would be fine too.
2013-05-08 15:21:52 -04:00
Rafael Mendonça França
d4de2c34c5 Merge pull request #10521 from yahonda/sanitize_oracle
Remove current_adapter? from test_sanitize_sql_hash_handles_associations
2013-05-08 10:44:16 -07:00
Yves Senn
7c694165f9 cleanup, assert on warning from postgres adapter 2013-05-08 07:30:09 +02:00
Yves Senn
99433fd86d cleanup, switch arguments in assert_equal calls 2013-05-08 07:28:11 +02:00
Prathamesh Sonpatki
b5429eec60 Fix Typo existant -> existent [ci skip] 2013-05-08 09:50:46 +05:30
wangjohn
26d19b4661 Created a method to automatically find inverse associations and cache
the results. Added tests to check to make sure that inverse associations are
automatically found when has_many, has_one, or belongs_to associations
are defined.
2013-05-07 23:24:43 -04:00
Yasuo Honda
798cf2b9ef Remove current_adapter? from test_sanitize_sql_hash_handles_associations
Because of each adapter implementation differences,
`expected_value` string needed to be handled by each adapter.
This commit removes current_adapter
by using ActiveRecord::ConnectionAdapters::Quoting methods.
2013-05-08 06:40:15 +09:00
Aaron Patterson
2b5e4f7f98 Revert "Merge pull request #10455 from patricksrobertson/bigserial_id_not_identifying_pk"
This reverts commit 3043d45eefc3776d5f3a9e7d212a01f99d869ef8, reversing
changes made to ca0275d36b395631725c4583db5a45c06443fdb9.
2013-05-07 10:39:41 -07:00
Patrick Robertson
0e00c6b296 Handle other pk types in PostgreSQL gracefully.
In #10410 it was noted that you can no longer create PK's with the
type of bigserial in PostgreSQL in 4.0.0.rc1. This is mostly
because the newer adapter is checking for column type with the
id column instead of just letting it pass through like it did
before.

Side effects:
You may just create a PK column of a type that you really don't
want to be your PK. As far as I can tell this was allowed in 3.2.X
and perhaps an exception should be raised if you try and do
something extremely dumb.
2013-05-07 08:21:41 -04:00
Rafael Mendonça França
17c1143af9 Improve CHANGELOG entry [ci skip] 2013-05-06 22:22:43 -03:00
Rafael Mendonça França
19d32e89af Merge pull request #10489 from greenriver/ar_counter_cache_multiple_destroy
Confirm a record has not already been destroyed before decrementing counter cache

Conflicts:
	activerecord/CHANGELOG.md
2013-05-06 22:22:07 -03:00
Ben Tucker
228720ef19 Confirm a record has not already been destroyed before decrementing
counter cache

At present, calling destroy multiple times on the same record results
in the belongs_to counter cache being decremented multiple times. With
this change the record is checked for whether it is already destroyed
prior to decrementing the counter cache.
2013-05-06 21:09:14 -04:00
Rafael Mendonça França
0f97ac6647 Fix test asserting the sanitized SQL hash differently to some adapters 2013-05-06 22:02:34 -03:00
Waynn Lue
54644f2e78 XML-files isn't a word 2013-05-06 17:22:18 -07:00
Rafael Mendonça França
9073400253 Merge pull request #10352 from zohlgren/fix_activerecord_sanitization_sanitize_sql_hash
Fix bug in ActiveRecord::Sanitization#sanitize_sql_hash_for_conditions
2013-05-06 17:05:20 -07:00
Zach Ohlgren
a6bc35c82c Fix bug in ActiveRecord::Sanitization#sanitize_sql_hash_for_conditions
Fixing CHANGLOG description

Remove extra line.

Remove blank lines.
2013-05-06 17:03:18 -07:00
Neeraj Singh
86ac1d9bb2 fix failing test caused by 3771e4d511 2013-05-06 16:49:06 -04:00
Neeraj Singh
3771e4d511 raise IrreversibleMigration if no column given
fixes #10419

Following code should raise  IrreversibleMigration. But the code was
failing since options is an array and not a hash.

def change
  change_table :users do |t|
    t.remove_index [:name, :email]
  end
end

Fix was to check if the options is a Hash before operating on it.
2013-05-06 15:16:42 -04:00
Akshay Khole
b79c1314a9 fix to remove warning on postgres adapter test.
Warning was: "/vagrant/rails/activerecord/test/cases/adapters/postgresql/uuid_test.rb:63:
warning: ambiguous first argument; put parentheses or even spaces"
2013-05-05 00:54:45 +05:30
Akshay Khole
20549051f8 Changing method call according to coding conventions 2013-05-05 00:25:22 +05:30
Rafael Mendonça França
903a2c2d33 Merge pull request #10458 from bwbuchanan/issue-10451
Make SchemaDumper emit "id: :uuid" when using UUID primary keys
2013-05-04 05:49:59 -07:00
Brian Buchanan
fa87e3166f Make SchemaDumper emit "id: :uuid" when appropriate. Fixes #10451. 2013-05-03 16:05:55 -07:00
Aaron Patterson
4c242e6d33 Squashed commit of the following:
commit 2683de5da85135e8d9fe48593ff6167db9d64b18
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Fri May 3 11:29:20 2013 -0700

    cannot support infinite ranges right now

commit cebb6acef2c3957f975f6db4afd849e535126253
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Fri May 3 11:26:12 2013 -0700

    reverting infinity comparison

commit 385f7e6b4efd1bf9b89e8d607fcb13e5b03737ea
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Fri May 3 11:23:28 2013 -0700

    Revert "Added ability to compare date/time with infinity"

    This reverts commit 38f28dca3aa16efd6cc3af6453f2e6b9e9655ec1.

    Conflicts:
    	activesupport/CHANGELOG.md
    	activesupport/lib/active_support/core_ext/numeric/infinite_comparable.rb
    	activesupport/test/core_ext/date_ext_test.rb
    	activesupport/test/core_ext/date_time_ext_test.rb
    	activesupport/test/core_ext/numeric_ext_test.rb
    	activesupport/test/core_ext/time_ext_test.rb
    	activesupport/test/core_ext/time_with_zone_test.rb

commit 0d799a188dc12b18267fc8421675729917610047
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Fri May 3 11:18:53 2013 -0700

    Revert "Refactor infinite comparable definition a bit"

    This reverts commit dd3360e05e4909f2f0c74a624cccc2def688f828.

commit 42dec90e49745bbfae546f0560b8783f6b48b074
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Fri May 3 11:18:47 2013 -0700

    Revert "Require 'active_support/core_ext/module/aliasing' in the infinite_comparable module"

    This reverts commit 7003e71c13c53ec3d34250560fbf80b8381df693.
2013-05-03 11:29:35 -07:00
Olek Janiszewski
534030cf83 Do not overwrite manually built records during one-to-one nested attribute assignment
For one-to-one nested associations, if you build the new (in-memory)
child object yourself before assignment, then the NestedAttributes
module will not overwrite it, e.g.:

    class Member < ActiveRecord::Base
      has_one :avatar
      accepts_nested_attributes_for :avatar

      def avatar
        super || build_avatar(width: 200)
      end
    end

    member = Member.new
    member.avatar_attributes = {icon: 'sad'}
    member.avatar.width # => 200
2013-05-03 16:18:37 +02:00
Jon Leighton
6023a50491 Merge pull request #10417 from jholton/fix_association_auto_save
autosave_association issue that occurs when table has unique index (resubmission)
2013-05-03 05:13:14 -07:00
Jon Leighton
66982772b7 Fix broken mysql test
test_mysql_integer_not_null_defaults in test/cases/defaults_test.rb was
failing. This test relies on the connection being in strict mode. By
default a new connection is not in strict mode, but Active Record
automatically places it in strict mode.

ActiveSchemaTest overwrites the connection's #execute method in order to
prevent SQL statements from actually being executed. One of the
operations which is performed in ActiveSchema test is a #recreate_database.

Since 2088bf27981137a2c6c8b2f718f33b417b4045af, recreate_database on
mysql or mysql2 will trigger a reconnect.

Due to the implementation of the hacking of #execute in
ActiveSchemaTest, this reconnect would take place, but the connection
would *not* be placed in strict mode because #execute had been
overridden to prevent SQL queries hitting the database.

Therefore, after ActiveSchemaTest, the connection would no longer be in
strict mode, causing test_mysql_integer_not_null_defaults to fail.

I don't think that the way that ActiveSchemaTest is implemented is
particularly nice or clean, but I have taken steps to make its hacks
more isolated - it now create a separate connection object which is
thrown away after the test, and the hacks are applied on the singleton
class of this object.
2013-05-03 11:36:02 +01:00
Neeraj Singh
b46e6416dc added to rdoc for unscope that default_scope wins 2013-05-03 01:00:43 -04:00
Rafael Mendonça França
efaecadaf9 Merge pull request #10424 from markevich/fix_test_prepare
Restore ActiveRecord connection to original environment after rake:db:test:prepare task.
2013-05-02 14:27:47 -07:00
Lars Kanis
950ef05585 Add parameter :sslcompression to PostgreSQL adapter.
It is new in PostgreSQL-9.2 .
2013-05-02 22:28:33 +02:00
markevich
56445c9075 rake:db:test:prepare falls back to original environment after execution. 2013-05-02 18:09:59 +03:00
Takehiro Adachi
ec0566cc91 Add test for AR::Base#to_param
According to the doc of `AR::Base#to_param`(
https://github.com/rails/rails/blob/04cda1848cb847c2bdad0bfc12160dc8d554
7775/activerecord/lib/active_record/integration.rb#L18 ), it returns
`nil` if the record is not persisted.
2013-05-02 22:16:51 +09:00
Johnny Holton
483c301e0a 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-05-02 03:27:06 -04:00
Carlos Antonio da Silva
730408fee2 Merge pull request #10396 from tkhr/extract-test-code-from-base_test.rb
Extract tests code out from AR's base_test.rb to integration_test.rb
2013-05-01 19:12:20 -07:00
Takehiro Adachi
a160c88172 Extract tests code out from AR's base_test.rb to integration_test.rb
`AR::Base#to_param` and `AR::Base#cache_key` is defined at
active_record/integration.rb, so tests for those methods should be at
integration_test.rb
2013-05-02 11:01:12 +09:00
Aaron Patterson
dd1f36078e Merge pull request #7839 from chancancode/handle_aliased_attributes_in_ar_relation
Handle aliased attributes in AR::Relation
2013-05-01 17:59:24 -07:00
Carlos Antonio da Silva
14a75a54a8 Improve docs for postgresql with uuid primary keys [ci skip]
Introduced in 09ac1776abc0d3482f491f2d49f47bcb3d9a4ad7.
2013-05-01 21:24:56 -03:00
Godfrey Chan
54122067ac Handle aliased attributes in ActiveRecord::Relation.
When using symbol keys, ActiveRecord will now translate aliased attribute names to the actual column name used in the database:

With the model

  class Topic
    alias_attribute :heading, :title
  end

The call

  Topic.where(heading: 'The First Topic')

should yield the same result as

  Topic.where(title: 'The First Topic')

This also applies to ActiveRecord::Relation::Calculations calls such as `Model.sum(:aliased)` and `Model.pluck(:aliased)`.

This will not work with SQL fragment strings like `Model.sum('DISTINCT aliased')`.

Github #7839

*Godfrey Chan*
2013-05-01 16:36:01 -07:00
Chad Moone
55c40c0ece allow override of uuid_generate_v4() default by passing default: nil
without this, it's not possible to use UUID primary keys without uuid-ossp installed and activated
2013-05-01 19:07:17 -04:00
Vijay Dev
7ead1d8143 Merge branch 'master' of github.com:lifo/docrails 2013-05-01 16:24:13 +05:30
Aaron Patterson
78db16d440 maintain return value for recreate_database 2013-04-30 18:38:57 -07:00
Godfrey Chan
2496bd9a98 Mute psql output when running rake db:schema:load 2013-04-30 17:24:29 -07:00
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
Rafael Mendonça França
2d03a7edd9 Merge pull request #10390 from Noemj/bind_param_handling
Added :nodoc: for relation.rb's private methods
2013-04-30 13:40:50 -07:00
Noemj
e2a58b2921 Added :nodoc: for private methods 2013-04-30 23:36:46 +03:00
Aaron Patterson
2088bf2798 mysql needs to reconnect after recreate. Thanks @mperham 2013-04-30 11:21:15 -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
Noemj
9693df61f0 Moved update_record logic to relation.rb 2013-04-30 14:27:18 +03:00
Francesco Rodriguez
1dee54442f add missing :nodoc: marks to ActiveRecord::Delegation [ci skip] 2013-04-29 20:32:13 -05:00
Rafael Mendonça França
feb44b9213 rails/master is now 4.1.0.beta 2013-04-29 13:15:24 -03:00
David Heinemeier Hansson
1ec64297f9 Bump version to rc1 2013-04-29 08:29:18 -07:00
Rafael Mendonça França
9848e8916f Bump activerecord-deprecated_finders. Fixes #10304 2013-04-29 12:03:14 -03:00
Jeremy Kemper
a91bde349f Merge pull request #10372 from jeremy/statement-invalid-wraps-underlying-exception
StatementInvalid takes WrappedDatabaseException's place
2013-04-28 21:12:14 -07:00
Jeremy Kemper
60bb1333c6 StatementInvalid takes WrappedDatabaseException's place 2013-04-28 20:59:30 -07: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
Xavier Noria
d495606168 ActiveRecord -> Active Record 2013-04-25 19:58:23 +02:00
Xavier Noria
288b56f550 fixes warning in the AR test suite 2013-04-25 19:31:07 +02:00
Carlos Antonio da Silva
8aafb3d33d Review DatabaseTasks docs [ci skip] 2013-04-24 20:52:02 -03:00
Rafael Mendonça França
3e067c07fc Merge pull request #10333 from ikataitsev/move-test-method-to-tests
Move method used only in the test to the test code itself
2013-04-24 16:39:56 -07:00
Carlos Antonio da Silva
e691272628 Minor AR changelog review [ci skip] 2013-04-24 20:32:52 -03:00
Ivan Kataitsev
df0cb9e34c Move method used only in the test to the test code itself 2013-04-25 01:43:28 +04:00
Piotr Sarnacki
a64894dac8 Merge branch 'active-record-standalone-improvements' 2013-04-24 21:41:08 +02:00
Piotr Sarnacki
1dac2edb01 Use env == 'development' instead of env.development?
It's simpler to assume that passed env is just a string without any
extensions, especially when DatabaseTasks are intended to be used also
without rails.
2013-04-24 21:37:11 +02:00
Piotr Sarnacki
b5ae43a436 Move CHANGELOG entry for db.rake improvements to 4.0.0 2013-04-24 21:05:43 +02:00
Piotr Sarnacki
20f1495af8 Don't require Rails.env in order to use AR::Tasks::DatabaseTasks 2013-04-24 20:59:39 +02:00
Piotr Sarnacki
414ab0c4f4 Add some documentation to ActiveRecord::Tasks::DatabaseTasks
This is a public class, which could be used directly in order to allow
easier database management. Now it also contains settings, which will be
used by databases.rake.
2013-04-24 20:58:29 +02:00
Piotr Sarnacki
4522761c0a Use DatabaseTasks.fixtures_path instead of FIXTURES_PATH in db.rake
This will allow to set fixtures path in global config easier, it should
be not needed to use FIXTURES_PATH every time user wants to load
fixtures.
2013-04-24 20:57:26 +02:00
kennyj
8c8d34fa55 Added testcase for #10067 and a CHANGELOG entry about this change. 2013-04-25 03:01:19 +09:00
Dan Erikson
5bdd76fc3b Fix a SystemStackError that occurs when using time zone aware attributes.
This fixes issue #10066
2013-04-25 03:01:19 +09:00
Neeraj Singh
44ea48efc3 Remove code duplication 2013-04-24 13:18:23 -04:00
Andrew White
2a89941225 Lookup the class at runtime, not when the association is built
Trying to lookup the parent class when the association is being built
runs the risk of generating uninitialized constant errors because
classes haven't been fully defined yet. To work around this we look up
the class at runtime through the `association` method.

Fixes #10197.
2013-04-24 15:07:39 +01:00