This project is archived and is in readonly mode.
Advanced / foxy fixture features doesn't work well with models in modules
Reported by kmpm | July 28th, 2009 @ 03:37 PM | in 3.0.2
If models reside within modules then fixture loading doesn't
work when you use advanced / foxy fixture features like label
references.
The attached patch adds some tests that fail already when
loading.
test_relations(FoxyFixturesInModulesTest):<br/>
ActiveRecord::StatementInvalid: SQLite3::SQLException: table tracks
has no column named album: INSERT INTO "tracks" ("title", "album")
VALUES ('Foxy Lady', 'album1')<br/>
One could argue the set_table_name and/or set_fixture_class should be used but that is certainly not convention over configuration and you can't do set_fixture_class when doing a rake db:fixtures:load.
According to #1976 so should fixtures for a module possibly be in a folder with the fixture name by default but that makes the current situation even worse.
Comments and changes to this ticket
-
Kane August 16th, 2009 @ 03:13 AM
Hey,
I took your tests modifed them to reflect #1976 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 August 16th, 2009 @ 08:37 AM
@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_name
Could 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 end
3) 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. :)
Good work, thanks!
-
Kane August 16th, 2009 @ 07:48 PM
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 August 28th, 2009 @ 12:39 AM
- Assigned user set to Jeremy Kemper
-
gjeudy December 3rd, 2009 @ 10:19 PM
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 April 14th, 2010 @ 06:30 PM
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 end
Code 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 is applied.
I was in two minds over stripping the namespace off the fixture accessor - what do you think?
-
José Valim April 14th, 2010 @ 08:06 PM
- Assigned user changed from Jeremy Kemper to José Valim
- Milestone cleared.
-
Andrew White April 15th, 2010 @ 06:12 AM
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 April 25th, 2010 @ 12:23 PM
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? 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.
-
Repository April 25th, 2010 @ 03:05 PM
- State changed from new to resolved
(from [8ec085bf1804770a547894967fcdee24087fda87]) Support fixtures for namespaced models [#2965 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/8ec085bf1804770a547894967fcdee... -
José Valim April 25th, 2010 @ 03:06 PM
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.
-
Jeremy Kemper October 15th, 2010 @ 11:01 PM
- Milestone set to 3.0.2
- Importance changed from to
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Tags
Referenced by
- 1976 Scaffold generator not working well with namespaced resources Kane... In #2965 I also mention the fact that when doing ...
- 4230 [PATCH] AR migration generator includes model's modules in table name. Thanks guys, applied! Can someone please tell me if #2965...
- 1628 Loading fixtures for a module's model 1) fixtures cannot be loaded when a set_table_name is use...
- 1976 Scaffold generator not working well with namespaced resources The rake tasks usually just invoke a method in a class. T...
- 2965 Advanced / foxy fixture features doesn't work well with models in modules (from [8ec085bf1804770a547894967fcdee24087fda87]) Support...
- 4230 AR migration generator includes model's modules in table name. After reading #1976 and #2965, it seems AR's table name i...
- 1976 Scaffold generator not working well with namespaced resources kmpm, i looked at #2965. I will use your tests and look i...