oveits / ProvisioningEngine

Ruby on Rails based ProvisioningEngine Frontend for provisioning of legacy systems via Apache Camel Backend (SOAP/XML+SPML+File import)
3 stars 6 forks source link

Error in rake:migrate for test DB: rake aborted! ActiveRecord::StatementInvalid: Could not find table 'system_settings' #21

Closed oveits closed 8 years ago

oveits commented 8 years ago

When re-doing all migrations for RAILS_ENV=test, I have seen that the statment 'if SystemSetting.webportal_simulation_mode' I have specified in spec/factories/targets.rb is evaluated BEFORE the database is migrated (why before? Does not really make sense!) As a workaround, I had to make sure that SystemSetting.webportal_simulation_mode does not raise an exception, even if the table is not yet created. This has been accomplised by a begin-rescue block around the self.where command in SystemSettings.method_missing and
by a special handling in the if block in case the table is missing: we just return the environment variable as a boolean without trying to auto-create a database entry in this case.

Begin of full log:

rm db/test.sqlite3
bundle exec rake db:migrate RAILS_ENV=test
rake aborted! ActiveRecord::StatementInvalid: Could not find table 'system_settings'
/usr/local/rvm/gems/ruby-2.2.4/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:511:in `table_structure'
/usr/local/rvm/gems/ruby-2.2.4/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:385:in `columns'
/usr/local/rvm/gems/ruby-2.2.4/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/schema_cache.rb:43:in `columns'
/usr/local/rvm/gems/ruby-2.2.4/gems/activerecord-4.2.5.1/lib/active_record/attributes.rb:93:in `columns'
/usr/local/rvm/gems/ruby-2.2.4/gems/activerecord-4.2.5.1/lib/active_record/attributes.rb:98:in `columns_hash'
/usr/local/rvm/gems/ruby-2.2.4/gems/activerecord-4.2.5.1/lib/active_record/inheritance.rb:205:in `subclass_from_attributes?'
/usr/local/rvm/gems/ruby-2.2.4/gems/activerecord-4.2.5.1/lib/active_record/inheritance.rb:54:in `new'
/home/ubuntu/workspace/app/models/system_setting.rb:30:in `method_missing'
/home/ubuntu/workspace/spec/factories/targets.rb:3:in `<top (required)>'
...

and /home/ubuntu/workspace/spec/factories/targets.rb:

# spec/factories/customers.rb
# spec/factories/targets_private.rb
if SystemSetting.webportal_simulation_mode
  FactoryGirl.define do
    factory :target do 
...