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
@@ -1,42 +0,0 @@
1
- RSpec.describe ROM::Repository, '#transaction' do
2
- let(:user_repo) do
3
- Class.new(ROM::Repository[:users]) { commands :create }.new(rom)
4
- end
5
-
6
- let(:task_repo) do
7
- Class.new(ROM::Repository[:tasks]) { commands :create, :update }.new(rom)
8
- end
9
-
10
- include_context 'database'
11
- include_context 'relations'
12
-
13
- it 'creating user with tasks' do
14
- user, task = user_repo.transaction do
15
- user_changeset = user_repo.changeset(name: 'Jane')
16
- task_changeset = task_repo.changeset(title: 'Task One')
17
-
18
- user = user_repo.create(user_changeset)
19
- task = task_repo.create(task_changeset.associate(user, :user))
20
-
21
- [user, task]
22
- end
23
-
24
- expect(user.name).to eql('Jane')
25
- expect(task.user_id).to be(user.id)
26
- expect(task.title).to eql('Task One')
27
- end
28
-
29
- it 'updating tasks user' do
30
- jane = user_repo.create(name: 'Jane')
31
- john = user_repo.create(name: 'John')
32
- task = task_repo.create(title: 'Jane Task', user_id: jane.id)
33
-
34
- task = task_repo.transaction do
35
- task_changeset = task_repo.changeset(task.id, title: 'John Task').associate(john, :user).commit
36
- task_repo.update(task_changeset)
37
- end
38
-
39
- expect(task.user_id).to be(john.id)
40
- expect(task.title).to eql('John Task')
41
- end
42
- end
@@ -1,46 +0,0 @@
1
- RSpec.describe ROM::Session do
2
- subject(:session) do
3
- ROM::Session.new(repo)
4
- end
5
-
6
- let(:repo) { instance_double(ROM::Repository) }
7
- let(:create_changeset) { instance_double(ROM::Changeset::Create, relation: relation) }
8
- let(:delete_changeset) { instance_double(ROM::Changeset::Delete, relation: relation) }
9
- let(:relation) { double.as_null_object }
10
-
11
- describe '#pending?' do
12
- it 'returns true before commit' do
13
- expect(session).to be_pending
14
- end
15
-
16
- it 'returns false after commit' do
17
- expect(session.commit!).to_not be_pending
18
- end
19
- end
20
-
21
- describe '#commit!' do
22
- it 'executes ops and restores pristine state' do
23
- expect(create_changeset).to receive(:commit).and_return(true)
24
-
25
- session.add(create_changeset).commit!
26
- session.commit!
27
-
28
- expect(session).to be_success
29
- end
30
-
31
- it 'executes ops and restores pristine state when exception was raised' do
32
- expect(create_changeset).to_not receive(:commit)
33
- expect(delete_changeset).to receive(:commit).and_raise(StandardError, 'oops')
34
-
35
- expect {
36
- session.add(delete_changeset)
37
- session.add(create_changeset)
38
- session.commit!
39
- }.to raise_error(StandardError, 'oops')
40
-
41
- expect(session).to be_failure
42
-
43
- session.commit!
44
- end
45
- end
46
- end
@@ -1,128 +0,0 @@
1
- RSpec.describe 'struct builder', '#call' do
2
- subject(:builder) { ROM::Repository::StructBuilder.new }
3
-
4
- def attr_double(name, type, **opts)
5
- double(
6
- name: name,
7
- aliased?: false,
8
- wrapped?: false,
9
- foreign_key?: false,
10
- to_read_type: ROM::Types.const_get(type),
11
- **opts
12
- )
13
- end
14
-
15
- let(:input) do
16
- [:users, [:header, [
17
- [:attribute, attr_double(:id, :Int)],
18
- [:attribute, attr_double(:name, :String)]]]]
19
- end
20
-
21
- context 'ROM::Struct' do
22
- before { builder[*input] }
23
-
24
- it 'generates a struct for a given relation name and columns' do
25
- struct = builder.class.cache[input.hash]
26
-
27
- user = struct.new(id: 1, name: 'Jane')
28
-
29
- expect(user.id).to be(1)
30
- expect(user.name).to eql('Jane')
31
-
32
- expect(user[:id]).to be(1)
33
- expect(user[:name]).to eql('Jane')
34
-
35
- expect(Hash[user]).to eql(id: 1, name: 'Jane')
36
-
37
- expect(user.inspect).to eql('#<ROM::Struct::User id=1 name="Jane">')
38
- expect(user.to_s).to match(/\A#<ROM::Struct::User:0x[0-9a-f]+>\z/)
39
- end
40
-
41
- it 'stores struct in the cache' do
42
- expect(builder.class.cache[input.hash]).to be(builder[*input])
43
- end
44
-
45
- context 'with reserved keywords as attribute names' do
46
- let(:input) do
47
- [:users, [:header, [
48
- [:attribute, attr_double(:id, :Int)],
49
- [:attribute, attr_double(:name, :String)],
50
- [:attribute, attr_double(:alias, :String)],
51
- [:attribute, attr_double(:until, :Time)]]]]
52
- end
53
-
54
- it 'allows to build a struct class without complaining' do
55
- struct = builder.class.cache[input.hash]
56
-
57
- user = struct.new(id: 1, name: 'Jane', alias: 'JD', until: Time.new(2030))
58
-
59
- expect(user.id).to be(1)
60
- expect(user.name).to eql('Jane')
61
- expect(user.alias).to eql('JD')
62
- expect(user.until).to eql(Time.new(2030))
63
- end
64
- end
65
-
66
- it 'raise a friendly error on missing keys' do
67
- struct = builder.class.cache[input.hash]
68
-
69
- expect { struct.new(id: 1) }.to raise_error(
70
- Dry::Struct::Error, /:name is missing/
71
- )
72
- end
73
- end
74
-
75
- context 'custom entity container' do
76
- before do
77
- module Test
78
- module Custom
79
- end
80
- end
81
- end
82
-
83
- let(:struct) { builder[*input] }
84
- subject(:builder) { ROM::Repository::StructBuilder.new(Test::Custom) }
85
-
86
- it 'generates a struct class inside a given module' do
87
- expect(struct.name).to eql('Test::Custom::User')
88
- user = struct.new(id: 1, name: 'Jane')
89
-
90
- expect(user.inspect).to eql(%q{#<Test::Custom::User id=1 name="Jane">})
91
- end
92
-
93
- it 'uses the existing class as a parent' do
94
- class Test::Custom::User < ROM::Struct
95
- def upcased_name
96
- name.upcase
97
- end
98
- end
99
-
100
- user = struct.new(id: 1, name: 'Jane')
101
-
102
- expect(user.upcased_name).to eql('JANE')
103
- end
104
-
105
- it 'raises a nice error on missing attributes' do
106
- class Test::Custom::User < ROM::Struct
107
- def upcased_middle_name
108
- middle_name.upcase
109
- end
110
- end
111
-
112
- user = struct.new(id: 1, name: 'Jane')
113
-
114
- expect {
115
- user.upcased_middle_name
116
- }.to raise_error(
117
- ROM::Struct::MissingAttribute,
118
- /not loaded attribute\?/
119
- )
120
- end
121
-
122
- it 'works with implicit coercions' do
123
- user = struct.new(id: 1, name: 'Jane')
124
-
125
- expect([user].flatten).to eql([user])
126
- end
127
- end
128
- end