logs_controller_spec.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. require 'spec_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, :agent_id => agents(:bob_weather_agent).id
  7. assigns(:logs).length.should == agents(:bob_weather_agent).logs.length
  8. assigns(:logs).all? {|i| i.agent.should == agents(:bob_weather_agent) }.should be_truthy
  9. end
  10. it "only loads Agents owned by the current user" do
  11. sign_in users(:bob)
  12. lambda {
  13. get :index, :agent_id => agents(:jane_weather_agent).id
  14. }.should 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. lambda {
  22. delete :clear, :agent_id => agents(:bob_weather_agent).id
  23. }.should change { AgentLog.count }.by(-1 * agents(:bob_weather_agent).logs.count)
  24. assigns(:logs).length.should == 0
  25. agents(:bob_weather_agent).reload.logs.count.should == 0
  26. agents(:bob_weather_agent).last_error_log_at.should be_nil
  27. end
  28. it "only deletes logs for an Agent owned by the current user" do
  29. sign_in users(:bob)
  30. lambda {
  31. delete :clear, :agent_id => agents(:jane_weather_agent).id
  32. }.should raise_error(ActiveRecord::RecordNotFound)
  33. end
  34. end
  35. end