Commit Graph

4240 Commits

Author SHA1 Message Date
Vipul A M
6e66de6091 Fix enum test unused variable warning.
Related - 5c55aafd38
2014-03-04 18:06:19 +05:30
Dieter Komendera
5c55aafd38 Add Enum type to postgresql adapter's oids to prevent unknown OID warnings. 2014-03-04 10:32:20 +01:00
Vipul A M
398b4de011 Fix warnings due to:
- unused variable in PG Adapter.
- Ambiguous argument warning from range_test for use - to + Infinity range without brackets.
2014-03-03 02:35:42 +05:30
Arthur Neves
774160b9ad
Remove unnecessary db call when replacing.
When replacing a has_many association with the same one, there is no
need to do a round-trip to the db to create/and drop a new transaction.

[fixes #14220]
2014-02-28 17:00:38 -05:00
Yves Senn
d1e7cd14c2 includes uses SQL parsing when String joins are involved.
This is a partial revert of 22b3481ba2aa55fad1f9a5db94072312b345fb55.
The current implementation of `references_eager_loaded_tables?` needs to know
every table involved in the query. With the current API this is not possible
without SQL parsing.

While a2dab46cae35a06fd5c5500037177492a047c252 deprecated SQL parsing for `includes`.
It did not issue deprecation warnings when String joins are involved. This resulted
in a breaking change after the deprecated behavior was removed (22b3481ba2aa55fad1f9a5db94072312b345fb55).

We will need to rethink the usage of `includes`, `preload` and `eager_load` but for now,
this brings back the old *working* behavior.
2014-02-28 09:56:07 +01:00
TheMonster
6e53d92498 Fix a bug affecting validations of enum attributes
This fixes a bug where any enum attribute of a model
would be evaluated always as 0 when calling the
database on validations.

This fix converts the value of the enum attribute
to its integer value rather than the string before
building the relation as the bug occured when the
string finally gets converted to integer using
string.to_i which converts it to 0.

[Vilius Luneckas, Ahmed AbouElhamayed]
2014-02-27 23:54:49 +02:00
Yves Senn
671e997e5a extract common code in uuid_test.rb. 2014-02-26 16:09:55 +01:00
Yves Senn
50be1d0d20 move PostgreSQL UUID tests from datatype_test.rb to uuid_test.rb. 2014-02-26 16:09:55 +01:00
Yves Senn
cfb2238145 test case for custom PostgreSQL enum type.
This test currently outputs the following warning:

```
unknown OID: current_mood(3567879) (SELECT  "postgresql_enums".* FROM "postgresql_enums"   ORDER BY "postgresql_enums"."id" ASC LIMIT 1)
unknown OID: current_mood(3567879) (SELECT  "postgresql_enums".* FROM "postgresql_enums"  WHERE "postgresql_enums"."id" = $1 LIMIT 1)
```

We have an open PR to deal with this issue. It will dynamically
register the OID for enum columns. This test case is merely to exhibit
the current behavior of PostgreSQL enum columns.
2014-02-26 14:20:14 +01:00
Aaron Patterson
b1656fa630 let insert_record actuall save the object.
`before_add` callbacks are fired before the record is saved on
`has_and_belongs_to_many` assocations *and* on `has_many :through`
associations.  Before this change, `before_add` callbacks would be fired
before the record was saved on `has_and_belongs_to_many` associations, but
*not* on `has_many :through` associations.

Fixes #14144
2014-02-25 14:57:49 -08:00
Jon Leighton
90ba6a762c Merge remote-tracking branch 'chancancode/fix_instance_method_already_implemented'
Conflicts:
	activerecord/CHANGELOG.md
2014-02-25 22:21:56 +00:00
Aaron Patterson
b189f2846a Merge pull request #14152 from schneems/schneems/fix-ar-wtf-why-is-there-no-environment
Handle missing environment from non empty config
2014-02-25 08:34:16 -08:00
Yasuo Honda
d64673c8fe Skip test_migrate_revert_add_index_with_name if databases
do not allow to create duplicate indexes on the same columns
2014-02-25 21:53:30 +09:00
Godfrey Chan
41554319f8 Fixed STI classes not defining an attribute method if there is a
conflicting private method defined on its ancestors.

The problem is that `method_defined_within?(name, klass, superklass)`
only works correclty when `klass` and `superklass` are both `Class`es.

If both `klass` and `superklass` are both `Class`es, they share the
same inheritance chain, so if a method is defined on `klass` but not
`superklass`, this method must be introduced at some point between
`klass` and `superklass`.

This does not work when `superklass` is a `Module`. A `Module`'s
inheritance chain contains just itself. So if a method is defined on
`klass` but not on `superklass`, the method could still be defined
somewhere upstream, e.g. in `Object`.

This fix works by avoiding calling `method_defined_within?` with a
module while still fufilling the requirement (checking that the
method is defined withing `superclass` but not is not a generated
attribute method).

4d8ee288 is likely an attempted partial fix for this problem. This
unrolls that fix and properly check the `superclass` as intended.

Fixes #11569.
2014-02-23 11:00:55 -08:00
Yves Senn
d9314b4c0a Coerce strings when reading attributes. 2014-02-23 13:42:16 +01:00
Yves Senn
91949e48cf deprecate support for pg ranges with excluding beginnings.
The Ruby Range object does not support excluding beginnings.
We currently support excluding beginnings for some subtypes using
manually by incrementing them (now using the `#succ` method).
This is approach is flawed as it's not equal to an excluding beginning.

This commit deprecates the current support for excluding beginnings.
It also raises an `ArgumentError` for subtypes that do not implement the `succ`
method.

This is a temporary solution to get rid of the broken state. We might still
add complete support for excluding beginnings afterwards. (Probably with a
new `PGRange` object, which acts like a `Range` but has excluding beginnings.
2014-02-23 12:47:30 +01:00
Yves Senn
4cb47167e7 dynamically define PostgreSQL OID range types.
This gets AR working with custom defined range types. It also
removes the need for subtype specific branches in `OID::Range`.

This expands the interface of all `OID` types with the `infinity` method.
It's responsible to provide a value for positive and negative infinity.
2014-02-23 12:47:30 +01:00
Jon Leighton
40a9d89877 Add tests for default scope behaviour change
See #13875
2014-02-23 11:14:05 +00:00
schneems
283a2edec2 Handle missing environment from non empty config
If using a `DATABASE_URL` and a `database.yml`. The connection information in `DATABASE_URL` should be merged into whatever environment we are in. As released in 4.1.0rc1 if someone has a database.yml but is missing a key like production:

```yml
development:
  host: localhost

```

Then the check for blank config will return false so the information from the `DATABASE_URL` will not be used when attempting to connect to the `production` database and the connection will incorrectly fail.

This commit fixes this problem and adds a test for the behavior.

In addition the ability to specify a connection url in a `database.yml` like this:

```
production: postgres://localhost/foo
```

Was introduced in 4.1.0rc1 though should not be used, instead using a url sub key

```
production:
  url: postgres://localhost/foo
```

This url sub key was also introduced in 4.1.0rc1 though the `production: postgres://localhost/foo` was not removed. As a result we should not test this behavior.
2014-02-21 16:18:10 -06:00
Aaron Patterson
7eaebd8579 adding a test for #14106 2014-02-20 11:26:07 -08:00
Aaron Patterson
358802b850 Revert "context in validation goes through has many relationship"
This reverts commit 5e3d466d52fa4e9a42c3a1f8773a7c31da875e48.
2014-02-20 11:26:07 -08:00
Arthur Neves
f96831e5ec Add regression test for collection proxy reader
[related #14116]
2014-02-20 10:36:06 -05:00
Rafael Mendonça França
1879c259b8 Merge branch '4-1-0-beta2'
Conflicts:
	actionview/CHANGELOG.md
	activerecord/CHANGELOG.md
2014-02-18 16:00:47 -03:00
Aaron Patterson
6256b1de9a Correctly escape PostgreSQL arrays.
Thanks Godfrey Chan for reporting this!

Fixes: CVE-2014-0080
2014-02-18 15:40:19 -03:00
Rafael Mendonça França
a2075f4142 Revert "Merge pull request #13344 from ccutrer/fix-from-default-select"
This reverts commit 3ea840355409dc205a9e0d027fc09f1452636969, reversing
changes made to e4cde5d58cbb09d1843796f96ba86225ff94fe05.

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/lib/active_record/relation/query_methods.rb

Reason: using `from` without `select` should not change the select list
to SELECT * because it can lead different query results. If it is needed
to change the table to a subquery or a view you can pass a table alias
in the `from` call or use `select('subquery.*')`.

Fixes #14049.
2014-02-17 10:49:38 -03:00
Rafael Mendonça França
141313c651 Don't skip tests if they are not broken. Just don't define they 2014-02-16 21:49:50 -03:00
Josh Goodall
da3fec2ea3 Resolve encoding issues with arrays of hstore (bug 11135).
We didn't have enough encoding for the wire protocol to store an array
of hstore types. So, further encode any hstore that is an array member.
Whilst we're here, ensure it's an HashWithIndifferentAccess being
returned, to be consistent with other serialized forms, and add testing
for arrays of hstore.

So now the following migration:

  enable_extension "hstore"
  create_table :servers do |t|
    t.string  :name
    t.hstore  :interfaces, array: true
  end

produces a model that can used like this, to store an array of hashes:

  server = Server.create(name: "server01", interfaces: [
    { name: "bge0", ipv4: "192.0.2.2", state: "up" },
    { name: "de0", state: "disabled", by: "misha" },
    { name: "fe0", state: "up" },
  ])

More at http://inopinatus.org/2013/07/12/using-arrays-of-hstore-with-rails-4/
2014-02-17 00:40:16 +02:00
Aaron Patterson
213b2fbf40 make a singleton for AssociationScope
AssociationScope no longer maintains state, so we're safe to keep a
singleton and save on GC time
2014-02-14 14:23:04 -08:00
Aaron Patterson
8e6ef92fd9 pass the association and connection to the scope method 2014-02-14 14:20:07 -08:00
Rajarshi Das
680f7d906e remove unused fixtures from sqlite3 test cases 2014-02-14 17:31:06 +05:30
Yves Senn
ad482673d7 Merge pull request #14034 from hdabrows/drop-correct-index-when-reverting-migration
Drop the correct index after reverting a migration
2014-02-13 19:07:13 +01:00
Hubert Dąbrowski
e1d4673102 Drop the correct index after reverting a migration
Previously when reverting a migration which added a named index it
would instead drop a corresponding index with matching columns but
without a name.
2014-02-13 17:18:16 +01:00
Yves Senn
ea3af7ee14 tests are responsible to clean up afterwards.
remove created state after test execution, not before the next test.
This prevents the leak of the `ex` table outside of a single test.
2014-02-13 16:45:56 +01:00
Matthew Draper
3b645fd3ed Terminate the backend ourselves on PG 9.2+
This should make it harder to accidentally break this test.
2014-02-12 15:21:11 -08:00
Yves Senn
4b11dcca74 test case to illustrate current PostgreSQL composite behavior. 2014-02-11 13:58:41 +01:00
Dmitry Polushkin
ec43584431 add activerecord test coverage for sanitize_sql_array
check it is handles empty statement
2014-02-09 12:05:42 +00:00
Aaron Patterson
e4dc3035ce Merge pull request #13981 from Fortisque/kevin/postgresql_reaper_threadsafe
Reaper has access to threadsafe active? call
2014-02-08 23:12:07 -08:00
Kevin Casey
02a3c0e771 Reaper has access to threadsafe active? call 2014-02-08 17:38:54 -08:00
Aaron Patterson
f99b254e4e Merge pull request #13978 from Fortisque/kevin/validation_context_for_children
context in validation goes through has many relationship
2014-02-08 17:11:27 -08:00
Mikko Johansson
28a450d590 Skips linked folder tests if symlink is invalid 2014-02-09 02:52:32 +02:00
Lauro Caetano
1ea61cb9bc Add test case for autosave HasMany with accepts_nested_attributes.
It should not save the parent record when the nested attributes are
invalid.

Test case to cover #8194.
2014-02-08 18:57:26 -02:00
Kevin Casey
5e3d466d52 context in validation goes through has many relationship 2014-02-08 08:44:10 -08:00
Andrew White
3f90787cd2 Adjust test value so that timezone has no effect
If the test is run in a timezone that is behind UTC it fails because
the time generated is ahead of 0000-01-01 00:00:00. Just increase the
time subtracted so that timezone has no effect.
2014-02-07 17:08:09 -08:00
Marc-Andre Lafortune
13d2696c10 Return sized enumerator from Batches#find_each 2014-02-05 16:53:02 -05:00
Marc-Andre Lafortune
d37f395be8 Return sized enumerator from Batches#find_in_batches 2014-02-05 16:49:29 -05:00
Marc-Andre Lafortune
4499ab5fde Strengthen test with different nb of rows and columns 2014-02-05 16:45:56 -05:00
Yves Senn
132834bc6a Merge pull request #13949 from vajrasky/fix_typo_column_definition_test
Fixed typos in column_definition_test.rb.
2014-02-05 10:14:00 +01:00
Vajrasky Kok
38777949f0 Fixed typo in column_definition_test.rb. 2014-02-05 16:51:34 +08:00
Yves Senn
3ba0eeda02 docs, AR already auto-detects primary keys. Closes #13946. [ci skip]
This behavior was introduced since Rails 3.1 (207f266ccaaa9cd04cd2a7513ae5598c4358b510)
but the docs were still out of date.
2014-02-05 08:52:59 +01:00
Rafael Mendonça França
f1a6307a94 Merge pull request #13935 from arthurnn/fix_12566
Make sure transaction state resets after commit
2014-02-04 06:03:14 -08:00