mongoid-rspec 1.5.1 → 1.5.3
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/README.md +39 -16
- data/lib/matchers/validations/inclusion_of.rb +9 -2
- data/lib/mongoid-rspec/version.rb +1 -1
- data/spec/models/user.rb +2 -0
- data/spec/unit/validations_spec.rb +1 -0
- metadata +8 -8
data/README.md
CHANGED
@@ -46,6 +46,19 @@ Association Matchers
|
|
46
46
|
it { should belong_to(:user).as_inverse_of(:record) }
|
47
47
|
end
|
48
48
|
|
49
|
+
Mass Assignment Matcher
|
50
|
+
-
|
51
|
+
describe User do
|
52
|
+
it { should allow_mass_assignment_of(:login) }
|
53
|
+
it { should allow_mass_assignment_of(:email) }
|
54
|
+
it { should allow_mass_assignment_of(:age) }
|
55
|
+
it { should allow_mass_assignment_of(:password) }
|
56
|
+
it { should allow_mass_assignment_of(:password) }
|
57
|
+
it { should allow_mass_assignment_of(:role).as(:admin) }
|
58
|
+
|
59
|
+
it { should_not allow_mass_assignment_of(:role) }
|
60
|
+
end
|
61
|
+
|
49
62
|
Validation Matchers
|
50
63
|
-
|
51
64
|
describe Site do
|
@@ -54,19 +67,20 @@ Validation Matchers
|
|
54
67
|
end
|
55
68
|
|
56
69
|
describe User do
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
+
it { should validate_presence_of(:login) }
|
71
|
+
it { should validate_uniqueness_of(:login).scoped_to(:site) }
|
72
|
+
it { should validate_uniqueness_of(:email).case_insensitive.with_message("is already taken") }
|
73
|
+
it { should validate_format_of(:login).to_allow("valid_login").not_to_allow("invalid login") }
|
74
|
+
it { should validate_associated(:profile) }
|
75
|
+
it { should validate_exclusion_of(:login).to_not_allow("super", "index", "edit") }
|
76
|
+
it { should validate_inclusion_of(:role).to_allow("admin", "member") }
|
77
|
+
it { should validate_confirmation_of(:email) }
|
78
|
+
it { should validate_presence_of(:age).on(:create, :update) }
|
79
|
+
it { should validate_numericality_of(:age).on(:create, :update) }
|
80
|
+
it { should validate_inclusion_of(:age).to_allow(23..42).on([:create, :update]) }
|
81
|
+
it { should validate_presence_of(:password).on(:create) }
|
82
|
+
it { should validate_presence_of(:provider_uid).on(:create) }
|
83
|
+
it { should validate_inclusion_of(:locale).to_allow([:en, :ru]) }
|
70
84
|
end
|
71
85
|
|
72
86
|
describe Article do
|
@@ -87,6 +101,18 @@ Validation Matchers
|
|
87
101
|
# should redefine the kind method to return :custom, i.e. "def self.kind() :custom end"
|
88
102
|
it { should custom_validate(:ssn).with_validator(SsnValidator) }
|
89
103
|
end
|
104
|
+
|
105
|
+
Index Matcher
|
106
|
+
-
|
107
|
+
describe Article do
|
108
|
+
it { should have_index_for(published: 1) }
|
109
|
+
it { should have_index_for(title: 1).with_options(unique: true, background: true) }
|
110
|
+
end
|
111
|
+
|
112
|
+
describe Profile do
|
113
|
+
it { should have_index_for(first_name: 1, last_name: 1) }
|
114
|
+
end
|
115
|
+
|
90
116
|
Others
|
91
117
|
-
|
92
118
|
describe User do
|
@@ -94,9 +120,6 @@ Others
|
|
94
120
|
it { should have_field(:active).of_type(Boolean).with_default_value_of(false) }
|
95
121
|
it { should have_fields(:birthdate, :registered_at).of_type(DateTime) }
|
96
122
|
|
97
|
-
it { should have_index_for(:last_name) }
|
98
|
-
it { should have_index_for(:email).with_options(:unique => true) }
|
99
|
-
|
100
123
|
it { should be_timestamped_document } # if you're declaring `include
|
101
124
|
Mongoid::Timestamps` or any of `include Mongoid::Timestamps::Created` and `Mongoid::Timestamps::Updated`
|
102
125
|
it { should be_timestamped_document.with(:created) }
|
@@ -13,9 +13,16 @@ module Mongoid
|
|
13
13
|
|
14
14
|
def matches?(actual)
|
15
15
|
return false unless result = super(actual)
|
16
|
-
|
16
|
+
|
17
17
|
if @allowed_values
|
18
|
-
|
18
|
+
raw_validator_allowed_values = @validator.options[:in]
|
19
|
+
|
20
|
+
validator_allowed_values = case raw_validator_allowed_values
|
21
|
+
when Range then raw_validator_allowed_values.to_a
|
22
|
+
when Proc then raw_validator_allowed_values.call(actual)
|
23
|
+
else raw_validator_allowed_values end
|
24
|
+
|
25
|
+
not_allowed_values = @allowed_values - validator_allowed_values
|
19
26
|
if not_allowed_values.empty?
|
20
27
|
@positive_result_message = @positive_result_message << " allowing all values mentioned"
|
21
28
|
else
|
data/spec/models/user.rb
CHANGED
@@ -8,6 +8,7 @@ class User
|
|
8
8
|
field :age, type: Integer
|
9
9
|
field :password, type: String
|
10
10
|
field :provider_uid
|
11
|
+
field :locale
|
11
12
|
|
12
13
|
belongs_to :site, :inverse_of => :users
|
13
14
|
has_many :articles, :foreign_key => :author_id
|
@@ -24,6 +25,7 @@ class User
|
|
24
25
|
validates :age, :presence => true, :numericality => true, :inclusion => { :in => 23..42 }, :on => [:create, :update]
|
25
26
|
validates :password, :presence => true, :on => [:create, :update]
|
26
27
|
validates :provider_uid, presence: true
|
28
|
+
validates :locale, :inclusion => {:in => lambda { |user| [:en, :ru] } }
|
27
29
|
|
28
30
|
attr_accessible :login, :email, :age, :password
|
29
31
|
attr_accessible :role, :as => :admin
|
@@ -20,6 +20,7 @@ describe "Validations" do
|
|
20
20
|
it { should validate_inclusion_of(:age).to_allow(23..42).on([:create, :update]) }
|
21
21
|
it { should validate_presence_of(:password).on(:create) }
|
22
22
|
it { should validate_presence_of(:provider_uid).on(:create) }
|
23
|
+
it { should validate_inclusion_of(:locale).to_allow([:en, :ru]) }
|
23
24
|
end
|
24
25
|
|
25
26
|
describe Profile do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70177756732360 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70177756732360
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: mongoid
|
27
|
-
requirement: &
|
27
|
+
requirement: &70177756731080 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 3.0.1
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70177756731080
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70177756728480 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '2.9'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70177756728480
|
47
47
|
description: RSpec matches for Mongoid models, including association and validation
|
48
48
|
matchers
|
49
49
|
email: evansagge@gmail.com
|