-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to test domain using not default datasource #21
Comments
i wonder why on https://github.com/grails/grails-testing-support/blob/master/grails-gorm-testing-support/src/main/groovy/org/grails/testing/gorm/spock/DataTestSetupSpecInterceptor.groovy#L49 it is using deprecated constructor of SimpleMapDatastore |
@jeffbrown do you have any idea on this issue ? |
thanks to @jameskleeh, and bdbogjoe/unit-test-multiple-datasource#3 i'm now able to able to pass my previous tests, but now i'm facing issue while trying to validate my domain
If i add annotation @transactional(connection = 'myDataSource') I got error :
i updated my repo : https://github.com/bdbogjoe/unit-test-multiple-datasource just run gradle test to have these errors |
@bdbogjoe In general my advice for situations like this is to use a real datastore. |
thanks @jameskleeh , i'm now back on this issue, i'm still blocked with it. What do you mean by using real datastore ? Seems we don't have choice : Line 59 in f1a61e4
SimpleDatastore is used, and we cannot change it, and using deprecated constructor I spent days already on this issue, i'm the only one testing domain which is not using default datasource ? I updated my repo to illustrate another issue, maybe same, don't know https://github.com/bdbogjoe/unit-test-multiple-datasource if you run test you have now : i have constraint defined : https://github.com/bdbogjoe/unit-test-multiple-datasource/blob/a0e35a37a698862884b5285127e7fbe7a1298ab1/grails-app/domain/joe/Test.groovy#L12 Same tests for other domain using default datasource works fine I think we need better solution than overriding dataStore in test, because in some other places we need to get datastore from application context |
i found one solution : bdbogjoe/unit-test-multiple-datasource@9fe9625 but don't think it is nice solution, any other proposal ? |
@jameskleeh In general my advice for situations like this is to use a real datastore. DataTest doesn't support enhancing Domain that comes from a different datastore than default one. The only way seem to hack the connections sources to make the default datastore create children datastore... |
@anthonyMoreira For example if you are using Hibernate, use the https://github.com/grails/gorm-hibernate5/blob/master/grails-plugin/src/main/groovy/grails/test/hibernate/HibernateSpec.groovy instead of this unit testing framework. |
i initially created issue but in wrong place grails/grails-core#10888
while doing test i have error :
I spent already days on this, cannot find correct solution.
One idea was to overwrite method getDatastore bdbogjoe/unit-test-multiple-datasource#2 but in some case does not work and don't think it is correct way to do this.
Do you have any idea how to fix this ? Was working fine in grails 3.1.x
The text was updated successfully, but these errors were encountered: