Commit Graph

4097 Commits

Author SHA1 Message Date
Rafael Mendonça França
e015f4e2e3 Merge pull request #13556 from yahonda/update_mysql_grant
Update grant statement to address #13549
2014-01-01 07:38:15 -08:00
Yasuo Honda
85a1f7ae1e Change the inexistent database name to inexistent_activerecord_unittest
to make this grant statement described in the document works

GRANT ALL PRIVILEGES ON inexistent_activerecord_unittest.* to 'rails'@'localhost';
2014-01-01 09:38:37 +09:00
Amr Tamimi
e0ad9ae27e Add the ability to nullify the enum column 2014-01-01 01:48:15 +02:00
Rafael Mendonça França
13c18fe2ca Improve tests to use only public API 2013-12-31 21:04:11 -02:00
Washington Luiz
8e1f26c66c Make outer joins on proper parent
Outer joins were being built on the root relation klass rather than the
one specified in the join dependency root
2013-12-31 01:10:38 -03:00
schneems
5b96027ef6 Allow "url" sub key in database.yml configuration
Currently a developer can pass in a YAML configuration that fully specifies connection information:

```
production:
  database: triage_production
  adapter: password
  pool: 5
```

They can also pass in a string that specifies a connection URL directly to an environment key:

```
production: postgresql://localhost/foo
```

This PR allows the use of both a connection url and specifying connection attributes via YAML through the use of the "url" sub key:

```
production:
  url: postgresql://localhost/foo
  pool: 3
```

This will allow developers to inherit Active Record options such as `pool` from `&defaults` and still use a secure connection url such as `<%= ENV['DATABASE_URL'] %>`. The URL is expanded into a hash and then merged back into the YAML hash. If there are any conflicts, the values from the connection URL are preferred. 

Talked this over with @josevalim
2013-12-30 12:21:14 -05:00
José Valim
10721450de Merge pull request #13527 from kuldeepaggarwal/f-independent-specs
Use user-defined configurations in mysql tests
2013-12-29 12:32:06 -08:00
Kuldeep Aggarwal
a2985e2067 raise ArgumentError exception if Model.where.not is called with nil argument 2013-12-30 01:53:02 +05:30
Kuldeep Aggarwal
143da09f51 used user-defined configurations for running tests that might depend on user's system configuration 2013-12-29 13:57:52 +05:30
Yves Senn
4fd3204a04 Merge pull request #13474 from jdelStrother/becomes
Copy changed_attributes across to newly become'd records
2013-12-27 11:15:19 -08:00
Jonathan del Strother
b7bf025374 Copy changed_attributes across to newly become'd records
Without this, the original record's values won't get saved, since the partial insertions support (144e8691cb) checks for changed values and thinks there are none.
2013-12-27 15:54:06 +00:00
schneems
2409c61661 Fix failure introduced from #13488 2013-12-25 18:45:26 -05:00
Guillermo Iguaran
278bbfd7df Merge pull request #13478 from schneems/schneems/fix-mysql
Move mysql2 test for when adapter will be loaded
2013-12-25 12:21:38 -08:00
Kuldeep Aggarwal
b9d79b1f5f using symbol instead of string in establish_connection 2013-12-25 15:24:25 +05:30
schneems
8e2c0803f5 Move mysql2 test for when adapter will be loaded
When run with only the Mysql adapter, we get this failure: https://travis-ci.org/rails/rails/jobs/15937907#L2416

Porting the test over to only run when mysql2 is loaded
2013-12-24 17:28:40 -05:00
schneems
f0311c2487 Raise NoDatabaseError when db does not exist
Building on the work of #13427 this PR adds a helpful error message to the adapters: mysql, mysql2, and sqlite3
2013-12-24 10:13:12 -05:00
José Valim
ec11807368 Deprecate use of string in establish_connection as connection lookup 2013-12-24 10:18:54 +01:00
José Valim
d2ed433b0a Only build a ConnectionSpecification if required 2013-12-24 10:02:07 +01:00
José Valim
33cb2f334d Merge pull request #13463 from josevalim/jv-env
Do not store production information in .yml files
2013-12-23 12:28:04 -08:00
José Valim
c390e60811 Guarantee the connection resolver handles string values
This commit also cleans up the rake tasks that were checking
for DATABASE_URL in different places.

In fact, it would be nice to deprecate DATABASE_URL usage in the long
term, considering the direction we are moving of allowing those in .yml
files.
2013-12-23 20:15:52 +01:00
Carlos Antonio da Silva
9e1740af9c Tidy up fix for PG extensions quoting
Always pass in the column for quote_bound_value and quote using it in
case it exists there.
2013-12-23 16:28:35 -02:00
Tadas Tamosauskas
73bba4c1e1 Serialize postgres' hstore, json and array types correctly in AR update methods.
Fixes #12261. Closes #12395.

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/test/cases/adapters/postgresql/array_test.rb
	activerecord/test/cases/adapters/postgresql/json_test.rb
2013-12-23 16:27:54 -02:00
Carlos Antonio da Silva
56510091fb Do not consider PG array columns as number or text columns
The code uses these checks in several places to know what to do with a
particular column, for instance AR attribute query methods has a branch
like this:

    if column.number?
      !value.zero?
    end

This should never be true for array columns, since it would be the same
as running [].zero?, which results in a NoMethodError exception.

Fixing this by ensuring that array columns in PostgreSQL never return
true for number?/text? checks.

Since most of the array support was based on the postgres_ext lib, it's
worth noting it does the same thing for numeric array columns too:

https://github.com/dockyard/postgres_ext/blob/v1.0.0/lib/postgres_ext/active_record/connection_adapters/postgres_adapter.rb#L72

This extended the same logic for text columns to ensure consistency.
2013-12-23 16:26:15 -02:00
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