enumerize 0.8.0 → 2.0.0

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