remarkable_activerecord 3.1.9 → 3.1.10
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/lib/remarkable_activerecord/base.rb +5 -1
- data/lib/remarkable_activerecord/describe.rb +1 -2
- metadata +20 -42
- data/spec/accept_nested_attributes_for_matcher_spec.rb +0 -130
- data/spec/allow_mass_assignment_of_matcher_spec.rb +0 -106
- data/spec/allow_values_for_matcher_spec.rb +0 -80
- data/spec/association_matcher_spec.rb +0 -671
- data/spec/describe_spec.rb +0 -102
- data/spec/have_column_matcher_spec.rb +0 -78
- data/spec/have_default_scope_matcher_spec.rb +0 -52
- data/spec/have_index_matcher_spec.rb +0 -87
- data/spec/have_readonly_attributes_matcher_spec.rb +0 -47
- data/spec/have_scope_matcher_spec.rb +0 -85
- data/spec/model_builder.rb +0 -101
- data/spec/rcov.opts +0 -2
- data/spec/spec.opts +0 -4
- data/spec/spec_helper.rb +0 -27
- data/spec/validate_acceptance_of_matcher_spec.rb +0 -68
- data/spec/validate_associated_matcher_spec.rb +0 -126
- data/spec/validate_confirmation_of_matcher_spec.rb +0 -58
- data/spec/validate_exclusion_of_matcher_spec.rb +0 -87
- data/spec/validate_inclusion_of_matcher_spec.rb +0 -87
- data/spec/validate_length_of_matcher_spec.rb +0 -218
- data/spec/validate_numericality_of_matcher_spec.rb +0 -186
- data/spec/validate_presence_of_matcher_spec.rb +0 -84
- data/spec/validate_uniqueness_of_matcher_spec.rb +0 -182
@@ -1,84 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe 'validate_presence_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 :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
|
-
|
18
|
-
it 'should contain a description' do
|
19
|
-
@matcher.description.should == 'require title and size to be set'
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should set allow_nil? message' do
|
23
|
-
@matcher = validate_presence_of(:category)
|
24
|
-
@matcher.matches?(@model)
|
25
|
-
@matcher.failure_message.should == 'Expected Product to require category to be set'
|
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
|
-
|
42
|
-
describe 'with belongs to' do
|
43
|
-
def define_and_validate(validation)
|
44
|
-
define_model :category
|
45
|
-
|
46
|
-
define_model :product, :category_id => :integer do
|
47
|
-
belongs_to :category
|
48
|
-
validates_presence_of :category if validation
|
49
|
-
end
|
50
|
-
|
51
|
-
validate_presence_of(:category)
|
52
|
-
end
|
53
|
-
|
54
|
-
it { should define_and_validate(true) }
|
55
|
-
it { should_not define_and_validate(false) }
|
56
|
-
end
|
57
|
-
|
58
|
-
describe 'with has many' do
|
59
|
-
def define_and_validate(validation)
|
60
|
-
define_model :stocks, :product_id => :integer
|
61
|
-
|
62
|
-
define_model :product do
|
63
|
-
has_many :stocks
|
64
|
-
validates_presence_of :stocks if validation
|
65
|
-
end
|
66
|
-
|
67
|
-
validate_presence_of :stocks
|
68
|
-
end
|
69
|
-
|
70
|
-
it { should define_and_validate(true) }
|
71
|
-
it { should_not define_and_validate(false) }
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe 'macros' do
|
76
|
-
before(:each){ define_and_validate }
|
77
|
-
|
78
|
-
should_validate_presence_of(:size)
|
79
|
-
should_validate_presence_of(:title)
|
80
|
-
should_validate_presence_of(:size, :title)
|
81
|
-
should_not_validate_presence_of(:category)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
@@ -1,182 +0,0 @@
|
|
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
|
-
@matcher.description.should == 'require unique values for username case insensitive, allowing nil values, and not allowing blank values'
|
35
|
-
|
36
|
-
@matcher = validate_uniqueness_of(:username, :scope => :email)
|
37
|
-
@matcher.description.should == 'require unique values for username scoped to :email'
|
38
|
-
|
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
|
77
|
-
it { should define_and_validate(:scope => :email).scope(:email) }
|
78
|
-
it { should define_and_validate(:scope => :public).scope(:public) }
|
79
|
-
it { should define_and_validate(:scope => :deleted_at).scope(:deleted_at) }
|
80
|
-
it { should define_and_validate(:scope => [:email, :public]).scope(:email, :public) }
|
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)
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'should raise an error if @existing record is the same as @subject' do
|
125
|
-
@matcher = define_and_validate
|
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
|
176
|
-
should_not_validate_uniqueness_of :username, :scope => :access_code
|
177
|
-
|
178
|
-
should_validate_uniqueness_of :username do |m|
|
179
|
-
m.scope :email
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|