Commit Graph

4074 Commits

Author SHA1 Message Date
schneems
0ec45cd15d Tell how to Create a Database in Error Message
Currently if you attempt to use a database that does not exist  you get an error:

```
PG::ConnectionBad FATAL:  database "db_error" does not exist
```

The solution is easy, create and migrate your database however new developers may not know these commands by memory. Instead of requiring the developer to search for a solution, tell them how to fix the problem in the error message:

```
ActiveRecord::NoDatabase: FATAL:  database "db_error" does not exist
Run `$ bin/rake db:create db:migrate` to create your database
```

Active Record should not know about `rake db:migrate` so this additional information needs to come from the railtie. Potential alternative implementation suggestions are welcome.
2013-12-23 10:23:48 -05:00
Paul Nikitochkin
2bcf7158d3 On destroying do not touch destroyed belongs to association.
Fixes: #13445
2013-12-23 15:44:48 +02:00
Yves Senn
00fc64a6dc Merge pull request #13446 from kuldeepaggarwal/resolver-test-cases
Resolver test cases
2013-12-23 05:14:14 -08:00
Kuldeep Aggarwal
34f17b871e added test cases for Resolver#connection_url_to_hash 2013-12-23 16:45:00 +05:30
Damien Mathieu
1f6a9b50ee fix quoting non-strings
Closes #13444
2013-12-22 17:00:50 +01:00
Aaron Patterson
fbb79b517f fix url connections for sqlite3 2013-12-20 16:13:34 -08:00
Rafael Mendonça França
ccaa3e47c4 Merge pull request #13412 from arthurnn/quote_id_not_id
quoting: Check if id is a valid method before using it
2013-12-19 13:57:14 -08:00
Arthur Neves
4a720a2cde quoting: Check if id is a valid method before using it
Need to check if valud also respond_to :id before calling it, otherwise
things could explode.
2013-12-19 16:51:28 -05:00
Cody Cutrer
847e9a95da fix default select when from is used 2013-12-19 14:40:13 -07:00
Carlos Antonio da Silva
e4cde5d58c Fix indent in PG array tests
[ci skip]
2013-12-19 19:14:23 -02:00
Carlos Antonio da Silva
cc1f0b4c2d Merge pull request #13395 from kuldeepaggarwal/postgres-table-ref-regex
modified regex for finding table_name from a multiline sql query in postgresql
2013-12-19 05:22:28 -08:00
Kuldeep Aggarwal
b082bece5e Fix PostgreSQL insert to properly extract table name from multiline string SQL.
Previously, executing an insert SQL in PostgreSQL with a command like this:

    insert into articles(
      number)
    values(
      5152
    )

would not work because the adapter was unable to extract the correct articles table name.
2013-12-19 18:46:17 +05:30
Carlos Antonio da Silva
c5b76b5362 Prefer assert_raise instead of flunk + rescue to test for exceptions
Change most tests to make use of assert_raise returning the raised
exception rather than relying on a combination of flunk + rescue to
check for exception types/messages.
2013-12-19 09:20:51 -02:00
Carlos Antonio da Silva
5b0fc1a007 Merge pull request #13393 from matthewd/fix_pg_range_tests
Fix PostgreSQL range tests on fresh DB

Correcting the name of the table we're creating is self-explanatory.

But we must also move away from the low IDs, because we're not touching the freshly-created primary key sequence; when the time comes, @new_range will be assigned an ID of 1.
2013-12-19 01:44:01 -08:00
Kuldeep Aggarwal
ff4673be52 set encoding UTF-8 for accepting multibyte character 2013-12-19 11:00:38 +05:30
Godfrey Chan
e63748cd37 Merge pull request #13366 from vipulnsward/minitest-namespace-change
Change all `MiniTest` to `Minitest`
2013-12-18 19:22:30 -08:00
Matthew Draper
f8b4110f00 Fix PostgreSQL range tests
The changes in c4044b2 meant the tests would error on a fresh DB.
2013-12-19 13:34:46 +10:30
rono23
ee738f9604 Fix to_param when attribute has multibyte character 2013-12-19 05:29:16 +09:00
Vipul A M
7bae2921ec Change all MiniTest to Minitest since, MiniTest namespace has been renamed to Minitest
Ref: https://github.com/seattlerb/minitest/blob/master/History.txt
2013-12-18 14:39:50 +05:30
Jeremy Kemper
c141dfc838 Add a failing test for assigning nil to a polymorphic belongs_to not nullifying its _type column 2013-12-17 21:45:55 -07:00
Jeremy Kemper
2b096c7170 Merge pull request #13314 from laurocaetano/blacklist_array_methods
Create a blacklist to disallow mutator methods to be delegated to Array

Conflicts:
	guides/source/upgrading_ruby_on_rails.md
2013-12-17 11:29:23 -07:00
Carlos Antonio da Silva
ae196e85ee Merge pull request #13341 from carlosantoniodasilva/ca-i18n
Default I18n.enforce_available_locales to true

We will default this option to true from now on to ensure users properly handle their list of available locales whenever necessary. This option was added as a security measure and thus Rails will follow it defaulting to secure option.

Also improve the handling of I18n config options in its railtie, taking the new enforce_available_locales option into account, by setting it as the last one in the process. This ensures no other configuration will trigger a deprecation warning due to that setting.
2013-12-17 08:22:26 -08:00
Lauro Caetano
d4ee09cda1 Create a blacklist to disallow mutator methods to be delegated to Array.
This change was necessary because the whitelist wouldn't work.
It would be painful for users trying to update their applications.

This blacklist intent to prevent odd bugs and confusion in code that call mutator
methods directely on the `Relation`.
2013-12-17 13:43:10 -02:00
Rafael Mendonça França
c56bbaaf6f Merge pull request #13343 from akshay-vishnoi/test-cases
test case for #limit added - picking latest value from limit
2013-12-17 06:23:05 -08:00
Carlos Antonio da Silva
6802196a6b Disable available locales checks to avoid warnings running the tests 2013-12-17 09:05:41 -02:00
Akshay Vishnoi
687cd75fb5 test case for #limit added - picking latest value from limit 2013-12-17 03:50:34 +05:30
Martin Emde
8062a30794 Better support for where() conditions that use an association name.
Using the name of an association in `where` previously worked only
if the value was a single `ActiveRecrd::Base` object. e.g.

    Post.where(author: Author.first)

Any other values, including `nil`, would cause invalid SQL to be
generated. This change supports arguments in the `where` query
conditions where the key is a `belongs_to` association name and the
value is `nil`, an `Array` of `ActiveRecord::Base` objects, or an
`ActiveRecord::Relation` object.

    # Given the Post model
    class Post < ActiveRecord::Base
      belongs_to :author
    end

    # nil value finds records where the association is not set
    Post.where(author: nil)
    # SELECT "posts".* FROM "posts" WHERE "posts"."author_id" IS NULL

    # Array values find records where the association foreign key
    # matches the ids of the passed ActiveRecord models, resulting
    # in the same query as Post.where(author_id: [1,2])
    authors_array = [Author.find(1), Author.find(2)]
    Post.where(author: authors_array)

    # ActiveRecord::Relation values find records using the same
    # query as Post.where(author_id: Author.where(last_name: "Emde"))
    Post.where(author: Author.where(last_name: "Emde"))

Polymorphic `belongs_to` associations will continue to be handled
appropriately, with the polymorphic `association_type` field added
to the query to match the base class of the value. This feature
previously only worked when the value was a single `ActveRecord::Base`.

    class Post < ActiveRecord::Base
      belongs_to :author, polymorphic: true
    end

    Post.where(author: Author.where(last_name: "Emde"))
    # Generates a query similar to:
    Post.where(author_id: Author.where(last_name: "Emde"), author_type: "Author")
2013-12-16 14:16:15 -08:00
Cody Cutrer
75a2e4a8df support creating temporary tables from queries
also override drop_table in AbstractMySQLAdapter to properly drop
temporary tables without committing the transaction
2013-12-14 07:07:10 -07:00
Rafael Mendonça França
1713e8fe16 Merge pull request #13306 from kassio/master
Fix mysql to support duplicated column names
2013-12-13 05:55:54 -08:00
Kassio Borges
b8569b9337 Fix mysql to support duplicated column names
This will fix the [broken
test](4a26508366)
 `test_with_limiting_with_custom_select`.

The query's result was built in a hash with column name as key, if the
result have a duplicated column name the last value was
overriding the first one.
2013-12-13 11:55:13 -02:00
Yves Senn
63f9a7507b refactor, reuse assertions in range_test.rb. 2013-12-13 14:28:13 +01:00
Yves Senn
c4044b2f8a extract PG range tests from datatype_test.rb into range_test.rb 2013-12-13 14:17:21 +01:00
Jeremy Kemper
0b142a6f84 Add a bunch of Relation -> Array delegate methods to the whitelist. This won't last - aim to switch back to a blacklist for mutator methods. 2013-12-12 21:10:03 -07:00
Lauro Caetano
1244aa7c5f Use public_send instead of just use send. 2013-12-12 20:19:04 -02:00
Lauro Caetano
aa85bdba68 Use a whitelist to delegate methods to array 2013-12-12 19:34:47 -02:00
laurocaetano
d1987846b3 Remove delegation test.
This test was removed, since Relation will not delegate class
methods to Array.
2013-12-12 19:31:48 -02:00
Aaron Patterson
da3891c898 make sure cached table name is a string. fixes #12582 2013-12-12 10:47:07 -08:00
Carlos Antonio da Silva
5ef040d0c6 Get rid of hack for freezing time on AR tests
We can now make use of the existent #travel/#travel_to helper methods
added to AS test case and available in all tests.
2013-12-12 08:57:07 -02:00
Rafael Mendonça França
c9b8ca9748 Merge pull request #13264 from laurocaetano/fix_dynamic_finder_with_reserved_words
Prevent invalid code when using dynamic finders with reserved ruby word.
2013-12-11 14:38:27 -08:00
Rafael Mendonça França
7a036ebd30 Revert the whole refactoring in the association builder classes.
This is to get activerecord-deprecated_finders work again
2013-12-11 19:28:32 -02:00
Rafael Mendonça França
e1ce005942 Revert "Merge pull request #12518 from vipulnsward/remove_count_options"
It is needed for activerecord-depecated_finders

This reverts commit dcff027a5242b20c0c90eb062dddb22ccf51aed9, reversing
changes made to 3a2093984ff49d86db1efeff0c7581e788ecfb9f.
2013-12-11 13:29:21 -02:00
Lauro Caetano
23ce3e5fde Prevent invalid code when using dynamic finders with Ruby's reserved words.
The dynamic finder was creating the method signature with the parameters name,
which may have reserved words and this way creating invalid Ruby code.

Closes: #13261

    Example:

        # Before
        Dog.find_by_alias('dog name')

        # Was creating this method
        def self.find_by_alias(alias, options = {})

        # After
        Dog.find_by_alias('dog name')

        # Will create this method
        def self.find_by_alias(_alias, options = {})
2013-12-11 01:00:32 -02:00
Yves Senn
821153525c Merge pull request #13236 from jetthoughts/13230_type_cast_bug_in_agr_functions
Fix type cast on group sum with custom expression
2013-12-10 05:29:25 -08:00
Paul Nikitochkin
2a7fe7ae9b Fix type cast on group sum with custom expression
For PG adapters with custom expression and grouped result
of aggregate functions have not found correct column type
for it. Extract column type from query result.

Closes: #13230
2013-12-10 14:30:12 +02:00
Carlos Antonio da Silva
7cf9a43268 Fix warnings on mysql2 explain test 2013-12-10 08:06:48 -02:00
Jeremy Kemper
2fd067c33b Merge pull request #13248 from yahonda/support_mysql573_explain
Support MySQL 5.7 explain
2013-12-09 23:22:32 -08:00
Yasuo Honda
b6655885ef Remove DEFAULT NULL for primary key column to support MySQL 5.7.3
Since MySQL 5.7.3 m13 does now allow primary key column is null.
2013-12-10 11:12:33 +09:00
Yasuo Honda
75f453ff4c Support MySQL 5.7 explain 2013-12-10 11:04:09 +09:00
George Guimarães
ea75eb6499 Add integration test for #12459 2013-12-05 21:32:51 -02:00
Carlos Antonio da Silva
871914c239 Remove deprecated call to Relation#all 2013-12-05 16:32:00 -02:00