Commit Graph

5460 Commits

Author SHA1 Message Date
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
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
Yves Senn
4d344bb4fd PostgreSQL determine Column#type through corresponding OID. #7814
I ran the whole test suite and compared the old to the new types.
Following is the list of types that did change with this patch:

```
DIFFERENT TYPE FOR mood: NEW: enum, BEFORE:
DIFFERENT TYPE FOR floatrange: NEW: floatrange, BEFORE: float
```

The `floatrange` is a custom type. The old type `float` was simply a coincidence
form the name `floatrange` and our type-guessing.
2014-04-01 09:54:32 +02:00
eileencodes
49e17431ca refactor assert_sql query to reuse capture_sql
set assert_sql to reuse the capture_sql method from above
instead of repeating the code

in response to comments on issue #14546
2014-03-31 22:56:39 -04:00
Aaron Patterson
e9f53f7a7a Merge pull request #14546 from eileencodes/fix_delete_all_to_not_use_IN_statement
Fix delete all to not produce sql in statement
2014-03-31 19:09:32 -07:00
eileencodes
a116afe536 add test to compare sql statements in delete_all query
delete_all sql if an association is not loaded should behave
the same as if the association is loaded. This test ensures
the SQL statements are exactly the same.
2014-03-31 19:28:44 -04:00
eileencodes
a67293638e add capture_sql method to compare sql statements and compare
Other methods compare specific patterns, this method outputs
the actual sql query that is generated.
2014-03-31 19:28:44 -04:00
Aaron Patterson
b88cfed7ab Merge pull request #14532 from thedarkone/polymorphic-preload-fix
Fix polymorphic preloads on NOT NULL _type columns
2014-03-31 10:11:33 -07:00
thedarkone
055942d6c5 Simplify Preloader#grouped_records code.
The new method relies on AR::Associations::Association knowing about both reflection and a model class.

AR::Base#association now raises a descriptive error when trying to access non-existent associations. Previously it would blow up with a confusing NoMethodError: undefined method `association_class' for nil:NilClass.
2014-03-30 20:52:01 +02:00
thedarkone
de32d972bf Fix polymorphic preloads on NOT NULL _type columns.
Defer to Association#klass instead of having a custom/duplicate code.
2014-03-30 20:23:50 +02:00
Luke Steensen
78e4862f6f fix bug on non empty defaults for pg array columns
fixes #10613
2014-03-30 11:10:41 -05:00
Guo Xiang Tan
0264762fea Refactor test to use DdlHelper.
Follow-Up to https://github.com/rails/rails/pull/14400

This ensures that all tables are removed after each test and thereby
allowing us to run the tests in a random order.
2014-03-29 09:43:19 -07:00
Yves Senn
0b33c06475 Merge pull request #14524 from tgxworld/fix_unsubscribe_from_notifications
Fix tests not unsubscribing from Notifications.
2014-03-29 14:53:29 +01:00
Godfrey Chan
945dd254ae Ensure we are returning either true or false for #==
460eb83d cused `ActiveRecord::Base#==` to sometimes return `nil` in some cases,
this ensures we always return a boolean value. Also fixed a similar problem in
AR reflections.
2014-03-29 04:34:20 -07:00
Guo Xiang Tan
0212a41700 Fix tests not unsubscribing from Notifications.
See https://github.com/rails/rails/blob/master/activesupport/lib/active_support/notifications.rb#L131
2014-03-28 18:56:40 -07:00
Yves Senn
a8bd7b1626 PostgreSQL, use PostgreSQLColumn in PG specific tests. 2014-03-28 16:20:26 +01:00
Yves Senn
d8b4583234 PostgreSQL, test-cases to lock down column default values. 2014-03-28 16:10:24 +01:00