rom-repository 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +10 -1
- data/lib/rom/repository/changeset.rb +1 -1
- data/lib/rom/repository/changeset/delete.rb +4 -0
- data/lib/rom/repository/changeset/restricted.rb +14 -0
- data/lib/rom/repository/changeset/stateful.rb +1 -1
- data/lib/rom/repository/changeset/update.rb +4 -0
- data/lib/rom/repository/version.rb +1 -1
- data/spec/unit/changeset_spec.rb +20 -0
- data/spec/unit/repository/changeset_spec.rb +10 -5
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6b048642fe2a94616f34fd16f97f14c66ef9d09
|
4
|
+
data.tar.gz: f5d68af52ed2f23e95f0b374c6dd8ec6c0fba51a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54fdd9a7b04880a7e3d3b9cdcaaf4794921bbfc9fe1fe95a6807b18e9c5d025cc295c86f8f4afb7f43a25939ef04bb665dfeeef84c768eb6b2d4037619b826d5
|
7
|
+
data.tar.gz: d4d7fe97225798174a5d7feee644f76188f321066501d2c8b4683dcc15d37b8fad1c1aa6fd0dd186962a3094a4ee9d486c29788d0047ffe830b8b7cc1e6dc2e1
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,13 @@
|
|
1
|
-
# v1.0.
|
1
|
+
# v1.0.1 2017-01-31
|
2
|
+
|
3
|
+
### Fixed
|
4
|
+
|
5
|
+
* `Changeset::Update` creates a command with restricted relation (solnic)
|
6
|
+
* `Changeset#result` will always return `:many` for arrays and `:one` for other objects (even a custom object is used) (solnic)
|
7
|
+
|
8
|
+
[Compare v1.0.1...v1.0.1](https://github.com/rom-rb/rom-repository/compare/v1.0.0...v1.0.1)
|
9
|
+
|
10
|
+
# v1.0.0 2017-01-30
|
2
11
|
|
3
12
|
### Added
|
4
13
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'rom/repository/changeset/restricted'
|
2
|
+
|
1
3
|
module ROM
|
2
4
|
class Changeset
|
3
5
|
# Changeset specialization for delete commands
|
@@ -7,6 +9,8 @@ module ROM
|
|
7
9
|
#
|
8
10
|
# @api public
|
9
11
|
class Delete < Changeset
|
12
|
+
include Restricted
|
13
|
+
|
10
14
|
command_type :delete
|
11
15
|
end
|
12
16
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'rom/repository/changeset/restricted'
|
2
|
+
|
1
3
|
module ROM
|
2
4
|
class Changeset
|
3
5
|
# Changeset specialization for update commands
|
@@ -13,6 +15,8 @@ module ROM
|
|
13
15
|
#
|
14
16
|
# @api public
|
15
17
|
class Update < Stateful
|
18
|
+
include Restricted
|
19
|
+
|
16
20
|
command_type :update
|
17
21
|
|
18
22
|
# Commit update changeset if there's a diff
|
data/spec/unit/changeset_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
1
3
|
RSpec.describe ROM::Changeset do
|
2
4
|
let(:jane) { { id: 2, name: "Jane" } }
|
3
5
|
let(:relation) { double(ROM::Relation, name: :users) }
|
@@ -120,6 +122,24 @@ RSpec.describe ROM::Changeset do
|
|
120
122
|
end
|
121
123
|
end
|
122
124
|
|
125
|
+
describe 'quacks like a custom object' do
|
126
|
+
subject(:changeset) { ROM::Changeset::Create.new(relation, __data__: data) }
|
127
|
+
|
128
|
+
let(:data) { OpenStruct.new(name: 'Jane') }
|
129
|
+
|
130
|
+
it 'delegates to its data hash' do
|
131
|
+
expect(changeset[:name]).to eql('Jane')
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'raises NoMethodError when an unknown message was sent' do
|
135
|
+
expect { changeset.not_here }.to raise_error(NoMethodError, /not_here/)
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'has correct result type' do
|
139
|
+
expect(changeset.result).to be(:one)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
123
143
|
describe '#inspect' do
|
124
144
|
context 'with a stateful changeset' do
|
125
145
|
subject(:changeset) { ROM::Changeset::Create.new(relation).data(name: 'Jane') }
|
@@ -54,10 +54,14 @@ RSpec.describe ROM::Repository, '#changeset' do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
shared_context 'a valid update changeset' do
|
57
|
-
let(:
|
57
|
+
let!(:jane) do
|
58
58
|
repo.command(:create, repo.users).call(name: 'Jane')
|
59
59
|
end
|
60
60
|
|
61
|
+
let!(:joe) do
|
62
|
+
repo.command(:create, repo.users).call(name: 'Joe')
|
63
|
+
end
|
64
|
+
|
61
65
|
it 'has data' do
|
62
66
|
expect(changeset.to_h).to eql(name: 'Jane Doe')
|
63
67
|
end
|
@@ -67,17 +71,18 @@ RSpec.describe ROM::Repository, '#changeset' do
|
|
67
71
|
end
|
68
72
|
|
69
73
|
it 'has relation' do
|
70
|
-
expect(changeset.relation.one).to eql(repo.users.by_pk(
|
74
|
+
expect(changeset.relation.one).to eql(repo.users.by_pk(jane[:id]).one)
|
71
75
|
end
|
72
76
|
|
73
|
-
it 'can
|
77
|
+
it 'can be commited' do
|
74
78
|
expect(changeset.commit).to eql(id: 1, name: 'Jane Doe')
|
79
|
+
expect(repo.users.by_pk(joe[:id]).one).to eql(joe)
|
75
80
|
end
|
76
81
|
end
|
77
82
|
|
78
83
|
context 'using PK to restrict a relation' do
|
79
84
|
let(:changeset) do
|
80
|
-
repo.changeset(:users,
|
85
|
+
repo.changeset(:users, jane[:id], data)
|
81
86
|
end
|
82
87
|
|
83
88
|
include_context 'a valid update changeset'
|
@@ -85,7 +90,7 @@ RSpec.describe ROM::Repository, '#changeset' do
|
|
85
90
|
|
86
91
|
context 'using custom relation' do
|
87
92
|
let(:changeset) do
|
88
|
-
repo.changeset(update: repo.users.by_pk(
|
93
|
+
repo.changeset(update: repo.users.by_pk(jane[:id])).data(data)
|
89
94
|
end
|
90
95
|
|
91
96
|
include_context 'a valid update changeset'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rom-repository
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rom
|
@@ -123,6 +123,7 @@ files:
|
|
123
123
|
- lib/rom/repository/changeset/create.rb
|
124
124
|
- lib/rom/repository/changeset/delete.rb
|
125
125
|
- lib/rom/repository/changeset/pipe.rb
|
126
|
+
- lib/rom/repository/changeset/restricted.rb
|
126
127
|
- lib/rom/repository/changeset/stateful.rb
|
127
128
|
- lib/rom/repository/changeset/update.rb
|
128
129
|
- lib/rom/repository/class_interface.rb
|