Closed betesh closed 9 years ago
@betesh I think I understand what you're saying.
The referenced line attempts to seed the mock data with the user you initialized the client with. It falsely assumes that the client will only be initialized with those credentials once.
Seems like the solution would be to handle duplicates when seeding the mock data. Do you agree ?
Yes. i.e. before calling create_user
, check whether the mock data for that client already contains a user with the same email.
@betesh https://rubygems.org/gems/zendesk2/versions/1.7.3 has the fix
Thanks!
In a Ruby-on-Rails controller test, I need to set up some data for my mock client. The actual controller builds a new Zendesk2::Client--it can't use the same instance as I used in the test to set things up, because if I inject the mock client into my application code, then I'm not really testing the application code.
However, when I try to create a new instance, I get this error:
From digging into the source code, it looks like the problem is that on this line, it assumes that whenever you instantiate a new
Zendesk2::Client::Mock
, you also want to instantiate a new user. In my case, that is an incorrect assumption.Here's a minimal demo of the issue:
I'm assuming that in production mode (i.e. when not mocking), this won't be a problem--whenever you instantiate a
Zendesk2::Client::Real
, the user already exists, so I'm looking for a way to create the same experience using aZendesk2::Client::Mock
.