simple_enum 1.6.1 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,11 +1,5 @@
1
1
  language: ruby
2
- env:
3
- - ORM=active_record
4
- - ORM=mongoid
5
2
  rvm:
6
3
  - 1.8.7
7
4
  - 1.9.3
8
- gemfile:
9
- - gemfiles/rails-3.0.gemfile
10
- - gemfiles/rails-3.1.gemfile
11
- - gemfiles/rails-3.2.gemfile
5
+ - jruby-19mode
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source "http://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  # some development deps
6
- gem 'jdbc-sqlite3', :platform => :jruby
6
+ gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
7
7
 
8
8
  gem 'sqlite3', :platform => :ruby
9
9
  gem 'bson_ext', :platform => :ruby
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple_enum (1.6.1)
4
+ simple_enum (1.6.2)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -18,9 +18,6 @@ GEM
18
18
  activesupport (3.2.0)
19
19
  i18n (~> 0.6)
20
20
  multi_json (~> 1.0)
21
- appraisal (0.4.0)
22
- bundler
23
- rake
24
21
  arel (3.0.0)
25
22
  bson (1.5.2)
26
23
  bson (1.5.2-java)
@@ -28,7 +25,6 @@ GEM
28
25
  bson (= 1.5.2)
29
26
  builder (3.0.0)
30
27
  i18n (0.6.0)
31
- jdbc-sqlite3 (3.7.2)
32
28
  minitest (2.10.1)
33
29
  mongo (1.5.2)
34
30
  bson (= 1.5.2)
@@ -47,9 +43,8 @@ PLATFORMS
47
43
 
48
44
  DEPENDENCIES
49
45
  activerecord (>= 3.0.0)
50
- appraisal (>= 0.4)
46
+ activerecord-jdbcsqlite3-adapter
51
47
  bson_ext
52
- jdbc-sqlite3
53
48
  minitest (>= 2.3.0)
54
49
  mongoid (~> 2.0)
55
50
  rake (>= 0.9.2)
data/Rakefile CHANGED
@@ -1,18 +1,30 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
- require 'appraisal'
4
3
  require 'rake/testtask'
5
4
 
6
- include Rake::DSL
7
-
8
5
  Bundler::GemHelper.install_tasks
9
6
 
10
- desc 'Default: run unit tests.'
7
+ desc 'Default: run all unit tests for both ActiveRecord & Mongoid.'
11
8
  task :default => :test
12
9
 
13
- desc 'Run unit tests, use ORM=...'
14
- Rake::TestTask.new(:test) do |t|
15
- t.libs << 'test'
16
- t.test_files = Dir.glob('test/**/*_test.rb')
17
- t.verbose = true
10
+ namespace :test do
11
+ Rake::TestTask.new(:units) do |t|
12
+ t.libs << "test"
13
+ t.test_files = Dir['test/*_test.rb']
14
+ t.verbose = true
15
+ end
16
+
17
+ desc 'Run all unit tests for ActiveRecord'
18
+ task :activerecord do |t|
19
+ ENV['SIMPLE_ENUM_TEST_ORM'] = 'active_record'
20
+ Rake::Task['test:units'].execute
21
+ end
22
+
23
+ desc 'Run all unit tests for Mongoid'
24
+ task :mongoid do |t|
25
+ ENV['SIMPLE_ENUM_TEST_ORM'] = 'mongoid'
26
+ Rake::Task['test:units'].execute
27
+ end
18
28
  end
29
+
30
+ task :test => [:'test:activerecord', :'test:mongoid']
data/lib/simple_enum.rb CHANGED
@@ -154,9 +154,11 @@ module SimpleEnum
154
154
  # <tt>false</tt> no exception is thrown and the internal value is set to <tt>nil</tt> (default is <tt>true</tt>)
155
155
  # * <tt>:dirty</tt> - Boolean value which if set to <tt>true</tt> generates <tt>..._was</tt> and <tt>..._changed?</tt>
156
156
  # methods for the enum, which delegate to the internal column (default is <tt>false</tt>)
157
+ # * <tt>:field</tt> - Also allowed as valid key, for Mongoid integration + default options, see simple_enum#27.
158
+ #
157
159
  def as_enum(enum_cd, values, options = {})
158
160
  options = SimpleEnum.default_options.merge({ :column => "#{enum_cd}_cd" }).merge(options)
159
- options.assert_valid_keys(:column, :whiny, :prefix, :slim, :upcase, :dirty)
161
+ options.assert_valid_keys(:column, :whiny, :prefix, :slim, :upcase, :dirty, :field)
160
162
 
161
163
  metaclass = (class << self; self; end)
162
164
 
@@ -1,5 +1,5 @@
1
1
  module SimpleEnum
2
2
 
3
3
  # +SimpleEnum+ version string.
4
- VERSION = "1.6.1"
4
+ VERSION = "1.6.2"
5
5
  end
data/simple_enum.gemspec CHANGED
@@ -23,16 +23,9 @@ Gem::Specification.new do |s|
23
23
  s.license = 'MIT'
24
24
 
25
25
  s.add_dependency "activesupport", '>= 3.0.0'
26
-
26
+
27
27
  s.add_development_dependency 'rake', '>= 0.9.2'
28
- s.add_development_dependency 'appraisal', '>= 0.4'
29
28
  s.add_development_dependency 'minitest', '>= 2.3.0'
30
29
  s.add_development_dependency 'activerecord', '>= 3.0.0'
31
30
  s.add_development_dependency 'mongoid', '~> 2.0'
32
-
33
- unless RUBY_PLATFORM =~ /java/
34
- s.add_development_dependency 'sqlite3'
35
- else
36
- s.add_development_dependency 'activerecord-jdbcsqlite3-adapter'
37
- end
38
- end
31
+ end
data/test/mongoid_test.rb CHANGED
@@ -1,7 +1,10 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class MongoidTest < MiniTest::Unit::TestCase
4
+ @@default_options = SimpleEnum.default_options
5
+
4
6
  def setup
7
+ SimpleEnum.default_options.clear.merge(@@default_options)
5
8
  reload_db
6
9
  end
7
10
 
@@ -35,4 +38,15 @@ class MongoidTest < MiniTest::Unit::TestCase
35
38
 
36
39
  assert_nil klass.new.fields['gender_cd']
37
40
  end
38
- end
41
+
42
+ def test_default_field_options
43
+ skip('Only available in mongoid') unless mongoid?
44
+ SimpleEnum.default_options[:field] = { :type => String }
45
+ klass = anonymous_dummy do
46
+ as_enum :gender, [:male, :female]
47
+ end
48
+
49
+ refute_nil klass.new.fields['gender_cd']
50
+ assert_equal String, klass.new.fields['gender_cd'].options[:type]
51
+ end
52
+ end
data/test/test_helper.rb CHANGED
@@ -1,15 +1,13 @@
1
1
  # Setup environment for both tests and IRB interactive console
2
2
  #
3
-
4
3
  $KCODE = 'u' unless RUBY_VERSION =~ /^1\.9/ # to make parameterize work...
5
4
 
6
5
  require 'rubygems'
7
6
  require 'bundler/setup'
8
7
 
9
- require 'test/unit'
8
+ require 'minitest/autorun'
10
9
  require 'active_support'
11
10
  require 'active_support/version'
12
- require 'minitest/autorun'
13
11
 
14
12
  # setup fake rails env
15
13
  ROOT = File.join(File.dirname(__FILE__), '..')
@@ -17,7 +15,7 @@ RAILS_ROOT = ROOT
17
15
  RAILS_ENV = 'test'
18
16
 
19
17
  # load orms
20
- ORM = ENV['ORM'] || 'active_record'
18
+ ORM = ENV['SIMPLE_ENUM_TEST_ORM'] || 'active_record'
21
19
 
22
20
  def mongoid?; return ORM == 'mongoid';end
23
21
  def activerecord?; return ORM == 'active_record';end
@@ -25,14 +23,14 @@ def activerecord?; return ORM == 'active_record';end
25
23
  # load database implemntation
26
24
  require ORM
27
25
 
28
- # load simple enum
26
+ # load simple enum AFTER ORM
29
27
  require 'simple_enum'
30
28
 
31
29
  # load ORM specific stuff
32
30
  require 'orm/common'
33
31
  require "orm/#{ORM}"
34
32
 
35
- # Add test locales
33
+ # Add locales
36
34
  I18n.load_path << File.join(File.dirname(__FILE__), 'locales.yml')
37
35
 
38
36
  # setup db
@@ -40,11 +38,3 @@ setup_db
40
38
 
41
39
  # Test environment info
42
40
  puts "Testing against: activesupport-#{ActiveSupport::VERSION::STRING}, #{ORM.to_s}-#{orm_version}"
43
-
44
- # do some magic to initialze DB for IRB session
45
- if Object.const_defined?('IRB')
46
- reload_db :fill => true, :genders => true
47
- else # and load test classes when in test cases...
48
- require 'test/unit'
49
- require 'active_support/test_case'
50
- end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_enum
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
5
- prerelease:
4
+ prerelease: false
6
5
  segments:
7
6
  - 1
8
7
  - 6
9
- - 1
10
- version: 1.6.1
8
+ - 2
9
+ version: 1.6.2
11
10
  platform: ruby
12
11
  authors:
13
12
  - Lukas Westermann
@@ -15,116 +14,78 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2012-06-30 00:00:00 Z
17
+ date: 2012-08-22 00:00:00 +02:00
18
+ default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- prerelease: false
21
+ type: :runtime
22
22
  version_requirements: &id001 !ruby/object:Gem::Requirement
23
- none: false
24
23
  requirements:
25
24
  - - ">="
26
25
  - !ruby/object:Gem::Version
27
- hash: 7
28
26
  segments:
29
27
  - 3
30
28
  - 0
31
29
  - 0
32
30
  version: 3.0.0
33
- requirement: *id001
34
- type: :runtime
35
31
  name: activesupport
36
- - !ruby/object:Gem::Dependency
32
+ requirement: *id001
37
33
  prerelease: false
34
+ - !ruby/object:Gem::Dependency
35
+ type: :development
38
36
  version_requirements: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
37
  requirements:
41
38
  - - ">="
42
39
  - !ruby/object:Gem::Version
43
- hash: 63
44
40
  segments:
45
41
  - 0
46
42
  - 9
47
43
  - 2
48
44
  version: 0.9.2
49
- requirement: *id002
50
- type: :development
51
45
  name: rake
52
- - !ruby/object:Gem::Dependency
46
+ requirement: *id002
53
47
  prerelease: false
54
- version_requirements: &id003 !ruby/object:Gem::Requirement
55
- none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 3
60
- segments:
61
- - 0
62
- - 4
63
- version: "0.4"
64
- requirement: *id003
65
- type: :development
66
- name: appraisal
67
48
  - !ruby/object:Gem::Dependency
68
- prerelease: false
69
- version_requirements: &id004 !ruby/object:Gem::Requirement
70
- none: false
49
+ type: :development
50
+ version_requirements: &id003 !ruby/object:Gem::Requirement
71
51
  requirements:
72
52
  - - ">="
73
53
  - !ruby/object:Gem::Version
74
- hash: 3
75
54
  segments:
76
55
  - 2
77
56
  - 3
78
57
  - 0
79
58
  version: 2.3.0
80
- requirement: *id004
81
- type: :development
82
59
  name: minitest
83
- - !ruby/object:Gem::Dependency
60
+ requirement: *id003
84
61
  prerelease: false
85
- version_requirements: &id005 !ruby/object:Gem::Requirement
86
- none: false
62
+ - !ruby/object:Gem::Dependency
63
+ type: :development
64
+ version_requirements: &id004 !ruby/object:Gem::Requirement
87
65
  requirements:
88
66
  - - ">="
89
67
  - !ruby/object:Gem::Version
90
- hash: 7
91
68
  segments:
92
69
  - 3
93
70
  - 0
94
71
  - 0
95
72
  version: 3.0.0
96
- requirement: *id005
97
- type: :development
98
73
  name: activerecord
99
- - !ruby/object:Gem::Dependency
74
+ requirement: *id004
100
75
  prerelease: false
101
- version_requirements: &id006 !ruby/object:Gem::Requirement
102
- none: false
76
+ - !ruby/object:Gem::Dependency
77
+ type: :development
78
+ version_requirements: &id005 !ruby/object:Gem::Requirement
103
79
  requirements:
104
80
  - - ~>
105
81
  - !ruby/object:Gem::Version
106
- hash: 3
107
82
  segments:
108
83
  - 2
109
84
  - 0
110
85
  version: "2.0"
111
- requirement: *id006
112
- type: :development
113
86
  name: mongoid
114
- - !ruby/object:Gem::Dependency
87
+ requirement: *id005
115
88
  prerelease: false
116
- version_requirements: &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
- requirement: *id007
126
- type: :development
127
- name: sqlite3
128
89
  description: Provides enum-like fields for ActiveRecord, ActiveModel and Mongoid models.
129
90
  email:
130
91
  - lukas.westermann@gmail.com
@@ -137,18 +98,11 @@ extra_rdoc_files: []
137
98
  files:
138
99
  - .gitignore
139
100
  - .travis.yml
140
- - Appraisals
141
101
  - Gemfile
142
102
  - Gemfile.lock
143
103
  - LICENCE
144
104
  - README.rdoc
145
105
  - 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
152
106
  - lib/simple_enum.rb
153
107
  - lib/simple_enum/enum_hash.rb
154
108
  - lib/simple_enum/mongoid.rb
@@ -172,6 +126,7 @@ files:
172
126
  - test/simple_enum_test.rb
173
127
  - test/test_helper.rb
174
128
  - test/without_shortcuts_test.rb
129
+ has_rdoc: true
175
130
  homepage: http://github.com/lwe/simple_enum
176
131
  licenses:
177
132
  - MIT
@@ -181,22 +136,18 @@ rdoc_options: []
181
136
  require_paths:
182
137
  - lib
183
138
  required_ruby_version: !ruby/object:Gem::Requirement
184
- none: false
185
139
  requirements:
186
140
  - - ">="
187
141
  - !ruby/object:Gem::Version
188
- hash: 57
189
142
  segments:
190
143
  - 1
191
144
  - 8
192
145
  - 7
193
146
  version: 1.8.7
194
147
  required_rubygems_version: !ruby/object:Gem::Requirement
195
- none: false
196
148
  requirements:
197
149
  - - ">="
198
150
  - !ruby/object:Gem::Version
199
- hash: 23
200
151
  segments:
201
152
  - 1
202
153
  - 3
@@ -205,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
156
  requirements: []
206
157
 
207
158
  rubyforge_project:
208
- rubygems_version: 1.8.15
159
+ rubygems_version: 1.3.6
209
160
  signing_key:
210
161
  specification_version: 3
211
162
  summary: Simple enum-like field support for models.
data/Appraisals DELETED
@@ -1,14 +0,0 @@
1
- appraise "rails-3.0" do
2
- gem 'activesupport', '~> 3.0.9'
3
- gem 'activerecord', '~> 3.0.9'
4
- end
5
-
6
- appraise "rails-3.1" do
7
- gem 'activesupport', '~> 3.1.0'
8
- gem 'activerecord', '~> 3.1.0'
9
- end
10
-
11
- appraise "rails-3.2" do
12
- gem 'activesupport', '~> 3.2.0'
13
- gem 'activerecord', '~> 3.2.0'
14
- end
@@ -1,11 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "jdbc-sqlite3", :platform=>:jruby
6
- gem "sqlite3", :platform=>:ruby
7
- gem "bson_ext", :platform=>:ruby
8
- gem "activesupport", "~> 3.0.9"
9
- gem "activerecord", "~> 3.0.9"
10
-
11
- gemspec :path=>"../"
@@ -1,53 +0,0 @@
1
- PATH
2
- remote: /Users/lukas/Projects/_github/simple_enum
3
- specs:
4
- simple_enum (1.6.1)
5
- activesupport (>= 3.0.0)
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- activemodel (3.0.15)
11
- activesupport (= 3.0.15)
12
- builder (~> 2.1.2)
13
- i18n (~> 0.5.0)
14
- activerecord (3.0.15)
15
- activemodel (= 3.0.15)
16
- activesupport (= 3.0.15)
17
- arel (~> 2.0.10)
18
- tzinfo (~> 0.3.23)
19
- activesupport (3.0.15)
20
- appraisal (0.4.1)
21
- bundler
22
- rake
23
- arel (2.0.10)
24
- bson (1.6.4)
25
- bson_ext (1.6.4)
26
- bson (~> 1.6.4)
27
- builder (2.1.2)
28
- i18n (0.5.0)
29
- minitest (3.2.0)
30
- mongo (1.6.4)
31
- bson (~> 1.6.4)
32
- mongoid (2.2.6)
33
- activemodel (~> 3.0.0)
34
- mongo (~> 1.3)
35
- tzinfo (~> 0.3.22)
36
- rake (0.9.2.2)
37
- sqlite3 (1.3.6)
38
- tzinfo (0.3.33)
39
-
40
- PLATFORMS
41
- ruby
42
-
43
- DEPENDENCIES
44
- activerecord (~> 3.0.9)
45
- activesupport (~> 3.0.9)
46
- appraisal (>= 0.4)
47
- bson_ext
48
- jdbc-sqlite3
49
- minitest (>= 2.3.0)
50
- mongoid (~> 2.0)
51
- rake (>= 0.9.2)
52
- simple_enum!
53
- sqlite3
@@ -1,11 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "jdbc-sqlite3", :platform=>:jruby
6
- gem "sqlite3", :platform=>:ruby
7
- gem "bson_ext", :platform=>:ruby
8
- gem "activesupport", "~> 3.1.0"
9
- gem "activerecord", "~> 3.1.0"
10
-
11
- gemspec :path=>"../"
@@ -1,55 +0,0 @@
1
- PATH
2
- remote: /Users/lukas/Projects/_github/simple_enum
3
- specs:
4
- simple_enum (1.6.1)
5
- activesupport (>= 3.0.0)
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- activemodel (3.1.6)
11
- activesupport (= 3.1.6)
12
- builder (~> 3.0.0)
13
- i18n (~> 0.6)
14
- activerecord (3.1.6)
15
- activemodel (= 3.1.6)
16
- activesupport (= 3.1.6)
17
- arel (~> 2.2.3)
18
- tzinfo (~> 0.3.29)
19
- activesupport (3.1.6)
20
- multi_json (>= 1.0, < 1.3)
21
- appraisal (0.4.1)
22
- bundler
23
- rake
24
- arel (2.2.3)
25
- bson (1.6.4)
26
- bson_ext (1.6.4)
27
- bson (~> 1.6.4)
28
- builder (3.0.0)
29
- i18n (0.6.0)
30
- minitest (3.2.0)
31
- mongo (1.6.2)
32
- bson (~> 1.6.2)
33
- mongoid (2.4.11)
34
- activemodel (~> 3.1)
35
- mongo (<= 1.6.2)
36
- tzinfo (~> 0.3.22)
37
- multi_json (1.2.0)
38
- rake (0.9.2.2)
39
- sqlite3 (1.3.6)
40
- tzinfo (0.3.33)
41
-
42
- PLATFORMS
43
- ruby
44
-
45
- DEPENDENCIES
46
- activerecord (~> 3.1.0)
47
- activesupport (~> 3.1.0)
48
- appraisal (>= 0.4)
49
- bson_ext
50
- jdbc-sqlite3
51
- minitest (>= 2.3.0)
52
- mongoid (~> 2.0)
53
- rake (>= 0.9.2)
54
- simple_enum!
55
- sqlite3
@@ -1,11 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "jdbc-sqlite3", :platform=>:jruby
6
- gem "sqlite3", :platform=>:ruby
7
- gem "bson_ext", :platform=>:ruby
8
- gem "activesupport", "~> 3.2.0"
9
- gem "activerecord", "~> 3.2.0"
10
-
11
- gemspec :path=>"../"
@@ -1,55 +0,0 @@
1
- PATH
2
- remote: /Users/lukas/Projects/_github/simple_enum
3
- specs:
4
- simple_enum (1.6.1)
5
- activesupport (>= 3.0.0)
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- activemodel (3.2.6)
11
- activesupport (= 3.2.6)
12
- builder (~> 3.0.0)
13
- activerecord (3.2.6)
14
- activemodel (= 3.2.6)
15
- activesupport (= 3.2.6)
16
- arel (~> 3.0.2)
17
- tzinfo (~> 0.3.29)
18
- activesupport (3.2.6)
19
- i18n (~> 0.6)
20
- multi_json (~> 1.0)
21
- appraisal (0.4.1)
22
- bundler
23
- rake
24
- arel (3.0.2)
25
- bson (1.6.4)
26
- bson_ext (1.6.4)
27
- bson (~> 1.6.4)
28
- builder (3.0.0)
29
- i18n (0.6.0)
30
- minitest (3.2.0)
31
- mongo (1.6.2)
32
- bson (~> 1.6.2)
33
- mongoid (2.4.11)
34
- activemodel (~> 3.1)
35
- mongo (<= 1.6.2)
36
- tzinfo (~> 0.3.22)
37
- multi_json (1.3.6)
38
- rake (0.9.2.2)
39
- sqlite3 (1.3.6)
40
- tzinfo (0.3.33)
41
-
42
- PLATFORMS
43
- ruby
44
-
45
- DEPENDENCIES
46
- activerecord (~> 3.2.0)
47
- activesupport (~> 3.2.0)
48
- appraisal (>= 0.4)
49
- bson_ext
50
- jdbc-sqlite3
51
- minitest (>= 2.3.0)
52
- mongoid (~> 2.0)
53
- rake (>= 0.9.2)
54
- simple_enum!
55
- sqlite3