has_constant 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.6.1
data/has_constant.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{has_constant}
8
- s.version = "0.6.0"
8
+ s.version = "0.6.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["mattbeedle"]
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, "value for #{singular} must be in #{self.class.send(name.to_s).join(', ')}"
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?(Array) ? Integer : String }.merge(options)
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: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 0
10
- version: 0.6.0
9
+ - 1
10
+ version: 0.6.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - mattbeedle