simple_enum 1.4.1 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -1
- data/.travis.yml +7 -3
- data/Appraisals +14 -0
- data/Gemfile +7 -1
- data/Gemfile.lock +57 -0
- data/README.rdoc +48 -4
- data/Rakefile +3 -3
- data/gemfiles/rails-3.0.gemfile +11 -0
- data/gemfiles/rails-3.0.gemfile.lock +56 -0
- data/gemfiles/rails-3.1.gemfile +11 -0
- data/gemfiles/rails-3.1.gemfile.lock +58 -0
- data/gemfiles/rails-3.2.gemfile +11 -0
- data/gemfiles/rails-3.2.gemfile.lock +58 -0
- data/lib/simple_enum.rb +35 -16
- data/lib/simple_enum/enum_hash.rb +24 -14
- data/lib/simple_enum/mongoid.rb +52 -0
- data/lib/simple_enum/validation.rb +1 -1
- data/lib/simple_enum/version.rb +1 -1
- data/locales/en.yml +4 -0
- data/simple_enum.gemspec +8 -6
- data/test/array_conversions_test.rb +9 -11
- data/test/class_methods_test.rb +20 -34
- data/test/dirty_attributes_test.rb +4 -5
- data/test/enum_hash_test.rb +16 -21
- data/test/finders_test.rb +13 -9
- data/test/locales.yml +17 -9
- data/test/mongoid_test.rb +38 -0
- data/test/object_backed_test.rb +17 -23
- data/test/orm/active_record.rb +99 -0
- data/test/orm/common.rb +23 -0
- data/test/orm/mongoid.rb +101 -0
- data/test/poro_test.rb +20 -0
- data/test/prefixes_test.rb +5 -7
- data/test/simple_enum_test.rb +68 -55
- data/test/test_helper.rb +22 -49
- data/test/without_shortcuts_test.rb +8 -9
- metadata +101 -39
- data/lib/simple_enum/object_support.rb +0 -37
- data/test/object_support_test.rb +0 -29
@@ -1,16 +1,15 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class
|
4
|
-
set_table_name 'dummies'
|
5
|
-
as_enum :gender, [:male, :female], :slim => true
|
6
|
-
end
|
7
|
-
|
8
|
-
class WithoutShortcutsTest < ActiveSupport::TestCase
|
3
|
+
class WithoutShortcutsTest < MiniTest::Unit::TestCase
|
9
4
|
def setup
|
10
5
|
reload_db
|
6
|
+
|
7
|
+
named_dummy('SlimDummy') do
|
8
|
+
as_enum :gender, [:male, :female], :slim => true
|
9
|
+
end
|
11
10
|
end
|
12
11
|
|
13
|
-
|
12
|
+
def test_that_no_shortcut_methods_are_generated_if_slime_is_true
|
14
13
|
jane = SlimDummy.new
|
15
14
|
jane.gender = :female
|
16
15
|
|
@@ -23,8 +22,8 @@ class WithoutShortcutsTest < ActiveSupport::TestCase
|
|
23
22
|
assert !jane.respond_to?(:female?), "should not respond_to <female?>"
|
24
23
|
end
|
25
24
|
|
26
|
-
|
27
|
-
anna = SlimDummy.
|
25
|
+
def test_that_saving_and_loading_from_datasource_works_even_if_slim_is_true
|
26
|
+
anna = SlimDummy.where(:name => 'Anna').first
|
28
27
|
|
29
28
|
assert_equal 1, anna.gender_cd
|
30
29
|
assert_equal :female, anna.gender
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 3
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 1
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 1.
|
8
|
+
- 5
|
9
|
+
- 0
|
10
|
+
version: 1.5.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Lukas Westermann
|
@@ -14,75 +15,117 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date:
|
18
|
-
default_executable:
|
18
|
+
date: 2012-04-10 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
|
22
|
-
prerelease: false
|
21
|
+
type: :runtime
|
23
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
+
hash: 7
|
27
28
|
segments:
|
28
29
|
- 3
|
29
30
|
- 0
|
30
|
-
|
31
|
-
|
31
|
+
- 0
|
32
|
+
version: 3.0.0
|
33
|
+
name: activesupport
|
32
34
|
version_requirements: *id001
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: rake
|
35
35
|
prerelease: false
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
type: :development
|
36
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
37
40
|
requirements:
|
38
41
|
- - ">="
|
39
42
|
- !ruby/object:Gem::Version
|
43
|
+
hash: 63
|
40
44
|
segments:
|
41
45
|
- 0
|
42
|
-
-
|
43
|
-
-
|
44
|
-
version: 0.
|
45
|
-
|
46
|
+
- 9
|
47
|
+
- 2
|
48
|
+
version: 0.9.2
|
49
|
+
name: rake
|
46
50
|
version_requirements: *id002
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: activerecord
|
49
51
|
prerelease: false
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
type: :development
|
50
54
|
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
51
56
|
requirements:
|
52
|
-
- -
|
57
|
+
- - ">="
|
53
58
|
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
54
60
|
segments:
|
55
|
-
- 3
|
56
61
|
- 0
|
57
|
-
|
58
|
-
|
62
|
+
- 4
|
63
|
+
version: "0.4"
|
64
|
+
name: appraisal
|
59
65
|
version_requirements: *id003
|
60
|
-
- !ruby/object:Gem::Dependency
|
61
|
-
name: mongoid
|
62
66
|
prerelease: false
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
type: :development
|
63
69
|
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
64
71
|
requirements:
|
65
|
-
- -
|
72
|
+
- - ">="
|
66
73
|
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
67
75
|
segments:
|
68
76
|
- 2
|
77
|
+
- 3
|
69
78
|
- 0
|
70
|
-
version:
|
71
|
-
|
79
|
+
version: 2.3.0
|
80
|
+
name: minitest
|
72
81
|
version_requirements: *id004
|
73
|
-
- !ruby/object:Gem::Dependency
|
74
|
-
name: sqlite3
|
75
82
|
prerelease: false
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
type: :development
|
76
85
|
requirement: &id005 !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
77
87
|
requirements:
|
78
88
|
- - ">="
|
79
89
|
- !ruby/object:Gem::Version
|
90
|
+
hash: 7
|
80
91
|
segments:
|
92
|
+
- 3
|
81
93
|
- 0
|
82
|
-
|
83
|
-
|
94
|
+
- 0
|
95
|
+
version: 3.0.0
|
96
|
+
name: activerecord
|
84
97
|
version_requirements: *id005
|
85
|
-
|
98
|
+
prerelease: false
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
type: :development
|
101
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ~>
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
hash: 3
|
107
|
+
segments:
|
108
|
+
- 2
|
109
|
+
- 0
|
110
|
+
version: "2.0"
|
111
|
+
name: mongoid
|
112
|
+
version_requirements: *id006
|
113
|
+
prerelease: false
|
114
|
+
- !ruby/object:Gem::Dependency
|
115
|
+
type: :development
|
116
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
hash: 3
|
122
|
+
segments:
|
123
|
+
- 0
|
124
|
+
version: "0"
|
125
|
+
name: sqlite3
|
126
|
+
version_requirements: *id007
|
127
|
+
prerelease: false
|
128
|
+
description: Provides enum-like fields for ActiveRecord, ActiveModel and Mongoid models.
|
86
129
|
email:
|
87
130
|
- lukas.westermann@gmail.com
|
88
131
|
executables: []
|
@@ -94,13 +137,21 @@ extra_rdoc_files: []
|
|
94
137
|
files:
|
95
138
|
- .gitignore
|
96
139
|
- .travis.yml
|
140
|
+
- Appraisals
|
97
141
|
- Gemfile
|
142
|
+
- Gemfile.lock
|
98
143
|
- LICENCE
|
99
144
|
- README.rdoc
|
100
145
|
- Rakefile
|
146
|
+
- gemfiles/rails-3.0.gemfile
|
147
|
+
- gemfiles/rails-3.0.gemfile.lock
|
148
|
+
- gemfiles/rails-3.1.gemfile
|
149
|
+
- gemfiles/rails-3.1.gemfile.lock
|
150
|
+
- gemfiles/rails-3.2.gemfile
|
151
|
+
- gemfiles/rails-3.2.gemfile.lock
|
101
152
|
- lib/simple_enum.rb
|
102
153
|
- lib/simple_enum/enum_hash.rb
|
103
|
-
- lib/simple_enum/
|
154
|
+
- lib/simple_enum/mongoid.rb
|
104
155
|
- lib/simple_enum/validation.rb
|
105
156
|
- lib/simple_enum/version.rb
|
106
157
|
- locales/en.yml
|
@@ -112,13 +163,16 @@ files:
|
|
112
163
|
- test/finders_test.rb
|
113
164
|
- test/locales.yml
|
114
165
|
- test/models.rb
|
166
|
+
- test/mongoid_test.rb
|
115
167
|
- test/object_backed_test.rb
|
116
|
-
- test/
|
168
|
+
- test/orm/active_record.rb
|
169
|
+
- test/orm/common.rb
|
170
|
+
- test/orm/mongoid.rb
|
171
|
+
- test/poro_test.rb
|
117
172
|
- test/prefixes_test.rb
|
118
173
|
- test/simple_enum_test.rb
|
119
174
|
- test/test_helper.rb
|
120
175
|
- test/without_shortcuts_test.rb
|
121
|
-
has_rdoc: true
|
122
176
|
homepage: http://github.com/lwe/simple_enum
|
123
177
|
licenses:
|
124
178
|
- MIT
|
@@ -128,18 +182,22 @@ rdoc_options: []
|
|
128
182
|
require_paths:
|
129
183
|
- lib
|
130
184
|
required_ruby_version: !ruby/object:Gem::Requirement
|
185
|
+
none: false
|
131
186
|
requirements:
|
132
187
|
- - ">="
|
133
188
|
- !ruby/object:Gem::Version
|
189
|
+
hash: 57
|
134
190
|
segments:
|
135
191
|
- 1
|
136
192
|
- 8
|
137
193
|
- 7
|
138
194
|
version: 1.8.7
|
139
195
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
196
|
+
none: false
|
140
197
|
requirements:
|
141
198
|
- - ">="
|
142
199
|
- !ruby/object:Gem::Version
|
200
|
+
hash: 23
|
143
201
|
segments:
|
144
202
|
- 1
|
145
203
|
- 3
|
@@ -148,10 +206,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
206
|
requirements: []
|
149
207
|
|
150
208
|
rubyforge_project:
|
151
|
-
rubygems_version: 1.
|
209
|
+
rubygems_version: 1.8.15
|
152
210
|
signing_key:
|
153
211
|
specification_version: 3
|
154
|
-
summary: Simple enum-like field support for
|
212
|
+
summary: Simple enum-like field support for models.
|
155
213
|
test_files:
|
156
214
|
- test/array_conversions_test.rb
|
157
215
|
- test/class_methods_test.rb
|
@@ -160,8 +218,12 @@ test_files:
|
|
160
218
|
- test/finders_test.rb
|
161
219
|
- test/locales.yml
|
162
220
|
- test/models.rb
|
221
|
+
- test/mongoid_test.rb
|
163
222
|
- test/object_backed_test.rb
|
164
|
-
- test/
|
223
|
+
- test/orm/active_record.rb
|
224
|
+
- test/orm/common.rb
|
225
|
+
- test/orm/mongoid.rb
|
226
|
+
- test/poro_test.rb
|
165
227
|
- test/prefixes_test.rb
|
166
228
|
- test/simple_enum_test.rb
|
167
229
|
- test/test_helper.rb
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module SimpleEnum
|
2
|
-
module ObjectSupport
|
3
|
-
|
4
|
-
# Convert object to symbol for use in symbolized enum
|
5
|
-
# methods. Return value is supposed to be a symbol,
|
6
|
-
# though strings should work as well.
|
7
|
-
#
|
8
|
-
# The default behaviour is to try +to_sym+ first, then
|
9
|
-
# checks if a field named +name+ exists or finally falls
|
10
|
-
# back to +to_param+ method as provided by ActiveSupport.
|
11
|
-
#
|
12
|
-
# It's perfectly for subclasses to override this method,
|
13
|
-
# to provide custom +to_enum_sym+ behaviour, e.g. if
|
14
|
-
# the symbolized value is in e.g. +title+:
|
15
|
-
#
|
16
|
-
# class FormOfAddress < ActiveRecord::Base
|
17
|
-
# attr_accessor :title
|
18
|
-
# def to_enum_sym; title; end
|
19
|
-
# end
|
20
|
-
#
|
21
|
-
# *Note*: to provide better looking methods values for +name+
|
22
|
-
# are <tt>parametereize('_')</tt>'d, so it might be a good idea to do
|
23
|
-
# the same thing in a custom +to_enum_sym+ method, like (for the
|
24
|
-
# example above):
|
25
|
-
#
|
26
|
-
# def to_enum_sym; title.parameterize('_').to_sym; end
|
27
|
-
#
|
28
|
-
# *TODO*: The current implementation does not handle nil values very
|
29
|
-
# gracefully, so if +name+ returns +nil+, it should be handled
|
30
|
-
# a bit better I suppose...
|
31
|
-
def to_enum_sym
|
32
|
-
return to_sym if respond_to?(:to_sym)
|
33
|
-
return name.to_s.parameterize('_').to_sym if respond_to?(:name)
|
34
|
-
to_param.to_sym unless blank? # fallback, unless empty...
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
data/test/object_support_test.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', __FILE__)
|
2
|
-
|
3
|
-
class ObjectSupportTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
test "ensure that symbols stay symbols" do
|
6
|
-
assert_same :sym, :sym.to_enum_sym
|
7
|
-
end
|
8
|
-
|
9
|
-
test "ensure that strings are just converted to symbols, whatever they look like" do
|
10
|
-
assert_same :sym, 'sym'.to_enum_sym
|
11
|
-
assert_same :OtherSym, 'OtherSym'.to_enum_sym
|
12
|
-
end
|
13
|
-
|
14
|
-
test "convert custom class to symbol, by providing attr_accessor :name" do
|
15
|
-
has_name = Class.new do
|
16
|
-
attr_accessor :name
|
17
|
-
end
|
18
|
-
|
19
|
-
named = has_name.new
|
20
|
-
named.name = 'sym'
|
21
|
-
|
22
|
-
assert_same :sym, named.to_enum_sym
|
23
|
-
|
24
|
-
another_named = has_name.new
|
25
|
-
another_named.name = 'Contains Spaces?'
|
26
|
-
|
27
|
-
assert_same :contains_spaces, another_named.to_enum_sym
|
28
|
-
end
|
29
|
-
end
|