Casecommons / with_model

Dynamically build an Active Record model (with table) within a test context
http://www.casebook.net
MIT License
166 stars 18 forks source link

Jenkins Issue #19

Closed JanStevens closed 10 years ago

JanStevens commented 10 years ago

Hello,

Using jenkins on our setup we get the following errors (rake spec)

An error occurred in an after hook
  NameError: constant Object::Voucher not defined
  occurred at /var/lib/jenkins/jobs/project/workspace/vendor/bundle/ruby/2.1.0/gems/with_model-1.1.0/lib/with_model/constant_stubber.rb:18:in `remove_const'

F
An error occurred in an after hook
  NameError: constant Object::Voucher not defined
  occurred at /var/lib/jenkins/jobs/project/workspace/vendor/bundle/ruby/2.1.0/gems/with_model-1.1.0/lib/with_model/constant_stubber.rb:18:in `remove_const'

F
An error occurred in an after hook
  NameError: constant Object::Voucher not defined
  occurred at /var/lib/jenkins/jobs/project/workspace/vendor/bundle/ruby/2.1.0/gems/with_model-1.1.0/lib/with_model/constant_stubber.rb:18:in `remove_const'

The Voucher is with_model object:

with_model :voucher do
    table do |t|
      t.string :ticket
    end

    model do
      attr_accessor :validation_hash
      validates :ticket, ticket: true
    end
  end

Any idea/solution? Thanks

nertzy commented 10 years ago

Capitalize Voucher:

  with_model :Voucher do
    table do |t|
      t.string :ticket
    end

    model do
      attr_accessor :validation_hash
      validates :ticket, ticket: true
    end
  end
amarshall commented 10 years ago

@nertzy Hmm, I’m not convinced that’s the issue here, though. The error would’ve been “voucher is not allowed as a constant name”. Plus we camelize it here and it’s capital-V Voucher in the error shown.

@JanStevens did changing it to :Voucher as above fix the issue?

JanStevens commented 10 years ago

Yea it did fix the issue... Thanks!

amarshall commented 10 years ago

Interesting.

nertzy commented 10 years ago

We should do something to make this situation more discoverable through better error messaging.

amarshall commented 10 years ago

Yea, I know we want to deprecate passing snake-cased symbols, but I’m still not convinced that’s the issue here.

The error they were getting doesn’t match the apparent fix, and changing several of the with_model specs to call with_model with e.g. :blog_post instead of :BlogPost doesn’t raise any exceptions and is in fact completely green, so I can’t reproduce the issue.

JanStevens commented 10 years ago

Thats why its only a Jenkins issue, locally I didnt saw any problems using :Voucher our :voucher

nertzy commented 10 years ago

@JanStevens Are you on the latest version of with_model? (1.1.0)

JanStevens commented 10 years ago

yes!

amarshall commented 10 years ago

It’s also odd that the error only occurs on removal, not creation. This implies that for some reason either: