Generate specs for your rails application the easy way. Regressor generates model and controller specs based on validations, associations, enums, database, routes, callbacks. Use regressor to capture your rails application behaviour.
MIT License
206
stars
33
forks
source link
Cannot create model regression when using table_name_prefix #25
ubuntu@localhost:~/app$ RAILS_ENV=test rails g regressor:model
Running via Spring preloader in process 3670
Cannot create model regression for User. Reason Mysql2::Error: Table 'app_test.users' doesn't exist: SHOW KEYS FROM `users`
If you are using a table_name_prefix:
ActiveRecord::Base.table_name_prefix = 'sr_'
Then running regressor will fail since it doesn't take it into account when retrieving the indexes:
module Regressor
module Model
module Database
module Index
def indices
::ActiveRecord::Base.connection.indexes(@model.tableize.gsub("/", "_")).map do |indexes|
"it { is_expected.to have_db_index #{indexes.columns} }"
end.flatten.join("\n ")
end
end
end
end
end
If you are using a
table_name_prefix
:Then running regressor will fail since it doesn't take it into account when retrieving the indexes:
To fix this the ActiveRecord class method
table_name
can be used: