datamappify 0.50.0 → 0.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +78 -4
- data/lib/datamappify/data/criteria/active_record/find_multiple.rb +28 -0
- data/lib/datamappify/data/criteria/common.rb +28 -8
- data/lib/datamappify/data/criteria/relational/find_multiple.rb +62 -3
- data/lib/datamappify/data/criteria/sequel/find_multiple.rb +31 -0
- data/lib/datamappify/data/errors.rb +3 -0
- data/lib/datamappify/data/mapper/attribute.rb +81 -3
- data/lib/datamappify/data/mapper.rb +12 -12
- data/lib/datamappify/data/provider/active_record.rb +20 -5
- data/lib/datamappify/data/provider/common_provider.rb +2 -0
- data/lib/datamappify/data/provider/sequel.rb +25 -6
- data/lib/datamappify/data/record.rb +18 -5
- data/lib/datamappify/entity/composable.rb +63 -7
- data/lib/datamappify/entity/relation.rb +1 -1
- data/lib/datamappify/repository/inheritable.rb +28 -0
- data/lib/datamappify/repository/query_method/find_multiple.rb +1 -7
- data/lib/datamappify/repository/query_method/method.rb +2 -2
- data/lib/datamappify/repository/query_methods.rb +8 -4
- data/lib/datamappify/repository.rb +2 -0
- data/lib/datamappify/version.rb +1 -1
- data/spec/entity/composable_spec.rb +34 -11
- data/spec/entity/inheritance_spec.rb +33 -0
- data/spec/entity/relation_spec.rb +11 -9
- data/spec/repository/finders_spec.rb +185 -7
- data/spec/support/entities/admin_user.rb +5 -0
- data/spec/support/entities/computer.rb +2 -0
- data/spec/support/entities/computer_hardware.rb +4 -0
- data/spec/support/entities/computer_software.rb +3 -0
- data/spec/support/repositories/active_record/admin_user_repository.rb +5 -0
- data/spec/support/repositories/sequel/admin_user_repository.rb +5 -0
- data/spec/support/tables/active_record.rb +1 -0
- data/spec/support/tables/sequel.rb +1 -0
- data/spec/unit/entity/relation_spec.rb +12 -2
- metadata +11 -2
@@ -12,14 +12,69 @@ module Datamappify
|
|
12
12
|
#
|
13
13
|
# @return [void]
|
14
14
|
def attributes_from(entity_class, options = {})
|
15
|
-
entity_class
|
15
|
+
setup_attributes(entity_class, options)
|
16
|
+
setup_validators(entity_class, options)
|
17
|
+
run_validators
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
# @param (see #attributes_from)
|
23
|
+
#
|
24
|
+
# @return (see #attributes_from)
|
25
|
+
def setup_attributes(entity_class, options)
|
26
|
+
entity_class.attribute_set.dup.each do |attribute|
|
16
27
|
unless excluded_attributes(entity_class).include?(attribute.name)
|
17
|
-
self.attribute_set << tweak_attribute
|
28
|
+
self.attribute_set << tweak_attribute(attribute, options)
|
18
29
|
end
|
19
30
|
end
|
20
31
|
end
|
21
32
|
|
22
|
-
|
33
|
+
# @param (see #attributes_from)
|
34
|
+
#
|
35
|
+
# @return (see #attributes_from)
|
36
|
+
def setup_validators(entity_class, options)
|
37
|
+
if options[:prefix_with]
|
38
|
+
rename_validators(entity_class, options[:prefix_with])
|
39
|
+
else
|
40
|
+
entity_class._validators.each { |k, v| self._validators[k] = v.dup }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# @return [void]
|
45
|
+
def run_validators
|
46
|
+
self._validators.each do |_, validators|
|
47
|
+
validators.each do |validator|
|
48
|
+
validate(validator, validator.options)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# @param entity_class [Entity]
|
54
|
+
#
|
55
|
+
# @param prefix [Symbol]
|
56
|
+
#
|
57
|
+
# @return [void]
|
58
|
+
def rename_validators(entity_class, prefix)
|
59
|
+
entity_class._validators.each do |attribute_name, validators|
|
60
|
+
dup_validators = validators.dup
|
61
|
+
|
62
|
+
dup_validators.each do |validator|
|
63
|
+
rename_validator_attributes(validator, prefix)
|
64
|
+
end
|
65
|
+
|
66
|
+
self._validators[:"#{prefix}_#{attribute_name}"] = dup_validators
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# @param validator [Validator]
|
71
|
+
#
|
72
|
+
# @param prefix (see #rename_validators)
|
73
|
+
#
|
74
|
+
# @return [void]
|
75
|
+
def rename_validator_attributes(validator, prefix)
|
76
|
+
validator.instance_variable_set :@attributes, validator.attributes.map { |name| :"#{prefix}_#{name}" }
|
77
|
+
end
|
23
78
|
|
24
79
|
# @param entity_class [Entity]
|
25
80
|
#
|
@@ -33,8 +88,8 @@ module Datamappify
|
|
33
88
|
# @param options [Hash]
|
34
89
|
#
|
35
90
|
# @return [Virtus::Attribute]
|
36
|
-
def tweak_attribute
|
37
|
-
prefix_attribute_name
|
91
|
+
def tweak_attribute(attribute, options)
|
92
|
+
prefix_attribute_name(attribute, options[:prefix_with]) if options[:prefix_with]
|
38
93
|
|
39
94
|
attribute
|
40
95
|
end
|
@@ -44,8 +99,9 @@ module Datamappify
|
|
44
99
|
# @param prefix [Symbol]
|
45
100
|
#
|
46
101
|
# @return [void]
|
47
|
-
def prefix_attribute_name
|
48
|
-
attribute.instance_variable_set :@name, :"#{prefix}_#{attribute.name}"
|
102
|
+
def prefix_attribute_name(attribute, prefix)
|
103
|
+
name = attribute.instance_variable_set :@name, :"#{prefix}_#{attribute.name}"
|
104
|
+
attribute.instance_variable_set :@instance_variable_name, "@#{name}".to_sym
|
49
105
|
end
|
50
106
|
end
|
51
107
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Datamappify
|
2
|
+
module Repository
|
3
|
+
module Inheritable
|
4
|
+
# @param klass [Repository]
|
5
|
+
#
|
6
|
+
# @return [void]
|
7
|
+
def inherited(klass)
|
8
|
+
klass.class_eval { include Repository }
|
9
|
+
|
10
|
+
setup_data_mapper(klass)
|
11
|
+
|
12
|
+
klass.data_mapper.default_source_class
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
# @param klass (see #inherited)
|
18
|
+
#
|
19
|
+
# @return [void]
|
20
|
+
def setup_data_mapper(klass)
|
21
|
+
klass.for_entity self.data_mapper.entity_class
|
22
|
+
klass.default_provider self.data_mapper.default_provider_name
|
23
|
+
|
24
|
+
klass.data_mapper.custom_mapping = self.data_mapper.custom_mapping.dup
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -14,7 +14,7 @@ module Datamappify
|
|
14
14
|
# @return [Array<Entity>]
|
15
15
|
def perform
|
16
16
|
dispatch_criteria_to_default_source(
|
17
|
-
:FindMultiple, data_mapper.entity_class, @criteria, attributes
|
17
|
+
:FindMultiple, data_mapper.entity_class, @criteria, data_mapper.attributes
|
18
18
|
)
|
19
19
|
end
|
20
20
|
|
@@ -22,12 +22,6 @@ module Datamappify
|
|
22
22
|
def reader?
|
23
23
|
true
|
24
24
|
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def attributes
|
29
|
-
data_mapper.attributes_from_default_source
|
30
|
-
end
|
31
25
|
end
|
32
26
|
end
|
33
27
|
end
|
@@ -73,10 +73,10 @@ module Datamappify
|
|
73
73
|
# @param entity [Entity]
|
74
74
|
#
|
75
75
|
# @return [void]
|
76
|
-
def dispatch_criteria_to_providers(criteria_name, entity)
|
76
|
+
def dispatch_criteria_to_providers(criteria_name, entity, *args)
|
77
77
|
attributes_walker(entity) do |provider_name, source_class, attributes|
|
78
78
|
data_mapper.provider(provider_name).build_criteria(
|
79
|
-
criteria_name, source_class, entity, attributes
|
79
|
+
criteria_name, source_class, entity, attributes, *args
|
80
80
|
)
|
81
81
|
end
|
82
82
|
end
|
@@ -20,12 +20,16 @@ module Datamappify
|
|
20
20
|
QueryMethod::Exists.new(query_options, entity).perform
|
21
21
|
end
|
22
22
|
|
23
|
-
# @param
|
24
|
-
# an entity id or a
|
23
|
+
# @param criteria [Integer, Hash]
|
24
|
+
# an entity id or a hash containing criteria
|
25
25
|
#
|
26
26
|
# @return [Entity, nil]
|
27
|
-
def find(
|
28
|
-
|
27
|
+
def find(criteria)
|
28
|
+
if criteria.is_a?(Integer)
|
29
|
+
QueryMethod::Find.new(query_options, criteria).perform
|
30
|
+
else
|
31
|
+
QueryMethod::FindMultiple.new(query_options, criteria).perform
|
32
|
+
end
|
29
33
|
end
|
30
34
|
|
31
35
|
# Returns a collection of all the entities in the repository
|
@@ -2,6 +2,7 @@ require 'datamappify/repository/lazy_checking'
|
|
2
2
|
require 'datamappify/repository/mapping_dsl'
|
3
3
|
require 'datamappify/repository/unit_of_work'
|
4
4
|
require 'datamappify/repository/query_methods'
|
5
|
+
require 'datamappify/repository/inheritable'
|
5
6
|
require 'datamappify/data'
|
6
7
|
|
7
8
|
module Datamappify
|
@@ -22,6 +23,7 @@ module Datamappify
|
|
22
23
|
include LazyChecking
|
23
24
|
extend MappingDSL
|
24
25
|
include QueryMethods
|
26
|
+
extend Inheritable
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
data/lib/datamappify/version.rb
CHANGED
@@ -1,25 +1,48 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Datamappify::Entity do
|
4
|
-
subject
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
4
|
+
subject do
|
5
|
+
Computer.new({
|
6
|
+
:brand => 'Fruit',
|
7
|
+
:cpu => '286',
|
8
|
+
:ram => 8192,
|
9
|
+
:hdd => 65536,
|
10
|
+
:gfx => 'Voodoo',
|
11
|
+
:vendor => 'Compaq',
|
12
|
+
:software_os => 'OS X',
|
13
|
+
:software_osx_id => 1,
|
14
|
+
:software_windows_id => 2,
|
15
|
+
:software_linux_id => 3,
|
16
|
+
:software_vendor => 'Lotus'
|
17
|
+
})
|
15
18
|
end
|
16
19
|
|
17
20
|
its(:cpu) { should == '286' }
|
18
21
|
its(:ram) { should == 8192 }
|
19
22
|
its(:hdd) { should == 65536 }
|
20
23
|
its(:gfx) { should == 'Voodoo' }
|
24
|
+
its(:vendor) { should == 'Compaq' }
|
21
25
|
its(:software_os) { should == 'OS X' }
|
22
26
|
its(:software_osx_id) { should == 1 }
|
23
27
|
its(:software_windows_id) { should == 2 }
|
24
28
|
its(:software_linux_id) { should == 3 }
|
29
|
+
its(:software_vendor) { should == 'Lotus' }
|
30
|
+
|
31
|
+
describe "validation" do
|
32
|
+
context "valid" do
|
33
|
+
it { should be_valid }
|
34
|
+
end
|
35
|
+
|
36
|
+
context "invalid" do
|
37
|
+
after do
|
38
|
+
subject.should be_invalid
|
39
|
+
end
|
40
|
+
|
41
|
+
it('brand') { subject.brand = nil }
|
42
|
+
it('ram') { subject.ram = 42 }
|
43
|
+
it('hdd') { subject.hdd = 42 }
|
44
|
+
it('hdd') { subject.hdd = 65537 }
|
45
|
+
it('software_os') { subject.software_os = nil }
|
46
|
+
end
|
47
|
+
end
|
25
48
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples_for "entity inheritance" do |data_provider|
|
4
|
+
context "#{data_provider}" do
|
5
|
+
let!(:admin_user_repository) { "AdminUserRepository#{data_provider}".constantize }
|
6
|
+
let(:admin_user) { admin_user_repository.save!(AdminUser.new(:first_name => 'Batman', :driver_license => 'ARKHAMCITY', :level => 42)) }
|
7
|
+
|
8
|
+
describe "persistence" do
|
9
|
+
subject { admin_user }
|
10
|
+
|
11
|
+
it_behaves_like "entity inheritance attributes"
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "finder" do
|
15
|
+
subject { admin_user_repository.find(admin_user.id) }
|
16
|
+
|
17
|
+
it_behaves_like "entity inheritance attributes"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
shared_examples_for "entity inheritance attributes" do
|
23
|
+
its(:id) { should be_kind_of(Integer) }
|
24
|
+
its(:first_name) { should == 'Batman' }
|
25
|
+
its(:driver_license) { should == 'ARKHAMCITY' }
|
26
|
+
its(:level) { should == 42 }
|
27
|
+
end
|
28
|
+
|
29
|
+
describe Datamappify::Entity do
|
30
|
+
DATA_PROVIDERS.each do |data_provider|
|
31
|
+
it_behaves_like "entity inheritance", data_provider
|
32
|
+
end
|
33
|
+
end
|
@@ -1,19 +1,21 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
shared_examples_for "entity relations" do |data_provider|
|
4
|
-
|
4
|
+
context "#{data_provider}" do
|
5
|
+
include_context "user repository", data_provider
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
let!(:comment_repository) { "CommentRepository#{data_provider}".constantize }
|
8
|
+
let(:comment) { comment_repository.save!(Comment.new) }
|
8
9
|
|
9
|
-
|
10
|
+
subject { comment }
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
before do
|
13
|
+
subject.user = existing_user
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
its(:user_id) { should == existing_user.id }
|
17
|
+
its(:user) { should == existing_user }
|
18
|
+
end
|
17
19
|
end
|
18
20
|
|
19
21
|
describe Datamappify::Entity do
|
@@ -7,17 +7,115 @@ shared_examples_for "finders" do |data_provider|
|
|
7
7
|
let!(:existing_user_2) { user_repository.save(new_valid_user.dup) }
|
8
8
|
|
9
9
|
context "#{data_provider}" do
|
10
|
-
describe "#
|
11
|
-
|
12
|
-
user_repository.
|
10
|
+
describe "#find" do
|
11
|
+
describe "by id" do
|
12
|
+
subject { user_repository.find(existing_user.id) }
|
13
|
+
|
14
|
+
its(:id) { should == existing_user.id }
|
13
15
|
end
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
+
describe "by criteria" do
|
18
|
+
before do
|
19
|
+
user_repository.save!(User.new(:first_name => 'Mary', :driver_license => 'IDONTCARE'))
|
20
|
+
user_repository.save!(User.new(:first_name => 'Bob', :driver_license => 'IDONTCARE'))
|
21
|
+
user_repository.save!(User.new(:first_name => 'Jane', :driver_license => 'NO_LICENSE'))
|
22
|
+
user_repository.save!(User.new(:first_name => 'Bob', :driver_license => 'NO_LICENSE'))
|
23
|
+
user_repository.save!(User.new(:first_name => 'Bob', :driver_license => 'IDONTCARE'))
|
24
|
+
user_repository.save!(User.new(:first_name => 'Bobb', :driver_license => 'IDONTCARE'))
|
25
|
+
user_repository.save!(User.new(:first_name => 'John', :driver_license => 'IDONTCARE'))
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "by attribute that does not exist" do
|
29
|
+
let(:records) { user_repository.find(:blah => 'Bob') }
|
30
|
+
|
31
|
+
it { expect { records }.to raise_exception(Datamappify::Data::EntityAttributeInvalid) }
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "by primary attribute" do
|
35
|
+
let(:records) { user_repository.find(:first_name => 'Bob') }
|
36
|
+
subject { records }
|
37
|
+
|
38
|
+
it { should have(3).users }
|
39
|
+
|
40
|
+
describe "record" do
|
41
|
+
subject { records.first }
|
42
|
+
|
43
|
+
its(:first_name) { should == 'Bob' }
|
44
|
+
its(:driver_license) { should == 'IDONTCARE' }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "by secondary attribute" do
|
49
|
+
let(:records) { user_repository.find(:driver_license => 'NO_LICENSE') }
|
50
|
+
subject { records }
|
51
|
+
|
52
|
+
it { should have(2).user }
|
53
|
+
|
54
|
+
describe "record" do
|
55
|
+
subject { records.first }
|
56
|
+
|
57
|
+
its(:first_name) { should == 'Jane' }
|
58
|
+
its(:driver_license) { should == 'NO_LICENSE' }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "by primary and secondary attributes" do
|
63
|
+
context "example 1" do
|
64
|
+
let(:records) { user_repository.find(:first_name => 'Bob', :driver_license => 'NO_LICENSE') }
|
65
|
+
subject { records }
|
66
|
+
|
67
|
+
it { should have(1).user }
|
68
|
+
|
69
|
+
describe "record" do
|
70
|
+
subject { records.first }
|
71
|
+
|
72
|
+
its(:first_name) { should == 'Bob' }
|
73
|
+
its(:driver_license) { should == 'NO_LICENSE' }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "example 2" do
|
78
|
+
let(:records) { user_repository.find(:first_name => 'Bob', :driver_license => 'IDONTCARE') }
|
79
|
+
subject { records }
|
80
|
+
|
81
|
+
it { should have(2).users }
|
82
|
+
|
83
|
+
describe "record" do
|
84
|
+
subject { records.first }
|
85
|
+
|
86
|
+
its(:first_name) { should == 'Bob' }
|
87
|
+
its(:driver_license) { should == 'IDONTCARE' }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context "example 3" do
|
92
|
+
subject { user_repository.find(:first_name => 'Nope', :driver_license => 'IDONTCARE') }
|
93
|
+
|
94
|
+
it { should be_empty }
|
95
|
+
end
|
96
|
+
|
97
|
+
context "example 4" do
|
98
|
+
subject { user_repository.find(:first_name => 'Bob', :driver_license => 'NOPE') }
|
99
|
+
|
100
|
+
it { should be_empty }
|
101
|
+
end
|
102
|
+
end
|
17
103
|
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "#all" do
|
107
|
+
let(:records) { user_repository.all }
|
108
|
+
subject { records }
|
109
|
+
|
110
|
+
it { should have(3).users }
|
18
111
|
|
19
|
-
|
20
|
-
|
112
|
+
its(:first) { should == existing_user }
|
113
|
+
its(:last) { should == existing_user_2 }
|
114
|
+
|
115
|
+
describe "record" do
|
116
|
+
subject { records.first }
|
117
|
+
|
118
|
+
its(:first_name) { should == existing_user.first_name }
|
21
119
|
end
|
22
120
|
end
|
23
121
|
end
|
@@ -28,3 +126,83 @@ describe Datamappify::Repository do
|
|
28
126
|
it_behaves_like "finders", data_provider
|
29
127
|
end
|
30
128
|
end
|
129
|
+
|
130
|
+
describe "attributes from different data providers" do
|
131
|
+
before do
|
132
|
+
pending
|
133
|
+
|
134
|
+
HeroUserRepository.save!(HeroUser.new(:first_name => 'Fred', :last_name => 'Wu'))
|
135
|
+
HeroUserRepository.save!(HeroUser.new(:first_name => 'Sheldon', :last_name => 'Cooper'))
|
136
|
+
HeroUserRepository.save!(HeroUser.new(:first_name => 'Fred', :last_name => 'Cooper'))
|
137
|
+
end
|
138
|
+
|
139
|
+
context "example 1" do
|
140
|
+
let(:records) { HeroUserRepository.find(:first_name => 'Fred') }
|
141
|
+
subject { records }
|
142
|
+
|
143
|
+
it { should have(2).users }
|
144
|
+
|
145
|
+
describe "record" do
|
146
|
+
subject { records.first }
|
147
|
+
|
148
|
+
its(:first_name) { should == 'Fred' }
|
149
|
+
its(:last_name) { should == 'Wu' }
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context "example 2" do
|
154
|
+
let(:records) { HeroUserRepository.find(:first_name => 'Sheldon') }
|
155
|
+
subject { records }
|
156
|
+
|
157
|
+
it { should have(1).user }
|
158
|
+
|
159
|
+
describe "record" do
|
160
|
+
subject { records.first }
|
161
|
+
|
162
|
+
its(:first_name) { should == 'Sheldon' }
|
163
|
+
its(:last_name) { should == 'Cooper' }
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
context "example 3" do
|
168
|
+
let(:records) { HeroUserRepository.find(:last_name => 'Cooper') }
|
169
|
+
subject { records }
|
170
|
+
|
171
|
+
it { should have(2).users }
|
172
|
+
|
173
|
+
describe "record" do
|
174
|
+
subject { records.first }
|
175
|
+
|
176
|
+
its(:first_name) { should == 'Sheldon' }
|
177
|
+
its(:last_name) { should == 'Cooper' }
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
context "example 4" do
|
182
|
+
let(:records) { HeroUserRepository.find(:first_name => 'Sheldon', :last_name => 'Cooper') }
|
183
|
+
subject { records }
|
184
|
+
|
185
|
+
it { should have(1).user }
|
186
|
+
|
187
|
+
describe "record" do
|
188
|
+
subject { records.first }
|
189
|
+
|
190
|
+
its(:first_name) { should == 'Sheldon' }
|
191
|
+
its(:last_name) { should == 'Cooper' }
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
context "example 5" do
|
196
|
+
let(:records) { HeroUserRepository.find(:first_name => 'Leonard', :last_name => 'Cooper') }
|
197
|
+
subject { records }
|
198
|
+
|
199
|
+
it { should be_empty }
|
200
|
+
end
|
201
|
+
|
202
|
+
context "example 6" do
|
203
|
+
let(:records) { HeroUserRepository.find(:first_name => 'Fred', :last_name => 'Woo') }
|
204
|
+
subject { records }
|
205
|
+
|
206
|
+
it { should be_empty }
|
207
|
+
end
|
208
|
+
end
|
@@ -5,4 +5,8 @@ class ComputerHardware
|
|
5
5
|
attribute :ram, Integer
|
6
6
|
attribute :hdd, Integer
|
7
7
|
attribute :gfx, String
|
8
|
+
attribute :vendor, String
|
9
|
+
|
10
|
+
validates :ram, :hdd, :numericality => { :greater_than_or_equal_to => 4096 }
|
11
|
+
validates :hdd, :numericality => { :less_than_or_equal_to => 65536 }
|
8
12
|
end
|
@@ -15,14 +15,14 @@ module Datamappify::Entity
|
|
15
15
|
subject { DummyEntity.new }
|
16
16
|
|
17
17
|
describe "#references" do
|
18
|
+
let(:another_entity) { AnotherEntity.new.tap { |e| e.id = 42 } }
|
19
|
+
|
18
20
|
it { should respond_to(:another_entity_id) }
|
19
21
|
it { should respond_to(:another_entity_id=) }
|
20
22
|
it { should respond_to(:another_entity) }
|
21
23
|
it { should respond_to(:another_entity=) }
|
22
24
|
|
23
25
|
describe "assigns the correct attribute" do
|
24
|
-
let(:another_entity) { AnotherEntity.new.tap { |e| e.id = 42 } }
|
25
|
-
|
26
26
|
before do
|
27
27
|
subject.another_entity = another_entity
|
28
28
|
end
|
@@ -31,6 +31,16 @@ module Datamappify::Entity
|
|
31
31
|
its(:another_entity) { should == another_entity }
|
32
32
|
its(:reference_keys) { should include(:another_entity_id) }
|
33
33
|
end
|
34
|
+
|
35
|
+
describe "assigns nil" do
|
36
|
+
before do
|
37
|
+
subject.another_entity = nil
|
38
|
+
end
|
39
|
+
|
40
|
+
its(:another_entity_id) { should be_nil }
|
41
|
+
its(:another_entity) { should be_nil }
|
42
|
+
its(:reference_keys) { should include(:another_entity_id) }
|
43
|
+
end
|
34
44
|
end
|
35
45
|
end
|
36
46
|
end
|