-
Notifications
You must be signed in to change notification settings - Fork 103
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
Test errors after switching to MySQL #42
Comments
I'm getting the same problem. I will investigate what causes this problem and let you know. |
I'm having a look as well. Will let you know if I get any fixed and get you a pull request. |
I'm getting less errors than you though. Seems some validations are not running. Very strange.
|
So, the issue with all of these errors except for #4 (the field length issue) appears to be related to this code in folder.rb:
You are storing the root folder, once it is retrieved, presumably so that you don't hit the database the next time you access Folder.root. All fine and good in the working app. However, the test db gets rolled back for each test, so the root folder is getting recreated each time FactoryGirl.create(:folder) is called. Apparently, SQLite3 resets the auto-increment counter on a table when a transaction is rolled back, but MySQL (and PostgreSQL, for that matter) does not. Because of this, each new creation of the root folder under MySQL gets a new ID number. The @root_folder instance variable never gets reset, it still refers to the first root folder that was created, including the original ID number, so in these tests you never get a match between the parent (current root folder) and the @root_folder value returned by the Folder#root method (original root folder). This is proven out by adding the following at line 148 of folder_test.rb:
... and then running your tests. Look at the "move a folder" test results. You'll see a trace listing two folder objects with different ID's. This indicates that Folder.root holds an object that no longer resides in the db, otherwise they'd match. Changing the code as such results in these test errors going away, further proving that this is the issue:
However, that's not really a solution - the issue isn't really with the code, it's with the way the testing runs under MySQL. I'm not sure if this is the cleanest fix for this, but here's what I did. I added the following class method to Folder:
And I added a setup step in the folder and userfile tests to call that method before each test to insure that the root_folder is valid for that test.
Sending you a pull request for all this. I also fixed the email too long issue on the ShareLink. Rails migrations on MySQL create string fields as VARCHAR(255), so I bumped the validation down from 256 to 255. |
I got less errors here at work as well - I'm not sure what the other three were about, but I will double-check them on home computer (where I was getting the original 10) tonight. |
Looking at the error differences, I believe that somewhere towards the end of debugging last night I may have run the install in TEST, which would account for those three additional "already taken" errors. Sorry about that. |
Since this is only used in test, instead of adding a
|
Fair enough! Give me a few minutes and I'll update my pull branch. |
Done! I added a test_helper method to execute code as above, and called that helper from folder and userfile tests. |
Thanks for noticing this, finding out what was wrong and fixing it. I did one more commit to reflect the change from 256 char to 255 char in the UI as well: 4508f02 |
Hiya
Cloned the repo, bundle installed and ran tests - all passed. Then I made the following changes:
Bundle installed again, ran all tests - 10 errors, as shown below. I started to look at a couple. I understand how to fix #4, but these "RecordInivalid expected" and "name already taken" errors have me stumped.
Do you have any idea why simply changing db's would cause these file folder errors?
The text was updated successfully, but these errors were encountered: