remarkable_activerecord 3.0.1 → 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +46 -46
- data/LICENSE +1 -1
- data/README +64 -64
- data/lib/remarkable_activerecord.rb +1 -1
- data/lib/remarkable_activerecord/base.rb +40 -40
- data/lib/remarkable_activerecord/human_names.rb +24 -24
- data/lib/remarkable_activerecord/matchers/allow_mass_assignment_of_matcher.rb +14 -14
- data/lib/remarkable_activerecord/matchers/allow_values_for_matcher.rb +70 -70
- data/lib/remarkable_activerecord/matchers/association_matcher.rb +197 -197
- data/lib/remarkable_activerecord/matchers/have_column_matcher.rb +29 -29
- data/lib/remarkable_activerecord/matchers/have_index_matcher.rb +20 -20
- data/lib/remarkable_activerecord/matchers/have_readonly_attributes_matcher.rb +7 -7
- data/lib/remarkable_activerecord/matchers/have_scope_matcher.rb +34 -34
- data/lib/remarkable_activerecord/matchers/validate_acceptance_of_matcher.rb +37 -37
- data/lib/remarkable_activerecord/matchers/validate_associated_matcher.rb +75 -75
- data/lib/remarkable_activerecord/matchers/validate_confirmation_of_matcher.rb +44 -44
- data/lib/remarkable_activerecord/matchers/validate_exclusion_of_matcher.rb +17 -17
- data/lib/remarkable_activerecord/matchers/validate_inclusion_of_matcher.rb +20 -20
- data/lib/remarkable_activerecord/matchers/validate_numericality_of_matcher.rb +14 -14
- data/lib/remarkable_activerecord/matchers/validate_uniqueness_of_matcher.rb +80 -61
- data/locale/en.yml +253 -253
- data/spec/allow_mass_assignment_of_matcher_spec.rb +50 -50
- data/spec/allow_values_for_matcher_spec.rb +45 -45
- data/spec/association_matcher_spec.rb +612 -612
- data/spec/have_column_matcher_spec.rb +67 -67
- data/spec/have_index_matcher_spec.rb +61 -61
- data/spec/have_readonly_attributes_matcher_spec.rb +40 -40
- data/spec/have_scope_matcher_spec.rb +60 -60
- data/spec/model_builder.rb +101 -101
- data/spec/spec_helper.rb +25 -25
- data/spec/validate_acceptance_of_matcher_spec.rb +64 -64
- data/spec/validate_associated_matcher_spec.rb +118 -118
- data/spec/validate_confirmation_of_matcher_spec.rb +54 -54
- data/spec/validate_exclusion_of_matcher_spec.rb +76 -76
- data/spec/validate_inclusion_of_matcher_spec.rb +72 -72
- data/spec/validate_numericality_of_matcher_spec.rb +100 -100
- data/spec/validate_presence_of_matcher_spec.rb +40 -40
- data/spec/validate_uniqueness_of_matcher_spec.rb +158 -139
- metadata +3 -3
@@ -1,52 +1,52 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe 'validate_presence_of' do
|
3
|
+
describe 'validate_presence_of' do
|
4
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, :title => :string, :size => :string, :category => :string do
|
9
|
-
validates_presence_of :title, :size, options
|
10
|
-
end
|
11
|
-
|
12
|
-
validate_presence_of(:title, :size)
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'messages' do
|
16
|
-
before(:each){ @matcher = define_and_validate }
|
5
|
+
|
6
|
+
# Defines a model, create a validation and returns a raw matcher
|
7
|
+
def define_and_validate(options={})
|
8
|
+
@model = define_model :product, :title => :string, :size => :string, :category => :string do
|
9
|
+
validates_presence_of :title, :size, options
|
10
|
+
end
|
11
|
+
|
12
|
+
validate_presence_of(:title, :size)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'messages' do
|
16
|
+
before(:each){ @matcher = define_and_validate }
|
17
17
|
|
18
18
|
it 'should contain a description' do
|
19
19
|
@matcher.description.should == 'require title and size to be set'
|
20
20
|
end
|
21
21
|
|
22
|
-
it 'should set allow_nil? message' do
|
23
|
-
@matcher = validate_presence_of(:category)
|
22
|
+
it 'should set allow_nil? message' do
|
23
|
+
@matcher = validate_presence_of(:category)
|
24
24
|
@matcher.matches?(@model)
|
25
|
-
@matcher.failure_message.should == 'Expected Product to require category to be set'
|
25
|
+
@matcher.failure_message.should == 'Expected Product to require category to be set'
|
26
26
|
@matcher.negative_failure_message.should == 'Did not expect Product to require category to be set'
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe 'matchers' do
|
31
|
-
describe 'without options' do
|
32
|
-
before(:each){ define_and_validate }
|
33
|
-
|
34
|
-
it { should validate_presence_of(:size) }
|
35
|
-
it { should validate_presence_of(:title) }
|
36
|
-
it { should validate_presence_of(:title, :size) }
|
37
|
-
it { should_not validate_presence_of(:category) }
|
38
|
-
end
|
39
|
-
|
40
|
-
create_message_specs(self)
|
41
|
-
end
|
42
|
-
|
43
|
-
describe 'macros' do
|
44
|
-
before(:each){ define_and_validate }
|
45
|
-
|
46
|
-
should_validate_presence_of(:size)
|
47
|
-
should_validate_presence_of(:title)
|
48
|
-
should_validate_presence_of(:size, :title)
|
49
|
-
should_not_validate_presence_of(:category)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'matchers' do
|
31
|
+
describe 'without options' do
|
32
|
+
before(:each){ define_and_validate }
|
33
|
+
|
34
|
+
it { should validate_presence_of(:size) }
|
35
|
+
it { should validate_presence_of(:title) }
|
36
|
+
it { should validate_presence_of(:title, :size) }
|
37
|
+
it { should_not validate_presence_of(:category) }
|
38
|
+
end
|
39
|
+
|
40
|
+
create_message_specs(self)
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'macros' do
|
44
|
+
before(:each){ define_and_validate }
|
45
|
+
|
46
|
+
should_validate_presence_of(:size)
|
47
|
+
should_validate_presence_of(:title)
|
48
|
+
should_validate_presence_of(:size, :title)
|
49
|
+
should_not_validate_presence_of(:category)
|
50
50
|
end
|
51
51
|
end
|
52
|
-
|
52
|
+
|
@@ -1,150 +1,169 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe 'validate_uniqueness_of' do
|
3
|
+
describe 'validate_uniqueness_of' do
|
4
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 :user, :username => :string, :email => :integer, :access_code => :string do
|
9
|
-
validates_uniqueness_of :username, options
|
10
|
-
end
|
11
|
-
|
12
|
-
# Create a model
|
13
|
-
User.create(:username => 'jose')
|
14
|
-
|
15
|
-
validate_uniqueness_of(:username)
|
16
|
-
end
|
17
5
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
@matcher.description.should == 'require unique values for username
|
35
|
-
|
36
|
-
@matcher.
|
37
|
-
@matcher.description.should == 'require unique values for username scoped to [:email
|
38
|
-
|
39
|
-
@matcher.
|
40
|
-
@matcher.description.should == 'require unique values for username scoped to [:email, :access_code]
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
@matcher.
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
@matcher
|
50
|
-
|
51
|
-
@matcher.
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
@matcher.
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
@matcher
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
User.
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
6
|
+
# Defines a model, create a validation and returns a raw matcher
|
7
|
+
def define_and_validate(options={})
|
8
|
+
@model = define_model :user, :username => :string, :email => :integer, :access_code => :string do
|
9
|
+
validates_uniqueness_of :username, options
|
10
|
+
end
|
11
|
+
|
12
|
+
# Create a model
|
13
|
+
User.create(:username => 'jose')
|
14
|
+
|
15
|
+
validate_uniqueness_of(:username)
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'messages' do
|
19
|
+
before(:each){ @matcher = define_and_validate }
|
20
|
+
|
21
|
+
it 'should contain a description' do
|
22
|
+
@matcher.description.should == 'require unique values for username'
|
23
|
+
|
24
|
+
@matcher.scope(:email)
|
25
|
+
@matcher.description.should == 'require unique values for username scoped to [:email]'
|
26
|
+
|
27
|
+
@matcher.scope(:email, :access_code)
|
28
|
+
@matcher.description.should == 'require unique values for username scoped to [:email, :access_code]'
|
29
|
+
|
30
|
+
@matcher.case_sensitive
|
31
|
+
@matcher.description.should == 'require unique values for username scoped to [:email, :access_code] and case sensitive'
|
32
|
+
|
33
|
+
@matcher.case_sensitive(false)
|
34
|
+
@matcher.description.should == 'require unique values for username scoped to [:email, :access_code] and case insensitive'
|
35
|
+
|
36
|
+
@matcher.allow_nil
|
37
|
+
@matcher.description.should == 'require unique values for username scoped to [:email, :access_code], case insensitive, and allowing nil values'
|
38
|
+
|
39
|
+
@matcher.allow_blank(false)
|
40
|
+
@matcher.description.should == 'require unique values for username scoped to [:email, :access_code], case insensitive, allowing nil values, and not allowing blank values'
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should set responds_to_scope? message' do
|
44
|
+
@matcher.scope(:title).matches?(@model)
|
45
|
+
@matcher.failure_message.should == 'Expected User instance responds to title='
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should set is_unique? message' do
|
49
|
+
@matcher = validate_uniqueness_of(:email)
|
50
|
+
@matcher.matches?(@model)
|
51
|
+
@matcher.failure_message.should == 'Expected User to require unique values for email'
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should set case_sensitive? message' do
|
55
|
+
@matcher.case_sensitive(false).matches?(@model)
|
56
|
+
@matcher.failure_message.should == 'Expected User to not be case sensitive on username validation'
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should valid with new scope' do
|
60
|
+
@matcher.scope(:email).matches?(@model)
|
61
|
+
@matcher.failure_message.should == 'Expected User to be valid when username scope (email) change'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe 'matcher' do
|
66
|
+
|
67
|
+
describe 'without options' do
|
68
|
+
before(:each){ define_and_validate }
|
69
|
+
|
70
|
+
it { should validate_uniqueness_of(:username) }
|
71
|
+
it { should_not validate_uniqueness_of(:email) }
|
72
|
+
end
|
73
|
+
|
74
|
+
describe 'scoped to' do
|
75
|
+
it { should define_and_validate(:scope => :email).scope(:email) }
|
76
|
+
it { should define_and_validate(:scope => [:email, :access_code]).scope(:email, :access_code) }
|
77
|
+
it { should_not define_and_validate(:scope => :email).scope(:title) }
|
78
|
+
it { should_not define_and_validate(:scope => :email).scope(:access_code) }
|
79
|
+
end
|
80
|
+
|
81
|
+
create_message_specs(self)
|
82
|
+
|
83
|
+
# Those are macros to test optionals which accept only boolean values
|
84
|
+
create_optional_boolean_specs(:allow_nil, self)
|
85
|
+
create_optional_boolean_specs(:allow_blank, self)
|
86
|
+
create_optional_boolean_specs(:case_sensitive, self)
|
87
|
+
end
|
88
|
+
|
89
|
+
describe 'errors' do
|
90
|
+
it 'should raise an error if no object is found' do
|
91
|
+
@matcher = define_and_validate
|
92
|
+
User.destroy_all
|
93
|
+
|
94
|
+
proc { @matcher.matches?(@model) }.should raise_error(ScriptError)
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should raise an error if no object with not nil attribute is found' do
|
98
|
+
@matcher = define_and_validate.allow_nil
|
99
|
+
User.destroy_all
|
100
|
+
|
101
|
+
User.create(:username => nil)
|
102
|
+
proc { @matcher.matches?(@model) }.should raise_error(ScriptError)
|
103
|
+
|
104
|
+
User.create(:username => 'jose')
|
105
|
+
proc { @matcher.matches?(@model) }.should_not raise_error(ScriptError)
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should raise an error if no object with not nil attribute is found' do
|
109
|
+
@matcher = define_and_validate.allow_blank
|
110
|
+
User.destroy_all
|
111
|
+
|
112
|
+
User.create(:username => '')
|
113
|
+
proc { @matcher.matches?(@model) }.should raise_error(ScriptError)
|
114
|
+
|
115
|
+
User.create(:username => 'jose')
|
116
|
+
proc { @matcher.matches?(@model) }.should_not raise_error(ScriptError)
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'should raise an error if cannot find a new scope value' do
|
120
|
+
@matcher = define_and_validate(:scope => :email).scope(:email)
|
121
|
+
|
122
|
+
User.stub!(:find).and_return do |many, conditions|
|
123
|
+
if many == :all
|
124
|
+
1000.upto(1100).map{|i| User.new(:email => i) }
|
125
|
+
else
|
126
|
+
User.new(:username => 'jose')
|
127
|
+
end
|
128
|
+
end
|
129
|
+
proc { @matcher.matches?(@model) }.should raise_error(ScriptError)
|
130
|
+
|
131
|
+
User.stub!(:find).and_return do |many, conditions|
|
132
|
+
if many == :all
|
133
|
+
1000.upto(1099).map{|i| User.new(:email => i) }
|
134
|
+
else
|
135
|
+
User.new(:username => 'jose')
|
136
|
+
end
|
137
|
+
end
|
138
|
+
proc { @matcher.matches?(@model) }.should_not raise_error(ScriptError)
|
117
139
|
end
|
118
140
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
141
|
+
describe 'when null or blank values are not allowed' do
|
142
|
+
def define_and_validate(options={})
|
143
|
+
@model = define_model :user, :username => [:string, {:null => false}] do
|
144
|
+
validates_uniqueness_of :username, options
|
145
|
+
end
|
146
|
+
|
147
|
+
# Create a model
|
148
|
+
User.create(:username => Time.now)
|
149
|
+
validate_uniqueness_of(:username)
|
128
150
|
end
|
129
|
-
proc { @matcher.matches?(@model) }.should raise_error(ScriptError)
|
130
151
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
end
|
152
|
+
it { should define_and_validate }
|
153
|
+
it { should define_and_validate.allow_nil(false) }
|
154
|
+
|
155
|
+
it 'should raise an error if allow nil is true but we cannot save nil values in the database'do
|
156
|
+
proc { should define_and_validate.allow_nil }.should raise_error(ScriptError, /You declared that username accepts nil values in validate_uniqueness_of, but I cannot save nil values in the database, got/)
|
137
157
|
end
|
138
|
-
|
139
|
-
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
describe 'macros' do
|
162
|
+
before(:each){ define_and_validate(:scope => :email) }
|
163
|
+
|
164
|
+
should_validate_uniqueness_of :username
|
165
|
+
should_validate_uniqueness_of :username, :scope => :email
|
166
|
+
should_not_validate_uniqueness_of :email
|
167
|
+
should_not_validate_uniqueness_of :username, :scope => :access_code
|
140
168
|
end
|
141
|
-
|
142
|
-
describe 'macros' do
|
143
|
-
before(:each){ define_and_validate(:scope => :email) }
|
144
|
-
|
145
|
-
should_validate_uniqueness_of :username
|
146
|
-
should_validate_uniqueness_of :username, :scope => :email
|
147
|
-
should_not_validate_uniqueness_of :email
|
148
|
-
should_not_validate_uniqueness_of :username, :scope => :access_code
|
149
|
-
end
|
150
169
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remarkable_activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Brando
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2009-04-
|
14
|
+
date: 2009-04-13 00:00:00 +02:00
|
15
15
|
default_executable:
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
@@ -22,7 +22,7 @@ dependencies:
|
|
22
22
|
requirements:
|
23
23
|
- - ">="
|
24
24
|
- !ruby/object:Gem::Version
|
25
|
-
version: 3.0.
|
25
|
+
version: 3.0.2
|
26
26
|
version:
|
27
27
|
description: "Remarkable ActiveRecord: collection of matchers and macros with I18n for ActiveRecord"
|
28
28
|
email:
|