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/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,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
@@ -0,0 +1,32 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe 'have_key' do
4
+ subject do
5
+ Article.new
6
+ end
7
+
8
+ describe 'messages' do
9
+
10
+ it 'should contain a description' do
11
+ matcher = have_key(:title, String)
12
+ matcher.description.should == 'have key(s) title with type String'
13
+ end
14
+
15
+ it 'should set has_key? message' do
16
+ matcher = have_key(:owner, String)
17
+ matcher.matches?(subject)
18
+ matcher.failure_message.should == 'Expected Article to have key named owner with type String'
19
+ end
20
+
21
+ end
22
+
23
+ describe 'matchers' do
24
+ it { should have_key(:title, String) }
25
+ it { should have_keys(:title, :body, String) }
26
+ end
27
+
28
+ describe 'macros' do
29
+ should_have_key :title, String
30
+ should_have_keys :title, :body, String
31
+ end
32
+ end
@@ -0,0 +1,64 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe 'validate_confirmation_of' 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 :person do
9
+ include MongoMapper::Document
10
+
11
+ key :name, String
12
+ key :email, String
13
+ key :age, String
14
+
15
+ validates_confirmation_of :name, :email, options
16
+ end
17
+
18
+ validate_confirmation_of(:name, :email)
19
+ end
20
+
21
+ describe 'messages' do
22
+ before(:each){ @matcher = define_and_validate }
23
+
24
+ it 'should contain a description' do
25
+ @matcher.description.should == 'require name and email to be confirmed'
26
+ end
27
+
28
+ it 'should set responds_to_confirmation? message' do
29
+ @matcher = validate_confirmation_of(:age)
30
+ @matcher.matches?(@model)
31
+ @matcher.failure_message.should == 'Expected Person instance responds to age_confirmation'
32
+ end
33
+
34
+ it 'should set confirms? message' do
35
+ @model.instance_eval{ def age_confirmation=(*args); end }
36
+ @matcher = validate_confirmation_of(:age)
37
+ @matcher.matches?(@model)
38
+ @matcher.failure_message.should == 'Expected Person to be valid only when age is confirmed'
39
+ end
40
+
41
+ end
42
+
43
+ describe 'matchers' do
44
+
45
+ describe 'without options' do
46
+ before(:each){ define_and_validate }
47
+
48
+ it { should validate_confirmation_of(:name) }
49
+ it { should validate_confirmation_of(:name, :email) }
50
+ it { should_not validate_confirmation_of(:name, :age) }
51
+ end
52
+
53
+ create_message_specs(self)
54
+ end
55
+
56
+ describe 'macros' do
57
+ before(:each){ define_and_validate }
58
+
59
+ should_validate_confirmation_of :name
60
+ should_validate_confirmation_of :name, :email
61
+ should_not_validate_confirmation_of :name, :age
62
+ end
63
+
64
+ end
@@ -0,0 +1,147 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe 'validate_length_of' do
4
+ include ModelBuilder
5
+
6
+ # Defines a model, create a validation and returns a raw matcher
7
+ def define_and_validate(options={})
8
+ options = options.merge(:within => 3..5) if options.slice(:within, :maximum, :minimum, :is).empty?
9
+
10
+ @model = define_model :product do
11
+ include MongoMapper::Document
12
+
13
+ key :size, String
14
+ key :category, String
15
+
16
+ validates_length_of :size, options
17
+ end
18
+
19
+ validate_length_of(:size)
20
+ end
21
+
22
+ describe 'messages' do
23
+ before(:each){ @matcher = define_and_validate }
24
+
25
+ it 'should contain a description' do
26
+ @matcher.within(3..5)
27
+ @matcher.description.should == 'ensure length of size is within 3..5 characters'
28
+
29
+ @matcher.within(nil).is(3)
30
+ @matcher.description.should == 'ensure length of size is equal to 3 characters'
31
+
32
+ @matcher.is(nil).maximum(5)
33
+ @matcher.description.should == 'ensure length of size is maximum 5 characters'
34
+
35
+ @matcher.maximum(nil).minimum(3)
36
+ @matcher.description.should == 'ensure length of size is minimum 3 characters'
37
+
38
+ @matcher.allow_nil(false)
39
+ @matcher.description.should == 'ensure length of size is minimum 3 characters and not allowing nil values'
40
+
41
+ @matcher.allow_blank
42
+ @matcher.description.should == 'ensure length of size is minimum 3 characters, not allowing nil values, and allowing blank values'
43
+ end
44
+
45
+ it 'should set less_than_min_length? message' do
46
+ @matcher.within(4..5).matches?(@model)
47
+ @matcher.failure_message.should == 'Expected Product to be invalid when size length is less than 4 characters'
48
+ end
49
+
50
+ it 'should set exactly_min_length? message' do
51
+ @matcher.should_receive(:less_than_min_length?).and_return(true)
52
+ @matcher.within(2..5).matches?(@model)
53
+ @matcher.failure_message.should == 'Expected Product to be valid when size length is 2 characters'
54
+ end
55
+
56
+ it 'should set more_than_max_length? message' do
57
+ @matcher.within(3..4).matches?(@model)
58
+ @matcher.failure_message.should == 'Expected Product to be invalid when size length is more than 4 characters'
59
+ end
60
+
61
+ it 'should set exactly_max_length? message' do
62
+ @matcher.should_receive(:more_than_max_length?).and_return(true)
63
+ @matcher.within(3..6).matches?(@model)
64
+ @matcher.failure_message.should == 'Expected Product to be valid when size length is 6 characters'
65
+ end
66
+
67
+ it 'should set allow_blank? message' do
68
+ @matcher.within(3..5).allow_blank.matches?(@model)
69
+ @matcher.failure_message.should == 'Expected Product to allow blank values for size'
70
+ end
71
+
72
+ it 'should set allow_nil? message' do
73
+ @matcher.within(3..5).allow_nil.matches?(@model)
74
+ @matcher.failure_message.should == 'Expected Product to allow nil values for size'
75
+ end
76
+ end
77
+
78
+ describe 'matcher' do
79
+ # Wrap specs without options. Usually a couple specs.
80
+ describe 'without options' do
81
+ before(:each){ define_and_validate }
82
+
83
+ it { should validate_length_of(:size, :within => 3..5) }
84
+ it { should_not validate_length_of(:category, :within => 3..5) }
85
+ end
86
+
87
+ describe "with message option" do
88
+
89
+ # if RAILS_VERSION =~ /^2.3/
90
+ # it { should define_and_validate(:message => 'not valid').within(3..5).message('not valid') }
91
+ # it { should_not define_and_validate(:message => 'not valid').within(3..5).message('valid') }
92
+ # else
93
+ # it { should define_and_validate(:too_short => 'not valid', :too_long => 'not valid').within(3..5).message('not valid') }
94
+ # it { should_not define_and_validate(:too_short => 'not valid', :too_long => 'not valid').within(3..5).message('valid') }
95
+ # end
96
+
97
+ it { should define_and_validate(:is => 4, :message => 'not valid').is(4).message('not valid') }
98
+ it { should_not define_and_validate(:is => 4, :message => 'not valid').is(4).message('valid') }
99
+ end
100
+
101
+ describe "with within option" do
102
+ it { should define_and_validate(:within => 3..5).within(3..5) }
103
+ it { should_not define_and_validate(:within => 3..5).within(2..5) }
104
+ it { should_not define_and_validate(:within => 3..5).within(4..5) }
105
+ it { should_not define_and_validate(:within => 3..5).within(3..4) }
106
+ it { should_not define_and_validate(:within => 3..5).within(3..6) }
107
+ end
108
+
109
+ describe "with minimum option" do
110
+ it { should define_and_validate(:minimum => 3).minimum(3) }
111
+ it { should_not define_and_validate(:minimum => 3).minimum(2) }
112
+ it { should_not define_and_validate(:minimum => 3).minimum(4) }
113
+ end
114
+
115
+ describe "with maximum option" do
116
+ it { should define_and_validate(:maximum => 3).maximum(3) }
117
+ it { should_not define_and_validate(:maximum => 3).maximum(2) }
118
+ it { should_not define_and_validate(:maximum => 3).maximum(4) }
119
+ end
120
+
121
+ describe "with is option" do
122
+ it { should define_and_validate(:is => 3).is(3) }
123
+ it { should_not define_and_validate(:is => 3).is(2) }
124
+ it { should_not define_and_validate(:is => 3).is(4) }
125
+ end
126
+
127
+ # Those are macros to test optionals which accept only boolean values
128
+ create_optional_boolean_specs(:allow_nil, self)
129
+ create_optional_boolean_specs(:allow_blank, self)
130
+ end
131
+
132
+ # In macros we include just a few tests to assure that everything works properly
133
+ describe 'macros' do
134
+ before(:each) { define_and_validate }
135
+
136
+ should_validate_length_of :size, :within => 3..5
137
+
138
+ should_not_validate_length_of :size, :within => 2..5
139
+ should_not_validate_length_of :size, :within => 4..5
140
+ should_not_validate_length_of :size, :within => 3..4
141
+ should_not_validate_length_of :size, :within => 3..6
142
+
143
+ should_validate_length_of :size do |m|
144
+ m.within = 3..5
145
+ end
146
+ end
147
+ end