-
-
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
Add have rich text matcher #1263
Conversation
@vsppedro How does |
Hi, @mcmire, to make the action text to work in a Rails app it's necessary to run: # This migration comes from action_text (originally 20180528164100)
class CreateActionTextTables < ActiveRecord::Migration[6.0]
def change
create_table :action_text_rich_texts do |t|
t.string :name, null: false
t.text :body, size: :long
t.references :record, null: false, polymorphic: true, index: false
t.timestamps
t.index [ :record_type, :record_id, :name ], name: "index_action_text_rich_texts_uniqueness", unique: true
end
end
end The problem is that I need this table to run the tests. I don't know how to improve this: create_table "action_text_rich_texts" do |t|
t.string "name"
t.string "record_type"
t.bigint "record_id"
end I can't reduce more than that. It's acceptable to add the content of the migration file in the tests? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution. Your progress is looking good.
Some comments in checking and testing the ActionText availability.
You can also add this new feature to README.md
🚀
spec/unit/shoulda/matchers/active_record/have_rich_text_matcher_spec.rb
Outdated
Show resolved
Hide resolved
@vsppedro So instead of adding a migration in the test itself, what I would do instead is to actually run the generator you mentioned. To explain how you would do this, before you run unit tests, a full Rails application is actually generated in the background. You can see that happening here: https://github.com/thoughtbot/shoulda-matchers/blob/master/spec/support/unit/load_environment.rb and here is the main method that generates the app: https://github.com/thoughtbot/shoulda-matchers/blob/master/spec/support/unit/rails_application.rb#L74. Given this, if you add a new method to UnitTests::RailsApplication#generate that does something like this: if rails_version >= 6 && bundle.includes?('actiontext')
fs.within_project do
run_command! `rails action_text:install`
end
end and then call it in #generate, then that may solve the issue for you. Migrations get run in the #load method after the #create method is called, so you shouldn't have to take care of that step. The benefit of this approach is that if Rails for some reason changes ActionText to use a different table, we shouldn't have to update shoulda-matchers in the future to accommodate this — everything should just continue to work. Let me know if you have any more questions on this. |
First of all, thanks for all the knowledge you two are sharing with me, I am learning a lot. @mcmire , I tried to use this:
inside the #generate, but without success. These errors were popping out: RAILS_ENV=development environment is not defined in config/webpacker.yml, falling back to production environment
rake aborted!
ActiveRecord::AdapterNotSpecified: The `development` database is not configured for the `development` environment. Only worked when I tried to call it inside the Another problems that I faced was that the command to install action_text only works with webpacker installed. I saw that the command to create the rails project skip the webpacker installation so I look for other options and I founded the possibility to copy only the migration file with this command: Another thing, I tried to use this method, I replaced with: TODO:
|
@vsppedro Thanks for looking into this further. I'm glad that you were able to get the migrations created! With regard to
Hopefully that helps! |
It helped a lot, @mcmire! Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, this is coming together! I have a few more comments on this to polish this up.
spec/unit/shoulda/matchers/active_record/have_rich_text_matcher_spec.rb
Outdated
Show resolved
Hide resolved
spec/unit/shoulda/matchers/active_record/have_rich_text_matcher_spec.rb
Outdated
Show resolved
Hide resolved
spec/unit/shoulda/matchers/active_record/have_rich_text_matcher_spec.rb
Outdated
Show resolved
Hide resolved
spec/unit/shoulda/matchers/active_record/have_rich_text_matcher_spec.rb
Outdated
Show resolved
Hide resolved
I removed the WIP, I think is almost done. What do you think? Tomorrow I'll look for the possibility of adding shared_examples. |
Done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reviewed this again and I have some more suggestions. Would you mind taking another look at this? I think we're getting pretty close :)
spec/unit/shoulda/matchers/active_record/have_rich_text_matcher_spec.rb
Outdated
Show resolved
Hide resolved
spec/unit/shoulda/matchers/active_record/have_rich_text_matcher_spec.rb
Outdated
Show resolved
Hide resolved
spec/unit/shoulda/matchers/active_record/have_rich_text_matcher_spec.rb
Outdated
Show resolved
Hide resolved
spec/unit/shoulda/matchers/active_record/have_rich_text_matcher_spec.rb
Outdated
Show resolved
Hide resolved
spec/unit/shoulda/matchers/active_record/have_rich_text_matcher_spec.rb
Outdated
Show resolved
Hide resolved
spec/unit/shoulda/matchers/active_record/have_rich_text_matcher_spec.rb
Outdated
Show resolved
Hide resolved
spec/unit/shoulda/matchers/active_record/have_rich_text_matcher_spec.rb
Outdated
Show resolved
Hide resolved
spec/unit/shoulda/matchers/active_record/have_rich_text_matcher_spec.rb
Outdated
Show resolved
Hide resolved
spec/unit/shoulda/matchers/active_record/have_rich_text_matcher_spec.rb
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more round. This is really looking nice :)
spec/unit/shoulda/matchers/active_record/have_rich_text_matcher_spec.rb
Outdated
Show resolved
Hide resolved
spec/unit/shoulda/matchers/active_record/have_rich_text_matcher_spec.rb
Outdated
Show resolved
Hide resolved
spec/unit/shoulda/matchers/active_record/have_rich_text_matcher_spec.rb
Outdated
Show resolved
Hide resolved
Everything LGTM now! The only thing left, it looks like, is to fix the merge conflicts. I'm not certain but it might have to do with the generated gemfile.lock file. Would you find looking into that and seeing if you can fix those? Other than that, @guialbuk you have any last thoughts on this? |
Sorry, but I'm not sure what to do. It's not showing any conflict to me.
Regardless of that, I updated my branch with master. Did that work out? |
@vsppedro What if you were to try rebasing the branch with master instead of merging master? If you would like to squash you are free to do that as well. |
Done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just two small comments, then it should be good to merge 🙂
spec/unit/shoulda/matchers/active_record/have_rich_text_matcher_spec.rb
Outdated
Show resolved
Hide resolved
The `have_rich_text` matcher tests usage of the `has_rich_text` macro that was added in Rails 6.
Looks like CI is green. Merging now! |
Hi, this PR solves the issue #1252.
It's a draft for now, I would love to know your opinion about it.
One of the things that needs to be improved in this PR is the creation of the
action_text_rich_texts
table. I'm out of ideas for now, any suggestions?