enumerate_it 1.2.3 → 1.2.4

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.2.3)
4
+ enumerate_it (1.2.4)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -56,11 +56,13 @@ module EnumerateIt
56
56
  end
57
57
 
58
58
  def self.values_for(values)
59
- values.map { |v| self.const_get(v.to_sym) }
59
+ values.map { |v| self.value_for v.to_sym }
60
60
  end
61
61
 
62
62
  def self.value_for(value)
63
63
  self.const_get(value.to_sym)
64
+ rescue NameError
65
+ nil
64
66
  end
65
67
 
66
68
  def self.keys
@@ -1,3 +1,3 @@
1
1
  module EnumerateIt
2
- VERSION = "1.2.3"
2
+ VERSION = "1.2.4"
3
3
  end
@@ -97,12 +97,22 @@ describe EnumerateIt::Base do
97
97
  it "returns an array with the corresponding values for a string array representing some of the enumeration's values" do
98
98
  TestEnumeration.values_for(%w(VALUE_1 VALUE_2)).should == [TestEnumeration::VALUE_1, TestEnumeration::VALUE_2]
99
99
  end
100
+
101
+ it "returns a nil value if the a constant named after one of the given strings cannot be found" do
102
+ TestEnumeration.values_for(%w(VALUE_1 THIS_IS_WRONG)).should == [TestEnumeration::VALUE_1, nil]
103
+ end
100
104
  end
101
105
 
102
106
  describe ".value_for" do
103
107
  it "returns the enumeration's value" do
104
108
  TestEnumeration.value_for("VALUE_1").should == TestEnumeration::VALUE_1
105
109
  end
110
+
111
+ context "when a constant named after the received value cannot be found" do
112
+ it "returns nil" do
113
+ TestEnumeration.value_for("THIS_IS_WRONG").should be_nil
114
+ end
115
+ end
106
116
  end
107
117
 
108
118
  describe ".keys" do
@@ -262,9 +262,15 @@ describe EnumerateIt do
262
262
  end
263
263
 
264
264
  context "when the hosting class do not respond to :scope" do
265
+ before do
266
+ class GenericClass
267
+ extend EnumerateIt
268
+ end
269
+ end
270
+
265
271
  it "raises no errors" do
266
272
  expect {
267
- setup_enumeration
273
+ GenericClass.send(:has_enumeration_for, :foobar, :with => TestEnumeration, :create_scopes => true)
268
274
  }.to_not raise_error
269
275
  end
270
276
  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.2.3
4
+ version: 1.2.4
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: 2014-07-25 00:00:00.000000000 Z
12
+ date: 2015-02-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -155,7 +155,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
155
155
  segments:
156
156
  - 0
157
157
  version: '0'
158
- hash: -4367608046587642592
158
+ hash: 786857682386495207
159
159
  required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  none: false
161
161
  requirements:
@@ -164,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
164
  segments:
165
165
  - 0
166
166
  version: '0'
167
- hash: -4367608046587642592
167
+ hash: 786857682386495207
168
168
  requirements: []
169
169
  rubyforge_project:
170
170
  rubygems_version: 1.8.24