Commit Graph

6647 Commits

Author SHA1 Message Date
Rafael Mendonça França
2c7c11d545 Merge pull request #20150 from karanarora/Typo-fix
remove redundant parenthesis
2015-05-13 20:57:14 -03:00
karanarora
1e34ed7d82 remove redundant parenthesis 2015-05-14 04:13:33 +05:30
Yves Senn
f7881d3e2b invalid sti error message contains the full class name.
This can resolve confusing situation when a top level constant exists
but a namespaced version is identified.

Related to #19531.
2015-05-13 11:35:34 +02:00
Yves Senn
15354b6fd0 Merge branch 'sti-subclass-from-attributes' of https://github.com/agrobbin/rails into agrobbin-sti-subclass-from-attributes
Conflicts:
	activerecord/CHANGELOG.md
2015-05-13 11:08:10 +02:00
Alex Coomans
01f7d14494 Add full set of MySQL CLI options to support SSL authentication when using db:structure dump and load 2015-05-12 17:06:49 -07:00
Alex Robbin
cbd66b430b allow setting of a demodulized class name when using STI
If your STI class looks like this:

```ruby
class Company < ActiveRecord::Base
  self.store_full_sti_class = false

  class GoodCo < Company
  end

  class BadCo < Company
  end
end
```

The expectation (which is valid) is that the `type` in the database is saved as
`GoodCo` or `BadCo`. However, another expectation should be that setting `type`
to `GoodCo` would correctly instantiate the object as a `Company::GoodCo`. That
second expectation is what this should fix.
2015-05-11 09:02:48 -04:00
Yves Senn
f1da919a05 remove duplicate test.
The old `test_create_bang_returns_falsy_when_join_record_has_errors` had
a missleading name and was a duplicate of
`test_save_should_not_raise_exception_when_join_record_has_errors`.

Since it had an assertion on the return value I renamed it accordingly
and got rid of the duplicate test.
2015-05-08 11:14:45 +02:00
Yves Senn
d27974d3fb tests, extract helpers to modify global state.
Make sure that tests do not hardcode the default value.
For example `test_instantiation_doesnt_try_to_require_corresponding_file`
always restored the configuration to `true` regardless of what it's
original value was.

Extract a helper to make the global modification consistent across tests.
2015-05-07 15:04:49 +02:00
Aaron Patterson
fcc46833a8 Merge pull request #17632 from eugeneius/schema_cache_dump_connection_pool
Apply schema cache dump when creating connections
2015-05-04 08:55:10 -07:00
Ryuta Kamizono
f380c29134 More exercise the create index sql tests 2015-05-04 08:22:44 +09:00
Rafael Mendonça França
02966105a5 Merge pull request #19994 from kamipo/dump_indexes_in_create_table
Dump indexes in `create_table` instead of `add_index`
2015-05-03 19:33:12 -03:00
Rafael Mendonça França
a278668624 Merge pull request #17824 from yuki24/change-record-not-saved-and-not-destroyed-to-include-error-msg
AR::RecordNotSaved & RecordNotDestroyed from save!/destroy! should include an error message
2015-05-03 18:50:51 -03:00
Rafael Mendonça França
b6cc44bfa6 Merge pull request #17569 from kamipo/dump_table_options
Correctly dump `:options` on `create_table` for MySQL
2015-05-03 18:43:58 -03:00
Rafael Mendonça França
8847bed3eb Merge pull request #19987 from kamipo/move_postgresql_specific_schema
Move PostgreSQL specific schema to postgresql_specific_schema.rb
2015-05-03 18:39:06 -03:00
Ryuta Kamizono
f8e748b4e8 PostgreSQL: :collation support for string and text columns
Example:

    create_table :foos do |t|
      t.string :string_en, collation: 'en_US.UTF-8'
      t.text   :text_ja,   collation: 'ja_JP.UTF-8'
    end
2015-05-04 03:53:41 +09:00
Ryuta Kamizono
99801c6a7b Dump indexes in create_table instead of add_index
If the adapter supports indexes in create table, generated SQL is
slightly more efficient.
2015-05-03 23:35:13 +09:00
Ryuta Kamizono
6c8ec48ba3 Move PostgreSQL specific schema to postgresql_specific_schema.rb 2015-05-03 21:13:13 +09:00
Ryuta Kamizono
486a3697c9 Remove unused require 2015-05-03 16:54:03 +09:00
Ryuta Kamizono
22ba159efc Correctly dump :options on create_table for MySQL 2015-05-03 16:41:19 +09:00
Yuki Nishijima
ad5824bde0 AR::RecordNotSaved & RecordNotDestroyed should include an error message
When `AR::Base.save!` or `AR::Base.destroy!` is called and an exception
is raised, the exception doesn't have any error message or has a weird
message like `#<FailedBulb:0x0000000907b4b8>`. Give a better message so
we can easily understand why it's failing to save/destroy.
2015-05-01 19:01:41 -07:00
Eugene Kenny
33fe7cc889 Apply schema cache dump when creating connections
The `db:schema:cache:dump` rake task dumps the database schema structure
to `db/schema_cache.dump`. If this file is present, the schema details
are loaded into the currently checked out connection by a railtie while
Rails is booting, to avoid having to query the database for its schema.

The schema cache dump is only applied to the initial connection used to
boot the application though; other connections from the same pool are
created with an empty schema cache, and still have to load the structure
of each table directly from the database.

With this change, a copy of the schema cache is associated with the
connection pool and applied to connections as they are created.
2015-04-29 11:02:47 +01:00
Yves Senn
80f011ea54 Merge pull request #19546 from DianthuDia/fix_unscope_for_less_than
Fix unscope for less than
2015-04-28 11:37:59 +02:00
Yves Senn
cdf3548a45 Merge pull request #19718 from eagletmt/find_by-without-arg
Raise ArgumentError when find_by receives no arguments
2015-04-28 11:06:53 +02:00
Yves Senn
f00554a822 test, for create_table and foreign_key: true no-op. Closes #19794.
Add a test-case to make sure that `create_table` with
a `foreign_key: true` and an adapter without foreign key support
does not blow up.

Motivated by #19794.

Originating from: 99a6f9e60e (commitcomment-10855210)
2015-04-27 12:12:20 +02:00
Prem Sichanugrist
150f40998d Silence warning from MySQL::Error object in test
When running Active Record MySQL test, this warning is printed in the
console:

    warning: instance variable errno not initialized

It turns out that this is a warning from `mysql` gem in MySQL::Error
object. However, since the `mysql` gem is no longer maintained, and
there won't be a newer version, it make sense for us to just silence
this warning to make the output cleaner.
2015-04-23 17:05:03 -04:00
Rafael Mendonça França
6f37d7e117 Merge pull request #18880 from mudge/timestamp-index-bug
Fix missing index when using timestamps with index
2015-04-23 13:51:55 -03:00
Andrew White
ac2b7a5c4d Rename association option :class to :anonymous_class
In 1f006c an option was added called :class to allow passing anonymous
classes to association definitions. Since using :class instead of
:class_name is a fairly common typo even amongst experienced developers
this can result in hard to debug errors arising in raise_on_type_mismatch?

To fix this we're renaming the option from :class to :anonymous_class as
that is a more correct description of what the option is for. Since this
was an internal, undocumented option there is no need for a deprecation.

Fixes #19659
2015-04-21 08:48:22 -04:00
Sean Griffin
9721b45b40 Merge pull request #19783 from vngrs/raise_error_on_touch_if_object_is_stale
Raise StaleObjectError if touched object is stale and locking is enabled
2015-04-19 16:54:39 -04:00
Mehmet Emin İNAÇ
5e8d96c523 Raise StaleObjectError if touched object is stale and locking is enabled
Fixes #19776

change test variable names and use more verbose on method

less verbose

use _read_attribute instead of send
2015-04-19 23:50:13 +03:00
Sean Griffin
d849f42b4e Autosave existing records on HMT associations when the parent is new
To me it seems like this should only be the case if `autosave: true` is
set on the association. However, when implemented that way, it caused
issues with has many associations, where we have explicit tests stating
that child records are updated when the parent is new, even if autosave
is not set (presumably to update the parent id, but other changed
attributes would be persisted as well).

It's quirky, but at least we should be consistently quirky. This
constitutes a minor but subtle change in behavior, and therefore should
not be backported to 4.2 and earlier.

Fixes #19782
2015-04-18 10:47:04 -04:00
Yves Senn
c0939a5038 Merge pull request #19763 from jonatack/fix-typos-in-docs
Fix typos and improve the documentation
2015-04-15 13:35:56 +02:00
Jon Atack
6345f31fbf Fix typos and improve the documentation
This is a squash of the following commits, from first to last:

-

Fix minor, random things I’ve come across lately that individually
did not seem worth making a PR for, so I saved them for one commit.

One common error is using “it’s” (which is an abbreviation of “it is”)
when the possessive “its” should be used for indicating possession.

-

Changes include the name of a test, so remove the `[skip ci]` (thanks @senny).

-

Line wrap the changes at 80 chars and add one more doc fix.

-

Add a missing line wrap in the Contributing to Ruby on Rails Guide.

-

Line wrap the `TIP` section in the Contributing to Ruby on Rails Guide as well.

Rendering the guide locally with `bundle exec rake guides:generate` did
not show any change in on-screen formatting after adding the line wrap.

The HTML generated is (extra line added to illustrate where the line
wrap takes place):

    <div class="info"><p>Please squash your commits into a single commit
when appropriate. This

    simplifies future cherry picks and also keeps the git log
clean.</p></div>

-

Squash commits.
2015-04-15 16:25:24 +05:30
Paul Mucur
c0abeadc0e Fix missing index when using timestamps with index
The `index` option used with `timestamps` should be passed to both
`column` definitions for `created_at` and `updated_at` rather than just
the first.

This was happening because `Hash#delete` is used to extract the `index`
option passed to `timestamps`, thereby mutating the `options` hash
in-place. Now take a copy of the `options` before deleting so that the
original is not modified.
2015-04-15 09:53:55 +01:00
Yves Senn
5f00ed10dd Revert "Merge pull request #19755 from yuki24/activerecord/support-for-set"
This reverts commit 524d40591eaa2f4d007409bfad386f6b107492eb, reversing
changes made to 34d3a6095100245283861ef480a54d0643bbee4c.

Reasoning behind the revert are in the PR discussion:
https://github.com/rails/rails/pull/19755

- This means that types can no longer cast to/from `Set`, and reasonably
  work with `where` (we already have this problem for `array`/`json`
  types on pg)
- This adds precedent for every other `Enumerable`, and we can't target
  `Enumerable` directly.
- Calling `to_a` on a `Set` is reasonable.
2015-04-15 09:10:00 +02:00
Yves Senn
524d40591e Merge pull request #19755 from yuki24/activerecord/support-for-set
Add support for Set to Relation#where
2015-04-14 08:57:10 +02:00
Yuki Nishijima
50cae600bd Add support for Set to Relation#where
Previously `#where` used to treat `Set`objects as nil, but now it treats
them as an array:

  set = Set.new([1, 2])
  Author.where(:id => set)
  # => SELECT "authors".* FROM "authors" WHERE "authors"."id" IN (1, 2)
2015-04-13 20:13:37 -07:00
Matthew Draper
c7b25b842c Fix (intermittent?) test failure
We don't actually need to enumerate the possible types here any more;
that dates back to before e105e599e706780905d4c348394da989de3b200f, when
they were symbols, and indistinguishable from other options.
2015-04-13 08:32:35 +09:30
Kohei Suzuki
28375dd621 Raise ArgumentError when find_by receives no arguments
It fixes the strange error saying undefined method `take'.

```
RelationTest#test_find_by_without_arg_behaves_same_with_find_by({}):
NoMethodError: undefined method `take' for #<ActiveRecord::QueryMethods::WhereChain:0x007f9c55db1d68>
```
2015-04-11 07:48:01 +09:00
Prem Sichanugrist
3e482f2956
Use use_transactional_tests in Active Record
`use_transactional_fixtures` was deprecated in favor of
`use_transactional_tests` in Rails 5.0. This removes one warning while
running test suite.
2015-04-10 16:51:02 -04:00
Arthur Neves
8971389783
Batch touch parent records
[fixes #18606]

Make belongs_to use touch over touch_later when running the callbacks.

Add more tests and small method rename

Thanks Jeremy for the feedback.
2015-04-08 13:31:28 -04:00
Sean Griffin
67c2deeb4b Merge branch 'fix_uniqueness_validation_when_value_is_out_of_range' 2015-04-08 11:07:39 -06:00
Andrey Voronkov
1a36be390e Fix uniqueness validation with out of range value 2015-04-08 19:28:45 +03:00
Jeremy Kemper
bd51bbc028 Merge pull request #17574 from kamipo/charset_collation_options
Add charset and collation options support for MySQL string and text columns.
2015-04-07 09:40:16 -07:00
Rafael Mendonça França
d5f80655f9 Merge pull request #19647 from codeout/association_update
Fix a regression introduced by removing unnecessary db call when replacing
2015-04-06 19:17:54 -03:00
Mehmet Emin İNAÇ
8c1180731f use singular table name if pluralize_table_names is setted as false while creating foreign key
test case for use singular table name if pluralize_table_names is setted as false while creating foreign key

refactor references foreign key addition tests

use singular table name while removing foreign key

merge foreign key singular table name methods

remove unnecessary drop table from test
2015-04-06 11:10:24 +03:00
Shintaro Kojima
e646d3bf57 Fix a regression introduced by removing unnecessary db call when replacing
When replacing a has_many association with the same one, there is nothing to do with database but a setter method should still return the substituted value for backward compatibility.
2015-04-04 12:48:36 +00:00
Rafael Mendonça França
baa176e3f0 Merge pull request #19586 from mechanicles/fix-eager-loading-for-find-methods
Fix eager loading association using default_scope for finder methods.
2015-03-31 15:06:22 -03:00
Santosh Wadghule
4596e16f1a Fix eager loading association using default_scope for finder methods.
- Eager loading was not working for the default_scope (class method)
  for 'find' & 'find_by' methods.
- Fixed these by adding a new check 'respond_to?(:default_scope)'.
2015-03-31 22:54:42 +05:30
Kuldeep Aggarwal
bf6a33fd82 use Model.reset_column_information to clear table cache connection wide.
`widgets` table is being created in `primary_keys_test.rb` for PostgreSQLAdapter, MysqlAdapter, Mysql2Adapter
    and it makes test to fail earlier.

    Before:
      `bundle exec rake mysql2:test`

    ```
    Finished in 127.287669s, 35.5258 runs/s, 97.8885 assertions/s.

      1) Error:
    PersistenceTest::SaveTest#test_save_touch_false:
    ActiveModel::UnknownAttributeError: unknown attribute 'name' for #<Class:0x0000000a7d6ef0>.
        /home/kd/projects/kd-rails/activerecord/lib/active_record/attribute_assignment.rb:36:in `rescue in _assign_attribute'
        /home/kd/projects/kd-rails/activerecord/lib/active_record/attribute_assignment.rb:34:in `_assign_attribute'
        /home/kd/projects/kd-rails/activemodel/lib/active_model/attribute_assignment.rb:40:in `block in _assign_attributes'
        /home/kd/projects/kd-rails/activemodel/lib/active_model/attribute_assignment.rb:39:in `each'
        /home/kd/projects/kd-rails/activemodel/lib/active_model/attribute_assignment.rb:39:in `_assign_attributes'
        /home/kd/projects/kd-rails/activerecord/lib/active_record/attribute_assignment.rb:26:in `_assign_attributes'
        /home/kd/projects/kd-rails/activemodel/lib/active_model/attribute_assignment.rb:33:in `assign_attributes'
        /home/kd/projects/kd-rails/activerecord/lib/active_record/core.rb:293:in `initialize'
        /home/kd/projects/kd-rails/activerecord/lib/active_record/inheritance.rb:61:in `new'
        /home/kd/projects/kd-rails/activerecord/lib/active_record/inheritance.rb:61:in `new'
        /home/kd/projects/kd-rails/activerecord/lib/active_record/persistence.rb:50:in `create!'
        /home/kd/projects/kd-rails/activerecord/test/cases/persistence_test.rb:913:in `test_save_touch_false'

    4522 runs, 12460 assertions, 0 failures, 1 errors, 4 skips
    ```

    After:
      `bundle exec rake mysql2:test`

    ```
       Finished in 135.785086s, 33.3026 runs/s, 91.7774 assertions/s.

       4522 runs, 12462 assertions, 0 failures, 0 errors, 4 skips
    ```
2015-03-31 12:14:03 +05:30
yuuji.yaginuma
5341cbcdc1 use correct method in batches test 2015-03-29 21:19:46 +09:00