coded_options 1.0.1 → 1.0.2
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.md +11 -0
- data/lib/coded_options/base.rb +2 -1
- data/lib/coded_options/version.rb +1 -1
- data/spec/coded_options_spec.rb +24 -23
- metadata +3 -3
data/README.md
CHANGED
@@ -43,6 +43,17 @@ GENDER will return a hash (the exact hash above), not an array. GENDER_OPTIONS
|
|
43
43
|
will return an array suitable for select tags. The array will be ordered
|
44
44
|
numerically by the keys of the hash.
|
45
45
|
|
46
|
+
The initial value used defaults to 0 but can be changed via the following two methods:
|
47
|
+
|
48
|
+
coded_options :state => %w(active closed),
|
49
|
+
:initial_value => 42
|
50
|
+
|
51
|
+
CodedOptions.initial_value = 42
|
52
|
+
coded_options :state => %w(active closed)
|
53
|
+
|
54
|
+
Obviously the first method only affects that statement whereas the second method
|
55
|
+
is global.
|
56
|
+
|
46
57
|
If you want to use this with MongoDB, just add
|
47
58
|
|
48
59
|
include CodedOptions
|
data/lib/coded_options/base.rb
CHANGED
data/spec/coded_options_spec.rb
CHANGED
@@ -3,6 +3,30 @@ require "active_support/inflector"
|
|
3
3
|
|
4
4
|
describe CodedOptions do
|
5
5
|
|
6
|
+
describe "given a hash" do
|
7
|
+
|
8
|
+
before(:all) do
|
9
|
+
class Bar
|
10
|
+
attr_accessor :state_id, :foo_id
|
11
|
+
|
12
|
+
include CodedOptions
|
13
|
+
coded_options :state => %w(initial active closed),
|
14
|
+
:foo => %w(bar quux baz)
|
15
|
+
end
|
16
|
+
|
17
|
+
@bar = Bar.new
|
18
|
+
@bar.state_id = 0
|
19
|
+
@bar.foo_id = 1
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should call setup_coded_options for each field" do
|
23
|
+
@bar.state.should == "initial"
|
24
|
+
@bar.foo.should == "quux"
|
25
|
+
Bar::STATE_OPTIONS = [["initial", 0], ["active", 1], ["closed", 2]]
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
6
30
|
describe "changing initial value" do
|
7
31
|
it "should use the initial value given when set manually" do
|
8
32
|
CodedOptions.initial_value = 1
|
@@ -78,29 +102,6 @@ describe CodedOptions do
|
|
78
102
|
|
79
103
|
end
|
80
104
|
|
81
|
-
describe "given a hash" do
|
82
|
-
|
83
|
-
before(:all) do
|
84
|
-
class Bar
|
85
|
-
attr_accessor :state_id, :foo_id
|
86
|
-
|
87
|
-
include CodedOptions
|
88
|
-
coded_options :state => %w(initial active closed),
|
89
|
-
:foo => %w(bar quux baz)
|
90
|
-
end
|
91
|
-
|
92
|
-
@bar = Bar.new
|
93
|
-
@bar.state_id = 0
|
94
|
-
@bar.foo_id = 1
|
95
|
-
end
|
96
|
-
|
97
|
-
it "should call setup_coded_options for each field" do
|
98
|
-
@bar.state.should == "initial"
|
99
|
-
@bar.foo.should == "quux"
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
105
|
describe "given a single field with a hash for the values" do
|
105
106
|
|
106
107
|
before(:all) do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coded_options
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 2
|
10
|
+
version: 1.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jason Dew
|