Commit Graph

4375 Commits

Author SHA1 Message Date
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
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
Dmitry Lavrov
1f432c5465 Treat blank UUID values as nil 2014-04-03 10:41:24 +02:00
Guo Xiang Tan
f1169d9d25 Add ConnectionHelper to refactor tests. 2014-04-03 01:06:43 -07:00
Jefferson Lai
1b187caaa1 CollectionProxy uses the arel of its association's scope.
CollectionProxy should be able to reuse the behavior (methods) of its parent class,
but with its own state. This change allows CollectionProxy to use the arel object
corresponding to its association's scope.
2014-04-02 13:43:26 -07:00
Matthew Draper
88e60a48ec Avoid a spurious deprecation warning for database URLs
This is all about the case where we have a `DATABASE_URL`, and we have a
`database.yml` present, but the latter doesn't contain the key we're
looking for.

If the key is a symbol, we'll always connect to `DATABASE_URL`, per the
new behaviour in 283a2edec2f8ccdf90fb58025608f02a63948fa0.

If the key is a string, on the other hand, it should always be a URL:
the ability to specify a name not present in `database.yml` is new in
this version of Rails, and that ability does not stretch to the
deprecated use of a string in place of a symbol.

Uncovered by @guilleiguaran while investigating #14495 -- this actually
may be related to the original report, but we don't have enough info to
confirm.
2014-04-03 06:16:03 +10:30
Matthew Draper
0a99fddc14 Complete change of sqlite3:/// path handling
That which was now relative is now absolute.
2014-04-03 01:41:34 +10:30
Matthew Draper
f846828dae Revise 'sqlite3:' URL handling for smoother upgrades
Restore the 4.0 behaviour for 'sqlite3:///', but deprecate it. We'll
change to the absolute-path interpretation in 4.2.

The current "correct" spellings for in-memory, relative, and absolute
URLs, respectively, are:

    sqlite3::memory:
    sqlite3:relative/path
    sqlite3:/full/path

Substantially reverses/defers fbb79b517f3127ba620fedd01849f9628b78d6ce.
Uncovered by @guilleiguaran while investigating #14495, though that
sounds like a different issue.
2014-04-03 01:30:27 +10:30
Rajarshi Das
ee36af1b77 We can conditional define the tests depending on the adapter or
connection.
2014-04-02 16:19:57 +05:30
Dave Lee
def60710ad PostgreSQL, Support for materialized views. [Dave Lee & Yves Senn]
Expand the query used in #table_exists? to include materialized views in the
kinds of relations it searches.
2014-04-02 10:47:15 +02:00
Yves Senn
f159b0a5a8 cleanup, reset_pg_session in range_test.rb
Also do not use transactional fixtures. We drop the type and the
table after every run, so there is nothing for the transaction to clean up.
2014-04-02 09:03:48 +02:00
Guo Xiang Tan
9896c5fba9 Allow postgresql enum_test to be run in random order.
Creating and dropping similar tables within the same connection causes postgresql to look up old values in the cache of tables which have already been dropped.
2014-04-01 21:34:11 -07:00
Yves Senn
f7a6b115fe PostgreSQL, register custom domains. Closes #14305.
This patch registers custom domains in our OID-type_map.
They will behave exactly as the type specified by `pg_type.typbasetype`.

/cc @matthewd
2014-04-01 19:52:34 +02:00
Rafael Mendonça França
fc0b98da0b Merge pull request #14513 from senny/pg/responsible_oid
PostgreSQL determine `Column#type` through corresponding OID. #7814
2014-04-01 09:56:06 -05:00