Dipak Panchal
Dipak Panchal

Reputation: 6026

How to Test Controller Private Method

This is my private method of controller

 def query_url(query)
   client_queries_path(@client, query)
 end

and this is my index.json.jbuilder file that I use that method

json.array!(@queries) do |query|
  json.extract! query, :id, :url, :keywords, :exclusions
  json.url query_url(query, format: :json)
end

I want to write test cases for that - so How can I write ?

Thanks In Advance

Upvotes: 0

Views: 581

Answers (1)

user740584
user740584

Reputation:

If you are using something like rspec you can call a private method with controller.send. So in your case:

controller.send(:query_url, "whatever query you want to test")

Upvotes: 1

Related Questions