has_constant 0.6.0 → 0.6.1
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/VERSION +1 -1
- data/has_constant.gemspec +1 -1
- data/lib/has_constant.rb +2 -1
- data/lib/has_constant/orm/mongoid.rb +1 -1
- data/test/unit/orm/mongoid_test.rb +5 -0
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.1
|
data/has_constant.gemspec
CHANGED
data/lib/has_constant.rb
CHANGED
@@ -59,7 +59,8 @@ module HasConstant
|
|
59
59
|
elsif values.is_a?(Hash) && values.has_value?(val)
|
60
60
|
instance_variable_set("@#{singular}", values.invert[val].to_s)
|
61
61
|
else
|
62
|
-
raise ArgumentError,
|
62
|
+
raise ArgumentError,
|
63
|
+
"value for #{singular} must be in #{self.class.send(name.to_s).join(', ')}"
|
63
64
|
end
|
64
65
|
else
|
65
66
|
instance_variable_set("@#{singular}", val)
|
@@ -23,7 +23,7 @@ module HasConstant
|
|
23
23
|
|
24
24
|
class_eval do
|
25
25
|
unless fields.map(&:first).include?(singular.to_s)
|
26
|
-
field singular.to_sym, { :type => values.is_a?(
|
26
|
+
field singular.to_sym, { :type => values.is_a?(Hash) ? String : Integer }.merge(options)
|
27
27
|
end
|
28
28
|
|
29
29
|
index singular.to_sym, :background => true if options[:index]
|
@@ -47,6 +47,11 @@ class MongoidTest < Test::Unit::TestCase
|
|
47
47
|
assert_equal 'Mr', MongoUser.new.salutation
|
48
48
|
end
|
49
49
|
|
50
|
+
should 'be able to take default option' do
|
51
|
+
MongoUser2.has_constant :salutations, lambda { %w(Mr Mrs) }, { :default => 0 }
|
52
|
+
assert_equal 'Mr', MongoUser2.new.salutation
|
53
|
+
end
|
54
|
+
|
50
55
|
should 'take the accessor into account when adding the field' do
|
51
56
|
MongoUser.has_constant :salutations, ['Mr', 'Mrs'], :accessor => :sal
|
52
57
|
assert MongoUser.fields.map(&:first).include?('sal')
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_constant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 5
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 1
|
10
|
+
version: 0.6.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- mattbeedle
|