How should i test controller with jbuilder views?

129 Views Asked by At

this is my controller

class NewsController < ApplicationController 
    def show 
        @news = News.find_by id: params[:id]
    end
 end

this is views

json.extract! @news ,:id, :title , :content , :created_at , :updated_at
json.image @news.images do |image| 
    json.url url_for(image)
  end

what is right way of testing this controller and views. I'am new into testing so i'am little bit frustrated with this

1

There are 1 best solutions below

0
On

You can verify the status and the json result you are expecting

it "should have a 200 code" do
  get :show, params: { id: 1 }, format: :json
  expect(response.status).to eq 200
  expect(response.body).to eq expected_json
end

Refer this article for more info