aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/inheritance_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Do not use default attributes for STI when instantiating a subclassSean Griffin2016-01-271-0/+4
| | | | | | | | | | The commit which originally added this behavior did not consider that doing `Subclass.new` does not actually populate the `type` field in the attributes (though perhaps it should). We simply need to not use the defaults for STI related things unless we are instantiating the base class. Fixes #23285.
* Fix test failure on PostgreSQL by sorting the result before comparisonPrathamesh Sonpatki2016-01-191-4/+5
|
* run `type` column through attribtues API type casting.Yves Senn2016-01-191-0/+75
| | | | | | | Closes #21986. This makes it possible to write custom types that define a different mapping for STI columns.
* don't rely on the columns hash to get defaults. follow-up to #17169.Yves Senn2015-12-021-0/+24
| | | | | | This will also get the defaults from attribute definitions like: attribute :type, :string, default: "SomethingElse"
* Merge pull request #17169 from kuldeepaggarwal/fix-STI-default-typeYves Senn2015-12-021-0/+21
|\ | | | | | | STI cast new instances to `default type` on initialize.
| * STI cast new instances to `default type` on initialize.Kuldeep Aggarwal2015-12-021-0/+20
|/ | | | fixes #17121
* Move some AR test cases to inheritance_test.rbyui-knk2015-10-311-1/+80
| | | | | | | | These methods are defined in inheritance.rb * `abstract_class?` * `descends_from_active_record?` * `compute_type`
* Revert "Merge pull request #21994 from mtodd/inherit-scopes"Rafael Mendonça França2015-10-271-2/+2
| | | | | | | This reverts commit 60c9701269f5b412849f1a507df61ba4735914d7, reversing changes made to 6a25202d9ea3b4a7c9f2d6154b97cf8ba58403db. Reason: Broken build
* Make inherited scope test failMatt Todd2015-10-261-2/+2
| | | | | | | | | | | | | | This triggers the JoinDependency work to reflect on the associations and trigger an error as follows: ActiveRecord::ConfigurationError: Association named 'account' was not found on Company; perhaps you misspelled it? Fix Company.of_first_firm joins association name Should be `Company.joins(:accounts)` not `Company.joins(:account)`. Do the same for Client.of_first_firm
* invalid sti error message contains the full class name.Yves Senn2015-05-131-0/+11
| | | | | | | This can resolve confusing situation when a top level constant exists but a namespaced version is identified. Related to #19531.
* Merge branch 'sti-subclass-from-attributes' of ↵Yves Senn2015-05-131-0/+7
|\ | | | | | | | | | | | | https://github.com/agrobbin/rails into agrobbin-sti-subclass-from-attributes Conflicts: activerecord/CHANGELOG.md
| * allow setting of a demodulized class name when using STIAlex Robbin2015-05-111-0/+8
|/ | | | | | | | | | | | | | | | | | | | | 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.
* tests, extract helpers to modify global state.Yves Senn2015-05-071-46/+55
| | | | | | | | | 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.
* Always reset changed attributes in becomesMiklos Fazekas2015-02-041-0/+6
| | | | | | | | | | When ```becomes``` changes @attributes it should also change @changed_attributes. Otherwise we'll experience a kind of split head situation where attributes are coming from ```self```, but changed_attributes is coming from ```klass.new```. This affects the inheritance_colmn as it's changed by new for example. Fixes #16881
* Test association was eager loaded, rather than reaching into internalsSean Griffin2015-01-261-2/+2
|
* Go through normal `where` logic when preloading associationsSean Griffin2014-12-261-1/+1
| | | | | | | | | | This will allow eager type casting to take place as needed. There doesn't seem to be any particular reason that the `in` statement was forced for single values, and the commit message where it was introduced gives no context. See https://github.com/rails/rails/commit/d90b4e2615e8048fdeffc6dffe3246704adee01f
* Improve the performance of reading attributesSean Griffin2014-11-181-1/+1
| | | | | | | We added a comparison to "id", and call to `self.class.primary_key` a *lot*. We also have performance hits from `&block` all over the place. We skip the check in a new method, in order to avoid breaking the behavior of `read_attribute`
* Remove dead test code for unsupported adaptersSean Griffin2014-05-171-8/+0
|
* Use teardown helper method.Guo Xiang Tan2014-03-141-1/+1
| | | | | | | | Follow-Up to https://github.com/rails/rails/pull/14348 Ensure that SQLCounter.clear_log is called after each test. This is a step to prevent side effects when running tests. This will allow us to run them in random order.
* Ensure AR #second, #third, etc. finders work through associationsJason Meller2014-01-211-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit fixes two regressions introduced in cafe31a078 where newly created finder methods #second, #third, #forth, and #fifth caused a NoMethodError error on reload associations and where we were pulling the wrong element out of cached associations. Examples: some_book.authors.reload.second # Before # => NoMethodError: undefined method 'first' for nil:NilClass # After # => #<Author id: 2, name: "Sally Second", ...> some_book.first.authors.first some_book.first.authors.second # Before # => #<Author id: 1, name: "Freddy First", ...> # => #<Author id: 1, name: "Freddy First", ...> # After # => #<Author id: 1, name: "Freddy First", ...> # => #<Author id: 2, name: "Sally Second", ...> Fixes #13783.
* Don't try to get the subclass if the inheritance column doesn't existUjjwal Thaakar2014-01-141-1/+8
| | | | | | | The `subclass_from_attrs` method is called even if the column specified by the `inheritance_column` setting doesn't exist. This prevents setting associations via the attributes hash if the association name clashes with the value of the setting, typically `:type`. This worked previously in Rails 3.2.
* fix bug in becomes! when changing from base to subclass. Closes #13272.Yves Senn2014-01-131-0/+11
|
* Change all "can not"s to the correct "cannot".T.J. Schuck2014-01-031-2/+2
|
* Port test from cf1904f to avoid future regressionPrem Sichanugrist2013-10-031-1/+5
| | | | Related issue: #11939, #12084
* Fix #new with an STI object with complex inheritanceNate Berkopec2013-04-021-0/+4
|
* move tests out from base_test.rbTakehiro Adachi2013-03-181-0/+14
| | | | | These tests should be in inheritance_test.rb since its testing a feature which is implemented in inheritance.rb
* add an missing assertion to inheritance_test.rbTakehiro Adachi2013-03-111-0/+1
| | | | | | assertion for https://github.com/rails/rails/blob/ad624345e54bd20802de67b2b5c9ef29ecf5 d5f4/activerecord/lib/active_record/inheritance.rb#L32
* Fix ActiveRecord `subclass_from_attrs` when eager_load is false.Dmitry Vorotilin2013-03-061-0/+11
| | | | | It cannot find subclass because all classes are loaded automatically when it needs.
* User assert_kind_of, invert assert_equal expectationsCarlos Antonio da Silva2012-11-291-3/+3
|
* Added STI support to init and building associationsJason Rush2012-11-291-0/+23
| | | | | | | | Allows you to do BaseClass.new(:type => "SubClass") as well as parent.children.build(:type => "SubClass") or parent.build_child to initialize an STI subclass. Ensures that the class name is a valid class and that it is in the ancestors of the super class that the association is expecting.
* Remove ActiveRecord::ModelJon Leighton2012-10-261-10/+1
| | | | | | | | | | In the end I think the pain of implementing this seamlessly was not worth the gain provided. The intention was that it would allow plain ruby objects that might not live in your main application to be subclassed and have persistence mixed in. But I've decided that the benefit of doing that is not worth the amount of complexity that the implementation introduced.
* test cleanup, remove ruby_type because it's no longer neededYves Senn2012-09-031-1/+1
| | | | | All tests with a custom inheritance_column use the `Vegtable` model. The field ruby_type on the Company models is no longer needed
* rewrite inheritance tests with a custom inheritance_columnYves Senn2012-09-031-48/+38
| | | | | | previously the tests with and without a custom `inheritance_column` used the same models. Since the model then has both fields this can lead to false positives.
* set the configured #inheritance_column on #become (#7503)Yves Senn2012-09-031-1/+9
| | | | | | | | | | | | | | | I had to create a new table because I needed an STI table, which does not have both a "type" and a "custom_type" the test fails with: 1) Error: test_alt_becomes_works_with_sti(InheritanceTest): NoMethodError: undefined method `type=' for #<Cabbage id: 1, name: "my cucumber", custom_type: "Cucumber"> /Users/username/Projects/rails/activemodel/lib/active_model/attribute_methods.rb:432:in `method_missing' /Users/username/Projects/rails/activerecord/lib/active_record/attribute_methods.rb:100:in `method_missing' /Users/username/Projects/rails/activerecord/lib/active_record/persistence.rb:165:in `becomes' test/cases/inheritance_test.rb:134:in `test_becomes_works_with_sti' test/cases/inheritance_test.rb:140:in `test_alt_becomes_works_with_sti'
* Remove ActiveRecord::Base.to_aJon Leighton2012-08-031-2/+2
| | | | | On reflection, it seems like a bit of a weird method to have on ActiveRecord::Base, and it shouldn't be needed most of the time anyway.
* Deprecate ActiveRecord::Base.scoped.Jon Leighton2012-07-271-12/+12
| | | | | | | It doesn't serve much purpose now that ActiveRecord::Base.all returns a Relation. The code is moved to active_record_deprecated_finders.
* ActiveRecord::Base.all returns a Relation.Jon Leighton2012-07-271-6/+6
| | | | | | | | | | | Previously it returned an Array. If you want an array, call e.g. `Post.to_a` rather than `Post.all`. This is more explicit. In most cases this should not break existing code, since Relations use method_missing to delegate unknown methods to #to_a anyway.
* Refactor ActiveRecord::Inheritance.base_class logicbeerlington2012-07-261-0/+30
| | | | | | | | | Moved logic from class_of_active_record_descendant(class) to the base_class method. This method was confusing because it required an argument, but that argument was 'self'. Moved base_class tests to inheritance_test.rb and added some test coverage for some untested cases.
* remove deprecated callsJon Leighton2012-04-271-2/+2
|
* find and replace deprecated keysJon Leighton2012-04-271-7/+7
|
* %s/find(:\(first\|last\|all\), \([^()]*\))/scoped(\2).\1/gcI amongst other ↵Jon Leighton2012-04-271-10/+10
| | | | things
* remove calls to find(:first), find(:last) and find(:all)Jon Leighton2012-04-261-4/+4
|
* Support establishing connection on ActiveRecord::Model.Jon Leighton2011-12-281-1/+0
| | | | | This is the 'top level' connection, inherited by any models that include ActiveRecord::Model or inherit from ActiveRecord::Base.
* Deprecate set_inheritance_column in favour of self.inheritance_column=Jon Leighton2011-11-291-2/+2
|
* 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.
* Rewrote AssociationPreload.Jon Leighton2011-02-281-1/+1
|
* just use a hash for doing association cachingAaron Patterson2011-01-071-1/+1
|
* take more advantage of arel sql compilerAaron Patterson2010-12-251-1/+1
|
* stop redifining methods on every call to set_primary_keyAaron Patterson2010-12-241-0/+4
|