remarkable_mongo 0.1.2
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 +1 -0
- data/LICENSE +20 -0
- data/README.md +23 -0
- data/Rakefile +28 -0
- data/VERSION +1 -0
- data/lib/remarkable/mongo_mapper.rb +30 -0
- data/lib/remarkable/mongo_mapper/base.rb +223 -0
- data/lib/remarkable/mongo_mapper/describe.rb +199 -0
- data/lib/remarkable/mongo_mapper/human_names.rb +37 -0
- data/lib/remarkable/mongo_mapper/matchers/allow_values_for_matcher.rb +86 -0
- data/lib/remarkable/mongo_mapper/matchers/association_matcher.rb +105 -0
- data/lib/remarkable/mongo_mapper/matchers/have_key_matcher.rb +38 -0
- data/lib/remarkable/mongo_mapper/matchers/validate_confirmation_of_matcher.rb +44 -0
- data/lib/remarkable/mongo_mapper/matchers/validate_length_of_matcher.rb +106 -0
- data/lib/remarkable/mongo_mapper/matchers/validate_presence_of_matcher.rb +37 -0
- data/locales/en.yml +135 -0
- data/spec/matchers/allow_values_for_matcher_spec.rb +71 -0
- data/spec/matchers/association_matcher_spec.rb +104 -0
- data/spec/matchers/have_key_matcher_spec.rb +32 -0
- data/spec/matchers/validate_confirmation_of_matcher_spec.rb +64 -0
- data/spec/matchers/validate_length_of_matcher_spec.rb +147 -0
- data/spec/matchers/validate_presence_of_matcher_spec.rb +33 -0
- data/spec/model_builder.rb +64 -0
- data/spec/models.rb +42 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +17 -0
- metadata +108 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe 'validate_presence_of' do
|
4
|
+
subject do
|
5
|
+
Article.new
|
6
|
+
end
|
7
|
+
|
8
|
+
describe 'messages' do
|
9
|
+
|
10
|
+
it 'should contain a description' do
|
11
|
+
matcher = validate_presence_of(:title, :body)
|
12
|
+
matcher.description.should == 'require title and body to be set'
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should set allow_nil? message' do
|
16
|
+
matcher = validate_presence_of(:body)
|
17
|
+
matcher.matches?(subject)
|
18
|
+
matcher.failure_message.should == 'Expected Article to require body to be set'
|
19
|
+
matcher.negative_failure_message.should == 'Did not expect Article to require body to be set'
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'matchers' do
|
25
|
+
it { should validate_presence_of(:title) }
|
26
|
+
it { should_not validate_presence_of(:body) }
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'macros' do
|
30
|
+
should_validate_presence_of(:title)
|
31
|
+
should_not_validate_presence_of(:body)
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# This is based on Shoulda model builder for Test::Unit.
|
2
|
+
#
|
3
|
+
module ModelBuilder
|
4
|
+
def self.included(base)
|
5
|
+
return unless base.name =~ /^Spec/
|
6
|
+
|
7
|
+
base.class_eval do
|
8
|
+
after(:each) do
|
9
|
+
if @defined_constants
|
10
|
+
@defined_constants.each do |class_name|
|
11
|
+
Object.send(:remove_const, class_name)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
base.extend ClassMethods
|
18
|
+
end
|
19
|
+
|
20
|
+
def define_constant(class_name, &block)
|
21
|
+
class_name = class_name.to_s.camelize
|
22
|
+
|
23
|
+
klass = Class.new
|
24
|
+
Object.const_set(class_name, klass)
|
25
|
+
|
26
|
+
klass.class_eval(&block) if block_given?
|
27
|
+
|
28
|
+
@defined_constants ||= []
|
29
|
+
@defined_constants << class_name
|
30
|
+
|
31
|
+
klass
|
32
|
+
end
|
33
|
+
|
34
|
+
def define_model(name, columns = {}, &block)
|
35
|
+
instance = define_constant(name.to_s.classify, &block).new
|
36
|
+
|
37
|
+
self.class.subject { instance } if self.class.respond_to?(:subject)
|
38
|
+
instance
|
39
|
+
end
|
40
|
+
|
41
|
+
module ClassMethods
|
42
|
+
# This is a macro to run validations of boolean optionals such as :allow_nil
|
43
|
+
# and :allow_blank. This macro tests all scenarios. The specs must have a
|
44
|
+
# define_and_validate method defined.
|
45
|
+
#
|
46
|
+
def create_optional_boolean_specs(optional, base, options={})
|
47
|
+
base.describe "with #{optional} option" do
|
48
|
+
it { should define_and_validate(options.merge(optional => true)).send(optional) }
|
49
|
+
it { should define_and_validate(options.merge(optional => false)).send(optional, false) }
|
50
|
+
it { should_not define_and_validate(options.merge(optional => true)).send(optional, false) }
|
51
|
+
it { should_not define_and_validate(options.merge(optional => false)).send(optional) }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def create_message_specs(base)
|
56
|
+
base.describe "with message option" do
|
57
|
+
it { should define_and_validate(:message => 'valid_message').message('valid_message') }
|
58
|
+
it { should_not define_and_validate(:message => 'not_valid').message('valid_message') }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
data/spec/models.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
class Article
|
2
|
+
include MongoMapper::Document
|
3
|
+
|
4
|
+
key :title, String, :required => true
|
5
|
+
key :body, String
|
6
|
+
|
7
|
+
many :comments
|
8
|
+
many :unknowns
|
9
|
+
many :ratings, :class_name => "Rate"
|
10
|
+
many :assets
|
11
|
+
belongs_to :user
|
12
|
+
belongs_to :unknown
|
13
|
+
belongs_to :site, :class_name => 'Site'
|
14
|
+
end
|
15
|
+
|
16
|
+
class Comment
|
17
|
+
include MongoMapper::EmbeddedDocument
|
18
|
+
|
19
|
+
key :body, String
|
20
|
+
end
|
21
|
+
|
22
|
+
class User
|
23
|
+
include MongoMapper::Document
|
24
|
+
|
25
|
+
key :login, String
|
26
|
+
end
|
27
|
+
|
28
|
+
class Rate
|
29
|
+
include MongoMapper::EmbeddedDocument
|
30
|
+
end
|
31
|
+
|
32
|
+
class Rating
|
33
|
+
include MongoMapper::EmbeddedDocument
|
34
|
+
end
|
35
|
+
|
36
|
+
class Site
|
37
|
+
include MongoMapper::Document
|
38
|
+
end
|
39
|
+
|
40
|
+
class Webiste
|
41
|
+
include MongoMapper::EmbeddedDocument
|
42
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "mongo_mapper"
|
3
|
+
|
4
|
+
MongoMapper.database = "remarkable_mongomapper"
|
5
|
+
|
6
|
+
def reset_test_db!
|
7
|
+
MongoMapper.connection.drop_database("remarkable_mongomapper")
|
8
|
+
end
|
9
|
+
|
10
|
+
Spec::Runner.configure do |config|
|
11
|
+
config.before(:all) { reset_test_db! }
|
12
|
+
config.after(:all) { reset_test_db! }
|
13
|
+
end
|
14
|
+
|
15
|
+
require File.join(File.dirname(__FILE__), "..", "lib", "remarkable/mongo_mapper")
|
16
|
+
require File.join(File.dirname(__FILE__), "models")
|
17
|
+
require File.join(File.dirname(__FILE__), "model_builder")
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: remarkable_mongo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "Nicolas M\xC3\xA9rouze"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-11 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: remarkable
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 3.1.8
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: mongo_mapper
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.6.1
|
34
|
+
version:
|
35
|
+
description:
|
36
|
+
email: nicolas.merouze@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README.md
|
44
|
+
files:
|
45
|
+
- .gitignore
|
46
|
+
- LICENSE
|
47
|
+
- README.md
|
48
|
+
- Rakefile
|
49
|
+
- VERSION
|
50
|
+
- lib/remarkable/mongo_mapper.rb
|
51
|
+
- lib/remarkable/mongo_mapper/base.rb
|
52
|
+
- lib/remarkable/mongo_mapper/describe.rb
|
53
|
+
- lib/remarkable/mongo_mapper/human_names.rb
|
54
|
+
- lib/remarkable/mongo_mapper/matchers/allow_values_for_matcher.rb
|
55
|
+
- lib/remarkable/mongo_mapper/matchers/association_matcher.rb
|
56
|
+
- lib/remarkable/mongo_mapper/matchers/have_key_matcher.rb
|
57
|
+
- lib/remarkable/mongo_mapper/matchers/validate_confirmation_of_matcher.rb
|
58
|
+
- lib/remarkable/mongo_mapper/matchers/validate_length_of_matcher.rb
|
59
|
+
- lib/remarkable/mongo_mapper/matchers/validate_presence_of_matcher.rb
|
60
|
+
- locales/en.yml
|
61
|
+
- spec/matchers/allow_values_for_matcher_spec.rb
|
62
|
+
- spec/matchers/association_matcher_spec.rb
|
63
|
+
- spec/matchers/have_key_matcher_spec.rb
|
64
|
+
- spec/matchers/validate_confirmation_of_matcher_spec.rb
|
65
|
+
- spec/matchers/validate_length_of_matcher_spec.rb
|
66
|
+
- spec/matchers/validate_presence_of_matcher_spec.rb
|
67
|
+
- spec/model_builder.rb
|
68
|
+
- spec/models.rb
|
69
|
+
- spec/spec.opts
|
70
|
+
- spec/spec_helper.rb
|
71
|
+
has_rdoc: true
|
72
|
+
homepage: http://github.com/nmerouze/remarkable_mongo
|
73
|
+
licenses: []
|
74
|
+
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options:
|
77
|
+
- --charset=UTF-8
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: "0"
|
85
|
+
version:
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: "0"
|
91
|
+
version:
|
92
|
+
requirements: []
|
93
|
+
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 1.3.5
|
96
|
+
signing_key:
|
97
|
+
specification_version: 3
|
98
|
+
summary: Remarkable Matchers for MongoDB ORMs
|
99
|
+
test_files:
|
100
|
+
- spec/matchers/allow_values_for_matcher_spec.rb
|
101
|
+
- spec/matchers/association_matcher_spec.rb
|
102
|
+
- spec/matchers/have_key_matcher_spec.rb
|
103
|
+
- spec/matchers/validate_confirmation_of_matcher_spec.rb
|
104
|
+
- spec/matchers/validate_length_of_matcher_spec.rb
|
105
|
+
- spec/matchers/validate_presence_of_matcher_spec.rb
|
106
|
+
- spec/model_builder.rb
|
107
|
+
- spec/models.rb
|
108
|
+
- spec/spec_helper.rb
|