enumerate_it 0.7.7 → 0.7.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/enumerate_it.rb +9 -5
- data/lib/version.rb +1 -1
- data/spec/enumerate_it_spec.rb +8 -1
- metadata +2 -2
data/Gemfile.lock
CHANGED
data/lib/enumerate_it.rb
CHANGED
@@ -127,14 +127,14 @@
|
|
127
127
|
# p.divorced? #=> false
|
128
128
|
#
|
129
129
|
# - If you pass the :create_scopes option as 'true', it will create a scope method for each enumeration option (this option defaults to false):
|
130
|
-
#
|
130
|
+
#
|
131
131
|
# class Person < ActiveRecord::Base
|
132
132
|
# has_enumeration_for :relationship_status, :with => RelationshipStatus, :create_scopes => true
|
133
133
|
# end
|
134
|
-
#
|
134
|
+
#
|
135
135
|
# Person.married.to_sql # => SELECT "people".* FROM "people" WHERE "people"."relationship_status" = 1
|
136
|
-
#
|
137
|
-
# NOTE: The :create_scopes option can only be used for Rails.version >= 3.0.0.
|
136
|
+
#
|
137
|
+
# NOTE: The :create_scopes option can only be used for Rails.version >= 3.0.0.
|
138
138
|
#
|
139
139
|
# - If your class can manage validations and responds to :validates_inclusion_of, it will create this
|
140
140
|
# validation:
|
@@ -309,7 +309,11 @@ module EnumerateIt
|
|
309
309
|
|
310
310
|
def set_validations(attribute, options)
|
311
311
|
validates_inclusion_of(attribute, :in => options[:with].list, :allow_blank => true) if self.respond_to?(:validates_inclusion_of)
|
312
|
-
|
312
|
+
|
313
|
+
if options[:required] && respond_to?(:validates_presence_of)
|
314
|
+
opts = options[:required].is_a?(Hash) ? options[:required] : {}
|
315
|
+
validates_presence_of(attribute, opts)
|
316
|
+
end
|
313
317
|
end
|
314
318
|
end
|
315
319
|
|
data/lib/version.rb
CHANGED
data/spec/enumerate_it_spec.rb
CHANGED
@@ -173,7 +173,7 @@ describe EnumerateIt do
|
|
173
173
|
end
|
174
174
|
end
|
175
175
|
|
176
|
-
it "when called, the scopes create the correct query" do
|
176
|
+
it "when called, the scopes create the correct query" do
|
177
177
|
TestEnumeration.enumeration do |symbol, pair|
|
178
178
|
TestClass.should_receive(:where).with(:foobar => pair.firs)
|
179
179
|
TestClass.send symbol
|
@@ -279,6 +279,13 @@ describe EnumerateIt::Base do
|
|
279
279
|
end
|
280
280
|
end
|
281
281
|
|
282
|
+
it "passes the given options to the validation method" do
|
283
|
+
ActiveRecordStub.should_receive(:validates_presence_of).with(:bla, :if => :some_method)
|
284
|
+
class ActiveRecordStub
|
285
|
+
has_enumeration_for :bla, :with => TestEnumeration, :required => { :if => :some_method }
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
282
289
|
it "do not require the attribute by default" do
|
283
290
|
ActiveRecordStub.should_not_receive(:validates_presence_of)
|
284
291
|
class ActiveRecordStub
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: enumerate_it
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.7.
|
5
|
+
version: 0.7.8
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- "C\xC3\xA1ssio Marques"
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-05-10 00:00:00 -03:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|