enumerate_it 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- enumerate_it (1.0.2)
4
+ enumerate_it (1.0.3)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -19,8 +19,16 @@ GEM
19
19
  activesupport (3.0.5)
20
20
  arel (2.0.9)
21
21
  builder (2.1.2)
22
+ coderay (1.0.9)
22
23
  diff-lcs (1.1.2)
23
24
  i18n (0.5.0)
25
+ method_source (0.8.1)
26
+ pry (0.9.12)
27
+ coderay (~> 1.0.5)
28
+ method_source (~> 0.8)
29
+ slop (~> 3.4)
30
+ pry-nav (0.2.3)
31
+ pry (~> 0.9.10)
24
32
  rake (0.9.2.2)
25
33
  rspec (2.5.0)
26
34
  rspec-core (~> 2.5.0)
@@ -30,6 +38,7 @@ GEM
30
38
  rspec-expectations (2.5.0)
31
39
  diff-lcs (~> 1.1.2)
32
40
  rspec-mocks (2.5.0)
41
+ slop (3.4.4)
33
42
  tzinfo (0.3.24)
34
43
 
35
44
  PLATFORMS
@@ -38,5 +47,7 @@ PLATFORMS
38
47
  DEPENDENCIES
39
48
  activerecord (>= 3.0.5)
40
49
  enumerate_it!
50
+ pry
51
+ pry-nav
41
52
  rake
42
53
  rspec (>= 2.5.0)
@@ -68,7 +68,8 @@ module EnumerateIt
68
68
 
69
69
  def define_enumeration_class(attribute, options)
70
70
  if options[:with].nil?
71
- options[:with] = attribute.to_s.camelize.constantize
71
+ inner_enum_class_name = attribute.to_s.camelize.to_sym
72
+ options[:with] = self.constants.include?(inner_enum_class_name) ? self.const_get(inner_enum_class_name) : attribute.to_s.camelize.constantize
72
73
  end
73
74
  end
74
75
 
@@ -1,3 +1,3 @@
1
1
  module EnumerateIt
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
@@ -1,5 +1,6 @@
1
1
  #encoding: utf-8
2
2
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+ require 'active_record'
3
4
 
4
5
  class TestEnumeration < EnumerateIt::Base
5
6
  associate_values(
@@ -132,7 +133,9 @@ describe EnumerateIt do
132
133
  class FooBar
133
134
  extend EnumerateIt
134
135
  attr_accessor :test_enumeration
136
+
135
137
  has_enumeration_for :test_enumeration
138
+
136
139
  def initialize(test_enumeration_value)
137
140
  @test_enumeration = test_enumeration_value
138
141
  end
@@ -143,6 +146,34 @@ describe EnumerateIt do
143
146
  target = FooBar.new(TestEnumeration::VALUE_1)
144
147
  target.test_enumeration_humanize.should == 'Hey, I am 1!'
145
148
  end
149
+
150
+ context "when using a nested class as the enumeration" do
151
+ before do
152
+ class NestedEnum < EnumerateIt::Base
153
+ associate_values :foo => ['1', 'Fooo'], :bar => ['2', 'Barrrr']
154
+ end
155
+
156
+ class ClassWithNestedEnum
157
+ class NestedEnum < EnumerateIt::Base
158
+ associate_values :foo => ['1', 'Blerrgh'], :bar => ['2' => 'Blarghhh']
159
+ end
160
+
161
+ extend EnumerateIt
162
+
163
+ attr_accessor :nested_enum
164
+
165
+ has_enumeration_for :nested_enum
166
+
167
+ def initialize(nested_enum_value)
168
+ @nested_enum = nested_enum_value
169
+ end
170
+ end
171
+ end
172
+
173
+ it "uses the inner class as the enumeration class" do
174
+ target = ClassWithNestedEnum.new('1').nested_enum_humanize.should == 'Blerrgh'
175
+ end
176
+ end
146
177
  end
147
178
  end
148
179
 
@@ -199,29 +230,28 @@ describe EnumerateIt do
199
230
 
200
231
  describe "using the :create_scopes option" do
201
232
  def setup_enumeration
202
- TestClass.send(:has_enumeration_for, :foobar, :with => TestEnumeration, :create_scopes => true)
233
+ OtherTestClass.send(:has_enumeration_for, :foobar, :with => TestEnumeration, :create_scopes => true)
203
234
  end
204
235
 
205
236
  context "if the hosting class responds to :scope" do
206
237
  before do
207
- class TestClass
208
- def self.where(whatever); end
209
- def self.scope(name, whatever); end
238
+ class OtherTestClass < ActiveRecord::Base
239
+ extend EnumerateIt
210
240
  end
211
241
 
212
242
  setup_enumeration
213
243
  end
214
244
 
215
245
  it "creates a scope for each enumeration value" do
216
- TestEnumeration.enumeration do |symbol, pair|
217
- TestClass.should respond_to(symbol)
246
+ TestEnumeration.enumeration.keys.each do |symbol|
247
+ OtherTestClass.should respond_to(symbol)
218
248
  end
219
249
  end
220
250
 
221
251
  it "when called, the scopes create the correct query" do
222
- TestEnumeration.enumeration do |symbol, pair|
223
- TestClass.should_receive(:where).with(:foobar => pair.firs)
224
- TestClass.send symbol
252
+ TestEnumeration.enumeration.each do |symbol, pair|
253
+ OtherTestClass.should_receive(:where).with(:foobar => pair.first)
254
+ OtherTestClass.send symbol
225
255
  end
226
256
  end
227
257
  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.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-18 00:00:00.000000000 Z
12
+ date: 2013-03-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -75,6 +75,38 @@ dependencies:
75
75
  - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: 3.0.5
78
+ - !ruby/object:Gem::Dependency
79
+ name: pry
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: pry-nav
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
78
110
  description: Have a legacy database and need some enumerations in your models to match
79
111
  those stupid '4 rows/2 columns' tables with foreign keys and stop doing joins just
80
112
  to fetch a simple description? Or maybe use some integers instead of strings as
@@ -124,7 +156,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
124
156
  version: '0'
125
157
  segments:
126
158
  - 0
127
- hash: 709884351936478852
159
+ hash: -1389146170184327843
128
160
  required_rubygems_version: !ruby/object:Gem::Requirement
129
161
  none: false
130
162
  requirements:
@@ -133,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
165
  version: '0'
134
166
  segments:
135
167
  - 0
136
- hash: 709884351936478852
168
+ hash: -1389146170184327843
137
169
  requirements: []
138
170
  rubyforge_project:
139
171
  rubygems_version: 1.8.24