enumerize 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +3 -20
- data/Gemfile.global +20 -0
- data/Gemfile.mongo_mapper +3 -20
- data/Gemfile.rails40 +2 -19
- data/README.md +146 -6
- data/Rakefile +2 -4
- data/lib/enumerize.rb +7 -0
- data/lib/enumerize/base.rb +3 -1
- data/lib/enumerize/hooks/sequel_dataset.rb +19 -0
- data/lib/enumerize/integrations/rspec/matcher.rb +107 -26
- data/lib/enumerize/scope/sequel.rb +40 -0
- data/lib/enumerize/sequel.rb +57 -0
- data/lib/enumerize/set.rb +2 -1
- data/lib/enumerize/version.rb +1 -1
- data/spec/enumerize/integrations/rspec/matcher_spec.rb +254 -0
- data/spec/spec_helper.rb +24 -0
- data/test/sequel_test.rb +291 -0
- data/test/value_test.rb +35 -27
- metadata +14 -7
- data/test/rspec_matcher_test.rb +0 -76
- data/test/rspec_spec.rb +0 -14
data/test/value_test.rb
CHANGED
@@ -2,27 +2,30 @@ require 'test_helper'
|
|
2
2
|
require 'yaml'
|
3
3
|
|
4
4
|
describe Enumerize::Value do
|
5
|
-
|
6
|
-
|
5
|
+
class Attr < Struct.new(:values)
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:attr) { Attr.new([]) }
|
9
|
+
let(:val) { Enumerize::Value.new(attr, 'test_value', 1) }
|
7
10
|
|
8
11
|
it 'is a string' do
|
9
|
-
|
12
|
+
val.must_be_kind_of String
|
10
13
|
end
|
11
14
|
|
12
15
|
describe 'equality' do
|
13
16
|
it 'is compared to string' do
|
14
|
-
|
15
|
-
|
17
|
+
val.must_be :==, 'test_value'
|
18
|
+
val.wont_be :==, 'not_value'
|
16
19
|
end
|
17
20
|
|
18
21
|
it 'is compared to symbol' do
|
19
|
-
|
20
|
-
|
22
|
+
val.must_be :==, :test_value
|
23
|
+
val.wont_be :==, :not_value
|
21
24
|
end
|
22
25
|
|
23
26
|
it 'is compared to integer' do
|
24
|
-
|
25
|
-
|
27
|
+
val.must_be :==, 1
|
28
|
+
val.wont_be :==, 2
|
26
29
|
end
|
27
30
|
end
|
28
31
|
|
@@ -31,13 +34,13 @@ describe Enumerize::Value do
|
|
31
34
|
|
32
35
|
it 'uses common translation' do
|
33
36
|
store_translations(:en, :enumerize => {:attribute_name => {:test_value => "Common translation"}}) do
|
34
|
-
|
37
|
+
val.text.must_be :==, "Common translation"
|
35
38
|
end
|
36
39
|
end
|
37
40
|
|
38
41
|
it 'uses default translation from the "default" section if its present' do
|
39
42
|
store_translations(:en, :enumerize => {:defaults => {:attribute_name => {:test_value => "Common translation"}}}) do
|
40
|
-
|
43
|
+
val.text.must_be :==, "Common translation"
|
41
44
|
end
|
42
45
|
end
|
43
46
|
|
@@ -45,7 +48,7 @@ describe Enumerize::Value do
|
|
45
48
|
attr.i18n_scopes = ["enumerize.model_name.attribute_name"]
|
46
49
|
|
47
50
|
store_translations(:en, :enumerize => {:model_name => {:attribute_name => {:test_value => "Model Specific translation"}}}) do
|
48
|
-
|
51
|
+
val.text.must_be :==, "Model Specific translation"
|
49
52
|
end
|
50
53
|
end
|
51
54
|
|
@@ -53,13 +56,13 @@ describe Enumerize::Value do
|
|
53
56
|
attr.i18n_scopes = ["enumerize.model_name.attribute_name"]
|
54
57
|
|
55
58
|
store_translations(:en, :enumerize => {:attribute_name => {:test_value => "Common translation"}, :model_name => {:attribute_name => {:test_value => "Model Specific translation"}}}) do
|
56
|
-
|
59
|
+
val.text.must_be :==, "Model Specific translation"
|
57
60
|
end
|
58
61
|
end
|
59
62
|
|
60
63
|
it 'uses simply humanized value when translation is undefined' do
|
61
64
|
store_translations(:en, :enumerize => {}) do
|
62
|
-
|
65
|
+
val.text.must_be :==, "Test value"
|
63
66
|
end
|
64
67
|
end
|
65
68
|
|
@@ -67,7 +70,7 @@ describe Enumerize::Value do
|
|
67
70
|
attr.i18n_scopes = ["other.scope"]
|
68
71
|
|
69
72
|
store_translations(:en, :other => {:scope => {:test_value => "Scope specific translation"}}) do
|
70
|
-
|
73
|
+
val.text.must_be :==, "Scope specific translation"
|
71
74
|
end
|
72
75
|
end
|
73
76
|
|
@@ -75,55 +78,60 @@ describe Enumerize::Value do
|
|
75
78
|
attr.i18n_scopes = ["nonexistent.scope", "other.scope"]
|
76
79
|
|
77
80
|
store_translations(:en, :other => {:scope => {:test_value => "Scope specific translation"}}) do
|
78
|
-
|
81
|
+
val.text.must_be :==, "Scope specific translation"
|
79
82
|
end
|
80
83
|
end
|
81
84
|
end
|
82
85
|
|
83
86
|
describe 'boolean methods comparison' do
|
84
87
|
before do
|
85
|
-
attr.values = [
|
88
|
+
attr.values = [val, Enumerize::Value.new(attr, 'other_value')]
|
86
89
|
end
|
87
90
|
|
88
91
|
it 'returns true if value equals method' do
|
89
|
-
|
92
|
+
val.test_value?.must_equal true
|
90
93
|
end
|
91
94
|
|
92
95
|
it 'returns false if value does not equal method' do
|
93
|
-
|
96
|
+
val.other_value?.must_equal false
|
94
97
|
end
|
95
98
|
|
96
99
|
it 'raises NoMethodError if there are no values like boolean method' do
|
97
100
|
proc {
|
98
|
-
|
101
|
+
val.some_method?
|
99
102
|
}.must_raise NoMethodError
|
100
103
|
end
|
101
104
|
|
102
105
|
it 'raises ArgumentError if arguments are passed' do
|
103
106
|
proc {
|
104
|
-
|
107
|
+
val.other_value?('<3')
|
105
108
|
}.must_raise ArgumentError
|
106
109
|
end
|
107
110
|
|
108
111
|
it 'responds to methods for existing values' do
|
109
|
-
|
110
|
-
|
112
|
+
val.must_respond_to :test_value?
|
113
|
+
val.must_respond_to :other_value?
|
111
114
|
end
|
112
115
|
|
113
116
|
it 'returns a method object' do
|
114
|
-
|
117
|
+
val.method(:test_value?).must_be_instance_of Method
|
115
118
|
end
|
116
119
|
|
117
120
|
it "doesn't respond to a method for not existing value" do
|
118
|
-
|
121
|
+
val.wont_respond_to :some_method?
|
119
122
|
end
|
120
123
|
end
|
121
124
|
|
122
125
|
describe 'serialization' do
|
123
|
-
let(:
|
126
|
+
let(:val) { Enumerize::Value.new(attr, 'test_value') }
|
124
127
|
|
125
128
|
it 'should be serialized to yaml as string value' do
|
126
|
-
assert_equal YAML.dump('test_value'), YAML.dump(
|
129
|
+
assert_equal YAML.dump('test_value'), YAML.dump(val)
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'serializes with Marshal' do
|
133
|
+
dump_value = Marshal.dump(val)
|
134
|
+
Marshal.load(dump_value).must_equal 'test_value'
|
127
135
|
end
|
128
136
|
end
|
129
137
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enumerize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Nartimov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -32,9 +32,11 @@ extensions: []
|
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
34
|
- ".gitignore"
|
35
|
+
- ".rspec"
|
35
36
|
- ".travis.yml"
|
36
37
|
- CHANGELOG.md
|
37
38
|
- Gemfile
|
39
|
+
- Gemfile.global
|
38
40
|
- Gemfile.mongo_mapper
|
39
41
|
- Gemfile.rails40
|
40
42
|
- MIT-LICENSE
|
@@ -47,6 +49,7 @@ files:
|
|
47
49
|
- lib/enumerize/attribute_map.rb
|
48
50
|
- lib/enumerize/base.rb
|
49
51
|
- lib/enumerize/hooks/formtastic.rb
|
52
|
+
- lib/enumerize/hooks/sequel_dataset.rb
|
50
53
|
- lib/enumerize/hooks/simple_form.rb
|
51
54
|
- lib/enumerize/hooks/uniqueness.rb
|
52
55
|
- lib/enumerize/integrations/rails_admin.rb
|
@@ -59,9 +62,13 @@ files:
|
|
59
62
|
- lib/enumerize/predicates.rb
|
60
63
|
- lib/enumerize/scope/activerecord.rb
|
61
64
|
- lib/enumerize/scope/mongoid.rb
|
65
|
+
- lib/enumerize/scope/sequel.rb
|
66
|
+
- lib/enumerize/sequel.rb
|
62
67
|
- lib/enumerize/set.rb
|
63
68
|
- lib/enumerize/value.rb
|
64
69
|
- lib/enumerize/version.rb
|
70
|
+
- spec/enumerize/integrations/rspec/matcher_spec.rb
|
71
|
+
- spec/spec_helper.rb
|
65
72
|
- test/activerecord_test.rb
|
66
73
|
- test/attribute_map_test.rb
|
67
74
|
- test/attribute_test.rb
|
@@ -73,8 +80,7 @@ files:
|
|
73
80
|
- test/multiple_test.rb
|
74
81
|
- test/predicates_test.rb
|
75
82
|
- test/rails_admin_test.rb
|
76
|
-
- test/
|
77
|
-
- test/rspec_spec.rb
|
83
|
+
- test/sequel_test.rb
|
78
84
|
- test/set_test.rb
|
79
85
|
- test/simple_form_test.rb
|
80
86
|
- test/support/mock_controller.rb
|
@@ -100,11 +106,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
106
|
version: '0'
|
101
107
|
requirements: []
|
102
108
|
rubyforge_project:
|
103
|
-
rubygems_version: 2.4.
|
109
|
+
rubygems_version: 2.4.5.1
|
104
110
|
signing_key:
|
105
111
|
specification_version: 4
|
106
112
|
summary: Enumerated attributes with I18n and ActiveRecord/Mongoid/MongoMapper support
|
107
113
|
test_files:
|
114
|
+
- spec/enumerize/integrations/rspec/matcher_spec.rb
|
115
|
+
- spec/spec_helper.rb
|
108
116
|
- test/activerecord_test.rb
|
109
117
|
- test/attribute_map_test.rb
|
110
118
|
- test/attribute_test.rb
|
@@ -116,8 +124,7 @@ test_files:
|
|
116
124
|
- test/multiple_test.rb
|
117
125
|
- test/predicates_test.rb
|
118
126
|
- test/rails_admin_test.rb
|
119
|
-
- test/
|
120
|
-
- test/rspec_spec.rb
|
127
|
+
- test/sequel_test.rb
|
121
128
|
- test/set_test.rb
|
122
129
|
- test/simple_form_test.rb
|
123
130
|
- test/support/mock_controller.rb
|
data/test/rspec_matcher_test.rb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'enumerize/integrations/rspec'
|
3
|
-
|
4
|
-
describe Enumerize::Integrations::RSpec do
|
5
|
-
class Should
|
6
|
-
include Enumerize::Integrations::RSpec
|
7
|
-
end
|
8
|
-
|
9
|
-
let(:klass) do
|
10
|
-
Class.new do
|
11
|
-
extend Enumerize
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
let(:should) { Should.new }
|
16
|
-
let(:object) { klass.new }
|
17
|
-
|
18
|
-
describe '#description' do
|
19
|
-
before do
|
20
|
-
klass.enumerize(:sex, :in => [:male, :female])
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'returns description without default value' do
|
24
|
-
matcher = should.enumerize(:sex).in(:male, :female)
|
25
|
-
matcher.description.must_equal 'enumerize :sex in: "female", "male"'
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'returns description with default value' do
|
29
|
-
matcher = should.enumerize(:sex).in(:male, :female).with_default(:male)
|
30
|
-
matcher.description.must_equal 'enumerize :sex in: "female", "male" with "male" as default value'
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe '#matches?' do
|
35
|
-
before do
|
36
|
-
klass.enumerize(:sex, :in => [:male, :female])
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'returns true' do
|
40
|
-
matcher = should.enumerize(:sex).in(:male, :female)
|
41
|
-
matcher.matches?(object).must_equal true
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'returns false' do
|
45
|
-
matcher = should.enumerize(:sex).in(:bar)
|
46
|
-
matcher.matches?(object).must_equal false
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe '#failure_message' do
|
51
|
-
before do
|
52
|
-
klass.enumerize(:sex, :in => [:male, :female], :default => :male)
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'returns failure message for invalid :in option' do
|
56
|
-
matcher = should.enumerize(:sex).in(:bar)
|
57
|
-
matcher.subject = object
|
58
|
-
expected = ' expected :sex to allow value: "bar", but it allows "female", "male" instead'
|
59
|
-
matcher.failure_message.must_equal expected
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'returns failure message for invalid :with_default option' do
|
63
|
-
matcher = should.enumerize(:sex).in(:male, :female).with_default(:foo)
|
64
|
-
matcher.subject = object
|
65
|
-
expected = ' expected :sex to have "foo" as default value, but it sets "male" instead'
|
66
|
-
matcher.failure_message.must_equal expected
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'returns failure message for ivalid :in option with default value' do
|
70
|
-
matcher = should.enumerize(:sex).in(:bar).with_default(:male)
|
71
|
-
matcher.subject = object
|
72
|
-
expected = ' expected :sex to allow value: "bar", but it allows "female", "male" instead'
|
73
|
-
matcher.failure_message.must_equal expected
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
data/test/rspec_spec.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'rails'
|
2
|
-
require 'enumerize'
|
3
|
-
require 'rspec'
|
4
|
-
|
5
|
-
class RSpecUser
|
6
|
-
extend Enumerize
|
7
|
-
|
8
|
-
enumerize :sex, in: [:male, :female], default: :male
|
9
|
-
end
|
10
|
-
|
11
|
-
describe RSpecUser do
|
12
|
-
it { should enumerize(:sex).in(:male, :female) }
|
13
|
-
it { should enumerize(:sex).in(:male, :female).with_default(:male) }
|
14
|
-
end
|