remarkable_activerecord 3.0.3 → 3.0.4

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.
@@ -10,7 +10,13 @@ module Remarkable
10
10
  protected
11
11
 
12
12
  def valid_values
13
- @in_range ? [ @options[:in].first - 1, @options[:in].last + 1 ] : []
13
+ if @in_range
14
+ [ @options[:in].first - 1, @options[:in].last + 1 ]
15
+ elsif @options[:in].empty?
16
+ []
17
+ else
18
+ [ @options[:in].map(&:to_s).max.to_s.next ]
19
+ end
14
20
  end
15
21
 
16
22
  def invalid_values
@@ -20,7 +26,10 @@ module Remarkable
20
26
  end
21
27
 
22
28
  # Ensures that given values are not valid for the attribute. If a range
23
- # is given, ensures that the attribute is not valid in the given range.
29
+ # is given, ensures that the attribute is not valid in the given range.
30
+ #
31
+ # If you give that :username does not accept ["admin", "user"], it will
32
+ # test that "uses" (the next of the array max value) is allowed.
24
33
  #
25
34
  # == Options
26
35
  #
@@ -14,13 +14,22 @@ module Remarkable
14
14
  end
15
15
 
16
16
  def invalid_values
17
- @in_range ? [ @options[:in].first - 1, @options[:in].last + 1 ] : []
17
+ if @in_range
18
+ [ @options[:in].first - 1, @options[:in].last + 1 ]
19
+ elsif @options[:in].empty?
20
+ []
21
+ else
22
+ [ @options[:in].map(&:to_s).max.to_s.next ]
23
+ end
18
24
  end
19
25
 
20
26
  end
21
27
 
22
28
  # Ensures that given values are valid for the attribute. If a range
23
- # is given, ensures that the attribute is valid in the given range.
29
+ # is given, ensures that the attribute is valid in the given range.
30
+ #
31
+ # If you give that :size accepts ["S", "M", "L"], it will test that "T"
32
+ # (the next of the array max value) is not allowed.
24
33
  #
25
34
  # == Options
26
35
  #
@@ -21,20 +21,32 @@ module Remarkable
21
21
 
22
22
  # Tries to find an object in the database. If allow_nil and/or allow_blank
23
23
  # is given, we must find a record which is not nil or not blank.
24
+ #
25
+ # We should also ensure that the object retrieved from the database
26
+ # is not the @subject.
24
27
  #
25
- # If any of these attempts fail, the validation fail.
28
+ # If any of these attempts fail, an error is raised.
26
29
  #
27
- def find_first_object?
28
- @existing, message = if @options[:allow_nil]
29
- [ subject_class.find(:first, :conditions => "#{@attribute} IS NOT NULL"), " with #{@attribute} not nil" ]
30
+ def find_first_object?
31
+ conditions, message = if @options[:allow_nil]
32
+ [ ["#{@attribute} IS NOT NULL"], " with #{@attribute} not nil" ]
30
33
  elsif @options[:allow_blank]
31
- [ subject_class.find(:first, :conditions => "#{@attribute} != ''"), " with #{@attribute} not blank" ]
34
+ [ ["#{@attribute} != ''"], " with #{@attribute} not blank" ]
32
35
  else
33
- [ subject_class.find(:first), "" ]
34
- end
36
+ [ [], "" ]
37
+ end
38
+
39
+ unless @subject.new_record?
40
+ primary_key = subject_class.primary_key
41
+
42
+ message << " which is different from the subject record (the object being validated is the same as the one in the database)"
43
+ conditions << "#{subject_class.primary_key} != '#{@subject.send(primary_key)}'"
44
+ end
45
+
46
+ options = conditions.empty? ? {} : { :conditions => conditions.join(' AND ') }
35
47
 
36
- return true if @existing
37
- raise ScriptError, "could not find a #{subject_class} in the database" + message
48
+ return true if @existing = subject_class.find(:first, options)
49
+ raise ScriptError, "could not find a #{subject_class} record in the database" + message
38
50
  end
39
51
 
40
52
  # Set subject scope to be equal to the object found.
@@ -94,14 +106,16 @@ module Remarkable
94
106
  #
95
107
  def allow_nil?
96
108
  return true unless @options.key?(:allow_nil)
109
+
110
+ begin
111
+ @existing.update_attribute(@attribute, nil)
112
+ rescue ::ActiveRecord::StatementInvalid => e
113
+ raise ScriptError, "You declared that #{@attribute} accepts nil values in validate_uniqueness_of, " <<
114
+ "but I cannot save nil values in the database, got: #{e.message}" if @options[:allow_nil]
115
+ return true
116
+ end
97
117
 
98
- @existing.update_attribute(@attribute, nil)
99
118
  super
100
- rescue Exception => e
101
- raise ScriptError, "You declared that #{@attribute} accepts nil values in validate_uniqueness_of, " <<
102
- "but I cannot save nil values in the database, got: #{e.message}" if @options[:allow_nil]
103
-
104
- true
105
119
  end
106
120
 
107
121
  # Change the existing object attribute to blank to run allow blank
@@ -109,14 +123,16 @@ module Remarkable
109
123
  #
110
124
  def allow_blank?
111
125
  return true unless @options.key?(:allow_blank)
126
+
127
+ begin
128
+ @existing.update_attribute(@attribute, '')
129
+ rescue ::ActiveRecord::StatementInvalid => e
130
+ raise ScriptError, "You declared that #{@attribute} accepts blank values in validate_uniqueness_of, " <<
131
+ "but I cannot save blank values in the database, got: #{e.message}" if @options[:allow_blank]
132
+ return true
133
+ end
112
134
 
113
- @existing.update_attribute(@attribute, '')
114
135
  super
115
- rescue Exception => e
116
- raise ScriptError, "You declared that #{@attribute} accepts blank values in validate_uniqueness_of, " <<
117
- "but I cannot save blank values in the database, got: #{e.message}" if @options[:allow_blank]
118
-
119
- true
120
136
  end
121
137
 
122
138
  # Returns a value to be used as new scope. It does a range query in the
data/locale/en.yml CHANGED
@@ -71,8 +71,6 @@ en:
71
71
  autosave:
72
72
  positive: "autosaving associated records"
73
73
  negative: "not autosaving associated records"
74
- polymorphic:
75
- positive: "through a polymorphic interface"
76
74
  as:
77
75
  positive: "through the polymorphic interface {{inspect}}"
78
76
  counter_cache:
@@ -91,8 +89,8 @@ en:
91
89
  positive: "allowing null values"
92
90
  negative: "not allowing null values"
93
91
  default:
94
- positive: "with default {{inspect}}"
95
- negative: "with default {{inspect}}"
92
+ positive: "with default value {{inspect}}"
93
+ negative: "with default value {{inspect}}"
96
94
  limit:
97
95
  positive: "with limit {{inspect}}"
98
96
 
@@ -114,7 +112,7 @@ en:
114
112
  have_scope:
115
113
  description: "have to scope itself to {{options}} when {{scope_name}} is called"
116
114
  expectations:
117
- is_scope: "{{scope_name}} when called on {{subject_name}} return a ActiveRecord::NamedScope::Scope object"
115
+ is_scope: "{{scope_name}} when called on {{subject_name}} return an instance of ActiveRecord::NamedScope::Scope"
118
116
  options_match: "{{scope_name}} when called on {{subject_name}} scope to {{options}}, got {{actual}}"
119
117
  optionals:
120
118
  with:
@@ -35,13 +35,12 @@ describe 'association_matcher' do
35
35
  matcher.readonly
36
36
  matcher.description.should == 'belong to company with dependent :destroy and with readonly records'
37
37
 
38
- matcher.polymorphic
39
- matcher.description.should == 'belong to company with dependent :destroy, with readonly records, ' <<
40
- 'and through a polymorphic interface'
38
+ matcher.as(:interface)
39
+ matcher.description.should == 'belong to company with dependent :destroy, through the polymorphic interface :interface, and with readonly records'
41
40
 
42
41
  matcher.counter_cache('projects_count')
43
- matcher.description.should == 'belong to company with dependent :destroy, with readonly records, ' <<
44
- 'through a polymorphic interface, and with counter cache "projects_count"'
42
+ matcher.description.should == 'belong to company with dependent :destroy, through the polymorphic interface :interface, ' <<
43
+ 'with readonly records, and with counter cache "projects_count"'
45
44
  end
46
45
 
47
46
  it 'should set association_exists? message' do
@@ -31,7 +31,7 @@ describe 'have_scope' do
31
31
  it 'should set is_scope? message' do
32
32
  @matcher = have_scope(:null)
33
33
  @matcher.matches?(@model)
34
- @matcher.failure_message.should == 'Expected :null when called on Product return a ActiveRecord::NamedScope::Scope object'
34
+ @matcher.failure_message.should == 'Expected :null when called on Product return an instance of ActiveRecord::NamedScope::Scope'
35
35
  end
36
36
 
37
37
  it 'should set options_match? message' do
@@ -1,88 +1,87 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe 'validate_exclusion_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 do
9
- validates_exclusion_of :title, :size, options
10
- end
11
-
12
- validate_exclusion_of(:title, :size)
13
- end
14
-
15
- describe 'messages' do
16
-
17
- it 'should contain a description' do
18
- @matcher = define_and_validate(:in => 2..10)
19
- @matcher.in(2..10)
20
- @matcher.description.should == 'ensure exclusion of title and size in 2..10'
21
-
22
- @matcher = validate_exclusion_of(:title, :size).in('X', 'Y', 'Z')
23
- @matcher.description.should == 'ensure exclusion of title and size in "X", "Y", and "Z"'
24
- end
25
-
26
- it 'should set is_invalid? message' do
27
- @matcher = define_and_validate(:in => 2..10)
28
- @matcher.in(1..10).matches?(@model)
29
- @matcher.failure_message.should == 'Expected Product to be invalid when title is set to 1'
30
- end
31
-
32
- it 'should set is_valid? message' do
33
- @matcher = define_and_validate(:in => 2..10)
34
- @matcher.in(3..10).matches?(@model)
35
- @matcher.failure_message.should == 'Expected Product to be valid when title is set to 2'
36
- end
37
-
38
- it 'should set allow_nil? message' do
39
- @matcher = define_and_validate(:in => [nil])
40
- @matcher.allow_nil.matches?(@model)
41
- @matcher.failure_message.should == 'Expected Product to allow nil values for title'
42
- end
43
-
44
- it 'should set allow_blank? message' do
45
- @matcher = define_and_validate(:in => [''])
46
- @matcher.allow_blank.matches?(@model)
47
- @matcher.failure_message.should == 'Expected Product to allow blank values for title'
48
- end
49
- end
50
-
51
- describe 'matchers' do
52
- it { should define_and_validate(:in => ['X', 'Y', 'Z']).in('X', 'Y', 'Z') }
53
- it { should_not define_and_validate(:in => ['X', 'Y', 'Z']).in('A') }
54
-
55
- it { should define_and_validate(:in => 2..3).in(2..3) }
56
- it { should define_and_validate(:in => 2..20).in(2..20) }
57
- it { should_not define_and_validate(:in => 2..20).in(1..20) }
58
- it { should_not define_and_validate(:in => 2..20).in(3..20) }
59
- it { should_not define_and_validate(:in => 2..20).in(2..19) }
60
- it { should_not define_and_validate(:in => 2..20).in(2..21) }
61
-
62
- it { should define_and_validate(:in => ['X', 'Y', 'Z'], :message => 'valid').in('X', 'Y', 'Z').message('valid') }
63
-
64
- create_optional_boolean_specs(:allow_nil, self, :in => [nil])
65
- create_optional_boolean_specs(:allow_blank, self, :in => [''])
66
- end
67
-
68
- describe 'macros' do
69
- describe 'with array' do
70
- before(:each){ define_and_validate(:in => ['X', 'Y', 'Z']) }
71
-
72
- should_validate_exclusion_of :title, :in => ['X']
73
- should_validate_exclusion_of :title, :size, :in => ['X']
74
- should_not_validate_exclusion_of :title, :size, :in => ['A']
75
- end
76
-
77
- describe 'with range' do
78
- before(:each){ define_and_validate(:in => 2..20) }
79
-
80
- should_validate_exclusion_of :title, :in => 2..20
81
- should_not_validate_exclusion_of :title, :in => 1..20
82
- should_not_validate_exclusion_of :title, :in => 3..20
83
- should_not_validate_exclusion_of :title, :in => 2..19
84
- should_not_validate_exclusion_of :title, :in => 2..21
85
- end
86
- end
87
- end
88
-
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe 'validate_exclusion_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 do
9
+ validates_exclusion_of :title, :size, options
10
+ end
11
+
12
+ validate_exclusion_of(:title, :size)
13
+ end
14
+
15
+ describe 'messages' do
16
+
17
+ it 'should contain a description' do
18
+ @matcher = define_and_validate(:in => 2..10)
19
+ @matcher.in(2..10)
20
+ @matcher.description.should == 'ensure exclusion of title and size in 2..10'
21
+
22
+ @matcher = validate_exclusion_of(:title, :size).in('X', 'Y', 'Z')
23
+ @matcher.description.should == 'ensure exclusion of title and size in "X", "Y", and "Z"'
24
+ end
25
+
26
+ it 'should set is_invalid? message' do
27
+ @matcher = define_and_validate(:in => 2..10)
28
+ @matcher.in(1..10).matches?(@model)
29
+ @matcher.failure_message.should == 'Expected Product to be invalid when title is set to 1'
30
+ end
31
+
32
+ it 'should set is_valid? message' do
33
+ @matcher = define_and_validate(:in => 2..10)
34
+ @matcher.in(3..10).matches?(@model)
35
+ @matcher.failure_message.should == 'Expected Product to be valid when title is set to 2'
36
+ end
37
+
38
+ it 'should set allow_nil? message' do
39
+ @matcher = define_and_validate(:in => [nil])
40
+ @matcher.allow_nil.matches?(@model)
41
+ @matcher.failure_message.should == 'Expected Product to allow nil values for title'
42
+ end
43
+
44
+ it 'should set allow_blank? message' do
45
+ @matcher = define_and_validate(:in => [''])
46
+ @matcher.allow_blank.matches?(@model)
47
+ @matcher.failure_message.should == 'Expected Product to allow blank values for title'
48
+ end
49
+ end
50
+
51
+ describe 'matchers' do it { should define_and_validate(:in => ['X', 'Y', 'Z']).in('X', 'Y', 'Z') }
52
+ it { should_not define_and_validate(:in => ['X', 'Y', 'Z']).in('X', 'Y') }
53
+ it { should_not define_and_validate(:in => ['X', 'Y', 'Z']).in('A') }
54
+
55
+ it { should define_and_validate(:in => 2..3).in(2..3) }
56
+ it { should define_and_validate(:in => 2..20).in(2..20) }
57
+ it { should_not define_and_validate(:in => 2..20).in(1..20) }
58
+ it { should_not define_and_validate(:in => 2..20).in(3..20) }
59
+ it { should_not define_and_validate(:in => 2..20).in(2..19) }
60
+ it { should_not define_and_validate(:in => 2..20).in(2..21) }
61
+
62
+ it { should define_and_validate(:in => ['X', 'Y', 'Z'], :message => 'not valid').in('X', 'Y', 'Z').message('not valid') }
63
+ it { should_not define_and_validate(:in => ['X', 'Y', 'Z'], :message => 'not valid').in('X', 'Y', 'Z').message('valid') }
64
+ end
65
+
66
+ describe 'macros' do
67
+ describe 'with array' do
68
+ before(:each){ define_and_validate(:in => ['X', 'Y', 'Z']) }
69
+
70
+ should_validate_exclusion_of :title, :in => ['X', 'Y', 'Z']
71
+ should_validate_exclusion_of :title, :size, :in => ['X', 'Y', 'Z']
72
+ should_not_validate_exclusion_of :title, :in => ['X', 'Y']
73
+ should_not_validate_exclusion_of :title, :size, :in => ['A']
74
+ end
75
+
76
+ describe 'with range' do
77
+ before(:each){ define_and_validate(:in => 2..20) }
78
+
79
+ should_validate_exclusion_of :title, :in => 2..20
80
+ should_not_validate_exclusion_of :title, :in => 1..20
81
+ should_not_validate_exclusion_of :title, :in => 3..20
82
+ should_not_validate_exclusion_of :title, :in => 2..19
83
+ should_not_validate_exclusion_of :title, :in => 2..21
84
+ end
85
+ end
86
+ end
87
+
@@ -1,84 +1,84 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe 'validate_inclusion_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 do
9
- validates_inclusion_of :title, :size, options
10
- end
11
-
12
- validate_inclusion_of(:title, :size)
13
- end
14
-
15
- describe 'messages' do
16
- before(:each){ @matcher = define_and_validate(:in => 2..10) }
17
-
18
- it 'should contain a description' do
19
- @matcher.in(2..10)
20
- @matcher.description.should == 'ensure inclusion of title and size in 2..10'
21
-
22
- @matcher = validate_inclusion_of(:title, :size).in('X', 'Y', 'Z')
23
- @matcher.description.should == 'ensure inclusion of title and size in "X", "Y", and "Z"'
24
- end
25
-
26
- it 'should set is_valid? message' do
27
- @matcher.in(1..10).matches?(@model)
28
- @matcher.failure_message.should == 'Expected Product to be valid when title is set to 1'
29
- end
30
-
31
- it 'should set is_invalid? message' do
32
- @matcher.in(3..10).matches?(@model)
33
- @matcher.failure_message.should == 'Expected Product to be invalid when title is set to 2'
34
- end
35
-
36
- it 'should set allow_nil? message' do
37
- @matcher.allow_nil.matches?(@model)
38
- @matcher.failure_message.should == 'Expected Product to allow nil values for title'
39
- end
40
-
41
- it 'should set allow_blank? message' do
42
- @matcher.allow_blank.matches?(@model)
43
- @matcher.failure_message.should == 'Expected Product to allow blank values for title'
44
- end
45
- end
46
-
47
- describe 'matchers' do
48
- it { should define_and_validate(:in => ['X', 'Y', 'Z']).in('X', 'Y', 'Z') }
49
- it { should_not define_and_validate(:in => ['X', 'Y', 'Z']).in('A') }
50
-
51
- it { should define_and_validate(:in => 2..3).in(2..3) }
52
- it { should define_and_validate(:in => 2..20).in(2..20) }
53
- it { should_not define_and_validate(:in => 2..20).in(1..20) }
54
- it { should_not define_and_validate(:in => 2..20).in(3..20) }
55
- it { should_not define_and_validate(:in => 2..20).in(2..19) }
56
- it { should_not define_and_validate(:in => 2..20).in(2..21) }
57
-
58
- it { should define_and_validate(:in => ['X', 'Y', 'Z'], :message => 'valid').in('X', 'Y', 'Z').message('valid') }
59
-
60
- create_optional_boolean_specs(:allow_nil, self, :in => ['X'])
61
- create_optional_boolean_specs(:allow_blank, self, :in => ['X'])
62
- end
63
-
64
- describe 'macros' do
65
- describe 'with array' do
66
- before(:each){ define_and_validate(:in => ['X', 'Y', 'Z']) }
67
-
68
- should_validate_inclusion_of :title, :in => ['X']
69
- should_validate_inclusion_of :title, :size, :in => ['X']
70
- should_not_validate_inclusion_of :title, :size, :in => ['A']
71
- end
72
-
73
- describe 'with range' do
74
- before(:each){ define_and_validate(:in => 2..20) }
75
-
76
- should_validate_inclusion_of :title, :in => 2..20
77
- should_not_validate_inclusion_of :title, :in => 1..20
78
- should_not_validate_inclusion_of :title, :in => 3..20
79
- should_not_validate_inclusion_of :title, :in => 2..19
80
- should_not_validate_inclusion_of :title, :in => 2..21
81
- end
82
- end
83
- end
84
-
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe 'validate_inclusion_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 do
9
+ validates_inclusion_of :title, :size, options
10
+ end
11
+
12
+ validate_inclusion_of(:title, :size)
13
+ end
14
+
15
+ describe 'messages' do
16
+ before(:each){ @matcher = define_and_validate(:in => 2..10) }
17
+
18
+ it 'should contain a description' do
19
+ @matcher.in(2..10)
20
+ @matcher.description.should == 'ensure inclusion of title and size in 2..10'
21
+
22
+ @matcher = validate_inclusion_of(:title, :size).in('X', 'Y', 'Z')
23
+ @matcher.description.should == 'ensure inclusion of title and size in "X", "Y", and "Z"'
24
+ end
25
+
26
+ it 'should set is_valid? message' do
27
+ @matcher.in(1..10).matches?(@model)
28
+ @matcher.failure_message.should == 'Expected Product to be valid when title is set to 1'
29
+ end
30
+
31
+ it 'should set is_invalid? message' do
32
+ @matcher.in(3..10).matches?(@model)
33
+ @matcher.failure_message.should == 'Expected Product to be invalid when title is set to 2'
34
+ end
35
+
36
+ it 'should set allow_nil? message' do
37
+ @matcher.allow_nil.matches?(@model)
38
+ @matcher.failure_message.should == 'Expected Product to allow nil values for title'
39
+ end
40
+
41
+ it 'should set allow_blank? message' do
42
+ @matcher.allow_blank.matches?(@model)
43
+ @matcher.failure_message.should == 'Expected Product to allow blank values for title'
44
+ end
45
+ end
46
+
47
+ describe 'matchers' do
48
+ it { should define_and_validate(:in => ['X', 'Y', 'Z']).in('X', 'Y', 'Z') }
49
+ it { should_not define_and_validate(:in => ['X', 'Y', 'Z']).in('X', 'Y') }
50
+ it { should_not define_and_validate(:in => ['X', 'Y', 'Z']).in('A') }
51
+
52
+ it { should define_and_validate(:in => 2..3).in(2..3) }
53
+ it { should define_and_validate(:in => 2..20).in(2..20) }
54
+ it { should_not define_and_validate(:in => 2..20).in(1..20) }
55
+ it { should_not define_and_validate(:in => 2..20).in(3..20) }
56
+ it { should_not define_and_validate(:in => 2..20).in(2..19) }
57
+ it { should_not define_and_validate(:in => 2..20).in(2..21) }
58
+
59
+ it { should define_and_validate(:in => ['X', 'Y', 'Z'], :message => 'not valid').in('X', 'Y', 'Z').message('not valid') }
60
+ it { should_not define_and_validate(:in => ['X', 'Y', 'Z'], :message => 'not valid').in('X', 'Y', 'Z').message('valid') }
61
+ end
62
+
63
+ describe 'macros' do
64
+ describe 'with array' do
65
+ before(:each){ define_and_validate(:in => ['X', 'Y', 'Z']) }
66
+
67
+ should_validate_inclusion_of :title, :in => ['X', 'Y', 'Z']
68
+ should_validate_inclusion_of :title, :size, :in => ['X', 'Y', 'Z']
69
+ should_not_validate_inclusion_of :title, :in => ['X', 'Y']
70
+ should_not_validate_inclusion_of :title, :size, :in => ['A']
71
+ end
72
+
73
+ describe 'with range' do
74
+ before(:each){ define_and_validate(:in => 2..20) }
75
+
76
+ should_validate_inclusion_of :title, :in => 2..20
77
+ should_not_validate_inclusion_of :title, :in => 1..20
78
+ should_not_validate_inclusion_of :title, :in => 3..20
79
+ should_not_validate_inclusion_of :title, :in => 2..19
80
+ should_not_validate_inclusion_of :title, :in => 2..21
81
+ end
82
+ end
83
+ end
84
+
@@ -105,7 +105,7 @@ describe 'validate_uniqueness_of' do
105
105
  proc { @matcher.matches?(@model) }.should_not raise_error(ScriptError)
106
106
  end
107
107
 
108
- it 'should raise an error if no object with not nil attribute is found' do
108
+ it 'should raise an error if no object with not blank attribute is found' do
109
109
  @matcher = define_and_validate.allow_blank
110
110
  User.destroy_all
111
111
 
@@ -114,6 +114,11 @@ describe 'validate_uniqueness_of' do
114
114
 
115
115
  User.create(:username => 'jose')
116
116
  proc { @matcher.matches?(@model) }.should_not raise_error(ScriptError)
117
+ end
118
+
119
+ it 'should raise an error if @existing record is the same as @subject' do
120
+ @matcher = define_and_validate
121
+ proc { @matcher.matches?(User.first) }.should raise_error(ScriptError, /which is different from the subject record/)
117
122
  end
118
123
 
119
124
  it 'should raise an error if cannot find a new scope value' do
@@ -145,12 +150,12 @@ describe 'validate_uniqueness_of' do
145
150
  end
146
151
 
147
152
  # Create a model
148
- User.create(:username => Time.now)
153
+ User.create(:username => 'jose')
149
154
  validate_uniqueness_of(:username)
150
155
  end
151
156
 
152
157
  it { should define_and_validate }
153
- it { should define_and_validate.allow_nil(false) }
158
+ it { should define_and_validate(:allow_nil => false).allow_nil(false) }
154
159
 
155
160
  it 'should raise an error if allow nil is true but we cannot save nil values in the database'do
156
161
  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/)
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.3
4
+ version: 3.0.4
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-15 00:00:00 +02:00
14
+ date: 2009-04-18 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.3
25
+ version: 3.0.4
26
26
  version:
27
27
  description: "Remarkable ActiveRecord: collection of matchers and macros with I18n for ActiveRecord"
28
28
  email: