mongoid-rspec 1.5.1 → 1.5.3

Sign up to get free protection for your applications and to get access to all the features.
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
- it { should validate_presence_of(:login) }
58
- it { should validate_uniqueness_of(:login).scoped_to(:site) }
59
- it { should validate_uniqueness_of(:email).case_insensitive.with_message("is already taken") }
60
- it { should validate_format_of(:login).to_allow("valid_login").not_to_allow("invalid login") }
61
- it { should validate_associated(:profile) }
62
- it { should validate_exclusion_of(:login).to_not_allow("super", "index", "edit") }
63
- it { should validate_inclusion_of(:role).to_allow("admin", "member") }
64
- it { should validate_confirmation_of(:email) }
65
- it { should validate_presence_of(:age).on(:create, :update) }
66
- # The on matcher can take var args or an array. Validations do not fail if on is not specified.
67
- it { should validate_numericality_of(:age).on(:create, :update) }
68
- it { should validate_inclusion_of(:age).to_allow(23..42).on([:create, :update]) }
69
- it { should validate_presence_of(:password).on(:create) }
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
- not_allowed_values = @allowed_values - @validator.options[:in].to_a
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
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Rspec
3
- VERSION = "1.5.1"
3
+ VERSION = "1.5.3"
4
4
  end
5
5
  end
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.1
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-07-27 00:00:00.000000000 Z
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: &70095909068120 !ruby/object:Gem::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: *70095909068120
24
+ version_requirements: *70177756732360
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mongoid
27
- requirement: &70095909066740 !ruby/object:Gem::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: *70095909066740
35
+ version_requirements: *70177756731080
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70095909065960 !ruby/object:Gem::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: *70095909065960
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