active_remote 2.1.0.beta2 → 2.1.0.rc1

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: 6eea2bfe1e14ec6f0915d7c9bfda568a1a1974a8
4
- data.tar.gz: 184a79d8077a63773de1e3d2c9e8b9238382d6bc
3
+ metadata.gz: 9db0dc04521916e66ca566f9ece9b5f0cc8e803e
4
+ data.tar.gz: aea18e2d9200b988918570898a95fb0a47ed15aa
5
5
  SHA512:
6
- metadata.gz: 02647968d80f3be1942b2dde24f9594003fda337403cda22e3054d5ec385c735b80dffb5afd6e3ae129ca22e71abb74ea17bc4c6a55780250657ed7f1e891e63
7
- data.tar.gz: 98d5289e8ed50bc6cd0fc5e2d8394bb043f806985ea1718bda9854a88e6ff1c962f27dd6aa6e9bc274196e7a705e1b8989701357fbf87d7da4fdedd0f330cd3a
6
+ metadata.gz: bead40af9673772592780b3a7b62252815fcd0805e2988a5d7d4b6f9d2a3eb32975e3fd2b50f1937096d32c1c053ae5ff8567959861f5c87aeac01cdd27b0b57
7
+ data.tar.gz: 56d7903986b4bbb33a3c703a833441d44dd76210a560bb48c9e12d72ac9fff3da23276ba3958752d4b8a8b30507f0c44185c4a57fa289c3fbf89dc20698ce330
@@ -32,8 +32,13 @@ module ActiveRemote
32
32
  # Tag.create_all(Generic::Remote::Tags.new(:records => [ Generic::Remote::Tag.new(:name => 'foo') ])
33
33
  #
34
34
  def create_all(*records)
35
- response = rpc.execute(:create_all, parse_records(records))
36
- serialize_records(response.records) if response.respond_to?(:records)
35
+ response = rpc.execute(:create_all, _parse_records(records))
36
+
37
+ if response.respond_to?(:records)
38
+ serialize_records(response.records)
39
+ else
40
+ warn "DEPRECATED responses to bulk methods must respond to :records. In Active Remote 3.0, bulk responses that don't respond to :records will raise an exception"
41
+ end
37
42
  end
38
43
 
39
44
  # Delete multiple records at the same time. Returns a collection of active
@@ -58,8 +63,13 @@ module ActiveRemote
58
63
  # Tag.delete_all(Generic::Remote::Tags.new(:records => [ Generic::Remote::Tag.new(:guid => 'foo') ])
59
64
  #
60
65
  def delete_all(*records)
61
- response = rpc.execute(:delete_all, parse_records(records))
62
- serialize_records(response.records) if response.respond_to?(:records)
66
+ response = rpc.execute(:delete_all, _parse_records(records))
67
+
68
+ if response.respond_to?(:records)
69
+ serialize_records(response.records)
70
+ else
71
+ warn "DEPRECATED responses to bulk methods must respond to :records. In Active Remote 3.0, bulk responses that don't respond to :records will raise an exception"
72
+ end
63
73
  end
64
74
 
65
75
  # Destroy multiple records at the same time. Returns a collection of active
@@ -84,8 +94,13 @@ module ActiveRemote
84
94
  # Tag.destroy_all(Generic::Remote::Tags.new(:records => [ Generic::Remote::Tag.new(:guid => 'foo') ])
85
95
  #
86
96
  def destroy_all(*records)
87
- response = rpc.execute(:destroy_all, parse_records(records))
88
- serialize_records(response.records) if response.respond_to?(:records)
97
+ response = rpc.execute(:destroy_all, _parse_records(records))
98
+
99
+ if response.respond_to?(:records)
100
+ serialize_records(response.records)
101
+ else
102
+ warn "DEPRECATED responses to bulk methods must respond to :records. In Active Remote 3.0, bulk responses that don't respond to :records will raise an exception"
103
+ end
89
104
  end
90
105
 
91
106
  # Parse given records to get them ready to be built into a request.
@@ -96,18 +111,9 @@ module ActiveRemote
96
111
  # Returns +{ :records => records }+.
97
112
  #
98
113
  def parse_records(*records)
99
- records.flatten!
114
+ warn "DEPRECATED Model.parse_records is deprecated. It will be removed in Active Remove 3.0"
100
115
 
101
- if records.first.respond_to?(:attributes)
102
- records.collect!(&:attributes)
103
- else
104
- records.collect!(&:to_hash)
105
- end
106
-
107
- return records.first if records.first && records.first.has_key?(:records)
108
-
109
- # If we made it this far, build a bulk-formatted hash.
110
- return { :records => records }
116
+ _parse_records(*records)
111
117
  end
112
118
 
113
119
  # Update multiple records at the same time. Returns a collection of active
@@ -132,8 +138,30 @@ module ActiveRemote
132
138
  # Tag.update_all(Generic::Remote::Tags.new(:records => [ Generic::Remote::Tag.new(:guid => 'foo', :name => 'baz') ])
133
139
  #
134
140
  def update_all(*records)
135
- response = rpc.execute(:update_all, parse_records(records))
136
- serialize_records(response.records) if response.respond_to?(:records)
141
+ response = rpc.execute(:update_all, _parse_records(records))
142
+
143
+ if response.respond_to?(:records)
144
+ serialize_records(response.records)
145
+ else
146
+ warn "DEPRECATED responses to bulk methods must respond to :records. In Active Remote 3.0, bulk responses that don't respond to :records will raise an exception"
147
+ end
148
+ end
149
+
150
+ private
151
+
152
+ def _parse_records(*records)
153
+ records.flatten!
154
+
155
+ if records.first.respond_to?(:attributes)
156
+ records.collect!(&:attributes)
157
+ else
158
+ records.collect!(&:to_hash)
159
+ end
160
+
161
+ return records.first if records.first && records.first.has_key?(:records)
162
+
163
+ # If we made it this far, build a bulk-formatted hash.
164
+ return { :records => records }
137
165
  end
138
166
  end
139
167
  end
@@ -78,8 +78,7 @@ module ActiveRemote
78
78
  raise ReadOnlyRemoteRecord if readonly?
79
79
  response = rpc.execute(:delete, scope_key_hash)
80
80
 
81
- # TODO: add errors here so success? actually does something...
82
- # add_errors(response.errors)
81
+ add_errors(response.errors)
83
82
 
84
83
  return success? ? freeze : false
85
84
  end
@@ -102,10 +101,9 @@ module ActiveRemote
102
101
  #
103
102
  def destroy
104
103
  raise ReadOnlyRemoteRecord if readonly?
105
- response = execute(:destroy, scope_key_hash)
104
+ response = rpc.execute(:destroy, scope_key_hash)
106
105
 
107
- # TODO: add errors here so success? actually does something...
108
- # add_errors(response.errors)
106
+ add_errors(response.errors)
109
107
 
110
108
  return success? ? freeze : false
111
109
  end
@@ -9,8 +9,6 @@ module ActiveRemote
9
9
  include Embedded
10
10
  end
11
11
 
12
- # TODO: Deprecate this pattern of executing RPC calls
13
- #
14
12
  module Embedded
15
13
  extend ActiveSupport::Concern
16
14
 
@@ -19,11 +17,10 @@ module ActiveRemote
19
17
  end
20
18
 
21
19
  module ClassMethods
22
- # Return a protobuf request object for the given rpc request.
23
- #
24
- # TODO: Add deprecation warning
25
- #
20
+ # :noapi:
26
21
  def request(rpc_method, request_args)
22
+ warn "DEPRECATED Model.request is deprecated and will be removed in Active Remote 3.0. This is handled by the Protobuf RPC adpater now"
23
+
27
24
  return request_args unless request_args.is_a?(Hash)
28
25
 
29
26
  message_class = request_type(rpc_method)
@@ -31,20 +28,18 @@ module ActiveRemote
31
28
  message_class.new(fields)
32
29
  end
33
30
 
34
- # Return the class applicable to the request for the given rpc method.
35
- #
36
- # TODO: Add deprecation warning
37
- #
31
+ # :noapi:
38
32
  def request_type(rpc_method)
33
+ warn "DEPRECATED Model.request_type is deprecated and will be removed in Active Remote 3.0. This is handled by the Protobuf RPC adpater now"
34
+
39
35
  service_class.rpcs[rpc_method].request_type
40
36
  end
41
37
  end
42
38
 
43
- # Invoke an RPC call to the service for the given rpc method.
44
- #
45
- # TODO: Add deprecation warning
46
- #
39
+ # :noapi:
47
40
  def execute(rpc_method, request_args)
41
+ warn "DEPRECATED Model#execute is deprecated and will be removed in Active Remote 3.0. Use Model#rpc.execute instead"
42
+
48
43
  @last_request = request(rpc_method, request_args)
49
44
 
50
45
  _service_class.client.__send__(rpc_method, @last_request) do |c|
@@ -63,22 +58,19 @@ module ActiveRemote
63
58
  @last_response
64
59
  end
65
60
 
66
-
67
- # Execute an RPC call to the remote service and return the raw response.
68
- #
69
- # TODO: Add deprecation warning
70
- #
61
+ # :noapi:
71
62
  def remote_call(rpc_method, request_args)
63
+ warn "DEPRECATED Model#remote_call is deprecated and will be removed in Active Remote 3.0. Use Model#rpc.execute instead"
64
+
72
65
  rpc.execute(rpc_method, request_args)
73
66
  end
74
67
 
75
68
  private
76
69
 
77
- # Return a protobuf request object for the given rpc call.
78
- #
79
- # TODO: Add deprecation warning
80
- #
70
+ # :noapi:
81
71
  def request(rpc_method, attributes)
72
+ warn "DEPRECATED Model#request is deprecated and will be removed in Active Remote 3.0. This is handled by the Protobuf RPC adpater now"
73
+
82
74
  self.class.request(rpc_method, attributes)
83
75
  end
84
76
  end
@@ -14,6 +14,13 @@ module ActiveRemote
14
14
 
15
15
  module ClassMethods
16
16
 
17
+ # :noapi:
18
+ def _active_remote_search_args(args)
19
+ warn "DEPRECATED Model._active_remote_search_args is depracted and will be remoted in Active Remote 3.0."
20
+
21
+ validate_search_args!(args)
22
+ end
23
+
17
24
  # Tries to load the first record; if it fails, an exception is raised.
18
25
  #
19
26
  # ====Examples
@@ -89,7 +96,7 @@ module ActiveRemote
89
96
  # Tag.search(Generic::Remote::TagRequest.new(:name => 'foo'))
90
97
  #
91
98
  def search(args)
92
- args = _active_remote_search_args(args)
99
+ args = validate_search_args!(args)
93
100
 
94
101
  response = rpc.execute(:search, args)
95
102
 
@@ -99,13 +106,15 @@ module ActiveRemote
99
106
  end
100
107
  end
101
108
 
102
- # :noapi:
103
- def _active_remote_search_args(args)
109
+ # Validates the given args to ensure they are compatible
110
+ # Search args must be a hash or respond to to_hash
111
+ #
112
+ def validate_search_args!(args)
104
113
  unless args.is_a?(Hash)
105
114
  if args.respond_to?(:to_hash)
106
115
  args = args.to_hash
107
116
  else
108
- raise "Invalid parameter: #{args}. First parameter must respond to :to_hash."
117
+ raise "Invalid parameter: #{args}. Search args must respond to :to_hash."
109
118
  end
110
119
  end
111
120
 
@@ -113,11 +122,10 @@ module ActiveRemote
113
122
  end
114
123
  end
115
124
 
116
- # Search for the given resource. Auto-paginates (i.e. continues searching
117
- # for records matching the given search args until all records have been
118
- # retrieved) if no pagination options are given.
119
- #
125
+ # :noapi:
120
126
  def _active_remote_search(args)
127
+ warn "DEPRECATED Model#_active_remote_search is depracted and will be remoted in Active Remote 3.0."
128
+
121
129
  run_callbacks :search do
122
130
  rpc.execute(:search, args)
123
131
  end
@@ -46,7 +46,7 @@ module ActiveRemote
46
46
  # DEPRECATED – Use :add_errors instead
47
47
  #
48
48
  def add_errors_from_response(response = nil)
49
- warn 'DEPRECATED :add_errors_from_response is deprecated and will be removed in Active Remote 3.0. Use :add_errors instead'
49
+ warn 'DEPRECATED Model#add_errors_from_response is deprecated and will be removed in Active Remote 3.0. Use Model#add_errors instead'
50
50
 
51
51
  response ||= last_response
52
52
 
@@ -56,7 +56,7 @@ module ActiveRemote
56
56
  # DEPRECATED – Use the class-level :serialize_errors instead
57
57
  #
58
58
  def serialize_records(records = nil)
59
- warn 'DEPRECATED Calling :serialize_records on an instance is deprecated and will be removed in Active Remote 3.0. Use the class-level :serialize_records instead'
59
+ warn 'DEPRECATED Calling Model#serialize_records is deprecated and will be removed in Active Remote 3.0. Use Model.serialize_records instead'
60
60
 
61
61
  records ||= last_response.records if last_response.respond_to?(:records)
62
62
  return if records.nil?
@@ -1,3 +1,3 @@
1
1
  module ActiveRemote
2
- VERSION = "2.1.0.beta2"
2
+ VERSION = "2.1.0.rc1"
3
3
  end
@@ -1,79 +1,69 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ActiveRemote::Bulk do
4
- let(:records) { double(:records, :to_hash => {}) }
5
- let(:serialized_records) { double(:serialized_records) }
6
-
7
- describe ".create_all" do
8
- before { Tag.better_stub(:parse_records).and_return(records) }
9
-
10
- it "creates remote records" do
11
- Tag.rpc.better_receive(:execute).with(:create_all, records)
12
- Tag.create_all(records)
13
- end
14
- end
15
-
16
- describe ".delete_all" do
17
- before { Tag.better_stub(:parse_records).and_return(records) }
4
+ shared_examples_for "a bulk method" do |bulk_method|
5
+ let(:records) { [ Hash.new ] }
6
+ let(:response) { double(:response, :records => []) }
18
7
 
19
- it "deletes remote records" do
20
- Tag.rpc.better_receive(:execute).with(:delete_all, records)
21
- Tag.delete_all(records)
22
- end
23
- end
8
+ before { Tag.rpc.better_stub(:execute).and_return(response) }
24
9
 
25
- describe ".destroy_all" do
26
- before { Tag.better_stub(:parse_records).and_return(records) }
10
+ context "given an empty array" do
11
+ let(:parsed_records) { { :records => records } }
12
+ let(:records) { [] }
27
13
 
28
- it "destroys remote records" do
29
- Tag.rpc.better_receive(:execute).with(:destroy_all, records)
30
- Tag.destroy_all(records)
14
+ it "calls #{bulk_method} with parsed records" do
15
+ Tag.rpc.better_receive(:execute).with(bulk_method, parsed_records)
16
+ Tag.__send__(bulk_method, records)
17
+ end
31
18
  end
32
- end
33
19
 
34
- describe ".parse_records" do
35
- let(:records) { [ Hash.new ] }
36
- let(:empty_records) { [] }
37
- let(:attribute_record) {
38
- record = double(Hash)
39
- record.stub(:attributes) { {} }
40
- record
41
- }
20
+ context "given an array of record hashes" do
21
+ let(:hash_record){ double(:record, :to_hash => {}) }
22
+ let(:parsed_records) { { :records => records.map(&:to_hash) } }
23
+ let(:records) { [ hash_record ] }
42
24
 
43
- it "returns an empty array when given empty records" do
44
- parsed_records = { :records => [] }
45
- Tag.parse_records(empty_records).should eq(parsed_records)
25
+ it "calls #{bulk_method} with parsed records" do
26
+ Tag.rpc.better_receive(:execute).with(bulk_method, parsed_records)
27
+ Tag.__send__(bulk_method, records)
28
+ end
46
29
  end
47
30
 
48
- it "preps records to be built into a bulk request" do
49
- parsed_records = { :records => records }
50
- Tag.parse_records(records).should eq parsed_records
51
- end
31
+ context "given an array of remote records" do
32
+ let(:parsed_records) { { :records => records.map(&:attributes) } }
33
+ let(:records) { [ remote_record ] }
34
+ let(:remote_record) { double(:remote, :attributes => {}) }
52
35
 
53
- it "preps records to be built into a bulk request (prioritizing :attributes over :to_hash)" do
54
- attribute_record.should_receive(:attributes)
55
- parsed_records = { :records => [ {} ] }
56
- Tag.parse_records([ attribute_record ]).should eq parsed_records
36
+ it "calls #{bulk_method} with parsed records" do
37
+ Tag.rpc.better_receive(:execute).with(bulk_method, parsed_records)
38
+ Tag.__send__(bulk_method, records)
39
+ end
57
40
  end
58
41
 
59
- context "when given a bulk message" do
60
- let(:records) { [ tag.to_hash ] }
42
+ context "given a bulk message" do
43
+ let(:parsed_records) { { :records => records.map(&:to_hash) } }
61
44
  let(:tag) { Generic::Remote::Tag.new }
62
45
  let(:tags) { Generic::Remote::Tags.new(:records => [ tag ]) }
63
46
 
64
- it "preps records to be built into a bulk request" do
65
- parsed_records = { :records => records }
66
- Tag.parse_records(tags).should eq parsed_records
47
+ it "calls #{bulk_method} with parsed records" do
48
+ Tag.rpc.better_receive(:execute).with(bulk_method, parsed_records)
49
+ Tag.__send__(bulk_method, tags)
67
50
  end
68
51
  end
69
52
  end
70
53
 
71
- describe ".update_all" do
72
- before { Tag.stub(:parse_records).and_return(records) }
54
+ describe ".create_all" do
55
+ it_behaves_like "a bulk method", :create_all
56
+ end
73
57
 
74
- it "updates remote records" do
75
- Tag.rpc.better_receive(:execute).with(:update_all, records)
76
- Tag.update_all(records)
77
- end
58
+ describe ".delete_all" do
59
+ it_behaves_like "a bulk method", :delete_all
60
+ end
61
+
62
+ describe ".destroy_all" do
63
+ it_behaves_like "a bulk method", :destroy_all
64
+ end
65
+
66
+ describe ".update_all" do
67
+ it_behaves_like "a bulk method", :update_all
78
68
  end
79
69
  end
@@ -57,16 +57,21 @@ describe ActiveRemote::Persistence do
57
57
  end
58
58
  end
59
59
 
60
- # TODO: This spec passes, but the implementation does not actually work.
61
- # Uncomment it once the implementation is correct.
62
- #
63
- # context "when the record has errors" do
64
- # before { subject.stub(:has_errors?).and_return(true) }
65
- #
66
- # it "returns false" do
67
- # subject.delete.should be_false
68
- # end
69
- # end
60
+ context "when the response has errors" do
61
+ let(:error) { Generic::Error.new(:field => 'name', :message => 'Boom!') }
62
+ let(:response) { Generic::Remote::Tag.new(:errors => [ error ]) }
63
+
64
+ before { rpc.better_stub(:execute).and_return(response) }
65
+
66
+ it "adds the errors to the record" do
67
+ subject.delete
68
+ subject.has_errors?.should be_true
69
+ end
70
+
71
+ it "returns false" do
72
+ subject.delete.should be_false
73
+ end
74
+ end
70
75
  end
71
76
 
72
77
  describe "#delete!" do
@@ -75,25 +80,21 @@ describe ActiveRemote::Persistence do
75
80
  subject.delete!
76
81
  end
77
82
 
78
- # FIXME: This spec tests that excute raises an execption, not that an
79
- # exception is raised when an error is returned (as it should).
80
- # Uncomment it once the implementation is correct.
81
- #
82
- # context "when an error occurs" do
83
- # before { rpc.stub(:execute).and_raise(ActiveRemote::ActiveRemoteError) }
84
- #
85
- # it "raises an exception" do
86
- # expect { subject.delete! }.to raise_error(ActiveRemote::ActiveRemoteError)
87
- # end
88
- # end
83
+ context "when an error occurs" do
84
+ let(:error) { Generic::Error.new(:field => 'name', :message => 'Boom!') }
85
+ let(:response) { Generic::Remote::Tag.new(:errors => [ error ]) }
86
+
87
+ before { rpc.better_stub(:execute).and_return(response) }
88
+
89
+ it "raises an exception" do
90
+ expect { subject.delete! }.to raise_error(ActiveRemote::ActiveRemoteError)
91
+ end
92
+ end
89
93
  end
90
94
 
91
95
  describe "#destroy" do
92
- before { subject.stub(:execute) }
93
- after { subject.unstub(:execute) }
94
-
95
96
  it "destroys a remote record" do
96
- subject.should_receive(:execute).with(:destroy, subject.scope_key_hash)
97
+ rpc.should_receive(:execute).with(:destroy, subject.scope_key_hash)
97
98
  subject.destroy
98
99
  end
99
100
 
@@ -104,35 +105,39 @@ describe ActiveRemote::Persistence do
104
105
  end
105
106
  end
106
107
 
107
- # TODO: This spec passes, but the implementation does not actually work.
108
- # Uncomment it once the implementation is correct.
109
- #
110
- # context "when the record has errors" do
111
- # before { subject.stub(:has_errors?).and_return(true) }
112
- #
113
- # it "returns false" do
114
- # subject.destroy.should be_false
115
- # end
116
- # end
108
+ context "when the response has errors" do
109
+ let(:error) { Generic::Error.new(:field => 'name', :message => 'Boom!') }
110
+ let(:response) { Generic::Remote::Tag.new(:errors => [ error ]) }
111
+
112
+ before { rpc.better_stub(:execute).and_return(response) }
113
+
114
+ it "adds the errors to the record" do
115
+ subject.destroy
116
+ subject.has_errors?.should be_true
117
+ end
118
+
119
+ it "returns false" do
120
+ subject.destroy.should be_false
121
+ end
122
+ end
117
123
  end
118
124
 
119
125
  describe "#destroy!" do
120
126
  it "destroys a remote record" do
121
- subject.should_receive(:execute).with(:destroy, subject.attributes.slice("guid"))
127
+ rpc.should_receive(:execute).with(:destroy, subject.scope_key_hash)
122
128
  subject.destroy!
123
129
  end
124
130
 
125
- # FIXME: This spec tests that excute raises an execption, not that an
126
- # exception is raised when an error is returned (as it should).
127
- # Uncomment it once the implementation is correct.
128
- #
129
- # context "when an error occurs" do
130
- # before { subject.stub(:execute).and_raise(ActiveRemote::ActiveRemoteError) }
131
- #
132
- # it "raises an exception" do
133
- # expect { subject.destroy! }.to raise_error(ActiveRemote::ActiveRemoteError)
134
- # end
135
- # end
131
+ context "when an error occurs" do
132
+ let(:error) { Generic::Error.new(:field => 'name', :message => 'Boom!') }
133
+ let(:response) { Generic::Remote::Tag.new(:errors => [ error ]) }
134
+
135
+ before { rpc.better_stub(:execute).and_return(response) }
136
+
137
+ it "raises an exception" do
138
+ expect { subject.destroy! }.to raise_error(ActiveRemote::ActiveRemoteError)
139
+ end
140
+ end
136
141
  end
137
142
 
138
143
  describe "#readonly?" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_remote
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0.beta2
4
+ version: 2.1.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Hutchison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-10 00:00:00.000000000 Z
11
+ date: 2014-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_attr