web_request_concern.rb 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. require 'spec_helper'
  2. shared_examples_for WebRequestConcern do
  3. let(:agent) do
  4. _agent = described_class.new(:name => "some agent", :options => @valid_options || {})
  5. _agent.user = users(:jane)
  6. _agent
  7. end
  8. describe "validations" do
  9. it "should be valid" do
  10. agent.should be_valid
  11. end
  12. it "should validate user_agent" do
  13. agent.options['user_agent'] = nil
  14. agent.should be_valid
  15. agent.options['user_agent'] = ""
  16. agent.should be_valid
  17. agent.options['user_agent'] = "foo"
  18. agent.should be_valid
  19. agent.options['user_agent'] = ["foo"]
  20. agent.should_not be_valid
  21. agent.options['user_agent'] = 1
  22. agent.should_not be_valid
  23. end
  24. it "should validate headers" do
  25. agent.options['headers'] = "blah"
  26. agent.should_not be_valid
  27. agent.options['headers'] = ""
  28. agent.should be_valid
  29. agent.options['headers'] = {}
  30. agent.should be_valid
  31. agent.options['headers'] = { 'foo' => 'bar' }
  32. agent.should be_valid
  33. end
  34. it "should validate basic_auth" do
  35. agent.options['basic_auth'] = "foo:bar"
  36. agent.should be_valid
  37. agent.options['basic_auth'] = ["foo", "bar"]
  38. agent.should be_valid
  39. agent.options['basic_auth'] = ""
  40. agent.should be_valid
  41. agent.options['basic_auth'] = nil
  42. agent.should be_valid
  43. agent.options['basic_auth'] = "blah"
  44. agent.should_not be_valid
  45. agent.options['basic_auth'] = ["blah"]
  46. agent.should_not be_valid
  47. end
  48. end
  49. end