Skip to content

fix: Run actiontext migrations for rails >= 6#1365

Merged
mcmire merged 1 commit intothoughtbot:masterfrom
KapilSachdev:fix/action_text_rails_version
Nov 8, 2020
Merged

fix: Run actiontext migrations for rails >= 6#1365
mcmire merged 1 commit intothoughtbot:masterfrom
KapilSachdev:fix/action_text_rails_version

Conversation

@KapilSachdev
Copy link
Copy Markdown
Collaborator

@KapilSachdev KapilSachdev commented Nov 1, 2020

... as actiontext is made available on rails 6.0

@KapilSachdev KapilSachdev force-pushed the fix/action_text_rails_version branch from 6e8602b to 1f9996e Compare November 1, 2020 17:47
@KapilSachdev KapilSachdev changed the title fix: Run actiontext migrations for rails > 6 fix: Run actiontext migrations for rails >= 6 Nov 1, 2020
@KapilSachdev KapilSachdev force-pushed the fix/action_text_rails_version branch from 1f9996e to c179dcf Compare November 1, 2020 17:50

if rails_version > 5 && bundle.includes?('actiontext')
if rails_version >= 6 && bundle.includes?('actiontext')
add_action_text_migration
Copy link
Copy Markdown
Collaborator

@vsppedro vsppedro Nov 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it can be used in versions below if included in the Gemfile that is why the other condition. (bundle.includes?('actiontext'))

For example: https://www.driftingruby.com/episodes/using-action-text-in-a-rails-5-2-application

I notice now that I forgot to test the actiontext on other versions. It's only tested on Rails 6. If we decide to not test on 5.2, I see no problem with this adjustment.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice now that I forgot to test the actiontext on other versions. It's only tested on Rails 6. If we decide to not test on 5.2, I see no problem with this adjustment.

Unless we use a patched fork to work around, rails/actiontext gem dependencies for rails < 6 can not be met from official sources.

We can also use bundle.includes?('actiontext') only rather than checking the version.

Copy link
Copy Markdown
Collaborator

@vsppedro vsppedro Nov 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you are right. We can ignore the version. I don't see any problem with this change, but I think we can do even better. Let me take another look at the project.

EDIT 1: LGTM!
EDIT2: I was looking at this file and wondering why I didn't do something similar, but I don't think something like that is necessary for this case. We can do this refactoring later if the need arises. Thank you for pointing this out.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, maybe later it becomes a refactoring candidate as we do not rely on version but rather on definition of actiontext.

@mcmire
Copy link
Copy Markdown
Collaborator

mcmire commented Nov 2, 2020

Is this build failing, is that what caused this change? I guess I'm wondering what this affects and how you knew to change this.

@KapilSachdev
Copy link
Copy Markdown
Collaborator Author

Yes, I noticed it because of the build failure while fixing Style/ClassEqualityComparison offence.

Though I think I will have to add defined?(ActionText::RichText) at

def has_expected_action_text?
@subject.send(rich_text_attribute).class.name == 'ActionText::RichText'
end

- as actiontext is made available on rails 6.0
@KapilSachdev KapilSachdev force-pushed the fix/action_text_rails_version branch from c179dcf to 8ac98be Compare November 2, 2020 17:03
@vsppedro
Copy link
Copy Markdown
Collaborator

vsppedro commented Nov 2, 2020

I'm sorry, but I'm not sure how this fix will help you with the CI breaking on #1350.

The problem there is ActionText::RichText being called without being defined. For that reason, we compared with a string as you can see in this comment: #1263 (comment)

There are tests when the ActionText is not defined: https://github.com/thoughtbot/shoulda-matchers/blob/master/spec/unit/shoulda/matchers/active_record/have_rich_text_matcher_spec.rb#L51

We need to find another way to check if the attribute is an ActionText::RichText instance without using the class.

EDIT:

I'm almost sure that this change will fix the problem on #1350:

defined?(ActionText::RichText) && @subject.send(rich_text_attribute).instance_of?(ActionText::RichText)

PS: But I think it should be done on #1350.

@KapilSachdev
Copy link
Copy Markdown
Collaborator Author

While running tests of this repo, actiontext will not be available for rails < 6, so the condition is wrong rails_version > 5.

defined?(ActionText::RichText) && @subject.send(rich_text_attribute).instance_of?(ActionText::RichText)

Yes, I would have to do that at #1350 .

I didn't wanted rails version changes to be part of #1350 because they don't belong there.
Though there had been some code changes that rubocop forced to be done, but i'm trying for them to be minimal.

@mcmire
Copy link
Copy Markdown
Collaborator

mcmire commented Nov 8, 2020

Ah, I see. The build isn't broken, this seems to be more of a consistency thing, as we don't check for a Rails version in the tests either:

Okay, that makes sense to me. Merging!

@mcmire mcmire merged commit a06f0ae into thoughtbot:master Nov 8, 2020
@KapilSachdev KapilSachdev deleted the fix/action_text_rails_version branch November 11, 2020 20:31
@KapilSachdev KapilSachdev added this to the 4.5.0 milestone Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants