-
-
Notifications
You must be signed in to change notification settings - Fork 909
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
Increase rails integration tests #1341
Increase rails integration tests #1341
Conversation
f687de5
to
afe121f
Compare
afe121f
to
0deeb9b
Compare
For now, the tests are only passing on Rails 6. TODO: For Rails 5.2 it's necessary to prevent
For Rails 5.1 or below it's necessary to prevent the same things on 5.2 plus
|
I wold like to suggest to move the rails_application.rb, rails_version.rb and load_environment.rb to outside of unit folder and use them both for unit tests and acceptance tests. It seems to me that these three files should be shared to prevent duplications on the configuration of the project. For example this one for the migrations of the rails project: if rails_gt_5? && bundle.includes?('actiontext')
run_rake_tasks!('action_text:install:migrations')
end The unit tests already have this configuration, but acceptance tests don't. You may be wondering how I got this idea. Or maybe why. I tried to include the Ok. So Rails is defined on I don't think I should add something like a The unit_spec_helper.rb first line told me where to look: `require_relative 'support/unit/load_environment'` Then these three lines from $test_app = UnitTests::RailsApplication.new
$test_app.create
$test_app.load And for my surprise, the load method is already doing almost everything that I need: def load
load_environment
if rails_version > 5 && bundle.includes?('actiontext')
add_action_text_migration
end
run_migrations
end It's only missing this piece of code: ...
if rails_version >= 5.2 && bundle.includes?('active_storage')
add_active_storage_migration
end
...
def add_action_text_migration
fs.within_project do
run_command! 'bundle exec rake active_storage:install:migrations'
end
end Should I refactor this in another PR? Or should I leave as it is? |
Hey @vsppedro. Sounds like you're finding some good stuff. You're right that there are some differences in how the unit tests set up the Rails applications vs. how the acceptance tests do it. This happened because I added both separately and didn't realize they were doing similar things. Since then, I've created a gem called Snowglobe which encapsulates the work of creating a Rails application for use in tests. This gem actually came out of both I think it's fine to include changes to the unit and/or acceptance test setup in this PR if it helps you write these tests better. In terms of whether or not to do the Snowglobe refactor, if synchronizing the two manually like you're doing isn't too much trouble, maybe it's best to stick with that approach for now and we can address the refactor in a future commit. * Snowglobe doesn't do everything that the |
0deeb9b
to
c33074f
Compare
Thank you for sharing your thoughts with me. I am interested in doing this factoring using Snowglobe, but I admit that there is still a long way to go to achieve this and I already promised other PRs here. :) So, I will follow your suggestion and leave this refactoring for later. For this PR, I see only the need to move |
@vsppedro I think moving |
d6b765b
to
63e1539
Compare
When Rails version is above 5.2 all the matchers will be tested. When the version of Rails is 5.2, It should not test: - have_implicit_order_column (Rails 6+) - have_rich_text (Rails 6+) When Rails is below 5.2, it should not test: - have_implicit_order_column (Rails 6+) - have_many_attached (Rails 5.2+) - have_one_attached (Rails 5.2+) - have_rich_text (Rails 6+)
63e1539
to
1aa56c3
Compare
I see know a better approach to this PR. I think it will help to make it leaner. :) Let me describe what I did first and what I intend to do know, after that, I would like to hear your thoughts on this, please. When you have the time. I've found three test scenarios so far: 1 - The rails version is equal to 6. In this case it will test all the matchers. To make this happen I create two more models: In case of scenario 1, all the files would be added. In case os scenario 2, it would only add user.rb and photo_album.rb. In case of scenario 3, it would only add user.rb. Of course, for each scenario, the necessary migrations and test files were also added. I thought that this type of organization would be an easy way to separate the configuration for each scenario and make the code simpler. Now I don't like that idea very much because and I think I found a better answer: def comment_lines_matching. So, I intend to remove the post.rb and photo_album.rb models. Move the code that was in them to user.rb and use the method I discovered to dynamically comment lines that are not compatible with the version of Rails being tested. What do you guys think? EDIT: Another idea would be to rename PS: For now, I'm stuck in a test, I will share more information after I understand why it is failing. |
@vsppedro Sorry I just saw your latest comment. Sounds like you're on a good track here! |
Adding more rails integration tests similar to those in Shoulda.
The lists below track which tests are missing.
ActiveModel Matchers:
ActiveRecord Matchers:
ActionController Matchers: