active_remote 2.1.1 → 2.2.0
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 +4 -4
- data/active_remote.gemspec +2 -1
- data/lib/active_remote/base.rb +5 -0
- data/lib/active_remote/errors.rb +11 -0
- data/lib/active_remote/persistence.rb +6 -6
- data/lib/active_remote/validations.rb +64 -0
- data/lib/active_remote/version.rb +1 -1
- data/spec/lib/active_remote/association_spec.rb +54 -54
- data/spec/lib/active_remote/base_spec.rb +1 -1
- data/spec/lib/active_remote/dirty_spec.rb +9 -9
- data/spec/lib/active_remote/dsl_spec.rb +6 -6
- data/spec/lib/active_remote/integration_spec.rb +10 -10
- data/spec/lib/active_remote/persistence_spec.rb +53 -53
- data/spec/lib/active_remote/primary_key_spec.rb +4 -4
- data/spec/lib/active_remote/publication_spec.rb +1 -1
- data/spec/lib/active_remote/rpc_spec.rb +9 -9
- data/spec/lib/active_remote/scope_keys_spec.rb +4 -4
- data/spec/lib/active_remote/search_spec.rb +10 -10
- data/spec/lib/active_remote/serialization_spec.rb +2 -2
- data/spec/lib/active_remote/serializers/json_spec.rb +7 -7
- data/spec/lib/active_remote/serializers/protobuf_spec.rb +5 -5
- data/spec/lib/active_remote/validations_spec.rb +56 -0
- data/spec/support/models/post.rb +2 -0
- metadata +21 -4
@@ -12,7 +12,7 @@ describe ActiveRemote::Publication do
|
|
12
12
|
after { reset_publishable_attributes(Tag) }
|
13
13
|
|
14
14
|
it "serializes to a hash with only the publishable attributes" do
|
15
|
-
subject.publishable_hash.
|
15
|
+
expect(subject.publishable_hash).to eq expected_hash
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -13,13 +13,13 @@ describe ActiveRemote::RPC do
|
|
13
13
|
before { ::Tag.better_stub(:rpc).and_return(rpc) }
|
14
14
|
|
15
15
|
it "calls the given RPC method" do
|
16
|
-
Tag.rpc.
|
16
|
+
expect(Tag.rpc).to receive(:execute).with(:remote_method, args)
|
17
17
|
Tag.remote_call(:remote_method, args)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "returns the response" do
|
21
|
-
Tag.rpc.
|
22
|
-
Tag.remote_call(:remote_method, args).
|
21
|
+
allow(Tag.rpc).to receive(:execute).and_return(response)
|
22
|
+
expect(Tag.remote_call(:remote_method, args)).to eq response
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -27,13 +27,13 @@ describe ActiveRemote::RPC do
|
|
27
27
|
let(:attributes) { Hash.new }
|
28
28
|
|
29
29
|
it "builds an RPC request" do
|
30
|
-
Tag.request(:create, attributes).
|
30
|
+
expect(Tag.request(:create, attributes)).to eq Generic::Remote::Tag.new(attributes)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
describe ".request_type" do
|
35
35
|
it "fetches the request type for the given RPC method" do
|
36
|
-
Tag.request_type(:search).
|
36
|
+
expect(Tag.request_type(:search)).to eq Generic::Remote::TagRequest
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -49,7 +49,7 @@ describe ActiveRemote::RPC do
|
|
49
49
|
mock_remote_service(Tag.service_class, :create, :response => double(:to_hash => {}))
|
50
50
|
|
51
51
|
subject.execute(:create, request)
|
52
|
-
subject.last_request.
|
52
|
+
expect(subject.last_request).to eq(request)
|
53
53
|
end
|
54
54
|
|
55
55
|
context "when request args is a hash" do
|
@@ -57,12 +57,12 @@ describe ActiveRemote::RPC do
|
|
57
57
|
let(:request) { double(:request) }
|
58
58
|
|
59
59
|
before {
|
60
|
-
subject.
|
60
|
+
allow(subject).to receive(:request).and_return(request)
|
61
61
|
mock_remote_service(Tag.service_class, :create, :response => double(:to_hash => {}))
|
62
62
|
}
|
63
63
|
|
64
64
|
it "creates a request" do
|
65
|
-
subject.
|
65
|
+
expect(subject).to receive(:request).with(:create, args)
|
66
66
|
subject.execute(:create, args)
|
67
67
|
end
|
68
68
|
end
|
@@ -76,7 +76,7 @@ describe ActiveRemote::RPC do
|
|
76
76
|
|
77
77
|
it "sets the last response" do
|
78
78
|
subject.execute(:create, request)
|
79
|
-
subject.last_response.
|
79
|
+
expect(subject.last_response).to eq(success_response)
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -12,7 +12,7 @@ describe ActiveRemote::ScopeKeys do
|
|
12
12
|
|
13
13
|
it 'adds scope_key to _scope_keys' do
|
14
14
|
Tag.scope_key(key)
|
15
|
-
Tag._scope_keys.
|
15
|
+
expect(Tag._scope_keys).to eq(_scope_keys)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -20,13 +20,13 @@ describe ActiveRemote::ScopeKeys do
|
|
20
20
|
before { Tag.better_stub(:_scope_keys).and_return(_scope_keys) }
|
21
21
|
|
22
22
|
it "combines primary key with _scope_keys" do
|
23
|
-
Tag.scope_keys.
|
23
|
+
expect(Tag.scope_keys).to eq(['guid'] + _scope_keys)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
describe "#scope_keys" do
|
28
28
|
it "returns the scope keys for the class" do
|
29
|
-
Tag.new.scope_keys.
|
29
|
+
expect(Tag.new.scope_keys).to eq Tag.scope_keys
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -36,7 +36,7 @@ describe ActiveRemote::ScopeKeys do
|
|
36
36
|
before { tag.better_stub(:scope_keys).and_return(scope_keys) }
|
37
37
|
|
38
38
|
it "returns a attribute hash of scope_keys" do
|
39
|
-
tag.scope_key_hash.
|
39
|
+
expect(tag.scope_key_hash).to eq(scope_key_hash)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -10,21 +10,21 @@ describe ActiveRemote::Search do
|
|
10
10
|
let(:record) { double(:record) }
|
11
11
|
let(:records) { [ record ] }
|
12
12
|
|
13
|
-
before { Tag.
|
13
|
+
before { allow(Tag).to receive(:search).and_return(records) }
|
14
14
|
|
15
15
|
it "searches with the given args" do
|
16
|
-
Tag.
|
16
|
+
expect(Tag).to receive(:search).with(args)
|
17
17
|
Tag.find(args)
|
18
18
|
end
|
19
19
|
|
20
20
|
context "when records are returned" do
|
21
21
|
it "returns the first record" do
|
22
|
-
Tag.find(args).
|
22
|
+
expect(Tag.find(args)).to eq record
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
context "when no records are returned" do
|
27
|
-
before { Tag.
|
27
|
+
before { allow(Tag).to receive(:search).and_return([]) }
|
28
28
|
|
29
29
|
it "raise an exception" do
|
30
30
|
expect { Tag.find(args) }.to raise_error(::ActiveRemote::RemoteRecordNotFound)
|
@@ -47,12 +47,12 @@ describe ActiveRemote::Search do
|
|
47
47
|
before { ::Tag.better_stub(:rpc).and_return(rpc) }
|
48
48
|
|
49
49
|
it "searches with the given args" do
|
50
|
-
Tag.rpc.
|
50
|
+
expect(Tag.rpc).to receive(:execute).with(:search, args)
|
51
51
|
Tag.search(args)
|
52
52
|
end
|
53
53
|
|
54
54
|
it "returns records" do
|
55
|
-
Tag.search(args).
|
55
|
+
expect(Tag.search(args)).to eq serialized_records
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -71,17 +71,17 @@ describe ActiveRemote::Search do
|
|
71
71
|
subject { Tag.new }
|
72
72
|
|
73
73
|
before {
|
74
|
-
rpc.
|
74
|
+
allow(rpc).to receive(:execute).and_return(response)
|
75
75
|
Tag.better_stub(:rpc).and_return(rpc)
|
76
76
|
}
|
77
77
|
|
78
78
|
it "runs callbacks" do
|
79
|
-
subject.
|
79
|
+
expect(subject).to receive(:run_callbacks).with(:search)
|
80
80
|
subject._active_remote_search(args)
|
81
81
|
end
|
82
82
|
|
83
83
|
it "executes the search" do
|
84
|
-
rpc.
|
84
|
+
expect(rpc).to receive(:execute).with(:search, args)
|
85
85
|
subject._active_remote_search(args)
|
86
86
|
end
|
87
87
|
end
|
@@ -101,7 +101,7 @@ describe ActiveRemote::Search do
|
|
101
101
|
|
102
102
|
it "assigns new attributes" do
|
103
103
|
subject.reload
|
104
|
-
subject.attributes.
|
104
|
+
expect(subject.attributes).to eq attributes
|
105
105
|
end
|
106
106
|
end
|
107
107
|
end
|
@@ -8,7 +8,7 @@ describe ActiveRemote::Serialization do
|
|
8
8
|
|
9
9
|
it "serializes records into active remote objects" do
|
10
10
|
Tag.serialize_records(records).each do |record|
|
11
|
-
record.
|
11
|
+
expect(record).to be_a Tag
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -26,7 +26,7 @@ describe ActiveRemote::Serialization do
|
|
26
26
|
context "when the response has errors" do
|
27
27
|
it "adds the errors to the active remote object" do
|
28
28
|
subject.add_errors(response.errors)
|
29
|
-
subject.errors[:name].
|
29
|
+
expect(subject.errors[:name]).to match_array(['Boom!'])
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -10,12 +10,12 @@ describe ActiveRemote::Serializers::JSON do
|
|
10
10
|
context "with roots in json" do
|
11
11
|
context "when options are nil" do
|
12
12
|
it "substitutes an empty hash" do
|
13
|
-
subject.as_json(nil).
|
13
|
+
expect(subject.as_json(nil)).to eq serializable_attributes
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
it "accepts standard JSON options" do
|
18
|
-
subject.as_json(:root => false).
|
18
|
+
expect(subject.as_json(:root => false)).to eq attributes.stringify_keys
|
19
19
|
end
|
20
20
|
|
21
21
|
context "with publishable attributes defined" do
|
@@ -25,7 +25,7 @@ describe ActiveRemote::Serializers::JSON do
|
|
25
25
|
after { reset_publishable_attributes(Tag) }
|
26
26
|
|
27
27
|
it "serializes to JSON with only the publishable attributes" do
|
28
|
-
subject.to_json.
|
28
|
+
expect(subject.to_json).to eq expected_json
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -33,7 +33,7 @@ describe ActiveRemote::Serializers::JSON do
|
|
33
33
|
let(:expected_json) { { :tag => attributes }.to_json }
|
34
34
|
|
35
35
|
it "serializes to JSON" do
|
36
|
-
subject.to_json.
|
36
|
+
expect(subject.to_json).to eq expected_json
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -51,7 +51,7 @@ describe ActiveRemote::Serializers::JSON do
|
|
51
51
|
|
52
52
|
context "when options are nil" do
|
53
53
|
it "substitutes an empty hash" do
|
54
|
-
subject.as_json(nil).
|
54
|
+
expect(subject.as_json(nil)).to eq serializable_attributes
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -62,7 +62,7 @@ describe ActiveRemote::Serializers::JSON do
|
|
62
62
|
after { reset_publishable_attributes(Tag) }
|
63
63
|
|
64
64
|
it "serializes to JSON with only the publishable attributes" do
|
65
|
-
subject.to_json.
|
65
|
+
expect(subject.to_json).to eq expected_json
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
@@ -70,7 +70,7 @@ describe ActiveRemote::Serializers::JSON do
|
|
70
70
|
let(:expected_json) { attributes.to_json }
|
71
71
|
|
72
72
|
it "serializes to JSON" do
|
73
|
-
subject.to_json.
|
73
|
+
expect(subject.to_json).to eq expected_json
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
@@ -6,7 +6,7 @@ describe ActiveRemote::Serializers::Protobuf::Fields do
|
|
6
6
|
let(:value) { { :records => { :name => 'Cool Post', :errors => { :message => 'Boom!' } } } }
|
7
7
|
|
8
8
|
it "gets protobuf-ready fields from attributes" do
|
9
|
-
described_class.from_attributes(Generic::Remote::Posts, value).
|
9
|
+
expect(described_class.from_attributes(Generic::Remote::Posts, value)).to eq ready_value
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -21,7 +21,7 @@ describe ActiveRemote::Serializers::Protobuf::Field do
|
|
21
21
|
let(:value) { { :name => 'Cool Post', :errors => { :message => 'Boom!' } } }
|
22
22
|
|
23
23
|
it "gets protobuf-ready fields from the value" do
|
24
|
-
described_class.from_attribute(field, value).
|
24
|
+
expect(described_class.from_attribute(field, value)).to eq ready_value
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -34,7 +34,7 @@ describe ActiveRemote::Serializers::Protobuf::Field do
|
|
34
34
|
let(:value) { { :name => 'Film', :errors => { :message => 'Boom!' } } }
|
35
35
|
|
36
36
|
it "gets protobuf-ready fields from the value" do
|
37
|
-
described_class.from_attribute(field, value).
|
37
|
+
expect(described_class.from_attribute(field, value)).to eq ready_value
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -47,7 +47,7 @@ describe ActiveRemote::Serializers::Protobuf::Field do
|
|
47
47
|
let(:value) { 'Cool Post' }
|
48
48
|
|
49
49
|
it "gets protobuf-ready fields from the value" do
|
50
|
-
described_class.from_attribute(field, value).
|
50
|
+
expect(described_class.from_attribute(field, value)).to eq ready_value
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -65,7 +65,7 @@ describe ActiveRemote::Serializers::Protobuf::Field do
|
|
65
65
|
|
66
66
|
def typecasts(field, conversion)
|
67
67
|
field = Serializer.get_field(field, true)
|
68
|
-
described_class.from_attribute(field, conversion.first[0]).
|
68
|
+
expect(described_class.from_attribute(field, conversion.first[0])).to eq conversion.first[1]
|
69
69
|
end
|
70
70
|
|
71
71
|
it { typecasts(:bool_field, '0' => false) }
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveRemote::Validations do
|
4
|
+
let(:invalid_record) { ::Post.new }
|
5
|
+
let(:valid_record) { ::Post.new(:name => 'test') }
|
6
|
+
|
7
|
+
before { allow(valid_record).to receive(:create_or_update).and_return(true) }
|
8
|
+
before { allow(invalid_record).to receive(:create_or_update).and_return(true) }
|
9
|
+
|
10
|
+
describe 'save' do
|
11
|
+
context 'valid record' do
|
12
|
+
it 'returns true' do
|
13
|
+
result = valid_record.save
|
14
|
+
expect(result).to be true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'invalid record' do
|
19
|
+
it 'returns false' do
|
20
|
+
result = invalid_record.save
|
21
|
+
expect(result).to be false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'save!' do
|
27
|
+
context 'valid record' do
|
28
|
+
it 'returns true' do
|
29
|
+
result = valid_record.save!
|
30
|
+
expect(result).to be true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'invalid record' do
|
35
|
+
it 'raises invalid record error' do
|
36
|
+
expect { invalid_record.save! }.to raise_error(ActiveRemote::RemoteRecordInvalid)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'valid?' do
|
42
|
+
context 'valid record' do
|
43
|
+
it 'returns true' do
|
44
|
+
result = valid_record.valid?
|
45
|
+
expect(result).to be true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'invalid record' do
|
50
|
+
it 'returns false' do
|
51
|
+
result = invalid_record.valid?
|
52
|
+
expect(result).to be false
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/spec/support/models/post.rb
CHANGED
@@ -16,4 +16,6 @@ class Post < ::ActiveRemote::Base
|
|
16
16
|
belongs_to :coauthor, :class_name => '::Author'
|
17
17
|
belongs_to :bestseller, :class_name => '::Author', :foreign_key => :bestseller_guid
|
18
18
|
belongs_to :user, :class_name => '::Author', :scope => :user_guid
|
19
|
+
|
20
|
+
validates :name, :presence => true
|
19
21
|
end
|
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.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Hutchison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_attr
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec-its
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: rspec-pride
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,7 +123,7 @@ dependencies:
|
|
109
123
|
- !ruby/object:Gem::Version
|
110
124
|
version: '0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
|
-
name: pry
|
126
|
+
name: pry
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
114
128
|
requirements:
|
115
129
|
- - ">="
|
@@ -191,6 +205,7 @@ files:
|
|
191
205
|
- lib/active_remote/serialization.rb
|
192
206
|
- lib/active_remote/serializers/json.rb
|
193
207
|
- lib/active_remote/serializers/protobuf.rb
|
208
|
+
- lib/active_remote/validations.rb
|
194
209
|
- lib/active_remote/version.rb
|
195
210
|
- spec/core_ext/date_time_spec.rb
|
196
211
|
- spec/lib/active_remote/association_spec.rb
|
@@ -208,6 +223,7 @@ files:
|
|
208
223
|
- spec/lib/active_remote/serialization_spec.rb
|
209
224
|
- spec/lib/active_remote/serializers/json_spec.rb
|
210
225
|
- spec/lib/active_remote/serializers/protobuf_spec.rb
|
226
|
+
- spec/lib/active_remote/validations_spec.rb
|
211
227
|
- spec/spec_helper.rb
|
212
228
|
- spec/support/definitions/author.proto
|
213
229
|
- spec/support/definitions/category.proto
|
@@ -248,7 +264,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
248
264
|
version: '0'
|
249
265
|
requirements: []
|
250
266
|
rubyforge_project:
|
251
|
-
rubygems_version: 2.
|
267
|
+
rubygems_version: 2.4.6
|
252
268
|
signing_key:
|
253
269
|
specification_version: 4
|
254
270
|
summary: Active Record for your platform
|
@@ -269,6 +285,7 @@ test_files:
|
|
269
285
|
- spec/lib/active_remote/serialization_spec.rb
|
270
286
|
- spec/lib/active_remote/serializers/json_spec.rb
|
271
287
|
- spec/lib/active_remote/serializers/protobuf_spec.rb
|
288
|
+
- spec/lib/active_remote/validations_spec.rb
|
272
289
|
- spec/spec_helper.rb
|
273
290
|
- spec/support/definitions/author.proto
|
274
291
|
- spec/support/definitions/category.proto
|