enumerize 0.8.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rspec +2 -0
- data/.travis.yml +8 -2
- data/CHANGELOG.md +91 -0
- data/Gemfile +4 -22
- data/{Gemfile.rails4 → Gemfile.global} +2 -5
- data/Gemfile.mongo_mapper +5 -0
- data/Gemfile.rails40 +5 -0
- data/README.md +171 -8
- data/Rakefile +2 -4
- data/lib/enumerize/activerecord.rb +3 -29
- data/lib/enumerize/attribute.rb +41 -9
- data/lib/enumerize/base.rb +25 -10
- data/lib/enumerize/hooks/sequel_dataset.rb +19 -0
- data/lib/enumerize/integrations/rspec/matcher.rb +107 -26
- data/lib/enumerize/mongoid.rb +13 -0
- data/lib/enumerize/predicatable.rb +7 -16
- data/lib/enumerize/predicates.rb +3 -1
- data/lib/enumerize/scope/activerecord.rb +37 -0
- data/lib/enumerize/scope/mongoid.rb +35 -0
- data/lib/enumerize/scope/sequel.rb +40 -0
- data/lib/enumerize/sequel.rb +57 -0
- data/lib/enumerize/set.rb +18 -8
- data/lib/enumerize/value.rb +8 -7
- data/lib/enumerize/version.rb +1 -1
- data/lib/enumerize.rb +23 -1
- data/spec/enumerize/integrations/rspec/matcher_spec.rb +258 -0
- data/spec/spec_helper.rb +28 -0
- data/test/activerecord_test.rb +58 -7
- data/test/attribute_test.rb +22 -0
- data/test/formtastic_test.rb +3 -12
- data/test/mongo_mapper_test.rb +6 -0
- data/test/mongoid_test.rb +55 -6
- data/test/multiple_test.rb +21 -0
- data/test/predicates_test.rb +6 -0
- data/test/sequel_test.rb +291 -0
- data/test/set_test.rb +14 -0
- data/test/simple_form_test.rb +0 -1
- data/test/support/view_test_helper.rb +4 -0
- data/test/test_helper.rb +23 -2
- data/test/value_test.rb +51 -21
- metadata +37 -8
- data/lib/enumerize/form_helper.rb +0 -23
- data/test/rspec_matcher_test.rb +0 -76
- data/test/rspec_spec.rb +0 -13
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,13 +0,0 @@
|
|
1
|
-
require 'enumerize'
|
2
|
-
require 'rspec'
|
3
|
-
|
4
|
-
class RSpecUser
|
5
|
-
extend Enumerize
|
6
|
-
|
7
|
-
enumerize :sex, in: [:male, :female], default: :male
|
8
|
-
end
|
9
|
-
|
10
|
-
describe RSpecUser do
|
11
|
-
it { should enumerize(:sex).in(:male, :female) }
|
12
|
-
it { should enumerize(:sex).in(:male, :female).with_default(:male) }
|
13
|
-
end
|