spec/audited/sweeper_spec.rb in audited-4.8.0 vs spec/audited/sweeper_spec.rb in audited-4.9.0

- old
+ new

@@ -1,7 +1,9 @@ require "spec_helper" +SingleCov.covered! uncovered: 2 # 2 conditional on_load conditions + class AuditsController < ActionController::Base before_action :populate_user attr_reader :company @@ -9,11 +11,11 @@ @company = Models::ActiveRecord::Company.create head :ok end def update - current_user.update_attributes(password: 'foo') + current_user.update!(password: 'foo') head :ok end private @@ -25,27 +27,35 @@ describe AuditsController do include RSpec::Rails::ControllerExampleGroup render_views - before(:each) do + before do Audited.current_user_method = :current_user end let(:user) { create_user } describe "POST audit" do - it "should audit user" do controller.send(:current_user=, user) expect { post :create }.to change( Audited::Audit, :count ) expect(controller.company.audits.last.user).to eq(user) end + it "does not audit when method is not found" do + controller.send(:current_user=, user) + Audited.current_user_method = :nope + expect { + post :create + }.to change( Audited::Audit, :count ) + expect(controller.company.audits.last.user).to eq(nil) + end + it "should support custom users for sweepers" do controller.send(:custom_user=, user) Audited.current_user_method = :custom_user expect { @@ -82,11 +92,10 @@ post :create }.to change( Audited::Audit, :count ) expect(controller.company.audits.last.user).to eq(user) end - end describe "PUT update" do it "should not save blank audits" do controller.send(:current_user=, user) @@ -95,10 +104,9 @@ put :update, Rails::VERSION::MAJOR == 4 ? {id: 123} : {params: {id: 123}} }.to_not change( Audited::Audit, :count ) end end end - describe Audited::Sweeper do it "should be thread-safe" do instance = Audited::Sweeper.new