remarkable_activerecord 3.1.8 → 3.1.9
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/CHANGELOG +140 -138
- data/LICENSE +20 -20
- data/README +80 -80
- data/lib/remarkable_activerecord.rb +29 -29
- data/lib/remarkable_activerecord/base.rb +248 -237
- data/lib/remarkable_activerecord/describe.rb +27 -27
- data/lib/remarkable_activerecord/human_names.rb +36 -36
- data/lib/remarkable_activerecord/matchers/accept_nested_attributes_for_matcher.rb +30 -30
- data/lib/remarkable_activerecord/matchers/allow_mass_assignment_of_matcher.rb +59 -59
- data/lib/remarkable_activerecord/matchers/allow_values_for_matcher.rb +85 -94
- data/lib/remarkable_activerecord/matchers/association_matcher.rb +283 -283
- data/lib/remarkable_activerecord/matchers/have_column_matcher.rb +68 -68
- data/lib/remarkable_activerecord/matchers/have_default_scope_matcher.rb +38 -38
- data/lib/remarkable_activerecord/matchers/have_index_matcher.rb +73 -73
- data/lib/remarkable_activerecord/matchers/have_readonly_attributes_matcher.rb +30 -30
- data/lib/remarkable_activerecord/matchers/have_scope_matcher.rb +85 -85
- data/lib/remarkable_activerecord/matchers/validate_acceptance_of_matcher.rb +50 -50
- data/lib/remarkable_activerecord/matchers/validate_associated_matcher.rb +97 -97
- data/lib/remarkable_activerecord/matchers/validate_confirmation_of_matcher.rb +44 -44
- data/lib/remarkable_activerecord/matchers/validate_exclusion_of_matcher.rb +53 -53
- data/lib/remarkable_activerecord/matchers/validate_inclusion_of_matcher.rb +52 -52
- data/lib/remarkable_activerecord/matchers/validate_length_of_matcher.rb +150 -150
- data/lib/remarkable_activerecord/matchers/validate_numericality_of_matcher.rb +181 -181
- data/lib/remarkable_activerecord/matchers/validate_presence_of_matcher.rb +29 -29
- data/lib/remarkable_activerecord/matchers/validate_uniqueness_of_matcher.rb +233 -233
- data/locale/en.yml +261 -261
- data/spec/accept_nested_attributes_for_matcher_spec.rb +1 -1
- data/spec/allow_mass_assignment_of_matcher_spec.rb +90 -82
- data/spec/allow_values_for_matcher_spec.rb +72 -63
- data/spec/association_matcher_spec.rb +612 -612
- data/spec/describe_spec.rb +3 -3
- data/spec/have_column_matcher_spec.rb +73 -73
- data/spec/have_default_scope_matcher_spec.rb +1 -1
- data/spec/have_index_matcher_spec.rb +87 -87
- data/spec/have_readonly_attributes_matcher_spec.rb +47 -47
- data/spec/have_scope_matcher_spec.rb +77 -77
- data/spec/model_builder.rb +101 -101
- data/spec/rcov.opts +1 -1
- data/spec/spec.opts +4 -4
- data/spec/spec_helper.rb +27 -27
- data/spec/validate_acceptance_of_matcher_spec.rb +68 -68
- data/spec/validate_associated_matcher_spec.rb +121 -121
- data/spec/validate_confirmation_of_matcher_spec.rb +58 -58
- data/spec/validate_length_of_matcher_spec.rb +218 -218
- data/spec/validate_numericality_of_matcher_spec.rb +179 -179
- data/spec/validate_presence_of_matcher_spec.rb +56 -56
- data/spec/validate_uniqueness_of_matcher_spec.rb +164 -164
- metadata +5 -5
@@ -1,182 +1,182 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe 'validate_uniqueness_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 :user, :username => :string, :email => :string, :public => :boolean, :deleted_at => :timestamp do
|
9
|
-
validates_uniqueness_of :username, options
|
10
|
-
end
|
11
|
-
|
12
|
-
# Create a model
|
13
|
-
User.create(:username => 'jose', :deleted_at => 1.day.ago, :public => false)
|
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.case_sensitive
|
25
|
-
@matcher.description.should == 'require unique values for username case sensitive'
|
26
|
-
|
27
|
-
@matcher.case_sensitive(false)
|
28
|
-
@matcher.description.should == 'require unique values for username case insensitive'
|
29
|
-
|
30
|
-
@matcher.allow_nil
|
31
|
-
@matcher.description.should == 'require unique values for username case insensitive and allowing nil values'
|
32
|
-
|
33
|
-
@matcher.allow_blank(false)
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe 'validate_uniqueness_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 :user, :username => :string, :email => :string, :public => :boolean, :deleted_at => :timestamp do
|
9
|
+
validates_uniqueness_of :username, options
|
10
|
+
end
|
11
|
+
|
12
|
+
# Create a model
|
13
|
+
User.create(:username => 'jose', :deleted_at => 1.day.ago, :public => false)
|
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.case_sensitive
|
25
|
+
@matcher.description.should == 'require unique values for username case sensitive'
|
26
|
+
|
27
|
+
@matcher.case_sensitive(false)
|
28
|
+
@matcher.description.should == 'require unique values for username case insensitive'
|
29
|
+
|
30
|
+
@matcher.allow_nil
|
31
|
+
@matcher.description.should == 'require unique values for username case insensitive and allowing nil values'
|
32
|
+
|
33
|
+
@matcher.allow_blank(false)
|
34
34
|
@matcher.description.should == 'require unique values for username case insensitive, allowing nil values, and not allowing blank values'
|
35
35
|
|
36
36
|
@matcher = validate_uniqueness_of(:username, :scope => :email)
|
37
|
-
@matcher.description.should == 'require unique values for username scoped to :email'
|
37
|
+
@matcher.description.should == 'require unique values for username scoped to :email'
|
38
38
|
|
39
39
|
@matcher = validate_uniqueness_of(:username)
|
40
|
-
@matcher.scope(:email)
|
41
|
-
@matcher.scope(:public)
|
42
|
-
@matcher.description.should == 'require unique values for username scoped to :email and :public'
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'should set responds_to_scope? message' do
|
46
|
-
@matcher.scope(:title).matches?(@model)
|
47
|
-
@matcher.failure_message.should == 'Expected User instance responds to title='
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'should set is_unique? message' do
|
51
|
-
@matcher = validate_uniqueness_of(:email)
|
52
|
-
@matcher.matches?(@model)
|
53
|
-
@matcher.failure_message.should == 'Expected User to require unique values for email'
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'should set case_sensitive? message' do
|
57
|
-
@matcher.case_sensitive(false).matches?(@model)
|
58
|
-
@matcher.failure_message.should == 'Expected User to not be case sensitive on username validation'
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'should valid with new scope' do
|
62
|
-
@matcher.scope(:email).matches?(@model)
|
63
|
-
@matcher.failure_message.should == 'Expected User to be valid when username scope (email) change'
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe 'matcher' do
|
68
|
-
|
69
|
-
describe 'without options' do
|
70
|
-
before(:each){ define_and_validate }
|
71
|
-
|
72
|
-
it { should validate_uniqueness_of(:username) }
|
73
|
-
it { should_not validate_uniqueness_of(:email) }
|
74
|
-
end
|
75
|
-
|
76
|
-
describe 'scoped to' do
|
40
|
+
@matcher.scope(:email)
|
41
|
+
@matcher.scope(:public)
|
42
|
+
@matcher.description.should == 'require unique values for username scoped to :email and :public'
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should set responds_to_scope? message' do
|
46
|
+
@matcher.scope(:title).matches?(@model)
|
47
|
+
@matcher.failure_message.should == 'Expected User instance responds to title='
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should set is_unique? message' do
|
51
|
+
@matcher = validate_uniqueness_of(:email)
|
52
|
+
@matcher.matches?(@model)
|
53
|
+
@matcher.failure_message.should == 'Expected User to require unique values for email'
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should set case_sensitive? message' do
|
57
|
+
@matcher.case_sensitive(false).matches?(@model)
|
58
|
+
@matcher.failure_message.should == 'Expected User to not be case sensitive on username validation'
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should valid with new scope' do
|
62
|
+
@matcher.scope(:email).matches?(@model)
|
63
|
+
@matcher.failure_message.should == 'Expected User to be valid when username scope (email) change'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'matcher' do
|
68
|
+
|
69
|
+
describe 'without options' do
|
70
|
+
before(:each){ define_and_validate }
|
71
|
+
|
72
|
+
it { should validate_uniqueness_of(:username) }
|
73
|
+
it { should_not validate_uniqueness_of(:email) }
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'scoped to' do
|
77
77
|
it { should define_and_validate(:scope => :email).scope(:email) }
|
78
78
|
it { should define_and_validate(:scope => :public).scope(:public) }
|
79
|
-
it { should define_and_validate(:scope => :deleted_at).scope(:deleted_at) }
|
79
|
+
it { should define_and_validate(:scope => :deleted_at).scope(:deleted_at) }
|
80
80
|
it { should define_and_validate(:scope => [:email, :public]).scope(:email, :public) }
|
81
81
|
it { should define_and_validate(:scope => [:email, :public, :deleted_at]).scope(:email, :public, :deleted_at) }
|
82
|
-
it { should_not define_and_validate(:scope => :email).scope(:title) }
|
83
|
-
it { should_not define_and_validate(:scope => :email).scope(:public) }
|
84
|
-
end
|
85
|
-
|
86
|
-
create_message_specs(self)
|
87
|
-
|
88
|
-
# Those are macros to test optionals which accept only boolean values
|
89
|
-
create_optional_boolean_specs(:allow_nil, self)
|
90
|
-
create_optional_boolean_specs(:allow_blank, self)
|
91
|
-
create_optional_boolean_specs(:case_sensitive, self)
|
92
|
-
end
|
93
|
-
|
94
|
-
describe 'errors' do
|
95
|
-
it 'should raise an error if no object is found' do
|
96
|
-
@matcher = define_and_validate
|
97
|
-
User.destroy_all
|
98
|
-
|
99
|
-
proc { @matcher.matches?(@model) }.should raise_error(ScriptError)
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'should raise an error if no object with not nil attribute is found' do
|
103
|
-
@matcher = define_and_validate.allow_nil
|
104
|
-
User.destroy_all
|
105
|
-
|
106
|
-
User.create(:username => nil)
|
107
|
-
proc { @matcher.matches?(@model) }.should raise_error(ScriptError)
|
108
|
-
|
109
|
-
User.create(:username => 'jose')
|
110
|
-
proc { @matcher.matches?(@model) }.should_not raise_error(ScriptError)
|
111
|
-
end
|
112
|
-
|
113
|
-
it 'should raise an error if no object with not blank attribute is found' do
|
114
|
-
@matcher = define_and_validate.allow_blank
|
115
|
-
User.destroy_all
|
116
|
-
|
117
|
-
User.create(:username => '')
|
118
|
-
proc { @matcher.matches?(@model) }.should raise_error(ScriptError)
|
119
|
-
|
120
|
-
User.create(:username => 'jose')
|
121
|
-
proc { @matcher.matches?(@model) }.should_not raise_error(ScriptError)
|
82
|
+
it { should_not define_and_validate(:scope => :email).scope(:title) }
|
83
|
+
it { should_not define_and_validate(:scope => :email).scope(:public) }
|
84
|
+
end
|
85
|
+
|
86
|
+
create_message_specs(self)
|
87
|
+
|
88
|
+
# Those are macros to test optionals which accept only boolean values
|
89
|
+
create_optional_boolean_specs(:allow_nil, self)
|
90
|
+
create_optional_boolean_specs(:allow_blank, self)
|
91
|
+
create_optional_boolean_specs(:case_sensitive, self)
|
92
|
+
end
|
93
|
+
|
94
|
+
describe 'errors' do
|
95
|
+
it 'should raise an error if no object is found' do
|
96
|
+
@matcher = define_and_validate
|
97
|
+
User.destroy_all
|
98
|
+
|
99
|
+
proc { @matcher.matches?(@model) }.should raise_error(ScriptError)
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should raise an error if no object with not nil attribute is found' do
|
103
|
+
@matcher = define_and_validate.allow_nil
|
104
|
+
User.destroy_all
|
105
|
+
|
106
|
+
User.create(:username => nil)
|
107
|
+
proc { @matcher.matches?(@model) }.should raise_error(ScriptError)
|
108
|
+
|
109
|
+
User.create(:username => 'jose')
|
110
|
+
proc { @matcher.matches?(@model) }.should_not raise_error(ScriptError)
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'should raise an error if no object with not blank attribute is found' do
|
114
|
+
@matcher = define_and_validate.allow_blank
|
115
|
+
User.destroy_all
|
116
|
+
|
117
|
+
User.create(:username => '')
|
118
|
+
proc { @matcher.matches?(@model) }.should raise_error(ScriptError)
|
119
|
+
|
120
|
+
User.create(:username => 'jose')
|
121
|
+
proc { @matcher.matches?(@model) }.should_not raise_error(ScriptError)
|
122
122
|
end
|
123
123
|
|
124
124
|
it 'should raise an error if @existing record is the same as @subject' do
|
125
125
|
@matcher = define_and_validate
|
126
126
|
proc { @matcher.matches?(User.first) }.should raise_error(ScriptError, /which is different from the subject record/)
|
127
|
-
end
|
128
|
-
|
129
|
-
it 'should raise an error if cannot find a new scope value' do
|
130
|
-
@matcher = define_and_validate(:scope => :email).scope(:email)
|
131
|
-
|
132
|
-
User.stub!(:find).and_return do |many, conditions|
|
133
|
-
if many == :all
|
134
|
-
1000.upto(1100).map{|i| User.new(:email => i) }
|
135
|
-
else
|
136
|
-
User.new(:username => 'jose')
|
137
|
-
end
|
138
|
-
end
|
139
|
-
lambda { @matcher.matches?(@model) }.should raise_error(ScriptError)
|
140
|
-
|
141
|
-
User.stub!(:find).and_return do |many, conditions|
|
142
|
-
if many == :all
|
143
|
-
1000.upto(1099).map{|i| User.new(:email => i) }
|
144
|
-
else
|
145
|
-
User.new(:username => 'jose')
|
146
|
-
end
|
147
|
-
end
|
148
|
-
lambda { @matcher.matches?(@model) }.should_not raise_error(ScriptError)
|
149
|
-
end
|
150
|
-
|
151
|
-
describe 'when null or blank values are not allowed' do
|
152
|
-
def define_and_validate(options={})
|
153
|
-
@model = define_model :user, :username => [:string, {:null => false}] do
|
154
|
-
validates_uniqueness_of :username, options
|
155
|
-
end
|
156
|
-
|
157
|
-
User.create(:username => 'jose')
|
158
|
-
validate_uniqueness_of(:username)
|
159
|
-
end
|
160
|
-
|
161
|
-
it { should define_and_validate }
|
162
|
-
it { should define_and_validate(:allow_nil => false).allow_nil(false) }
|
163
|
-
|
164
|
-
it 'should raise an error if allow nil is true but we cannot save nil values in the database'do
|
165
|
-
lambda { 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/)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
describe 'macros' do
|
171
|
-
before(:each){ define_and_validate(:scope => :email) }
|
172
|
-
|
173
|
-
should_validate_uniqueness_of :username
|
174
|
-
should_validate_uniqueness_of :username, :scope => :email
|
175
|
-
should_not_validate_uniqueness_of :email
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'should raise an error if cannot find a new scope value' do
|
130
|
+
@matcher = define_and_validate(:scope => :email).scope(:email)
|
131
|
+
|
132
|
+
User.stub!(:find).and_return do |many, conditions|
|
133
|
+
if many == :all
|
134
|
+
1000.upto(1100).map{|i| User.new(:email => i) }
|
135
|
+
else
|
136
|
+
User.new(:username => 'jose')
|
137
|
+
end
|
138
|
+
end
|
139
|
+
lambda { @matcher.matches?(@model) }.should raise_error(ScriptError)
|
140
|
+
|
141
|
+
User.stub!(:find).and_return do |many, conditions|
|
142
|
+
if many == :all
|
143
|
+
1000.upto(1099).map{|i| User.new(:email => i) }
|
144
|
+
else
|
145
|
+
User.new(:username => 'jose')
|
146
|
+
end
|
147
|
+
end
|
148
|
+
lambda { @matcher.matches?(@model) }.should_not raise_error(ScriptError)
|
149
|
+
end
|
150
|
+
|
151
|
+
describe 'when null or blank values are not allowed' do
|
152
|
+
def define_and_validate(options={})
|
153
|
+
@model = define_model :user, :username => [:string, {:null => false}] do
|
154
|
+
validates_uniqueness_of :username, options
|
155
|
+
end
|
156
|
+
|
157
|
+
User.create(:username => 'jose')
|
158
|
+
validate_uniqueness_of(:username)
|
159
|
+
end
|
160
|
+
|
161
|
+
it { should define_and_validate }
|
162
|
+
it { should define_and_validate(:allow_nil => false).allow_nil(false) }
|
163
|
+
|
164
|
+
it 'should raise an error if allow nil is true but we cannot save nil values in the database'do
|
165
|
+
lambda { 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/)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
describe 'macros' do
|
171
|
+
before(:each){ define_and_validate(:scope => :email) }
|
172
|
+
|
173
|
+
should_validate_uniqueness_of :username
|
174
|
+
should_validate_uniqueness_of :username, :scope => :email
|
175
|
+
should_not_validate_uniqueness_of :email
|
176
176
|
should_not_validate_uniqueness_of :username, :scope => :access_code
|
177
177
|
|
178
178
|
should_validate_uniqueness_of :username do |m|
|
179
179
|
m.scope :email
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
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.1.
|
4
|
+
version: 3.1.9
|
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-
|
14
|
+
date: 2009-08-30 00:00:00 +02:00
|
15
15
|
default_executable:
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
@@ -30,9 +30,9 @@ dependencies:
|
|
30
30
|
version_requirement:
|
31
31
|
version_requirements: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
|
-
- -
|
33
|
+
- - ~>
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: 3.1.
|
35
|
+
version: 3.1.9
|
36
36
|
version:
|
37
37
|
description: "Remarkable ActiveRecord: collection of matchers and macros with I18n for ActiveRecord"
|
38
38
|
email:
|
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
98
|
requirements: []
|
99
99
|
|
100
100
|
rubyforge_project: remarkable
|
101
|
-
rubygems_version: 1.3.
|
101
|
+
rubygems_version: 1.3.5
|
102
102
|
signing_key:
|
103
103
|
specification_version: 3
|
104
104
|
summary: "Remarkable ActiveRecord: collection of matchers and macros with I18n for ActiveRecord"
|