Jak
Jak

Reputation: 3233

How to create mysql function in rails test database?

I wrote a Mysql function for my rails app and i added it to my database by manual. When i want to test the function using Rails UNIT test, it through the errors like below

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

How to add the function, out of the test suite or beginning of test run ?

Thanks in Advance, Aaa.

Upvotes: 4

Views: 969

Answers (1)

Omar Qureshi
Omar Qureshi

Reputation: 9093

I can't see the error. But I assume the problem is your schema format.

config.active_record.schema_format = :sql

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

The reason behind that is by default your test database is not made from a schema only dump of your development database, but, instead from db/schema.rb - which knows nothing about mysql functions.

an sql schema format will do a mysqldump (or pg_dump) with the schema only flag set to true and create a development_structure.sql file.

Upvotes: 2

Related Questions