enumerize 0.8.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +27 -12
  5. data/CHANGELOG.md +135 -0
  6. data/Gemfile +5 -21
  7. data/Gemfile.global +20 -0
  8. data/Gemfile.mongo_mapper +7 -0
  9. data/Gemfile.rails42 +7 -0
  10. data/Gemfile.rails51 +7 -0
  11. data/README.md +185 -9
  12. data/Rakefile +2 -4
  13. data/enumerize.gemspec +1 -0
  14. data/lib/enumerize/activerecord.rb +55 -27
  15. data/lib/enumerize/attribute.rb +41 -9
  16. data/lib/enumerize/base.rb +28 -17
  17. data/lib/enumerize/hooks/formtastic.rb +3 -8
  18. data/lib/enumerize/hooks/sequel_dataset.rb +15 -0
  19. data/lib/enumerize/hooks/simple_form.rb +5 -11
  20. data/lib/enumerize/hooks/uniqueness.rb +3 -8
  21. data/lib/enumerize/integrations/rspec/matcher.rb +107 -26
  22. data/lib/enumerize/mongoid.rb +13 -0
  23. data/lib/enumerize/predicatable.rb +7 -16
  24. data/lib/enumerize/predicates.rb +3 -1
  25. data/lib/enumerize/scope/activerecord.rb +37 -0
  26. data/lib/enumerize/scope/mongoid.rb +35 -0
  27. data/lib/enumerize/scope/sequel.rb +40 -0
  28. data/lib/enumerize/sequel.rb +57 -0
  29. data/lib/enumerize/set.rb +18 -8
  30. data/lib/enumerize/value.rb +10 -9
  31. data/lib/enumerize/version.rb +3 -1
  32. data/lib/enumerize.rb +23 -1
  33. data/spec/enumerize/integrations/rspec/matcher_spec.rb +258 -0
  34. data/spec/spec_helper.rb +28 -0
  35. data/test/activerecord_test.rb +233 -10
  36. data/test/attribute_test.rb +22 -0
  37. data/test/base_test.rb +7 -7
  38. data/test/formtastic_test.rb +3 -12
  39. data/test/mongo_mapper_test.rb +7 -1
  40. data/test/mongoid_test.rb +63 -7
  41. data/test/multiple_test.rb +21 -0
  42. data/test/predicates_test.rb +6 -0
  43. data/test/sequel_test.rb +291 -0
  44. data/test/set_test.rb +14 -0
  45. data/test/simple_form_test.rb +0 -1
  46. data/test/support/mock_controller.rb +4 -0
  47. data/test/support/view_test_helper.rb +4 -0
  48. data/test/test_helper.rb +23 -2
  49. data/test/value_test.rb +51 -21
  50. metadata +40 -9
  51. data/Gemfile.rails4 +0 -23
  52. data/lib/enumerize/form_helper.rb +0 -23
  53. data/test/rspec_matcher_test.rb +0 -76
  54. data/test/rspec_spec.rb +0 -13
@@ -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