ardm 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +5 -13
  2. data/Gemfile +1 -2
  3. data/LICENSE +2 -2
  4. data/README.md +72 -16
  5. data/ardm.gemspec +1 -0
  6. data/lib/ardm.rb +2 -1
  7. data/lib/ardm/active_record.rb +8 -1
  8. data/lib/ardm/active_record/associations.rb +33 -4
  9. data/lib/ardm/active_record/base.rb +2 -0
  10. data/lib/ardm/active_record/collection.rb +5 -0
  11. data/lib/ardm/active_record/data_mapper_constant.rb +1 -0
  12. data/lib/ardm/active_record/data_mapper_constant_proxy.rb +24 -0
  13. data/lib/ardm/active_record/finalize.rb +18 -0
  14. data/lib/ardm/active_record/predicate_builder/array_handler.rb +10 -16
  15. data/lib/ardm/active_record/predicate_builder/rails3.rb +42 -15
  16. data/lib/ardm/active_record/predicate_builder/rails4.rb +39 -13
  17. data/lib/ardm/active_record/property.rb +24 -12
  18. data/lib/ardm/active_record/query.rb +9 -18
  19. data/lib/ardm/active_record/record.rb +54 -11
  20. data/lib/ardm/active_record/relation.rb +36 -6
  21. data/lib/ardm/active_record/repository.rb +6 -2
  22. data/lib/ardm/data_mapper.rb +2 -0
  23. data/lib/ardm/data_mapper/record.rb +3 -9
  24. data/lib/ardm/version.rb +1 -1
  25. data/spec/ardm/datamapper_constants_spec.rb +31 -0
  26. data/spec/fixtures/article.rb +2 -0
  27. data/spec/integration/api_key_spec.rb +3 -3
  28. data/spec/integration/bcrypt_hash_spec.rb +7 -7
  29. data/spec/integration/comma_separated_list_spec.rb +11 -11
  30. data/spec/integration/dirty_minder_spec.rb +23 -39
  31. data/spec/integration/enum_spec.rb +11 -11
  32. data/spec/integration/epoch_time_spec.rb +6 -6
  33. data/spec/integration/file_path_spec.rb +23 -23
  34. data/spec/integration/flag_spec.rb +11 -13
  35. data/spec/integration/ip_address_spec.rb +15 -15
  36. data/spec/integration/json_spec.rb +7 -7
  37. data/spec/integration/slug_spec.rb +6 -6
  38. data/spec/integration/uri_spec.rb +11 -11
  39. data/spec/integration/uuid_spec.rb +16 -16
  40. data/spec/integration/yaml_spec.rb +8 -8
  41. data/spec/public/model_spec.rb +193 -0
  42. data/spec/public/property/binary_spec.rb +4 -4
  43. data/spec/public/property/boolean_spec.rb +3 -3
  44. data/spec/public/property/class_spec.rb +2 -2
  45. data/spec/public/property/date_spec.rb +2 -2
  46. data/spec/public/property/date_time_spec.rb +2 -2
  47. data/spec/public/property/decimal_spec.rb +2 -2
  48. data/spec/public/property/discriminator_spec.rb +21 -20
  49. data/spec/public/property/float_spec.rb +2 -2
  50. data/spec/public/property/integer_spec.rb +2 -2
  51. data/spec/public/property/object_spec.rb +14 -13
  52. data/spec/public/property/serial_spec.rb +2 -2
  53. data/spec/public/property/string_spec.rb +2 -2
  54. data/spec/public/property/text_spec.rb +2 -2
  55. data/spec/public/property/time_spec.rb +2 -2
  56. data/spec/public/property_spec.rb +44 -48
  57. data/spec/public/resource_spec.rb +278 -0
  58. data/spec/schema.rb +33 -4
  59. data/spec/semipublic/property/boolean_spec.rb +5 -5
  60. data/spec/semipublic/property/class_spec.rb +3 -3
  61. data/spec/semipublic/property/date_spec.rb +8 -8
  62. data/spec/semipublic/property/date_time_spec.rb +9 -9
  63. data/spec/semipublic/property/decimal_spec.rb +16 -16
  64. data/spec/semipublic/property/float_spec.rb +16 -16
  65. data/spec/semipublic/property/integer_spec.rb +16 -16
  66. data/spec/semipublic/property/lookup_spec.rb +4 -4
  67. data/spec/semipublic/property/text_spec.rb +2 -2
  68. data/spec/semipublic/property/time_spec.rb +10 -10
  69. data/spec/semipublic/property_spec.rb +4 -4
  70. data/spec/shared/finder_shared_spec.rb +1151 -0
  71. data/spec/shared/flags_shared_spec.rb +6 -6
  72. data/spec/shared/identity_function_group.rb +1 -1
  73. data/spec/shared/public_property_spec.rb +26 -25
  74. data/spec/shared/resource_spec.rb +1218 -0
  75. data/spec/shared/semipublic_property_spec.rb +23 -22
  76. data/spec/spec_helper.rb +17 -0
  77. data/spec/unit/bcrypt_hash_spec.rb +15 -15
  78. data/spec/unit/csv_spec.rb +11 -11
  79. data/spec/unit/dirty_minder_spec.rb +3 -5
  80. data/spec/unit/enum_spec.rb +17 -17
  81. data/spec/unit/epoch_time_spec.rb +8 -8
  82. data/spec/unit/file_path_spec.rb +9 -9
  83. data/spec/unit/flag_spec.rb +9 -9
  84. data/spec/unit/ip_address_spec.rb +9 -9
  85. data/spec/unit/json_spec.rb +11 -11
  86. data/spec/unit/paranoid_boolean_spec.rb +19 -17
  87. data/spec/unit/paranoid_datetime_spec.rb +21 -19
  88. data/spec/unit/regexp_spec.rb +4 -4
  89. data/spec/unit/uri_spec.rb +8 -8
  90. data/spec/unit/yaml_spec.rb +9 -9
  91. metadata +35 -27
  92. data/lib/ardm/active_record/not_found.rb +0 -7
  93. data/lib/ardm/data_mapper/not_found.rb +0 -5
@@ -16,13 +16,13 @@ describe Ardm::Property::EpochTime do
16
16
  describe 'with a Time instance' do
17
17
  let(:value) { Time.now }
18
18
 
19
- it { should == value.to_i }
19
+ it { is_expected.to eq(value.to_i) }
20
20
  end
21
21
 
22
22
  describe 'with nil' do
23
23
  let(:value) { nil }
24
24
 
25
- it { should == value }
25
+ it { is_expected.to eq(value) }
26
26
  end
27
27
  end
28
28
 
@@ -32,25 +32,25 @@ describe Ardm::Property::EpochTime do
32
32
  describe 'with a DateTime instance' do
33
33
  let(:value) { DateTime.now }
34
34
 
35
- it { should == Time.parse(value.to_s) }
35
+ it { is_expected.to eq(Time.parse(value.to_s)) }
36
36
  end
37
37
 
38
38
  describe 'with a number' do
39
39
  let(:value) { Time.now.to_i }
40
40
 
41
- it { should == ::Time.at(value) }
41
+ it { is_expected.to eq(::Time.at(value)) }
42
42
  end
43
43
 
44
44
  describe 'with a numeric string' do
45
45
  let(:value) { Time.now.to_i.to_s }
46
46
 
47
- it { should == ::Time.at(value.to_i) }
47
+ it { is_expected.to eq(::Time.at(value.to_i)) }
48
48
  end
49
49
 
50
50
  describe 'with a DateTime string' do
51
51
  let(:value) { '2011-07-11 15:00:04 UTC' }
52
52
 
53
- it { should == ::Time.parse(value) }
53
+ it { is_expected.to eq(::Time.parse(value)) }
54
54
  end
55
55
  end
56
56
 
@@ -60,13 +60,13 @@ describe Ardm::Property::EpochTime do
60
60
  describe 'with a number' do
61
61
  let(:value) { Time.now.to_i }
62
62
 
63
- it { should == Time.at(value) }
63
+ it { is_expected.to eq(Time.at(value)) }
64
64
  end
65
65
 
66
66
  describe 'with nil' do
67
67
  let(:value) { nil }
68
68
 
69
- it { should == value }
69
+ it { is_expected.to eq(value) }
70
70
  end
71
71
  end
72
72
  end
@@ -15,19 +15,19 @@ try_spec do
15
15
  describe '.dump' do
16
16
  describe 'when input is a string' do
17
17
  it 'does not modify input' do
18
- @property.dump(@input).should == @input
18
+ expect(@property.dump(@input)).to eq(@input)
19
19
  end
20
20
  end
21
21
 
22
22
  describe 'when input is nil' do
23
23
  it 'returns nil' do
24
- @property.dump(nil).should be_nil
24
+ expect(@property.dump(nil)).to be_nil
25
25
  end
26
26
  end
27
27
 
28
28
  describe 'when input is a blank string' do
29
29
  it 'returns nil' do
30
- @property.dump('').should be_nil
30
+ expect(@property.dump('')).to be_nil
31
31
  end
32
32
  end
33
33
  end
@@ -35,19 +35,19 @@ try_spec do
35
35
  describe '.load' do
36
36
  describe 'when value is a non-blank file path' do
37
37
  it 'returns Pathname for a path' do
38
- @property.load(@input).should == @path
38
+ expect(@property.load(@input)).to eq(@path)
39
39
  end
40
40
  end
41
41
 
42
42
  describe 'when value is nil' do
43
43
  it 'return nil' do
44
- @property.load(nil).should be_nil
44
+ expect(@property.load(nil)).to be_nil
45
45
  end
46
46
  end
47
47
 
48
48
  describe 'when value is a blank string' do
49
49
  it 'returns nil' do
50
- @property.load('').should be_nil
50
+ expect(@property.load('')).to be_nil
51
51
  end
52
52
  end
53
53
  end
@@ -55,19 +55,19 @@ try_spec do
55
55
  describe '.typecast' do
56
56
  describe 'when a Pathname is given' do
57
57
  it 'does not modify input' do
58
- @property.typecast(@path).should == @path
58
+ expect(@property.typecast(@path)).to eq(@path)
59
59
  end
60
60
  end
61
61
 
62
62
  describe 'when a nil is given' do
63
63
  it 'does not modify input' do
64
- @property.typecast(nil).should == nil
64
+ expect(@property.typecast(nil)).to eq(nil)
65
65
  end
66
66
  end
67
67
 
68
68
  describe 'when a string is given' do
69
69
  it 'returns Pathname for given path' do
70
- @property.typecast(@input).should == @path
70
+ expect(@property.typecast(@input)).to eq(@path)
71
71
  end
72
72
  end
73
73
  end
@@ -20,7 +20,7 @@ try_spec do
20
20
  end
21
21
 
22
22
  it 'returns flag bit of value' do
23
- @result.should == 1
23
+ expect(@result).to eq(1)
24
24
  end
25
25
  end
26
26
 
@@ -30,7 +30,7 @@ try_spec do
30
30
  end
31
31
 
32
32
  it 'returns flag bit of value' do
33
- @result.should == 2
33
+ expect(@result).to eq(2)
34
34
  end
35
35
  end
36
36
 
@@ -40,7 +40,7 @@ try_spec do
40
40
  end
41
41
 
42
42
  it 'builds binary flag from key values of all matches' do
43
- @result.should == 10
43
+ expect(@result).to eq(10)
44
44
  end
45
45
  end
46
46
 
@@ -50,7 +50,7 @@ try_spec do
50
50
  end
51
51
 
52
52
  it 'builds binary flag from key values of all matches' do
53
- @result.should == 31
53
+ expect(@result).to eq(31)
54
54
  end
55
55
  end
56
56
 
@@ -60,7 +60,7 @@ try_spec do
60
60
  end
61
61
 
62
62
  it 'returns zero' do
63
- @result.should == 0
63
+ expect(@result).to eq(0)
64
64
  end
65
65
  end
66
66
 
@@ -70,7 +70,7 @@ try_spec do
70
70
  end
71
71
 
72
72
  it 'behaves the same as if there were no duplicates' do
73
- @result.should == @flag.dump([ :second, :fourth ])
73
+ expect(@result).to eq(@flag.dump([ :second, :fourth ]))
74
74
  end
75
75
  end
76
76
  end
@@ -86,7 +86,7 @@ try_spec do
86
86
  end
87
87
 
88
88
  it 'returns array with a single matching element' do
89
- @result.should == [ :tres ]
89
+ expect(@result).to eq([ :tres ])
90
90
  end
91
91
  end
92
92
 
@@ -96,7 +96,7 @@ try_spec do
96
96
  end
97
97
 
98
98
  it 'returns array of matching values' do
99
- @result.should == [ :dos, :cuatro ]
99
+ expect(@result).to eq([ :dos, :cuatro ])
100
100
  end
101
101
  end
102
102
 
@@ -106,7 +106,7 @@ try_spec do
106
106
  end
107
107
 
108
108
  it 'returns an empty array' do
109
- @result.should == []
109
+ expect(@result).to eq([])
110
110
  end
111
111
  end
112
112
  end
@@ -17,7 +17,7 @@ try_spec do
17
17
  end
18
18
 
19
19
  it 'dumps input into a string' do
20
- @result.should == @stored
20
+ expect(@result).to eq(@stored)
21
21
  end
22
22
  end
23
23
 
@@ -27,7 +27,7 @@ try_spec do
27
27
  end
28
28
 
29
29
  it 'returns nil' do
30
- @result.should be_nil
30
+ expect(@result).to be_nil
31
31
  end
32
32
  end
33
33
 
@@ -37,7 +37,7 @@ try_spec do
37
37
  end
38
38
 
39
39
  it 'retuns a blank string' do
40
- @result.should == ''
40
+ expect(@result).to eq('')
41
41
  end
42
42
  end
43
43
  end
@@ -49,7 +49,7 @@ try_spec do
49
49
  end
50
50
 
51
51
  it 'returns IPAddr instance from stored value' do
52
- @result.should == @input
52
+ expect(@result).to eq(@input)
53
53
  end
54
54
  end
55
55
 
@@ -59,7 +59,7 @@ try_spec do
59
59
  end
60
60
 
61
61
  it 'returns nil' do
62
- @result.should be_nil
62
+ expect(@result).to be_nil
63
63
  end
64
64
  end
65
65
 
@@ -69,7 +69,7 @@ try_spec do
69
69
  end
70
70
 
71
71
  it 'returns IPAddr instance from stored value' do
72
- @result.should == IPAddr.new('0.0.0.0')
72
+ expect(@result).to eq(IPAddr.new('0.0.0.0'))
73
73
  end
74
74
  end
75
75
 
@@ -79,7 +79,7 @@ try_spec do
79
79
  end
80
80
 
81
81
  it 'raises ArgumentError with a meaningful message' do
82
- @operation.should raise_error(ArgumentError, '+value+ must be nil or a String')
82
+ expect(@operation).to raise_error(ArgumentError, '+value+ must be nil or a String')
83
83
  end
84
84
  end
85
85
  end
@@ -91,7 +91,7 @@ try_spec do
91
91
  end
92
92
 
93
93
  it 'does not change the value' do
94
- @result.should == @input
94
+ expect(@result).to eq(@input)
95
95
  end
96
96
  end
97
97
 
@@ -101,7 +101,7 @@ try_spec do
101
101
  end
102
102
 
103
103
  it 'instantiates IPAddr instance' do
104
- @result.should == @input
104
+ expect(@result).to eq(@input)
105
105
  end
106
106
  end
107
107
  end
@@ -13,21 +13,21 @@ try_spec do
13
13
  describe '.load' do
14
14
  describe 'when nil is provided' do
15
15
  it 'returns nil' do
16
- @property.load(nil).should be_nil
16
+ expect(@property.load(nil)).to be_nil
17
17
  end
18
18
  end
19
19
 
20
20
  describe 'when Json encoded primitive string is provided' do
21
21
  it 'returns decoded value as Ruby string' do
22
- @property.load(MultiJson.dump(:value => 'JSON encoded string')).should == { 'value' => 'JSON encoded string' }
22
+ expect(@property.load(MultiJson.dump(:value => 'JSON encoded string'))).to eq({ 'value' => 'JSON encoded string' })
23
23
  end
24
24
  end
25
25
 
26
26
  describe 'when something else is provided' do
27
27
  it 'raises ArgumentError with a meaningful message' do
28
- lambda {
28
+ expect {
29
29
  @property.load(:sym)
30
- }.should raise_error(ArgumentError, '+value+ of a property of JSON type must be nil or a String')
30
+ }.to raise_error(ArgumentError, '+value+ of a property of JSON type must be nil or a String')
31
31
  end
32
32
  end
33
33
  end
@@ -35,32 +35,32 @@ try_spec do
35
35
  describe '.dump' do
36
36
  describe 'when nil is provided' do
37
37
  it 'returns nil' do
38
- @property.dump(nil).should be_nil
38
+ expect(@property.dump(nil)).to be_nil
39
39
  end
40
40
  end
41
41
 
42
42
  describe 'when Json encoded primitive string is provided' do
43
43
  it 'does not do double encoding' do
44
- @property.dump('Json encoded string').should == 'Json encoded string'
44
+ expect(@property.dump('Json encoded string')).to eq('Json encoded string')
45
45
  end
46
46
  end
47
47
 
48
48
  describe 'when regular Ruby string is provided' do
49
49
  it 'dumps argument to Json' do
50
- @property.dump('dump me (to JSON)').should == 'dump me (to JSON)'
50
+ expect(@property.dump('dump me (to JSON)')).to eq('dump me (to JSON)')
51
51
  end
52
52
  end
53
53
 
54
54
  describe 'when Ruby array is provided' do
55
55
  it 'dumps argument to Json' do
56
- @property.dump([1, 2, 3]).should == '[1,2,3]'
56
+ expect(@property.dump([1, 2, 3])).to eq('[1,2,3]')
57
57
  end
58
58
  end
59
59
 
60
60
  describe 'when Ruby hash is provided' do
61
61
  it 'dumps argument to Json' do
62
- @property.dump({ :datamapper => 'Data access layer in Ruby' }).
63
- should == '{"datamapper":"Data access layer in Ruby"}'
62
+ expect(@property.dump({ :datamapper => 'Data access layer in Ruby' })).
63
+ to eq('{"datamapper":"Data access layer in Ruby"}')
64
64
  end
65
65
  end
66
66
  end
@@ -108,7 +108,7 @@ try_spec do
108
108
  end
109
109
 
110
110
  it 'decodes value from JSON' do
111
- @result.should == { 'value' => 11 }
111
+ expect(@result).to eq({ 'value' => 11 })
112
112
  end
113
113
  end
114
114
 
@@ -5,6 +5,7 @@ module ::ParanoidBooleanBlog
5
5
  self.table_name = "articles"
6
6
  property :id, Serial
7
7
  property :deleted, ParanoidBoolean
8
+ timestamps :at
8
9
 
9
10
  before_destroy :before_destroy
10
11
 
@@ -30,16 +31,16 @@ describe Ardm::Property::ParanoidBoolean do
30
31
  end
31
32
 
32
33
  it 'should not delete the resource from the datastore' do
33
- method(:subject).should_not change { @model.with_deleted.size }.from(0)
34
+ expect(method(:subject)).not_to change { @model.with_deleted.size }.from(0)
34
35
  end
35
36
 
36
37
  it 'should not set the paranoid column' do
37
- method(:subject).should_not change { @resource.deleted }.from(false)
38
+ expect(method(:subject)).not_to change { @resource.deleted }.from(false)
38
39
  end
39
40
 
40
41
  it 'should run the destroy hook' do
41
42
  # NOTE: changed behavior because AR doesn't call hooks on destroying new objects
42
- @resource.should_not_receive(:before_destroy).with(no_args)
43
+ expect(@resource).not_to receive(:before_destroy).with(no_args)
43
44
  subject
44
45
  end
45
46
  end
@@ -49,18 +50,18 @@ describe Ardm::Property::ParanoidBoolean do
49
50
  @resource = @model.create
50
51
  end
51
52
 
52
- it { (!!subject).should be_true }
53
+ it { expect(!!subject).to be true }
53
54
 
54
55
  it 'should not delete the resource from the datastore' do
55
- method(:subject).should_not change { @model.with_deleted.size }.from(1)
56
+ expect(method(:subject)).not_to change { @model.with_deleted.size }.from(1)
56
57
  end
57
58
 
58
59
  it 'should set the paranoid column' do
59
- method(:subject).should change { @resource.deleted }.from(false).to(true)
60
+ expect(method(:subject)).to change { @resource.deleted }.from(false).to(true)
60
61
  end
61
62
 
62
63
  it 'should run the destroy hook' do
63
- @resource.should_receive(:before_destroy).with(no_args)
64
+ expect(@resource).to receive(:before_destroy).with(no_args)
64
65
  subject
65
66
  end
66
67
  end
@@ -75,15 +76,15 @@ describe Ardm::Property::ParanoidBoolean do
75
76
  end
76
77
 
77
78
  it 'should not delete the resource from the datastore' do
78
- method(:subject).should_not change { @model.with_deleted.size }.from(0)
79
+ expect(method(:subject)).not_to change { @model.with_deleted.size }.from(0)
79
80
  end
80
81
 
81
82
  it 'should not set the paranoid column' do
82
- method(:subject).should_not change { @resource.deleted }.from(false)
83
+ expect(method(:subject)).not_to change { @resource.deleted }.from(false)
83
84
  end
84
85
 
85
86
  it 'should not run the destroy hook' do
86
- @resource.should_not_receive(:before_destroy).with(no_args)
87
+ expect(@resource).not_to receive(:before_destroy).with(no_args)
87
88
  subject
88
89
  end
89
90
  end
@@ -93,18 +94,18 @@ describe Ardm::Property::ParanoidBoolean do
93
94
  @resource = @model.create
94
95
  end
95
96
 
96
- it { (!!subject).should be_true }
97
+ it { expect(!!subject).to be true }
97
98
 
98
99
  it 'should delete the resource from the datastore' do
99
- method(:subject).should change { @model.with_deleted.size }.from(1).to(0)
100
+ expect(method(:subject)).to change { @model.with_deleted.size }.from(1).to(0)
100
101
  end
101
102
 
102
103
  it 'should not set the paranoid column' do
103
- method(:subject).should_not change { @resource.deleted }.from(false)
104
+ expect(method(:subject)).not_to change { @resource.deleted }.from(false)
104
105
  end
105
106
 
106
107
  it 'should not run the destroy hook' do
107
- @resource.should_not_receive(:before_destroy).with(no_args)
108
+ expect(@resource).not_to receive(:before_destroy).with(no_args)
108
109
  subject
109
110
  end
110
111
  end
@@ -120,7 +121,7 @@ describe Ardm::Property::ParanoidBoolean do
120
121
  subject { @model.with_deleted { @model.all } }
121
122
 
122
123
  it 'should scope the block to return all resources' do
123
- subject.map { |resource| resource.key }.should == [ @resource.key ]
124
+ expect(subject.map { |resource| resource.key }).to eq([ @resource.key ])
124
125
  end
125
126
  end
126
127
 
@@ -128,15 +129,16 @@ describe Ardm::Property::ParanoidBoolean do
128
129
  subject { @model.with_deleted }
129
130
 
130
131
  it 'should return a collection scoped to return all resources' do
131
- subject.map { |resource| resource.key }.should == [ @resource.key ]
132
+ expect(subject.map { |resource| resource.key }).to eq([ @resource.key ])
132
133
  end
133
134
  end
134
135
  end
135
136
 
136
137
  describe 'Model.inherited' do
137
138
  it 'sets @paranoid_properties' do
138
- ::ParanoidBooleanBlog::Review.instance_variable_get(:@paranoid_properties).should ==
139
+ expect(::ParanoidBooleanBlog::Review.instance_variable_get(:@paranoid_properties)).to eq(
139
140
  ::ParanoidBooleanBlog::Article.instance_variable_get(:@paranoid_properties)
141
+ )
140
142
  end
141
143
  end
142
144
  end