1. 08 8月, 2019 3 次提交
  2. 07 8月, 2019 2 次提交
    • R
      Fix GROUP BY aggregation alias to not duplicate "_" chars · e62195e2
      Ryuta Kamizono 提交于
      c9e4c848 has one performance optimization for `aggregate_alias` to early
      returning by `aggregate_alias.match?(/\A\w+\z/)`, but it is caused a
      regression that failing deduplication for non word chars #36867.
      
      I've quited the optimization and add a test to prevent a future
      regression.
      
      Fixes #36867.
      e62195e2
    • E
      Fix thread safety of prevent_writes · ff70c176
      eileencodes 提交于
      As demonstrated in the test added and in #36830 the code that prevents
      writes wasn't thread safe. If one thread does a read, then another does
      a write, and then another does a read the second read will cause the
      first write to be unwriteable.
      
      This change removes the instance variable and instead uses a
      getter/setter on Thread.current[:prevent_writes] for the connection
      handler to set whether writes are allowed.
      
      Fixes #36830
      ff70c176
  3. 05 8月, 2019 1 次提交
  4. 03 8月, 2019 3 次提交
    • Y
      Address `DEPRECATED: Use assert_nil if expecting nil` · 20772f6c
      Yasuo Honda 提交于
      ```ruby
      $ cd activerecord
      $ bin/test test/cases/dirty_test.rb:494
      ... snip ...
      DEPRECATED: Use assert_nil if expecting nil from /home/yahonda/git/rails/activerecord/test/cases/dirty_test.rb:494. This will fail in Minitest 6.
      DEPRECATED: Use assert_nil if expecting nil from /home/yahonda/git/rails/activerecord/test/cases/dirty_test.rb:511. This will fail in Minitest 6.
      .
      
      Finished in 0.061593s, 16.2356 runs/s, 795.5428 assertions/s.
      1 runs, 49 assertions, 0 failures, 0 errors, 0 skips
      $
      ```
      
      Refer seattlerb/minitest#666 rails/rails#27712
      20772f6c
    • J
      Raise TypeError instead of infinite looping · d0e95f45
      John Hawthorn 提交于
      d0e95f45
    • E
      Add ability to unset preventing writes · f2de4481
      eileencodes 提交于
      Previously if an app attempts to do a write inside a read request it will be
      impossilbe to switch back to writing to the primary. This PR adds an
      argument to the `while_preventing_writes` so that we can make sure to
      turn it off if we're doing a write on a primary.
      
      Fixes #36830
      Co-authored-by: NJohn Crepezzi <john.crepezzi@gmail.com>
      f2de4481
  5. 02 8月, 2019 6 次提交
  6. 01 8月, 2019 1 次提交
  7. 31 7月, 2019 2 次提交
    • Y
      fix a typo · b8309e85
      yamato-payforward 提交于
      b8309e85
    • K
      Polymorphic has_one touch: Reset association cache result after create transaction · cea392eb
      Kasper Timm Hansen 提交于
      In case of a polymorphic association there's no automatic inverse_of to assign the
      inverse record. So to get the record there needs to be a query executed,
      however, if the query fires within the transaction that's trying to create
      the associated record, no record can be found. And worse, the nil result is cached
      on the association so after the transaction commits the record can't be found.
      
      That's what happens if touch is enabled on a polymorphic has_one association.
      
      Consider a Comment with a commentable association that needs to be touched.
      
      For `Comment.create(commentable: Post.new)`, the existing code essentially
      does `commentable.send(:comment)` within the create transaction for the comment
      and thus not finding the comment.
      
      Now we're purposefully clearing the cache in case we've tried accessing
      the association within the transaction and found no object.
      
      Before:
      
      ```
      kaspth-imac 2.6.3 ~/code/rails/activerecord master *= ARCONN=postgresql bin/test test/cases/associations/has_one_associations_test.rb -n /commit/
      Using postgresql
      Run options: -n /commit/ --seed 46022
      
      D, [2019-07-19T03:30:37.864537 #96022] DEBUG -- :   Chef Load (0.2ms)  SELECT "chefs".* FROM "chefs" WHERE "chefs"."employable_id" = $1 AND "chefs"."employable_type" = $2 LIMIT $3  [["employable_id", 1], ["employable_type", "DrinkDesignerWithPolymorphicTouchChef"], ["LIMIT", 1]]
      D, [2019-07-19T03:30:37.865013 #96022] DEBUG -- :   Chef Create (0.2ms)  INSERT INTO "chefs" ("employable_id", "employable_type") VALUES ($1, $2) RETURNING "id"  [["employable_id", 1], ["employable_type", "DrinkDesignerWithPolymorphicTouchChef"]]
      D, [2019-07-19T03:30:37.865201 #96022] DEBUG -- :   TRANSACTION (0.1ms)  RELEASE SAVEPOINT active_record_1
      D, [2019-07-19T03:30:37.874136 #96022] DEBUG -- :   TRANSACTION (0.1ms)  ROLLBACK
      D, [2019-07-19T03:30:37.874323 #96022] DEBUG -- :   TRANSACTION (0.1ms)  ROLLBACK
      F
      
      Failure:
      HasOneAssociationsTest#test_polymorphic_has_one_with_touch_option_on_create_wont_cache_assocation_so_fetching_after_transaction_commit_works [/Users/kaspth/code/rails/activerecord/test/cases/associations/has_one_associations_test.rb:716]:
      --- expected
      +++ actual
      @@ -1 +1 @@
      -#<Chef id: 1, employable_id: 1, employable_type: "DrinkDesignerWithPolymorphicTouchChef", department_id: nil, employable_list_type: nil, employable_list_id: nil>
      +nil
      ```
      
      After:
      
      ```
      kaspth-imac 2.6.3 ~/code/rails/activerecord master *= ARCONN=postgresql bin/test test/cases/associations/has_one_associations_test.rb -n /commit/
      Using postgresql
      Run options: -n /commit/ --seed 46022
      
      D, [2019-07-19T03:30:22.479387 #95973] DEBUG -- :   Chef Create (0.3ms)  INSERT INTO "chefs" ("employable_id", "employable_type") VALUES ($1, $2) RETURNING "id"  [["employable_id", 1], ["employable_type", "DrinkDesignerWithPolymorphicTouchChef"]]
      D, [2019-07-19T03:30:22.479574 #95973] DEBUG -- :   TRANSACTION (0.1ms)  RELEASE SAVEPOINT active_record_1
      D, [2019-07-19T03:30:22.482051 #95973] DEBUG -- :   Chef Load (0.1ms)  SELECT "chefs".* FROM "chefs" WHERE "chefs"."employable_id" = $1 AND "chefs"."employable_type" = $2 LIMIT $3  [["employable_id", 1], ["employable_type", "DrinkDesignerWithPolymorphicTouchChef"], ["LIMIT", 1]]
      D, [2019-07-19T03:30:22.482317 #95973] DEBUG -- :   TRANSACTION (0.1ms)  ROLLBACK
      D, [2019-07-19T03:30:22.482437 #95973] DEBUG -- :   TRANSACTION (0.1ms)  ROLLBACK
      .
      
      Finished in 0.088498s, 11.2997 runs/s, 22.5994 assertions/s.
      1 runs, 2 assertions, 0 failures, 0 errors, 0 skips
      ```
      
      Notice the select now fires after the commit.
      cea392eb
  8. 30 7月, 2019 2 次提交
    • R
      Add `silence_warnings` for defining 'not_' prefix enum elements · fff120c7
      Ryuta Kamizono 提交于
      To suppress the following warnings in tests.
      
      ```
      ~/rails/activerecord/lib/active_record/scoping/named.rb:190: warning: method redefined; discarding old not_sent
      ~/rails/activerecord/lib/active_record/scoping/named.rb:190: warning: previous definition of not_sent was here
      ```
      fff120c7
    • R
      Preserve user supplied joins order as much as possible · b4478ae8
      Ryuta Kamizono 提交于
      Currently, string joins are always applied as last joins part, and Arel
      join nodes are always applied as leading joins part (since #36304), it
      makes people struggled to preserve user supplied joins order.
      
      To mitigate this problem, preserve the order of string joins and Arel
      join nodes either before or after of association joins.
      
      Fixes #36761.
      Fixes #34328.
      Fixes #24281.
      Fixes #12953.
      b4478ae8
  9. 29 7月, 2019 3 次提交
    • J
      Move DatabaseAlreadyExists detection to DB adapter · 69700c9e
      John Hawthorn 提交于
      Previously it was the responsibility of the database tasks to translate
      the invalid statement from creating a duplicate database into an
      ActiveRecord::Tasks::DatabaseAlreadyExists error.
      
      It's actually easier for us to do this detection inside of the adapter,
      where we already do a case statement on the return code to translate the
      error.
      
      This commit introduces ActiveRecord::DatabaseAlreadyExists, a subclass
      of StatementInvalid, and updates both AbstractMysqlAdapter and
      PostgresqlAdapter to return this more specific exception in that case.
      
      Because this is a subclass of the old exception, StatementInvalid, it
      should be backwards compatible with any code expecting that from
      create_database.
      
      This works for both create_database and exectute("CREATE DATABASE")
      69700c9e
    • J
      Enabled matches_regex for MySql · 92c265b3
      James Pearson 提交于
      Previously matches_regex was only availble on PostgreSql, this will enable it for MySql
      
      Usage example:
      
          users = User.arel_table;
          users = User.arel_table; User.where(users[:email].matches_regexp('(.*)\@gmail.com'))
      
      Update activerecord/test/cases/arel/visitors/mysql_test.rb
      Co-Authored-By: NRyuta Kamizono <kamipo@gmail.com>
      92c265b3
    • A
      Use match? where we don't need MatchData · 0196551e
      Akira Matsuda 提交于
      0196551e
  10. 28 7月, 2019 1 次提交
  11. 27 7月, 2019 5 次提交
    • T
      Allow specify fixtures to be ignored · c09a4fd2
      Tongfei Gao 提交于
      Allow specifying what fixtures can be ignored by setting
      `ignore` in fixtures YAML file:
      
          # users.yml
          _fixture:
            ignore:
              - base
      
          base: &base
            admin: false
            introduction: "This is a default description"
      
          admin:
            <<: *base
            admin: true
      
          visitor:
            <<: *base
      
      In the above example, "base" fixture will be ignored when creating
      users fixture. This is helpful when you want to inherit attributes
      and it makes your fixtures more "DRY".
      c09a4fd2
    • Y
      Avoid to use a method that acts on the hash · 121551b8
      yuuji.yaginuma 提交于
      To avoid a deprecation warning.
      121551b8
    • A
      Use match? where we don't need MatchData · d1ffe59a
      Akira Matsuda 提交于
      We're already running Performance/RegexpMatch cop, but it seems like the cop is not always =~ justice
      d1ffe59a
    • J
      Allow separate database env variables per-connection · 7df0eefa
      John Crepezzi 提交于
      This commit adds a feature which allows separate database ENV variables
      to be defined for each spec in a 3-tier config. The names for the
      environment variables will be `#{name.upcase}_DATABASE_URL`
      
      This commit also introduces a change in behavior around handling of
      `DATABASE_URL`. Instead of using `DATABASE_URL` to change _all_ specs
      in a multi-database configuration, it will now only affect the `primary`
      connection.
      7df0eefa
    • R
      Merge pull request #36372 from instructure-bridge/6-0-stable · 344bed41
      Rafael França 提交于
      Don't break configurations.each, .first before the deprecation period
      344bed41
  12. 26 7月, 2019 3 次提交
    • T
      Fix join middle table alias when using HABTM · 285f081e
      Takayuki Nakata 提交于
      In using HABTM, join middle table alias is combined with the associated
      models name without sort, while middle table name is combined with those
      models name with sort.
      
      Fixes #36742.
      285f081e
    • J
      Only merge DATABASE_URL settings into the current env · 5e260574
      John Crepezzi 提交于
      This commit fixes a regression where when the `DATABASE_URL` environment
      variable was set and the current Rails environment had a valid configuration
      defined in the database config, settings from the environment variable would
      affect _all_ environments (not just the current one).
      5e260574
    • J
      Use connection.error_number in MySQLDatabaseTasks · 15c81c8e
      John Hawthorn 提交于
      MySQLDatabaseTasks, like AbstractMysqlAdapter, should be able to operate
      on any mysql adapter, not just mysql2. Errors having a .error_number
      attribute is a mysql2 specific API, which we (Rails) don't control, so
      we should instead use connection.error_number(err), which we do.
      
      This also updates tests to better test how this really works, previously
      it stubbed create_database to raise Tasks::DatabaseAlreadyExists, which
      can never happen.
      15c81c8e
  13. 25 7月, 2019 2 次提交
    • S
      Fix index_exists? for PostgreSQL expression indexes · ec0dc76c
      Stan Hu 提交于
      Previously Rails expected indexes to be an array of columns, but for
      PostgreSQL a expression index can just be a string of text. Handle this
      by forcing `Index#columns` to be an Array inside `index_exists?`.
      
      Closes #36739
      ec0dc76c
    • J
      Fix multiple database support for DATABASE_URL env variable · 396dba08
      John Crepezzi 提交于
      This commit fixes an issue where multi-database configurations were
      incompatible with setting a `DATABASE_URL` environment variable.
      
      As part of this work, this commit also includes a light refactor
      to make both multi and single database configurations lead into the same
      code path so they behave the same.
      
      As mentioned in #36736, this regression was introduced as part of
      f2ad69fe
      396dba08
  14. 19 7月, 2019 1 次提交
  15. 17 7月, 2019 3 次提交
  16. 16 7月, 2019 2 次提交
    • E
      Move the `ActiveModel:Errors#full_message` method to the `Error` class: · b677aded
      Edouard CHIN 提交于
      - One regression introduced by the "AM errors as object" features is
        about the `full_messages` method.
      
        It's currently impossible to call that method if the `base` object
        passed in the constructor of `AM::Errors` doesn't respond to the
        `errors` method.
        That's because `full_messages` now makes a weird back and forth trip
      
        `AM::Errors#full_messages` -> `AM::Error#full_message` -> `AM::Errors#full_message`
      
        Since `full_message` (singular) isn't needed by AM::Errors, I moved
        it to the `AM::Error` (singular) class. This way we don't need to
        grab the `AM::Errors` object from the base.
      b677aded
    • W
      Don't validate non dirty association targets · 6ea80b61
      Will Jessop 提交于
      Fixes #36581.
      
      This fixes an issue where validations would return differently when a previously saved invalid association was loaded between calls:
      
          assert_equal true, squeak.valid?
          assert_equal true, squeak.mouse.present?
          assert_equal true, squeak.valid?
      
      Here the second assert would return
      
          Expected: true
          Actual: false
      
      Limiting validations to associations that would be normally saved (using autosave: true) due to changes means that loading invalid associated relations will not change the return value of the parent relations's `valid?` method.
      6ea80b61