4

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.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the Quick answer, i am using 2.3.12 version. I don't think we can use config object in application.rb file.. Please correct me if i was wrong.. i added it in enviroment.rb file but no help..
ok - environment.rb is fine - did it create the development_structure file?
environment.rb is the place to add this configuration. Please run rake db:schema:dump to generate the schema.rb in the sql format and then run your unit tests.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.