scenario_spec.rb 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. require 'spec_helper'
  2. describe Scenario do
  3. let(:new_instance) { users(:bob).scenarios.build(:name => "some scenario") }
  4. it_behaves_like HasGuid
  5. describe "validations" do
  6. before do
  7. new_instance.should be_valid
  8. end
  9. it "validates the presence of name" do
  10. new_instance.name = ''
  11. new_instance.should_not be_valid
  12. end
  13. it "validates the presence of user" do
  14. new_instance.user = nil
  15. new_instance.should_not be_valid
  16. end
  17. it "validates tag_fg_color is hex color" do
  18. new_instance.tag_fg_color = '#N07H3X'
  19. new_instance.should_not be_valid
  20. new_instance.tag_fg_color = '#BADA55'
  21. new_instance.should be_valid
  22. end
  23. it "allows nil tag_fg_color" do
  24. new_instance.tag_fg_color = nil
  25. new_instance.should be_valid
  26. end
  27. it "validates tag_bg_color is hex color" do
  28. new_instance.tag_bg_color = '#N07H3X'
  29. new_instance.should_not be_valid
  30. new_instance.tag_bg_color = '#BADA55'
  31. new_instance.should be_valid
  32. end
  33. it "allows nil tag_bg_color" do
  34. new_instance.tag_bg_color = nil
  35. new_instance.should be_valid
  36. end
  37. it "only allows Agents owned by user" do
  38. new_instance.agent_ids = [agents(:bob_website_agent).id]
  39. new_instance.should be_valid
  40. new_instance.agent_ids = [agents(:jane_website_agent).id]
  41. new_instance.should_not be_valid
  42. end
  43. end
  44. describe "counters" do
  45. it "maintains a counter cache on user" do
  46. lambda {
  47. new_instance.save!
  48. }.should change { users(:bob).reload.scenario_count }.by(1)
  49. lambda {
  50. new_instance.destroy
  51. }.should change { users(:bob).reload.scenario_count }.by(-1)
  52. end
  53. end
  54. end