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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c707538203786422c6f8a84fb4c0cc9eeb09c042
4
- data.tar.gz: c926f00d3af0cced7bf8c49cd631d0d6d8d49325
3
+ metadata.gz: e6b048642fe2a94616f34fd16f97f14c66ef9d09
4
+ data.tar.gz: f5d68af52ed2f23e95f0b374c6dd8ec6c0fba51a
5
5
  SHA512:
6
- metadata.gz: e2cd0fbb32bc8ad51c6d7c4242c74bd9ac6117630c0f3cfb7e14a08f90cb04225e82d52308d0699fe9d59e4d1c601514864c2a1f3165bd67027abfa813823710
7
- data.tar.gz: c75b062e768280c3d6a347c4608c74e372d243add19d425b1b0a98d49964c869a8b611e1e8d89f373dd698d56cb3cab1020f6f12da06d34d66e7a90f2d8144a4
6
+ metadata.gz: 54fdd9a7b04880a7e3d3b9cdcaaf4794921bbfc9fe1fe95a6807b18e9c5d025cc295c86f8f4afb7f43a25939ef04bb665dfeeef84c768eb6b2d4037619b826d5
7
+ data.tar.gz: d4d7fe97225798174a5d7feee644f76188f321066501d2c8b4683dcc15d37b8fad1c1aa6fd0dd186962a3094a4ee9d486c29788d0047ffe830b8b7cc1e6dc2e1
data/.travis.yml CHANGED
@@ -13,7 +13,7 @@ rvm:
13
13
  - 2.3
14
14
  - 2.2
15
15
  - rbx-3
16
- - jruby
16
+ - jruby-9.1.6.0
17
17
  env:
18
18
  global:
19
19
  - JRUBY_OPTS='--dev -J-Xmx1024M'
data/CHANGELOG.md CHANGED
@@ -1,4 +1,13 @@
1
- # v1.0.0 to-be-released
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
 
@@ -121,7 +121,7 @@ module ROM
121
121
  #
122
122
  # @api private
123
123
  def command
124
- command_compiler.(command_type, relation_identifier, DEFAULT_COMMAND_OPTS).new(relation)
124
+ command_compiler.(command_type, relation_identifier, DEFAULT_COMMAND_OPTS)
125
125
  end
126
126
 
127
127
  private
@@ -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
@@ -0,0 +1,14 @@
1
+ module ROM
2
+ class Changeset
3
+ module Restricted
4
+ # Return a command restricted by the changeset's relation
5
+ #
6
+ # @see Changeset#command
7
+ #
8
+ # @api private
9
+ def command
10
+ super.new(relation)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -197,7 +197,7 @@ module ROM
197
197
  #
198
198
  # @api private
199
199
  def result
200
- __data__.is_a?(Hash) ? :one : :many
200
+ __data__.is_a?(Array) ? :many : :one
201
201
  end
202
202
 
203
203
  # @api public
@@ -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
@@ -1,5 +1,5 @@
1
1
  module ROM
2
2
  class Repository
3
- VERSION = '1.0.0'.freeze
3
+ VERSION = '1.0.1'.freeze
4
4
  end
5
5
  end
@@ -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(:user) do
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(user[:id]).one)
74
+ expect(changeset.relation.one).to eql(repo.users.by_pk(jane[:id]).one)
71
75
  end
72
76
 
73
- it 'can return be commited' do
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, user[:id], data)
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(user[:id])).data(data)
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.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-29 00:00:00.000000000 Z
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