remarkable_mongo_ign 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/LICENSE +20 -0
- data/README.md +23 -0
- data/Rakefile +31 -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/remarkable_mongo.gemspec +79 -0
- data/remarkable_mongo_ign.gemspec +81 -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 +126 -0
data/locales/en.yml
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
en:
|
2
|
+
remarkable:
|
3
|
+
mongo_mapper:
|
4
|
+
describe:
|
5
|
+
each: "{{key}} is {{value}}"
|
6
|
+
prepend: "when "
|
7
|
+
connector: " and "
|
8
|
+
expectations:
|
9
|
+
allow_nil: "{{subject_name}} to {{not}}allow nil values for {{attribute}}"
|
10
|
+
allow_blank: "{{subject_name}} to {{not}}allow blank values for {{attribute}}"
|
11
|
+
optionals:
|
12
|
+
allow_nil:
|
13
|
+
positive: "allowing nil values"
|
14
|
+
negative: "not allowing nil values"
|
15
|
+
allow_blank:
|
16
|
+
positive: "allowing blank values"
|
17
|
+
negative: "not allowing blank values"
|
18
|
+
|
19
|
+
allow_values_for:
|
20
|
+
description: "allow {{in}} as values for {{attributes}}"
|
21
|
+
expectations:
|
22
|
+
is_valid: "{{subject_name}} to be valid when {{attribute}} is set to {{value}}"
|
23
|
+
|
24
|
+
association:
|
25
|
+
many: have many
|
26
|
+
belongs_to: belong to
|
27
|
+
description: "{{type}} {{associations}}"
|
28
|
+
expectations:
|
29
|
+
association_exists: "{{subject_name}} records {{type}} {{association}}, but the association does not exist"
|
30
|
+
type_matches: "{{subject_name}} records {{type}} {{association}}, got {{subject_name}} records {{actual_type}} {{association}}"
|
31
|
+
klass_exists: "{{subject_name}} records {{type}} {{association}}, but the association class does not exist"
|
32
|
+
options_match: "{{subject_name}} records {{type}} {{association}} with options {{options}}, got {{actual}}"
|
33
|
+
|
34
|
+
have_key:
|
35
|
+
description: "have key(s) {{attributes}} with type {{type}}"
|
36
|
+
expectations:
|
37
|
+
has_key: "{{subject_name}} to have key named {{attribute}} with type {{type}}"
|
38
|
+
|
39
|
+
validate_acceptance_of:
|
40
|
+
description: "require {{attributes}} to be accepted"
|
41
|
+
expectations:
|
42
|
+
requires_acceptance: "{{subject_name}} to be invalid if {{attribute}} is not accepted"
|
43
|
+
accept_is_valid: "{{subject_name}} to be valid when {{attribute}} is accepted with value {{accept}}"
|
44
|
+
optionals:
|
45
|
+
accept:
|
46
|
+
positive: "with value {{inspect}}"
|
47
|
+
|
48
|
+
validate_associated:
|
49
|
+
description: "require associated {{associations}} to be valid"
|
50
|
+
expectations:
|
51
|
+
is_valid: "{{subject_name}} to be invalid when {{association}} is invalid"
|
52
|
+
|
53
|
+
validate_confirmation_of:
|
54
|
+
description: "require {{attributes}} to be confirmed"
|
55
|
+
expectations:
|
56
|
+
responds_to_confirmation: "{{subject_name}} instance responds to {{attribute}}_confirmation"
|
57
|
+
confirms: "{{subject_name}} to be valid only when {{attribute}} is confirmed"
|
58
|
+
|
59
|
+
validate_exclusion_of:
|
60
|
+
description: "ensure exclusion of {{attributes}} in {{in}}"
|
61
|
+
expectations:
|
62
|
+
is_valid: "{{subject_name}} to be valid when {{attribute}} is set to {{value}}"
|
63
|
+
is_invalid: "{{subject_name}} to be invalid when {{attribute}} is set to {{value}}"
|
64
|
+
|
65
|
+
validate_inclusion_of:
|
66
|
+
description: "ensure inclusion of {{attributes}} in {{in}}"
|
67
|
+
expectations:
|
68
|
+
is_valid: "{{subject_name}} to be valid when {{attribute}} is set to {{value}}"
|
69
|
+
is_invalid: "{{subject_name}} to be invalid when {{attribute}} is set to {{value}}"
|
70
|
+
|
71
|
+
validate_length_of:
|
72
|
+
description: "ensure length of {{attributes}}"
|
73
|
+
expectations:
|
74
|
+
less_than_min_length: "{{subject_name}} to be invalid when {{attribute}} length is less than {{minimum}} characters"
|
75
|
+
exactly_min_length: "{{subject_name}} to be valid when {{attribute}} length is {{minimum}} characters"
|
76
|
+
more_than_max_length: "{{subject_name}} to be invalid when {{attribute}} length is more than {{maximum}} characters"
|
77
|
+
exactly_max_length: "{{subject_name}} to be valid when {{attribute}} length is {{maximum}} characters"
|
78
|
+
optionals:
|
79
|
+
within:
|
80
|
+
positive: "is within {{inspect}} characters"
|
81
|
+
maximum:
|
82
|
+
positive: "is maximum {{inspect}} characters"
|
83
|
+
minimum:
|
84
|
+
positive: "is minimum {{inspect}} characters"
|
85
|
+
is:
|
86
|
+
positive: "is equal to {{inspect}} characters"
|
87
|
+
with_kind_of:
|
88
|
+
positive: "with kind of {{value}}"
|
89
|
+
|
90
|
+
validate_numericality_of:
|
91
|
+
description: "ensure numericality of {{attributes}}"
|
92
|
+
expectations:
|
93
|
+
only_numeric_values: "{{subject_name}} to allow only numeric values for {{attribute}}"
|
94
|
+
only_integer: "{{subject_name}} to {{not}}allow only integer values for {{attribute}}"
|
95
|
+
only_even: "{{subject_name}} to allow only even values for {{attribute}}"
|
96
|
+
only_odd: "{{subject_name}} to allow only odd values for {{attribute}}"
|
97
|
+
equals_to: "{{subject_name}} to be valid only when {{attribute}} is equal to {{count}}"
|
98
|
+
more_than_maximum: "{{subject_name}} to be invalid when {{attribute}} is greater than {{count}}"
|
99
|
+
less_than_minimum: "{{subject_name}} to be invalid when {{attribute}} is less than {{count}}"
|
100
|
+
optionals:
|
101
|
+
only_integer:
|
102
|
+
positive: "allowing only integer values"
|
103
|
+
odd:
|
104
|
+
positive: "allowing only odd values"
|
105
|
+
even:
|
106
|
+
positive: "allowing only even values"
|
107
|
+
equal_to:
|
108
|
+
positive: "is equal to {{inspect}}"
|
109
|
+
less_than:
|
110
|
+
positive: "is less than {{inspect}}"
|
111
|
+
greater_than:
|
112
|
+
positive: "is greater than {{inspect}}"
|
113
|
+
less_than_or_equal_to:
|
114
|
+
positive: "is less than or equal to {{inspect}}"
|
115
|
+
greater_than_or_equal_to:
|
116
|
+
positive: "is greater than or equal to {{inspect}}"
|
117
|
+
|
118
|
+
validate_presence_of:
|
119
|
+
description: "require {{attributes}} to be set"
|
120
|
+
expectations:
|
121
|
+
allow_nil: "{{subject_name}} to require {{attribute}} to be set"
|
122
|
+
|
123
|
+
validate_uniqueness_of:
|
124
|
+
description: "require unique values for {{attributes}}"
|
125
|
+
expectations:
|
126
|
+
responds_to_scope: "{{subject_name}} instance responds to {{method}}"
|
127
|
+
is_unique: "{{subject_name}} to require unique values for {{attribute}}"
|
128
|
+
case_sensitive: "{{subject_name}} to {{not}}be case sensitive on {{attribute}} validation"
|
129
|
+
valid_with_new_scope: "{{subject_name}} to be valid when {{attribute}} scope ({{method}}) change"
|
130
|
+
optionals:
|
131
|
+
scope:
|
132
|
+
positive: "scoped to {{sentence}}"
|
133
|
+
case_sensitive:
|
134
|
+
positive: "case sensitive"
|
135
|
+
negative: "case insensitive"
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{remarkable_mongo}
|
8
|
+
s.version = "0.1.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Nicolas M\303\251rouze"]
|
12
|
+
s.date = %q{2010-01-11}
|
13
|
+
s.email = %q{nicolas.merouze@gmail.com}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"LICENSE",
|
16
|
+
"README.md"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".gitignore",
|
20
|
+
"LICENSE",
|
21
|
+
"README.md",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION",
|
24
|
+
"lib/remarkable/mongo_mapper.rb",
|
25
|
+
"lib/remarkable/mongo_mapper/base.rb",
|
26
|
+
"lib/remarkable/mongo_mapper/describe.rb",
|
27
|
+
"lib/remarkable/mongo_mapper/human_names.rb",
|
28
|
+
"lib/remarkable/mongo_mapper/matchers/allow_values_for_matcher.rb",
|
29
|
+
"lib/remarkable/mongo_mapper/matchers/association_matcher.rb",
|
30
|
+
"lib/remarkable/mongo_mapper/matchers/have_key_matcher.rb",
|
31
|
+
"lib/remarkable/mongo_mapper/matchers/validate_confirmation_of_matcher.rb",
|
32
|
+
"lib/remarkable/mongo_mapper/matchers/validate_length_of_matcher.rb",
|
33
|
+
"lib/remarkable/mongo_mapper/matchers/validate_presence_of_matcher.rb",
|
34
|
+
"locales/en.yml",
|
35
|
+
"spec/matchers/allow_values_for_matcher_spec.rb",
|
36
|
+
"spec/matchers/association_matcher_spec.rb",
|
37
|
+
"spec/matchers/have_key_matcher_spec.rb",
|
38
|
+
"spec/matchers/validate_confirmation_of_matcher_spec.rb",
|
39
|
+
"spec/matchers/validate_length_of_matcher_spec.rb",
|
40
|
+
"spec/matchers/validate_presence_of_matcher_spec.rb",
|
41
|
+
"spec/model_builder.rb",
|
42
|
+
"spec/models.rb",
|
43
|
+
"spec/spec.opts",
|
44
|
+
"spec/spec_helper.rb"
|
45
|
+
]
|
46
|
+
s.homepage = %q{http://github.com/nmerouze/remarkable_mongo}
|
47
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
48
|
+
s.require_paths = ["lib"]
|
49
|
+
s.rubygems_version = %q{1.3.5}
|
50
|
+
s.summary = %q{Remarkable Matchers for MongoDB ORMs}
|
51
|
+
s.test_files = [
|
52
|
+
"spec/matchers/allow_values_for_matcher_spec.rb",
|
53
|
+
"spec/matchers/association_matcher_spec.rb",
|
54
|
+
"spec/matchers/have_key_matcher_spec.rb",
|
55
|
+
"spec/matchers/validate_confirmation_of_matcher_spec.rb",
|
56
|
+
"spec/matchers/validate_length_of_matcher_spec.rb",
|
57
|
+
"spec/matchers/validate_presence_of_matcher_spec.rb",
|
58
|
+
"spec/model_builder.rb",
|
59
|
+
"spec/models.rb",
|
60
|
+
"spec/spec_helper.rb"
|
61
|
+
]
|
62
|
+
|
63
|
+
if s.respond_to? :specification_version then
|
64
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
65
|
+
s.specification_version = 3
|
66
|
+
|
67
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
68
|
+
s.add_runtime_dependency(%q<remarkable>, ["~> 3.1.8"])
|
69
|
+
s.add_runtime_dependency(%q<mongo_mapper>, ["~> 0.6.1"])
|
70
|
+
else
|
71
|
+
s.add_dependency(%q<remarkable>, ["~> 3.1.8"])
|
72
|
+
s.add_dependency(%q<mongo_mapper>, ["~> 0.6.1"])
|
73
|
+
end
|
74
|
+
else
|
75
|
+
s.add_dependency(%q<remarkable>, ["~> 3.1.8"])
|
76
|
+
s.add_dependency(%q<mongo_mapper>, ["~> 0.6.1"])
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{remarkable_mongo_ign}
|
8
|
+
s.version = "0.1.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Nicolas M\303\251rouze", "Chandra Patni"]
|
12
|
+
s.date = %q{2010-05-21}
|
13
|
+
s.email = %q{nicolas.merouze@gmail.com, rubyorchard@gmail.com}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"LICENSE",
|
16
|
+
"README.md"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".gitignore",
|
20
|
+
"LICENSE",
|
21
|
+
"README.md",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION",
|
24
|
+
"lib/remarkable/mongo_mapper.rb",
|
25
|
+
"lib/remarkable/mongo_mapper/base.rb",
|
26
|
+
"lib/remarkable/mongo_mapper/describe.rb",
|
27
|
+
"lib/remarkable/mongo_mapper/human_names.rb",
|
28
|
+
"lib/remarkable/mongo_mapper/matchers/allow_values_for_matcher.rb",
|
29
|
+
"lib/remarkable/mongo_mapper/matchers/association_matcher.rb",
|
30
|
+
"lib/remarkable/mongo_mapper/matchers/have_key_matcher.rb",
|
31
|
+
"lib/remarkable/mongo_mapper/matchers/validate_confirmation_of_matcher.rb",
|
32
|
+
"lib/remarkable/mongo_mapper/matchers/validate_length_of_matcher.rb",
|
33
|
+
"lib/remarkable/mongo_mapper/matchers/validate_presence_of_matcher.rb",
|
34
|
+
"locales/en.yml",
|
35
|
+
"remarkable_mongo.gemspec",
|
36
|
+
"remarkable_mongo_ign.gemspec",
|
37
|
+
"spec/matchers/allow_values_for_matcher_spec.rb",
|
38
|
+
"spec/matchers/association_matcher_spec.rb",
|
39
|
+
"spec/matchers/have_key_matcher_spec.rb",
|
40
|
+
"spec/matchers/validate_confirmation_of_matcher_spec.rb",
|
41
|
+
"spec/matchers/validate_length_of_matcher_spec.rb",
|
42
|
+
"spec/matchers/validate_presence_of_matcher_spec.rb",
|
43
|
+
"spec/model_builder.rb",
|
44
|
+
"spec/models.rb",
|
45
|
+
"spec/spec.opts",
|
46
|
+
"spec/spec_helper.rb"
|
47
|
+
]
|
48
|
+
s.homepage = %q{http://github.com/rubyorchard/remarkable_mongo}
|
49
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
50
|
+
s.require_paths = ["lib"]
|
51
|
+
s.rubygems_version = %q{1.3.6}
|
52
|
+
s.summary = %q{Remarkable Matchers for MongoDB ORMs}
|
53
|
+
s.test_files = [
|
54
|
+
"spec/matchers/allow_values_for_matcher_spec.rb",
|
55
|
+
"spec/matchers/association_matcher_spec.rb",
|
56
|
+
"spec/matchers/have_key_matcher_spec.rb",
|
57
|
+
"spec/matchers/validate_confirmation_of_matcher_spec.rb",
|
58
|
+
"spec/matchers/validate_length_of_matcher_spec.rb",
|
59
|
+
"spec/matchers/validate_presence_of_matcher_spec.rb",
|
60
|
+
"spec/model_builder.rb",
|
61
|
+
"spec/models.rb",
|
62
|
+
"spec/spec_helper.rb"
|
63
|
+
]
|
64
|
+
|
65
|
+
if s.respond_to? :specification_version then
|
66
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
67
|
+
s.specification_version = 3
|
68
|
+
|
69
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
70
|
+
s.add_runtime_dependency(%q<remarkable>, [">= 3.1.13"])
|
71
|
+
s.add_runtime_dependency(%q<mongo_mapper_ign>, [">= 0.7.6"])
|
72
|
+
else
|
73
|
+
s.add_dependency(%q<remarkable>, [">= 3.1.13"])
|
74
|
+
s.add_dependency(%q<mongo_mapper_ign>, [">= 0.7.6"])
|
75
|
+
end
|
76
|
+
else
|
77
|
+
s.add_dependency(%q<remarkable>, [">= 3.1.13"])
|
78
|
+
s.add_dependency(%q<mongo_mapper_ign>, [">= 0.7.6"])
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe 'allow_values_for' do
|
4
|
+
include ModelBuilder
|
5
|
+
|
6
|
+
# Defines a model, create a validation and returns a raw matcher
|
7
|
+
def define_and_validate(options={})
|
8
|
+
@model = define_model :product do
|
9
|
+
include MongoMapper::Document
|
10
|
+
|
11
|
+
key :title, String
|
12
|
+
key :category, String
|
13
|
+
|
14
|
+
validates_format_of :title, options
|
15
|
+
end
|
16
|
+
|
17
|
+
allow_values_for(:title)
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'messages' do
|
21
|
+
before(:each){ @matcher = define_and_validate(:with => /X|Y|Z/) }
|
22
|
+
|
23
|
+
it 'should contain a description' do
|
24
|
+
@matcher = allow_values_for(:title, "X", "Y", "Z")
|
25
|
+
@matcher.description.should == 'allow "X", "Y", and "Z" as values for title'
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should set is_valid? message' do
|
29
|
+
@matcher.in("A").matches?(subject)
|
30
|
+
@matcher.failure_message.should == 'Expected Product to be valid when title is set to "A"'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should set allow_nil? message' do
|
34
|
+
@matcher.allow_nil.matches?(subject)
|
35
|
+
@matcher.failure_message.should == 'Expected Product to allow nil values for title'
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should set allow_blank? message' do
|
39
|
+
@matcher.allow_blank.matches?(subject)
|
40
|
+
@matcher.failure_message.should == 'Expected Product to allow blank values for title'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'matchers' do
|
45
|
+
it { should define_and_validate(:with => /X|Y|Z/).in('X', 'Y', 'Z') }
|
46
|
+
it { should_not define_and_validate(:with => /X|Y|Z/).in('A') }
|
47
|
+
|
48
|
+
it { should define_and_validate(:with => /X|Y|Z/, :message => 'valid').in('X', 'Y', 'Z').message('valid') }
|
49
|
+
|
50
|
+
create_optional_boolean_specs(:allow_nil, self, :with => /X|Y|Z/)
|
51
|
+
create_optional_boolean_specs(:allow_blank, self, :with => /X|Y|Z/)
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'macros' do
|
55
|
+
before(:each){ define_and_validate(:with => /X|Y|Z/) }
|
56
|
+
|
57
|
+
should_allow_values_for :title, 'X'
|
58
|
+
should_not_allow_values_for :title, 'A'
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'failures' do
|
62
|
+
it "should fail if any of the values are valid on invalid cases" do
|
63
|
+
define_and_validate(:with => /X|Y|Z/)
|
64
|
+
|
65
|
+
lambda {
|
66
|
+
should_not allow_values_for(:title, 'A', 'X', 'B')
|
67
|
+
}.should raise_error(Spec::Expectations::ExpectationNotMetError, /Did not expect Product to be valid/)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe 'association_matcher' do
|
4
|
+
subject do
|
5
|
+
Article.new
|
6
|
+
end
|
7
|
+
|
8
|
+
describe 'have_many' do
|
9
|
+
|
10
|
+
describe 'messages' do
|
11
|
+
it 'should contain a description' do
|
12
|
+
matcher = have_many(:comments)
|
13
|
+
matcher.description.should == 'have many comments'
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should set association_exists? message' do
|
17
|
+
matcher = have_many(:whatever)
|
18
|
+
matcher.matches?(subject)
|
19
|
+
matcher.failure_message.should == 'Expected Article records have many whatever, but the association does not exist'
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should set type_matches? message' do
|
23
|
+
matcher = belong_to(:comments)
|
24
|
+
matcher.matches?(subject)
|
25
|
+
matcher.failure_message.should == 'Expected Article records belong to comments, got Article records have many comments'
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should set klass_exists? message' do
|
29
|
+
matcher = have_many(:unknowns)
|
30
|
+
matcher.matches?(subject)
|
31
|
+
matcher.failure_message.should == 'Expected Article records have many unknowns, but the association class does not exist'
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should set options_matches? message when :class_name is given' do
|
35
|
+
matcher = have_many(:ratings, :class_name => 'Rating')
|
36
|
+
matcher.matches?(subject)
|
37
|
+
matcher.failure_message.should == 'Expected Article records have many ratings with options {:class_name=>"Rating"}, got {:class_name=>"Rate"}'
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should set options_matches? message when :polymorphic is given' do
|
41
|
+
matcher = have_many(:assets, :polymorphic => true)
|
42
|
+
matcher.matches?(subject)
|
43
|
+
matcher.failure_message.should == 'Expected Article records have many assets with options {:polymorphic=>"true"}, got {:polymorphic=>""}'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'matchers' do
|
48
|
+
it { should have_many(:comments) }
|
49
|
+
it { should_not belong_to(:comment) }
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'macros' do
|
53
|
+
should_have_many :comments
|
54
|
+
should_not_belong_to :comment
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'belong_to' do
|
60
|
+
|
61
|
+
describe 'messages' do
|
62
|
+
it 'should contain a description' do
|
63
|
+
matcher = belong_to(:user)
|
64
|
+
matcher.description.should == 'belong to user'
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should set association_exists? message' do
|
68
|
+
matcher = belong_to(:whatever)
|
69
|
+
matcher.matches?(subject)
|
70
|
+
matcher.failure_message.should == 'Expected Article records belong to whatever, but the association does not exist'
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should set type_matches? message' do
|
74
|
+
matcher = have_many(:user)
|
75
|
+
matcher.matches?(subject)
|
76
|
+
matcher.failure_message.should == 'Expected Article records have many user, got Article records belong to user'
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should set klass_exists? message' do
|
80
|
+
matcher = belong_to(:unknown)
|
81
|
+
matcher.matches?(subject)
|
82
|
+
matcher.failure_message.should == 'Expected Article records belong to unknown, but the association class does not exist'
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should set options_matches? message when :class_name is given' do
|
86
|
+
matcher = belong_to(:site, :class_name => 'Website')
|
87
|
+
matcher.matches?(subject)
|
88
|
+
matcher.failure_message.should == 'Expected Article records belong to site with options {:class_name=>"Website"}, got {:class_name=>"Site"}'
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe 'matchers' do
|
93
|
+
it { should belong_to(:user) }
|
94
|
+
it { should_not have_many(:users) }
|
95
|
+
end
|
96
|
+
|
97
|
+
describe 'macros' do
|
98
|
+
should_belong_to :user
|
99
|
+
should_not_have_many :users
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|