jpignata/temping

Reusing already defined constants

mschulkind opened this issue · 7 comments

What's the purpose of reusing already defined constants?

Specifically talking about:
https://github.com/jpignata/temping/blob/master/lib/temping.rb#L17

This seems to increase the chance that you'll create cross-dependencies between tests and also breaks the following usage with transactional fixtures turned on:

describe Foo do
  before(:each) do
    Temping.create(:bar) do
      with_columns do |t|
        t.string :baz
      end
    end
  end

  it 'one spec' do
  end

  it  'another spec' do
  end
end

When the second spec runs, then Temping.create() will end up reusing Bar internally, which skips ModelFactory#build, which in turn skips creating the table. At this point the table no longer exists because the transaction rollback from the first spec removed the table, so when the with_columns block tries to create the baz column, it fails because the table doesn't exist.

From what I can tell, this caching is only meant as a super small optimization, and I'd propose just removing it really doesn't speed much up and breaks the above.

This change would look something like:
mschulkind@6cf7b85

I had to change a good bit of code because of the weird way the class is passed around using #klass, @klass and #const_get/#const_set.

I was getting the same issue. Using @mschulkind fork fixes this issue for me.

@mschulkind feel free to send a PR! Thanks for the changes.

I been using another similar gem more recently https://github.com/Casecommons/with_model

@mrloop thanks for the info! Didn't know about it.

Do you just want the commit I linked as a PR?

kitop commented

Hey @mschulkind #31 fixed a similar issue.
Is this still happening?