active_enum 0.9.12 → 1.0.0.pre

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.
@@ -27,33 +27,33 @@ describe ActiveEnum::Storage::I18nStore do
27
27
  describe '#set' do
28
28
  it 'should store value of id and name' do
29
29
  store.set 1, 'test name'
30
- store.send(:_values).should == [[1, 'test name']]
30
+ expect(store.send(:_values)).to eq([[1, 'test name']])
31
31
  end
32
32
 
33
33
  it 'should store value of id, name and meta hash' do
34
34
  store.set 1, 'test name', :description => 'meta'
35
- store.send(:_values).should == [[1, 'test name', {:description => 'meta'}]]
35
+ expect(store.send(:_values)).to eq([[1, 'test name', {:description => 'meta'}]])
36
36
  end
37
37
 
38
38
  it 'should raise error if duplicate id' do
39
39
  expect {
40
40
  store.set 1, 'Name 1'
41
41
  store.set 1, 'Other Name'
42
- }.should raise_error(ActiveEnum::DuplicateValue)
42
+ }.to raise_error(ActiveEnum::DuplicateValue)
43
43
  end
44
44
 
45
45
  it 'should raise error if duplicate name' do
46
46
  expect {
47
47
  store.set 1, 'Name 1'
48
48
  store.set 2, 'Name 1'
49
- }.should raise_error(ActiveEnum::DuplicateValue)
49
+ }.to raise_error(ActiveEnum::DuplicateValue)
50
50
  end
51
51
 
52
52
  it 'should not raise error if duplicate name with alternate case matches' do
53
53
  expect {
54
54
  store.set 1, 'Name 1'
55
55
  store.set 2, 'name 1'
56
- }.should_not raise_error(ActiveEnum::DuplicateValue)
56
+ }.not_to raise_error()
57
57
  end
58
58
  end
59
59
 
@@ -67,10 +67,10 @@ describe ActiveEnum::Storage::I18nStore do
67
67
  store.set 1, 'thanks'
68
68
 
69
69
  I18n.locale = :en
70
- store.values.should == [ [1, 'Thanks'] ]
70
+ expect(store.values).to eq([ [1, 'Thanks'] ])
71
71
 
72
72
  I18n.locale = :fr
73
- store.values.should == [ [1, 'Merce'] ]
73
+ expect(store.values).to eq([ [1, 'Merce'] ])
74
74
  end
75
75
 
76
76
  end
@@ -83,22 +83,22 @@ describe ActiveEnum::Storage::I18nStore do
83
83
 
84
84
  it 'should return the value for a given id' do
85
85
  store.set 1, 'test'
86
- store.get_by_id(1).should == [1, 'Testing']
86
+ expect(store.get_by_id(1)).to eq([1, 'Testing'])
87
87
  end
88
88
 
89
89
  it 'should return the value with meta for a given id' do
90
90
  store.set 1, 'test', :description => 'meta'
91
- store.get_by_id(1).should == [1, 'Testing', { :description => 'meta' }]
91
+ expect(store.get_by_id(1)).to eq([1, 'Testing', { :description => 'meta' }])
92
92
  end
93
93
 
94
94
  it 'should return nil when id not found' do
95
- store.get_by_id(1).should be_nil
95
+ expect(store.get_by_id(1)).to be_nil
96
96
  end
97
97
 
98
98
  it 'should return key when translation missing' do
99
99
  I18n.locale = :ja
100
100
  store.set 1, 'test'
101
- store.get_by_id(1).should == [1, 'test']
101
+ expect(store.get_by_id(1)).to eq([1, 'test'])
102
102
  end
103
103
  end
104
104
 
@@ -110,16 +110,16 @@ describe ActiveEnum::Storage::I18nStore do
110
110
 
111
111
  it 'should return the value for a given name' do
112
112
  store.set 1, 'test'
113
- store.get_by_name('test').should == [1, 'Testing']
113
+ expect(store.get_by_name('test')).to eq([1, 'Testing'])
114
114
  end
115
115
 
116
116
  it 'should return the value with meta for a given name' do
117
117
  store.set 1, 'test', :description => 'meta'
118
- store.get_by_name('test').should == [1, 'Testing', { :description => 'meta' }]
118
+ expect(store.get_by_name('test')).to eq([1, 'Testing', { :description => 'meta' }])
119
119
  end
120
120
 
121
121
  it 'should return nil when name not found' do
122
- store.get_by_name('test').should be_nil
122
+ expect(store.get_by_name('test')).to be_nil
123
123
  end
124
124
  end
125
125
 
@@ -137,7 +137,7 @@ describe ActiveEnum::Storage::I18nStore do
137
137
 
138
138
  store.set 2, 'name2'
139
139
  store.set 1, 'name1'
140
- store.values.should == [[1,'Name 1'], [2, 'Name 2']]
140
+ expect(store.values).to eq([[1,'Name 1'], [2, 'Name 2']])
141
141
  end
142
142
 
143
143
  it 'should sort values descending when passed :desc' do
@@ -145,7 +145,7 @@ describe ActiveEnum::Storage::I18nStore do
145
145
 
146
146
  store.set 1, 'name1'
147
147
  store.set 2, 'name2'
148
- store.values.should == [[2, 'Name 2'], [1,'Name 1']]
148
+ expect(store.values).to eq([[2, 'Name 2'], [1,'Name 1']])
149
149
  end
150
150
 
151
151
  it 'should not sort values when passed :natural' do
@@ -154,7 +154,7 @@ describe ActiveEnum::Storage::I18nStore do
154
154
  store.set 1, 'name1'
155
155
  store.set 3, 'name3'
156
156
  store.set 2, 'name2'
157
- store.values.should == [[1,'Name 1'], [3,'Name 3'], [2, 'Name 2']]
157
+ expect(store.values).to eq([[1,'Name 1'], [3,'Name 3'], [2, 'Name 2']])
158
158
  end
159
159
  end
160
160
 
@@ -171,12 +171,12 @@ describe ActiveEnum::Storage::I18nStore do
171
171
 
172
172
  it 'should return array values from yaml' do
173
173
  store.set 1, 'things'
174
- store.get_by_name('things').should eq [1, 'Generic things']
174
+ expect(store.get_by_name('things')).to eq [1, 'Generic things']
175
175
  end
176
176
 
177
177
  it 'should not load locale entry unless defined in enum' do
178
178
  store.set 1, 'things'
179
- store.get_by_name('not_found').should be_nil
179
+ expect(store.get_by_name('not_found')).to be_nil
180
180
  end
181
181
  end
182
182
 
@@ -186,12 +186,12 @@ describe ActiveEnum::Storage::I18nStore do
186
186
 
187
187
  it 'should return array values from yaml' do
188
188
  store.set 1, 'things'
189
- store.get_by_name('things').should eq [1, 'Model things']
189
+ expect(store.get_by_name('things')).to eq [1, 'Model things']
190
190
  end
191
191
 
192
192
  it 'should not load locale entry unless defined in enum' do
193
193
  store.set 1, 'things'
194
- store.get_by_name('not_found').should be_nil
194
+ expect(store.get_by_name('not_found')).to be_nil
195
195
  end
196
196
  end
197
197
 
@@ -9,73 +9,73 @@ describe ActiveEnum::Storage::MemoryStore do
9
9
  describe '#set' do
10
10
  it 'should store value of id and name' do
11
11
  store.set 1, 'test name'
12
- store.values.should == [[1, 'test name']]
12
+ expect(store.values).to eq([[1, 'test name']])
13
13
  end
14
14
 
15
15
  it 'should store value of id, name and meta hash' do
16
16
  store.set 1, 'test name', :description => 'meta'
17
- store.values.should == [[1, 'test name', {:description => 'meta'}]]
17
+ expect(store.values).to eq([[1, 'test name', {:description => 'meta'}]])
18
18
  end
19
19
 
20
20
  it 'should raise error if duplicate id' do
21
21
  expect {
22
22
  store.set 1, 'Name 1'
23
23
  store.set 1, 'Other Name'
24
- }.should raise_error(ActiveEnum::DuplicateValue)
24
+ }.to raise_error(ActiveEnum::DuplicateValue)
25
25
  end
26
26
 
27
27
  it 'should raise error if duplicate name' do
28
28
  expect {
29
29
  store.set 1, 'Name 1'
30
30
  store.set 2, 'Name 1'
31
- }.should raise_error(ActiveEnum::DuplicateValue)
31
+ }.to raise_error(ActiveEnum::DuplicateValue)
32
32
  end
33
33
 
34
34
  it 'should raise error if duplicate name matches title-case name' do
35
35
  expect {
36
36
  store.set 1, 'Name 1'
37
37
  store.set 2, 'name 1'
38
- }.should raise_error(ActiveEnum::DuplicateValue)
38
+ }.to raise_error(ActiveEnum::DuplicateValue)
39
39
  end
40
40
  end
41
41
 
42
42
  describe "#values" do
43
43
  it 'should return array of stored values' do
44
44
  store.set 1, 'Name 1'
45
- store.values.should == [[1, 'Name 1']]
45
+ expect(store.values).to eq([[1, 'Name 1']])
46
46
  end
47
47
 
48
48
  it 'should return values for set enum only' do
49
49
  alt_store.set 1, 'Other Name 1'
50
50
  store.set 1, 'Name 1'
51
- store.values.should == [[1, 'Name 1']]
51
+ expect(store.values).to eq([[1, 'Name 1']])
52
52
  end
53
53
  end
54
54
 
55
55
  describe "#get_by_id" do
56
56
  it 'should return the value for a given id' do
57
57
  store.set 1, 'test name', :description => 'meta'
58
- store.get_by_id(1).should == [1, 'test name', {:description => "meta"}]
58
+ expect(store.get_by_id(1)).to eq([1, 'test name', {:description => "meta"}])
59
59
  end
60
60
 
61
61
  it 'should return nil when id not found' do
62
- store.get_by_id(1).should be_nil
62
+ expect(store.get_by_id(1)).to be_nil
63
63
  end
64
64
  end
65
65
 
66
66
  describe "#get_by_name" do
67
67
  it 'should return the value for a given name' do
68
68
  store.set 1, 'test name'
69
- store.get_by_name('test name').should == [1, 'test name']
69
+ expect(store.get_by_name('test name')).to eq([1, 'test name'])
70
70
  end
71
71
 
72
72
  it 'should return the value with title-cased name for a given lowercase name' do
73
73
  store.set 1, 'Test Name'
74
- store.get_by_name('test name').should == [1, 'Test Name']
74
+ expect(store.get_by_name('test name')).to eq([1, 'Test Name'])
75
75
  end
76
76
 
77
77
  it 'should return nil when name not found' do
78
- store.get_by_name('test name').should be_nil
78
+ expect(store.get_by_name('test name')).to be_nil
79
79
  end
80
80
  end
81
81
 
@@ -84,14 +84,14 @@ describe ActiveEnum::Storage::MemoryStore do
84
84
  @order = :asc
85
85
  store.set 2, 'Name 2'
86
86
  store.set 1, 'Name 1'
87
- store.values.should == [[1,'Name 1'], [2, 'Name 2']]
87
+ expect(store.values).to eq([[1,'Name 1'], [2, 'Name 2']])
88
88
  end
89
89
 
90
90
  it 'should sort values descending when passed :desc' do
91
91
  @order = :desc
92
92
  store.set 1, 'Name 1'
93
93
  store.set 2, 'Name 2'
94
- store.values.should == [[2, 'Name 2'], [1,'Name 1']]
94
+ expect(store.values).to eq([[2, 'Name 2'], [1,'Name 1']])
95
95
  end
96
96
 
97
97
  it 'should not sort values when passed :natural' do
@@ -99,7 +99,7 @@ describe ActiveEnum::Storage::MemoryStore do
99
99
  store.set 1, 'Name 1'
100
100
  store.set 3, 'Name 3'
101
101
  store.set 2, 'Name 2'
102
- store.values.should == [[1,'Name 1'], [3,'Name 3'], [2, 'Name 2']]
102
+ expect(store.values).to eq([[1,'Name 1'], [3,'Name 3'], [2, 'Name 2']])
103
103
  end
104
104
  end
105
105
 
@@ -13,8 +13,8 @@ describe ActiveEnum do
13
13
  value :id => 1, :name => 'Bar 1'
14
14
  end
15
15
  end
16
- Foo.all.should == [[1,'Foo 1']]
17
- Bar.all.should == [[1,'Bar 1']]
16
+ expect(Foo.all).to eq([[1,'Foo 1']])
17
+ expect(Bar.all).to eq([[1,'Bar 1']])
18
18
  end
19
19
  end
20
20
 
@@ -24,9 +24,9 @@ describe ActiveEnum do
24
24
  end
25
25
 
26
26
  it 'should pass module into block as configuration object' do
27
- ActiveEnum.use_name_as_value.should be_false
27
+ expect(ActiveEnum.use_name_as_value).to be_falsey
28
28
  ActiveEnum.setup {|config| config.use_name_as_value = true }
29
- ActiveEnum.use_name_as_value.should be_true
29
+ expect(ActiveEnum.use_name_as_value).to be_truthy
30
30
  end
31
31
 
32
32
  after :all do
@@ -38,16 +38,16 @@ describe ActiveEnum do
38
38
  it 'should add enumerate extensions to given classes' do
39
39
  ActiveEnum.extend_classes = [NotActiveRecord]
40
40
 
41
- NotActiveRecord.should_not respond_to(:enumerate)
41
+ expect(NotActiveRecord).not_to respond_to(:enumerate)
42
42
 
43
43
  ActiveEnum.extend_classes!
44
44
 
45
- NotActiveRecord.should respond_to(:enumerate)
45
+ expect(NotActiveRecord).to respond_to(:enumerate)
46
46
  end
47
47
  end
48
48
 
49
49
  it 'should use the memory store by default' do
50
- ActiveEnum.storage.should == :memory
50
+ expect(ActiveEnum.storage).to eq(:memory)
51
51
  end
52
52
 
53
53
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
- require 'rspec'
1
+ ENV["RAILS_ENV"] ||= 'test'
2
+ require 'spec_helper'
2
3
 
3
4
  require 'rails'
4
5
  require 'active_record'
@@ -8,6 +9,8 @@ require 'action_mailer'
8
9
 
9
10
  require 'active_enum'
10
11
  require 'active_enum/acts_as_enum'
12
+ require 'securerandom'
13
+ require 'byebug'
11
14
 
12
15
  module ActiveEnum
13
16
  class Application < Rails::Application
@@ -16,20 +19,26 @@ module ActiveEnum
16
19
  g.test_framework :rspec, :fixture => false
17
20
  end
18
21
  config.active_support.deprecation = :notify
22
+ config.eager_load = false if Rails.version >= "4.0"
23
+ config.secret_key_base = SecureRandom.hex(10) if Rails.version >= "4.0"
19
24
  end
20
25
  end
21
26
  ActiveEnum::Application.initialize!
22
27
 
23
- require 'rspec/rails'
28
+ I18n.enforce_available_locales = false
29
+ I18n.available_locales = ['en', 'ja']
24
30
 
25
31
  ActiveRecord::Migration.verbose = false
26
- ActiveRecord::Base.establish_connection({:adapter => 'sqlite3', :database => ':memory:'})
32
+ ActiveRecord::Base.establish_connection({:adapter => "sqlite3", :database => ':memory:'})
27
33
 
34
+ require 'rspec/rails'
28
35
  require 'support/schema'
29
36
 
37
+ Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each { |f| require f }
38
+
30
39
  class Person < ActiveRecord::Base; end
31
40
  class NoEnumPerson < ActiveRecord::Base
32
- set_table_name 'people'
41
+ self.table_name = 'people'
33
42
  end
34
43
 
35
44
  class NotActiveRecord
@@ -53,4 +62,16 @@ end
53
62
 
54
63
  RSpec.configure do |config|
55
64
  config.include SpecHelper
65
+ config.include ConfigHelper
66
+
67
+ # rspec-rails 3 will no longer automatically infer an example group's spec type
68
+ # from the file location. You can explicitly opt-in to the feature using this
69
+ # config option.
70
+ # To explicitly tag specs without using automatic inference, set the `:type`
71
+ # metadata manually:
72
+ #
73
+ # describe ThingsController, :type => :controller do
74
+ # # Equivalent to being in spec/controllers
75
+ # end
76
+ config.infer_spec_type_from_file_location!
56
77
  end
@@ -0,0 +1,26 @@
1
+ module ConfigHelper
2
+ extend ActiveSupport::Concern
3
+
4
+ def with_config(preference_name, temporary_value)
5
+ original_config_value = ActiveEnum.config.send(preference_name)
6
+
7
+ ActiveEnum.config.send(:"#{preference_name}=", temporary_value)
8
+ yield
9
+ ensure
10
+ ActiveEnum.config.send(:"#{preference_name}=", original_config_value)
11
+ end
12
+
13
+ module ClassMethods
14
+ def with_config(preference_name, temporary_value)
15
+ original_config_value = ActiveEnum.config.send(preference_name)
16
+
17
+ before(:all) do
18
+ ActiveEnum.config.send(:"#{preference_name}=", temporary_value)
19
+ end
20
+
21
+ after(:all) do
22
+ ActiveEnum.config.send(:"#{preference_name}=", original_config_value)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -7,6 +7,14 @@ ActiveRecord::Schema.define(:version => 1) do
7
7
  t.integer :staying
8
8
  end
9
9
 
10
+ create_table :sorted_people, :force => true do |t|
11
+ t.string :first_name
12
+ t.string :last_name
13
+ t.integer :sex
14
+ t.integer :attending
15
+ t.integer :staying
16
+ end
17
+
10
18
  create_table :sexes, :force => true do |t|
11
19
  t.string :name
12
20
  end
metadata CHANGED
@@ -1,49 +1,39 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: active_enum
3
- version: !ruby/object:Gem::Version
4
- hash: 35
5
- prerelease:
6
- segments:
7
- - 0
8
- - 9
9
- - 12
10
- version: 0.9.12
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.pre
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Adam Meehan
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2012-09-11 00:00:00 +10:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
11
+ date: 2016-10-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
22
14
  name: activesupport
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 7
30
- segments:
31
- - 3
32
- - 0
33
- version: "3.0"
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
34
20
  type: :runtime
35
- version_requirements: *id001
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
36
27
  description: Define enum classes in Rails and use them to enumerate ActiveRecord attributes
37
28
  email: adam.meehan@gmail.com
38
29
  executables: []
39
-
40
30
  extensions: []
41
-
42
- extra_rdoc_files:
31
+ extra_rdoc_files:
43
32
  - README.rdoc
44
33
  - CHANGELOG
45
34
  - MIT-LICENSE
46
- files:
35
+ files:
36
+ - ".travis.yml"
47
37
  - CHANGELOG
48
38
  - MIT-LICENSE
49
39
  - README.rdoc
@@ -54,8 +44,6 @@ files:
54
44
  - lib/active_enum/acts_as_enum.rb
55
45
  - lib/active_enum/base.rb
56
46
  - lib/active_enum/extensions.rb
57
- - lib/active_enum/form_helpers/formtastic.rb
58
- - lib/active_enum/form_helpers/formtastic2.rb
59
47
  - lib/active_enum/form_helpers/simple_form.rb
60
48
  - lib/active_enum/railtie.rb
61
49
  - lib/active_enum/storage/abstract_store.rb
@@ -69,59 +57,46 @@ files:
69
57
  - spec/active_enum/acts_as_enum_spec.rb
70
58
  - spec/active_enum/base_spec.rb
71
59
  - spec/active_enum/extensions_spec.rb
72
- - spec/active_enum/form_helpers/formtastic2_spec.rb
73
- - spec/active_enum/form_helpers/formtastic_spec.rb
74
60
  - spec/active_enum/form_helpers/simple_form_spec.rb
75
61
  - spec/active_enum/storage/i18n_store_spec.rb
76
62
  - spec/active_enum/storage/memory_store_spec.rb
77
63
  - spec/active_enum_spec.rb
78
64
  - spec/spec_helper.rb
65
+ - spec/support/config_helper.rb
79
66
  - spec/support/i18n.yml
80
67
  - spec/support/schema.rb
81
- has_rdoc: true
82
68
  homepage: http://github.com/adzap/active_enum
83
69
  licenses: []
84
-
70
+ metadata: {}
85
71
  post_install_message:
86
72
  rdoc_options: []
87
-
88
- require_paths:
73
+ require_paths:
89
74
  - lib
90
- required_ruby_version: !ruby/object:Gem::Requirement
91
- none: false
92
- requirements:
93
- - - ">="
94
- - !ruby/object:Gem::Version
95
- hash: 3
96
- segments:
97
- - 0
98
- version: "0"
99
- required_rubygems_version: !ruby/object:Gem::Requirement
100
- none: false
101
- requirements:
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
102
77
  - - ">="
103
- - !ruby/object:Gem::Version
104
- hash: 3
105
- segments:
106
- - 0
107
- version: "0"
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">"
83
+ - !ruby/object:Gem::Version
84
+ version: 1.3.1
108
85
  requirements: []
109
-
110
86
  rubyforge_project:
111
- rubygems_version: 1.5.2
87
+ rubygems_version: 2.5.1
112
88
  signing_key:
113
- specification_version: 3
89
+ specification_version: 4
114
90
  summary: Define enum classes in Rails and use them to enumerate ActiveRecord attributes
115
- test_files:
91
+ test_files:
116
92
  - spec/active_enum/acts_as_enum_spec.rb
117
93
  - spec/active_enum/base_spec.rb
118
94
  - spec/active_enum/extensions_spec.rb
119
- - spec/active_enum/form_helpers/formtastic2_spec.rb
120
- - spec/active_enum/form_helpers/formtastic_spec.rb
121
95
  - spec/active_enum/form_helpers/simple_form_spec.rb
122
96
  - spec/active_enum/storage/i18n_store_spec.rb
123
97
  - spec/active_enum/storage/memory_store_spec.rb
124
98
  - spec/active_enum_spec.rb
125
99
  - spec/spec_helper.rb
100
+ - spec/support/config_helper.rb
126
101
  - spec/support/i18n.yml
127
102
  - spec/support/schema.rb