logs_controller_spec.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. require 'rails_helper'
  2. describe LogsController do
  3. describe "GET index" do
  4. it "can filter by Agent" do
  5. sign_in users(:bob)
  6. get :index, params: {:agent_id => agents(:bob_weather_agent).id}
  7. expect(assigns(:logs).length).to eq(agents(:bob_weather_agent).logs.length)
  8. expect(assigns(:logs).all? {|i| expect(i.agent).to eq(agents(:bob_weather_agent)) }).to be_truthy
  9. end
  10. it "only loads Agents owned by the current user" do
  11. sign_in users(:bob)
  12. expect {
  13. get :index, params: {:agent_id => agents(:jane_weather_agent).id}
  14. }.to raise_error(ActiveRecord::RecordNotFound)
  15. end
  16. end
  17. describe "DELETE clear" do
  18. it "deletes all logs for a specific Agent" do
  19. agents(:bob_weather_agent).last_error_log_at = 2.hours.ago
  20. sign_in users(:bob)
  21. expect {
  22. delete :clear, params: {:agent_id => agents(:bob_weather_agent).id}
  23. }.to change { AgentLog.count }.by(-1 * agents(:bob_weather_agent).logs.count)
  24. expect(assigns(:logs).length).to eq(0)
  25. expect(agents(:bob_weather_agent).reload.logs.count).to eq(0)
  26. expect(agents(:bob_weather_agent).last_error_log_at).to be_nil
  27. end
  28. it "only deletes logs for an Agent owned by the current user" do
  29. sign_in users(:bob)
  30. expect {
  31. delete :clear, params: {:agent_id => agents(:jane_weather_agent).id}
  32. }.to raise_error(ActiveRecord::RecordNotFound)
  33. end
  34. end
  35. end