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

Add some sort of with_keys option to send_json #1846

Open
jwoertink opened this issue Nov 30, 2023 · 1 comment
Open

Add some sort of with_keys option to send_json #1846

jwoertink opened this issue Nov 30, 2023 · 1 comment
Labels
hacktoberfest Valid Issue for Hacktoberfest

Comments

@jwoertink
Copy link
Member

I don't know exactly what this looks like yet, but I have a ton of really large custom JSON output in my actions that are too complex to say response.should send_json(200, messages: [{.......}]). Really I don't care that the value looks exactly a specific way, I just want to ensure that there is a value from that key. So really I want something kind of like..

response.should send_json(200, with_keys: [:messages, ....])

or maybe comparing a type somehow?

response.should send_json(200, with: {messages: Array(MessageSerializer)})

definitely a half-baked idea 😂

def send_json(status, **expected)

@jwoertink
Copy link
Member Author

Thinking about this more... Maybe we can just do deep nested checks? For example, I want to know if the response has a key with a value that's a massive object, but I only need to verify that one of the key/values in that massive object exist...

# {user: {username: "...", slug: "...", created_at: ..., updated_at: ...., preferences: {theme: "dark", size: "large"}}}
response.should send_json(200, user: {username: "...", preferences: {theme: "dark"}})

This would then let me just do a quick few spot checks on an object instead of trying to worry about the exact time on created_at, or building out each object in a sub array and so on.

@jwoertink jwoertink added the hacktoberfest Valid Issue for Hacktoberfest label Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest Valid Issue for Hacktoberfest
Projects
None yet
Development

No branches or pull requests

1 participant