#spec/controllers/third_party_elements_controller_spec.rb -fd
require 'rails_helper'
RSpec.describe ThirdPartySitesController, type: :controller do
...
end
describe 'GET #index' do
it 'returns http success' do
get :index
expect(response).to have_http_status(:success)
end
end
it 'adds a new record in database' do
params = { id: 18,
name: "Pixabay",
category: "internet",
kind: "video",
domain: "https://pixabay.com/en/videos/" }
expect { post(:create, third_party_site: params, format: :js) }
.to change { ThirdPartySite.count }.by(1)
end
it 'deletes a record from database' do
third_party_site # needed to lazy load the third party site
expect { delete(:destroy, id: third_party_site.id, format: :js) }
.to change { ThirdPartySite.count }.from(1).to(0)
end
# to access the @users variable set in users_controller we need to use assigns(:users)
it 'lists only active users' do
get :suspects
expect(assigns(:users).count).to eq(9)
end
it 'lists only active users', pry: true do
get :suspects
expect(assigns(:users).count).to eq(9)
end
rspec .spec/controllers/third_party_elements_controller_spec.rb -fd
the -fd flag is for improved readability