jeffp-enumerated_attribute 0.2.2 → 0.2.3
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/README.rdoc +4 -0
- data/Rakefile +15 -1
- data/lib/enumerated_attribute/attribute.rb +44 -24
- data/lib/enumerated_attribute/attribute/attribute_descriptor.rb +2 -1
- data/lib/enumerated_attribute/integrations/active_record.rb +19 -13
- data/lib/enumerated_attribute/integrations/object.rb +8 -6
- data/lib/jeffp-enumerated_attribute.rb +1 -0
- data/spec/active_record/active_record_spec.rb +74 -2
- data/spec/active_record/inheritance_classes.rb +19 -0
- data/spec/active_record/inheritance_spec.rb +60 -0
- data/spec/active_record/race_car.rb +5 -0
- data/spec/cfg.rb +2 -1
- data/spec/inheritance_classes.rb +16 -0
- data/spec/inheritance_spec.rb +80 -0
- metadata +8 -2
data/README.rdoc
CHANGED
@@ -510,6 +510,10 @@ overwriting the plugin's methods. The best approach is shown here:
|
|
510
510
|
enum_attr temp:, %w(cold warm hot boiling)
|
511
511
|
end
|
512
512
|
|
513
|
+
==== ActiveRecord
|
514
|
+
|
515
|
+
ActiveRecord's write_attribute and read_attribute methods do not support symbols for enumerated attributes.
|
516
|
+
|
513
517
|
|
514
518
|
== Testing
|
515
519
|
|
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ require 'rake/contrib/sshpublisher'
|
|
5
5
|
|
6
6
|
spec = Gem::Specification.new do |s|
|
7
7
|
s.name = 'enumerated_attribute'
|
8
|
-
s.version = '0.2.
|
8
|
+
s.version = '0.2.3'
|
9
9
|
s.platform = Gem::Platform::RUBY
|
10
10
|
s.description = 'Enumerated model attributes and view helpers'
|
11
11
|
s.summary = 'Add enumerated attributes to your models and expose them in drop-down lists in your views'
|
@@ -37,6 +37,20 @@ namespace :spec do
|
|
37
37
|
#t.rcov_dir = 'coverage'
|
38
38
|
#t.rcov_opts = ['--exclude', "kernel,load-diff-lcs\.rb,instance_exec\.rb,lib/spec.rb,lib/spec/runner.rb,^spec/*,bin/spec,examples,/gems,/Library/Ruby,\.autotest,#{ENV['GEM_HOME']}"]
|
39
39
|
end
|
40
|
+
=begin
|
41
|
+
Spec::Rake::SpecTask.new(:sub) do |t|
|
42
|
+
t.spec_files = FileList['spec/inheritance_spec.rb']
|
43
|
+
t.libs << 'lib' << 'spec'
|
44
|
+
t.rcov = false
|
45
|
+
t.spec_opts = ['--options', 'spec/spec.opts']
|
46
|
+
end
|
47
|
+
Spec::Rake::SpecTask.new(:poro) do |t|
|
48
|
+
t.spec_files = FileList['spec/poro_spec.rb']
|
49
|
+
t.libs << 'lib' << 'spec'
|
50
|
+
t.rcov = false
|
51
|
+
t.spec_opts = ['--options', 'spec/spec.opts']
|
52
|
+
end
|
53
|
+
=end
|
40
54
|
desc "Run ActiveRecord integration specs"
|
41
55
|
Spec::Rake::SpecTask.new(:active_record) do |t|
|
42
56
|
t.spec_files = FileList['spec/active_record/*_spec.rb']
|
@@ -44,10 +44,25 @@ module EnumeratedAttribute
|
|
44
44
|
enums = enums.map{|v| (v =~ /^\^/ ? (initial_value ||= v[1, v.length-1].to_sym) : v.to_sym )}
|
45
45
|
|
46
46
|
class_eval <<-ATTRIB
|
47
|
-
def self.enumerated_attributes
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
def self.enumerated_attributes(all=true)
|
48
|
+
return @enumerated_attributes unless all
|
49
|
+
return @all_enumerated_attributes_cache if @all_enumerated_attributes_cache
|
50
|
+
@all_enumerated_attributes_cache = @enumerated_attributes ? @enumerated_attributes.dup : {}
|
51
|
+
klass = self.superclass
|
52
|
+
while (klass)
|
53
|
+
if (klass.respond_to?(:enumerated_attributes))
|
54
|
+
if (sub_enums = klass.enumerated_attributes)
|
55
|
+
@all_enumerated_attributes_cache = sub_enums.merge @all_enumerated_attributes_cache
|
56
|
+
break
|
57
|
+
end
|
58
|
+
end
|
59
|
+
klass = klass.superclass
|
60
|
+
end
|
61
|
+
@all_enumerated_attributes_cache
|
62
|
+
end
|
63
|
+
def enums(attr); self.class.enumerated_attributes[attr.to_sym]; end
|
64
|
+
@enumerated_attributes ||= {}
|
65
|
+
@enumerated_attributes[:#{attr_name}] = AttributeDescriptor.new(:#{attr_name}, #{enums.inspect}, #{opts.inspect})
|
51
66
|
ATTRIB
|
52
67
|
|
53
68
|
#define_enumerated_attribute_[writer, reader] may be modified in a named Integrations module (see Integrations::ActiveRecord)
|
@@ -62,14 +77,14 @@ module EnumeratedAttribute
|
|
62
77
|
|
63
78
|
def self.has_enumerated_attribute?(name)
|
64
79
|
return(false) if name.nil?
|
65
|
-
|
80
|
+
self.enumerated_attributes.key?(name.to_sym)
|
66
81
|
end
|
67
82
|
def self.enumerated_attribute_allows_nil?(name)
|
68
|
-
return(false) unless (descriptor =
|
83
|
+
return(false) unless (descriptor = self.enumerated_attributes[name.to_sym])
|
69
84
|
descriptor.allows_nil?
|
70
85
|
end
|
71
86
|
def self.enumerated_attribute_allows_value?(name, value)
|
72
|
-
return (false) unless (descriptor =
|
87
|
+
return (false) unless (descriptor = self.enumerated_attributes[name.to_sym])
|
73
88
|
return descriptor.allows_nil? if (value == nil || value == '')
|
74
89
|
descriptor.allows_value?(value)
|
75
90
|
end
|
@@ -103,8 +118,11 @@ module EnumeratedAttribute
|
|
103
118
|
end
|
104
119
|
|
105
120
|
def initialize_enumerated_attributes(only_if_nil = false)
|
106
|
-
self.class.enumerated_attribute_initial_value_list.each do |k,v|
|
107
|
-
|
121
|
+
#self.class.enumerated_attribute_initial_value_list.each do |k,v|
|
122
|
+
# self.write_enumerated_attribute(k, v) unless (only_if_nil && read_enumerated_attribute(k) != nil)
|
123
|
+
#end
|
124
|
+
self.class.enumerated_attributes.each do |k,v|
|
125
|
+
self.write_enumerated_attribute(k, v.init_value) unless (only_if_nil && read_enumerated_attribute(k) != nil)
|
108
126
|
end
|
109
127
|
end
|
110
128
|
|
@@ -116,7 +134,7 @@ module EnumeratedAttribute
|
|
116
134
|
middle = meth_name.chop #remove the ?
|
117
135
|
|
118
136
|
attr = nil
|
119
|
-
|
137
|
+
self.class.enumerated_attributes.keys.each do |name|
|
120
138
|
if middle.sub!(Regexp.new("^"+name.to_s), "")
|
121
139
|
attr = name; break
|
122
140
|
end
|
@@ -124,7 +142,7 @@ module EnumeratedAttribute
|
|
124
142
|
|
125
143
|
value = nil
|
126
144
|
attr_sym = attr ? attr.to_sym : nil
|
127
|
-
if (descriptor =
|
145
|
+
if (descriptor = self.class.enumerated_attributes[attr_sym])
|
128
146
|
descriptor.enums.each do |v|
|
129
147
|
if middle.sub!(Regexp.new(v.to_s+"$"), "")
|
130
148
|
value = v; break
|
@@ -132,7 +150,7 @@ module EnumeratedAttribute
|
|
132
150
|
end
|
133
151
|
else
|
134
152
|
#search through enum values one at time and identify any ambiguities
|
135
|
-
|
153
|
+
self.class.enumerated_attributes.each do |attr_key,descriptor|
|
136
154
|
descriptor.enums.each do|v|
|
137
155
|
if middle.match(v.to_s+"$")
|
138
156
|
raise(AmbiguousMethod, meth_name+" is ambiguous, use something like "+attr_sym.to_s+(middle[0,1]=='_'? '' : '_')+middle+"? or "+attr_key.to_s+(middle[0,1]=='_'? '' : '_')+middle+"?", caller) if attr_sym
|
@@ -172,7 +190,7 @@ module EnumeratedAttribute
|
|
172
190
|
#create state and action methods from block
|
173
191
|
initial_value = opts[:init] || initial_value
|
174
192
|
if block_given?
|
175
|
-
m = EnumeratedAttribute::MethodDefinitionDSL.new(self, enumerated_attributes[attr_sym]) #attr_name, enums)
|
193
|
+
m = EnumeratedAttribute::MethodDefinitionDSL.new(self, self.enumerated_attributes(false)[attr_sym]) #attr_name, enums)
|
176
194
|
m.instance_eval(&block)
|
177
195
|
initial_value = m.initial_value || initial_value
|
178
196
|
plural_name = m.pluralized_name || plural_name
|
@@ -183,31 +201,33 @@ module EnumeratedAttribute
|
|
183
201
|
#define the enum values accessor
|
184
202
|
class_eval <<-ENUM
|
185
203
|
def #{plural_name}
|
186
|
-
|
204
|
+
self.class.enumerated_attributes[:#{attr_name}]
|
187
205
|
end
|
188
206
|
def #{incrementor}
|
189
|
-
z =
|
207
|
+
z = self.class.enumerated_attributes[:#{attr_name}].enums
|
190
208
|
index = z.index(read_enumerated_attribute(:#{attr_name}))
|
191
209
|
write_enumerated_attribute(:#{attr_name}, z[index >= z.size-1 ? 0 : index+1])
|
192
210
|
end
|
193
211
|
def #{decrementor}
|
194
|
-
z =
|
212
|
+
z = self.class.enumerated_attributes[:#{attr_name}].enums
|
195
213
|
index = z.index(read_enumerated_attribute(:#{attr_name}))
|
196
214
|
write_enumerated_attribute(:#{attr_name}, z[index > 0 ? index-1 : z.size-1])
|
197
215
|
end
|
198
216
|
ENUM
|
199
217
|
|
200
|
-
unless @enumerated_attribute_init
|
218
|
+
#unless defined?(@enumerated_attribute_init)
|
201
219
|
define_enumerated_attribute_new_method
|
202
|
-
end
|
203
|
-
|
204
|
-
if (initial_value = opts[:init] || initial_value)
|
205
|
-
|
206
|
-
end
|
220
|
+
#end
|
221
|
+
#@enumerated_attribute_init ||= {}
|
222
|
+
#if (initial_value = opts[:init] || initial_value)
|
223
|
+
# @enumerated_attribute_init[attr_sym] = initial_value
|
224
|
+
#end
|
207
225
|
class_eval do
|
208
|
-
|
209
|
-
|
226
|
+
@enumerated_attributes ||={}
|
227
|
+
if (initial_value = opts[:init] || initial_value)
|
228
|
+
@enumerated_attributes[attr_sym].init_value = initial_value
|
210
229
|
end
|
230
|
+
#def self.enumerated_attribute_initial_value_list; @enumerated_attribute_init; end
|
211
231
|
end
|
212
232
|
|
213
233
|
def self.define_enumerated_attribute_custom_method(symbol, attr_name, value, negated)
|
@@ -3,6 +3,7 @@ module EnumeratedAttribute
|
|
3
3
|
module Attribute
|
4
4
|
class AttributeDescriptor < Array
|
5
5
|
attr_reader :name
|
6
|
+
attr_accessor :init_value
|
6
7
|
|
7
8
|
def initialize(name, enums=[], opts={})
|
8
9
|
super enums
|
@@ -39,7 +40,7 @@ module EnumeratedAttribute
|
|
39
40
|
@labels_hash[enum_value.to_sym] = label_string
|
40
41
|
end
|
41
42
|
|
42
|
-
|
43
|
+
protected
|
43
44
|
def reset_labels
|
44
45
|
@labels_array = nil
|
45
46
|
@select_options = nil
|
@@ -50,9 +50,13 @@ module EnumeratedAttribute
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def attributes
|
53
|
-
|
54
|
-
|
53
|
+
atts = super
|
54
|
+
atts.each do |k,v|
|
55
|
+
if self.class.has_enumerated_attribute?(k)
|
56
|
+
atts[k] = v.to_sym if v
|
57
|
+
end
|
55
58
|
end
|
59
|
+
atts
|
56
60
|
end
|
57
61
|
|
58
62
|
def [](attr_name); read_enumerated_attribute(attr_name); end
|
@@ -73,9 +77,9 @@ module EnumeratedAttribute
|
|
73
77
|
|
74
78
|
def instantiate(record)
|
75
79
|
object = super(record)
|
76
|
-
|
77
|
-
unless object.has_attribute?(k)
|
78
|
-
object.write_enumerated_attribute(k, v)
|
80
|
+
self.enumerated_attributes.each do |k,v|
|
81
|
+
unless object.has_attribute?(k) #only initialize the non-column enumerated attributes
|
82
|
+
object.write_enumerated_attribute(k, v.init_value)
|
79
83
|
end
|
80
84
|
end
|
81
85
|
object
|
@@ -84,14 +88,16 @@ module EnumeratedAttribute
|
|
84
88
|
def define_enumerated_attribute_new_method
|
85
89
|
class_eval <<-INITVAL
|
86
90
|
class << self
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
91
|
+
unless method_defined?(:new_without_enumerated_attribute)
|
92
|
+
alias_method :new_without_enumerated_attribute, :new
|
93
|
+
def new(*args, &block)
|
94
|
+
result = new_without_enumerated_attribute(*args, &block)
|
95
|
+
params = (!args.empty? && args.first.instance_of?(Hash)) ? args.first : {}
|
96
|
+
params.each { |k, v| result.write_enumerated_attribute(k, v) }
|
97
|
+
result.initialize_enumerated_attributes(true)
|
98
|
+
yield result if block_given?
|
99
|
+
result
|
100
|
+
end
|
95
101
|
end
|
96
102
|
end
|
97
103
|
INITVAL
|
@@ -27,12 +27,14 @@ module EnumeratedAttribute
|
|
27
27
|
def define_enumerated_attribute_new_method
|
28
28
|
class_eval <<-NEWMETH
|
29
29
|
class << self
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
unless method_defined?(:new_without_enumerated_attribute)
|
31
|
+
alias_method :new_without_enumerated_attribute, :new
|
32
|
+
def new(*args, &block)
|
33
|
+
result = new_without_enumerated_attribute(*args)
|
34
|
+
result.initialize_enumerated_attributes
|
35
|
+
yield result if block_given?
|
36
|
+
result
|
37
|
+
end
|
36
38
|
end
|
37
39
|
end
|
38
40
|
NEWMETH
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'enumerated_attribute'
|
@@ -192,6 +192,42 @@ describe "RaceCar" do
|
|
192
192
|
r=RaceCar.new
|
193
193
|
lambda { r.attributes = {:lights=>'off', :gear =>:drive} }.should raise_error(EnumeratedAttribute::InvalidEnumeration)
|
194
194
|
end
|
195
|
+
|
196
|
+
=begin
|
197
|
+
#do not write symbols to enumerated column attributes using write_attribute
|
198
|
+
#do not user read_attribute to read an enumerated column attribute
|
199
|
+
it "should write enumeration with write_attribute" do
|
200
|
+
r=RaceCar.new
|
201
|
+
r.write_attribute(:gear, :first)
|
202
|
+
r.gear.should == :first
|
203
|
+
r.save!
|
204
|
+
|
205
|
+
s=RaceCar.find r.id
|
206
|
+
s.gear.should == :first
|
207
|
+
s.write_attribute(:gear, :second)
|
208
|
+
s.save!
|
209
|
+
|
210
|
+
t=RaceCar.find s.id
|
211
|
+
t.gear.should == :second
|
212
|
+
end
|
213
|
+
|
214
|
+
it "should raise error when setting enumerated column attribute to invalid enum using write_attribute" do
|
215
|
+
r=RaceCar.new
|
216
|
+
lambda { r.write_attribute(:gear, :yo) }.should raise_error
|
217
|
+
end
|
218
|
+
=end
|
219
|
+
|
220
|
+
it "should retrieve symbols for enumerations from ActiveRecord :attributes method" do
|
221
|
+
r=RaceCar.new
|
222
|
+
r.gear = :second
|
223
|
+
r.choke = :medium
|
224
|
+
r.lights = 'on'
|
225
|
+
r.save!
|
226
|
+
|
227
|
+
s = RaceCar.find(r.id)
|
228
|
+
s.attributes['gear'].should == :second
|
229
|
+
s.attributes['lights'].should == 'on'
|
230
|
+
end
|
195
231
|
|
196
232
|
it "should update_attribute for enumerated column attribute" do
|
197
233
|
r=RaceCar.new
|
@@ -231,12 +267,48 @@ describe "RaceCar" do
|
|
231
267
|
end
|
232
268
|
|
233
269
|
it "should provide symbol values for enumerated column attributes from the :attributes method" do
|
270
|
+
r=RaceCar.new
|
271
|
+
r.lights = 'on'
|
272
|
+
r.save!
|
273
|
+
|
274
|
+
s=RaceCar.find r.id
|
275
|
+
s.attributes['gear'].should == :neutral
|
276
|
+
end
|
277
|
+
|
278
|
+
it "should provide normal values for non-enumerated column attributes from the :attributes method" do
|
279
|
+
r=RaceCar.new
|
280
|
+
r.lights = 'on'
|
281
|
+
r.save!
|
282
|
+
|
283
|
+
s=RaceCar.find r.id
|
284
|
+
s.attributes['lights'].should == 'on'
|
234
285
|
end
|
235
286
|
|
236
|
-
it "should
|
287
|
+
it "should raise InvalidEnumeration when setting invalid enumertion value with :attributes= method" do
|
288
|
+
r=RaceCar.new
|
289
|
+
lambda { r.attributes = {:gear=>:yo, :lights=>'on'} }.should raise_error(EnumeratedAttribute::InvalidEnumeration)
|
237
290
|
end
|
238
291
|
|
239
|
-
it "should
|
292
|
+
it "should not set init value for enumerated column attribute saved as nil" do
|
293
|
+
r=RaceCar.new
|
294
|
+
r.gear = nil
|
295
|
+
r.lights = 'on'
|
296
|
+
r.save!
|
297
|
+
|
298
|
+
s=RaceCar.find r.id
|
299
|
+
s.gear.should == nil
|
300
|
+
s.lights.should == 'on'
|
301
|
+
end
|
302
|
+
|
303
|
+
it "should not set init value for enumerated column attributes saved as value" do
|
304
|
+
r=RaceCar.new
|
305
|
+
r.gear = :second
|
306
|
+
r.lights = 'all'
|
307
|
+
r.save!
|
308
|
+
|
309
|
+
s=RaceCar.find r.id
|
310
|
+
s.gear.should == :second
|
311
|
+
s.lights.should == 'all'
|
240
312
|
end
|
241
313
|
|
242
314
|
it "should save and retrieve its name" do
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'race_car'
|
2
|
+
|
3
|
+
class SubRaceCar < RaceCar
|
4
|
+
set_table_name "race_cars"
|
5
|
+
|
6
|
+
enum_attr :extra, %w(^one two three four)
|
7
|
+
end
|
8
|
+
|
9
|
+
class SubRaceCar2 < RaceCar
|
10
|
+
set_table_name "race_cars"
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
class SubRaceCar3 < RaceCar
|
15
|
+
set_table_name "race_cars"
|
16
|
+
|
17
|
+
enum_attr :gear, %w(reverse neutral ^first second third over_drive)
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'test_in_memory'
|
2
|
+
require 'enumerated_attribute'
|
3
|
+
require 'active_record'
|
4
|
+
require 'inheritance_classes'
|
5
|
+
|
6
|
+
def one_to_four; [:one, :two, :three, :four]; end
|
7
|
+
def gear1; [:reverse, :neutral, :first, :second, :over_drive]; end
|
8
|
+
def gear2; [:reverse, :neutral, :first, :second, :third, :over_drive]; end
|
9
|
+
def choke; [:none, :medium, :full]; end
|
10
|
+
|
11
|
+
describe "SubRaceCar" do
|
12
|
+
it "should have :gear init to :neutral" do
|
13
|
+
o=SubRaceCar.new
|
14
|
+
o.gear.should == :neutral
|
15
|
+
o.enums(:gear).should == gear1
|
16
|
+
o.gear_previous.should == :reverse
|
17
|
+
end
|
18
|
+
it "should have :choke init to :none" do
|
19
|
+
o=SubRaceCar.new
|
20
|
+
o.choke.should == :none
|
21
|
+
o.enums(:choke).should == choke
|
22
|
+
o.choke_previous.should == :full
|
23
|
+
end
|
24
|
+
it "should have :extra init to :one" do
|
25
|
+
o=SubRaceCar.new
|
26
|
+
o.extra.should == :one
|
27
|
+
o.enums(:extra).should == one_to_four
|
28
|
+
o.extra_previous.should == :four
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "SubRaceCar2" do
|
33
|
+
it "should have :gear init to :neutral" do
|
34
|
+
o=SubRaceCar2.new
|
35
|
+
o.gear.should == :neutral
|
36
|
+
o.enums(:gear).should == gear1
|
37
|
+
o.gear_previous.should == :reverse
|
38
|
+
end
|
39
|
+
it "should have :choke init to :none" do
|
40
|
+
o=SubRaceCar2.new
|
41
|
+
o.choke.should == :none
|
42
|
+
o.enums(:choke).should == choke
|
43
|
+
o.choke_previous.should == :full
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "SubRaceCar3" do
|
48
|
+
it "should have overridden :gear init to :first" do
|
49
|
+
o=SubRaceCar3.new
|
50
|
+
o.gear.should == :first
|
51
|
+
o.enums(:gear).should == gear2
|
52
|
+
o.gear_previous.should == :neutral
|
53
|
+
end
|
54
|
+
it "should have :choke init to :none" do
|
55
|
+
o=SubRaceCar3.new
|
56
|
+
o.choke.should == :none
|
57
|
+
o.enums(:choke).should == choke
|
58
|
+
o.choke_previous.should == :full
|
59
|
+
end
|
60
|
+
end
|
data/spec/cfg.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'enumerated_attribute'
|
2
|
+
|
3
|
+
class Base
|
4
|
+
enum_attr :base1, %w(^one two three four)
|
5
|
+
enum_attr :inherited1, %w(^one two three four)
|
6
|
+
enum_attr :inherited2, %w(^one two three four)
|
7
|
+
end
|
8
|
+
|
9
|
+
class Sub < Base
|
10
|
+
enum_attr :sub1, %w(one ^two three four)
|
11
|
+
enum_attr :inherited1, %w(one ^two three four)
|
12
|
+
enum_attr :inherited2, %w(^five six seven eight)
|
13
|
+
end
|
14
|
+
|
15
|
+
class Sub2 < Base
|
16
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'inheritance_classes'
|
2
|
+
|
3
|
+
def one_to_four; [:one, :two, :three, :four]; end
|
4
|
+
def five_to_eight; [:five, :six, :seven, :eight]; end
|
5
|
+
|
6
|
+
describe "Base" do
|
7
|
+
it "should have :base1 init to :one" do
|
8
|
+
o=Base.new
|
9
|
+
o.base1.should == :one
|
10
|
+
o.enums(:base1).should == one_to_four
|
11
|
+
o.base1_previous.should == :four
|
12
|
+
end
|
13
|
+
it "should have :inherited1 init to :one" do
|
14
|
+
o=Base.new
|
15
|
+
o.inherited1.should == :one
|
16
|
+
o.enums(:inherited1).should == one_to_four
|
17
|
+
o.inherited1_previous.should == :four
|
18
|
+
end
|
19
|
+
it "should have :inherited2 init to :one" do
|
20
|
+
o=Base.new
|
21
|
+
o.inherited2.should == :one
|
22
|
+
o.enums(:inherited2).should == one_to_four
|
23
|
+
o.inherited2_previous.should == :four
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "Sub<Base" do
|
28
|
+
it "should instantiate an object" do
|
29
|
+
lambda { s=Sub.new }.should_not raise_error
|
30
|
+
end
|
31
|
+
it "should have :sub1 init to :two" do
|
32
|
+
o=Sub.new
|
33
|
+
o.sub1.should == :two
|
34
|
+
o.enums(:sub1).should == one_to_four
|
35
|
+
o.sub1_previous.should == :one
|
36
|
+
end
|
37
|
+
it "should have :base1 init to :one" do
|
38
|
+
o=Sub.new
|
39
|
+
o.base1.should == :one
|
40
|
+
o.enums(:base1).should == one_to_four
|
41
|
+
o.base1_previous.should == :four
|
42
|
+
end
|
43
|
+
it "should have :inherited1 init to :two" do
|
44
|
+
o=Sub.new
|
45
|
+
o.inherited1.should == :two
|
46
|
+
o.enums(:inherited1).should == one_to_four
|
47
|
+
o.inherited1_previous.should == :one
|
48
|
+
end
|
49
|
+
it "should have :inherited2 init to :five" do
|
50
|
+
o=Sub.new
|
51
|
+
o.inherited2.should == :five
|
52
|
+
o.enums(:inherited2).should == five_to_eight
|
53
|
+
o.inherited2_previous.should == :eight
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "Sub2<Base" do
|
58
|
+
it "should instantiate an object" do
|
59
|
+
lambda {s=Sub2.new}.should_not raise_error
|
60
|
+
end
|
61
|
+
it "should have :base1 init to :one" do
|
62
|
+
o=Sub2.new
|
63
|
+
o.base1.should == :one
|
64
|
+
o.enums(:base1).should == one_to_four
|
65
|
+
o.base1_previous.should == :four
|
66
|
+
end
|
67
|
+
it "should have :inherited1 init to :one" do
|
68
|
+
o=Sub2.new
|
69
|
+
o.inherited1.should == :one
|
70
|
+
o.enums(:inherited1).should == one_to_four
|
71
|
+
o.inherited1_previous.should == :four
|
72
|
+
end
|
73
|
+
it "should have :inherited2 init to :one" do
|
74
|
+
o=Sub2.new
|
75
|
+
o.inherited2.should == :one
|
76
|
+
o.enums(:inherited2).should == one_to_four
|
77
|
+
o.inherited2_previous.should == :four
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jeffp-enumerated_attribute
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Patmon
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-08-
|
12
|
+
date: 2009-08-08 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -35,16 +35,21 @@ files:
|
|
35
35
|
- lib/enumerated_attribute/method_definition_dsl.rb
|
36
36
|
- lib/enumerated_attribute/rails_helpers.rb
|
37
37
|
- lib/enumerated_attribute.rb
|
38
|
+
- lib/jeffp-enumerated_attribute.rb
|
38
39
|
- spec/active_record
|
39
40
|
- spec/active_record/active_record_spec.rb
|
40
41
|
- spec/active_record/associations_spec.rb
|
41
42
|
- spec/active_record/association_test_classes.rb
|
42
43
|
- spec/active_record/cfg.rb
|
44
|
+
- spec/active_record/inheritance_classes.rb
|
45
|
+
- spec/active_record/inheritance_spec.rb
|
43
46
|
- spec/active_record/race_car.rb
|
44
47
|
- spec/active_record/single_table_inheritance_spec.rb
|
45
48
|
- spec/active_record/test_in_memory.rb
|
46
49
|
- spec/car.rb
|
47
50
|
- spec/cfg.rb
|
51
|
+
- spec/inheritance_classes.rb
|
52
|
+
- spec/inheritance_spec.rb
|
48
53
|
- spec/new_and_method_missing_spec.rb
|
49
54
|
- spec/plural.rb
|
50
55
|
- spec/poro_spec.rb
|
@@ -175,5 +180,6 @@ signing_key:
|
|
175
180
|
specification_version: 3
|
176
181
|
summary: Add enumerated attributes to your models and expose them in drop-down lists in your views
|
177
182
|
test_files:
|
183
|
+
- spec/inheritance_spec.rb
|
178
184
|
- spec/new_and_method_missing_spec.rb
|
179
185
|
- spec/poro_spec.rb
|