acts_as_enumeration 0.1.9 → 0.1.10
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/lib/active_record/acts/enumeration.rb +7 -3
- data/test/enumeration_test.rb +9 -6
- metadata +2 -2
@@ -2,7 +2,7 @@ module ActiveRecord
|
|
2
2
|
module Acts
|
3
3
|
module Enumeration
|
4
4
|
|
5
|
-
VERSION="0.1.
|
5
|
+
VERSION="0.1.10"
|
6
6
|
class << self
|
7
7
|
|
8
8
|
def included(base)
|
@@ -76,8 +76,12 @@ module ActiveRecord
|
|
76
76
|
define_method(key.camelize) { self.send("id_for_#{field}", y)}
|
77
77
|
define_method(key.camelize.upcase) { self.send(key.camelize)}
|
78
78
|
end
|
79
|
-
|
80
|
-
|
79
|
+
begin
|
80
|
+
self.const_set(key.camelize,self.send("id_for_#{field}",y)) unless self.const_defined?(key.camelize)
|
81
|
+
self.const_set(key.camelize.upcase,self.send("id_for_#{field}",y)) unless self.const_defined?(key.camelize.upcase)
|
82
|
+
rescue Exception=>e
|
83
|
+
puts("Warning: Skipping constant definition for #{key}")
|
84
|
+
end
|
81
85
|
end
|
82
86
|
end
|
83
87
|
end
|
data/test/enumeration_test.rb
CHANGED
@@ -29,12 +29,10 @@ def teardown_db
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
class Enumerate < ActiveRecord::Base;
|
33
|
-
end
|
34
|
-
class
|
35
|
-
end
|
36
|
-
class EnumerateSome < Enumerate;
|
37
|
-
end
|
32
|
+
class Enumerate < ActiveRecord::Base; end
|
33
|
+
class EnumerateAll < Enumerate; end
|
34
|
+
class EnumerateSome < Enumerate; end
|
35
|
+
class BrokenEnumeration < Enumerate; end
|
38
36
|
|
39
37
|
class EnumerateTest < (
|
40
38
|
begin
|
@@ -52,8 +50,12 @@ end)
|
|
52
50
|
klass.create! :name => 'fifth', :description => 'Fifth field'
|
53
51
|
klass.create! :name => 'sixth', :description => 'Sixth field'
|
54
52
|
end
|
53
|
+
[BrokenEnumeration].each do |klass|
|
54
|
+
klass.create! :name => '33108', :description => '33108 field'
|
55
|
+
end
|
55
56
|
EnumerateAll.acts_as_enumeration :description
|
56
57
|
EnumerateSome.acts_as_enumeration :description
|
58
|
+
BrokenEnumeration.acts_as_enumeration :name
|
57
59
|
end
|
58
60
|
|
59
61
|
def teardown
|
@@ -84,6 +86,7 @@ end)
|
|
84
86
|
assert EnumerateAll::FirstField,Enumerate.first.id
|
85
87
|
assert EnumerateAll.FIRSTFIELD,Enumerate.first.id
|
86
88
|
assert EnumerateAll.FirstField,Enumerate.first.id
|
89
|
+
assert BrokenEnumeration._33108,BrokenEnumeration.first.id
|
87
90
|
end
|
88
91
|
|
89
92
|
def test_sti
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_enumeration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-05-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|