Dynamic find_or_create_by_x_and_y always creates new records in Rails 2.3.11 #331

Closed
wants to merge 1 commit into
from
Commits on Apr 28, 2011
  1. Fixing dynamic finders on associations to properly send arguments to …

    daphonz committed Apr 28, 2011
    …the find_by_* method. Closes issue #330.
    
    Commit fdfc8e3 introduced a bugfix to prevent additional values passed
    to a dynamic find_or_create_by_x methods from confusing the finder.
    This patch also broke the essential behavior of this method on an
    association by incorrectly sending arguments to the find_by_x methods.
    The finder method would always see its inputs as a single array of
    values instead of individual arguments, almost guaranteeing that the
    finder call would be incorrect, and that we'd always create a new
    record instead.
    
    This patch adds a splat operator to the parameter array we send along to
    the dynamic finder so that it receives its inputs correctly, and
    includes an additional test to ensure that repeated calls to
    find_or_create_by_x only creates one new record.