logs_controller_spec.rb 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738
  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_true
  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. sign_in users(:bob)
  20. lambda {
  21. delete :clear, :agent_id => agents(:bob_weather_agent).id
  22. }.should change { AgentLog.count }.by(-1 * agents(:bob_weather_agent).logs.count)
  23. assigns(:logs).length.should == 0
  24. agents(:bob_weather_agent).logs.count.should == 0
  25. end
  26. it "only deletes logs for an Agent owned by the current user" do
  27. sign_in users(:bob)
  28. lambda {
  29. delete :clear, :agent_id => agents(:jane_weather_agent).id
  30. }.should raise_error(ActiveRecord::RecordNotFound)
  31. end
  32. end
  33. end