For my Rails 4 app i have the following written in my spec_helper.rb to maintain the test database automatically:
ActiveRecord::Migration.maintain_test_schema
But as it seems this doesn't work, because i still get the message afterwards, that there are migrations pending.
So, i debugged this and found the following line in active_records' migration.rb which actually executes the schema preparation (or should):
system("bin/rake db:test:prepare")
But when i try to execute this line separatly in a rails console nothing happens. Calling it with
`bin/rake db:test:prepare`
to get the output gives me the following error
Errno::ENOEXEC: Exec format error - bin/rake db:test:prepare
So is this a bug in rails or did i just something wrong? I am on windows if that matters, but it didn't work on my co-workers mac too.
Related
In the following project
https://github.com/Crash1hd/MultipleTestTesting
I am getting the following error
java.lang.IllegalStateException: Illegal connection pointer 1. Current pointers for thread Thread[DefaultDispatcher-worker-1 #coroutine#3,5,SDK 28] []
at org.robolectric.shadows.ShadowSQLiteConnection$Connections.getConnection(ShadowSQLiteConnection.java:367)
at org.robolectric.shadows.ShadowSQLiteConnection$Connections.prepareStatement(ShadowSQLiteConnection.java:416)
at org.robolectric.shadows.ShadowSQLiteConnection.nativePrepareStatement(ShadowSQLiteConnection.java:89)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(SQLiteConnection.java)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:903)
at android.database.sqlite.SQLiteConnection.execute(SQLiteConnection.java:562)
at android.database.sqlite.SQLiteSession.beginTransactionUnchecked(SQLiteSession.java:323)
at android.database.sqlite.SQLiteSession.beginTransaction(SQLiteSession.java:298)
at android.database.sqlite.SQLiteDatabase.beginTransaction(SQLiteDatabase.java:549)
at android.database.sqlite.SQLiteDatabase.beginTransaction(SQLiteDatabase.java:460)
at androidx.sqlite.db.framework.FrameworkSQLiteDatabase.beginTransaction(FrameworkSQLiteDatabase.java:69)
at androidx.room.RoomDatabase.beginTransaction(RoomDatabase.java:277)
at com.mycomp.roomwordsample.data.db.WordDao_Impl.deleteAll(WordDao_Impl.java:81)
at com.mycomp.roomwordsample.data.db.WordRepository$deleteAllLogsOlderThan$2.invokeSuspend(WordRepository.kt:28)
at |b|b|b(Coroutine boundary.|b(|b)
at com.mycomp.roomwordsample.ui.WordViewModel$deleteAllLogsOlderThanA$1.invokeSuspend(WordViewModel.kt:36)
Caused by: java.lang.IllegalStateException: Illegal connection pointer 1. Current pointers for thread Thread[DefaultDispatcher-worker-1 #coroutine#3,5,SDK 28] []
at org.robolectric.shadows.ShadowSQLiteConnection$Connections.getConnection(ShadowSQLiteConnection.java:367)
at org.robolectric.shadows.ShadowSQLiteConnection$Connections.prepareStatement(ShadowSQLiteConnection.java:416)
at org.robolectric.shadows.ShadowSQLiteConnection.nativePrepareStatement(ShadowSQLiteConnection.java:89)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(SQLiteConnection.java)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:903)
at android.database.sqlite.SQLiteConnection.execute(SQLiteConnection.java:562)
at android.database.sqlite.SQLiteSession.beginTransactionUnchecked(SQLiteSession.java:323)
at android.database.sqlite.SQLiteSession.beginTransaction(SQLiteSession.java:298)
at android.database.sqlite.SQLiteDatabase.beginTransaction(SQLiteDatabase.java:549)
at android.database.sqlite.SQLiteDatabase.beginTransaction(SQLiteDatabase.java:460)
at androidx.sqlite.db.framework.FrameworkSQLiteDatabase.beginTransaction(FrameworkSQLiteDatabase.java:69)
at androidx.room.RoomDatabase.beginTransaction(RoomDatabase.java:277)
at com.mycomp.roomwordsample.data.db.WordDao_Impl.deleteAll(WordDao_Impl.java:81)
at com.mycomp.roomwordsample.data.db.WordRepository$deleteAllLogsOlderThan$2.invokeSuspend(WordRepository.kt:28)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:233)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:594)
at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely(CoroutineScheduler.kt:60)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:742)
When I run this set of tests
https://github.com/Crash1hd/MultipleTestTesting/blob/master/app/src/test/java/com/mycomp/roomwordsample/WordDaoTestA.kt
It seems to have to do with the function that I am calling in initializationLogging in WordApplication
https://github.com/Crash1hd/MultipleTestTesting/blob/master/app/src/main/java/com/mycomp/roomwordsample/WordApplication.kt
Commenting out LogA.purgeOldLogsGreaterThan(7) this line all the tests pass.
I am at a loss as to why it is failing? each test is exactly the same and they all work (just not all at once).
I am wondering if it has to do with how I am calling the WordViewModel in application...
Ok So I came across this blog post
https://artemzin.com/blog/how-to-mock-dependencies-in-unit-integration-and-functional-tests-dagger-robolectric-instrumentation/
and in the comments, there is this comment by Krzysiek Bielicki
You can just create Application class prefixed with 'Test'. Robolectric will automatically use it as Application for all tests.
So I tried that created class TestWordApplication added everything that was in WordApplication (but excluded the call to initializationLogging() and now all the test pass as its no longer trying to access and purge the actual database.
I found this also on the Robolectric website confirming
http://robolectric.org/custom-test-runner/
Thanks. and a very special thank you to Krzysiek Bielicki (whomever you are) as you just made my night :)
I am struggling with this error message which has no direct forum discussion anywhere. From some of the things I saw around the web I tried:
Changing localhost to 127.0.0.1
Played around with browser.driver.manage() v/s browser.manage()
Cleaning out/updating my node modules
The same code runs on other machines with same configuration (Win 10, chromedriver 2 etc.)
The code essetially gets the cookie value through API calls before
and uses it as such:
browser.get(URL);
browser.manage().addCookie('cookie_name', value);
Any help would be appreciated!
Assumption that you are on Protractor 5.0.0. Adding cookies have been changed in selenium webdriver 3 and was noted as a breaking change in the Protractor changelog:
Before:
browser.manage().addCookie('testcookie', 'Jane-1234');
After:
browser.manage().addCookie({name:'testcookie', value: 'Jane-1234'});
The answer above did not work for me because i kept getting this error:
"Expected 2-6 arguments but got 1"
This is what I had to do to make it compile at least:
(browser.manage() as any).addCookie({name:'cookieName', value: 'cookieVal'});
Here is the thread I got this info from:
https://github.com/angular/protractor/issues/4148
It is still an open issue.
I'm using Travis CI for a gem I'm developing and ran into a strange error (links are at the end of the question).
The gem is storing some information serialized with YAML which isn't built manually, but using YAML.dump and later loaded again with YAML.load.
The following lines are used to dump and load a hash to/from YAML:
headers[:ar_mailer_settings] = YAML.dump(settings)
...
ar_settings = YAML.load(mail['ar_mailer_settings'].value)
The later line seems to be producing an error on Travis CI, but when I run the tests locally using the same binary versions, everything runs perfectly fine:
Psych::SyntaxError: (<unknown>): mapping values are not allowed in this context at line 1 column 22
/home/travis/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/psych.rb:205:in `parse'
...
/home/travis/build/Stex/ar_mailer_revised/lib/action_mailer/ar_mailer.rb:84:in `deliver!'
I put a simple puts into the deliver! method to see if there would be a difference in the stored values, and it seems that Travis CI is ignoring newlines in the generated YAML which then causes a parse error:
Travis:
"--- smtp_settings: :address: localhost :port: 25 :domain: localhost.localdomain :user_name: some.user :password: some.password :authentication: :plain :enable_starttls_auto: true "
Locally:
"---\nsmtp_settings:\n :address: localhost\n :port: 25\n :domain: localhost.localdomain\n :user_name: some.user\n :password: some.password\n :authentication: :plain\n :enable_starttls_auto: true\n"
Interestingly, I didn't change anything regarding these methods before the Travis CI was failing, so I'm not sure if I'm simply overlooking something here or if it's some kind of incompatibility issue.
Can I do something to preserve the newline characters?
Edit: Additional Information
The gem allows setting custom SMTP settings and attributes for single email records.
These can be set directly when generating the email in an ActionMailer::Base instance see here for a dummy mailer
To transport these custom settings to ActionMailer's deliver!-method which actually creates a new email record, I serialize these settings via YAML, save them in the email header temporarily and restore them later see ar_mailer_setting and deliver! here
The source code which raises the error: here
The complete Travis CI output: here
If more information is needed, please let me know and I'll add it to the question.
Thanks in advance!
I'm using Rails 4.1.2. I have some environments which are exact copies of my development environment. In other words, I created them by simply copying config/environments/development.rb to a file with a different name (e.g., destaging.rb). They differ only in the connection information in database.yml.
If I issue RAILS_ENV=destaging rails s or rails s -e destaging at the command line, everything works just as I desire, except that I get no SQL logging to STDOUT, which is a bummer.
Since my destaging environment is absolutely identical to my development environment except for different connection settings in database.yml, I suspect that something is looking for an environment named development and enabling SQL logging to STDOUT only if an environment with that name is active. How can I enable SQL logging to STDOUT for other environments launched through WEBRick?
For posterity, I've discovered how to do this. First, I'm running Ruby 2.1.2 with Rails 4.1.2. If that is not your environment, your mileage may vary, though I suspect the solution will be very similar.
So, first you must modify bin/rails. Open this file and change it as follows. (I have posted the entire file, minus the shebang, for clarity.)
begin
load File::expand_path("../spring", __FILE__)
rescue LoadError
end
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
# Here comes the important part
require 'rails/commands/server'
class Rails::Server::Options
def parse_with_logging!(args)
options = parse_without_logging!(args)
options[:log_stdout] = true # Or whatever condition you want
options
end
alias_method_chain :parse!, :logging
end
require 'rails/commands'
Since require 'rails/commands' executes the server immediately, monkey-patching after that line does not work. It is simply ignored. If you try to monkey-patch it before you require the commands, it explodes because the Rails::Server::Options class has not yet been defined. Thus, we have to pre-emptively require rails/commands/server so we can alias its parse! method.
Monkey-patching should almost always be a last resort, IMHO. However, I see no alternative in this case. If anyone has a better idea, I'd love to hear it.
I also encountered this problem with the same versions of Rails and Ruby, using a non-standard environment name (in your case "destaging"). However I did not want it to affect all environments, nor lose any more time to not getting work done, so I simply changed the way I start the server:
(tail -F log/destaging.log &) && rails s
Then afterwards to restart the server, ctrl-c as usual and then rails s again. The tail will keep going in the background and for all intents and purposes the experience will be like it was before this stopped working.
For 2 weeks i'm struggling with fallowing problem.
Im using DataFixturesBundle to load my fixtures to database. Everything works fine.
I decided to use capifony (capistrano) to deploy my application on production.
That went well too. I have implemented all things i wanted capifony to do for me with my app on production server.
But I do get one error and I dont even know what bundle is causing that.
IMPORTANT This error only shows on production server, it does NOT matter if i'm on DEV or PROD environment ( also DEBUG ), but the error never shows on my local hosts (tested on 2 computers, mac & win ).
Fatal error: Cannot redeclare Proxies\TestBundleEntityPartnerProxy::unserialize() in /public_path/testapp.com/app/releases/20110929191120/app/cache/dev/doctrine/orm/Proxies/TestBundleEntityPartnerProxy.php on line 489
And that is right. Doctrine makes two the same methods both for unserialize() and both for serialize() in the same class (proxy).
This only happens on my production server. I can't even make the problem shows on my local host. On my local host there are no two methods with the same name (unserialize() and serialize()). There is one unserialize() and one serialize()
Any help would be appreciated.
Cheers, Bart
fixed here:
https://github.com/doctrine/doctrine2/pull/177
This is not capifony, but some edge case bug or situation. I'm not sure what's causing it yet. Some details here:
http://groups.google.com/group/symfony-devs/browse_thread/thread/435a19119e9d6bdb