https://www.redmine.org/https://www.redmine.org/favicon.ico?16793021292011-02-12T13:08:43ZRedmineRedmine - Defect #7613: Generated test instances may share the same attribute value objecthttps://www.redmine.org/issues/7613?journal_id=251492011-02-12T13:08:43ZEtienne Massip
<ul><li><strong>File</strong> <a href="/attachments/5373">object_daddy_exemplars.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/5373/object_daddy_exemplars.patch">object_daddy_exemplars.patch</a> added</li><li><strong>Status</strong> changed from <i>New</i> to <i>Resolved</i></li></ul><p>Here comes the patch.</p>
<p>All tests pass.</p>
<p>This issue was blocking me writting tests for <a class="issue tracker-3 status-1 priority-4 priority-default" title="Patch: Gantt filters (New)" href="https://www.redmine.org/issues/7456">#7456</a>.</p> Redmine - Defect #7613: Generated test instances may share the same attribute value objecthttps://www.redmine.org/issues/7613?journal_id=251502011-02-12T13:11:45ZEtienne Massip
<ul><li><strong>Subject</strong> changed from <i>Generated test instances may share the same attribute value objects</i> to <i>Generated test instances may share the same attribute value object</i></li></ul> Redmine - Defect #7613: Generated test instances may share the same attribute value objecthttps://www.redmine.org/issues/7613?journal_id=251512011-02-12T14:03:39ZJean-Baptiste Barth
<ul></ul><p>Sorry I don't really understand how your patched version works. Does ObjectDaddy pass the last_<item> as an argument implictly ?</p>
<p>But I see the problem in actual version. Why not a <code>@@last_identifier</code> instead of <code>@last_identifier</code> ? I think the problem is here since it's a class method, an instance variable doesn't make much sense. And it should solve your first problem.</p>
<p>What do you think ?</p> Redmine - Defect #7613: Generated test instances may share the same attribute value objecthttps://www.redmine.org/issues/7613?journal_id=251572011-02-12T16:00:30ZEtienne Massip
<ul></ul><p>Jean-Baptiste Barth wrote:</p>
<blockquote>
<p>But I see the problem in actual version. Why not a <code>@@last_identifier</code> instead of <code>@last_identifier</code> ? I think the problem is here since it's a class method, an instance variable doesn't make much sense. And it should solve your first problem.</p>
</blockquote>
<p>Nope, I've been a bit too much sybilline in my description :</p>
<p>The problem is that the generator returns the same object instance each time (<code>@last_name</code>), and that this instance is set by ObjectDaddy as the attribute value of the newly spawned Project instance.</p>
<p>That is to say :<br /><pre>p1.identifier.object_id == p2.identifier.object_id == @last_name.object_id </pre></p>
<p>So, doing a <code>@last_name.succ!</code> when generating p2 actually also change the p1.identifier value, which is not the desired effect.</p>
<p>If <code>@last_name.succ!</code> was replaced by <code>@last_name = @last_name.succ</code>, the test would pass, but using a class variable would not change anything.</p>
<blockquote>
<p>Does ObjectDaddy pass the last_<item> as an argument implictly ?</p>
</blockquote>
<p>Absolutly, it passes the previous value if generator method/block arity is 1 ; using this, IMHO, is the most elegant way to fix this issue.</p> Redmine - Defect #7613: Generated test instances may share the same attribute value objecthttps://www.redmine.org/issues/7613?journal_id=251632011-02-13T01:21:03ZJean-Baptiste Barth
<ul></ul><p>Okay, I'll have a deeper look at it, thanks for the infos.</p> Redmine - Defect #7613: Generated test instances may share the same attribute value objecthttps://www.redmine.org/issues/7613?journal_id=251872011-02-14T14:49:23ZEtienne Massip
<ul><li><strong>Status</strong> changed from <i>Resolved</i> to <i>New</i></li></ul> Redmine - Defect #7613: Generated test instances may share the same attribute value objecthttps://www.redmine.org/issues/7613?journal_id=254062011-02-21T12:51:48ZJean-Philippe Langjp_lang@yahoo.fr
<ul></ul><p>I confirm the problem in current implementation but according to object_daddy documentation, there's a cleaner way to declare generators. The following patch fixes the problem for project generators:</p>
<pre>
Index: test/exemplars/project_exemplar.rb
===================================================================
--- test/exemplars/project_exemplar.rb (revision 4892)
+++ test/exemplars/project_exemplar.rb (working copy)
@@ -1,22 +1,9 @@
class Project < ActiveRecord::Base
- generator_for :name, :method => :next_name
- generator_for :identifier, :method => :next_identifier_from_object_daddy
+ generator_for :name, :start => 'Project 0'
+ generator_for :identifier, :start => 'project-0000'
generator_for :enabled_modules, :method => :all_modules
generator_for :trackers, :method => :next_tracker
- def self.next_name
- @last_name ||= 'Project 0'
- @last_name.succ!
- @last_name
- end
-
- # Project#next_identifier is defined on Redmine
- def self.next_identifier_from_object_daddy
- @last_identifier ||= 'project-0000'
- @last_identifier.succ!
- @last_identifier
- end
-
def self.all_modules
[].tap do |modules|
Redmine::AccessControl.available_project_modules.each do |name|
</pre> Redmine - Defect #7613: Generated test instances may share the same attribute value objecthttps://www.redmine.org/issues/7613?journal_id=254072011-02-21T13:02:14ZEtienne Massip
<ul></ul><p>Yes, saw that too.</p>
<p>I was not at ease with so much change and I thought Eric was not ignorant of this way to do when he committed the exemplars in the first place, and that he chose to write full generator methods on purpose.</p>
<p>But really, no idea why he didn't do that.</p> Redmine - Defect #7613: Generated test instances may share the same attribute value objecthttps://www.redmine.org/issues/7613?journal_id=254172011-02-21T14:05:26ZEtienne Massip
<ul></ul><p>Also, there is possibility that the <code>Issue.generate_for_project!()</code> method in <a class="source" href="https://www.redmine.org/projects/redmine/repository/svn/entry/trunk/test/object_daddy_helpers.rb#L30">source:trunk/test/object_daddy_helpers.rb#L30</a> could have been written to supersede this issue, as it is called many times in a row in <code>gantt_test.rb</code> and that <code>generate!()</code> already deals with a block argument.</p> Redmine - Defect #7613: Generated test instances may share the same attribute value objecthttps://www.redmine.org/issues/7613?journal_id=254362011-02-21T17:23:51ZJean-Philippe Langjp_lang@yahoo.fr
<ul></ul><p>I don't think so. I think the problem hasn't been noticed before.<br />Anyway, I don't see any reason not to clean up these generators.</p> Redmine - Defect #7613: Generated test instances may share the same attribute value objecthttps://www.redmine.org/issues/7613?journal_id=254372011-02-21T17:25:35ZEtienne Massip
<ul></ul><p>I do agree, the more clean, the better !</p> Redmine - Defect #7613: Generated test instances may share the same attribute value objecthttps://www.redmine.org/issues/7613?journal_id=256632011-02-26T16:43:23ZEtienne Massip
<ul><li><strong>Target version</strong> set to <i>Candidate for next minor release</i></li></ul> Redmine - Defect #7613: Generated test instances may share the same attribute value objecthttps://www.redmine.org/issues/7613?journal_id=323172011-09-17T12:03:54ZEtienne Massip
<ul><li><strong>Category</strong> changed from <i>Core Plugins</i> to <i>Code cleanup/refactoring</i></li></ul> Redmine - Defect #7613: Generated test instances may share the same attribute value objecthttps://www.redmine.org/issues/7613?journal_id=324552011-09-23T06:47:54ZEtienne Massip
<ul><li><strong>Target version</strong> changed from <i>Candidate for next minor release</i> to <i>1.2.2</i></li></ul><p>Still needs merging.</p> Redmine - Defect #7613: Generated test instances may share the same attribute value objecthttps://www.redmine.org/issues/7613?journal_id=324602011-09-23T06:54:04ZEtienne Massip
<ul><li><strong>Status</strong> changed from <i>New</i> to <i>Resolved</i></li></ul> Redmine - Defect #7613: Generated test instances may share the same attribute value objecthttps://www.redmine.org/issues/7613?journal_id=325072011-09-26T18:06:55ZEtienne Massip
<ul><li><strong>Resolution</strong> set to <i>Fixed</i></li></ul> Redmine - Defect #7613: Generated test instances may share the same attribute value objecthttps://www.redmine.org/issues/7613?journal_id=336442011-11-11T11:29:11ZJean-Philippe Langjp_lang@yahoo.fr
<ul><li><strong>Status</strong> changed from <i>Resolved</i> to <i>Closed</i></li></ul>