Commit Graph

5489 Commits

Author SHA1 Message Date
Eric Chahin
eaa3949d36 Changed change_column in PG schema_statements.rb to make sure that the uuid_generate function was not being quoted. 2014-04-15 16:08:04 -04:00
Lauro Caetano
34945e41c2 The Association Relation should use empty? and size from Relation.
968c581ea34b5236af14805e6a77913b1cb36238 have introduced this bug #14744
on Association Relation when the method `empty?` or `size` was called.

Example:
  # Given an author that does have 3 posts, but none of them with the
  # title 'Some Title'
  Author.last.posts.where(title: 'Some Title').size
  # => 3

It was occurring, because the Association Relation had implemented these
methods based on `@association`, this way giving wrong results.

To fix it, was necessary to remove the methods `empty?` and `size` from
Association Relation. It just have to use these methods from Relation.

Example:
  # Given an author that does have 3 posts, but none of them with the
  # title 'Some Title'
  Author.last.posts.where(title: 'Some Title').size
  # => 0
  # Now it will return the correct value.

Fixes #14744.
2014-04-14 22:00:21 -03:00
Rafael Mendonça França
ed6894bf23 Remove outdated comment 2014-04-14 17:09:35 -03:00
Aaron Patterson
a1e2db2e9b Merge pull request #14735 from byroot/idempotent-counter-caches
Idempotent counter caches, fix concurrency issues with counter caches
2014-04-14 10:16:27 -07:00
Lauro Caetano
a16f33045a Just call read_attribute, no need to use send.
Follow up to af549a1ad6692d7e2c756750651f0e1b293f5185
2014-04-14 00:04:08 -03:00
Jean Boussier
dd063f6ef4 Write the failing test case for concurrent counter cache 2014-04-13 12:03:54 -04:00
Lauro Caetano
783982ab2d Ensure that the comparison between 'CollectionProxy' and 'AssociationRelation' is consistent. 2014-04-12 11:00:57 -03:00
Lauro Caetano
24052f925f Make the comparison between 'Relation' and 'AssociationRelation'
consistent.
2014-04-12 11:00:33 -03:00
Lauro Caetano
d6840f914a The comparison between Relation and CollectionProxy should be consistent.
Example:

    author.posts == Post.where(author_id: author.id)
    # => true
      Post.where(author_id: author.id) == author.posts
    # => true

Fixes #13506
2014-04-11 20:06:19 -03:00
Rafael Mendonça França
8d11fbf679 Use assert_not 2014-04-11 15:46:49 -03:00
Rafael Mendonça França
8a08f5cb23 ✂️ 2014-04-11 15:46:04 -03:00
Rafael Mendonça França
d447eef20b Merge pull request #14711 from swoker/activerecord_fix_aggregate_methods_with_select
Activerecord fix aggregate methods with select
2014-04-11 15:13:36 -03:00
Simon Woker
70fffaccfc fix exception on polymorphic associations with predicates 2014-04-11 17:54:03 +00:00
Yves Senn
9f62344d95 PostgreSQL, warn once per connection per missing OID. Closes #14275.
[Yves Senn & Matthew Draper]
2014-04-11 11:07:38 +02:00
Yves Senn
0c9bbc6326 PostgreSQL, adapter automatically reloads it's type map. Closes #14678.
[Yves Senn & Matthew Draper]
2014-04-11 11:07:17 +02:00
Rafael Mendonça França
a7a180bd81 Merge pull request #12829 from iantropov/issue_insert_via_hmt_scope_3548
Fix insertion of records for hmt association with scope

Conflicts:
	activerecord/CHANGELOG.md
2014-04-10 17:44:32 -03:00
Rafael Mendonça França
1938c9646b Remove warning of unused variable 2014-04-10 15:58:08 -03:00
Rafael Mendonça França
085ce4f141 Merge branch 'master' into rm-uuid-fixtures
Conflicts:
	activerecord/CHANGELOG.md
	activesupport/CHANGELOG.md
2014-04-10 15:34:55 -03:00
Simon Woker
afd4d8205e Fix error for aggregate methods with select, see issue #13648 2014-04-10 16:58:39 +00:00
Lauro Caetano
213ef567ae Make sure the reflection test is passing a String to the reflection
cache.
2014-04-09 21:56:40 -03:00
Lauro Caetano
a91e5ff2cb The source option for has_many => through should accept String
values.

With the changes introduced by 16b70fddd4dc7e7fb7be108add88bae6e3c2509b
it was expecting the value to be a Symbol, while it could be also a
String value.
2014-04-09 14:57:30 -03:00
Matthew Draper
d72a0cbc80 Drop in @jeremy's new database.yml template text
In passing, allow multi-word adapters to be referenced in a URL:
underscored_name must become hyphened-name.
2014-04-09 01:46:48 +09:30
Matthew Draper
88cd65b174 Don't deprecate after all 2014-04-09 00:58:44 +09:30
Matthew Draper
615e0dcdf1 Less ambition, more deprecation
The "DATABASE_URL_*" idea was moving in the wrong direction.

Instead, let's deprecate the situation where we end up using
ENV['DATABASE_URL'] at all: the Right Way is to explicitly include it in
database.yml with ERB.
2014-04-09 00:17:13 +09:30
Matthew Draper
8f23c22008 Ensure we correctly and immediately load all ENV entries
.. even when the supplied config made no hint that name was relevant.
2014-04-08 15:15:08 +09:30
Matthew Draper
23692184bb Give a deprecation message even when the lookup fails
If the supplied string doesn't contain a colon, it clearly cannot be a
database URL. They must have intended to do a key lookup, so even though
it failed, give the explanatory deprecation warning, and raise the
exception that lists the known configs.

Conveniently, this also simplifies our logical behaviour: if the string
matches a known configuration, or doesn't contain a colon (and is
therefore clearly not a URL), then we output a deprecation warning, and
behave exactly as we would if it were a symbol.
2014-04-08 15:15:07 +09:30
Rafael Mendonça França
d459f751c9 Test DATABASE_URL has precendance over DATABASE_URL_#{environment} 2014-04-08 15:15:00 +09:30
Rafael Mendonça França
e533826f48 Make sure DEFAULT_URL only override current environment database
configuration
2014-04-08 15:14:58 +09:30
Matthew Draper
2b817cde62 Only apply DATABASE_URL for Rails.env
As we like ENV vars, also support DATABASE_URL_#{env}, for more obscure
use cases.
2014-04-08 15:14:26 +09:30
Godfrey Chan
a5664fe27b Follow up to bbe7fe41 to fix enum leakage across classes.
The original attempt didn't really fix the problem and wasn't testing the
problematic area. This commit corrected those issues in the original commit.

Also removed the private `enum_mapping_for` method. As `defined_enums` is now a
method, this method doesn't provide much value anymore.
2014-04-07 18:52:21 -07:00
Lauro Caetano
6c311e0b75 Build the reverse_order on its proper method.
The reverse_order method was using a flag to control if the order should
be reversed or not. Instead of using this variable just build the reverse order
inside its proper method.

This implementation was leading to an unexpected behavior when using
reverse_order and then applying reorder(nil).

Example:
  Before
    Post.order(:name).reverse_order.reorder(nil)
    # => SELECT "posts".* FROM "posts"   ORDER BY "posts"."id" DESC

  After
    Post.order(:name).reverse_order.reorder(nil)
   # => SELECT "posts".* FROM "posts"
2014-04-07 16:23:34 -03:00
Rafael Mendonça França
6bbbe0b651 Merge pull request #14632 from matthewd/escape_bytea
Use connection-specific bytea escaping
2014-04-07 12:23:29 -05:00
Matthew Draper
c4bdca19a7 Use connection-specific bytea escaping
In our normal usage, it's rare for this to make a difference... but is
more technically correct.

As well as a spec that proves this is a good idea, let's also add a more
sane-looking one that just covers basic to_sql functionality. There
aren't many places where we actually use escape_bytea, but that's one
that won't be going away.
2014-04-08 00:36:30 +09:30
Lauro Caetano
bbad7523f0 Ignore order when doing count.
This is necessary because Postgresql doesn't play nice with ORDER BY and
no GROUP BY.

Fixes #14621.
2014-04-07 11:15:30 -03:00
Evan Whalen
bbe7fe4169 make enums distinct per class 2014-04-07 10:01:03 -04:00
Rafael Mendonça França
8d1c703727 Merge pull request #14579 from senny/pg/remove_string_limit
PostgreSQL, remove varchar limit.

Conflicts:
	activerecord/CHANGELOG.md
2014-04-04 19:51:35 -03:00
Rafael Mendonça França
57c7d5cb80 Fix the test defining the models in the right place 2014-04-04 19:44:17 -03:00
Rafael Mendonça França
e9e5341549 Merge pull request #11650 from prathamesh-sonpatki/rename
Renamed private methods _create_record and _update_record
2014-04-04 18:38:06 -03:00
Rafael Mendonça França
5f1346b0c7 Merge pull request #14562 from jefflai2/collection_proxy
CollectionProxy uses the arel of its association's scope.

Conflicts:
	activerecord/CHANGELOG.md
2014-04-04 13:31:10 -03:00
Rafael Mendonça França
54d8c81fef Merge pull request #12016 from roderickvd/uuid_fixes
Auto-generate stable fixture UUIDs on PostgreSQL

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/lib/active_record/fixtures.rb
	activerecord/test/cases/adapters/postgresql/uuid_test.rb
	activesupport/CHANGELOG.md
2014-04-04 12:52:49 -03:00
Rafael Mendonça França
b9774a5943 Remove unused variable 2014-04-04 09:52:43 -05:00
Yves Senn
80f4a65bbd test, show current adapter behavior for add_column limit: nil.
This is an illustration of https://github.com/rails/rails/pull/13435#issuecomment-33789752
Removing the limit from the PG and SQLite adapter solves the issue.
MySQL is still affected by the issue.
2014-04-04 10:35:26 +02:00
Yves Senn
f4226c3ab6 PostgreSQL and SQLite, remove varchar limit. [Vladimir Sazhin & Toms Mikoss & Yves Senn]
There is no reason for the PG adapter to have a default limit of 255 on :string
columns. See this snippet from the PG docs:

    Tip: There is no performance difference among these three types, apart
    from increased storage space when using the blank-padded type, and a
    few extra CPU cycles to check the length when storing into a
    length-constrained column. While character(n) has performance
    advantages in some other database systems, there is no such advantage
    in PostgreSQL; in fact character(n) is usually the slowest of the
    three because of its additional storage costs. In most situations text
    or character varying should be used instead.
2014-04-04 10:35:26 +02:00
Guo Xiang Tan
20181e4fa9 Prevent state leak in test.
This will allow us to run the tests in random order.
2014-04-03 19:40:30 -07:00
Arthur Neves
815c9deae8
Block a few default Class methods as scope name.
Add tests to make sure scopes cannot be create with names such as:
private, protected, public.
Make sure enum values don't collide with those methods too.
2014-04-03 16:40:01 -04:00
Rafael Mendonça França
ae110ce5d4 Merge pull request #14572 from laurocaetano/with_options_and_scope
Fix error when using `with_options` with lambda.

Conflicts:
	activerecord/CHANGELOG.md
2014-04-03 17:13:24 -03:00
Rafael Mendonça França
7e6630329e Merge pull request #14569 from matthewd/sqlite_relative_deprecated
Revise 'sqlite3:' URL handling for smoother upgrades

Conflicts:
	activerecord/CHANGELOG.md
2014-04-03 11:12:54 -03:00
Lauro Caetano
db5d26c9d7 Fix error when using with_options with lambda.
It was causing error when using `with_options` passing a lambda as its
last argument.

    class User < ActiveRecord::Base
      with_options dependent: :destroy do |assoc|
        assoc.has_many :profiles, -> { where(active: true) }
      end
    end

It was happening because the `option_merger` was taking the last
argument and checking if it was a Hash. This breaks the HasMany usage,
because its last argument can be a Hash or a Proc.

As the behavior described in this test:
https://github.com/rails/rails/blob/master/activesupport/test/option_merger_test.rb#L69
the method will only accept the lambda, this way it will keep the expected behavior. See 9eaa0a34
2014-04-03 10:26:37 -03:00
Rafael Mendonça França
3fafc1cc42 Merge pull request #14570 from matthewd/uri_deprecation_warning
Avoid a spurious deprecation warning for database URLs
2014-04-03 08:21:00 -05:00
Yves Senn
7531404a44 Merge pull request #14561 from tgxworld/refactor_run_without_connection
Add ConnectionHelper to refactor tests.
2014-04-03 10:48:27 +02:00