virtus 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/.travis.yml +1 -0
  2. data/Changelog.md +9 -1
  3. data/Gemfile +1 -1
  4. data/Guardfile +0 -1
  5. data/README.md +0 -2
  6. data/Rakefile +0 -1
  7. data/config/flay.yml +1 -1
  8. data/config/flog.yml +1 -1
  9. data/config/site.reek +1 -1
  10. data/lib/virtus.rb +4 -2
  11. data/lib/virtus/attribute.rb +2 -2
  12. data/lib/virtus/attribute/boolean.rb +1 -1
  13. data/lib/virtus/attribute/default_value.rb +4 -14
  14. data/lib/virtus/attribute/default_value/from_callable.rb +5 -3
  15. data/lib/virtus/attribute/default_value/from_clonable.rb +4 -4
  16. data/lib/virtus/attribute/default_value/from_symbol.rb +4 -4
  17. data/lib/virtus/attribute/embedded_value.rb +0 -2
  18. data/lib/virtus/class_methods.rb +1 -1
  19. data/lib/virtus/coercion.rb +1 -1
  20. data/lib/virtus/coercion/numeric.rb +12 -12
  21. data/lib/virtus/coercion/object.rb +1 -1
  22. data/lib/virtus/support/equalizer.rb +129 -0
  23. data/lib/virtus/support/type_lookup.rb +2 -2
  24. data/lib/virtus/value_object.rb +0 -5
  25. data/lib/virtus/version.rb +1 -1
  26. data/spec/spec_helper.rb +0 -3
  27. data/spec/unit/virtus/attribute/default_spec.rb +0 -4
  28. data/spec/unit/virtus/attribute/default_value/call_spec.rb +21 -0
  29. data/spec/unit/virtus/attribute/default_value/class_methods/build_spec.rb +1 -3
  30. data/spec/unit/virtus/attribute/default_value/class_methods/new_spec.rb +1 -3
  31. data/spec/unit/virtus/attribute/default_value/from_callable/call_spec.rb +19 -0
  32. data/spec/unit/virtus/attribute/default_value/from_callable/class_methods/handle_spec.rb +1 -4
  33. data/spec/unit/virtus/attribute/default_value/from_clonable/call_spec.rb +20 -0
  34. data/spec/unit/virtus/attribute/default_value/from_clonable/class_methods/handle_spec.rb +1 -2
  35. data/spec/unit/virtus/attribute/default_value/from_symbol/{evaluate_spec.rb → call_spec.rb} +3 -4
  36. data/spec/unit/virtus/attribute/default_value/from_symbol/class_methods/handle_spec.rb +1 -4
  37. data/spec/unit/virtus/attribute/default_value/value_spec.rb +2 -3
  38. data/spec/unit/virtus/attributes_accessor/define_reader_method_spec.rb +0 -1
  39. data/spec/unit/virtus/attributes_accessor/define_writer_method_spec.rb +0 -1
  40. data/spec/unit/virtus/coercion/decimal/class_methods/to_decimal_spec.rb +0 -1
  41. data/spec/unit/virtus/coercion/float/class_methods/to_float_spec.rb +0 -1
  42. data/spec/unit/virtus/coercion/integer/class_methods/to_integer_spec.rb +0 -1
  43. data/spec/unit/virtus/coercion/numeric/class_methods/to_decimal_spec.rb +10 -0
  44. data/spec/unit/virtus/coercion/numeric/class_methods/to_float_spec.rb +10 -0
  45. data/spec/unit/virtus/coercion/numeric/class_methods/to_integer_spec.rb +10 -0
  46. data/spec/unit/virtus/coercion/numeric/class_methods/to_string_spec.rb +12 -0
  47. data/spec/unit/virtus/coercion/string/class_methods/to_symbol_spec.rb +0 -1
  48. data/spec/unit/virtus/coercion/time/class_methods/to_integer_spec.rb +0 -1
  49. data/spec/unit/virtus/coercion/time_coercions/to_date_spec.rb +33 -0
  50. data/spec/unit/virtus/coercion/time_coercions/to_datetime_spec.rb +33 -0
  51. data/spec/unit/virtus/coercion/time_coercions/to_string_spec.rb +18 -0
  52. data/spec/unit/virtus/coercion/time_coercions/to_time_spec.rb +33 -0
  53. data/spec/unit/virtus/equalizer/append_spec.rb +82 -0
  54. data/spec/unit/virtus/equalizer/class_method/new_spec.rb +111 -0
  55. data/spec/unit/virtus/equalizer/methods/eql_spec.rb +47 -0
  56. data/spec/unit/virtus/equalizer/methods/equal_value_spec.rb +57 -0
  57. data/spec/unit/virtus/type_lookup/class_methods/extended_spec.rb +0 -1
  58. data/spec/unit/virtus/value_object/class_methods/attribute_spec.rb +15 -8
  59. data/spec/unit/virtus/value_object/class_methods/equalizer_spec.rb +1 -1
  60. data/spec/unit/virtus/value_object/{with_spec.rb → instance_methods/with_spec.rb} +1 -1
  61. data/tasks/metrics/heckle.rake +2 -2
  62. data/virtus.gemspec +2 -1
  63. metadata +29 -23
  64. data/lib/virtus/value_object/equalizer.rb +0 -125
  65. data/spec/unit/virtus/attribute/default_value/attribute_spec.rb +0 -11
  66. data/spec/unit/virtus/attribute/default_value/evaluate_spec.rb +0 -22
  67. data/spec/unit/virtus/attribute/default_value/from_callable/evaluate_spec.rb +0 -21
  68. data/spec/unit/virtus/attribute/default_value/from_clonable/evaluate_spec.rb +0 -22
  69. data/spec/unit/virtus/value_object/equalizer/append_spec.rb +0 -61
@@ -1,11 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Virtus::Attribute::DefaultValue, '#attribute' do
4
- subject { object.attribute }
5
-
6
- let(:object) { described_class.new(attribute, value) }
7
- let(:attribute) { mock('attribute') }
8
- let(:value) { mock('value') }
9
-
10
- it { should be(attribute) }
11
- end
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Virtus::Attribute::DefaultValue, '#evaluate' do
4
- subject { object.evaluate(instance) }
5
-
6
- let(:object) { described_class.build(attribute, value) }
7
- let(:attribute) { mock('attribute') }
8
- let(:value) { mock('value') }
9
- let(:instance) { mock('instance') }
10
- let(:response) { stub('response') }
11
-
12
- # smallest number that is Bignum across major ruby impls
13
- bignum = 0x7fffffffffffffff + 1
14
-
15
- [ nil, true, false, 0, 0.0, bignum, :symbol ].each do |value|
16
- context "when the value is #{value.inspect} (#{value.class})" do
17
- let(:value) { value }
18
-
19
- it { should be(value) }
20
- end
21
- end
22
- end
@@ -1,21 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Virtus::Attribute::DefaultValue::FromCallable, '#evaluate' do
4
- subject { object.evaluate(instance) }
5
-
6
- let(:object) { described_class.new(attribute, value) }
7
- let(:attribute) { mock('attribute') }
8
- let(:value) { mock('value') }
9
- let(:instance) { mock('instance') }
10
- let(:response) { stub('response') }
11
-
12
- before { value.stub(:call => response) }
13
-
14
- it { should be(response) }
15
-
16
- it 'calls the value with the instance and attribute' do
17
- value.should_receive(:call).with(instance, attribute)
18
- subject
19
- end
20
- end
21
-
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Virtus::Attribute::DefaultValue::FromClonable, '#evaluate' do
4
- subject { object.evaluate(instance) }
5
-
6
- let(:object) { described_class.new(attribute, value) }
7
- let(:attribute) { mock('attribute') }
8
- let(:value) { mock('value') }
9
- let(:instance) { mock('instance') }
10
- let(:response) { mock('response') }
11
- let(:clone) { mock('clone') }
12
-
13
- before { value.stub(:clone => clone) }
14
-
15
- it { should be(clone) }
16
-
17
- it 'clones the value' do
18
- value.should_receive(:clone).with(no_args)
19
- subject
20
- end
21
- end
22
-
@@ -1,61 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Virtus::ValueObject::Equalizer, '#<<' do
4
- let(:equalizer) { described_class.new(:user, [ :first_name ]) }
5
-
6
- let(:klass) do
7
- klass = Class.new { attr_accessor :first_name, :last_name }
8
- klass.send(:include, equalizer)
9
- end
10
-
11
- let(:user_one) { klass.new }
12
- let(:user_two) { klass.new }
13
-
14
- let(:first_name) { 'john' }
15
- let(:last_name) { 'doe' }
16
-
17
- before do
18
- equalizer << :last_name
19
-
20
- user_one.first_name = first_name
21
- user_one.last_name = last_name
22
-
23
- user_two.first_name = first_name
24
- user_two.last_name = last_name
25
- end
26
-
27
- describe "#eql?" do
28
- subject { user_one.eql?(user_two) }
29
-
30
- context 'when key values match' do
31
- it { should be(true) }
32
- end
33
-
34
- context 'when key values match' do
35
- before { user_two.last_name = 'other' }
36
-
37
- it { should be(false) }
38
- end
39
- end
40
-
41
- describe "#==?" do
42
- subject { user_one == user_two }
43
-
44
- context 'when key values match' do
45
- it { should be(true) }
46
- end
47
-
48
- context 'when key values match' do
49
- before { user_two.last_name = 'other' }
50
-
51
- it { should be(false) }
52
- end
53
- end
54
-
55
- describe "#hash" do
56
- subject { user_one.hash }
57
-
58
- it { should eql(klass.hash ^ first_name.hash ^ last_name.hash) }
59
- end
60
- end
61
-