PageRenderTime 58ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/spec/integration/conditional_validation/if_condition_spec.rb

http://github.com/datamapper/dm-validations
Ruby | 63 lines | 48 code | 15 blank | 0 comment | 2 complexity | 38773ae3bae7b51788ce91fe8e640b07 MD5 | raw file
  1. require 'spec_helper'
  2. require 'integration/conditional_validation/spec_helper'
  3. describe 'DataMapper::Validations::Fixtures::UDPPacket' do
  4. before :all do
  5. DataMapper::Validations::Fixtures::UDPPacket.auto_migrate!
  6. @model = DataMapper::Validations::Fixtures::UDPPacket.new
  7. end
  8. describe "that is transported encapsulated into IPv4 packet" do
  9. before :all do
  10. @model.underlying_ip_version = 4
  11. end
  12. describe "and has no checksum" do
  13. before :all do
  14. @model.checksum = nil
  15. end
  16. it_should_behave_like "valid model"
  17. end
  18. describe "and has no checksum algorithm" do
  19. before :all do
  20. @model.checksum_algorithm = nil
  21. end
  22. it_should_behave_like "valid model"
  23. end
  24. end
  25. describe "that is transported encapsulated into IPv6 packet" do
  26. before :all do
  27. @model.underlying_ip_version = 6
  28. end
  29. describe "and has no checksum" do
  30. before :all do
  31. @model.checksum = nil
  32. end
  33. it_should_behave_like "invalid model"
  34. it "has a meaningful error message" do
  35. @model.errors.on(:checksum).should == [ 'Checksum is mandatory when used with IPv6' ]
  36. end
  37. end
  38. describe "and has no checksum algorithm" do
  39. before :all do
  40. @model.checksum_algorithm = nil
  41. end
  42. it_should_behave_like "invalid model"
  43. it "has a meaningful error message" do
  44. @model.errors.on(:checksum_algorithm).should == [ 'Checksum is mandatory when used with IPv6' ]
  45. end
  46. end
  47. end
  48. end