#find_model does not use label to find the model
-
Ian White
If you are using find_model to retrieve a model using the pickle ref, I think that the 'model' method is what you want...
model 'user: "Fred"'
or
model! 'user: "Fred"' (raises if no such model is available in the scenario)find_model finds a model using the passed attrs, and stores it for pickle usage under the given named. So, in your case it finds the first model (because you;ve not given any attrs to find by) and stores it as 'user: "Fred"'
Cheers,
Ian -
Bo Kirkeby
Yeah,
#modelworks great. I was trying to do something like:Given a user: "Fred" exists When I delete the user: "Fred" Then the user: "Fred" should not existAnd this does not work as I expect if another user exists because the generated pickle step matching
Then the user: "Fred" should not existuses#find_model.I could tweak the step definition to do what I want with
#model, but I thought#find_modelwas supposed to use the label also.Thanks for your time,
Bo -
Ian White
Hi Bo,
Remember that the pickle refs are purely for internal referencing in a scenario.
With that in mind, You probably want to use an attribute on the model to find/create the user:
Given a user "Fred" exists with name: "fred"
When I delete the user "Fred"
Then a user should not exist with name: "fred"Cheers,
Ian -
Ian White
Thinking about it some more, your use case illustrates that an error should be raised if you are asserting non-existence of models, and giving a name
EIther that, or make two steps, one which queries the db, and one which queries via pickle
Then the user: "fred" should not exist Then the user should not exist #=> model(pickle_ref).should be_nil Then 0 users should exist with name: "fred" Then no users should exist with name: "fred" #=> look in the dbCheers,
Ian -
Bo Kirkeby
Alright, I guess I misunderstood the intent of
#find_model.Do you think it is wrong to test non-existence of a model using a label instead of by attributes?
I could do something like this in the step definition:lambda { model(name) }.should raise_error(ActiveRecord::RecordNotFound)It seems to work correctly, but is it using the pickle reference for something that was really not intended?
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.