aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/reflection_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-2/+2
|
* Add a test for reflection keys as Strings, fixes #16928Zachary Scott2014-11-231-0/+4
| | | | See also PR: #17610
* Begin refactoring ThroughReflectioneileencodes2014-07-081-34/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This allows us to decouple AssociationReflection and ThroughReflection making ThroughReflection it's own Reflection bucket in a way. The benefit of this is to be able to remove checks against the macro's symbol for exmaple `macro == :belongs_to`. Get all tests passing again Some of the methods that used to be inherited from MacroReflection through AssociationReflection were no longer getting passed through. They needed to be duplicated into the ThroughReflection. I will extract these out into a separate class. Refactor shared methods into strategy object Now that we've separated ThroughReflection and AssociationReflection we can combine shared methods into one class to avoid duplication. Break out class for each type of reflection This creates a class for each reflection type (has_many, has_one, belongs_to and habtm). We then can remove the need to set the macro symbol in each initialization. Tests were updated to reflect these changes because creation of these reflections is now different. Remove need for @collection instance var We now define `collection?` as `false` by default and set it to `true` in `has_and_belongs_to_many` and `has_many` reflections. This removes the need for the `@collection` instance variable. Raise exception on unknown macro types We shouldn't accept just any macro when creating reflections. An unrecongnized AssociationReflection raises an error. Tests in `reflection_test` were updated to reflect these new changes. `:has_and_belongs_to_many` macro tests were removed because we no longer internally return HABTM.
* Add regression tests for keys on nested associationseileencodes2014-07-011-0/+32
| | | | | | This adds the regressions tests from issue #15893 to master. It's checking that both strings and symbols are accepted as keys for nested associations.
* Add a deprecation cycle for `NullColumn` from `column_for_attribute`Sean Griffin2014-06-231-18/+4
| | | | | | This is public API, and `simple_form` depends on the `nil` return value. We need to go through a deprecation cycle to return a null object. If people want hash access, they can access the hash.
* Rename `type_cast` to `type_cast_from_database`Sean Griffin2014-06-091-1/+1
| | | | | | | | In some cases there is a difference between the two, we should always be doing one or the other. For convenience, `type_cast` is still a private method on type, so new types that do not need different behavior don't need to implement two methods, but it has been moved to private so it cannot be used accidentally.
* Make `_before_type_cast` actually be before type castSean Griffin2014-06-091-1/+1
| | | | | | | | | | | | | - The following is now true for all types, all the time - `model.attribute_before_type_cast == given_value` - `model.attribute == model.save_and_reload.attribute` - `model.attribute == model.dup.attribute` - `model.attribute == YAML.load(YAML.dump(model)).attribute` - Removes the remaining types implementing `type_cast_for_write` - Simplifies the implementation of time zone aware attributes - Brings tz aware attributes closer to being implemented as an attribute decorator - Adds additional point of control for custom types
* have an actual `NullColumn` object and update docs accordingly.Yves Senn2014-06-041-0/+1
| | | | | | Follow up to #15438 and #15502. /cc @sgrif
* Return a null column when no column exists for an attributeSean Griffin2014-06-031-0/+19
|
* Merge pull request #15210 from arthurnn/fix_hbtm_reflectionArthur Neves2014-05-241-1/+6
| | | | | | | | | Fix habtm reflection Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/counter_cache.rb activerecord/lib/active_record/reflection.rb activerecord/test/cases/reflection_test.rb
* Regression test for irregular inflection on has_manyArthur Neves2014-04-181-0/+8
| | | | | | | Also add a Changelog entry [related #9702] [fixes #8928]
* Make sure the reflection test is passing a String to the reflectionLauro Caetano2014-04-091-1/+1
| | | | cache.
* PostgreSQL and SQLite, remove varchar limit. [Vladimir Sazhin & Toms Mikoss ↵Yves Senn2014-04-041-1/+1
| | | | | | | | | | | | | | | | & Yves Senn] There is no reason for the PG adapter to have a default limit of 255 on :string columns. See this snippet from the PG docs: Tip: There is no performance difference among these three types, apart from increased storage space when using the blank-padded type, and a few extra CPU cycles to check the length when storing into a length-constrained column. While character(n) has performance advantages in some other database systems, there is no such advantage in PostgreSQL; in fact character(n) is usually the slowest of the three because of its additional storage costs. In most situations text or character varying should be used instead.
* scope_chain should not be mutated for other reflectionsNeeraj Singh2013-10-141-0/+16
| | | | | | | | | | | Currently `scope_chain` uses same array for building different `scope_chain` for different associations. During processing these arrays are sometimes mutated and because of in-place mutation the changed `scope_chain` impacts other reflections. Fix is to dup the value before adding to the `scope_chain`. Fixes #3882.
* acually get the actual source reflection :cry::gun:Aaron Patterson2013-07-231-2/+3
|
* Removing not useful test related to reflect_on_all_associationsNeeraj Singh2013-07-021-8/+0
| | | | | | | | | | | | | | | | The comment in the test pretty much summarizes the issue. `FIXME these assertions bust a lot` Adding any type of association in class `Firm` will break this test. I removed some deprecated stuff and this test failed. I do not think this test provides any useful value. First of all who counted last that 39 is the right number of associations. Secondly there are a large number of tests which depend on reflection returning right information about associations. Those tests will start failing if there is a bug in the code.
* Fix tests which started to fail due to commit ↵Takehiro Adachi2013-05-181-3/+3
| | | | | | | | 0123c39f41e2062311b2197e6e230ef8ad67e20e Due to commit 0123c39f41e2062311b2197e6e230ef8ad67e20e, column topic.unique_replies_count has been added, and these test started to fail since the tests depends on the topic tables column info.
* remove duplicated require statements in AR test casesYves Senn2012-10-091-1/+0
|
* Revert "Remove :finder_sql, :counter_sql, :insert_sql, :delete_sql."Jon Leighton2012-08-011-2/+2
| | | | | | | | | This reverts commit 3803fcce26b837c0117f7d278b83c366dc4ed370. Conflicts: activerecord/CHANGELOG.md It will be deprecated only in 4.0, and removed properly in 4.1.
* Revert "Removing composed_of from ActiveRecord."Rafael Mendonça França2012-07-271-0/+24
| | | | | | | | | | | This reverts commit 14fc8b34521f8354a17e50cd11fa3f809e423592. Reason: we need to discuss a better path from this removal. Conflicts: activerecord/lib/active_record/reflection.rb activerecord/test/cases/base_test.rb activerecord/test/models/developer.rb
* Remove :finder_sql, :counter_sql, :insert_sql, :delete_sql.Jon Leighton2012-07-201-2/+2
|
* Represent association scope options as AR::Relations insternally.Jon Leighton2012-07-131-19/+23
|
* Allow associations to take a lambda which builds the scopeJon Leighton2012-07-131-22/+22
|
* Add test cases for 46492949b8c09f99db78b9f7a02d039e7bc6a702Andrew White2012-06-231-0/+52
|
* Removing composed_of from ActiveRecord.Steve Klabnik2012-06-181-24/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This feature adds a lot of complication to ActiveRecord for dubious value. Let's talk about what it does currently: class Customer < ActiveRecord::Base composed_of :balance, :class_name => "Money", :mapping => %w(balance amount) end Instead, you can do something like this: def balance @balance ||= Money.new(value, currency) end def balance=(balance) self[:value] = balance.value self[:currency] = balance.currency @balance = balance end Since that's fairly easy code to write, and doesn't need anything extra from the framework, if you use composed_of today, you'll have to add accessors/mutators like that. Closes #1436 Closes #2084 Closes #3807
* remove calls to find(:first), find(:last) and find(:all)Jon Leighton2012-04-261-1/+1
|
* reflection test fixedgregolsen2012-01-311-2/+2
|
* Deprecate inferred JOINs with includes + SQL snippets.Jon Leighton2012-01-161-2/+2
| | | | | | See the CHANGELOG for details. Fixes #950.
* serialize fails on subclassAlvaro Bautista2011-12-231-5/+5
|
* Fix test as one more has_many addedArun Agrawal2011-11-041-1/+1
|
* Allow the :class_name option for associations to take a symbol.Jon Leighton2011-11-041-1/+5
| | | | | This is to avoid confusing newbies, and to be consistent with the fact that other options like :foreign_key already allow a symbol or a string.
* Fix #3271.Jon Leighton2011-11-031-0/+6
| | | | | | | | Building the conditions of a nested through association could potentially modify the conditions of the through and/or source association. This is a Bad Thing.
* Raise an exception on unknown primary key inside AssociationReflection.Jon Leighton2011-10-051-0/+15
| | | | | An association between two models cannot be made if a relevant key is unknown, so fail fast rather than generating invalid SQL. Fixes #3207.
* Don't call self.class unless necessary. Closes #3171.Jon Leighton2011-09-291-0/+1
|
* Fix belongs_to polymorphic with custom primary key on target.Jon Leighton2011-09-261-1/+0
| | | | Closes #3104.
* cache the plural name on the reflection so we do not pay pluralize costs on ↵Aaron Patterson2011-06-301-1/+1
| | | | joins
* please use ruby -I lib:test path/to/test.rb, or export RUBY_OPTAaron Patterson2011-06-061-1/+1
|
* Refactor Active Record test connection setup. Please see the ↵Jon Leighton2011-06-041-1/+1
| | | | RUNNING_UNIT_TESTS file for details, but essentially you can now configure things in test/config.yml. You can also run tests directly via the command line, e.g. ruby path/to/test.rb (no rake needed, uses default db connection from test/config.yml). This will help us fix the CI by enabling us to isolate the different Rails versions to different databases.
* removed deprecated methods, and related tests, from ActiveRecordJosh Kalderimis2011-05-251-7/+0
|
* Fix problem with loading polymorphic associations which have been defined in ↵Jon Leighton2011-05-221-2/+2
| | | | an abstract superclass. Fixes #552.
* oracle, y u defy meJon Leighton2011-03-161-5/+5
|
* Simplify implementation of ThroughReflection#chainJon Leighton2011-03-111-1/+1
|
* Rename Reflection#through_reflection_chain and #through_options to ↵Jon Leighton2011-03-101-5/+5
| | | | Reflection#chain and Reflection#options as they now no longer relate solely to through associations.
* Push source_type and polymorphic conditions out of ThroughAssociation and ↵Jon Leighton2011-03-051-2/+2
| | | | JoinDependency::JoinAssociation and into the reflection instead.
* Merge branch 'master' into nested_has_many_throughJon Leighton2011-03-041-5/+24
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: activerecord/CHANGELOG activerecord/lib/active_record/association_preload.rb activerecord/lib/active_record/associations.rb activerecord/lib/active_record/associations/class_methods/join_dependency.rb activerecord/lib/active_record/associations/class_methods/join_dependency/join_association.rb activerecord/lib/active_record/associations/has_many_association.rb activerecord/lib/active_record/associations/has_many_through_association.rb activerecord/lib/active_record/associations/has_one_association.rb activerecord/lib/active_record/associations/has_one_through_association.rb activerecord/lib/active_record/associations/through_association_scope.rb activerecord/lib/active_record/reflection.rb activerecord/test/cases/associations/has_many_through_associations_test.rb activerecord/test/cases/associations/has_one_through_associations_test.rb activerecord/test/cases/reflection_test.rb activerecord/test/cases/relations_test.rb activerecord/test/fixtures/memberships.yml activerecord/test/models/categorization.rb activerecord/test/models/category.rb activerecord/test/models/member.rb activerecord/test/models/reference.rb activerecord/test/models/tagging.rb
| * Construct an actual ActiveRecord::Relation object for the association scope, ↵Jon Leighton2011-01-071-2/+2
| | | | | | | | rather than a hash which is passed to apply_finder_options. This allows more flexibility in how the scope is created, for example because scope.where(a, b) and scope.where(a).where(b) mean different things.
| * Implement deprecated version of AssociationReflection#primary_key_name, ↵Jon Leighton2011-01-031-0/+12
| | | | | | | | which has been renamed to #foreign_key. Also bumping the deprecation_horizon in Active Support to 3.1.
| * Have a proper AssociationReflection#foreign_type method rather than using ↵Jon Leighton2011-01-031-0/+6
| | | | | | | | options[:foreign_type]
| * Rename AssociationReflection#primary_key_name to foreign_key, since the ↵Jon Leighton2010-12-311-3/+5
| | | | | | | | options key which it relates to is :foreign_key
| * Improved strategy for updating a belongs_to association when the foreign key ↵Jon Leighton2010-12-231-0/+2
| | | | | | | | changes. Rather than resetting each affected association when the foreign key changes, we should lazily check for 'staleness' (where fk does not match target id) when the association is accessed.