datamappify 0.60.0 → 0.70.0.beta1
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/.travis.yml +0 -1
- data/CHANGELOG.md +20 -0
- data/README.md +120 -3
- data/datamappify.gemspec +3 -3
- data/lib/datamappify/data/criteria/active_record/count.rb +0 -2
- data/lib/datamappify/data/criteria/active_record/criteria.rb +10 -0
- data/lib/datamappify/data/criteria/active_record/criteria_method.rb +65 -0
- data/lib/datamappify/data/criteria/active_record/find.rb +10 -2
- data/lib/datamappify/data/criteria/active_record/find_by_key.rb +4 -2
- data/lib/datamappify/data/criteria/active_record/limit.rb +10 -0
- data/lib/datamappify/data/criteria/active_record/match.rb +40 -0
- data/lib/datamappify/data/criteria/active_record/order.rb +41 -0
- data/lib/datamappify/data/criteria/active_record/rollback.rb +13 -0
- data/lib/datamappify/data/criteria/active_record/save.rb +1 -4
- data/lib/datamappify/data/criteria/active_record/save_by_key.rb +0 -1
- data/lib/datamappify/data/criteria/active_record/where.rb +18 -0
- data/lib/datamappify/data/criteria/common.rb +5 -2
- data/lib/datamappify/data/criteria/concerns/update_primary_record.rb +2 -0
- data/lib/datamappify/data/criteria/relational/concerns/find.rb +35 -0
- data/lib/datamappify/data/criteria/relational/concerns/find_by_key.rb +19 -0
- data/lib/datamappify/data/criteria/relational/criteria.rb +29 -0
- data/lib/datamappify/data/criteria/relational/{find_multiple.rb → criteria_base_method.rb} +2 -28
- data/lib/datamappify/data/criteria/relational/criteria_method.rb +44 -0
- data/lib/datamappify/data/criteria/relational/limit.rb +13 -0
- data/lib/datamappify/data/criteria/relational/save.rb +12 -0
- data/lib/datamappify/data/criteria/sequel/count.rb +0 -2
- data/lib/datamappify/data/criteria/sequel/criteria.rb +10 -0
- data/lib/datamappify/data/criteria/sequel/criteria_method.rb +51 -0
- data/lib/datamappify/data/criteria/sequel/find.rb +10 -2
- data/lib/datamappify/data/criteria/sequel/find_by_key.rb +4 -2
- data/lib/datamappify/data/criteria/sequel/limit.rb +10 -0
- data/lib/datamappify/data/criteria/sequel/match.rb +22 -0
- data/lib/datamappify/data/criteria/sequel/order.rb +22 -0
- data/lib/datamappify/data/criteria/sequel/rollback.rb +13 -0
- data/lib/datamappify/data/criteria/sequel/save.rb +1 -4
- data/lib/datamappify/data/criteria/sequel/save_by_key.rb +0 -1
- data/lib/datamappify/data/criteria/sequel/where.rb +18 -0
- data/lib/datamappify/data/errors.rb +8 -9
- data/lib/datamappify/data/mapper/attribute.rb +13 -33
- data/lib/datamappify/data/mapper.rb +13 -2
- data/lib/datamappify/data/provider/active_record.rb +8 -6
- data/lib/datamappify/data/provider/common_provider.rb +2 -2
- data/lib/datamappify/data/provider/sequel.rb +9 -6
- data/lib/datamappify/entity/association/reference.rb +63 -0
- data/lib/datamappify/entity/association/validation.rb +59 -0
- data/lib/datamappify/entity/association.rb +44 -0
- data/lib/datamappify/entity/{active_model/compatibility.rb → compatibility/active_model.rb} +2 -2
- data/lib/datamappify/entity/compatibility/active_record.rb +22 -0
- data/lib/datamappify/entity/compatibility/association/active_record.rb +43 -0
- data/lib/datamappify/entity/composable/attributes.rb +8 -16
- data/lib/datamappify/entity.rb +8 -6
- data/lib/datamappify/lazy/attributes_handler.rb +1 -1
- data/lib/datamappify/lazy.rb +0 -1
- data/lib/datamappify/repository/mapping_dsl.rb +9 -0
- data/lib/datamappify/repository/query_method/criteria.rb +21 -0
- data/lib/datamappify/repository/query_method/destroy.rb +1 -1
- data/lib/datamappify/repository/query_method/exists.rb +1 -1
- data/lib/datamappify/repository/query_method/find.rb +1 -9
- data/lib/datamappify/repository/query_method/method/multi_result_blender.rb +24 -0
- data/lib/datamappify/repository/query_method/method/reference_handler.rb +60 -0
- data/lib/datamappify/repository/query_method/method/source_attributes_walker.rb +19 -4
- data/lib/datamappify/repository/query_method/method.rb +58 -17
- data/lib/datamappify/repository/query_method/save.rb +4 -4
- data/lib/datamappify/repository/query_method/where_or_match.rb +24 -0
- data/lib/datamappify/repository/query_methods.rb +21 -5
- data/lib/datamappify/repository/unit_of_work/persistent_states/object.rb +2 -2
- data/lib/datamappify/version.rb +1 -1
- data/spec/entity/{relation_spec.rb → association/reference_spec.rb} +2 -2
- data/spec/repository/associations/has_many_spec.rb +259 -0
- data/spec/repository/dirty_tracking_spec.rb +68 -57
- data/spec/repository/finders/all_spec.rb +29 -0
- data/spec/repository/finders/criteria_spec.rb +61 -0
- data/spec/repository/finders/different_providers_spec.rb +81 -0
- data/spec/repository/finders/find_spec.rb +21 -0
- data/spec/repository/finders/match_spec.rb +28 -0
- data/spec/repository/finders/where_spec.rb +18 -0
- data/spec/repository/reverse_mapped_spec.rb +20 -4
- data/spec/support/entities/group.rb +4 -0
- data/spec/support/entities/super_user.rb +9 -0
- data/spec/support/entities/user.rb +5 -0
- data/spec/support/entities/user_info.rb +5 -0
- data/spec/support/repositories/active_record/group_repository.rb +4 -0
- data/spec/support/repositories/active_record/super_user_repository.rb +23 -0
- data/spec/support/repositories/active_record/user_repository.rb +6 -4
- data/spec/support/repositories/sequel/group_repository.rb +4 -0
- data/spec/support/repositories/sequel/super_user_repository.rb +23 -0
- data/spec/support/repositories/sequel/user_repository.rb +6 -4
- data/spec/support/shared/contexts.rb +8 -1
- data/spec/support/shared/examples/repository/finders/where_or_match.rb +130 -0
- data/spec/support/tables/active_record.rb +20 -10
- data/spec/support/tables/sequel.rb +20 -7
- data/spec/unit/entity/{relation_spec.rb → association/reference_spec.rb} +5 -5
- data/spec/unit/repository/query_method_spec.rb +9 -2
- metadata +74 -42
- data/lib/datamappify/data/criteria/active_record/find_multiple.rb +0 -40
- data/lib/datamappify/data/criteria/relational/find.rb +0 -25
- data/lib/datamappify/data/criteria/relational/find_by_key.rb +0 -18
- data/lib/datamappify/data/criteria/sequel/find_multiple.rb +0 -43
- data/lib/datamappify/entity/relation.rb +0 -61
- data/lib/datamappify/repository/query_method/find_multiple.rb +0 -28
- data/spec/repository/finders_spec.rb +0 -211
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "attributes from different data providers" do
|
|
4
|
+
before do
|
|
5
|
+
pending
|
|
6
|
+
|
|
7
|
+
HeroUserRepository.save!(HeroUser.new(:first_name => 'Fred', :last_name => 'Wu'))
|
|
8
|
+
HeroUserRepository.save!(HeroUser.new(:first_name => 'Sheldon', :last_name => 'Cooper'))
|
|
9
|
+
HeroUserRepository.save!(HeroUser.new(:first_name => 'Fred', :last_name => 'Cooper'))
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
context "example 1" do
|
|
13
|
+
let(:records) { HeroUserRepository.find(:first_name => 'Fred') }
|
|
14
|
+
subject { records }
|
|
15
|
+
|
|
16
|
+
it { should have(2).users }
|
|
17
|
+
|
|
18
|
+
describe "record" do
|
|
19
|
+
subject { records.first }
|
|
20
|
+
|
|
21
|
+
its(:first_name) { should == 'Fred' }
|
|
22
|
+
its(:last_name) { should == 'Wu' }
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
context "example 2" do
|
|
27
|
+
let(:records) { HeroUserRepository.find(:first_name => 'Sheldon') }
|
|
28
|
+
subject { records }
|
|
29
|
+
|
|
30
|
+
it { should have(1).user }
|
|
31
|
+
|
|
32
|
+
describe "record" do
|
|
33
|
+
subject { records.first }
|
|
34
|
+
|
|
35
|
+
its(:first_name) { should == 'Sheldon' }
|
|
36
|
+
its(:last_name) { should == 'Cooper' }
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
context "example 3" do
|
|
41
|
+
let(:records) { HeroUserRepository.find(:last_name => 'Cooper') }
|
|
42
|
+
subject { records }
|
|
43
|
+
|
|
44
|
+
it { should have(2).users }
|
|
45
|
+
|
|
46
|
+
describe "record" do
|
|
47
|
+
subject { records.first }
|
|
48
|
+
|
|
49
|
+
its(:first_name) { should == 'Sheldon' }
|
|
50
|
+
its(:last_name) { should == 'Cooper' }
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
context "example 4" do
|
|
55
|
+
let(:records) { HeroUserRepository.find(:first_name => 'Sheldon', :last_name => 'Cooper') }
|
|
56
|
+
subject { records }
|
|
57
|
+
|
|
58
|
+
it { should have(1).user }
|
|
59
|
+
|
|
60
|
+
describe "record" do
|
|
61
|
+
subject { records.first }
|
|
62
|
+
|
|
63
|
+
its(:first_name) { should == 'Sheldon' }
|
|
64
|
+
its(:last_name) { should == 'Cooper' }
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
context "example 5" do
|
|
69
|
+
let(:records) { HeroUserRepository.find(:first_name => 'Leonard', :last_name => 'Cooper') }
|
|
70
|
+
subject { records }
|
|
71
|
+
|
|
72
|
+
it { should be_empty }
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
context "example 6" do
|
|
76
|
+
let(:records) { HeroUserRepository.find(:first_name => 'Fred', :last_name => 'Woo') }
|
|
77
|
+
subject { records }
|
|
78
|
+
|
|
79
|
+
it { should be_empty }
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
shared_examples_for "finder find" do |data_provider|
|
|
4
|
+
include_context "user repository for finders", data_provider
|
|
5
|
+
|
|
6
|
+
context "#{data_provider}" do
|
|
7
|
+
describe "#find" do
|
|
8
|
+
describe "by id" do
|
|
9
|
+
subject { user_repository.find(existing_user.id) }
|
|
10
|
+
|
|
11
|
+
its(:id) { should == existing_user.id }
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe Datamappify::Repository do
|
|
18
|
+
DATA_PROVIDERS.each do |data_provider|
|
|
19
|
+
it_behaves_like "finder find", data_provider
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
shared_examples_for "finder match" do |data_provider|
|
|
4
|
+
include_context "user repository for finders", data_provider
|
|
5
|
+
|
|
6
|
+
context "#{data_provider}" do
|
|
7
|
+
describe "#match" do
|
|
8
|
+
context "case sensitive" do
|
|
9
|
+
include_context "where or match context"
|
|
10
|
+
it_behaves_like "where or match finder", :match, data_provider
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
context "case insensitive" do
|
|
14
|
+
let(:bob) { 'bob' }
|
|
15
|
+
let(:license) { 'yeslicense' }
|
|
16
|
+
let(:no_license) { 'No_License' }
|
|
17
|
+
|
|
18
|
+
it_behaves_like "where or match finder", :match, data_provider
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe Datamappify::Repository do
|
|
25
|
+
DATA_PROVIDERS.each do |data_provider|
|
|
26
|
+
it_behaves_like "finder match", data_provider
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
shared_examples_for "finder where" do |data_provider|
|
|
4
|
+
include_context "user repository for finders", data_provider
|
|
5
|
+
|
|
6
|
+
context "#{data_provider}" do
|
|
7
|
+
describe "#where" do
|
|
8
|
+
include_context "where or match context"
|
|
9
|
+
it_behaves_like "where or match finder", :where, data_provider
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe Datamappify::Repository do
|
|
15
|
+
DATA_PROVIDERS.each do |data_provider|
|
|
16
|
+
it_behaves_like "finder where", data_provider
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -6,6 +6,8 @@ shared_examples_for "reverse mapped" do |data_provider|
|
|
|
6
6
|
let(:new_author) { Reversed::Author.new(:name => 'George R. R. Martin', :bio => 'GoT') }
|
|
7
7
|
let(:new_post) { Reversed::Post.new(:title => 'Hello world', :author_name => 'Fred Wu', :author_bio => 'x')}
|
|
8
8
|
let(:new_post_2) { Reversed::Post.new(:title => 'Hello earth', :author_name => 'Sheldon Cooper', :author_bio => 'y')}
|
|
9
|
+
let(:data_authors) { "Datamappify::Data::Record::#{data_provider}::Reversed::Author".constantize }
|
|
10
|
+
let(:data_posts) { "Datamappify::Data::Record::#{data_provider}::Reversed::Post".constantize }
|
|
9
11
|
|
|
10
12
|
context "#{data_provider}" do
|
|
11
13
|
before do
|
|
@@ -46,9 +48,24 @@ shared_examples_for "reverse mapped" do |data_provider|
|
|
|
46
48
|
end
|
|
47
49
|
|
|
48
50
|
describe "update record" do
|
|
51
|
+
let(:record) { post_repository.find(saved_post.id) }
|
|
52
|
+
|
|
53
|
+
describe "data records" do
|
|
54
|
+
it "does not create extra primary data records" do
|
|
55
|
+
expect { post_repository.save!(record) }.to change { data_posts.count }.by(0)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "does not create extra secondary data records" do
|
|
59
|
+
expect { post_repository.save!(record) }.to change { data_authors.count }.by(0)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "does not change data record's foreign key value" do
|
|
63
|
+
expect { post_repository.save!(record) }.not_to change { data_posts.last.author_id }
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
49
67
|
context "example 1" do
|
|
50
|
-
|
|
51
|
-
subject { post_repository.save!(record) }
|
|
68
|
+
subject { post_repository.save!(record) }
|
|
52
69
|
|
|
53
70
|
its(:title) { should == 'Hello world' }
|
|
54
71
|
its(:author_name) { should == 'Fred Wu' }
|
|
@@ -56,8 +73,7 @@ shared_examples_for "reverse mapped" do |data_provider|
|
|
|
56
73
|
end
|
|
57
74
|
|
|
58
75
|
context "example 2" do
|
|
59
|
-
|
|
60
|
-
subject { post_repository.find(record.id) }
|
|
76
|
+
subject { post_repository.find(record.id) }
|
|
61
77
|
|
|
62
78
|
before do
|
|
63
79
|
record.title = 'Hello mars'
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require_relative 'user_info'
|
|
2
|
+
|
|
1
3
|
class User
|
|
2
4
|
include Datamappify::Entity
|
|
3
5
|
|
|
@@ -15,6 +17,9 @@ class User
|
|
|
15
17
|
validates :driver_license, :presence => true,
|
|
16
18
|
:length => { :minimum => 8 }
|
|
17
19
|
|
|
20
|
+
attributes_from UserInfo, :prefix_with => :personal
|
|
21
|
+
attributes_from UserInfo, :prefix_with => :business
|
|
22
|
+
|
|
18
23
|
def full_name
|
|
19
24
|
"#{first_name} #{last_name}"
|
|
20
25
|
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require_relative 'user_repository'
|
|
2
|
+
|
|
3
|
+
class SuperUserRepositoryActiveRecord
|
|
4
|
+
include Datamappify::Repository
|
|
5
|
+
|
|
6
|
+
for_entity SuperUser
|
|
7
|
+
default_provider :ActiveRecord
|
|
8
|
+
|
|
9
|
+
group :via => :base_user_id do
|
|
10
|
+
map_attribute :first_name, :to => 'User#first_name'
|
|
11
|
+
map_attribute :last_name, :to => 'User#surname'
|
|
12
|
+
map_attribute :age, :to => 'User#age'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
group :reference_key => :user_id do
|
|
16
|
+
map_attribute :driver_license, :to => 'UserDriverLicense#number'
|
|
17
|
+
map_attribute :passport, :to => 'UserPassport#number'
|
|
18
|
+
map_attribute :health_care, :to => 'UserHealthCare#number'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
map_attribute :personal_content, :to => 'UserInfo#content', :via => :personal_info_id
|
|
22
|
+
map_attribute :business_content, :to => 'UserInfo#content', :via => :business_info_id
|
|
23
|
+
end
|
|
@@ -4,8 +4,10 @@ class UserRepositoryActiveRecord
|
|
|
4
4
|
for_entity User
|
|
5
5
|
default_provider :ActiveRecord
|
|
6
6
|
|
|
7
|
-
map_attribute :last_name,
|
|
8
|
-
map_attribute :driver_license,
|
|
9
|
-
map_attribute :passport,
|
|
10
|
-
map_attribute :health_care,
|
|
7
|
+
map_attribute :last_name, :to => 'User#surname'
|
|
8
|
+
map_attribute :driver_license, :to => 'UserDriverLicense#number'
|
|
9
|
+
map_attribute :passport, :to => 'UserPassport#number'
|
|
10
|
+
map_attribute :health_care, :to => 'UserHealthCare#number'
|
|
11
|
+
map_attribute :personal_content, :to => 'UserInfo#content', :via => :personal_info_id
|
|
12
|
+
map_attribute :business_content, :to => 'UserInfo#content', :via => :business_info_id
|
|
11
13
|
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require_relative 'user_repository'
|
|
2
|
+
|
|
3
|
+
class SuperUserRepositorySequel
|
|
4
|
+
include Datamappify::Repository
|
|
5
|
+
|
|
6
|
+
for_entity SuperUser
|
|
7
|
+
default_provider :Sequel
|
|
8
|
+
|
|
9
|
+
group :via => :base_user_id do
|
|
10
|
+
map_attribute :first_name, :to => 'User#first_name'
|
|
11
|
+
map_attribute :last_name, :to => 'User#surname'
|
|
12
|
+
map_attribute :age, :to => 'User#age'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
group :reference_key => :user_id do
|
|
16
|
+
map_attribute :driver_license, :to => 'UserDriverLicense#number'
|
|
17
|
+
map_attribute :passport, :to => 'UserPassport#number'
|
|
18
|
+
map_attribute :health_care, :to => 'UserHealthCare#number'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
map_attribute :personal_content, :to => 'UserInfo#content', :via => :personal_info_id
|
|
22
|
+
map_attribute :business_content, :to => 'UserInfo#content', :via => :business_info_id
|
|
23
|
+
end
|
|
@@ -4,8 +4,10 @@ class UserRepositorySequel
|
|
|
4
4
|
for_entity User
|
|
5
5
|
default_provider :Sequel
|
|
6
6
|
|
|
7
|
-
map_attribute :last_name,
|
|
8
|
-
map_attribute :driver_license,
|
|
9
|
-
map_attribute :passport,
|
|
10
|
-
map_attribute :health_care,
|
|
7
|
+
map_attribute :last_name, :to => 'User#surname'
|
|
8
|
+
map_attribute :driver_license, :to => 'UserDriverLicense#number'
|
|
9
|
+
map_attribute :passport, :to => 'UserPassport#number'
|
|
10
|
+
map_attribute :health_care, :to => 'UserHealthCare#number'
|
|
11
|
+
map_attribute :personal_content, :to => 'UserInfo#content', :via => :personal_info_id
|
|
12
|
+
map_attribute :business_content, :to => 'UserInfo#content', :via => :business_info_id
|
|
11
13
|
end
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
shared_context "user repository" do |data_provider|
|
|
2
|
-
let
|
|
2
|
+
let(:user_repository) { "UserRepository#{data_provider}".constantize }
|
|
3
3
|
let!(:existing_user) { user_repository.save(User.new(:first_name => 'Fred', :driver_license => 'FREDWU42')) }
|
|
4
4
|
let(:new_valid_user) { User.new(:first_name => 'Batman', :driver_license => 'ARKHAMCITY') }
|
|
5
5
|
let(:new_valid_user2) { User.new(:first_name => 'Ironman', :driver_license => 'NEWYORKCITY') }
|
|
@@ -8,3 +8,10 @@ shared_context "user repository" do |data_provider|
|
|
|
8
8
|
let(:data_passports) { "Datamappify::Data::Record::#{data_provider}::UserPassport".constantize }
|
|
9
9
|
let(:data_driver_licenses) { "Datamappify::Data::Record::#{data_provider}::UserDriverLicense".constantize }
|
|
10
10
|
end
|
|
11
|
+
|
|
12
|
+
shared_context "user repository for finders" do |data_provider|
|
|
13
|
+
include_context "user repository", data_provider
|
|
14
|
+
|
|
15
|
+
let!(:existing_user_1) { user_repository.save(new_valid_user.dup) }
|
|
16
|
+
let!(:existing_user_2) { user_repository.save(new_valid_user.dup) }
|
|
17
|
+
end
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
shared_context "where or match context" do
|
|
2
|
+
let(:bob) { 'Bob' }
|
|
3
|
+
let(:license) { 'YESLICENSE' }
|
|
4
|
+
let(:no_license) { 'NO_LICENSE' }
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
shared_examples_for "where or match finder" do |finder, data_provider|
|
|
8
|
+
subject { records }
|
|
9
|
+
|
|
10
|
+
before do
|
|
11
|
+
user_repository.save!(User.new(:first_name => 'Mary', :driver_license => 'YESLICENSE'))
|
|
12
|
+
user_repository.save!(User.new(:first_name => 'Bob', :driver_license => 'YESLICENSE', :personal_content => 'Ok'))
|
|
13
|
+
user_repository.save!(User.new(:first_name => 'Jane', :driver_license => 'NO_LICENSE', :business_content => 'Ok'))
|
|
14
|
+
user_repository.save!(User.new(:first_name => 'Bob', :driver_license => 'NO_LICENSE'))
|
|
15
|
+
user_repository.save!(User.new(:first_name => 'Bob', :driver_license => 'YESLICENSE', :business_content => 'No'))
|
|
16
|
+
user_repository.save!(User.new(:first_name => 'Bobb', :driver_license => 'YESLICENSE'))
|
|
17
|
+
user_repository.save!(User.new(:first_name => 'John', :driver_license => 'YESLICENSE'))
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe "by attribute that does not exist" do
|
|
21
|
+
let(:records) { user_repository.send(finder, :blah => bob) }
|
|
22
|
+
|
|
23
|
+
it { expect { records }.to raise_exception(Datamappify::Data::EntityAttributeInvalid) }
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe "by primary attribute" do
|
|
27
|
+
let(:records) { user_repository.send(finder, :first_name => bob) }
|
|
28
|
+
|
|
29
|
+
it { should have(3).users }
|
|
30
|
+
|
|
31
|
+
describe "record" do
|
|
32
|
+
subject { records.first }
|
|
33
|
+
|
|
34
|
+
its(:first_name) { should == 'Bob' }
|
|
35
|
+
its(:driver_license) { should == 'YESLICENSE' }
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe "by secondary attribute" do
|
|
40
|
+
let(:records) { user_repository.send(finder, :driver_license => no_license) }
|
|
41
|
+
|
|
42
|
+
it { should have(2).users }
|
|
43
|
+
|
|
44
|
+
describe "record" do
|
|
45
|
+
subject { records.first }
|
|
46
|
+
|
|
47
|
+
its(:first_name) { should == 'Jane' }
|
|
48
|
+
its(:driver_license) { should == 'NO_LICENSE' }
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
describe "by primary and secondary attributes" do
|
|
53
|
+
context "example 1" do
|
|
54
|
+
let(:records) { user_repository.send(finder, :first_name => bob, :driver_license => no_license) }
|
|
55
|
+
subject { records }
|
|
56
|
+
|
|
57
|
+
it { should have(1).user }
|
|
58
|
+
|
|
59
|
+
describe "record" do
|
|
60
|
+
subject { records.first }
|
|
61
|
+
|
|
62
|
+
its(:first_name) { should == 'Bob' }
|
|
63
|
+
its(:driver_license) { should == 'NO_LICENSE' }
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
context "example 2" do
|
|
68
|
+
let(:records) { user_repository.send(finder, :first_name => bob, :driver_license => license) }
|
|
69
|
+
subject { records }
|
|
70
|
+
|
|
71
|
+
it { should have(2).users }
|
|
72
|
+
|
|
73
|
+
describe "record" do
|
|
74
|
+
subject { records.first }
|
|
75
|
+
|
|
76
|
+
its(:first_name) { should == 'Bob' }
|
|
77
|
+
its(:driver_license) { should == 'YESLICENSE' }
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
context "example 3" do
|
|
82
|
+
subject { user_repository.send(finder, :first_name => 'Nope', :driver_license => license) }
|
|
83
|
+
|
|
84
|
+
it { should be_empty }
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
context "example 4" do
|
|
88
|
+
subject { user_repository.send(finder, :first_name => bob, :driver_license => 'NOPE') }
|
|
89
|
+
|
|
90
|
+
it { should be_empty }
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
context "example 5 (string keys)" do
|
|
94
|
+
let(:records) { user_repository.send(finder, 'first_name' => bob, 'driver_license' => license) }
|
|
95
|
+
|
|
96
|
+
it { should have(2).users }
|
|
97
|
+
|
|
98
|
+
describe "record" do
|
|
99
|
+
subject { records.first }
|
|
100
|
+
|
|
101
|
+
its(:first_name) { should == 'Bob' }
|
|
102
|
+
its(:driver_license) { should == 'YESLICENSE' }
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
describe "by reverse mapped attribute" do
|
|
108
|
+
let(:records) { user_repository.send(finder, :business_content => 'Ok') }
|
|
109
|
+
|
|
110
|
+
it { should have(1).user }
|
|
111
|
+
|
|
112
|
+
context "record" do
|
|
113
|
+
subject { records.first }
|
|
114
|
+
|
|
115
|
+
its(:personal_content) { should be_nil }
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
context "data record" do
|
|
119
|
+
subject { "Datamappify::Data::Record::#{data_provider}::User".constantize.last }
|
|
120
|
+
|
|
121
|
+
it "has proper personal_info association" do
|
|
122
|
+
-> { subject.personal_info }.should_not raise_error
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
it "has proper business_info association" do
|
|
126
|
+
-> { subject.business_info }.should_not raise_error
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
@@ -13,18 +13,33 @@ ActiveRecord::Migration.suppress_messages do
|
|
|
13
13
|
t.timestamps
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
+
create_table :super_users do |t|
|
|
17
|
+
t.references :personal_info
|
|
18
|
+
t.references :business_info
|
|
19
|
+
t.references :base_user
|
|
20
|
+
t.references :group
|
|
21
|
+
t.timestamps
|
|
22
|
+
end
|
|
23
|
+
|
|
16
24
|
create_table :users do |t|
|
|
17
25
|
t.string :first_name, :null => false
|
|
18
26
|
t.string :surname
|
|
19
27
|
t.integer :age
|
|
20
28
|
t.integer :level
|
|
21
|
-
t.references :
|
|
29
|
+
t.references :personal_info
|
|
30
|
+
t.references :business_info
|
|
31
|
+
t.timestamps
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
create_table :user_infos do |t|
|
|
35
|
+
t.string :content
|
|
36
|
+
t.references :user
|
|
22
37
|
t.timestamps
|
|
23
38
|
end
|
|
24
39
|
|
|
25
40
|
create_table :comments do |t|
|
|
26
41
|
t.string :content
|
|
27
|
-
t.
|
|
42
|
+
t.references :user
|
|
28
43
|
t.timestamps
|
|
29
44
|
end
|
|
30
45
|
|
|
@@ -38,29 +53,24 @@ ActiveRecord::Migration.suppress_messages do
|
|
|
38
53
|
t.timestamps
|
|
39
54
|
end
|
|
40
55
|
|
|
41
|
-
create_table :groups_users do |t|
|
|
42
|
-
t.belongs_to :user
|
|
43
|
-
t.belongs_to :group
|
|
44
|
-
end
|
|
45
|
-
|
|
46
56
|
create_table :user_driver_licenses do |t|
|
|
47
57
|
t.string :number
|
|
48
58
|
t.string :expiry
|
|
49
|
-
t.
|
|
59
|
+
t.references :user
|
|
50
60
|
t.timestamps
|
|
51
61
|
end
|
|
52
62
|
|
|
53
63
|
create_table :user_passports do |t|
|
|
54
64
|
t.string :number
|
|
55
65
|
t.string :expiry, :null => false
|
|
56
|
-
t.
|
|
66
|
+
t.references :user
|
|
57
67
|
t.timestamps
|
|
58
68
|
end
|
|
59
69
|
|
|
60
70
|
create_table :user_health_cares do |t|
|
|
61
71
|
t.string :number
|
|
62
72
|
t.string :expiry
|
|
63
|
-
t.
|
|
73
|
+
t.references :user
|
|
64
74
|
t.timestamps
|
|
65
75
|
end
|
|
66
76
|
|
|
@@ -11,13 +11,32 @@ DB.create_table :hero_user_last_names do
|
|
|
11
11
|
DateTime :updated_at
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
+
DB.create_table :super_users do
|
|
15
|
+
primary_key :id
|
|
16
|
+
foreign_key :personal_info_id
|
|
17
|
+
foreign_key :business_info_id
|
|
18
|
+
foreign_key :base_user_id
|
|
19
|
+
foreign_key :group_id
|
|
20
|
+
DateTime :created_at
|
|
21
|
+
DateTime :updated_at
|
|
22
|
+
end
|
|
23
|
+
|
|
14
24
|
DB.create_table :users do
|
|
15
25
|
primary_key :id
|
|
16
26
|
String :first_name, :null => false
|
|
17
27
|
String :surname
|
|
18
28
|
Integer :age
|
|
19
29
|
Integer :level
|
|
20
|
-
foreign_key :
|
|
30
|
+
foreign_key :personal_info_id
|
|
31
|
+
foreign_key :business_info_id
|
|
32
|
+
DateTime :created_at
|
|
33
|
+
DateTime :updated_at
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
DB.create_table :user_infos do
|
|
37
|
+
primary_key :id
|
|
38
|
+
String :content
|
|
39
|
+
foreign_key :user_id
|
|
21
40
|
DateTime :created_at
|
|
22
41
|
DateTime :updated_at
|
|
23
42
|
end
|
|
@@ -44,12 +63,6 @@ DB.create_table :groups do
|
|
|
44
63
|
DateTime :updated_at
|
|
45
64
|
end
|
|
46
65
|
|
|
47
|
-
DB.create_table :groups_users do
|
|
48
|
-
primary_key :id
|
|
49
|
-
foreign_key :user_id
|
|
50
|
-
foreign_key :group_id
|
|
51
|
-
end
|
|
52
|
-
|
|
53
66
|
DB.create_table :user_driver_licenses do
|
|
54
67
|
primary_key :id
|
|
55
68
|
String :number
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
module Datamappify::Entity
|
|
4
|
-
describe Datamappify::Entity::
|
|
5
|
-
class
|
|
4
|
+
describe Datamappify::Entity::Association::Reference do
|
|
5
|
+
class DummyEntityA
|
|
6
6
|
include Datamappify::Entity
|
|
7
7
|
|
|
8
8
|
references :another_entity
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
class
|
|
11
|
+
class DummyEntityB
|
|
12
12
|
include Datamappify::Entity
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
subject {
|
|
15
|
+
subject { DummyEntityA.new }
|
|
16
16
|
|
|
17
17
|
describe "#references" do
|
|
18
|
-
let(:another_entity) {
|
|
18
|
+
let(:another_entity) { DummyEntityB.new.tap { |e| e.id = 42 } }
|
|
19
19
|
|
|
20
20
|
it { should respond_to(:another_entity_id) }
|
|
21
21
|
it { should respond_to(:another_entity_id=) }
|
|
@@ -37,8 +37,15 @@ module Datamappify::Repository::QueryMethod
|
|
|
37
37
|
it { should_not be_a_writer }
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
describe
|
|
41
|
-
subject {
|
|
40
|
+
describe Where do
|
|
41
|
+
subject { Where }
|
|
42
|
+
|
|
43
|
+
it { should be_a_reader }
|
|
44
|
+
it { should_not be_a_writer }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
describe Criteria do
|
|
48
|
+
subject { Criteria }
|
|
42
49
|
|
|
43
50
|
it { should be_a_reader }
|
|
44
51
|
it { should_not be_a_writer }
|