glebtv-mongoid-rspec 1.12.0

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.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.gitignore +6 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +14 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE +20 -0
  9. data/README.md +203 -0
  10. data/Rakefile +18 -0
  11. data/gemfiles/mongoid-3.1.gemfile +5 -0
  12. data/gemfiles/mongoid-4.0.gemfile +5 -0
  13. data/glebtv-mongoid-rspec.gemspec +25 -0
  14. data/lib/glebtv-mongoid-rspec.rb +1 -0
  15. data/lib/matchers/accept_nested_attributes.rb +65 -0
  16. data/lib/matchers/allow_mass_assignment.rb +101 -0
  17. data/lib/matchers/associations.rb +313 -0
  18. data/lib/matchers/collections.rb +9 -0
  19. data/lib/matchers/document.rb +160 -0
  20. data/lib/matchers/indexes.rb +81 -0
  21. data/lib/matchers/validations.rb +78 -0
  22. data/lib/matchers/validations/acceptance_of.rb +9 -0
  23. data/lib/matchers/validations/associated.rb +19 -0
  24. data/lib/matchers/validations/confirmation_of.rb +9 -0
  25. data/lib/matchers/validations/custom_validation_of.rb +47 -0
  26. data/lib/matchers/validations/exclusion_of.rb +49 -0
  27. data/lib/matchers/validations/format_of.rb +71 -0
  28. data/lib/matchers/validations/inclusion_of.rb +49 -0
  29. data/lib/matchers/validations/length_of.rb +147 -0
  30. data/lib/matchers/validations/numericality_of.rb +74 -0
  31. data/lib/matchers/validations/presence_of.rb +9 -0
  32. data/lib/matchers/validations/uniqueness_of.rb +82 -0
  33. data/lib/matchers/validations/with_message.rb +27 -0
  34. data/lib/mongoid-rspec.rb +33 -0
  35. data/lib/mongoid-rspec/version.rb +5 -0
  36. data/spec/models/article.rb +29 -0
  37. data/spec/models/comment.rb +6 -0
  38. data/spec/models/log.rb +4 -0
  39. data/spec/models/movie_article.rb +8 -0
  40. data/spec/models/permalink.rb +5 -0
  41. data/spec/models/person.rb +10 -0
  42. data/spec/models/profile.rb +16 -0
  43. data/spec/models/record.rb +5 -0
  44. data/spec/models/site.rb +9 -0
  45. data/spec/models/user.rb +36 -0
  46. data/spec/spec_helper.rb +34 -0
  47. data/spec/unit/accept_nested_attributes_spec.rb +12 -0
  48. data/spec/unit/associations_spec.rb +42 -0
  49. data/spec/unit/collections_spec.rb +7 -0
  50. data/spec/unit/document_spec.rb +27 -0
  51. data/spec/unit/indexes_spec.rb +13 -0
  52. data/spec/unit/validations_spec.rb +52 -0
  53. data/spec/validators/ssn_validator.rb +16 -0
  54. metadata +163 -0
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Collections" do
4
+ describe Log do
5
+ it { should be_stored_in :logs }
6
+ end
7
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Document" do
4
+ describe User do
5
+ it { should have_fields(:email, :login) }
6
+ it { should be_timestamped_document }
7
+ it { should be_timestamped_document.with(:created) }
8
+ it { should_not be_timestamped_document.with(:updated) }
9
+ end
10
+
11
+ describe Article do
12
+ if defined?(Mongoid::Boolean)
13
+ it { should have_field(:published).of_type(Mongoid::Boolean).with_default_value_of(false) }
14
+ it { should have_field(:allow_comments).of_type(Mongoid::Boolean).with_default_value_of(true) }
15
+ it { should_not have_field(:allow_comments).of_type(Mongoid::Boolean).with_default_value_of(false) }
16
+ else
17
+ it { should have_field(:published).of_type(Boolean).with_default_value_of(false) }
18
+ it { should have_field(:allow_comments).of_type(Boolean).with_default_value_of(true) }
19
+ it { should_not have_field(:allow_comments).of_type(Boolean).with_default_value_of(false) }
20
+ end
21
+ it { should belong_to(:author) }
22
+ it { should have_field(:title).localized }
23
+ it { should_not have_field(:number_of_comments).of_type(Integer).with_default_value_of(1) }
24
+ it { should be_mongoid_document }
25
+ it { should be_timestamped_document }
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Indexes" do
4
+ describe Article do
5
+ it { should have_index_for(published: 1) }
6
+ it { should have_index_for(title: 1).with_options(unique: true, background: true, drop_dups: true) }
7
+ it { should have_index_for('permalink._id' => 1) }
8
+ end
9
+
10
+ describe Profile do
11
+ it { should have_index_for(first_name: 1, last_name: 1) }
12
+ end
13
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Validations" do
4
+ describe Site do
5
+ it { should validate_presence_of(:name) }
6
+ it { should validate_uniqueness_of(:name) }
7
+ end
8
+
9
+ describe User do
10
+ it { should validate_presence_of(:login) }
11
+ it { should validate_uniqueness_of(:login).scoped_to(:site) }
12
+ it { should validate_uniqueness_of(:email).case_insensitive.with_message("is already taken") }
13
+ it { should validate_format_of(:login).to_allow("valid_login").not_to_allow("invalid login") }
14
+ it { should validate_associated(:profile) }
15
+ it { should validate_exclusion_of(:login).to_not_allow("super", "index", "edit") }
16
+ it { should validate_exclusion_of(:password).to_not_allow("password") }
17
+ it { should validate_inclusion_of(:role).to_allow("admin", "member") }
18
+ it { should validate_inclusion_of(:role).to_allow(["admin", "member"]) }
19
+ it { should validate_confirmation_of(:email) }
20
+ it { should validate_presence_of(:age).on(:create, :update) }
21
+ it { should validate_numericality_of(:age).on(:create, :update) }
22
+ it { should validate_inclusion_of(:age).to_allow(23..42).on([:create, :update]) }
23
+ it { should validate_presence_of(:password).on(:create) }
24
+ it { should validate_presence_of(:provider_uid).on(:create) }
25
+ it { should validate_inclusion_of(:locale).to_allow([:en, :ru]) }
26
+ end
27
+
28
+ describe Profile do
29
+ it { should validate_numericality_of(:age).greater_than(0) }
30
+ it { should validate_acceptance_of(:terms_of_service) }
31
+ it { should validate_length_of(:hobbies).with_minimum(1).with_message("requires at least one hobby") }
32
+ end
33
+
34
+ describe Article do
35
+ it { should validate_length_of(:title).within(8..16) }
36
+ it { should_not validate_length_of(:content).greater_than(200).less_than(16) }
37
+ it { should validate_length_of(:content).greater_than(200) }
38
+ it { should validate_inclusion_of(:status).to_allow([:pending]).on( :create ) }
39
+ it { should validate_inclusion_of(:status).to_allow([:approved, :rejected]).on( :update ) }
40
+ end
41
+
42
+ describe MovieArticle do
43
+ it { should validate_numericality_of(:rating).greater_than(0) }
44
+ it { should validate_numericality_of(:rating).to_allow(:greater_than => 0).less_than_or_equal_to(5) }
45
+ it { should validate_numericality_of(:classification).to_allow(:even => true, :only_integer => true, :nil => false) }
46
+ end
47
+
48
+ describe Person do
49
+ it { should custom_validate(:ssn).with_validator(SsnValidator) }
50
+ it { should_not custom_validate(:name) }
51
+ end
52
+ end
@@ -0,0 +1,16 @@
1
+ class SsnValidator < ActiveModel::EachValidator
2
+
3
+ def validate_each(record, attribute, value)
4
+ unless valid_ssn?(record, attribute, value)
5
+ record.errors[attribute] << "#{value} is not a valid Social Security Number"
6
+ end
7
+ end
8
+
9
+ def self.kind() :custom end
10
+
11
+ def valid_ssn?(record, attribute, value)
12
+ # irrelevant here how validation is done
13
+ true
14
+ end
15
+
16
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: glebtv-mongoid-rspec
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.12.0
5
+ platform: ruby
6
+ authors:
7
+ - Evan Sagge
8
+ - GlebTv
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-03-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: mongoid
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '3.0'
35
+ - - "<"
36
+ - !ruby/object:Gem::Version
37
+ version: '4.1'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '3.0'
45
+ - - "<"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.1'
48
+ - !ruby/object:Gem::Dependency
49
+ name: rspec
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '2.14'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '2.14'
62
+ description: RSpec matches for Mongoid models, including association and validation
63
+ matchers
64
+ email: evansagge@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - ".bundle/config"
70
+ - ".document"
71
+ - ".gitignore"
72
+ - ".ruby-gemset"
73
+ - ".ruby-version"
74
+ - ".travis.yml"
75
+ - Gemfile
76
+ - LICENSE
77
+ - README.md
78
+ - Rakefile
79
+ - gemfiles/mongoid-3.1.gemfile
80
+ - gemfiles/mongoid-4.0.gemfile
81
+ - glebtv-mongoid-rspec.gemspec
82
+ - lib/glebtv-mongoid-rspec.rb
83
+ - lib/matchers/accept_nested_attributes.rb
84
+ - lib/matchers/allow_mass_assignment.rb
85
+ - lib/matchers/associations.rb
86
+ - lib/matchers/collections.rb
87
+ - lib/matchers/document.rb
88
+ - lib/matchers/indexes.rb
89
+ - lib/matchers/validations.rb
90
+ - lib/matchers/validations/acceptance_of.rb
91
+ - lib/matchers/validations/associated.rb
92
+ - lib/matchers/validations/confirmation_of.rb
93
+ - lib/matchers/validations/custom_validation_of.rb
94
+ - lib/matchers/validations/exclusion_of.rb
95
+ - lib/matchers/validations/format_of.rb
96
+ - lib/matchers/validations/inclusion_of.rb
97
+ - lib/matchers/validations/length_of.rb
98
+ - lib/matchers/validations/numericality_of.rb
99
+ - lib/matchers/validations/presence_of.rb
100
+ - lib/matchers/validations/uniqueness_of.rb
101
+ - lib/matchers/validations/with_message.rb
102
+ - lib/mongoid-rspec.rb
103
+ - lib/mongoid-rspec/version.rb
104
+ - spec/models/article.rb
105
+ - spec/models/comment.rb
106
+ - spec/models/log.rb
107
+ - spec/models/movie_article.rb
108
+ - spec/models/permalink.rb
109
+ - spec/models/person.rb
110
+ - spec/models/profile.rb
111
+ - spec/models/record.rb
112
+ - spec/models/site.rb
113
+ - spec/models/user.rb
114
+ - spec/spec_helper.rb
115
+ - spec/unit/accept_nested_attributes_spec.rb
116
+ - spec/unit/associations_spec.rb
117
+ - spec/unit/collections_spec.rb
118
+ - spec/unit/document_spec.rb
119
+ - spec/unit/indexes_spec.rb
120
+ - spec/unit/validations_spec.rb
121
+ - spec/validators/ssn_validator.rb
122
+ homepage: http://github.com/glebtv/mongoid-rspec
123
+ licenses: []
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project: mongoid-rspec
141
+ rubygems_version: 2.2.2
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: RSpec matchers for Mongoid
145
+ test_files:
146
+ - spec/models/article.rb
147
+ - spec/models/comment.rb
148
+ - spec/models/log.rb
149
+ - spec/models/movie_article.rb
150
+ - spec/models/permalink.rb
151
+ - spec/models/person.rb
152
+ - spec/models/profile.rb
153
+ - spec/models/record.rb
154
+ - spec/models/site.rb
155
+ - spec/models/user.rb
156
+ - spec/spec_helper.rb
157
+ - spec/unit/accept_nested_attributes_spec.rb
158
+ - spec/unit/associations_spec.rb
159
+ - spec/unit/collections_spec.rb
160
+ - spec/unit/document_spec.rb
161
+ - spec/unit/indexes_spec.rb
162
+ - spec/unit/validations_spec.rb
163
+ - spec/validators/ssn_validator.rb