dm-validations 0.9.11 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{History.txt → History.rdoc} +10 -3
- data/LICENSE +1 -0
- data/Manifest.txt +103 -33
- data/README.rdoc +172 -0
- data/Rakefile +4 -5
- data/lib/dm-validations.rb +73 -75
- data/lib/dm-validations/auto_validate.rb +98 -56
- data/lib/dm-validations/contextual_validators.rb +37 -14
- data/lib/dm-validations/exceptions.rb +3 -0
- data/lib/dm-validations/formats/url.rb +3 -1
- data/lib/dm-validations/support/context.rb +54 -0
- data/lib/dm-validations/validation_errors.rb +51 -27
- data/lib/dm-validations/{absent_field_validator.rb → validators/absent_field_validator.rb} +2 -8
- data/lib/dm-validations/{acceptance_validator.rb → validators/acceptance_validator.rb} +7 -7
- data/lib/dm-validations/{block_validator.rb → validators/block_validator.rb} +0 -0
- data/lib/dm-validations/{confirmation_validator.rb → validators/confirmation_validator.rb} +7 -7
- data/lib/dm-validations/{format_validator.rb → validators/format_validator.rb} +10 -16
- data/lib/dm-validations/{generic_validator.rb → validators/generic_validator.rb} +28 -6
- data/lib/dm-validations/validators/length_validator.rb +214 -0
- data/lib/dm-validations/validators/method_validator.rb +68 -0
- data/lib/dm-validations/validators/numeric_validator.rb +171 -0
- data/lib/dm-validations/{primitive_validator.rb → validators/primitive_validator.rb} +2 -7
- data/lib/dm-validations/{required_field_validator.rb → validators/required_field_validator.rb} +0 -6
- data/lib/dm-validations/{uniqueness_validator.rb → validators/uniqueness_validator.rb} +9 -20
- data/lib/dm-validations/{within_validator.rb → validators/within_validator.rb} +4 -4
- data/lib/dm-validations/version.rb +1 -1
- data/spec/fixtures/barcode.rb +32 -0
- data/spec/fixtures/basketball_court.rb +58 -0
- data/spec/fixtures/basketball_player.rb +37 -0
- data/spec/fixtures/beta_tester_account.rb +33 -0
- data/spec/fixtures/bill_of_landing.rb +42 -0
- data/spec/fixtures/boat_dock.rb +26 -0
- data/spec/fixtures/city.rb +25 -0
- data/spec/fixtures/company.rb +95 -0
- data/spec/fixtures/corporate_world.rb +47 -0
- data/spec/fixtures/country.rb +25 -0
- data/spec/fixtures/currency.rb +42 -0
- data/spec/fixtures/ethernet_frame.rb +56 -0
- data/spec/fixtures/event.rb +44 -0
- data/spec/fixtures/g3_concert.rb +57 -0
- data/spec/fixtures/jabberwock.rb +27 -0
- data/spec/fixtures/kayak.rb +28 -0
- data/spec/fixtures/lernean_hydra.rb +39 -0
- data/spec/fixtures/mathematical_function.rb +34 -0
- data/spec/fixtures/memory_object.rb +30 -0
- data/spec/fixtures/mittelschnauzer.rb +35 -0
- data/spec/fixtures/motor_launch.rb +21 -0
- data/spec/fixtures/page.rb +32 -0
- data/spec/fixtures/phone_number.rb +28 -0
- data/spec/fixtures/pirogue.rb +28 -0
- data/spec/fixtures/programming_language.rb +83 -0
- data/spec/fixtures/reservation.rb +38 -0
- data/spec/fixtures/scm_operation.rb +67 -0
- data/spec/fixtures/sms_message.rb +22 -0
- data/spec/fixtures/udp_packet.rb +49 -0
- data/spec/integration/absent_field_validator/absent_field_validator_spec.rb +86 -0
- data/spec/integration/absent_field_validator/spec_helper.rb +7 -0
- data/spec/integration/acceptance_validator/acceptance_validator_spec.rb +196 -0
- data/spec/integration/acceptance_validator/spec_helper.rb +7 -0
- data/spec/integration/automatic_validation/custom_messages_for_inferred_validation_spec.rb +47 -0
- data/spec/integration/automatic_validation/disabling_inferred_validation_spec.rb +41 -0
- data/spec/integration/automatic_validation/inferred_boolean_properties_validation_spec.rb +104 -0
- data/spec/integration/automatic_validation/inferred_float_property_validation_spec.rb +35 -0
- data/spec/integration/automatic_validation/inferred_format_validation_spec.rb +33 -0
- data/spec/integration/automatic_validation/inferred_integer_properties_validation_spec.rb +73 -0
- data/spec/integration/automatic_validation/inferred_length_validation_spec.rb +121 -0
- data/spec/integration/automatic_validation/inferred_presence_validation_spec.rb +41 -0
- data/spec/integration/automatic_validation/inferred_primitive_validation_spec.rb +20 -0
- data/spec/integration/automatic_validation/inferred_within_validation_spec.rb +33 -0
- data/spec/integration/automatic_validation/spec_helper.rb +74 -0
- data/spec/integration/block_validator/block_validator_spec.rb +32 -0
- data/spec/integration/block_validator/spec_helper.rb +5 -0
- data/spec/integration/conditional_validation/if_condition_spec.rb +61 -0
- data/spec/integration/conditional_validation/spec_helper.rb +5 -0
- data/spec/integration/confirmation_validator/confirmation_validator_spec.rb +74 -0
- data/spec/integration/confirmation_validator/spec_helper.rb +5 -0
- data/spec/integration/datamapper_models/association_validation_spec.rb +23 -0
- data/spec/integration/datamapper_models/inheritance_spec.rb +78 -0
- data/spec/integration/duplicated_validations/duplicated_validations_spec.rb +22 -0
- data/spec/integration/duplicated_validations/spec_helper.rb +5 -0
- data/spec/integration/format_validator/email_format_validator_spec.rb +113 -0
- data/spec/integration/format_validator/format_validator_spec.rb +60 -0
- data/spec/integration/format_validator/regexp_validator_spec.rb +29 -0
- data/spec/integration/format_validator/spec_helper.rb +5 -0
- data/spec/integration/format_validator/url_format_validator_spec.rb +63 -0
- data/spec/integration/length_validator/default_value_spec.rb +12 -0
- data/spec/integration/length_validator/equality_spec.rb +79 -0
- data/spec/integration/length_validator/error_message_spec.rb +15 -18
- data/spec/integration/length_validator/maximum_spec.rb +40 -24
- data/spec/integration/length_validator/minimum_spec.rb +32 -21
- data/spec/integration/length_validator/range_spec.rb +50 -60
- data/spec/integration/length_validator/spec_helper.rb +7 -12
- data/spec/integration/method_validator/method_validator_spec.rb +239 -0
- data/spec/integration/method_validator/spec_helper.rb +5 -0
- data/spec/integration/numeric_validator/equality_with_float_type_spec.rb +61 -0
- data/spec/integration/numeric_validator/equality_with_integer_type_spec.rb +37 -0
- data/spec/integration/numeric_validator/float_type_spec.rb +42 -56
- data/spec/integration/numeric_validator/gt_with_float_type_spec.rb +35 -0
- data/spec/integration/numeric_validator/gte_with_float_type_spec.rb +35 -0
- data/spec/integration/numeric_validator/integer_only_true_spec.rb +3 -6
- data/spec/integration/numeric_validator/integer_type_spec.rb +8 -24
- data/spec/integration/numeric_validator/lt_with_float_type_spec.rb +35 -0
- data/spec/integration/numeric_validator/lte_with_float_type_spec.rb +35 -0
- data/spec/integration/numeric_validator/spec_helper.rb +5 -77
- data/spec/integration/primitive_validator/primitive_validator_spec.rb +90 -0
- data/spec/integration/primitive_validator/spec_helper.rb +5 -0
- data/spec/integration/pure_ruby_objects/plain_old_ruby_object_validation_spec.rb +118 -0
- data/spec/integration/required_field_validator/association_spec.rb +5 -8
- data/spec/integration/required_field_validator/boolean_type_value_spec.rb +4 -7
- data/spec/integration/required_field_validator/date_type_value_spec.rb +3 -6
- data/spec/integration/required_field_validator/datetime_type_value_spec.rb +3 -6
- data/spec/integration/required_field_validator/float_type_value_spec.rb +3 -6
- data/spec/integration/required_field_validator/integer_type_value_spec.rb +2 -5
- data/spec/integration/required_field_validator/plain_old_ruby_object_spec.rb +5 -8
- data/spec/integration/required_field_validator/shared_examples.rb +1 -1
- data/spec/integration/required_field_validator/spec_helper.rb +6 -67
- data/spec/integration/required_field_validator/string_type_value_spec.rb +2 -5
- data/spec/integration/required_field_validator/text_type_value_spec.rb +2 -5
- data/spec/integration/shared/default_validation_context.rb +13 -0
- data/spec/integration/shared/valid_and_invalid_model.rb +27 -0
- data/spec/integration/uniqueness_validator/spec_helper.rb +5 -0
- data/spec/integration/uniqueness_validator/uniqueness_validator_spec.rb +114 -0
- data/spec/integration/within_validator/spec_helper.rb +5 -0
- data/spec/integration/within_validator/within_validator_spec.rb +164 -0
- data/spec/public/resource_spec.rb +68 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +12 -4
- data/spec/unit/contextual_validators/emptiness_spec.rb +50 -0
- data/spec/unit/contextual_validators/execution_spec.rb +55 -0
- data/spec/unit/contextual_validators/spec_helper.rb +37 -0
- data/spec/unit/generic_validator/equality_operator_spec.rb +26 -0
- data/spec/unit/validation_errors/adding_spec.rb +54 -0
- data/spec/unit/validation_errors/emptiness_spec.rb +38 -0
- data/spec/unit/validation_errors/enumerable_spec.rb +32 -0
- data/tasks/install.rb +1 -1
- data/tasks/spec.rb +4 -4
- metadata +118 -55
- data/README.txt +0 -72
- data/lib/dm-validations/custom_validator.rb +0 -72
- data/lib/dm-validations/length_validator.rb +0 -113
- data/lib/dm-validations/method_validator.rb +0 -68
- data/lib/dm-validations/numeric_validator.rb +0 -83
- data/spec/integration/absent_field_validator_spec.rb +0 -36
- data/spec/integration/acceptance_validator_spec.rb +0 -87
- data/spec/integration/auto_validate_spec.rb +0 -342
- data/spec/integration/block_validator_spec.rb +0 -30
- data/spec/integration/confirmation_validator_spec.rb +0 -105
- data/spec/integration/contextual_validators_spec.rb +0 -27
- data/spec/integration/custom_validator_spec.rb +0 -9
- data/spec/integration/format_validator_spec.rb +0 -193
- data/spec/integration/generic_validator_spec.rb +0 -17
- data/spec/integration/length_validator/valid_objects_spec.rb +0 -13
- data/spec/integration/method_validator_spec.rb +0 -58
- data/spec/integration/numeric_validator_spec.rb +0 -253
- data/spec/integration/primitive_validator_spec.rb +0 -30
- data/spec/integration/uniqueness_validator_spec.rb +0 -97
- data/spec/integration/validation_errors_spec.rb +0 -18
- data/spec/integration/validation_spec.rb +0 -404
- data/spec/integration/within_validator_spec.rb +0 -79
@@ -0,0 +1,42 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module DataMapper
|
4
|
+
module Validate
|
5
|
+
module Fixtures
|
6
|
+
class BillOfLading
|
7
|
+
#
|
8
|
+
# Behaviors
|
9
|
+
#
|
10
|
+
|
11
|
+
include DataMapper::Resource
|
12
|
+
|
13
|
+
#
|
14
|
+
# Properties
|
15
|
+
#
|
16
|
+
|
17
|
+
property :id, Serial
|
18
|
+
|
19
|
+
property :doc_no, String, :auto_validation => false
|
20
|
+
property :email, String, :auto_validation => false
|
21
|
+
property :username, String, :auto_validation => false
|
22
|
+
property :url, String, :auto_validation => false
|
23
|
+
property :code, String, :auto_validation => false, :default => "123456"
|
24
|
+
|
25
|
+
#
|
26
|
+
# Validations
|
27
|
+
#
|
28
|
+
|
29
|
+
# this is a trivial example
|
30
|
+
validates_format :doc_no, :with => lambda { |code|
|
31
|
+
code =~ /\AA\d{4}\z/ || code =~ /\A[B-Z]\d{6}X12\z/
|
32
|
+
}
|
33
|
+
|
34
|
+
validates_format :email, :as => :email_address
|
35
|
+
validates_format :url, :as => :url, :allow_nil => false
|
36
|
+
|
37
|
+
validates_format :username, :with => /[a-z]/, :message => 'Username must have at least one letter', :allow_nil => true
|
38
|
+
validates_format :code, :with => /\d{5,6}/, :message => 'Code format is invalid'
|
39
|
+
end
|
40
|
+
end # Fixtures
|
41
|
+
end # Validate
|
42
|
+
end # DataMapper
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module DataMapper
|
2
|
+
module Validate
|
3
|
+
module Fixtures
|
4
|
+
class BoatDock
|
5
|
+
#
|
6
|
+
# Behaviors
|
7
|
+
#
|
8
|
+
|
9
|
+
include DataMapper::Resource
|
10
|
+
|
11
|
+
#
|
12
|
+
# Properties
|
13
|
+
#
|
14
|
+
|
15
|
+
property :id, Serial
|
16
|
+
property :name, String, :auto_validation => false, :default => "I'm a long string"
|
17
|
+
|
18
|
+
#
|
19
|
+
# Validations
|
20
|
+
#
|
21
|
+
|
22
|
+
validates_length :name, :min => 3
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
class City
|
4
|
+
#
|
5
|
+
# Behaviors
|
6
|
+
#
|
7
|
+
|
8
|
+
include DataMapper::Resource
|
9
|
+
|
10
|
+
#
|
11
|
+
# Properties
|
12
|
+
#
|
13
|
+
|
14
|
+
property :id, Serial
|
15
|
+
property :name, String
|
16
|
+
|
17
|
+
property :founded_in, Integer, :auto_validation => false
|
18
|
+
|
19
|
+
#
|
20
|
+
# Validations
|
21
|
+
#
|
22
|
+
|
23
|
+
validates_is_number :founded_in, :message => "Foundation year must be an integer"
|
24
|
+
end
|
25
|
+
City.auto_migrate!
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module DataMapper
|
4
|
+
module Validate
|
5
|
+
module Fixtures
|
6
|
+
class Company
|
7
|
+
#
|
8
|
+
# Behaviors
|
9
|
+
#
|
10
|
+
|
11
|
+
include DataMapper::Resource
|
12
|
+
|
13
|
+
#
|
14
|
+
# Properties
|
15
|
+
#
|
16
|
+
|
17
|
+
property :id, Serial
|
18
|
+
property :title, String
|
19
|
+
property :type, Discriminator
|
20
|
+
|
21
|
+
|
22
|
+
#
|
23
|
+
# Validations
|
24
|
+
#
|
25
|
+
|
26
|
+
validates_present :title, :message => "Company name is a required field"
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
class ServiceCompany < Company
|
31
|
+
|
32
|
+
#
|
33
|
+
# Properties
|
34
|
+
#
|
35
|
+
|
36
|
+
without_auto_validations do
|
37
|
+
property :area_of_expertise, String, :length => (1..60)
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# Validations
|
42
|
+
#
|
43
|
+
|
44
|
+
validates_present :area_of_expertise
|
45
|
+
end
|
46
|
+
|
47
|
+
class ProductCompany < Company
|
48
|
+
|
49
|
+
#
|
50
|
+
# Properties
|
51
|
+
#
|
52
|
+
|
53
|
+
without_auto_validations do
|
54
|
+
property :flagship_product, String, :length => (1..60)
|
55
|
+
end
|
56
|
+
|
57
|
+
#
|
58
|
+
# Validations
|
59
|
+
#
|
60
|
+
|
61
|
+
validates_present :title, :message => "Product company must have a name"
|
62
|
+
validates_present :flagship_product
|
63
|
+
end
|
64
|
+
ProductCompany.auto_migrate!
|
65
|
+
|
66
|
+
|
67
|
+
class Product
|
68
|
+
#
|
69
|
+
# Behaviors
|
70
|
+
#
|
71
|
+
|
72
|
+
include DataMapper::Resource
|
73
|
+
|
74
|
+
#
|
75
|
+
# Properties
|
76
|
+
#
|
77
|
+
|
78
|
+
property :id, Serial
|
79
|
+
property :name, String, :nullable => false
|
80
|
+
|
81
|
+
#
|
82
|
+
# Associations
|
83
|
+
#
|
84
|
+
|
85
|
+
belongs_to :company, :model => DataMapper::Validate::Fixtures::ProductCompany
|
86
|
+
|
87
|
+
#
|
88
|
+
# Validations
|
89
|
+
#
|
90
|
+
|
91
|
+
validates_present :company
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
4
|
+
module DataMapper
|
5
|
+
module Validate
|
6
|
+
module Fixtures
|
7
|
+
class Organisation
|
8
|
+
include DataMapper::Resource
|
9
|
+
|
10
|
+
property :id, Serial
|
11
|
+
property :name, String
|
12
|
+
property :domain, String, :unique_index => true
|
13
|
+
|
14
|
+
validates_is_unique :domain, :allow_nil => true
|
15
|
+
|
16
|
+
auto_migrate!
|
17
|
+
end
|
18
|
+
|
19
|
+
class Department
|
20
|
+
include DataMapper::Resource
|
21
|
+
|
22
|
+
property :id, Serial
|
23
|
+
property :name, String, :unique_index => true
|
24
|
+
|
25
|
+
validates_is_unique :name
|
26
|
+
|
27
|
+
auto_migrate!
|
28
|
+
end
|
29
|
+
|
30
|
+
class User
|
31
|
+
include DataMapper::Resource
|
32
|
+
|
33
|
+
property :id, Serial
|
34
|
+
property :user_name, String
|
35
|
+
|
36
|
+
belongs_to :organisation
|
37
|
+
belongs_to :department
|
38
|
+
|
39
|
+
validates_is_unique :user_name, :when => :signing_up_for_department_account, :scope => [:department]
|
40
|
+
validates_is_unique :user_name, :when => :signing_up_for_organization_account, :scope => [:organisation]
|
41
|
+
|
42
|
+
auto_migrate!
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
class Country
|
4
|
+
#
|
5
|
+
# Behaviors
|
6
|
+
#
|
7
|
+
|
8
|
+
include DataMapper::Resource
|
9
|
+
|
10
|
+
#
|
11
|
+
# Properties
|
12
|
+
#
|
13
|
+
|
14
|
+
property :id, Serial
|
15
|
+
property :name, String
|
16
|
+
|
17
|
+
property :area, Integer
|
18
|
+
|
19
|
+
#
|
20
|
+
# Validations
|
21
|
+
#
|
22
|
+
|
23
|
+
validates_is_number :area, :message => "Please use integers to specify area"
|
24
|
+
end
|
25
|
+
Country.auto_migrate!
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module DataMapper
|
2
|
+
module Validate
|
3
|
+
module Fixtures
|
4
|
+
class Currency
|
5
|
+
|
6
|
+
#
|
7
|
+
# Behaviors
|
8
|
+
#
|
9
|
+
|
10
|
+
include DataMapper::Resource
|
11
|
+
|
12
|
+
#
|
13
|
+
# Properties
|
14
|
+
#
|
15
|
+
|
16
|
+
without_auto_validations do
|
17
|
+
property :name, String, :length => 1..50, :key => true
|
18
|
+
property :code, String, :length => 3, :unique_index => true
|
19
|
+
property :symbol, String, :length => 1
|
20
|
+
end
|
21
|
+
|
22
|
+
#
|
23
|
+
# Validations
|
24
|
+
#
|
25
|
+
|
26
|
+
validates_length :name, :within => 1..50
|
27
|
+
validates_length :code, :is => 3
|
28
|
+
validates_length :symbol, :is => 1
|
29
|
+
|
30
|
+
def self.valid_instance(overrides = {})
|
31
|
+
defaults = {
|
32
|
+
:name => 'United States Dollar',
|
33
|
+
:code => 'USD',
|
34
|
+
:symbol => '$'
|
35
|
+
}
|
36
|
+
|
37
|
+
new(defaults.merge(overrides))
|
38
|
+
end
|
39
|
+
end # Barcode
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module DataMapper
|
2
|
+
module Validate
|
3
|
+
module Fixtures
|
4
|
+
|
5
|
+
# for pedants: we refer to DIX Ethernet here
|
6
|
+
class EthernetFrame
|
7
|
+
|
8
|
+
#
|
9
|
+
# Behaviors
|
10
|
+
#
|
11
|
+
|
12
|
+
include DataMapper::Resource
|
13
|
+
|
14
|
+
#
|
15
|
+
# Properties
|
16
|
+
#
|
17
|
+
|
18
|
+
attr_accessor :link_support_fragmentation
|
19
|
+
|
20
|
+
# we have to have a key in a DM resource
|
21
|
+
property :id, Serial
|
22
|
+
|
23
|
+
without_auto_validations do
|
24
|
+
property :destination_mac, String
|
25
|
+
property :source_mac, String
|
26
|
+
property :ether_type, String
|
27
|
+
property :payload, Text
|
28
|
+
property :crc, String
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Validations
|
33
|
+
#
|
34
|
+
|
35
|
+
validates_length :destination_mac, :source_mac, :equals => 6
|
36
|
+
validates_length :ether_type, :equals => 2
|
37
|
+
validates_length :payload, :min => 46, :max => 1500, :unless => :link_support_fragmentation
|
38
|
+
# :is is alias for :equal
|
39
|
+
validates_length :crc, :is => 4
|
40
|
+
|
41
|
+
def self.valid_instance
|
42
|
+
# these are obvisouly not bits, and not in hexadecimal
|
43
|
+
# format either, but give fixture models some slack
|
44
|
+
attributes = {
|
45
|
+
:destination_mac => "7b7d93",
|
46
|
+
:source_mac => "abe763",
|
47
|
+
:ether_type => "88",
|
48
|
+
:payload => "Imagine yourself a beautiful bag full of bits here",
|
49
|
+
:crc => "4132"
|
50
|
+
}
|
51
|
+
new(attributes)
|
52
|
+
end
|
53
|
+
end # EthernetFrame
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module DataMapper
|
4
|
+
module Validate
|
5
|
+
module Fixtures
|
6
|
+
|
7
|
+
class Event
|
8
|
+
#
|
9
|
+
# Behaviors
|
10
|
+
#
|
11
|
+
|
12
|
+
include ::DataMapper::Resource
|
13
|
+
|
14
|
+
#
|
15
|
+
# Properties
|
16
|
+
#
|
17
|
+
|
18
|
+
property :id, Serial
|
19
|
+
property :name, String, :nullable => false
|
20
|
+
|
21
|
+
property :starts_at, DateTime
|
22
|
+
property :ends_at, DateTime
|
23
|
+
|
24
|
+
#
|
25
|
+
# Validations
|
26
|
+
#
|
27
|
+
|
28
|
+
validates_with_method :starts_at, :method => :ensure_dates_order_is_correct
|
29
|
+
|
30
|
+
#
|
31
|
+
# API
|
32
|
+
#
|
33
|
+
|
34
|
+
def ensure_dates_order_is_correct
|
35
|
+
if starts_at && ends_at && (starts_at <= ends_at)
|
36
|
+
true
|
37
|
+
else
|
38
|
+
[false, "Start time cannot be after end time"]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end # Event
|
42
|
+
end # Fixtures
|
43
|
+
end # Validate
|
44
|
+
end # DataMapper
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module DataMapper
|
4
|
+
module Validate
|
5
|
+
module Fixtures
|
6
|
+
class G3Concert
|
7
|
+
#
|
8
|
+
# Bahaviors
|
9
|
+
#
|
10
|
+
|
11
|
+
include ::DataMapper::Validate
|
12
|
+
|
13
|
+
#
|
14
|
+
# Attributes
|
15
|
+
#
|
16
|
+
|
17
|
+
attr_accessor :year, :participants, :city
|
18
|
+
|
19
|
+
#
|
20
|
+
# Validations
|
21
|
+
#
|
22
|
+
|
23
|
+
validates_with_block :participants do
|
24
|
+
if self.class.known_performances.any? { |perf| perf == self }
|
25
|
+
true
|
26
|
+
else
|
27
|
+
[false, "this G3 is probably yet to take place"]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# API
|
33
|
+
#
|
34
|
+
|
35
|
+
def initialize(attributes = {})
|
36
|
+
attributes.each do |key, value|
|
37
|
+
self.send("#{key}=", value)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def ==(other)
|
42
|
+
other.year == self.year && other.participants == self.participants && other.city == self.city
|
43
|
+
end
|
44
|
+
|
45
|
+
# obvisouly this is intentionally shortened list ;)
|
46
|
+
def self.known_performances
|
47
|
+
[
|
48
|
+
new(:year => 2004, :participants => "Joe Satriani, Steve Vai, Yngwie Malmsteen", :city => "Denver"),
|
49
|
+
new(:year => 1996, :participants => "Joe Satriani, Steve Vai, Eric Johnson", :city => "San Francisco"),
|
50
|
+
new(:year => 2001, :participants => "Joe Satriani, Steve Vai, John Petrucci", :city => "Los Angeles"),
|
51
|
+
new(:year => 2002, :participants => "Joe Satriani, Steve Vai, John Petrucci", :city => "Los Angeles")
|
52
|
+
]
|
53
|
+
end
|
54
|
+
end # G3Concert
|
55
|
+
end # Fixtures
|
56
|
+
end # Validate
|
57
|
+
end # DataMapper
|