Hi there. Is it possible to get access to request ...
# pact-ruby
r
Hi there. Is it possible to get access to request params from provider states? For example: on consumer side I send GET/POST params and on provider side I want to see the list of those params and rewrite if needed
t
No, because this would mean that you couldn’t be sure the contract was appropriately validated
what are you trying to do?
r
Thanks for your response @Timothy Jones. I'm trying to rewrite on provider state 1 POST param ("memberId") which comes from consumer. I rewrite it using:
Copy code
allow_any_instance_of(ActionController::Parameters).to receive(:[]).with(:variables).and_return({ "memberId" => member.id, "stateCd" => 'CT' })
but the problem is that I don't want to specify other params like "stateCd" because I want them to come from consumer side. if I override only "memberId":
Copy code
allow_any_instance_of(ActionController::Parameters).to receive(:[]).with(:variables).and_return({ "memberId" => member.id})
then I'll lost "stateCd"
t
Why are you trying to do this?
r
@Timothy Jones because on provider side I already have generated members and their "ids" I don't know from consumer sides but only theirs names. So I send a request from consumer side specifying random member_id and on provider side I fetch specific member_id by name and override GET/POST params "memberId" which came from consumer:
Copy code
member = Member.find_by(name: 'user0')

allow_any_instance_of(ActionController::Parameters).to receive(:[]).with(:variables).and_return({ "memberId" => member.id})
I don'w want to hardcode correct member_id on consumer side. It may work locally on my laptop but there is no guarantee that the same DB id will be on another instance
t
Aha! Have a look into the provider state variables and fromProviderStat- I’m not sure if it’s supported in Ruby yet, but it’s for this exact use case
r
@Timothy Jones thanks. I will be grateful if you could send me some links because I didn't find how to pass vars into provider states.
t
They come from provider states. I don’t know the Ruby docs, I’m afraid. If it supports pact state v3, you can do it
1
*pact spec, sorry