dm-validations 0.10.2 → 1.0.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +36 -0
- data/Gemfile +143 -0
- data/README.rdoc +52 -102
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/dm-validations.gemspec +126 -14
- data/lib/dm-validations.rb +78 -18
- data/lib/dm-validations/auto_validate.rb +27 -23
- data/lib/dm-validations/contextual_validators.rb +3 -3
- data/lib/dm-validations/formats/email.rb +3 -3
- data/lib/dm-validations/formats/url.rb +3 -3
- data/lib/dm-validations/support/context.rb +1 -1
- data/lib/dm-validations/validation_errors.rb +5 -7
- data/lib/dm-validations/validators/absent_field_validator.rb +13 -9
- data/lib/dm-validations/validators/acceptance_validator.rb +10 -7
- data/lib/dm-validations/validators/block_validator.rb +3 -3
- data/lib/dm-validations/validators/confirmation_validator.rb +10 -7
- data/lib/dm-validations/validators/format_validator.rb +14 -10
- data/lib/dm-validations/validators/generic_validator.rb +3 -3
- data/lib/dm-validations/validators/length_validator.rb +10 -7
- data/lib/dm-validations/validators/method_validator.rb +3 -3
- data/lib/dm-validations/validators/numeric_validator.rb +25 -14
- data/lib/dm-validations/validators/primitive_validator.rb +12 -8
- data/lib/dm-validations/validators/required_field_validator.rb +12 -9
- data/lib/dm-validations/validators/uniqueness_validator.rb +9 -6
- data/lib/dm-validations/validators/within_validator.rb +3 -3
- data/spec/fixtures/barcode.rb +10 -2
- data/spec/fixtures/basketball_court.rb +7 -7
- data/spec/fixtures/basketball_player.rb +3 -3
- data/spec/fixtures/beta_tester_account.rb +4 -4
- data/spec/fixtures/bill_of_landing.rb +7 -7
- data/spec/fixtures/boat_dock.rb +2 -2
- data/spec/fixtures/city.rb +1 -1
- data/spec/fixtures/company.rb +7 -7
- data/spec/fixtures/corporate_world.rb +24 -26
- data/spec/fixtures/country.rb +1 -1
- data/spec/fixtures/currency.rb +4 -4
- data/spec/fixtures/ethernet_frame.rb +5 -5
- data/spec/fixtures/event.rb +2 -2
- data/spec/fixtures/g3_concert.rb +3 -3
- data/spec/fixtures/jabberwock.rb +2 -2
- data/spec/fixtures/kayak.rb +2 -2
- data/spec/fixtures/lernean_hydra.rb +3 -3
- data/spec/fixtures/mathematical_function.rb +2 -2
- data/spec/fixtures/memory_object.rb +3 -3
- data/spec/fixtures/mittelschnauzer.rb +3 -3
- data/spec/fixtures/motor_launch.rb +1 -1
- data/spec/fixtures/page.rb +3 -3
- data/spec/fixtures/phone_number.rb +2 -2
- data/spec/fixtures/pirogue.rb +2 -2
- data/spec/fixtures/programming_language.rb +3 -3
- data/spec/fixtures/reservation.rb +5 -5
- data/spec/fixtures/scm_operation.rb +42 -45
- data/spec/fixtures/sms_message.rb +1 -1
- data/spec/fixtures/udp_packet.rb +3 -3
- data/spec/integration/absent_field_validator/absent_field_validator_spec.rb +6 -6
- data/spec/integration/acceptance_validator/acceptance_validator_spec.rb +3 -3
- data/spec/integration/automatic_validation/inferred_length_validation_spec.rb +5 -5
- data/spec/integration/automatic_validation/spec_helper.rb +1 -1
- data/spec/integration/block_validator/block_validator_spec.rb +2 -2
- data/spec/integration/conditional_validation/if_condition_spec.rb +3 -3
- data/spec/integration/confirmation_validator/confirmation_validator_spec.rb +3 -3
- data/spec/integration/datamapper_models/association_validation_spec.rb +5 -5
- data/spec/integration/datamapper_models/inheritance_spec.rb +6 -6
- data/spec/integration/duplicated_validations/duplicated_validations_spec.rb +3 -3
- data/spec/integration/format_validator/email_format_validator_spec.rb +6 -6
- data/spec/integration/format_validator/format_validator_spec.rb +8 -8
- data/spec/integration/format_validator/regexp_validator_spec.rb +4 -4
- data/spec/integration/format_validator/url_format_validator_spec.rb +4 -4
- data/spec/integration/length_validator/default_value_spec.rb +3 -3
- data/spec/integration/length_validator/equality_spec.rb +4 -4
- data/spec/integration/length_validator/error_message_spec.rb +3 -3
- data/spec/integration/length_validator/maximum_spec.rb +3 -3
- data/spec/integration/length_validator/minimum_spec.rb +3 -3
- data/spec/integration/length_validator/range_spec.rb +3 -3
- data/spec/integration/method_validator/method_validator_spec.rb +8 -8
- data/spec/integration/numeric_validator/equality_with_float_type_spec.rb +7 -7
- data/spec/integration/numeric_validator/equality_with_integer_type_spec.rb +5 -5
- data/spec/integration/numeric_validator/float_type_spec.rb +3 -3
- data/spec/integration/numeric_validator/gt_with_float_type_spec.rb +3 -3
- data/spec/integration/numeric_validator/gte_with_float_type_spec.rb +3 -3
- data/spec/integration/numeric_validator/lt_with_float_type_spec.rb +3 -3
- data/spec/integration/numeric_validator/lte_with_float_type_spec.rb +3 -3
- data/spec/integration/primitive_validator/primitive_validator_spec.rb +4 -4
- data/spec/integration/pure_ruby_objects/plain_old_ruby_object_validation_spec.rb +4 -4
- data/spec/integration/required_field_validator/association_spec.rb +19 -51
- data/spec/integration/required_field_validator/boolean_type_value_spec.rb +4 -1
- data/spec/integration/required_field_validator/date_type_value_spec.rb +4 -2
- data/spec/integration/required_field_validator/datetime_type_value_spec.rb +4 -2
- data/spec/integration/required_field_validator/float_type_value_spec.rb +4 -2
- data/spec/integration/required_field_validator/integer_type_value_spec.rb +4 -2
- data/spec/integration/required_field_validator/plain_old_ruby_object_spec.rb +6 -4
- data/spec/integration/required_field_validator/string_type_value_spec.rb +3 -1
- data/spec/integration/required_field_validator/text_type_value_spec.rb +3 -1
- data/spec/integration/shared/valid_and_invalid_model.rb +8 -0
- data/spec/integration/uniqueness_validator/uniqueness_validator_spec.rb +29 -25
- data/spec/integration/within_validator/within_validator_spec.rb +6 -6
- data/spec/public/resource_spec.rb +47 -9
- data/spec/spec_helper.rb +13 -27
- data/spec/unit/contextual_validators/emptiness_spec.rb +4 -4
- data/spec/unit/contextual_validators/execution_spec.rb +6 -6
- data/spec/unit/contextual_validators/spec_helper.rb +3 -3
- data/spec/unit/generic_validator/equality_operator_spec.rb +7 -7
- data/spec/unit/validation_errors/adding_spec.rb +2 -2
- data/spec/unit/validation_errors/emptiness_spec.rb +2 -2
- data/spec/unit/validation_errors/enumerable_spec.rb +2 -2
- data/tasks/local_gemfile.rake +18 -0
- data/tasks/spec.rake +0 -3
- metadata +157 -25
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'integration/numeric_validator/spec_helper'
|
3
3
|
|
4
|
-
describe 'DataMapper::
|
4
|
+
describe 'DataMapper::Validations::Fixtures::BasketballPlayer' do
|
5
5
|
before :all do
|
6
|
-
DataMapper::
|
6
|
+
DataMapper::Validations::Fixtures::BasketballPlayer.auto_migrate!
|
7
7
|
|
8
|
-
@model = DataMapper::
|
8
|
+
@model = DataMapper::Validations::Fixtures::BasketballPlayer.new(:name => "Michael Jordan", :height => 198.1, :weight => 97.2)
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "with height as float" do
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'integration/numeric_validator/spec_helper'
|
3
3
|
|
4
|
-
describe 'DataMapper::
|
4
|
+
describe 'DataMapper::Validations::Fixtures::BasketballCourt' do
|
5
5
|
before :all do
|
6
|
-
DataMapper::
|
6
|
+
DataMapper::Validations::Fixtures::BasketballCourt.auto_migrate!
|
7
7
|
|
8
|
-
@model = DataMapper::
|
8
|
+
@model = DataMapper::Validations::Fixtures::BasketballCourt.valid_instance
|
9
9
|
@model.valid?
|
10
10
|
end
|
11
11
|
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'integration/numeric_validator/spec_helper'
|
3
3
|
|
4
|
-
describe 'DataMapper::
|
4
|
+
describe 'DataMapper::Validations::Fixtures::BasketballCourt' do
|
5
5
|
before :all do
|
6
|
-
DataMapper::
|
6
|
+
DataMapper::Validations::Fixtures::BasketballCourt.auto_migrate!
|
7
7
|
|
8
|
-
@model = DataMapper::
|
8
|
+
@model = DataMapper::Validations::Fixtures::BasketballCourt.valid_instance
|
9
9
|
@model.valid?
|
10
10
|
end
|
11
11
|
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'integration/numeric_validator/spec_helper'
|
3
3
|
|
4
|
-
describe 'DataMapper::
|
4
|
+
describe 'DataMapper::Validations::Fixtures::BasketballCourt' do
|
5
5
|
before :all do
|
6
|
-
DataMapper::
|
6
|
+
DataMapper::Validations::Fixtures::BasketballCourt.auto_migrate!
|
7
7
|
|
8
|
-
@model = DataMapper::
|
8
|
+
@model = DataMapper::Validations::Fixtures::BasketballCourt.valid_instance
|
9
9
|
@model.valid?
|
10
10
|
end
|
11
11
|
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'integration/numeric_validator/spec_helper'
|
3
3
|
|
4
|
-
describe 'DataMapper::
|
4
|
+
describe 'DataMapper::Validations::Fixtures::BasketballCourt' do
|
5
5
|
before :all do
|
6
|
-
DataMapper::
|
6
|
+
DataMapper::Validations::Fixtures::BasketballCourt.auto_migrate!
|
7
7
|
|
8
|
-
@model = DataMapper::
|
8
|
+
@model = DataMapper::Validations::Fixtures::BasketballCourt.valid_instance
|
9
9
|
@model.valid?
|
10
10
|
end
|
11
11
|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'integration/primitive_validator/spec_helper'
|
3
3
|
|
4
|
-
describe 'DataMapper::
|
5
|
-
include DataMapper::
|
4
|
+
describe 'DataMapper::Validations::Fixtures::MemoryObject' do
|
5
|
+
include DataMapper::Validations::Fixtures
|
6
6
|
|
7
7
|
before :all do
|
8
|
-
DataMapper::
|
8
|
+
DataMapper::Validations::Fixtures::MemoryObject.auto_migrate!
|
9
9
|
|
10
|
-
@model = DataMapper::
|
10
|
+
@model = DataMapper::Validations::Fixtures::MemoryObject.new
|
11
11
|
end
|
12
12
|
|
13
13
|
describe "with color given as a string" do
|
@@ -7,18 +7,18 @@ module PureRubyObjects
|
|
7
7
|
# Behaviors
|
8
8
|
#
|
9
9
|
|
10
|
-
include DataMapper::
|
10
|
+
include DataMapper::Validations
|
11
11
|
|
12
12
|
#
|
13
13
|
# Validations
|
14
14
|
#
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
validates_presence_of :name, :when => [:default, :adding_to_encyclopedia]
|
17
|
+
validates_presence_of :population, :when => :adding_to_encyclopedia, :message => Proc.new { |record|
|
18
18
|
"population really needs to be specified when adding %s to encyclopedia" % [record.class.name]
|
19
19
|
}
|
20
20
|
|
21
|
-
|
21
|
+
validates_length_of :name, :in => (4..50)
|
22
22
|
|
23
23
|
#
|
24
24
|
# API
|
@@ -1,71 +1,42 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'integration/required_field_validator/spec_helper'
|
3
3
|
|
4
|
-
|
5
|
-
class Artist
|
6
|
-
#
|
7
|
-
# Behaviors
|
8
|
-
#
|
4
|
+
describe 'required_field_validator/association_spec' do
|
9
5
|
|
10
|
-
|
6
|
+
before :all do
|
11
7
|
|
12
|
-
|
13
|
-
# Properties
|
14
|
-
#
|
8
|
+
class ::Artist
|
15
9
|
|
16
|
-
|
17
|
-
property :name, String, :auto_validation => false
|
10
|
+
include DataMapper::Resource
|
18
11
|
|
19
|
-
|
20
|
-
|
21
|
-
#
|
12
|
+
property :id, Serial
|
13
|
+
property :name, String, :auto_validation => false
|
22
14
|
|
23
|
-
|
15
|
+
has n, :albums
|
24
16
|
|
25
|
-
|
26
|
-
# Validations
|
27
|
-
#
|
17
|
+
validates_presence_of :name
|
28
18
|
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
class Album
|
33
|
-
#
|
34
|
-
# Behaviors
|
35
|
-
#
|
19
|
+
end
|
36
20
|
|
37
|
-
|
21
|
+
class ::Album
|
38
22
|
|
39
|
-
|
40
|
-
# Properties
|
41
|
-
#
|
23
|
+
include DataMapper::Resource
|
42
24
|
|
43
|
-
|
44
|
-
|
45
|
-
|
25
|
+
property :id, Serial
|
26
|
+
property :name, String, :auto_validation => false
|
27
|
+
property :artist_id, Integer, :index => :artist
|
46
28
|
|
47
|
-
|
48
|
-
# Associations
|
49
|
-
#
|
29
|
+
belongs_to :artist
|
50
30
|
|
51
|
-
|
31
|
+
validates_presence_of :name, :artist
|
52
32
|
|
53
|
-
|
54
|
-
# Validations
|
55
|
-
#
|
33
|
+
end
|
56
34
|
|
57
|
-
|
35
|
+
Artist.auto_migrate!
|
58
36
|
end
|
59
|
-
Artist.auto_migrate!
|
60
|
-
Album.auto_migrate!
|
61
|
-
|
62
37
|
|
63
38
|
|
64
39
|
describe 'Album' do
|
65
|
-
before :all do
|
66
|
-
Artist.auto_migrate!
|
67
|
-
Album.auto_migrate!
|
68
|
-
end
|
69
40
|
|
70
41
|
before do
|
71
42
|
@artist = Artist.create(:name => "Oceanlab")
|
@@ -88,13 +59,10 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
88
59
|
end
|
89
60
|
|
90
61
|
describe 'with specified artist and name' do
|
91
|
-
before do
|
92
|
-
# no op
|
93
|
-
end
|
94
|
-
|
95
62
|
it 'is valid' do
|
96
63
|
@album.should be_valid
|
97
64
|
end
|
98
65
|
end
|
99
66
|
end
|
67
|
+
|
100
68
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'integration/required_field_validator/spec_helper'
|
3
3
|
|
4
|
-
|
4
|
+
describe 'required_field_validator/boolean_type_value_spec' do
|
5
|
+
|
5
6
|
# keep in mind any ScmOperation has a default value for brand property
|
6
7
|
# so it is used
|
7
8
|
describe 'GitOperation' do
|
@@ -149,4 +150,6 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
149
150
|
end
|
150
151
|
end
|
151
152
|
end
|
153
|
+
|
154
|
+
|
152
155
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'integration/required_field_validator/spec_helper'
|
3
3
|
|
4
|
-
|
4
|
+
describe 'required_field_validator/date_type_value_spec' do
|
5
|
+
|
5
6
|
class Holiday
|
6
7
|
#
|
7
8
|
# Behaviors
|
@@ -20,7 +21,7 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
20
21
|
# Validations
|
21
22
|
#
|
22
23
|
|
23
|
-
|
24
|
+
validates_presence_of :on
|
24
25
|
end
|
25
26
|
|
26
27
|
describe 'Holiday' do
|
@@ -122,4 +123,5 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
122
123
|
end
|
123
124
|
end
|
124
125
|
end
|
126
|
+
|
125
127
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'integration/required_field_validator/spec_helper'
|
3
3
|
|
4
|
-
|
4
|
+
describe 'required_field_validator/datetime_type_value_spec' do
|
5
|
+
|
5
6
|
class ScheduledOperation
|
6
7
|
#
|
7
8
|
# Behaviors
|
@@ -20,7 +21,7 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
20
21
|
# Validations
|
21
22
|
#
|
22
23
|
|
23
|
-
|
24
|
+
validates_presence_of :at
|
24
25
|
end
|
25
26
|
|
26
27
|
describe 'ScheduledOperation' do
|
@@ -122,4 +123,5 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
122
123
|
end
|
123
124
|
end
|
124
125
|
end
|
126
|
+
|
125
127
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'integration/required_field_validator/spec_helper'
|
3
3
|
|
4
|
-
|
4
|
+
describe 'required_field_validator/float_type_value_spec' do
|
5
|
+
|
5
6
|
#
|
6
7
|
# Especially stupid example since Hg adds local repository revision
|
7
8
|
# to each new commit, but lets roll on with this SCM-ish classes and
|
@@ -25,7 +26,7 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
25
26
|
# Validations
|
26
27
|
#
|
27
28
|
|
28
|
-
|
29
|
+
validates_presence_of :percent
|
29
30
|
end
|
30
31
|
|
31
32
|
describe 'CpuConsumption' do
|
@@ -126,4 +127,5 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
126
127
|
end
|
127
128
|
end
|
128
129
|
end
|
130
|
+
|
129
131
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'integration/required_field_validator/spec_helper'
|
3
3
|
|
4
|
-
|
4
|
+
describe 'required_field_validator/integer_type_value_spec' do
|
5
|
+
|
5
6
|
#
|
6
7
|
# Especially stupid example since Hg adds local repository revision
|
7
8
|
# to each new commit, but lets roll on with this SCM-ish classes and
|
@@ -18,7 +19,7 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
18
19
|
# Validations
|
19
20
|
#
|
20
21
|
|
21
|
-
|
22
|
+
validates_presence_of :local_repo_revision_num
|
22
23
|
end
|
23
24
|
|
24
25
|
describe 'HgCommit' do
|
@@ -94,4 +95,5 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
94
95
|
end
|
95
96
|
end
|
96
97
|
end
|
98
|
+
|
97
99
|
end
|
@@ -1,14 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'integration/required_field_validator/spec_helper'
|
3
3
|
|
4
|
-
|
4
|
+
describe 'required_field_validator/plain_old_ruby_object_spec' do
|
5
|
+
|
5
6
|
describe "A plain old Ruby object (not a DM resource)" do
|
6
7
|
before do
|
7
8
|
class PlainClass
|
8
|
-
extend DataMapper::
|
9
|
-
include DataMapper::
|
9
|
+
extend DataMapper::Validations::ClassMethods
|
10
|
+
include DataMapper::Validations
|
10
11
|
attr_accessor :accessor
|
11
|
-
|
12
|
+
validates_presence_of :here, :empty, :nil, :accessor
|
12
13
|
def here; "here" end
|
13
14
|
def empty; "" end
|
14
15
|
def nil; nil end
|
@@ -30,4 +31,5 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
30
31
|
@pc.errors.on(:accessor).should be_nil
|
31
32
|
end
|
32
33
|
end
|
34
|
+
|
33
35
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'integration/required_field_validator/spec_helper'
|
3
3
|
|
4
|
-
|
4
|
+
describe 'required_field_validator/string_type_value_spec' do
|
5
|
+
|
5
6
|
# keep in mind any ScmOperation has a default value for brand property
|
6
7
|
# so it is used
|
7
8
|
describe 'GitOperation' do
|
@@ -162,4 +163,5 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
162
163
|
end
|
163
164
|
end
|
164
165
|
end
|
166
|
+
|
165
167
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'integration/required_field_validator/spec_helper'
|
3
3
|
|
4
|
-
|
4
|
+
describe 'required_field_validator/text_type_value_spec' do
|
5
|
+
|
5
6
|
# keep in mind any ScmOperation has a default value for brand property
|
6
7
|
# so it is used
|
7
8
|
describe 'GitOperation' do
|
@@ -44,4 +45,5 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
44
45
|
end
|
45
46
|
end
|
46
47
|
end
|
48
|
+
|
47
49
|
end
|
@@ -1,4 +1,8 @@
|
|
1
1
|
describe "valid model", :shared => true do
|
2
|
+
before do
|
3
|
+
@model.valid?
|
4
|
+
end
|
5
|
+
|
2
6
|
it "is valid" do
|
3
7
|
@model.should be_valid
|
4
8
|
end
|
@@ -13,6 +17,10 @@ describe "valid model", :shared => true do
|
|
13
17
|
end
|
14
18
|
|
15
19
|
describe "invalid model", :shared => true do
|
20
|
+
before do
|
21
|
+
@model.valid?
|
22
|
+
end
|
23
|
+
|
16
24
|
it "is NOT valid" do
|
17
25
|
@model.should_not be_valid
|
18
26
|
end
|
@@ -2,42 +2,43 @@ require 'spec_helper'
|
|
2
2
|
require 'integration/uniqueness_validator/spec_helper'
|
3
3
|
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
describe 'uniqueness_validator/uniqueness_validator_spec' do
|
6
|
+
|
7
|
+
describe 'DataMapper::Validations::Fixtures::Department' do
|
7
8
|
before :all do
|
8
|
-
DataMapper::
|
9
|
+
DataMapper::Validations::Fixtures::Department.all.destroy!
|
9
10
|
|
10
|
-
DataMapper::
|
11
|
+
DataMapper::Validations::Fixtures::Department.create(:name => "HR").should be_saved
|
11
12
|
end
|
12
13
|
|
13
14
|
describe "with unique name" do
|
14
|
-
before
|
15
|
-
@model = DataMapper::
|
15
|
+
before do
|
16
|
+
@model = DataMapper::Validations::Fixtures::Department.new(:name => "R & D")
|
16
17
|
end
|
17
18
|
|
18
19
|
it_should_behave_like "valid model"
|
19
20
|
end
|
20
21
|
|
21
22
|
describe "with a duplicate name" do
|
22
|
-
before
|
23
|
-
@model = DataMapper::
|
23
|
+
before do
|
24
|
+
@model = DataMapper::Validations::Fixtures::Department.new(:name => "HR")
|
24
25
|
end
|
25
26
|
|
26
27
|
it_should_behave_like "invalid model"
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
30
|
-
describe 'DataMapper::
|
31
|
+
describe 'DataMapper::Validations::Fixtures::Organisation' do
|
31
32
|
before :all do
|
32
|
-
DataMapper::
|
33
|
+
DataMapper::Validations::Fixtures::Organisation.all.destroy!
|
33
34
|
|
34
35
|
@model = DataMapper.repository do
|
35
|
-
DataMapper::
|
36
|
+
DataMapper::Validations::Fixtures::Organisation.create(:name => 'Apple', :domain => 'apple.com')
|
36
37
|
end
|
37
38
|
end
|
38
39
|
|
39
40
|
describe "with missing domain" do
|
40
|
-
before
|
41
|
+
before do
|
41
42
|
@model.domain = nil
|
42
43
|
end
|
43
44
|
|
@@ -45,8 +46,8 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
45
46
|
end
|
46
47
|
|
47
48
|
describe "with a duplicate domain" do
|
48
|
-
before
|
49
|
-
@model = DataMapper::
|
49
|
+
before do
|
50
|
+
@model = DataMapper::Validations::Fixtures::Organisation.new(:name => 'Fake Apple', :domain => 'apple.com')
|
50
51
|
end
|
51
52
|
|
52
53
|
it_should_behave_like "invalid model"
|
@@ -63,16 +64,16 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
63
64
|
end
|
64
65
|
end
|
65
66
|
|
66
|
-
describe 'DataMapper::
|
67
|
+
describe 'DataMapper::Validations::Fixtures::User' do
|
67
68
|
before :all do
|
68
|
-
DataMapper::
|
69
|
-
DataMapper::
|
70
|
-
DataMapper::
|
69
|
+
DataMapper::Validations::Fixtures::Organisation.all.destroy!
|
70
|
+
DataMapper::Validations::Fixtures::Department.all.destroy!
|
71
|
+
DataMapper::Validations::Fixtures::User.all.destroy!
|
71
72
|
|
72
73
|
DataMapper.repository do
|
73
|
-
@organization = DataMapper::
|
74
|
-
@dept = DataMapper::
|
75
|
-
@user = DataMapper::
|
74
|
+
@organization = DataMapper::Validations::Fixtures::Organisation.create(:name => 'Org 101', :domain => '101')
|
75
|
+
@dept = DataMapper::Validations::Fixtures::Department.create(:name => 'accounting')
|
76
|
+
@user = DataMapper::Validations::Fixtures::User.create(:organisation => @organization, :user_name => 'guy', :department => @dept)
|
76
77
|
|
77
78
|
@organization.should be_saved
|
78
79
|
@dept.should be_saved
|
@@ -81,8 +82,8 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
81
82
|
end
|
82
83
|
|
83
84
|
describe "with username not valid across the organization" do
|
84
|
-
before
|
85
|
-
@model = DataMapper::
|
85
|
+
before do
|
86
|
+
@model = DataMapper::Validations::Fixtures::User.new(:organisation => @organization, :user_name => 'guy')
|
86
87
|
end
|
87
88
|
|
88
89
|
it "is not valid for signing up" do
|
@@ -90,14 +91,15 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
90
91
|
end
|
91
92
|
|
92
93
|
it "has a meaningful error message" do
|
94
|
+
@model.valid?(:signing_up_for_organization_account)
|
93
95
|
@model.errors.on(:user_name).should == [ 'User name is already taken' ]
|
94
96
|
end
|
95
97
|
end
|
96
98
|
|
97
99
|
|
98
100
|
describe "with username not valid across the department" do
|
99
|
-
before
|
100
|
-
@model = DataMapper::
|
101
|
+
before do
|
102
|
+
@model = DataMapper::Validations::Fixtures::User.new(:user_name => 'guy', :department => @dept)
|
101
103
|
end
|
102
104
|
|
103
105
|
it "is not valid for setting up the account" do
|
@@ -105,8 +107,10 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
105
107
|
end
|
106
108
|
|
107
109
|
it "has a meaningful error message" do
|
110
|
+
@model.valid?(:signing_up_for_department_account)
|
108
111
|
@model.errors.on(:user_name).should == [ 'User name is already taken' ]
|
109
112
|
end
|
110
113
|
end
|
111
114
|
end
|
115
|
+
|
112
116
|
end
|