This project is archived and is in readonly mode.
Advanced / foxy fixture features doesn't work well with models in modules
-
kmpm
missed adding the patch
-
Kane
Hey,
I took your tests modifed them to reflect #1976 Scaffold generator not working well with namespaced resources so fixtures are in subfolders representing the namespace for organisational purpose. generators should now generate the fixtures and models (no namespace in tablename) correctly.
also modified fixtures:load but no clue how to test it.
-
José Valim
@Kane, awesome! I have some small feedback about the patch:
1) This code repeats in three parts in the patch:
namespace = Fixtures.extract_namespace(fixture_file) class_name = Fixtures.build_class_name(table_name, namespace) Fixtures.try_to_load_dependency(class_name.underscore) class_name if Fixtures.class_exists? class_nameCould you put it in its own method?
2) There is a "debug" line in the patch:
if table_names.include?'albums' puts table_names.inspect puts class_names.inspect end3) One question, why do you have split, prune and join the namespace?
namespace = namespace.split('/')[0..-2].join('/')4) And there is no need to add the generators changes on this patch. We will do that in #1976 Scaffold generator not working well with namespaced resources. :)
Good work, thanks!
-
Kane
thanks for the feedback
i removed all generator specific changes and the debug lines.
also made refactoring to reduce the repeating code. and to 3) i assume you mean line 510, its to remove the classname. -
Kane
- Assigned user set to Jeremy Kemper
-
gjeudy
Is there a workaround for this bug? using set_fixture_class doesn't help in my case. I'm trying the same thing a bidirectional one-to-many association with foxy fixtures.
-
Andrew White
Attached patch adds support for namespaced model fixtures. Fixture name uses '/' to specify the namespace, so to use in a test you'd do something like this:
class Admin::AccountTest < ActiveSupport::TestCase fixtures :"admin/accounts" def test_something assert admin_accounts(:fixture_name) end endCode isn't as clean as I'd like but I'm guessing you don't want a major refactoring of fixtures at this point. It should be possible to backport this to 2-3-stable if desired as soon as the backport of #2283 Unnecessary exception raised in AS::Dependencies.load_missing_constant is applied.
I was in two minds over stripping the namespace off the fixture accessor - what do you think?
-
José Valim
- Assigned user changed from Jeremy Kemper to José Valim
- Milestone cleared.
-
Andrew White
It would help if I included the fixtures and models. Got burned (again!) by the fact that git commit -a doesn't include new files.
-
José Valim
Hey Andrey, sorry for the delay but the patch does not apply anymore. Can you please rebase it?
Also, what is the deal with #2283 Unnecessary exception raised in AS::Dependencies.load_missing_constant? It's marked as resolved, but the problem still persists for you?Finally, I'm -1 in back porting these changes to 2.3 since I don't want to make significative changes and break plugins in a maintenance branch.
-
Andrew White
Rebased patch attached.
The issue with #2283 Unnecessary exception raised in AS::Dependencies.load_missing_constant is that I backported the patch but it's never been applied to 2-3-stable. Since I was asked to backport #4032 Module specific table_name_prefix I thought there was an attempt to get nested models working the same in 2.3 and 3.0, which is why I suggested backporting this patch.
-
Repository
- State changed from new to resolved
(from [8ec085bf1804770a547894967fcdee24087fda87]) Support fixtures for namespaced models [#2965 Advanced / foxy fixture features doesn't work well with models in modules state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/8ec085bf1804770a547894967fcdee... -
José Valim
Awesome, thanks for the patch! Imho, there is no need to backport for 2-3-stable. If anyone else is interested, they can apply it.
