has_constant 0.4.7 → 0.4.8

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 CHANGED
@@ -1 +1 @@
1
- 0.4.7
1
+ 0.4.8
data/has_constant.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{has_constant}
8
- s.version = "0.4.7"
8
+ s.version = "0.4.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["mattbeedle"]
12
- s.date = %q{2011-02-04}
12
+ s.date = %q{2011-02-07}
13
13
  s.description = %q{Allows certain fields to be limited to a set of values}
14
14
  s.email = %q{mattbeedle@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -22,7 +22,9 @@ module HasConstant
22
22
  singular = (options[:accessor] || name.to_s.singularize).to_s
23
23
 
24
24
  class_eval do
25
- field singular.to_sym, { :type => Integer }.merge(options)
25
+ unless fields.map(&:first).include?(singular.to_s)
26
+ field singular.to_sym, { :type => Integer }.merge(options)
27
+ end
26
28
 
27
29
  index singular.to_sym, :background => true if options[:index]
28
30
 
@@ -31,6 +31,12 @@ class MongoidTest < Test::Unit::TestCase
31
31
  assert MongoUserWithout.fields.map(&:first).include?('salutation')
32
32
  end
33
33
 
34
+ should 'not add the field if it is already there' do
35
+ MongoUserWithout.send(:field, :salutation, :type => Integer, :default => 0)
36
+ MongoUserWithout.has_constant :salutations, ['Mr', 'Mrs']
37
+ assert_equal 'Mr', MongoUserWithout.new.salutation
38
+ end
39
+
34
40
  should 'take the accessor into account when adding the field' do
35
41
  MongoUserWithout.has_constant :salutations, ['Mr', 'Mrs'], :accessor => :sal
36
42
  assert MongoUserWithout.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: 1
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 7
10
- version: 0.4.7
9
+ - 8
10
+ version: 0.4.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - mattbeedle
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-04 00:00:00 +01:00
18
+ date: 2011-02-07 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency