remarkable_activerecord 3.1.9 → 3.1.10
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -181,7 +181,11 @@ module Remarkable
|
|
181
181
|
def error_message_from_model(model, attribute, message) #:nodoc:
|
182
182
|
if message.is_a? Symbol
|
183
183
|
message = if RAILS_I18N # Rails >= 2.2
|
184
|
-
|
184
|
+
if ::ActiveRecord.const_defined?(:Error)
|
185
|
+
::ActiveRecord::Error.new(model, attribute, message, :count => '12345').to_s
|
186
|
+
else
|
187
|
+
model.errors.generate_message(attribute, message, :count => '12345')
|
188
|
+
end
|
185
189
|
else # Rails <= 2.1
|
186
190
|
::ActiveRecord::Errors.default_error_messages[message] % '12345'
|
187
191
|
end
|
@@ -108,7 +108,6 @@ module Remarkable
|
|
108
108
|
def describe(*args, &block)
|
109
109
|
if described_class && args.first.is_a?(Hash)
|
110
110
|
attributes = args.shift
|
111
|
-
|
112
111
|
connector = Remarkable.t "remarkable.active_record.describe.connector", :default => " and "
|
113
112
|
|
114
113
|
description = if self.describe_subject_attributes.blank?
|
@@ -130,7 +129,7 @@ module Remarkable
|
|
130
129
|
:key => translated_key.downcase, :value => value.inspect)
|
131
130
|
end
|
132
131
|
|
133
|
-
description
|
132
|
+
description += pieces.join(connector)
|
134
133
|
args.unshift(description)
|
135
134
|
|
136
135
|
# Creates an example group, set the subject and eval the given block.
|
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.10
|
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-10-01 00:00:00 -03:00
|
15
15
|
default_executable:
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
requirements:
|
33
33
|
- - ~>
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: 3.1.
|
35
|
+
version: 3.1.10
|
36
36
|
version:
|
37
37
|
description: "Remarkable ActiveRecord: collection of matchers and macros with I18n for ActiveRecord"
|
38
38
|
email:
|
@@ -52,26 +52,26 @@ files:
|
|
52
52
|
- LICENSE
|
53
53
|
- CHANGELOG
|
54
54
|
- lib/remarkable_activerecord/base.rb
|
55
|
-
- lib/remarkable_activerecord/human_names.rb
|
56
55
|
- lib/remarkable_activerecord/describe.rb
|
57
|
-
- lib/remarkable_activerecord/
|
58
|
-
- lib/remarkable_activerecord/matchers/validate_length_of_matcher.rb
|
59
|
-
- lib/remarkable_activerecord/matchers/have_default_scope_matcher.rb
|
60
|
-
- lib/remarkable_activerecord/matchers/have_readonly_attributes_matcher.rb
|
56
|
+
- lib/remarkable_activerecord/human_names.rb
|
61
57
|
- lib/remarkable_activerecord/matchers/accept_nested_attributes_for_matcher.rb
|
62
|
-
- lib/remarkable_activerecord/matchers/
|
63
|
-
- lib/remarkable_activerecord/matchers/validate_associated_matcher.rb
|
64
|
-
- lib/remarkable_activerecord/matchers/have_column_matcher.rb
|
65
|
-
- lib/remarkable_activerecord/matchers/association_matcher.rb
|
66
|
-
- lib/remarkable_activerecord/matchers/validate_presence_of_matcher.rb
|
67
|
-
- lib/remarkable_activerecord/matchers/have_scope_matcher.rb
|
58
|
+
- lib/remarkable_activerecord/matchers/allow_mass_assignment_of_matcher.rb
|
68
59
|
- lib/remarkable_activerecord/matchers/allow_values_for_matcher.rb
|
60
|
+
- lib/remarkable_activerecord/matchers/association_matcher.rb
|
61
|
+
- lib/remarkable_activerecord/matchers/have_column_matcher.rb
|
62
|
+
- lib/remarkable_activerecord/matchers/have_default_scope_matcher.rb
|
69
63
|
- lib/remarkable_activerecord/matchers/have_index_matcher.rb
|
70
|
-
- lib/remarkable_activerecord/matchers/
|
64
|
+
- lib/remarkable_activerecord/matchers/have_readonly_attributes_matcher.rb
|
65
|
+
- lib/remarkable_activerecord/matchers/have_scope_matcher.rb
|
71
66
|
- lib/remarkable_activerecord/matchers/validate_acceptance_of_matcher.rb
|
72
|
-
- lib/remarkable_activerecord/matchers/
|
67
|
+
- lib/remarkable_activerecord/matchers/validate_associated_matcher.rb
|
68
|
+
- lib/remarkable_activerecord/matchers/validate_confirmation_of_matcher.rb
|
69
|
+
- lib/remarkable_activerecord/matchers/validate_exclusion_of_matcher.rb
|
70
|
+
- lib/remarkable_activerecord/matchers/validate_inclusion_of_matcher.rb
|
71
|
+
- lib/remarkable_activerecord/matchers/validate_length_of_matcher.rb
|
73
72
|
- lib/remarkable_activerecord/matchers/validate_numericality_of_matcher.rb
|
74
|
-
- lib/remarkable_activerecord/matchers/
|
73
|
+
- lib/remarkable_activerecord/matchers/validate_presence_of_matcher.rb
|
74
|
+
- lib/remarkable_activerecord/matchers/validate_uniqueness_of_matcher.rb
|
75
75
|
- lib/remarkable_activerecord.rb
|
76
76
|
- locale/en.yml
|
77
77
|
has_rdoc: true
|
@@ -98,31 +98,9 @@ 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.4
|
102
102
|
signing_key:
|
103
103
|
specification_version: 3
|
104
104
|
summary: "Remarkable ActiveRecord: collection of matchers and macros with I18n for ActiveRecord"
|
105
|
-
test_files:
|
106
|
-
|
107
|
-
- spec/validate_length_of_matcher_spec.rb
|
108
|
-
- spec/rcov.opts
|
109
|
-
- spec/spec_helper.rb
|
110
|
-
- spec/validate_acceptance_of_matcher_spec.rb
|
111
|
-
- spec/accept_nested_attributes_for_matcher_spec.rb
|
112
|
-
- spec/describe_spec.rb
|
113
|
-
- spec/allow_mass_assignment_of_matcher_spec.rb
|
114
|
-
- spec/have_scope_matcher_spec.rb
|
115
|
-
- spec/validate_inclusion_of_matcher_spec.rb
|
116
|
-
- spec/spec.opts
|
117
|
-
- spec/have_readonly_attributes_matcher_spec.rb
|
118
|
-
- spec/validate_confirmation_of_matcher_spec.rb
|
119
|
-
- spec/allow_values_for_matcher_spec.rb
|
120
|
-
- spec/validate_uniqueness_of_matcher_spec.rb
|
121
|
-
- spec/have_column_matcher_spec.rb
|
122
|
-
- spec/have_default_scope_matcher_spec.rb
|
123
|
-
- spec/have_index_matcher_spec.rb
|
124
|
-
- spec/association_matcher_spec.rb
|
125
|
-
- spec/validate_exclusion_of_matcher_spec.rb
|
126
|
-
- spec/model_builder.rb
|
127
|
-
- spec/validate_numericality_of_matcher_spec.rb
|
128
|
-
- spec/validate_presence_of_matcher_spec.rb
|
105
|
+
test_files: []
|
106
|
+
|
@@ -1,130 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
if RAILS_VERSION == '2.3.3'
|
4
|
-
describe 'accept_nested_attributes_for' do
|
5
|
-
include ModelBuilder
|
6
|
-
|
7
|
-
def define_and_validate(default=:category, options={})
|
8
|
-
@model = define_model :product do
|
9
|
-
has_one :category
|
10
|
-
has_many :orders
|
11
|
-
has_many :labels
|
12
|
-
has_many :tags, :autosave => true
|
13
|
-
|
14
|
-
accepts_nested_attributes_for :category, options
|
15
|
-
accepts_nested_attributes_for :orders, options
|
16
|
-
end
|
17
|
-
|
18
|
-
accept_nested_attributes_for *default
|
19
|
-
end
|
20
|
-
|
21
|
-
describe 'messages' do
|
22
|
-
|
23
|
-
it 'should contain a description' do
|
24
|
-
matcher = define_and_validate
|
25
|
-
matcher.description.should == 'accept nested attributes for category'
|
26
|
-
|
27
|
-
matcher.allow_destroy
|
28
|
-
matcher.description.should == 'accept nested attributes for category allowing destroy'
|
29
|
-
|
30
|
-
matcher.accept(:name => 'jose')
|
31
|
-
matcher.accept(:name => 'maria')
|
32
|
-
matcher.description.should == 'accept nested attributes for category allowing destroy and accepting {:name=>"jose"} and {:name=>"maria"}'
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'should set association_match? message' do
|
36
|
-
matcher = define_and_validate(:nothing)
|
37
|
-
matcher.matches?(@model)
|
38
|
-
matcher.failure_message.should == 'Expected Product to have association nothing, but does not'
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'should set is_autosave? message' do
|
42
|
-
matcher = define_and_validate(:labels)
|
43
|
-
matcher.matches?(@model)
|
44
|
-
matcher.failure_message.should == 'Expected Product to have association labels with autosave true, got false'
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'should set responds_to_attributes? message' do
|
48
|
-
matcher = define_and_validate(:tags)
|
49
|
-
matcher.matches?(@model)
|
50
|
-
matcher.failure_message.should == 'Expected Product to respond to :tags_attributes=, but does not'
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'should set allows_destroy? message' do
|
54
|
-
matcher = define_and_validate(:category, :allow_destroy => false)
|
55
|
-
matcher.allow_destroy.matches?(@model)
|
56
|
-
matcher.failure_message.should == 'Expected Product with allow destroy equals to true, got false'
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'should set accepts? message' do
|
60
|
-
matcher = define_and_validate(:category, :reject_if => proc{|a| true })
|
61
|
-
matcher.accept({}).matches?(@model)
|
62
|
-
matcher.failure_message.should == 'Expected Product to accept attributes {} for category, but does not'
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'should set rejects? message' do
|
66
|
-
matcher = define_and_validate(:category, :reject_if => proc{|a| false })
|
67
|
-
matcher.reject({}).matches?(@model)
|
68
|
-
matcher.failure_message.should == 'Expected Product to reject attributes {} for category, but does not'
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
describe 'matchers' do
|
74
|
-
it { should define_and_validate(:category) }
|
75
|
-
it { should define_and_validate(:orders) }
|
76
|
-
|
77
|
-
it { should_not define_and_validate(:nothing) }
|
78
|
-
it { should_not define_and_validate(:labels) }
|
79
|
-
it { should_not define_and_validate(:tags) }
|
80
|
-
|
81
|
-
describe 'with allow destroy as option' do
|
82
|
-
it { should define_and_validate(:category, :allow_destroy => true).allow_destroy }
|
83
|
-
it { should define_and_validate(:category, :allow_destroy => false).allow_destroy(false) }
|
84
|
-
it { should_not define_and_validate(:category, :allow_destroy => false).allow_destroy }
|
85
|
-
it { should_not define_and_validate(:category, :allow_destroy => true).allow_destroy(false) }
|
86
|
-
|
87
|
-
it { should define_and_validate(:orders, :allow_destroy => true).allow_destroy }
|
88
|
-
it { should define_and_validate(:orders, :allow_destroy => false).allow_destroy(false) }
|
89
|
-
it { should_not define_and_validate(:orders, :allow_destroy => false).allow_destroy }
|
90
|
-
it { should_not define_and_validate(:orders, :allow_destroy => true).allow_destroy(false) }
|
91
|
-
end
|
92
|
-
|
93
|
-
describe 'with accept as option' do
|
94
|
-
it { should define_and_validate(:category, :reject_if => proc{ |a| a[:name].blank? }).accept({ :name => 'Jose' }) }
|
95
|
-
it { should define_and_validate(:category, :reject_if => proc{ |a| a[:name].blank? }).accept({ :name => 'Jose' }, { :name => 'Maria' }) }
|
96
|
-
it { should_not define_and_validate(:category, :reject_if => proc{ |a| a[:name].blank? }).accept({ :name => '' }) }
|
97
|
-
end
|
98
|
-
|
99
|
-
describe 'with reject as option' do
|
100
|
-
it { should define_and_validate(:category, :reject_if => proc{ |a| !a[:name].blank? }).reject({ :name => 'Jose' }) }
|
101
|
-
it { should define_and_validate(:category, :reject_if => proc{ |a| !a[:name].blank? }).reject({ :name => 'Jose' }, { :name => 'Maria' }) }
|
102
|
-
it { should_not define_and_validate(:category, :reject_if => proc{ |a| !a[:name].blank? }).reject({ :name => '' }) }
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
describe 'macros' do
|
107
|
-
before(:each){ define_and_validate(:category, :allow_destroy => true, :reject_if => proc{ |a| a[:name].blank? }) }
|
108
|
-
|
109
|
-
should_accept_nested_attributes_for :category
|
110
|
-
should_accept_nested_attributes_for :category, :allow_destroy => true
|
111
|
-
should_accept_nested_attributes_for :category, :accept => { :name => 'Jose' }
|
112
|
-
should_accept_nested_attributes_for :category, :accept => [ { :name => 'Jose' }, { :name => 'Maria' } ]
|
113
|
-
should_accept_nested_attributes_for :category, :reject => [ { :name => '' } ]
|
114
|
-
|
115
|
-
should_accept_nested_attributes_for :category do |m|
|
116
|
-
m.allow_destroy
|
117
|
-
m.accept :name => "Jose"
|
118
|
-
m.accept :name => "Maria"
|
119
|
-
m.reject :name => ""
|
120
|
-
end
|
121
|
-
|
122
|
-
should_not_accept_nested_attributes_for :nothing
|
123
|
-
should_not_accept_nested_attributes_for :labels
|
124
|
-
should_not_accept_nested_attributes_for :tags
|
125
|
-
should_not_accept_nested_attributes_for :category, :allow_destroy => false
|
126
|
-
should_not_accept_nested_attributes_for :category, :accept => [ { :name => '' } ]
|
127
|
-
should_not_accept_nested_attributes_for :category, :reject => [ { :name => 'Jose' }, { :name => 'Maria' } ]
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
@@ -1,106 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe 'allow_mass_assignment_of' do
|
4
|
-
include ModelBuilder
|
5
|
-
|
6
|
-
def define_and_validate(options={})
|
7
|
-
@model = define_model :product, :title => :string, :category => :string do
|
8
|
-
attr_protected :title, :category if options[:protected]
|
9
|
-
|
10
|
-
attr_accessible :title, :category if options[:accessible] == true
|
11
|
-
attr_accessible *options[:accessible] if options[:accessible].is_a?(Array)
|
12
|
-
end
|
13
|
-
|
14
|
-
allow_mass_assignment_of(:title, :category)
|
15
|
-
end
|
16
|
-
|
17
|
-
describe 'messages' do
|
18
|
-
|
19
|
-
it 'should contain a description' do
|
20
|
-
@matcher = allow_mass_assignment_of(:title, :category)
|
21
|
-
@matcher.description.should == 'allow mass assignment of title and category'
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'should set allows? message' do
|
25
|
-
define_and_validate(:protected => true)
|
26
|
-
@matcher = allow_mass_assignment_of
|
27
|
-
@matcher.matches?(@model)
|
28
|
-
@matcher.failure_message.should == 'Expected Product to allow mass assignment (Product is protecting category and title)'
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'should set is_protected? message' do
|
32
|
-
@matcher = define_and_validate(:protected => true)
|
33
|
-
@matcher.matches?(@model)
|
34
|
-
@matcher.failure_message.should == 'Expected Product to allow mass assignment of title (Product is protecting title)'
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'should set is_accessible? message' do
|
38
|
-
@matcher = define_and_validate(:accessible => [:another])
|
39
|
-
@matcher.matches?(@model)
|
40
|
-
@matcher.failure_message.should == 'Expected Product to allow mass assignment of title (Product has not made title accessible)'
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
describe 'matchers' do
|
46
|
-
it { should define_and_validate }
|
47
|
-
it { should define_and_validate(:accessible => true) }
|
48
|
-
|
49
|
-
it { should_not define_and_validate(:protected => true) }
|
50
|
-
it { should_not define_and_validate(:accessible => [:another]) }
|
51
|
-
|
52
|
-
describe 'with no argument' do
|
53
|
-
it 'should allow mass assignment if no attribute is accessible or protected' do
|
54
|
-
define_and_validate
|
55
|
-
should allow_mass_assignment_of
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'should allow mass assignment if attributes are accessible' do
|
59
|
-
define_and_validate(:accessible => true)
|
60
|
-
should allow_mass_assignment_of
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'should not allow mass assignment if attributes are protected' do
|
64
|
-
define_and_validate(:protected => true)
|
65
|
-
should_not allow_mass_assignment_of
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe 'macros' do
|
71
|
-
before(:each){ define_and_validate(:accessible => true) }
|
72
|
-
|
73
|
-
should_allow_mass_assignment_of :title
|
74
|
-
should_allow_mass_assignment_of :category
|
75
|
-
should_allow_mass_assignment_of :title, :category
|
76
|
-
|
77
|
-
should_not_allow_mass_assignment_of :another
|
78
|
-
end
|
79
|
-
|
80
|
-
describe 'failures' do
|
81
|
-
it "should fail if some attribute is accessible when it shuold be protected" do
|
82
|
-
define_and_validate(:accessible => true)
|
83
|
-
|
84
|
-
lambda {
|
85
|
-
should_not allow_mass_assignment_of :title, :another
|
86
|
-
}.should raise_error(Spec::Expectations::ExpectationNotMetError, /Product has made title accessible/)
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should fail if attributes are accessible when none should" do
|
90
|
-
define_and_validate(:accessible => true)
|
91
|
-
|
92
|
-
lambda {
|
93
|
-
should_not allow_mass_assignment_of
|
94
|
-
}.should raise_error(Spec::Expectations::ExpectationNotMetError, /Product made category and title accessible/)
|
95
|
-
end
|
96
|
-
|
97
|
-
it "should fail if nothing was declared but expected to be protected" do
|
98
|
-
define_and_validate
|
99
|
-
|
100
|
-
lambda {
|
101
|
-
should_not allow_mass_assignment_of(:title)
|
102
|
-
}.should raise_error(Spec::Expectations::ExpectationNotMetError, /Did not expect Product to allow mass assignment of title/)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
@@ -1,80 +0,0 @@
|
|
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, :title => :string, :category => :string do
|
9
|
-
validates_format_of :title, options
|
10
|
-
end
|
11
|
-
|
12
|
-
allow_values_for(:title)
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'messages' do
|
16
|
-
before(:each){ @matcher = define_and_validate(:with => /X|Y|Z/) }
|
17
|
-
|
18
|
-
it 'should contain a description' do
|
19
|
-
@matcher = allow_values_for(:title, "X", "Y", "Z")
|
20
|
-
@matcher.description.should == 'allow "X", "Y", and "Z" as values for title'
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'should set is_valid? message' do
|
24
|
-
@matcher.in("A").matches?(@model)
|
25
|
-
@matcher.failure_message.should == 'Expected Product to be valid when title is set to "A"'
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'should set allow_nil? message' do
|
29
|
-
@matcher.allow_nil.matches?(@model)
|
30
|
-
@matcher.failure_message.should == 'Expected Product to allow nil values for title'
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should set allow_blank? message' do
|
34
|
-
@matcher.allow_blank.matches?(@model)
|
35
|
-
@matcher.failure_message.should == 'Expected Product to allow blank values for title'
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe 'matchers' do
|
40
|
-
it { should define_and_validate(:with => /X|Y|Z/).in('X', 'Y', 'Z') }
|
41
|
-
|
42
|
-
it { should_not define_and_validate(:with => /X|Y|Z/).in('A') }
|
43
|
-
it { should_not define_and_validate(:with => /X|Y|Z/, :message => 'invalid').in('A') }
|
44
|
-
|
45
|
-
create_optional_boolean_specs(:allow_nil, self, :with => /X|Y|Z/)
|
46
|
-
create_optional_boolean_specs(:allow_blank, self, :with => /X|Y|Z/)
|
47
|
-
end
|
48
|
-
|
49
|
-
describe 'macros' do
|
50
|
-
before(:each){ define_and_validate(:with => /X|Y|Z/) }
|
51
|
-
|
52
|
-
should_allow_values_for :title, 'X'
|
53
|
-
should_not_allow_values_for :title, 'A'
|
54
|
-
end
|
55
|
-
|
56
|
-
describe 'failures' do
|
57
|
-
before(:each) do
|
58
|
-
define_and_validate(:with => /X|Y|Z/)
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should fail if any of the values are valid on invalid cases" do
|
62
|
-
lambda {
|
63
|
-
should_not allow_values_for :title, 'A', 'X', 'B'
|
64
|
-
}.should raise_error(Spec::Expectations::ExpectationNotMetError, /Did not expect Product to be valid/)
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should also fail if all values are valid" do
|
68
|
-
lambda {
|
69
|
-
should_not allow_values_for :title, 'X', 'Y', 'Z'
|
70
|
-
}.should raise_error(Spec::Expectations::ExpectationNotMetError, /Did not expect Product to be valid/)
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should not fail if all values are invalid" do
|
74
|
-
lambda {
|
75
|
-
should_not allow_values_for :title, 'A', 'B', 'C'
|
76
|
-
}.should_not raise_error
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|