So, I sat down to use set_fixture_class, and it bombed on the first thing I tried: set_fixture_class :content_drafts => "Article::Draft" I made a quick patch, and I''d appreciate a quick run through your tests to make sure it doesn''t disturb anything: http://dev.rubyonrails.org/ticket/4095 As I was typing this, I realized that the string gives us no benefits. I made a much lighter patch that accepts the class instead (which was actually the first thing I tried): set_fixture_class :content_drafts => Article::Draft thoughts? -- Rick Olson http://techno-weenie.net
On 3/6/06, Rick Olson <technoweenie@gmail.com> wrote:> So, I sat down to use set_fixture_class, and it bombed on the first > thing I tried: > > set_fixture_class :content_drafts => "Article::Draft" > > I made a quick patch, and I''d appreciate a quick run through your > tests to make sure it doesn''t disturb anything: > http://dev.rubyonrails.org/ticket/4095 > > As I was typing this, I realized that the string gives us no benefits. > I made a much lighter patch that accepts the class instead (which was > actually the first thing I tried): > > set_fixture_class :content_drafts => Article::DraftI like the fact you''re passing a class, much nicer way of handling things like modules. However, http://dev.rubyonrails.org/attachment/ticket/4095/simpler_set_fixture_class.diff#L18 12 + klass = case @class_name 13 + when Symbol, String 14 + Object.const_get(@class_name) if Object.const_defined?(@class_name) 15 + when Class 16 + @class_name 17 + else 18 + nil 19 end 20 + klass.find(self[klass.primary_key]) if klass That nil is just going to raise a NoMethodError, why not raise a specific exception, or at least a RuntimeError with a nice message?> thoughts? > > -- > Rick Olson > http://techno-weenie.net > _______________________________________________ > Rails-core mailing list > Rails-core@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-core >-- Cheers Koz
I like it better with classes as well. I''ll test against my code at work in the morning. Additionally, Obie Fernandez recently posted about a different way of reworking fixtures (http://jroller.com/page/obie/20060304) that we might want to take a look at. Obie, if you''re on the list, do you want to chime in here?
> Additionally, Obie Fernandez recently posted about a different way of > reworking fixtures (http://jroller.com/page/obie/20060304) that we > might want to take a look at. Obie, if you''re on the list, do you > want to chime in here?That''s a pretty radical change to fixtures. How do you deal with fixtures for tables with no models, like habtm join tables? I think I had a patch from awhile back that let you put classes in the fixtures. Doing this sets the class name and the table name. It just looks funky alongside the symbols: fixtures :people, Project, :people_projects -- Rick Olson http://techno-weenie.net
Whoops I totally forgot about habtm table fixtures when considering that patch idea. I''m not sure there''s a good way to handle them with my approach. I should be revisiting tomorrow and will chime in with any insights. No good answers so far. Um, I guess context might help... We''re writing tests for code that runs against read-only (to our app) tables -- these are the ugly-named legacy tables that I talk about in my blog. Fixtures don''t play well with the concept of read-only tables. As a workaround we tried wrapping the legacy stuff in more Rails-friendly views, but that path is troublesome also and caused us problems as far as varied support of all our database engines for updateable views. Perversely, SQLite (win32) which we use for testing on our dev boxen worked fine with fixtures on views, but bombed on our FreeBSD build server. We''re in the process of migrating everyone to MySQL5 but the whole experience has been a total PITA so far. Obie On 3/6/06, Rick Olson <technoweenie@gmail.com> wrote:> > Additionally, Obie Fernandez recently posted about a different way of > > reworking fixtures (http://jroller.com/page/obie/20060304) that we > > might want to take a look at. Obie, if you''re on the list, do you > > want to chime in here? > > That''s a pretty radical change to fixtures. How do you deal with > fixtures for tables with no models, like habtm join tables? > > I think I had a patch from awhile back that let you put classes in the > fixtures. Doing this sets the class name and the table name. It just > looks funky alongside the symbols: > > fixtures :people, Project, :people_projects > > > -- > Rick Olson > http://techno-weenie.net > _______________________________________________ > Rails-core mailing list > Rails-core@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-core >