tradesman 1.0.3 → 1.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 11e364aa8aa559b1fde2cc8dbe60a017ceae2b99
4
- data.tar.gz: 490d82d0fdd65109eb01f8a1a3a6d9f0282029c2
3
+ metadata.gz: 10813cc7d5e09a97feaeeafd533d659bcecbfb90
4
+ data.tar.gz: b43ef980ddba913bd45345334a39aee135bd333f
5
5
  SHA512:
6
- metadata.gz: d6924c2f37b47fefe39b121951b52407d7f8a7251e931a5207b2d6c8df6be6c297f0b7c1f5395f12f0211c53d31edbac90e8b41979f61893d95be67cc01b4db7
7
- data.tar.gz: 635b74cfa73a87ae22900419d71d11c0c7c1110468079f39087cda3b25b3d5008c3e9e269253bf7a3a8ba8d374111aaa4da3747e843c565e62db9cafce844637
6
+ metadata.gz: 3dc5fad716ab91b6b8f7503ff3617987841afdb44a6da420f293e50d05d154d482791ae7a046f076a195ba195a2995a0d4f63508f2b9b900c8fcb5c4bc4f2eca
7
+ data.tar.gz: 879af35ef09b7e5058e134c6436e3fd6cc2d621ac8d9f370d773f13e3ebbe47fde8819bca6dcf19a728d7aaeab7c4b01bc9d44c3f10ef2ba06ab910ca5bc93c9
data/README.md CHANGED
@@ -52,6 +52,9 @@ Tradesman::CreateUserForEmployer.go(employer, [user_params, user_params, user_pa
52
52
  # Update multiple records with 1 set of parameters
53
53
  Tradesman::UpdateUser.go([user1, user2, user3], update_params)
54
54
 
55
+ # Update multiple records based on a query hash
56
+ Tradesman::UpdateUser.go({ first_name: 'Blake' }, update_params)
57
+
55
58
  # Update n records with n sets of parameters
56
59
  update_params = {
57
60
  user1.id => user1_params,
@@ -63,6 +66,9 @@ Tradesman::UpdateUser.go(update_params.keys, update_params.values)
63
66
 
64
67
  # Delete multiple records
65
68
  Tradesman::DeleteUser.go([id1, id2, id3])
69
+
70
+ # Delete multiple records based on a query hash
71
+ Tradesman::DeleteUser.go(first_name: 'Blake')
66
72
  ```
67
73
 
68
74
  ## Parsing Rules
@@ -19,7 +19,8 @@ module Tradesman
19
19
  end
20
20
 
21
21
  def prepare_ids(obj)
22
- return id_from_obj(obj) unless obj.is_a? Array
22
+ return obj if (obj.is_a?(Hash) && !obj.respond_to?(:id))
23
+ return id_from_obj(obj) unless (obj.is_a?(Array) || obj.respond_to?(:push))
23
24
  obj.map { |object| id_from_obj(object) }
24
25
  end
25
26
 
@@ -2,6 +2,11 @@ module Tradesman
2
2
  module ExistingRecordsMultipleExecute
3
3
  private
4
4
 
5
+ def query_for_ids(params)
6
+ params[:id] = self.class.adapter.find_all(conditions: params[:id]).collect &:id
7
+ params
8
+ end
9
+
5
10
  def execute_multiple(params_hash)
6
11
  params = params_hash[:params] || params_hash.except(:id)
7
12
 
@@ -6,6 +6,7 @@ module Tradesman
6
6
  extend ::Tradesman::ErrorHandling
7
7
 
8
8
  def call(params)
9
+ params = query_for_ids(params) if (params.is_a?(Hash) && params[:id] && params[:id].is_a?(Hash))
9
10
  return execute_single(params) unless (params.is_a?(Array) || params[:id].is_a?(Array) || params[:params].is_a?(Array))
10
11
  execute_multiple(params)
11
12
  rescue *self.class.expected_horza_errors_map.keys => e
@@ -14,6 +15,10 @@ module Tradesman
14
15
 
15
16
  private
16
17
 
18
+ def query_for_ids(params)
19
+ raise Tradesman::MethodNotImplemented.new('You must implement query_for_ids in a child class')
20
+ end
21
+
17
22
  def execute_single(params)
18
23
  raise Tradesman::MethodNotImplemented.new('You must implement execute_single in a child class')
19
24
  end
@@ -260,6 +260,25 @@ describe Tradesman do
260
260
  expect(results.last.last_name).to eq params.last[:last_name]
261
261
  end
262
262
  end
263
+
264
+ context 'passing query hash and single valid parameters' do
265
+ let(:query_params) { { last_name: 'Smith' } }
266
+ let(:update_params) { { last_name: 'Turner' } }
267
+ let(:other_params) { { last_name: 'Sharkasy' } }
268
+ let!(:records) { Tradesman::CreateStrictUser.go([valid_params, valid_params, valid_params]).result }
269
+ let!(:extraneous_records) { Tradesman::CreateStrictUser.go([other_params, other_params]).result }
270
+
271
+ before do
272
+ Tradesman::CreateStrictUser.go([query_params, query_params, query_params])
273
+ end
274
+ it 'updates all records that match the query' do
275
+ outcome = Tradesman::UpdateStrictUser.go(query_params, update_params)
276
+ expect(outcome.success?).to be true
277
+ expect(outcome.result.length).to eq 3
278
+ expect(outcome.result.first.last_name).to eq 'Turner'
279
+ expect(outcome.result.last.last_name).to eq 'Turner'
280
+ end
281
+ end
263
282
  end
264
283
  end
265
284
 
@@ -298,6 +317,24 @@ describe Tradesman do
298
317
  expect(outcome.result.uniq.first).to eq true
299
318
  end
300
319
  end
320
+
321
+ context 'passing query hash and single valid parameters' do
322
+ let(:query_params) { { last_name: 'Smith' } }
323
+ let(:update_params) { { last_name: 'Turner' } }
324
+ let(:records) { Tradesman::CreateStrictUser.go([valid_params, valid_params, valid_params]).result }
325
+
326
+ before do
327
+ Tradesman::CreateStrictUser.go([query_params, query_params, query_params])
328
+ end
329
+ it 'updates all records that match the query' do
330
+ outcome = Tradesman::DeleteStrictUser.go(query_params)
331
+ expect(outcome.success?).to be true
332
+ expect(outcome.result.length).to eq 3
333
+ expect(outcome.result.first).to be true
334
+ expect(outcome.result.second).to be true
335
+ expect(outcome.result.third).to be true
336
+ end
337
+ end
301
338
  end
302
339
  end
303
340
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tradesman
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Turner
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-07-01 00:00:00.000000000 Z
12
+ date: 2015-07-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: horza
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 0.3.8
20
+ version: 0.3.9
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: 0.3.8
27
+ version: 0.3.9
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: tzu
30
30
  requirement: !ruby/object:Gem::Requirement