Permalink
Switch branches/tags
Commits on Apr 6, 2017
  1. Improve logging when Origin header doesn't match

    jonleighton committed Apr 6, 2017
    I came up against this while dealing with a misconfigured server. The
    browser was setting the Origin header to "https://example.com", but the
    Rails app returned "http://example.com" from request.base_url (because
    it was failing to detect that HTTPS was used).
    
    This caused verify_authenticity_token to fail, but the message in the
    log was "Can't verify CSRF token", which is confusing because the
    failure had nothing to do with the CSRF token sent in the request. This
    made it very hard to identify the issue, so hopefully this will make it
    more obvious for the next person.
Commits on Feb 25, 2014
  1. Merge remote-tracking branch 'chancancode/fix_instance_method_already…

    jonleighton committed Feb 25, 2014
    …_implemented'
    
    Conflicts:
    	activerecord/CHANGELOG.md
Commits on Feb 23, 2014
Commits on Jan 4, 2014
  1. Fix mergefail in changelog

    jonleighton committed Jan 4, 2014
    The line was duplicated
Commits on Jan 2, 2014
  1. Merge pull request #13528 from jonleighton/maintain_test_schema

    jonleighton committed Jan 2, 2014
    Automatically maintain test database schema
  2. Automatically maintain test database schema

    jonleighton committed Dec 29, 2013
    * Move check from generated helper to test_help.rb, so that all
      applications can benefit
    * Rather than just raising when the test schema has pending migrations,
      try to load in the schema and only raise if there are pending
      migrations afterwards
    * Opt out of the check by setting
      config.active_record.maintain_test_schema = false
    * Deprecate db:test:* tasks. The test helper is now fully responsible
      for maintaining the test schema, so we don't need rake tasks for this.
      This is also a speed improvement since we're no longer reloading the
      test database on every call to "rake test".
Commits on Dec 4, 2013
  1. Merge pull request #12958 from jonleighton/spring

    jonleighton committed Dec 4, 2013
    Install Spring preloader when generating new applications
Commits on Dec 3, 2013
Commits on Nov 20, 2013
  1. Fix ActiveRecord::Relation#unscope

    jonleighton committed Nov 20, 2013
    I'm pretty confused about the addition of this method. The documentation
    says that it was intended to allow the removal of values from the
    default scope (in contrast to #except). However it behaves exactly the
    same as except: https://gist.github.com/jonleighton/7537008 (other than
    having a slightly enhanced syntax).
    
    The removal of the default scope is allowed by
    94924dc, which was not a change we
    could make until 4.1 due to the need to deprecate things. However after
    that change #unscope still gives us nothing that #except doesn't already
    give us.
    
    However there *is* a desire to be able to unscope stuff in a way that
    persists across merges, which would allow associations to be defined
    which unscope stuff from the default scope of the associated model. E.g.
    
      has_many :comments, -> { unscope where: :trashed }
    
    So that's what this change implements. I've also corrected the
    documentation. I removed the guide references to #except as I think
    unscope really supercedes #except now.
    
    While we're here, there's also a potential desire to be able to write
    this:
    
      has_many :comments, -> { unscoped }
    
    However, it doesn't make sense and would not be straightforward to
    implement. While with #unscope we're specifying exactly what we want to
    be removed from the relation, with "unscoped" we're just saying that we
    want it to not have some things which were added earlier on by the
    default scope. However in the case of an association, we surely don't
    want *all* conditions to be removed, otherwise the above would just
    become "SELECT * FROM comments" with no foreign key constraint.
    
    To make the above work, we'd have to somehow tag the relation values
    which get added when evaluating the default scope in order to
    differentiate them from other relation values. Which is way too much
    complexity and therefore not worth it when most use cases can be
    satisfied with unscope.
    
    Closes #10643, #11061.
Commits on Jun 28, 2013
  1. Simplify/fix implementation of default scopes

    jonleighton committed Jun 28, 2013
    The previous implementation was necessary in order to support stuff
    like:
    
        class Post < ActiveRecord::Base
          default_scope where(published: true)
          scope :ordered, order("created_at")
        end
    
    If we didn't evaluate the default scope at the last possible moment
    before sending the SQL to the database, it would become impossible to
    do:
    
        Post.unscoped.ordered
    
    This is because the default scope would already be bound up in the
    "ordered" scope, and therefore wouldn't be removed by the
    "Post.unscoped" part.
    
    In 4.0, we have deprecated all "eager" forms of scopes. So now you must
    write:
    
        class Post < ActiveRecord::Base
          default_scope { where(published: true) }
          scope :ordered, -> { order("created_at") }
        end
    
    This prevents the default scope getting bound up inside the "ordered"
    scope, which means we can now have a simpler/better/more natural
    implementation of default scoping.
    
    A knock on effect is that some things that didn't work properly now do.
    For example it was previously impossible to use #except to remove a part
    of the default scope, since the default scope was evaluated after the
    call to #except.
  2. Apply default scope when joining associations.

    jonleighton committed Apr 19, 2013
    For example:
    
        class Post < ActiveRecord::Base
          default_scope -> { where published: true }
        end
    
        class Comment
          belongs_to :post
        end
    
    When calling `Comment.join(:post)`, we expect to receive only
    comments on published posts, since that is the default scope for
    posts.
    
    Before this change, the default scope from `Post` was not applied,
    so we'd get comments on unpublished posts.
  3. Fix test

    jonleighton committed Jun 28, 2013
    Oops. We need to estalish/remove the connection in the setup/teardown,
    else it messes with the fixtures.
  4. Fix rake test_sqlite3_mem

    jonleighton committed Jun 28, 2013
    Clearly nobody uses this except me. It's fast people!
  5. Merge pull request #11153 from strzalek/remove-ar-deprecated-finders

    jonleighton committed Jun 28, 2013
    Remove depreacted finders
Commits on Jun 22, 2013
  1. Merge pull request #10796 from neerajdotname/10669

    jonleighton committed Jun 22, 2013
    flatten merged join_values before building the joins
Commits on Jun 21, 2013
  1. Merge pull request #11051 from neerajdotname/10509f

    jonleighton committed Jun 21, 2013
    do not load all child records for inverse case
  2. Merge pull request #11049 from neerajdotname/no-need-of-large-number

    jonleighton committed Jun 21, 2013
    fix bad test by making number that fits for integer
Commits on Jun 19, 2013
  1. Revert "Merge pull request #10566 from neerajdotname/10509d"

    jonleighton committed Jun 19, 2013
    This reverts commit 2b817a5, reversing
    changes made to 353a398.
    
    Conflicts:
    	activerecord/CHANGELOG.md
    
    Reason: the build broke
Commits on Jun 18, 2013
  1. Merge pull request #10566 from neerajdotname/10509d

    jonleighton committed Jun 18, 2013
    do not load all child records for inverse case
Commits on Jun 9, 2013
  1. Merge pull request #10710 from senny/5554_let_the_database_raise_on_c…

    jonleighton committed Jun 9, 2013
    …ounts
    
    Remove column restrictions for `#count`, let the database raise if the SQL is invalid.
  2. Merge pull request #10886 from wangjohn/chnges_for_automatic_inverse_…

    jonleighton committed Jun 9, 2013
    …associations
    
    Documentation and cleanup of automatic discovery of inverse associations
Commits on Jun 7, 2013
  1. Revert "Merge pull request #10539 from davidcelis/ar-sql-improvements"

    jonleighton committed Jun 7, 2013
    This reverts commit 257fa68, reversing
    changes made to 94725b8.
    
    The build failed
    
    https://travis-ci.org/rails/rails/builds/7883546
  2. Merge pull request #10539 from davidcelis/ar-sql-improvements

    jonleighton committed Jun 7, 2013
    Improve performance of ActiveRecord::Relation#blank?
  3. Merge pull request #10561 from Empact/nix-throwresult

    jonleighton committed Jun 7, 2013
    Rather than raising ThrowResult when construct_limited_ids_conditions comes up empty, set the relation to NullRelation and rely on its results.
Commits on May 10, 2013
  1. Merge pull request #6792 from Empact/postgres-distinct

    jonleighton committed May 10, 2013
    Fix that #exists? can produce invalid SQL: "SELECT DISTINCT DISTINCT"
  2. Set the inverse when association queries are refined

    jonleighton committed Apr 25, 2013
    Suppose Man has_many interests, and inverse_of is used.
    
    Man.first.interests.first.man will correctly execute two queries,
    avoiding the need for a third query when Interest#man is called. This is
    because CollectionAssociation#first calls set_inverse_instance.
    
    However Man.first.interests.where("1=1").first.man will execute three
    queries, even though this is obviously a subset of the records in the
    association.
    
    This is because calling where("1=1") spawns a new Relation object from
    the CollectionProxy object, and the Relation has no knowledge of the
    association, so it cannot set the inverse instance.
    
    This commit solves the problem by making relations spawned from
    CollectionProxies return a new Relation subclass called
    AssociationRelation, which does know about associations. Records loaded
    from this class will get the inverse instance set properly.
    
    Fixes #5717.
    
    Live commit from La Conf! 
Commits on May 3, 2013
  1. Merge pull request #9426 from exviva/nested_attributes_reuse_existing…

    jonleighton committed May 3, 2013
    …_new_record
    
    Do not overwrite manually built records during one-to-one nested attribute assignment
  2. Merge pull request #10417 from jholton/fix_association_auto_save

    jonleighton committed May 3, 2013
    autosave_association issue that occurs when table has unique index (resubmission)
  3. Revert "Merge pull request #10433 from wangjohn/making_callbacks_more…

    jonleighton committed May 3, 2013
    …_performant"
    
    This reverts commit 09751fd, reversing
    changes made to 6a5ab08.
    
    This change caused a failure in
    actionpack/test/abstract/callbacks_test.rb.
  4. Work around change in how MiniTest detects SIGINFO

    jonleighton committed May 3, 2013
    MiniTest 4.7.3 detects the presence of SIGINFO and stores the answer in
    a constant.
    
    It seems that MiniTest 4.7.4 changes this, and instead relies on an
    info_signal method being implemented on the runner object.
    
    In ActiveSupport::Testing::Isolation, we use ProxyTestResult to stand in
    for the runner object. This object implements `method_missing`, and as
    such its #info_signal method has a truthy return value. This results in
    MiniTest trying to install the SIGINFO handler on platforms where
    SIGINFO does not exists.
    
    To fix, I am simply defining an explicit ProxyTestResult#info_signal
    method.
  5. Fix broken mysql test

    jonleighton committed May 3, 2013
    test_mysql_integer_not_null_defaults in test/cases/defaults_test.rb was
    failing. This test relies on the connection being in strict mode. By
    default a new connection is not in strict mode, but Active Record
    automatically places it in strict mode.
    
    ActiveSchemaTest overwrites the connection's #execute method in order to
    prevent SQL statements from actually being executed. One of the
    operations which is performed in ActiveSchema test is a #recreate_database.
    
    Since 2088bf2, recreate_database on
    mysql or mysql2 will trigger a reconnect.
    
    Due to the implementation of the hacking of #execute in
    ActiveSchemaTest, this reconnect would take place, but the connection
    would *not* be placed in strict mode because #execute had been
    overridden to prevent SQL queries hitting the database.
    
    Therefore, after ActiveSchemaTest, the connection would no longer be in
    strict mode, causing test_mysql_integer_not_null_defaults to fail.
    
    I don't think that the way that ActiveSchemaTest is implemented is
    particularly nice or clean, but I have taken steps to make its hacks
    more isolated - it now create a separate connection object which is
    thrown away after the test, and the hacks are applied on the singleton
    class of this object.
Commits on Apr 19, 2013
  1. Revert "Merge pull request #10183 from jholton/fix_association_auto_s…

    jonleighton committed Apr 19, 2013
    …ave"
    
    This reverts commit e8727d3, reversing
    changes made to d098e1c.
    
    Reason: it broke the mysql build
  2. Merge pull request #10183 from jholton/fix_association_auto_save

    jonleighton committed Apr 19, 2013
    autosave_association issue that occurs when table has unique index