enumerate_it 1.3.0 → 1.3.1.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,7 @@
3
3
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
4
4
 
5
5
  describe EnumerateIt do
6
- before do
6
+ let :target do
7
7
  class TestClass
8
8
  extend EnumerateIt
9
9
  attr_accessor :foobar
@@ -16,57 +16,62 @@ describe EnumerateIt do
16
16
  I18n.locale = :en
17
17
  end
18
18
 
19
- @target = TestClass.new(TestEnumeration::VALUE_2)
19
+ TestClass.new(TestEnumeration::VALUE_2)
20
20
  end
21
21
 
22
- context "associating an enumeration with a class attribute" do
22
+ context 'associating an enumeration with a class attribute' do
23
23
  it "creates an humanized description for the attribute's value" do
24
- expect(@target.foobar_humanize).to eq('Hey, I am 2!')
24
+ expect(target.foobar_humanize).to eq('Hey, I am 2!')
25
25
  end
26
26
 
27
- it "if the attribute is blank, the humanize description is nil" do
28
- @target.foobar = nil
29
- expect(@target.foobar_humanize).to be_nil
27
+ it 'if the attribute is blank, the humanize description is nil' do
28
+ target.foobar = nil
29
+ expect(target.foobar_humanize).to be_nil
30
30
  end
31
31
 
32
- it "defaults to not creating helper methods" do
33
- expect(@target).not_to respond_to(:value_1?)
32
+ it 'defaults to not creating helper methods' do
33
+ expect(target).not_to respond_to(:value_1?)
34
34
  end
35
35
 
36
- it "stores the enumeration class in a class-level hash" do
36
+ it 'stores the enumeration class in a class-level hash' do
37
37
  expect(TestClass.enumerations[:foobar]).to eq(TestEnumeration)
38
38
  end
39
39
 
40
40
  context 'use the same enumeration from an inherited class' do
41
- before do
41
+ let :target do
42
42
  class SomeClassWithoutEnum < BaseClass
43
43
  end
44
- @target = SomeClassWithoutEnum.new
44
+
45
+ SomeClassWithoutEnum.new
45
46
  end
46
47
 
47
- it 'should have use the correct class' do
48
- @base = BaseClass.new
49
- expect(@base.class.enumerations[:foobar]).to eq(TestEnumeration)
50
- expect(@target.class.enumerations[:foobar]).to eq(TestEnumeration)
48
+ let(:base) { BaseClass.new }
49
+
50
+ it 'has use the correct class' do
51
+ expect(base.class.enumerations[:foobar]).to eq(TestEnumeration)
52
+ expect(target.class.enumerations[:foobar]).to eq(TestEnumeration)
51
53
  end
52
54
  end
53
55
 
54
56
  context 'declaring a simple enum on an inherited class' do
55
- before do
57
+ let :target do
56
58
  class SomeClass < BaseClass
57
59
  has_enumeration_for :foobar
58
60
  end
59
- @target = SomeClass.new
61
+
62
+ SomeClass.new
60
63
  end
61
- it 'should have use the corret class' do
62
- @base = BaseClass.new
63
- expect(@base.class.enumerations[:foobar]).to eq(TestEnumeration)
64
- expect(@target.class.enumerations[:foobar]).to eq(Foobar)
64
+
65
+ let(:base) { BaseClass.new }
66
+
67
+ it 'has use the corret class' do
68
+ expect(base.class.enumerations[:foobar]).to eq(TestEnumeration)
69
+ expect(target.class.enumerations[:foobar]).to eq(Foobar)
65
70
  end
66
71
  end
67
72
 
68
- context "passing the value of each option without the human string (just the value, without an array)" do
69
- before do
73
+ context 'passing options values without the human string (just the value, without an array)' do
74
+ let :target do
70
75
  class TestClassForEnumerationWithoutArray
71
76
  extend EnumerateIt
72
77
  attr_accessor :foobar
@@ -77,56 +82,54 @@ describe EnumerateIt do
77
82
  end
78
83
  end
79
84
 
80
- @target = TestClassForEnumerationWithoutArray.new(TestEnumerationWithoutArray::VALUE_TWO)
85
+ TestClassForEnumerationWithoutArray.new(TestEnumerationWithoutArray::VALUE_TWO)
81
86
  end
82
87
 
83
- it "humanizes the respective hash key" do
84
- expect(@target.foobar_humanize).to eq('Value Two')
88
+ it 'humanizes the respective hash key' do
89
+ expect(target.foobar_humanize).to eq('Value Two')
85
90
  end
86
91
 
87
- it "translates the respective hash key when a translation is found" do
88
- @target.foobar = TestEnumerationWithoutArray::VALUE_ONE
89
- expect(@target.foobar_humanize).to eq('First Value')
92
+ it 'translates the respective hash key when a translation is found' do
93
+ target.foobar = TestEnumerationWithoutArray::VALUE_ONE
94
+ expect(target.foobar_humanize).to eq('First Value')
90
95
  I18n.locale = :pt
91
96
 
92
- expect(@target.foobar_humanize).to eq('Primeiro Valor')
97
+ expect(target.foobar_humanize).to eq('Primeiro Valor')
93
98
  end
94
99
  end
95
100
 
96
- context "without passing the enumeration class" do
97
- before do
101
+ context 'without passing the enumeration class' do
102
+ let :target do
98
103
  class FooBar
99
104
  extend EnumerateIt
100
105
  attr_accessor :test_enumeration
101
-
102
106
  has_enumeration_for :test_enumeration
103
107
 
104
108
  def initialize(test_enumeration_value)
105
109
  @test_enumeration = test_enumeration_value
106
110
  end
107
111
  end
112
+
113
+ FooBar.new(TestEnumeration::VALUE_1)
108
114
  end
109
115
 
110
- it "should find out which enumeration class to use" do
111
- target = FooBar.new(TestEnumeration::VALUE_1)
116
+ it 'finds out which enumeration class to use' do
112
117
  expect(target.test_enumeration_humanize).to eq('Hey, I am 1!')
113
118
  end
114
119
 
115
- context "when using a nested class as the enumeration" do
120
+ context 'when using a nested class as the enumeration' do
116
121
  before do
117
122
  class NestedEnum < EnumerateIt::Base
118
- associate_values foo: ['1', 'Fooo'], bar: ['2', 'Barrrr']
123
+ associate_values foo: %w(1 Fooo), bar: %w(2 Barrrr)
119
124
  end
120
125
 
121
126
  class ClassWithNestedEnum
122
127
  class NestedEnum < EnumerateIt::Base
123
- associate_values foo: ['1', 'Blerrgh'], bar: ['2' => 'Blarghhh']
128
+ associate_values foo: %w(1 Blerrgh), bar: ['2' => 'Blarghhh']
124
129
  end
125
130
 
126
131
  extend EnumerateIt
127
-
128
132
  attr_accessor :nested_enum
129
-
130
133
  has_enumeration_for :nested_enum
131
134
 
132
135
  def initialize(nested_enum_value)
@@ -135,14 +138,14 @@ describe EnumerateIt do
135
138
  end
136
139
  end
137
140
 
138
- it "uses the inner class as the enumeration class" do
141
+ it 'uses the inner class as the enumeration class' do
139
142
  expect(ClassWithNestedEnum.new('1').nested_enum_humanize).to eq('Blerrgh')
140
143
  end
141
144
  end
142
145
  end
143
146
  end
144
147
 
145
- context "using the :create_helpers option" do
148
+ context 'using the :create_helpers option' do
146
149
  before do
147
150
  class TestClassWithHelper
148
151
  extend EnumerateIt
@@ -155,13 +158,13 @@ describe EnumerateIt do
155
158
  end
156
159
  end
157
160
 
158
- it "creates helpers methods with question marks for each enumeration option" do
161
+ it 'creates helpers methods with question marks for each enumeration option' do
159
162
  target = TestClassWithHelper.new(TestEnumeration::VALUE_2)
160
163
  expect(target).to be_value_2
161
164
  expect(target).not_to be_value_1
162
165
  end
163
166
 
164
- it "creates a mutator method for each enumeration value" do
167
+ it 'creates a mutator method for each enumeration value' do
165
168
  [:value_1, :value_2, :value_3].each do |value|
166
169
  expect(TestClassWithHelper.new(TestEnumeration::VALUE_1)).to respond_to(:"#{value}!")
167
170
  end
@@ -173,21 +176,22 @@ describe EnumerateIt do
173
176
  expect(target.foobar).to eq(TestEnumeration::VALUE_3)
174
177
  end
175
178
 
176
- context "with :prefix option" do
179
+ context 'with :prefix option' do
177
180
  before do
178
181
  class TestClassWithHelper
179
182
  has_enumeration_for :foobar, with: TestEnumeration, create_helpers: { prefix: true }
180
183
  end
181
184
  end
182
185
 
183
- it "creates helpers methods with question marks and prefixes for each enumeration option" do
186
+ it 'creates helpers methods with question marks and prefixes for each enumeration option' do
184
187
  target = TestClassWithHelper.new(TestEnumeration::VALUE_2)
185
188
  expect(target).to be_foobar_value_2
186
189
  end
187
190
 
188
- it "creates a mutator method for each enumeration value" do
191
+ it 'creates a mutator method for each enumeration value' do
189
192
  [:value_1, :value_2, :value_3].each do |value|
190
- expect(TestClassWithHelper.new(TestEnumeration::VALUE_1)).to respond_to(:"foobar_#{value}!")
193
+ expect(TestClassWithHelper.new(TestEnumeration::VALUE_1))
194
+ .to respond_to(:"foobar_#{value}!")
191
195
  end
192
196
  end
193
197
 
@@ -198,7 +202,7 @@ describe EnumerateIt do
198
202
  end
199
203
  end
200
204
 
201
- context "with :polymorphic option" do
205
+ context 'with :polymorphic option' do
202
206
  before do
203
207
  class Polymorphic
204
208
  extend EnumerateIt
@@ -211,23 +215,24 @@ describe EnumerateIt do
211
215
  target = Polymorphic.new
212
216
  target.foo = PolymorphicEnum::NORMAL
213
217
 
214
- expect(target.foo_object.print("Gol")).to eq("I'm Normal: Gol")
218
+ expect(target.foo_object.print('Gol')).to eq("I'm Normal: Gol")
215
219
 
216
220
  target.foo = PolymorphicEnum::CRAZY
217
221
 
218
- expect(target.foo_object.print("Gol")).to eq("Whoa!: Gol")
222
+ expect(target.foo_object.print('Gol')).to eq('Whoa!: Gol')
219
223
  end
220
224
 
221
- it "returns nil if foo is not set" do
225
+ it 'returns nil if foo is not set' do
222
226
  target = Polymorphic.new
223
227
 
224
228
  expect(target.foo_object).to be_nil
225
229
  end
226
230
 
227
- context "and :suffix" do
231
+ context 'and :suffix' do
228
232
  before do
229
233
  class Polymorphic
230
- has_enumeration_for :foo, with: PolymorphicEnum, create_helpers: { polymorphic: { suffix: "_strategy" } }
234
+ has_enumeration_for :foo, with: PolymorphicEnum,
235
+ create_helpers: { polymorphic: { suffix: '_strategy' } }
231
236
  end
232
237
  end
233
238
 
@@ -235,22 +240,20 @@ describe EnumerateIt do
235
240
  target = Polymorphic.new
236
241
  target.foo = PolymorphicEnum::NORMAL
237
242
 
238
- expect(target.foo_strategy.print("Gol")).to eq("I'm Normal: Gol")
243
+ expect(target.foo_strategy.print('Gol')).to eq("I'm Normal: Gol")
239
244
 
240
245
  target.foo = PolymorphicEnum::CRAZY
241
246
 
242
- expect(target.foo_strategy.print("Gol")).to eq("Whoa!: Gol")
247
+ expect(target.foo_strategy.print('Gol')).to eq('Whoa!: Gol')
243
248
  end
244
249
  end
245
250
  end
246
251
  end
247
252
 
248
- describe "using the :create_scopes option" do
249
- context "if the hosting class responds to :scope" do
253
+ describe 'using the :create_scopes option' do
254
+ context 'if the hosting class responds to :scope' do
250
255
  before do
251
- if ActiveSupport::VERSION::STRING =~ /3\.1/
252
- Object.send :remove_const, 'TestClassWithScope' if defined?(TestClassWithScope)
253
- end
256
+ Object.send :remove_const, 'TestClassWithScope' if defined?(TestClassWithScope)
254
257
 
255
258
  class TestClassWithScope < ActiveRecord::Base
256
259
  extend EnumerateIt
@@ -258,43 +261,44 @@ describe EnumerateIt do
258
261
  end
259
262
  end
260
263
 
261
- it "creates a scope for each enumeration value" do
264
+ it 'creates a scope for each enumeration value' do
262
265
  TestEnumeration.enumeration.keys.each do |symbol|
263
266
  expect(TestClassWithScope).to respond_to(symbol)
264
267
  end
265
268
  end
266
269
 
267
- it "when called, the scopes create the correct query" do
270
+ it 'when called, the scopes create the correct query' do
268
271
  TestEnumeration.enumeration.each do |symbol, pair|
269
272
  expect(TestClassWithScope).to receive(:where).with(foobar: pair.first)
270
- TestClassWithScope.send symbol
273
+ TestClassWithScope.send(symbol)
271
274
  end
272
275
  end
273
276
  end
274
277
 
275
- context "when the hosting class do not respond to :scope" do
278
+ context 'when the hosting class do not respond to :scope' do
276
279
  before do
277
280
  class GenericClass
278
281
  extend EnumerateIt
279
282
  end
280
283
  end
281
284
 
282
- it "raises no errors" do
283
- expect {
284
- GenericClass.send(:has_enumeration_for, :foobar, with: TestEnumeration, create_scopes: true)
285
- }.to_not raise_error
285
+ it 'raises no errors' do
286
+ expect do
287
+ GenericClass.has_enumeration_for(:foobar, with: TestEnumeration, create_scopes: true)
288
+ end.not_to raise_error
286
289
  end
287
290
  end
288
291
 
289
- context "with :prefix option" do
292
+ context 'with :prefix option' do
290
293
  before do
291
294
  class OtherTestClass < ActiveRecord::Base
292
295
  extend EnumerateIt
293
- has_enumeration_for :foobar, with: TestEnumerationWithReservedWords, create_scopes: { prefix: true }
296
+ has_enumeration_for :foobar, with: TestEnumerationWithReservedWords,
297
+ create_scopes: { prefix: true }
294
298
  end
295
299
  end
296
300
 
297
- it "creates a scope with prefix for each enumeration value" do
301
+ it 'creates a scope with prefix for each enumeration value' do
298
302
  TestEnumerationWithReservedWords.enumeration.keys.each do |symbol|
299
303
  expect(OtherTestClass).to respond_to(:"foobar_#{symbol}")
300
304
  end
@@ -11,6 +11,6 @@ I18n.config.enforce_available_locales = false
11
11
  I18n.load_path = Dir['spec/i18n/*.yml']
12
12
 
13
13
  RSpec.configure do |config|
14
- config.filter_run_including focus: true
14
+ config.filter_run :focus
15
15
  config.run_all_when_everything_filtered = true
16
16
  end
@@ -75,10 +75,10 @@ def create_enumeration_class_with_sort_mode(sort_mode)
75
75
  sort_by sort_mode
76
76
 
77
77
  associate_values(
78
- foo: ["1", "xyz"],
79
- bar: ["2", "fgh"],
80
- omg: ["3", "abc"],
81
- zomg: ["0", "jkl"]
78
+ foo: %w(1 xyz),
79
+ bar: %w(2 fgh),
80
+ omg: %w(3 abc),
81
+ zomg: %w(0 jkl)
82
82
  )
83
83
  end
84
84
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enumerate_it
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cássio Marques
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-06-01 00:00:00.000000000 Z
12
+ date: 2016-08-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -95,15 +95,29 @@ dependencies:
95
95
  - - ">="
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: rubocop-rspec
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
98
112
  description: Enumerations for Ruby with some magic powers!
99
113
  email:
100
114
  executables: []
101
115
  extensions: []
102
116
  extra_rdoc_files: []
103
117
  files:
104
- - ".document"
105
118
  - ".gitignore"
106
119
  - ".rspec"
120
+ - ".rubocop.yml"
107
121
  - ".ruby-version"
108
122
  - ".travis.yml"
109
123
  - Appraisals
@@ -114,12 +128,13 @@ files:
114
128
  - README.md
115
129
  - Rakefile
116
130
  - enumerate_it.gemspec
117
- - gemfiles/activesupport_3_0.gemfile
118
- - gemfiles/activesupport_3_1.gemfile
119
- - gemfiles/activesupport_3_2.gemfile
120
- - gemfiles/activesupport_4_0.gemfile
121
- - gemfiles/activesupport_4_1.gemfile
122
- - gemfiles/activesupport_4_2.gemfile
131
+ - gemfiles/rails_3.0.gemfile
132
+ - gemfiles/rails_3.1.gemfile
133
+ - gemfiles/rails_3.2.gemfile
134
+ - gemfiles/rails_4.0.gemfile
135
+ - gemfiles/rails_4.1.gemfile
136
+ - gemfiles/rails_4.2.gemfile
137
+ - gemfiles/rails_5.0.gemfile
123
138
  - lib/enumerate_it.rb
124
139
  - lib/enumerate_it/base.rb
125
140
  - lib/enumerate_it/class_methods.rb
@@ -151,12 +166,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
151
166
  version: '0'
152
167
  required_rubygems_version: !ruby/object:Gem::Requirement
153
168
  requirements:
154
- - - ">="
169
+ - - ">"
155
170
  - !ruby/object:Gem::Version
156
- version: '0'
171
+ version: 1.3.1
157
172
  requirements: []
158
173
  rubyforge_project:
159
- rubygems_version: 2.5.1
174
+ rubygems_version: 2.6.6
160
175
  signing_key:
161
176
  specification_version: 4
162
177
  summary: Ruby Enumerations