jeffp-enumerated_attribute 0.1.2 → 0.1.4
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/.gitignore +1 -1
- data/CHANGELOG.rdoc +11 -0
- data/README.rdoc +90 -6
- data/Rakefile +20 -24
- data/lib/enumerated_attribute.rb +274 -107
- data/spec/active_record/active_record_spec.rb +244 -0
- data/spec/active_record/cfg.rb +3 -0
- data/spec/active_record/race_car.rb +10 -0
- data/spec/active_record/single_table_inheritance_spec.rb +0 -0
- data/spec/active_record/test_in_memory.rb +21 -0
- data/spec/car.rb +46 -16
- data/spec/new_and_method_missing_spec.rb +73 -0
- data/spec/plural.rb +8 -0
- data/spec/{tractor_spec.rb → poro_spec.rb} +40 -6
- data/spec/tractor.rb +3 -3
- metadata +13 -6
- data/spec/car_spec.rb +0 -21
@@ -1,7 +1,39 @@
|
|
1
1
|
require 'tractor'
|
2
|
+
require 'plural'
|
3
|
+
|
4
|
+
describe "Plural" do
|
5
|
+
it "should have plural accessor :boxes for :box" do
|
6
|
+
p=Plural.new
|
7
|
+
p.methods.should include("boxes")
|
8
|
+
p.boxes.should == [:small, :medium, :large]
|
9
|
+
end
|
10
|
+
it "should have plural accessor :batches for :batch" do
|
11
|
+
p=Plural.new
|
12
|
+
p.methods.should include("batches")
|
13
|
+
p.batches.should == [:none, :daily, :weekly]
|
14
|
+
end
|
15
|
+
it "should have plural accessor :cherries for :cherry" do
|
16
|
+
p=Plural.new
|
17
|
+
p.methods.should include("cherries")
|
18
|
+
p.cherries.should == [:red, :green, :yellow]
|
19
|
+
end
|
20
|
+
it "should have plural accessor :guys for :guy" do
|
21
|
+
p=Plural.new
|
22
|
+
p.methods.should include("guys")
|
23
|
+
p.guys.should == [:handsome, :funny, :cool]
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
2
27
|
|
3
28
|
describe "Tractor" do
|
4
|
-
|
29
|
+
|
30
|
+
it "should initialize :gear for two instances of the same class" do
|
31
|
+
t=Tractor.new
|
32
|
+
t.gear.should == :neutral
|
33
|
+
s=Tractor.new
|
34
|
+
s.gear.should == :neutral
|
35
|
+
end
|
36
|
+
|
5
37
|
it "should dynamically create :plow_nil? and :plow_not_nil?" do
|
6
38
|
t=Tractor.new
|
7
39
|
t.plow_nil?.should be_false
|
@@ -35,7 +67,8 @@ describe "Tractor" do
|
|
35
67
|
t.gear = :neutral
|
36
68
|
t.not_driving?.should be_true
|
37
69
|
end
|
38
|
-
|
70
|
+
|
71
|
+
=begin
|
39
72
|
it "should have getter but no setter for :temperature" do
|
40
73
|
Tractor.instance_methods.should_not include('temperature=')
|
41
74
|
Tractor.instance_methods.should include('temperature')
|
@@ -45,10 +78,11 @@ describe "Tractor" do
|
|
45
78
|
Tractor.instance_methods.should_not include('ignition')
|
46
79
|
Tractor.instance_methods.should include('ignition=')
|
47
80
|
end
|
81
|
+
=end
|
48
82
|
|
49
83
|
it "should be able to set :plow to nil" do
|
50
84
|
t=Tractor.new
|
51
|
-
lambda { t.plow = nil }.should_not raise_error(
|
85
|
+
lambda { t.plow = nil }.should_not raise_error(EnumeratedAttribute::InvalidEnumeration)
|
52
86
|
end
|
53
87
|
|
54
88
|
it "should have method :plow_nil? that operates correctly" do
|
@@ -60,9 +94,9 @@ describe "Tractor" do
|
|
60
94
|
t.plow_nil?.should be_true
|
61
95
|
end
|
62
96
|
|
63
|
-
it "should raise
|
97
|
+
it "should raise EnumeratedAttribute::InvalidEnumeration when setting :gear to nil" do
|
64
98
|
t=Tractor.new
|
65
|
-
lambda{ t.gear = nil }.should raise_error(
|
99
|
+
lambda{ t.gear = nil }.should raise_error(EnumeratedAttribute::InvalidEnumeration)
|
66
100
|
end
|
67
101
|
|
68
102
|
it "should have respond_to? method for :gear_is_in_neutral?" do
|
@@ -285,7 +319,7 @@ describe "Tractor" do
|
|
285
319
|
|
286
320
|
it "should raise error when set gear attribute to :broken" do
|
287
321
|
t = Tractor.new
|
288
|
-
lambda { t.gear= :broken }.should raise_error(
|
322
|
+
lambda { t.gear= :broken }.should raise_error(EnumeratedAttribute::InvalidEnumeration)
|
289
323
|
end
|
290
324
|
|
291
325
|
it "should have name attribute initially set to 'old faithful'" do
|
data/spec/tractor.rb
CHANGED
@@ -15,7 +15,7 @@ class Tractor
|
|
15
15
|
enumerated_attribute :gear, %w(reverse ^neutral first second over_drive) do
|
16
16
|
parked? is :neutral
|
17
17
|
driving? is [:first, :second, :over_drive]
|
18
|
-
not_parked?
|
18
|
+
not_parked? is_not :neutral
|
19
19
|
not_driving? is_not [:first, :second, :over_drive]
|
20
20
|
upshift { self.gear_is_in_over_drive? ? self.gear : self.gear_next }
|
21
21
|
downshift { self.driving? ? self.gear_previous : self.gear }
|
@@ -37,7 +37,7 @@ class Tractor
|
|
37
37
|
decrementor :side_light_down
|
38
38
|
end
|
39
39
|
|
40
|
-
enum_attr_reader :temperature, %w(low med high)
|
41
|
-
enum_attr_writer :ignition, %w(^off activate)
|
40
|
+
#enum_attr_reader :temperature, %w(low med high)
|
41
|
+
#enum_attr_writer :ignition, %w(^off activate)
|
42
42
|
|
43
43
|
end
|
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.1.
|
4
|
+
version: 0.1.4
|
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-07-
|
12
|
+
date: 2009-07-14 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -23,10 +23,17 @@ extra_rdoc_files: []
|
|
23
23
|
|
24
24
|
files:
|
25
25
|
- lib/enumerated_attribute.rb
|
26
|
+
- spec/active_record
|
27
|
+
- spec/active_record/active_record_spec.rb
|
28
|
+
- spec/active_record/cfg.rb
|
29
|
+
- spec/active_record/race_car.rb
|
30
|
+
- spec/active_record/single_table_inheritance_spec.rb
|
31
|
+
- spec/active_record/test_in_memory.rb
|
26
32
|
- spec/car.rb
|
27
|
-
- spec/
|
33
|
+
- spec/new_and_method_missing_spec.rb
|
34
|
+
- spec/plural.rb
|
35
|
+
- spec/poro_spec.rb
|
28
36
|
- spec/tractor.rb
|
29
|
-
- spec/tractor_spec.rb
|
30
37
|
- CHANGELOG.rdoc
|
31
38
|
- init.rb
|
32
39
|
- LICENSE
|
@@ -60,5 +67,5 @@ signing_key:
|
|
60
67
|
specification_version: 3
|
61
68
|
summary: Defines enumerated attributes, initial state and dynamic state methods.
|
62
69
|
test_files:
|
63
|
-
- spec/
|
64
|
-
- spec/
|
70
|
+
- spec/new_and_method_missing_spec.rb
|
71
|
+
- spec/poro_spec.rb
|
data/spec/car_spec.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'car'
|
2
|
-
|
3
|
-
#used to test that method_missing chaining plays nice in inheritance situation
|
4
|
-
|
5
|
-
describe "Car" do
|
6
|
-
|
7
|
-
it "should not hit Car method_missing when calling dynamic state method :gear_is_in_reverse?" do
|
8
|
-
c = Car.new
|
9
|
-
c.gear_is_in_reverse?
|
10
|
-
c.car_method_hit.should be_false
|
11
|
-
c.vehicle_method_hit.should be_false
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should hit Car and Vehicle method_missing when not calling supported dynamic state method" do
|
15
|
-
c = Car.new
|
16
|
-
c.parking_break_is_on?
|
17
|
-
c.car_method_hit.should be_true
|
18
|
-
c.vehicle_method_hit.should be_true
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|