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
@@ -1,8 +1,5 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
require __dir__.parent.parent + 'spec_helper'
|
5
|
-
require __dir__ + 'spec_helper'
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/required_field_validator/spec_helper'
|
6
3
|
|
7
4
|
if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
8
5
|
class Artist
|
@@ -16,7 +13,7 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
16
13
|
# Properties
|
17
14
|
#
|
18
15
|
|
19
|
-
property :id,
|
16
|
+
property :id, Serial
|
20
17
|
property :name, String, :auto_validation => false
|
21
18
|
|
22
19
|
#
|
@@ -43,7 +40,7 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
43
40
|
# Properties
|
44
41
|
#
|
45
42
|
|
46
|
-
property :id,
|
43
|
+
property :id, Serial
|
47
44
|
property :name, String, :auto_validation => false
|
48
45
|
property :artist_id, Integer, :index => :artist
|
49
46
|
|
@@ -81,7 +78,7 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
81
78
|
|
82
79
|
it 'has a meaninful error messages on association key property' do
|
83
80
|
@album.valid?
|
84
|
-
@album.errors.on(:artist).should
|
81
|
+
@album.errors.on(:artist).should == [ 'Artist must not be blank' ]
|
85
82
|
end
|
86
83
|
end
|
87
84
|
|
@@ -1,8 +1,5 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
require __dir__.parent.parent + 'spec_helper'
|
5
|
-
require __dir__ + 'spec_helper'
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/required_field_validator/spec_helper'
|
6
3
|
|
7
4
|
if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
8
5
|
# keep in mind any ScmOperation has a default value for brand property
|
@@ -39,13 +36,13 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
39
36
|
it "is not valid for pushing" do
|
40
37
|
@operation.should_not be_valid_for_pushing
|
41
38
|
@operation.errors.on(:network_connection).
|
42
|
-
first[:pushing].should
|
39
|
+
first[:pushing].should == 'though git is advanced, it cannot push without network connectivity'
|
43
40
|
end
|
44
41
|
|
45
42
|
it "is not valid for pulling" do
|
46
43
|
@operation.should_not be_valid_for_pulling
|
47
44
|
@operation.errors.on(:network_connection).
|
48
|
-
first[:pulling].should
|
45
|
+
first[:pulling].should == 'you must have network connectivity to pull from others'
|
49
46
|
end
|
50
47
|
|
51
48
|
it "is not valid in default context" do
|
@@ -1,8 +1,5 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
require __dir__.parent.parent + 'spec_helper'
|
5
|
-
require __dir__ + 'spec_helper'
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/required_field_validator/spec_helper'
|
6
3
|
|
7
4
|
if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
8
5
|
class Holiday
|
@@ -16,7 +13,7 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
16
13
|
# Properties
|
17
14
|
#
|
18
15
|
|
19
|
-
property :id,
|
16
|
+
property :id, Serial
|
20
17
|
property :on, Date, :auto_validation => false
|
21
18
|
|
22
19
|
#
|
@@ -1,8 +1,5 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
require __dir__.parent.parent + 'spec_helper'
|
5
|
-
require __dir__ + 'spec_helper'
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/required_field_validator/spec_helper'
|
6
3
|
|
7
4
|
if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
8
5
|
class ScheduledOperation
|
@@ -16,7 +13,7 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
16
13
|
# Properties
|
17
14
|
#
|
18
15
|
|
19
|
-
property :id,
|
16
|
+
property :id, Serial
|
20
17
|
property :at, DateTime, :auto_validation => false
|
21
18
|
|
22
19
|
#
|
@@ -1,8 +1,5 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
require __dir__.parent.parent + 'spec_helper'
|
5
|
-
require __dir__ + 'spec_helper'
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/required_field_validator/spec_helper'
|
6
3
|
|
7
4
|
if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
8
5
|
#
|
@@ -21,7 +18,7 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
21
18
|
# Properties
|
22
19
|
#
|
23
20
|
|
24
|
-
property :id,
|
21
|
+
property :id, Serial
|
25
22
|
property :percent, Float, :auto_validation => false
|
26
23
|
|
27
24
|
#
|
@@ -1,8 +1,5 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
require __dir__.parent.parent + 'spec_helper'
|
5
|
-
require __dir__ + 'spec_helper'
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/required_field_validator/spec_helper'
|
6
3
|
|
7
4
|
if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
8
5
|
#
|
@@ -1,8 +1,5 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
require __dir__.parent.parent + 'spec_helper'
|
5
|
-
require __dir__ + 'spec_helper'
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/required_field_validator/spec_helper'
|
6
3
|
|
7
4
|
if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
8
5
|
describe "A plain old Ruby object (not a DM resource)" do
|
@@ -22,9 +19,9 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
22
19
|
|
23
20
|
it "should fail validation with empty, nil, or blank fields" do
|
24
21
|
@pc.should_not be_valid
|
25
|
-
@pc.errors.on(:empty).should
|
26
|
-
@pc.errors.on(:nil).should
|
27
|
-
@pc.errors.on(:accessor).should
|
22
|
+
@pc.errors.on(:empty).should == [ 'Empty must not be blank' ]
|
23
|
+
@pc.errors.on(:nil).should == [ 'Nil must not be blank' ]
|
24
|
+
@pc.errors.on(:accessor).should == [ 'Accessor must not be blank' ]
|
28
25
|
end
|
29
26
|
|
30
27
|
it "giving accessor a value should remove validation error" do
|
@@ -1,68 +1,7 @@
|
|
1
|
-
|
1
|
+
# make sure you check out spec/fixtures to see fixture models
|
2
|
+
# already written
|
3
|
+
#
|
4
|
+
# DataMapper developers feels strongly against foobars in the spec
|
5
|
+
# suite
|
2
6
|
|
3
|
-
|
4
|
-
# SCMs
|
5
|
-
#
|
6
|
-
# This example may look stupid (I am sure it is),
|
7
|
-
# but it is way better than foobars and easier to read/add cases
|
8
|
-
# compared to gardening examples because every software engineer has idea
|
9
|
-
# about SCMs and not every software engineer does gardening often.
|
10
|
-
#
|
11
|
-
|
12
|
-
class ScmOperation
|
13
|
-
include DataMapper::Resource
|
14
|
-
|
15
|
-
#
|
16
|
-
# Property
|
17
|
-
#
|
18
|
-
|
19
|
-
property :id, Integer, :serial => true
|
20
|
-
|
21
|
-
# operation name
|
22
|
-
property :name, String, :auto_validation => false
|
23
|
-
|
24
|
-
property :committer_name, String, :auto_validation => false, :default => "Just another Ruby hacker"
|
25
|
-
property :author_name, String, :auto_validation => false, :default => "Just another Ruby hacker"
|
26
|
-
property :network_connection, Boolean, :auto_validation => false
|
27
|
-
property :message, Text, :auto_validation => false
|
28
|
-
property :clean_working_copy, Boolean, :auto_validation => false
|
29
|
-
|
30
|
-
#
|
31
|
-
# Validations
|
32
|
-
#
|
33
|
-
|
34
|
-
validates_present :name
|
35
|
-
end
|
36
|
-
|
37
|
-
class SubversionOperation < ScmOperation
|
38
|
-
#
|
39
|
-
# Validations
|
40
|
-
#
|
41
|
-
|
42
|
-
validates_present :network_connection, :when => [:committing, :log_viewing]
|
43
|
-
end
|
44
|
-
|
45
|
-
class GitOperation < ScmOperation
|
46
|
-
#
|
47
|
-
# Validations
|
48
|
-
#
|
49
|
-
|
50
|
-
validates_present :author_name, :when => :committing
|
51
|
-
validates_present :committer_name, :when => :committing
|
52
|
-
|
53
|
-
validates_present :message, :when => :committing
|
54
|
-
validates_present :network_connection, :when => [:pushing, :pulling], :message => {
|
55
|
-
:pushing => "though git is advanced, it cannot push without network connectivity",
|
56
|
-
:pulling => "you must have network connectivity to pull from others"
|
57
|
-
}
|
58
|
-
validates_present :clean_working_copy, :when => :pulling
|
59
|
-
end
|
60
|
-
|
61
|
-
|
62
|
-
[ScmOperation, SubversionOperation, GitOperation].each do |dm_resource|
|
63
|
-
dm_resource.auto_migrate!
|
64
|
-
end
|
65
|
-
|
66
|
-
__dir__ = File.dirname(__FILE__)
|
67
|
-
require File.join(__dir__, "shared_examples")
|
68
|
-
end
|
7
|
+
require 'integration/required_field_validator/shared_examples'
|
@@ -1,8 +1,5 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
require __dir__.parent.parent + 'spec_helper'
|
5
|
-
require __dir__ + 'spec_helper'
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/required_field_validator/spec_helper'
|
6
3
|
|
7
4
|
if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
8
5
|
# keep in mind any ScmOperation has a default value for brand property
|
@@ -1,8 +1,5 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
require __dir__.parent.parent + 'spec_helper'
|
5
|
-
require __dir__ + 'spec_helper'
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/required_field_validator/spec_helper'
|
6
3
|
|
7
4
|
if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
8
5
|
# keep in mind any ScmOperation has a default value for brand property
|
@@ -0,0 +1,13 @@
|
|
1
|
+
describe "object invalid in default context", :shared => true do
|
2
|
+
it "is not valid in default context" do
|
3
|
+
@model.should_not be_valid
|
4
|
+
@model.should_not be_valid(:default)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "object valid in default context", :shared => true do
|
9
|
+
it "is valid in default context" do
|
10
|
+
@model.should be_valid
|
11
|
+
@model.should be_valid(:default)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
describe "valid model", :shared => true do
|
2
|
+
it "is valid" do
|
3
|
+
@model.should be_valid
|
4
|
+
end
|
5
|
+
|
6
|
+
it "has no error messages" do
|
7
|
+
@model.errors.should be_empty
|
8
|
+
end
|
9
|
+
|
10
|
+
it "has empty list of full error messages" do
|
11
|
+
@model.errors.full_messages.should be_empty
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "invalid model", :shared => true do
|
16
|
+
it "is NOT valid" do
|
17
|
+
@model.should_not be_valid
|
18
|
+
end
|
19
|
+
|
20
|
+
it "has error messages" do
|
21
|
+
@model.errors.should_not be_blank
|
22
|
+
end
|
23
|
+
|
24
|
+
it "has list of full error messages" do
|
25
|
+
@model.errors.full_messages.should_not be_blank
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/uniqueness_validator/spec_helper'
|
3
|
+
|
4
|
+
|
5
|
+
if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
6
|
+
describe DataMapper::Validate::Fixtures::Department do
|
7
|
+
before :all do
|
8
|
+
::DataMapper::Validate::Fixtures::Department.create(:name => "HR")
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "with unique name" do
|
12
|
+
before :all do
|
13
|
+
@model = ::DataMapper::Validate::Fixtures::Department.new(:name => "R & D")
|
14
|
+
end
|
15
|
+
|
16
|
+
it_should_behave_like "valid model"
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "with a duplicate name" do
|
20
|
+
before :all do
|
21
|
+
@model = ::DataMapper::Validate::Fixtures::Department.new(:name => "HR")
|
22
|
+
end
|
23
|
+
|
24
|
+
it_should_behave_like "invalid model"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
describe DataMapper::Validate::Fixtures::Organisation do
|
31
|
+
before :all do
|
32
|
+
DataMapper.repository do
|
33
|
+
@model = ::DataMapper::Validate::Fixtures::Organisation.create(:name => 'Apple', :domain => 'apple.com')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "with missing domain" do
|
38
|
+
before :all do
|
39
|
+
@model.domain = nil
|
40
|
+
end
|
41
|
+
|
42
|
+
it_should_behave_like "valid model"
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "with a duplicate domain" do
|
46
|
+
before :all do
|
47
|
+
@model.name = "Fake Apple"
|
48
|
+
@model.domain = "apple.com"
|
49
|
+
end
|
50
|
+
|
51
|
+
it_should_behave_like "invalid model"
|
52
|
+
|
53
|
+
it "has a meaningful error message" do
|
54
|
+
@model.valid?
|
55
|
+
@model.errors.on(:domain).should == [ 'Domain is already taken' ]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it "shouldn't fail on itself when checking for records with identical fields" do
|
60
|
+
@model.name = "Steve Job's Pony Express"
|
61
|
+
@model.should be_valid
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
describe DataMapper::Validate::Fixtures::User do
|
68
|
+
before :all do
|
69
|
+
# remove data from previous spec runs
|
70
|
+
::DataMapper::Validate::Fixtures::Organisation.all.destroy!
|
71
|
+
::DataMapper::Validate::Fixtures::Department.all.destroy!
|
72
|
+
::DataMapper::Validate::Fixtures::User.all.destroy!
|
73
|
+
|
74
|
+
DataMapper.repository do
|
75
|
+
@organization = ::DataMapper::Validate::Fixtures::Organisation.create(:name => 'Org 101', :domain => '101')
|
76
|
+
@dept = ::DataMapper::Validate::Fixtures::Department.create(:name => 'accounting')
|
77
|
+
@user = ::DataMapper::Validate::Fixtures::User.create(:organisation => @organization, :user_name => 'guy', :department => @dept)
|
78
|
+
|
79
|
+
@organization.should be_saved
|
80
|
+
@dept.should be_saved
|
81
|
+
@user.should be_saved
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "with username not valid across the organization" do
|
86
|
+
before :all do
|
87
|
+
@model = ::DataMapper::Validate::Fixtures::User.new(:organisation => @organization, :user_name => 'guy')
|
88
|
+
end
|
89
|
+
|
90
|
+
it "is not valid for signing up" do
|
91
|
+
@model.should_not be_valid_for_signing_up_for_organization_account
|
92
|
+
end
|
93
|
+
|
94
|
+
it "has a meaningful error message" do
|
95
|
+
@model.errors.on(:user_name).should == [ 'User name is already taken' ]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
describe "with username not valid across the department" do
|
101
|
+
before :all do
|
102
|
+
@model = ::DataMapper::Validate::Fixtures::User.new(:user_name => 'guy', :department => @dept)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "is not valid for setting up the account" do
|
106
|
+
@model.should_not be_valid_for_signing_up_for_department_account
|
107
|
+
end
|
108
|
+
|
109
|
+
it "has a meaningful error message" do
|
110
|
+
@model.errors.on(:user_name).should == [ 'User name is already taken' ]
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end # describe DataMapper::Validate::Fixtures::User
|
114
|
+
end # if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|