remarkable_mongoid 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Brian Cardarella
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,28 @@
1
+ # remarkable_mongoid
2
+ RSpec Matchers for Mongoid
3
+
4
+ ## Matchers
5
+
6
+ Associations
7
+
8
+ * reference_one
9
+ * reference_many
10
+ * be_referenced_in
11
+ * embed_one
12
+ * embed_many
13
+ * be_embedded_in
14
+
15
+ Validations
16
+
17
+ * validates_uniqueness_of
18
+ * All ActiveModel validations from [Remarkable::ActiveModel](http://github.com/remarkable/remarkable/tree/master/remarkable_activemodel)
19
+
20
+ ## Usage
21
+
22
+ describe Book do
23
+ it { should reference_one :author }
24
+ end
25
+
26
+ ## Copyright
27
+
28
+ Copyright (c) 2010 Brian Cardarella. See LICENSE for details.
@@ -0,0 +1,56 @@
1
+ module Remarkable::Mongoid
2
+ module Matchers
3
+ def reference_one(attr)
4
+ AssociationMatcher.new(attr, ::Mongoid::Associations::ReferencesOne)
5
+ end
6
+
7
+ def reference_many(attr)
8
+ AssociationMatcher.new(attr, ::Mongoid::Associations::ReferencesMany)
9
+ end
10
+
11
+ def be_referenced_in(attr)
12
+ AssociationMatcher.new(attr, ::Mongoid::Associations::ReferencedIn)
13
+ end
14
+
15
+ def embed_one(attr)
16
+ AssociationMatcher.new(attr, ::Mongoid::Associations::EmbedsOne)
17
+ end
18
+
19
+ def embed_many(attr)
20
+ AssociationMatcher.new(attr, ::Mongoid::Associations::EmbedsMany)
21
+ end
22
+
23
+ def be_embedded_in(attr)
24
+ AssociationMatcher.new(attr, ::Mongoid::Associations::EmbeddedIn)
25
+ end
26
+
27
+ class AssociationMatcher
28
+ attr_accessor :attr, :association_type
29
+
30
+ def initialize(attr, association_type)
31
+ self.attr = attr.to_s
32
+ self.association_type = association_type
33
+ end
34
+
35
+ def matches?(subject)
36
+ @subject = subject
37
+ a = @subject.associations.select { |k,v| v.association == association_type }
38
+ a.detect { |k| k.first == attr } != nil
39
+ end
40
+
41
+ def description
42
+ "has #{humanized_association} association :#{attr}"
43
+ end
44
+
45
+ def failure_message_for_should
46
+ "\n#{humanized_association} association failure\nExpected: '#{attr}'"
47
+ end
48
+
49
+ private
50
+
51
+ def humanized_association
52
+ association_type.to_s.split('::').last
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,46 @@
1
+ module Remarkable::Mongoid
2
+ module Matchers
3
+ def validate_uniqueness_of(attr)
4
+ ValidateUniquenessOfMatcher.new(attr)
5
+ end
6
+
7
+ class ValidateUniquenessOfMatcher
8
+ attr_accessor :attr, :validation_type, :message
9
+
10
+ def initialize(attr)
11
+ self.attr = attr.to_sym
12
+ end
13
+
14
+ def with_message(message)
15
+ self.message = message
16
+ self
17
+ end
18
+
19
+ def matches?(subject)
20
+ @subject = subject
21
+ validations = @subject._validators[attr]
22
+ if validations
23
+ validation = validations.detect { |k| k.class == ::Mongoid::Validations::UniquenessValidator }
24
+
25
+ if validation && self.message
26
+ validation.options[:message] == self.message
27
+ else
28
+ validation != nil
29
+ end
30
+ else
31
+ false
32
+ end
33
+ end
34
+
35
+ def description
36
+ "validates that :#{attr} is unique"
37
+ end
38
+
39
+ def failure_message_for_should
40
+ "\nUniqueness validation failure\nExpected: '#{attr}' to be unique"
41
+ end
42
+
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,8 @@
1
+ module Remarkable
2
+ module Mongoid
3
+ end
4
+ end
5
+
6
+ require 'remarkable/active_model'
7
+ require 'remarkable_mongoid/associations'
8
+ require 'remarkable_mongoid/validate_uniqueness_of'
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: remarkable_mongoid
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 1
9
+ version: 0.1.1
10
+ platform: ruby
11
+ authors:
12
+ - Brian Cardarella
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-07-10 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: remarkable_activemodel
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 4
29
+ - 0
30
+ - 0
31
+ - alpha2
32
+ version: 4.0.0.alpha2
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: RSpec Matchers for Mongoid
36
+ email: bcardarella@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.markdown
44
+ files:
45
+ - LICENSE
46
+ - README.markdown
47
+ - lib/remarkable_mongoid.rb
48
+ - lib/remarkable_mongoid/associations.rb
49
+ - lib/remarkable_mongoid/validate_uniqueness_of.rb
50
+ has_rdoc: true
51
+ homepage: http://github.com/bcardarella/remarkable_mongoid
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options:
56
+ - --charset=UTF-8
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.3.6
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: RSpec Matchers for Mongoid
80
+ test_files: []
81
+