has_constant 0.4.3 → 0.4.4
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.
- data/Gemfile +1 -0
- data/Gemfile.lock +3 -0
- data/VERSION +1 -1
- data/has_constant.gemspec +2 -2
- data/lib/has_constant.rb +1 -2
- data/test/has_constant_test.rb +8 -0
- metadata +4 -4
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -21,6 +21,8 @@ GEM
|
|
21
21
|
bundler (~> 1.0.0)
|
22
22
|
git (>= 1.2.5)
|
23
23
|
rake
|
24
|
+
mocha (0.9.11)
|
25
|
+
rake
|
24
26
|
mongo (1.1.5)
|
25
27
|
bson (>= 1.1.5)
|
26
28
|
mongoid (2.0.0.beta.20)
|
@@ -43,6 +45,7 @@ DEPENDENCIES
|
|
43
45
|
bson
|
44
46
|
bson_ext
|
45
47
|
jeweler
|
48
|
+
mocha
|
46
49
|
mongoid (= 2.0.0.beta.20)
|
47
50
|
shoulda
|
48
51
|
sqlite3-ruby
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.4
|
data/has_constant.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{has_constant}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["mattbeedle"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-02-04}
|
13
13
|
s.description = %q{Allows certain fields to be limited to a set of values}
|
14
14
|
s.email = %q{mattbeedle@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/has_constant.rb
CHANGED
@@ -30,8 +30,7 @@ module HasConstant
|
|
30
30
|
# User.by_constant('title', 'Mr') #=> [@user]
|
31
31
|
#
|
32
32
|
module ClassMethods
|
33
|
-
def has_constant(name, values, options = {})
|
34
|
-
|
33
|
+
def has_constant(name, values = lambda { I18n.t(name) }, options = {})
|
35
34
|
singular = (options[:accessor] || name.to_s.singularize).to_s
|
36
35
|
|
37
36
|
(class << self; self; end).instance_eval do
|
data/test/has_constant_test.rb
CHANGED
@@ -1,10 +1,18 @@
|
|
1
1
|
require 'helper'
|
2
|
+
require 'mocha'
|
2
3
|
|
3
4
|
class Model
|
4
5
|
include HasConstant
|
5
6
|
end
|
6
7
|
|
7
8
|
class TestHasConstant < Test::Unit::TestCase
|
9
|
+
|
10
|
+
should 'default values to translated values list' do
|
11
|
+
I18n.stubs(:t).returns(['a', 'b'])
|
12
|
+
Model.has_constant :titles
|
13
|
+
assert_equal ['a', 'b'], Model.titles
|
14
|
+
end
|
15
|
+
|
8
16
|
should 'default accessor to singular of the constant name' do
|
9
17
|
Model.has_constant :titles, ['Mr', 'Mrs']
|
10
18
|
assert Model.new.respond_to?(:title)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_constant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 4
|
10
|
+
version: 0.4.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- mattbeedle
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-02-04 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|