remarkable_activerecord 3.0.2 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +0 -0
- data/LICENSE +0 -0
- data/README +0 -0
- data/lib/remarkable_activerecord.rb +0 -0
- data/lib/remarkable_activerecord/base.rb +0 -0
- data/lib/remarkable_activerecord/human_names.rb +0 -0
- data/lib/remarkable_activerecord/matchers/allow_mass_assignment_of_matcher.rb +0 -0
- data/lib/remarkable_activerecord/matchers/allow_values_for_matcher.rb +0 -0
- data/lib/remarkable_activerecord/matchers/association_matcher.rb +0 -0
- data/lib/remarkable_activerecord/matchers/have_column_matcher.rb +0 -0
- data/lib/remarkable_activerecord/matchers/have_index_matcher.rb +0 -0
- data/lib/remarkable_activerecord/matchers/have_readonly_attributes_matcher.rb +0 -0
- data/lib/remarkable_activerecord/matchers/have_scope_matcher.rb +0 -0
- data/lib/remarkable_activerecord/matchers/validate_acceptance_of_matcher.rb +0 -0
- data/lib/remarkable_activerecord/matchers/validate_associated_matcher.rb +0 -0
- data/lib/remarkable_activerecord/matchers/validate_confirmation_of_matcher.rb +0 -0
- data/lib/remarkable_activerecord/matchers/validate_exclusion_of_matcher.rb +0 -0
- data/lib/remarkable_activerecord/matchers/validate_inclusion_of_matcher.rb +0 -0
- data/lib/remarkable_activerecord/matchers/validate_length_of_matcher.rb +0 -0
- data/lib/remarkable_activerecord/matchers/validate_numericality_of_matcher.rb +0 -0
- data/lib/remarkable_activerecord/matchers/validate_presence_of_matcher.rb +0 -0
- data/lib/remarkable_activerecord/matchers/validate_uniqueness_of_matcher.rb +35 -30
- data/locale/en.yml +0 -0
- data/spec/allow_mass_assignment_of_matcher_spec.rb +0 -0
- data/spec/allow_values_for_matcher_spec.rb +0 -0
- data/spec/association_matcher_spec.rb +0 -0
- data/spec/have_column_matcher_spec.rb +0 -0
- data/spec/have_index_matcher_spec.rb +0 -0
- data/spec/have_readonly_attributes_matcher_spec.rb +0 -0
- data/spec/have_scope_matcher_spec.rb +0 -0
- data/spec/model_builder.rb +0 -0
- data/spec/rcov.opts +0 -0
- data/spec/spec.opts +0 -0
- data/spec/spec_helper.rb +0 -0
- data/spec/validate_acceptance_of_matcher_spec.rb +0 -0
- data/spec/validate_associated_matcher_spec.rb +0 -0
- data/spec/validate_confirmation_of_matcher_spec.rb +0 -0
- data/spec/validate_exclusion_of_matcher_spec.rb +0 -0
- data/spec/validate_inclusion_of_matcher_spec.rb +0 -0
- data/spec/validate_length_of_matcher_spec.rb +0 -0
- data/spec/validate_numericality_of_matcher_spec.rb +0 -0
- data/spec/validate_presence_of_matcher_spec.rb +0 -0
- data/spec/validate_uniqueness_of_matcher_spec.rb +11 -11
- metadata +28 -28
data/CHANGELOG
CHANGED
File without changes
|
data/LICENSE
CHANGED
File without changes
|
data/README
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -41,10 +41,12 @@ module Remarkable
|
|
41
41
|
#
|
42
42
|
def responds_to_scope?
|
43
43
|
(@options[:scope] || []).each do |scope|
|
44
|
-
|
45
|
-
|
44
|
+
setter = :"#{scope}="
|
45
|
+
|
46
|
+
return false, :method => setter unless @subject.respond_to?(setter)
|
47
|
+
return false, :method => scope unless @existing.respond_to?(scope)
|
46
48
|
|
47
|
-
@subject.send(
|
49
|
+
@subject.send(setter, @existing.send(scope))
|
48
50
|
end
|
49
51
|
true
|
50
52
|
end
|
@@ -72,47 +74,48 @@ module Remarkable
|
|
72
74
|
# Now test that the object is valid when changing the scoped attribute.
|
73
75
|
#
|
74
76
|
def valid_with_new_scope?
|
75
|
-
(@options[:scope] || []).each do |scope|
|
76
|
-
|
77
|
+
(@options[:scope] || []).each do |scope|
|
78
|
+
setter = :"#{scope}="
|
77
79
|
|
78
|
-
@subject.send(
|
80
|
+
previous_scope_value = @subject.send(scope)
|
81
|
+
@subject.send(setter, new_value_for_scope(scope))
|
79
82
|
return false, :method => scope unless good?(@value)
|
80
83
|
|
81
|
-
@subject.send(
|
84
|
+
@subject.send(setter, previous_scope_value)
|
82
85
|
end
|
83
86
|
true
|
84
87
|
end
|
85
88
|
|
86
|
-
# Change the existing object attribute to nil to run allow nil
|
87
|
-
# validations. If we find any problem while updating the @existing
|
88
|
-
# record, it's because we can't save nil values in the database. So it
|
89
|
-
# passes when :allow_nil is false, but should raise an error when
|
89
|
+
# Change the existing object attribute to nil to run allow nil
|
90
|
+
# validations. If we find any problem while updating the @existing
|
91
|
+
# record, it's because we can't save nil values in the database. So it
|
92
|
+
# passes when :allow_nil is false, but should raise an error when
|
90
93
|
# :allow_nil is true
|
91
94
|
#
|
92
|
-
def allow_nil?
|
93
|
-
return true unless @options.key?(:allow_nil)
|
94
|
-
|
95
|
+
def allow_nil?
|
96
|
+
return true unless @options.key?(:allow_nil)
|
97
|
+
|
95
98
|
@existing.update_attribute(@attribute, nil)
|
96
|
-
super
|
97
|
-
rescue Exception => e
|
98
|
-
raise ScriptError, "You declared that #{@attribute} accepts nil values in validate_uniqueness_of, " <<
|
99
|
-
"but I cannot save nil values in the database, got: #{e.message}" if @options[:allow_nil]
|
100
|
-
|
101
|
-
true
|
99
|
+
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
|
102
105
|
end
|
103
106
|
|
104
|
-
# Change the existing object attribute to blank to run allow blank
|
107
|
+
# Change the existing object attribute to blank to run allow blank
|
105
108
|
# validation. It uses the same logic as :allow_nil.
|
106
109
|
#
|
107
|
-
def allow_blank?
|
108
|
-
return true unless @options.key?(:allow_blank)
|
110
|
+
def allow_blank?
|
111
|
+
return true unless @options.key?(:allow_blank)
|
109
112
|
|
110
113
|
@existing.update_attribute(@attribute, '')
|
111
|
-
super
|
112
|
-
rescue Exception => e
|
113
|
-
raise ScriptError, "You declared that #{@attribute} accepts blank values in validate_uniqueness_of, " <<
|
114
|
-
"but I cannot save blank values in the database, got: #{e.message}" if @options[:allow_blank]
|
115
|
-
|
114
|
+
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
|
+
|
116
119
|
true
|
117
120
|
end
|
118
121
|
|
@@ -120,10 +123,12 @@ module Remarkable
|
|
120
123
|
# database and tries to return a new value which does not belong to it.
|
121
124
|
#
|
122
125
|
def new_value_for_scope(scope)
|
123
|
-
|
126
|
+
values = [(@existing.send(scope) || 999).next.to_s]
|
124
127
|
|
125
128
|
# Generate a range of values to search in the database
|
126
|
-
|
129
|
+
100.times do
|
130
|
+
values << values.last.next
|
131
|
+
end
|
127
132
|
conditions = { scope => values, @attribute => @value }
|
128
133
|
|
129
134
|
# Get values from the database, get the scope attribute and map them to string.
|
data/locale/en.yml
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/spec/model_builder.rb
CHANGED
File without changes
|
data/spec/rcov.opts
CHANGED
File without changes
|
data/spec/spec.opts
CHANGED
File without changes
|
data/spec/spec_helper.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -136,9 +136,9 @@ describe 'validate_uniqueness_of' do
|
|
136
136
|
end
|
137
137
|
end
|
138
138
|
proc { @matcher.matches?(@model) }.should_not raise_error(ScriptError)
|
139
|
-
end
|
140
|
-
|
141
|
-
describe 'when null or blank values are not allowed' do
|
139
|
+
end
|
140
|
+
|
141
|
+
describe 'when null or blank values are not allowed' do
|
142
142
|
def define_and_validate(options={})
|
143
143
|
@model = define_model :user, :username => [:string, {:null => false}] do
|
144
144
|
validates_uniqueness_of :username, options
|
@@ -147,14 +147,14 @@ describe 'validate_uniqueness_of' do
|
|
147
147
|
# Create a model
|
148
148
|
User.create(:username => Time.now)
|
149
149
|
validate_uniqueness_of(:username)
|
150
|
-
end
|
151
|
-
|
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/)
|
157
|
-
end
|
150
|
+
end
|
151
|
+
|
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/)
|
157
|
+
end
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|
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.3
|
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-15 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.3
|
26
26
|
version:
|
27
27
|
description: "Remarkable ActiveRecord: collection of matchers and macros with I18n for ActiveRecord"
|
28
28
|
email:
|
@@ -45,22 +45,22 @@ files:
|
|
45
45
|
- lib/remarkable_activerecord/base.rb
|
46
46
|
- lib/remarkable_activerecord/human_names.rb
|
47
47
|
- lib/remarkable_activerecord/matchers
|
48
|
-
- lib/remarkable_activerecord/matchers/allow_mass_assignment_of_matcher.rb
|
49
|
-
- lib/remarkable_activerecord/matchers/allow_values_for_matcher.rb
|
50
|
-
- lib/remarkable_activerecord/matchers/association_matcher.rb
|
51
|
-
- lib/remarkable_activerecord/matchers/have_column_matcher.rb
|
52
|
-
- lib/remarkable_activerecord/matchers/have_index_matcher.rb
|
53
|
-
- lib/remarkable_activerecord/matchers/have_readonly_attributes_matcher.rb
|
54
|
-
- lib/remarkable_activerecord/matchers/have_scope_matcher.rb
|
55
|
-
- lib/remarkable_activerecord/matchers/validate_acceptance_of_matcher.rb
|
56
|
-
- lib/remarkable_activerecord/matchers/validate_associated_matcher.rb
|
57
48
|
- lib/remarkable_activerecord/matchers/validate_confirmation_of_matcher.rb
|
58
|
-
- lib/remarkable_activerecord/matchers/validate_exclusion_of_matcher.rb
|
59
|
-
- lib/remarkable_activerecord/matchers/validate_inclusion_of_matcher.rb
|
60
49
|
- lib/remarkable_activerecord/matchers/validate_length_of_matcher.rb
|
61
|
-
- lib/remarkable_activerecord/matchers/
|
50
|
+
- lib/remarkable_activerecord/matchers/have_readonly_attributes_matcher.rb
|
51
|
+
- lib/remarkable_activerecord/matchers/validate_exclusion_of_matcher.rb
|
52
|
+
- lib/remarkable_activerecord/matchers/validate_associated_matcher.rb
|
53
|
+
- lib/remarkable_activerecord/matchers/have_column_matcher.rb
|
54
|
+
- lib/remarkable_activerecord/matchers/association_matcher.rb
|
62
55
|
- lib/remarkable_activerecord/matchers/validate_presence_of_matcher.rb
|
56
|
+
- lib/remarkable_activerecord/matchers/have_scope_matcher.rb
|
57
|
+
- lib/remarkable_activerecord/matchers/allow_values_for_matcher.rb
|
58
|
+
- lib/remarkable_activerecord/matchers/have_index_matcher.rb
|
59
|
+
- lib/remarkable_activerecord/matchers/validate_inclusion_of_matcher.rb
|
60
|
+
- lib/remarkable_activerecord/matchers/validate_acceptance_of_matcher.rb
|
63
61
|
- lib/remarkable_activerecord/matchers/validate_uniqueness_of_matcher.rb
|
62
|
+
- lib/remarkable_activerecord/matchers/validate_numericality_of_matcher.rb
|
63
|
+
- lib/remarkable_activerecord/matchers/allow_mass_assignment_of_matcher.rb
|
64
64
|
- lib/remarkable_activerecord.rb
|
65
65
|
- locale/en.yml
|
66
66
|
has_rdoc: true
|
@@ -90,23 +90,23 @@ signing_key:
|
|
90
90
|
specification_version: 2
|
91
91
|
summary: "Remarkable ActiveRecord: collection of matchers and macros with I18n for ActiveRecord"
|
92
92
|
test_files:
|
93
|
-
- spec/
|
94
|
-
- spec/
|
95
|
-
- spec/association_matcher_spec.rb
|
96
|
-
- spec/have_column_matcher_spec.rb
|
97
|
-
- spec/have_index_matcher_spec.rb
|
98
|
-
- spec/have_readonly_attributes_matcher_spec.rb
|
99
|
-
- spec/have_scope_matcher_spec.rb
|
100
|
-
- spec/model_builder.rb
|
93
|
+
- spec/validate_associated_matcher_spec.rb
|
94
|
+
- spec/validate_length_of_matcher_spec.rb
|
101
95
|
- spec/rcov.opts
|
102
|
-
- spec/spec.opts
|
103
96
|
- spec/spec_helper.rb
|
104
97
|
- spec/validate_acceptance_of_matcher_spec.rb
|
105
|
-
- spec/
|
98
|
+
- spec/allow_mass_assignment_of_matcher_spec.rb
|
99
|
+
- spec/have_scope_matcher_spec.rb
|
100
|
+
- spec/validate_inclusion_of_matcher_spec.rb
|
101
|
+
- spec/spec.opts
|
102
|
+
- spec/have_readonly_attributes_matcher_spec.rb
|
106
103
|
- spec/validate_confirmation_of_matcher_spec.rb
|
104
|
+
- spec/allow_values_for_matcher_spec.rb
|
105
|
+
- spec/validate_uniqueness_of_matcher_spec.rb
|
106
|
+
- spec/have_column_matcher_spec.rb
|
107
|
+
- spec/have_index_matcher_spec.rb
|
108
|
+
- spec/association_matcher_spec.rb
|
107
109
|
- spec/validate_exclusion_of_matcher_spec.rb
|
108
|
-
- spec/
|
109
|
-
- spec/validate_length_of_matcher_spec.rb
|
110
|
+
- spec/model_builder.rb
|
110
111
|
- spec/validate_numericality_of_matcher_spec.rb
|
111
112
|
- spec/validate_presence_of_matcher_spec.rb
|
112
|
-
- spec/validate_uniqueness_of_matcher_spec.rb
|