How to create mysql function in rails test database?

I wrote a Mysql function for my rails application, and I manually added it to my database. When I want to test a function using the Rails UNIT test, this can be done with errors, as shown below

ActiveRecord::StatementInvalid: Mysql::Error: FUNCTION mydatabase.fn_Sample_Function does not exist: 

How to add a function from a test suite or start a test run?

Thanks, Advance, Ahh.

+4
source share
1 answer

I do not see a mistake. But I guess the problem is with your schema format.

 config.active_record.schema_format = :sql 

in application.rb should be what you need to do.

The reason for this is that by default your test database is not created from a schema, but only from db / schema.rb, which knows nothing about mysql functions.

sql schema format will do mysqldump (or pg_dump) if only the schema flag is set to true and creates the development_structure.sql file.

+1
source

All Articles