Skip to content
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

Make Hashie play nice with Rails 6 Hash#except method #479

Merged
merged 16 commits into from
Oct 2, 2019

Conversation

BobbyMcWho
Copy link
Collaborator

Resolves #476

Because Rails 6 switched their implementation of #except to use slice and slice returns a new ruby hash, we need to translate that back to the class that slice was called on.

Let me know if you see any concerns that can be improved upon.

Copy link
Member

@michaelherold michaelherold left a comment

Choose a reason for hiding this comment

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

I like this implementation. I'm happy to see that it's not a Rails-specific issue, but that Mash doesn't implement #slice. Since that is a standard library method, we should implement it on Rubies that have it, like you're doing here.

I have a couple of changes I'd like to make to the test suite. If those pass once you merge them, we're good-to-go!

spec/integration/rails/integration_spec.rb Outdated Show resolved Hide resolved
spec/hashie/mash_spec.rb Outdated Show resolved Hide resolved
@BobbyMcWho
Copy link
Collaborator Author

@michaelherold e1700b2 adds a railtie for except, I've never made a railtie before, so feel free to let me know if I broke any conventions, the symbol keys test now passes.

@michaelherold
Copy link
Member

As I mentioned in the issue thread, I would rather not ship Rails-specific behavior in Hashie proper if we can avoid it ... but I guess we already have the Railtie for logging. I'm going to think about this for a bit.

@BobbyMcWho
Copy link
Collaborator Author

@michaelherold more than happy to move that specific piece to a gem if you'd like

@michaelherold
Copy link
Member

Since we already have the Railtie, I think I'm alright with this as-is. For Hashie 4, we'll consider moving all Rails-specific behavior into a companion gem.

@michaelherold
Copy link
Member

Thinking about this a little more, I think we might want to gate redefinition of #except to Rails 6+. Since it works with 5.2, we wouldn't want to monkey-patch code that works.

What do you think, @BobbyMcWho?

@BobbyMcWho
Copy link
Collaborator Author

@michaelherold I could see it going either way, since I switched it to use super, it will be backwards compatible with the old implementation, but will call an unnecessary string_keys = keys.map { |key| convert_key(key) }

@dblock
Copy link
Member

dblock commented Aug 18, 2019

Let's rebase this and deal with it? @BobbyMcWho

@BobbyMcWho
Copy link
Collaborator Author

Rails 6 seems to have broken the rails integration test. If I find some time I'll try and figure out what exactly is wrong now.

Using the view_paths was causing issues in rails 6, rendering inline
erb prevents those issues.
@BobbyMcWho
Copy link
Collaborator Author

@dblock I've fixed the failing CI

@dblock
Copy link
Member

dblock commented Sep 16, 2019

LGTM, @michaelherold ?

Copy link
Member

@michaelherold michaelherold left a comment

Choose a reason for hiding this comment

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

One question, otherwise this looks good to me.


def index; end
def index
render inline: PAGE
Copy link
Member

Choose a reason for hiding this comment

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

🤔 Hmm. I think I'm good with this. I don't believe we'll ever do anything where we monkey with view paths so the simplification is good.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

something changed with the rails 6 release that broke this test and I couldn't pinpoint what it was, this was the only semi reasonable way I could get it passing again since I believe that view paths method was deprecated and removed

.rubocop.yml Show resolved Hide resolved
@dblock
Copy link
Member

dblock commented Sep 26, 2019

This LGTM, @michaelherold shall we squash & merge?

@dblock
Copy link
Member

dblock commented Sep 30, 2019

So can we fix the faraday error in danger here? Hopefully without an if :)

@BobbyMcWho
Copy link
Collaborator Author

@michaelherold and I both had faraday changes merged and released over the weekend, so hopefully it's finally fixed. I don't know why CI failed to kick off a build just now...

@michaelherold
Copy link
Member

I don't know why CI failed to kick off a build just now...

It's because Octokit hasn't merged and released octokit/octokit.rb#1154 yet, so Danger is pulling a broken combination of Faraday and Octokit. The easiest way to work around this is to lock faraday to 0.15.4 for now for the purposes of Danger.

@BobbyMcWho
Copy link
Collaborator Author

Hmm, I thought 1.16.2 would have fixed it (your original implementation failed when inheriting the old error-namespaced classes :( @michaelherold )

@BobbyMcWho
Copy link
Collaborator Author

BobbyMcWho commented Sep 30, 2019

Ahh @michaelherold it didn't run because I simply dropped the last commit and it already had a run on that commit I'm guessing. Looks like build is passing in my CI if you wanna manually trigger a build here.
Edit:
I amended the commit with no changes to trigger the build.

Copy link
Member

@michaelherold michaelherold left a comment

Choose a reason for hiding this comment

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

Gotcha! That makes a lot more sense. Your find with the subclassing constant was a really good one, by the way. 😄

I don't see a reason why we should sit on this any longer. The NoMethodError -> NameError change is still a little concerning to me, but I don't really remember the specifics of what I was thinking with the index_document test so I'm going to let it be. We're testing that an error happens and that seems good enough!

@BobbyMcWho
Copy link
Collaborator Author

Gotcha! That makes a lot more sense. Your find with the subclassing constant was a really good one, by the way. 😄

Ha, I saw the error message in this CI run and was like aw man. My solution for 0.16.2 was kinda cobbled together, and I think lostisland/faraday#1043 is a better solution than what I originally got merged 😆

@dblock dblock merged commit ca36045 into hashie:master Oct 2, 2019
@dblock
Copy link
Member

dblock commented Oct 2, 2019

I merged this. Thanks for hanging in here with us @BobbyMcWho!

@BobbyMcWho
Copy link
Collaborator Author

Awesome, are we still planning a major bump release of this all since that 1 PR that changed some non-destructive method return types? Will it be a rc1?

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.

Rails 6 #except incompatible with Hashie::Mash
3 participants