Does anyone know how to test the logging of Unpermitted parameters using Rspec.
I have tried using Rails.logger.should_receive() with :warn, :info, :error but I can't seem to capture the log message.
Here is the controller test:
describe Api::V2::ItemsController do
before do
@item = FactoryGirl.create(:item)
@user_id = @item.user_id
@invalid_user_id = @user_id + 1
end
it 'should not assign user_id' do
put :update, id: @item.id, item: { user_id: @invalid_user_id }
assigns(:item).user_id.should == @user_id
end
it 'should write "Unpermitted parameters: user_id" to log' do
Rails.logger.should_receive(:warn).with("Unpermitted parameters: user_id")
put :update, id: @item.id, item: { user_id: @invalid_user_id }
end
end
Have you tried with :debug?
expect(Rails.logger).to receive(:debug).with('...')
# or
# expect(ActionController::Base.logger).to receive(:debug).with('...')
To change the log level to warn you could try the config below in any of your environment files.
# config/environments/development.rb
# config/environments/production.rb
config.log_level = :warn