active_enum 1.0.0.rc3 → 1.0.0.rc4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_enum/acts_as_enum.rb +4 -0
- data/lib/active_enum/base.rb +3 -1
- data/lib/active_enum/version.rb +1 -1
- data/spec/active_enum/acts_as_enum_spec.rb +6 -0
- data/spec/active_enum/base_spec.rb +11 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86faf9c711cf0ac0e6cce2450bee21b48d979c7e3feff9db3fde5d89628e2ee3
|
4
|
+
data.tar.gz: 49a52e216f81e72be6ac0ad601281efa6f171d599a7d91d974a2745e3d6ddfd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 817cd0815232eddfad91e4aa95e2e09a9aa13ed04265e0427644255722f257a4da323e9179cbb37a601ccb4f59190c5ac1358cc242db290c0820377947ac83dd
|
7
|
+
data.tar.gz: 42eede1664ec537ba56c5d657baefe168e588955d1b29e7e8c2e346977a2d2ef3f9f02413ee0efdf783639a657a9d677eec619b46c799f82668ee46a3ff5ea09
|
data/lib/active_enum/base.rb
CHANGED
data/lib/active_enum/version.rb
CHANGED
@@ -45,6 +45,12 @@ describe ActiveEnum::ActsAsEnum do
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
context '#values' do
|
49
|
+
it "should return array of arrays containing id and name column values" do
|
50
|
+
expect(Person.values).to eq([[1, 'Dave'], [2, 'John']])
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
48
54
|
context '#to_select' do
|
49
55
|
it "should return array for select helpers" do
|
50
56
|
expect(Person.to_select).to eq([['Dave', 1], ['John', 2]])
|
@@ -24,9 +24,9 @@ describe ActiveEnum::Base do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
describe ".
|
27
|
+
describe ".values" do
|
28
28
|
it 'should return an empty array when no values defined' do
|
29
|
-
expect(define_enum.
|
29
|
+
expect(define_enum.values).to eq([])
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'should return an array of arrays with all values defined as [id, name]' do
|
@@ -34,7 +34,7 @@ describe ActiveEnum::Base do
|
|
34
34
|
value :name => 'Name 1'
|
35
35
|
value :name => 'Name 2'
|
36
36
|
end
|
37
|
-
expect(enum.
|
37
|
+
expect(enum.values).to eq([[1,'Name 1'], [2, 'Name 2']])
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -43,28 +43,28 @@ describe ActiveEnum::Base do
|
|
43
43
|
enum = define_enum do
|
44
44
|
value :id => 1, :name => 'Name'
|
45
45
|
end
|
46
|
-
expect(enum.
|
46
|
+
expect(enum.values).to eq([[1,'Name']])
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'should allow me to define a value with a name only' do
|
50
50
|
enum = define_enum do
|
51
51
|
value :name => 'Name'
|
52
52
|
end
|
53
|
-
expect(enum.
|
53
|
+
expect(enum.values).to eq([[1,'Name']])
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'should allow me to define a value as hash with id as key and name as value' do
|
57
57
|
enum = define_enum do
|
58
58
|
value 1 => 'Name'
|
59
59
|
end
|
60
|
-
expect(enum.
|
60
|
+
expect(enum.values).to eq([[1,'Name']])
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'should allow to define meta data value with extra key value pairs' do
|
64
64
|
enum = define_enum do
|
65
65
|
value :id => 1, :name => 'Name', :description => 'extra'
|
66
66
|
end
|
67
|
-
expect(enum.
|
67
|
+
expect(enum.values).to eq([[1,'Name',{:description => 'extra'}]])
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'should increment value ids when defined without ids' do
|
@@ -72,7 +72,7 @@ describe ActiveEnum::Base do
|
|
72
72
|
value :name => 'Name 1'
|
73
73
|
value :name => 'Name 2'
|
74
74
|
end
|
75
|
-
expect(enum.
|
75
|
+
expect(enum.values).to eq([[1,'Name 1'], [2, 'Name 2']])
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'should raise error if the id is a duplicate' do
|
@@ -117,7 +117,7 @@ describe ActiveEnum::Base do
|
|
117
117
|
value :id => 2, :name => 'Name 2'
|
118
118
|
value :id => 1, :name => 'Name 1'
|
119
119
|
end
|
120
|
-
expect(enum.
|
120
|
+
expect(enum.values).to eq([[1,'Name 1'], [2, 'Name 2']])
|
121
121
|
end
|
122
122
|
|
123
123
|
it 'should return sorted values by id using order setting' do
|
@@ -126,7 +126,7 @@ describe ActiveEnum::Base do
|
|
126
126
|
value :id => 1, :name => 'Name 1'
|
127
127
|
value :id => 2, :name => 'Name 2'
|
128
128
|
end
|
129
|
-
expect(enum.
|
129
|
+
expect(enum.values).to eq([[2, 'Name 2'], [1,'Name 1']])
|
130
130
|
end
|
131
131
|
|
132
132
|
it 'should return sorted values by id using order setting' do
|
@@ -136,7 +136,7 @@ describe ActiveEnum::Base do
|
|
136
136
|
value :id => 1, :name => 'Name 1'
|
137
137
|
value :id => 2, :name => 'Name 2'
|
138
138
|
end
|
139
|
-
expect(enum.
|
139
|
+
expect(enum.values).to eq([[3,'Name 3'], [1,'Name 1'], [2, 'Name 2']])
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.rc4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Meehan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|