rom-repository 1.4.0 → 2.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -6
  3. data/{LICENSE.txt → LICENSE} +1 -1
  4. data/README.md +18 -1
  5. data/lib/rom-repository.rb +1 -2
  6. data/lib/rom/repository.rb +9 -216
  7. data/lib/rom/repository/class_interface.rb +16 -33
  8. data/lib/rom/repository/relation_reader.rb +46 -0
  9. data/lib/rom/repository/root.rb +3 -59
  10. data/lib/rom/repository/version.rb +1 -1
  11. metadata +9 -98
  12. data/.gitignore +0 -3
  13. data/.rspec +0 -3
  14. data/.travis.yml +0 -27
  15. data/.yardopts +0 -2
  16. data/Gemfile +0 -38
  17. data/Rakefile +0 -19
  18. data/lib/rom/open_struct.rb +0 -35
  19. data/lib/rom/repository/changeset.rb +0 -155
  20. data/lib/rom/repository/changeset/associated.rb +0 -100
  21. data/lib/rom/repository/changeset/create.rb +0 -16
  22. data/lib/rom/repository/changeset/delete.rb +0 -17
  23. data/lib/rom/repository/changeset/pipe.rb +0 -97
  24. data/lib/rom/repository/changeset/restricted.rb +0 -28
  25. data/lib/rom/repository/changeset/stateful.rb +0 -282
  26. data/lib/rom/repository/changeset/update.rb +0 -82
  27. data/lib/rom/repository/command_compiler.rb +0 -257
  28. data/lib/rom/repository/command_proxy.rb +0 -26
  29. data/lib/rom/repository/header_builder.rb +0 -65
  30. data/lib/rom/repository/mapper_builder.rb +0 -23
  31. data/lib/rom/repository/relation_proxy.rb +0 -337
  32. data/lib/rom/repository/relation_proxy/combine.rb +0 -320
  33. data/lib/rom/repository/relation_proxy/wrap.rb +0 -78
  34. data/lib/rom/repository/struct_builder.rb +0 -83
  35. data/lib/rom/struct.rb +0 -113
  36. data/log/.gitkeep +0 -0
  37. data/rom-repository.gemspec +0 -23
  38. data/spec/integration/changeset_spec.rb +0 -193
  39. data/spec/integration/command_macros_spec.rb +0 -191
  40. data/spec/integration/command_spec.rb +0 -228
  41. data/spec/integration/multi_adapter_spec.rb +0 -73
  42. data/spec/integration/repository/aggregate_spec.rb +0 -58
  43. data/spec/integration/repository_spec.rb +0 -406
  44. data/spec/integration/root_repository_spec.rb +0 -106
  45. data/spec/integration/typed_structs_spec.rb +0 -64
  46. data/spec/shared/database.rb +0 -79
  47. data/spec/shared/mappers.rb +0 -35
  48. data/spec/shared/models.rb +0 -41
  49. data/spec/shared/plugins.rb +0 -66
  50. data/spec/shared/relations.rb +0 -115
  51. data/spec/shared/repo.rb +0 -86
  52. data/spec/shared/seeds.rb +0 -30
  53. data/spec/shared/structs.rb +0 -140
  54. data/spec/spec_helper.rb +0 -83
  55. data/spec/support/mapper_registry.rb +0 -9
  56. data/spec/support/mutant.rb +0 -10
  57. data/spec/unit/changeset/associate_spec.rb +0 -120
  58. data/spec/unit/changeset/map_spec.rb +0 -111
  59. data/spec/unit/changeset_spec.rb +0 -186
  60. data/spec/unit/relation_proxy_spec.rb +0 -202
  61. data/spec/unit/repository/changeset_spec.rb +0 -197
  62. data/spec/unit/repository/inspect_spec.rb +0 -18
  63. data/spec/unit/repository/session_spec.rb +0 -251
  64. data/spec/unit/repository/transaction_spec.rb +0 -42
  65. data/spec/unit/session_spec.rb +0 -46
  66. data/spec/unit/struct_builder_spec.rb +0 -128
data/spec/shared/repo.rb DELETED
@@ -1,86 +0,0 @@
1
- RSpec.shared_context('repo') do
2
- include_context 'models'
3
- include_context 'mappers'
4
-
5
- let(:repo) { repo_class.new(rom) }
6
-
7
- let(:repo_class) do
8
- Class.new(ROM::Repository[:users]) do
9
- relations :tasks, :tags, :posts, :labels, :posts_labels, :books, :authors
10
-
11
- def find_users(criteria)
12
- users.find(criteria)
13
- end
14
-
15
- def all_users
16
- users.all
17
- end
18
-
19
- def all_users_as_users
20
- users.as(:user).all
21
- end
22
-
23
- def users_with_tasks
24
- aggregate(many: { all_tasks: tasks.for_users })
25
- end
26
-
27
- def users_with_tasks_and_tags
28
- aggregate(many: { all_tasks: tasks_with_tags(tasks.for_users) })
29
- end
30
-
31
- def users_with_task
32
- aggregate(one: tasks)
33
- end
34
-
35
- def users_with_task_by_title(title)
36
- aggregate(one: tasks.find(title: title))
37
- end
38
-
39
- def users_with_posts_and_their_labels
40
- users.combine(posts: [:labels])
41
- end
42
-
43
- def posts_with_labels
44
- posts.combine_children(many: labels)
45
- end
46
-
47
- def label_with_posts
48
- labels.combine_children(one: posts)
49
- end
50
-
51
- def tasks_for_users(users)
52
- tasks.for_users(users)
53
- end
54
-
55
- def task_with_user
56
- tasks.find(tasks[:id].qualified => 2).wrap_parent(user: users)
57
- end
58
-
59
- def task_with_owner
60
- tasks.find(id: 2).combine_parents(one: { owner: users })
61
- end
62
-
63
- def tasks_with_tags(tasks = self.tasks)
64
- tasks.combine_children(many: tags)
65
- end
66
-
67
- def tag_with_wrapped_task
68
- tags.wrap_parent(task: tasks)
69
- end
70
- end
71
- end
72
-
73
- let(:comments_repo) do
74
- Class.new(ROM::Repository[:comments]) do
75
- relations :likes
76
-
77
- def comments_with_likes
78
- aggregate(many: { likes: likes })
79
- end
80
-
81
- def comments_with_emotions
82
- root.combine(:emotions)
83
- end
84
- end.new(rom)
85
- end
86
- end
data/spec/shared/seeds.rb DELETED
@@ -1,30 +0,0 @@
1
- RSpec.shared_context 'seeds' do
2
- before do
3
- jane_id = conn[:users].insert name: 'Jane'
4
- joe_id = conn[:users].insert name: 'Joe'
5
-
6
- conn[:tasks].insert user_id: joe_id, title: 'Joe Task'
7
- task_id = conn[:tasks].insert user_id: jane_id, title: 'Jane Task'
8
-
9
- conn[:tags].insert task_id: task_id, name: 'red'
10
-
11
- jane_post_id = conn[:posts].insert author_id: jane_id, title: 'Hello From Jane', body: 'Jane Post'
12
- joe_post_id = conn[:posts].insert author_id: joe_id, title: 'Hello From Joe', body: 'Joe Post'
13
-
14
- red_id = conn[:labels].insert name: 'red'
15
- green_id = conn[:labels].insert name: 'green'
16
- blue_id = conn[:labels].insert name: 'blue'
17
-
18
- conn[:posts_labels].insert post_id: jane_post_id, label_id: red_id
19
- conn[:posts_labels].insert post_id: jane_post_id, label_id: blue_id
20
-
21
- conn[:posts_labels].insert post_id: joe_post_id, label_id: green_id
22
-
23
- conn[:messages].insert author: 'Jane', body: 'Hello folks'
24
- conn[:messages].insert author: 'Joe', body: 'Hello Jane'
25
-
26
- conn[:reactions].insert message_id: 1, author: 'Joe'
27
- conn[:reactions].insert message_id: 1, author: 'Anonymous'
28
- conn[:reactions].insert message_id: 2, author: 'Jane'
29
- end
30
- end
@@ -1,140 +0,0 @@
1
- RSpec.shared_context 'structs' do
2
- let(:user_struct) do
3
- repo.users.mapper.model
4
- end
5
-
6
- let(:task_struct) do
7
- repo.tasks.mapper.model
8
- end
9
-
10
- let(:tag_struct) do
11
- repo.tags.mapper.model
12
- end
13
-
14
- let(:post_struct) do
15
- repo.posts.mapper.model
16
- end
17
-
18
- let(:label_struct) do
19
- repo.labels.mapper.model
20
- end
21
-
22
- let(:post_with_labels_struct) do
23
- mapper_for(repo.posts_with_labels).model
24
- end
25
-
26
- let(:label_with_posts_struct) do
27
- mapper_for(repo.label_with_posts).model
28
- end
29
-
30
- let(:tag_with_task_struct) do
31
- mapper_for(repo.tag_with_wrapped_task).model
32
- end
33
-
34
- let(:user_with_tasks_struct) do
35
- mapper_for(repo.users_with_tasks).model
36
- end
37
-
38
- let(:user_with_task_struct) do
39
- mapper_for(repo.users_with_task).model
40
- end
41
-
42
- let(:user_with_posts_struct) do
43
- mapper_for(repo.users_with_posts_and_their_labels).model
44
- end
45
-
46
- let(:task_with_tags_struct) do
47
- mapper_for(repo.tasks_with_tags).model
48
- end
49
-
50
- let(:task_with_user_struct) do
51
- mapper_for(repo.task_with_user).model
52
- end
53
-
54
- let(:task_with_owner_struct) do
55
- mapper_for(repo.task_with_owner).model
56
- end
57
-
58
- let(:jane) do
59
- user_struct.new(id: 1, name: 'Jane')
60
- end
61
-
62
- let(:jane_with_tasks) do
63
- user_with_tasks_struct.new(id: 1, name: 'Jane', all_tasks: [jane_task])
64
- end
65
-
66
- let(:jane_with_task) do
67
- user_with_task_struct.new(id: 1, name: 'Jane', task: jane_task)
68
- end
69
-
70
- let(:jane_without_task) do
71
- user_with_task_struct.new(id: 1, name: 'Jane', task: nil)
72
- end
73
-
74
- let(:jane_task) do
75
- task_struct.new(id: 2, user_id: 1, title: 'Jane Task')
76
- end
77
-
78
- let(:task_with_user) do
79
- task_with_user_struct.new(id: 2, user_id: 1, title: 'Jane Task', user: jane)
80
- end
81
-
82
- let(:task_with_owner) do
83
- task_with_owner_struct.new(id: 2, user_id: 1, title: 'Jane Task', owner: jane)
84
- end
85
-
86
- let(:tag) do
87
- tag_struct.new(id: 1, task_id: 2, name: 'red')
88
- end
89
-
90
- let(:task) do
91
- task_struct.new(id: 2, user_id: 1, title: 'Jane Task')
92
- end
93
-
94
- let(:tag_with_task) do
95
- tag_with_task_struct.new(id: 1, task_id: 2, name: 'red', task: task)
96
- end
97
-
98
- let(:task_with_tag) do
99
- task_with_tags_struct.new(id: 2, user_id: 1, title: 'Jane Task', tags: [tag])
100
- end
101
-
102
- let(:user_with_task_and_tags) do
103
- user_with_tasks_struct.new(id: 1, name: 'Jane', all_tasks: [task_with_tag])
104
- end
105
-
106
- let(:joe) do
107
- user_struct.new(id: 2, name: 'Joe')
108
- end
109
-
110
- let(:joe_with_tasks) do
111
- user_with_tasks_struct.new(id: 2, name: 'Joe', all_tasks: [joe_task])
112
- end
113
-
114
- let(:joe_with_task) do
115
- user_with_task_struct.new(id: 2, name: 'Joe', task: joe_task)
116
- end
117
-
118
- let(:joe_task) do
119
- task_struct.new(id: 1, user_id: 2, title: 'Joe Task')
120
- end
121
-
122
- let(:jane_with_posts) do
123
- user_with_posts_struct.new(id: 1, name: 'Jane', posts: [post_with_label])
124
- end
125
-
126
- let(:label_red) do
127
- label_with_posts_struct.new(id: 1, name: 'red', post: 1)
128
- end
129
-
130
- let(:label_blue) do
131
- label_with_posts_struct.new(id: 3, name: 'blue', post: 1)
132
- end
133
-
134
- let(:post_with_label) do
135
- post_with_labels_struct.new(id: 2, title: 'Hello From Jane',
136
- body: 'Jane Post',
137
- author_id: 1,
138
- labels: [label_red, label_blue])
139
- end
140
- end
data/spec/spec_helper.rb DELETED
@@ -1,83 +0,0 @@
1
- # this is needed for guard to work, not sure why :(
2
- require "bundler"
3
- Bundler.setup
4
-
5
- if RUBY_ENGINE == 'ruby' && ENV['COVERAGE'] == 'true'
6
- require 'yaml'
7
- rubies = YAML.load(File.read(File.join(__dir__, '..', '.travis.yml')))['rvm']
8
- latest_mri = rubies.select { |v| v =~ /\A\d+\.\d+.\d+\z/ }.max
9
-
10
- if RUBY_VERSION == latest_mri
11
- require 'simplecov'
12
- SimpleCov.start do
13
- add_filter '/spec/'
14
- end
15
- end
16
- end
17
-
18
- require 'rom-sql'
19
- require 'rom-repository'
20
-
21
- begin
22
- require 'byebug'
23
- rescue LoadError
24
- end
25
-
26
- root = Pathname(__FILE__).dirname
27
- LOGGER = Logger.new(File.open('./log/test.log', 'a'))
28
-
29
- require 'dry/core/deprecations'
30
- Dry::Core::Deprecations.set_logger!(root.join('../log/deprecations.log'))
31
-
32
- # Make inference errors quiet
33
- class ROM::SQL::Schema::Inferrer
34
- def self.on_error(*args)
35
- # shush
36
- end
37
- end
38
-
39
- # Namespace holding all objects created during specs
40
- module Test
41
- def self.remove_constants
42
- constants.each(&method(:remove_const))
43
- end
44
- end
45
-
46
- warning_api_available = RUBY_VERSION >= '2.4.0'
47
-
48
- module SileneceWarnings
49
- def warn(str)
50
- if str['/sequel/'] || str['/rspec-core']
51
- nil
52
- else
53
- super
54
- end
55
- end
56
- end
57
-
58
- DB_URI = if defined? JRUBY_VERSION
59
- 'jdbc:postgresql://localhost/rom_repository'
60
- else
61
- 'postgres://localhost/rom_repository'
62
- end
63
-
64
- Warning.extend(SileneceWarnings) if warning_api_available
65
-
66
- RSpec.configure do |config|
67
- config.disable_monkey_patching!
68
- config.warnings = warning_api_available
69
-
70
- config.after do
71
- Test.remove_constants
72
- end
73
-
74
- Dir[root.join('support/*.rb').to_s].each do |f|
75
- require f
76
- end
77
-
78
- Dir[root.join('shared/*.rb').to_s].each do |f|
79
- require f
80
- end
81
-
82
- config.include(MapperRegistry)
83
- end
@@ -1,9 +0,0 @@
1
- module MapperRegistry
2
- def mapper_for(relation)
3
- mapper_builder[relation.to_ast]
4
- end
5
-
6
- def mapper_builder
7
- @mapper_builder ||= ROM::Repository::MapperBuilder.new
8
- end
9
- end
@@ -1,10 +0,0 @@
1
- module Mutant
2
- class Selector
3
- # Expression based test selector
4
- class Expression < self
5
- def call(_subject)
6
- integration.all_tests
7
- end
8
- end # Expression
9
- end # Selector
10
- end # Mutant
@@ -1,120 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe ROM::Changeset, '#associate' do
4
- include_context 'database setup'
5
-
6
- before do
7
- [:todos, :projects, :people].each { |table| conn.drop_table?(table) }
8
-
9
- conn.create_table :people do
10
- primary_key :id
11
- column :name, String
12
- end
13
-
14
- conn.create_table :projects do
15
- primary_key :id
16
- column :name, String
17
- end
18
-
19
- conn.create_table :todos do
20
- primary_key :id
21
- foreign_key :user_id, :people, null: false, on_delete: :cascade
22
- foreign_key :project_id, :projects, null: true, on_delete: :cascade
23
- column :title, String
24
- end
25
-
26
- configuration.relation(:people) do
27
- schema(infer: true) do
28
- associations do
29
- has_many :todos
30
- end
31
- end
32
- end
33
-
34
- configuration.relation(:projects) do
35
- schema(infer: true) do
36
- associations do
37
- has_many :todos
38
- end
39
- end
40
- end
41
-
42
- configuration.relation(:todos) do
43
- schema(infer: true) do
44
- associations do
45
- belongs_to :people, as: :user
46
- belongs_to :projects, as: :project
47
- end
48
- end
49
- end
50
- end
51
-
52
- let(:user_repo) do
53
- Class.new(ROM::Repository[:people]) { commands :create }.new(rom)
54
- end
55
-
56
- let(:project_repo) do
57
- Class.new(ROM::Repository[:projects]) { commands :create }.new(rom)
58
- end
59
-
60
- let(:task_repo) do
61
- Class.new(ROM::Repository[:todos]) { commands :create }.new(rom)
62
- end
63
-
64
- context 'with Create' do
65
- let(:jane) do
66
- user_repo.create(name: 'Jane')
67
- end
68
-
69
- let(:project) do
70
- project_repo.create(name: 'rom-rb')
71
- end
72
-
73
- it 'associates child with parent' do
74
- changeset = task_repo.changeset(title: 'Test 1').associate(jane, :user)
75
-
76
- expect(changeset.commit).to include(user_id: jane.id, title: 'Test 1')
77
- end
78
-
79
- it 'associates child with multiple parents' do
80
- changeset = task_repo.changeset(title: 'Test 1').
81
- associate(jane, :user).
82
- associate(project)
83
-
84
- expect(changeset.commit).
85
- to include(user_id: jane.id, project_id: project.id, title: 'Test 1')
86
- end
87
-
88
- it 'raises when assoc name cannot be inferred' do
89
- other = Class.new do
90
- def self.schema
91
- []
92
- end
93
- end.new
94
-
95
- expect { task_repo.changeset(title: 'Test 1').associate(other) }.
96
- to raise_error(ArgumentError, /can't infer association name for/)
97
- end
98
- end
99
-
100
- context 'with Update' do
101
- let!(:john) do
102
- user_repo.create(name: 'John')
103
- end
104
-
105
- let!(:jane) do
106
- user_repo.create(name: 'Jane')
107
- end
108
-
109
- let!(:task) do
110
- task_repo.create(title: 'Test 1', user_id: john.id)
111
- end
112
-
113
- it 'associates child with parent' do
114
- changeset = task_repo.changeset(task.id, title: 'Test 2')
115
-
116
- expect(changeset.associate(jane, :user).commit).
117
- to include(user_id: jane.id, title: 'Test 2')
118
- end
119
- end
120
- end