active_remote 7.1.0 → 7.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/.rspec +1 -1
- data/.standard.yml +2 -1
- data/{CHANGES.md → CHANGELOG.md} +10 -4
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/Rakefile +13 -8
- data/lib/active_remote/association.rb +8 -13
- data/lib/active_remote/attribute_methods.rb +1 -1
- data/lib/active_remote/base.rb +2 -4
- data/lib/active_remote/dirty.rb +0 -32
- data/lib/active_remote/version.rb +1 -1
- metadata +18 -186
- data/.github/workflows/main.yml +0 -41
- data/.gitignore +0 -13
- data/Gemfile +0 -4
- data/LICENSE +0 -22
- data/active_remote.gemspec +0 -38
- data/bin/benchmark +0 -43
- data/bin/console +0 -10
- data/spec/lib/active_remote/association_spec.rb +0 -257
- data/spec/lib/active_remote/base_spec.rb +0 -10
- data/spec/lib/active_remote/dirty_spec.rb +0 -93
- data/spec/lib/active_remote/dsl_spec.rb +0 -85
- data/spec/lib/active_remote/errors_spec.rb +0 -31
- data/spec/lib/active_remote/integration_spec.rb +0 -111
- data/spec/lib/active_remote/persistence_spec.rb +0 -416
- data/spec/lib/active_remote/primary_key_spec.rb +0 -49
- data/spec/lib/active_remote/query_attribute_spec.rb +0 -43
- data/spec/lib/active_remote/rpc_adapters/protobuf_adapter_spec.rb +0 -24
- data/spec/lib/active_remote/rpc_spec.rb +0 -86
- data/spec/lib/active_remote/scope_keys_spec.rb +0 -42
- data/spec/lib/active_remote/search_spec.rb +0 -114
- data/spec/lib/active_remote/serialization_spec.rb +0 -33
- data/spec/lib/active_remote/serializers/protobuf_spec.rb +0 -89
- data/spec/lib/active_remote/validations_spec.rb +0 -56
- data/spec/spec_helper.rb +0 -29
- data/spec/support/definitions/author.proto +0 -30
- data/spec/support/definitions/category.proto +0 -33
- data/spec/support/definitions/error.proto +0 -6
- data/spec/support/definitions/post.proto +0 -35
- data/spec/support/definitions/serializer.proto +0 -23
- data/spec/support/definitions/tag.proto +0 -30
- data/spec/support/helpers.rb +0 -35
- data/spec/support/models/author.rb +0 -26
- data/spec/support/models/category.rb +0 -19
- data/spec/support/models/default_author.rb +0 -12
- data/spec/support/models/message_with_options.rb +0 -11
- data/spec/support/models/no_attributes.rb +0 -2
- data/spec/support/models/post.rb +0 -21
- data/spec/support/models/tag.rb +0 -22
- data/spec/support/models.rb +0 -7
- data/spec/support/protobuf/author.pb.rb +0 -58
- data/spec/support/protobuf/category.pb.rb +0 -61
- data/spec/support/protobuf/error.pb.rb +0 -21
- data/spec/support/protobuf/post.pb.rb +0 -63
- data/spec/support/protobuf/serializer.pb.rb +0 -36
- data/spec/support/protobuf/tag.pb.rb +0 -58
- data/spec/support/protobuf.rb +0 -5
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe ::ActiveRemote::RPC do
|
|
4
|
-
subject { ::Tag.new }
|
|
5
|
-
|
|
6
|
-
describe ".build_from_rpc" do
|
|
7
|
-
let(:new_attributes) { {name: "test"} }
|
|
8
|
-
|
|
9
|
-
it "dups the default attributes" do
|
|
10
|
-
expect { ::Tag.build_from_rpc(new_attributes).to_h }.to_not change { ::Tag._default_attributes["name"] }
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
context "missing attributes from rpc" do
|
|
14
|
-
it "initializes to nil" do
|
|
15
|
-
expect(::Tag.build_from_rpc(new_attributes).to_h).to include("guid" => nil)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
context "extra attributes from rpc" do
|
|
20
|
-
let(:new_attributes) { {foobar: "test"} }
|
|
21
|
-
|
|
22
|
-
it "ignores unknown attributes" do
|
|
23
|
-
expect(::Tag.build_from_rpc(new_attributes).to_h).to_not include("foobar" => "test")
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
context "typecasted attributes" do
|
|
28
|
-
let(:new_attributes) { {birthday: "2017-01-01"} }
|
|
29
|
-
|
|
30
|
-
it "calls the typecasters" do
|
|
31
|
-
expect(::Author.build_from_rpc(new_attributes).to_h).to include({"birthday" => "2017-01-01".to_datetime})
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
describe ".remote_call" do
|
|
37
|
-
let(:args) { double(:args) }
|
|
38
|
-
let(:response) { double(:response) }
|
|
39
|
-
|
|
40
|
-
let(:rpc) { ::ActiveRemote::RPCAdapters::ProtobufAdapter.new(::Tag.service_class, ::Tag.endpoints) }
|
|
41
|
-
|
|
42
|
-
before { allow(rpc).to receive(:execute).and_return(response) }
|
|
43
|
-
before { allow(::Tag).to receive(:rpc).and_return(rpc) }
|
|
44
|
-
|
|
45
|
-
it "calls the given RPC method" do
|
|
46
|
-
expect(::Tag.rpc).to receive(:execute).with(:remote_method, args)
|
|
47
|
-
::Tag.remote_call(:remote_method, args)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it "returns the response" do
|
|
51
|
-
allow(::Tag.rpc).to receive(:execute).and_return(response)
|
|
52
|
-
expect(::Tag.remote_call(:remote_method, args)).to eq response
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
describe "#assign_attributes_from_rpc" do
|
|
57
|
-
let(:response) { ::Generic::Remote::Tag.new(guid: tag.guid, name: "bar") }
|
|
58
|
-
let(:tag) { ::Tag.new(guid: SecureRandom.uuid) }
|
|
59
|
-
|
|
60
|
-
it "updates the attributes from the response" do
|
|
61
|
-
expect { tag.assign_attributes_from_rpc(response) }.to change { tag.name }.to(response.name)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
context "when response does not respond to errors" do
|
|
65
|
-
let(:response) { double(:response, to_hash: {}) }
|
|
66
|
-
|
|
67
|
-
it "does not add errors from the response" do
|
|
68
|
-
expect { tag.assign_attributes_from_rpc(response) }.to_not change { tag.has_errors? }
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
context "when errors are returned" do
|
|
73
|
-
let(:response) {
|
|
74
|
-
::Generic::Remote::Tag.new(
|
|
75
|
-
guid: tag.guid,
|
|
76
|
-
name: "bar",
|
|
77
|
-
errors: [{field: "name", message: "message"}]
|
|
78
|
-
)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
it "adds errors from the response" do
|
|
82
|
-
expect { tag.assign_attributes_from_rpc(response) }.to change { tag.has_errors? }.to(true)
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
end
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe ActiveRemote::ScopeKeys do
|
|
4
|
-
let(:key) { :user_guid }
|
|
5
|
-
let(:_scope_keys) { ["user_guid"] }
|
|
6
|
-
let(:scope_keys) { ["guid"] + _scope_keys }
|
|
7
|
-
let(:tag) { Tag.new(tag_hash) }
|
|
8
|
-
let(:tag_hash) { {guid: "TAG-123", user_guid: "USR-123", name: "teh tag"} }
|
|
9
|
-
|
|
10
|
-
describe ".scope_key" do
|
|
11
|
-
after { Tag._scope_keys = [] }
|
|
12
|
-
|
|
13
|
-
it "adds scope_key to _scope_keys" do
|
|
14
|
-
Tag.scope_key(key)
|
|
15
|
-
expect(Tag._scope_keys).to eq(_scope_keys)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
describe ".scope_keys" do
|
|
20
|
-
before { allow(Tag).to receive(:_scope_keys).and_return(_scope_keys) }
|
|
21
|
-
|
|
22
|
-
it "combines primary key with _scope_keys" do
|
|
23
|
-
expect(Tag.scope_keys).to eq(["guid"] + _scope_keys)
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
describe "#scope_keys" do
|
|
28
|
-
it "returns the scope keys for the class" do
|
|
29
|
-
expect(Tag.new.scope_keys).to eq Tag.scope_keys
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
describe "#scope_key_hash" do
|
|
34
|
-
let(:scope_key_hash) { {"guid" => "TAG-123", "user_guid" => "USR-123"} }
|
|
35
|
-
|
|
36
|
-
before { allow(tag).to receive(:scope_keys).and_return(scope_keys) }
|
|
37
|
-
|
|
38
|
-
it "returns a attribute hash of scope_keys" do
|
|
39
|
-
expect(tag.scope_key_hash).to eq(scope_key_hash)
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe ActiveRemote::Search do
|
|
4
|
-
let(:records) { [Generic::Remote::Tag.new(guid: "123")] }
|
|
5
|
-
let(:response) { Generic::Remote::Tags.new(records: records) }
|
|
6
|
-
let(:rpc) { double(:rpc) }
|
|
7
|
-
|
|
8
|
-
describe ".find" do
|
|
9
|
-
let(:args) { {} }
|
|
10
|
-
let(:record) { double(:record) }
|
|
11
|
-
let(:records) { [record] }
|
|
12
|
-
|
|
13
|
-
before { allow(Tag).to receive(:search).and_return(records) }
|
|
14
|
-
|
|
15
|
-
it "searches with the given args" do
|
|
16
|
-
expect(Tag).to receive(:search).with(args)
|
|
17
|
-
Tag.find(args)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
context "when records are returned" do
|
|
21
|
-
it "returns the first record" do
|
|
22
|
-
expect(Tag.find(args)).to eq record
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
context "when no records are returned" do
|
|
27
|
-
before { allow(Tag).to receive(:search).and_return([]) }
|
|
28
|
-
|
|
29
|
-
it "raise an exception" do
|
|
30
|
-
expect { Tag.find(args) }.to raise_error(::ActiveRemote::RemoteRecordNotFound)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it "gives the class of the remote record not found in the message" do
|
|
34
|
-
expect { Tag.find(args) }.to raise_error(::ActiveRemote::RemoteRecordNotFound, /Tag/)
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
describe ".find_by" do
|
|
40
|
-
let(:args) { {} }
|
|
41
|
-
let(:record) { double(:record) }
|
|
42
|
-
let(:records) { [record] }
|
|
43
|
-
|
|
44
|
-
before { allow(Tag).to receive(:search).and_return(records) }
|
|
45
|
-
|
|
46
|
-
it "searches with the given args" do
|
|
47
|
-
expect(Tag).to receive(:search).with(args)
|
|
48
|
-
Tag.find_by(args)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
context "when records are returned" do
|
|
52
|
-
it "returns the first record" do
|
|
53
|
-
expect(Tag.find_by(args)).to eq record
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
context "when no records are returned" do
|
|
58
|
-
before { allow(Tag).to receive(:search).and_return([]) }
|
|
59
|
-
|
|
60
|
-
it "returns nil" do
|
|
61
|
-
expect(Tag.find_by(args)).to be_nil
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
describe ".search" do
|
|
67
|
-
let(:serialized_records) { [Tag.instantiate(guid: "123")] }
|
|
68
|
-
|
|
69
|
-
context "given args that respond to :to_hash" do
|
|
70
|
-
let(:args) { {} }
|
|
71
|
-
let(:rpc) { ::ActiveRemote::RPCAdapters::ProtobufAdapter.new(::Tag.service_class, ::Tag.endpoints) }
|
|
72
|
-
|
|
73
|
-
before { allow(rpc).to receive(:execute).and_return(response) }
|
|
74
|
-
before { allow(::Tag).to receive(:rpc).and_return(rpc) }
|
|
75
|
-
|
|
76
|
-
it "searches with the given args" do
|
|
77
|
-
expect(Tag.rpc).to receive(:execute).with(:search, args)
|
|
78
|
-
Tag.search(args)
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
it "returns records" do
|
|
82
|
-
records = Tag.search(args)
|
|
83
|
-
expect(records).to eq serialized_records
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
context "given args that don't respond to :to_hash" do
|
|
88
|
-
let(:request) { double(:request) }
|
|
89
|
-
|
|
90
|
-
it "raises an exception" do
|
|
91
|
-
expect { Tag.search(request) }.to raise_error(::RuntimeError, /Invalid parameter/)
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
describe "#reload" do
|
|
97
|
-
let(:args) { attributes.slice("guid", "user_guid") }
|
|
98
|
-
let(:attributes) { HashWithIndifferentAccess.new(guid: "foo", name: "bar", updated_at: nil, user_guid: "baz") }
|
|
99
|
-
|
|
100
|
-
subject { Tag.new(args) }
|
|
101
|
-
|
|
102
|
-
before { allow(Tag).to receive(:find).and_return(Tag.new(attributes)) }
|
|
103
|
-
|
|
104
|
-
it "reloads the record" do
|
|
105
|
-
expect(Tag).to receive(:find).with(subject.scope_key_hash)
|
|
106
|
-
subject.reload
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
it "assigns new attributes" do
|
|
110
|
-
subject.reload
|
|
111
|
-
expect(subject.attributes).to eq attributes
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
end
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe ActiveRemote::Serialization do
|
|
4
|
-
describe ".serialize_records" do
|
|
5
|
-
let(:records) { [{foo: "bar"}] }
|
|
6
|
-
|
|
7
|
-
subject { Tag.new }
|
|
8
|
-
|
|
9
|
-
it "serializes records into active remote objects" do
|
|
10
|
-
Tag.serialize_records(records).each do |record|
|
|
11
|
-
expect(record).to be_a Tag
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
describe "#add_errors" do
|
|
17
|
-
let(:error) { Generic::Error.new(field: "name", message: "Boom!") }
|
|
18
|
-
let(:response) {
|
|
19
|
-
tag = Generic::Remote::Tag.new
|
|
20
|
-
tag.errors << error
|
|
21
|
-
tag
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
subject { Tag.new }
|
|
25
|
-
|
|
26
|
-
context "when the response has errors" do
|
|
27
|
-
it "adds the errors to the active remote object" do
|
|
28
|
-
subject.add_errors(response.errors)
|
|
29
|
-
expect(subject.errors[:name]).to match_array(["Boom!"])
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe ActiveRemote::Serializers::Protobuf::Fields do
|
|
4
|
-
describe ".from_attributes" do
|
|
5
|
-
let(:ready_value) { {records: [{name: "Cool Post", errors: [{message: "Boom!"}]}]} }
|
|
6
|
-
let(:value) { {records: {name: "Cool Post", errors: {message: "Boom!"}}} }
|
|
7
|
-
|
|
8
|
-
it "gets protobuf-ready fields from attributes" do
|
|
9
|
-
expect(described_class.from_attributes(Generic::Remote::Posts, value)).to eq ready_value
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
describe ActiveRemote::Serializers::Protobuf::Field do
|
|
15
|
-
describe ".from_attribute" do
|
|
16
|
-
context "when field is a repeated message" do
|
|
17
|
-
let(:field) { Generic::Remote::Posts.get_field(:records) }
|
|
18
|
-
|
|
19
|
-
context "and the value is not an array" do
|
|
20
|
-
let(:ready_value) { [{name: "Cool Post", errors: [{message: "Boom!"}]}] }
|
|
21
|
-
let(:value) { {name: "Cool Post", errors: {message: "Boom!"}} }
|
|
22
|
-
|
|
23
|
-
it "gets protobuf-ready fields from the value" do
|
|
24
|
-
expect(described_class.from_attribute(field, value)).to eq ready_value
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
context "when field is a message" do
|
|
30
|
-
let(:field) { Generic::Remote::Post.get_field(:category) }
|
|
31
|
-
|
|
32
|
-
context "and value is a hash" do
|
|
33
|
-
let(:ready_value) { {name: "Film", errors: [{message: "Boom!"}]} }
|
|
34
|
-
let(:value) { {name: "Film", errors: {message: "Boom!"}} }
|
|
35
|
-
|
|
36
|
-
it "gets protobuf-ready fields from the value" do
|
|
37
|
-
expect(described_class.from_attribute(field, value)).to eq ready_value
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
context "when field is repeated" do
|
|
43
|
-
let(:field) { Generic::Remote::PostRequest.get_field(:name) }
|
|
44
|
-
|
|
45
|
-
context "and the value is not an array" do
|
|
46
|
-
let(:ready_value) { ["Cool Post"] }
|
|
47
|
-
let(:value) { "Cool Post" }
|
|
48
|
-
|
|
49
|
-
it "gets protobuf-ready fields from the value" do
|
|
50
|
-
expect(described_class.from_attribute(field, value)).to eq ready_value
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
# TODO: Find a better way to write this. It works for now, but it's not
|
|
56
|
-
# very clear and is hard to track down since failures don't include a
|
|
57
|
-
# description.
|
|
58
|
-
#
|
|
59
|
-
# TODO: Consider adding specific specs for typecasting dates to integers
|
|
60
|
-
# or strings since that's what prompted the re-introduction of the
|
|
61
|
-
# typecasting.
|
|
62
|
-
#
|
|
63
|
-
context "when typecasting fields" do
|
|
64
|
-
let(:string_value) { double(:string, to_s: "") }
|
|
65
|
-
|
|
66
|
-
def typecasts(field, conversion)
|
|
67
|
-
field = Serializer.get_field(field, true)
|
|
68
|
-
expect(described_class.from_attribute(field, conversion.first[0])).to eq conversion.first[1]
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it { typecasts(:bool_field, "0" => false) }
|
|
72
|
-
it { typecasts(:bytes_field, string_value => "") }
|
|
73
|
-
it { typecasts(:double_field, 0 => 0.0) }
|
|
74
|
-
it { typecasts(:fixed32_field, "0" => 0) }
|
|
75
|
-
it { typecasts(:fixed64_field, "0" => 0) }
|
|
76
|
-
it { typecasts(:float_field, 0 => 0.0) }
|
|
77
|
-
it { typecasts(:int32_field, "0" => 0) }
|
|
78
|
-
it { typecasts(:int64_field, "0" => 0) }
|
|
79
|
-
it { typecasts(:sfixed32_field, "0" => 0) }
|
|
80
|
-
it { typecasts(:sfixed64_field, "0" => 0) }
|
|
81
|
-
it { typecasts(:sint32_field, "0" => 0) }
|
|
82
|
-
it { typecasts(:sint64_field, "0" => 0) }
|
|
83
|
-
it { typecasts(:string_field, string_value => "") }
|
|
84
|
-
it { typecasts(:uint32_field, "0" => 0) }
|
|
85
|
-
it { typecasts(:uint64_field, "0" => 0) }
|
|
86
|
-
it { typecasts(:enum_field, 0 => 0) }
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
end
|
|
@@ -1,56 +0,0 @@
|
|
|
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/spec_helper.rb
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
require "rubygems"
|
|
2
|
-
require "bundler"
|
|
3
|
-
|
|
4
|
-
require "simplecov"
|
|
5
|
-
SimpleCov.start do
|
|
6
|
-
add_filter "/spec/"
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
Bundler.require(:default, :development, :test)
|
|
10
|
-
|
|
11
|
-
require "protobuf/rspec"
|
|
12
|
-
require "support/helpers"
|
|
13
|
-
|
|
14
|
-
$LOAD_PATH << ::File.expand_path("../support/protobuf", __FILE__)
|
|
15
|
-
require "support/protobuf"
|
|
16
|
-
require "support/models"
|
|
17
|
-
|
|
18
|
-
RSpec.configure do |config|
|
|
19
|
-
config.include Protobuf::RSpec::Helpers
|
|
20
|
-
|
|
21
|
-
# Turn deprecation warnings into errors with full backtrace.
|
|
22
|
-
config.raise_errors_for_deprecations!
|
|
23
|
-
|
|
24
|
-
# Verifies the existance of any stubbed methods, replaces better_receive and better_stub
|
|
25
|
-
# https://www.relishapp.com/rspec/rspec-mocks/v/3-1/docs/verifying-doubles/partial-doubles
|
|
26
|
-
config.mock_with :rspec do |mocks|
|
|
27
|
-
mocks.verify_partial_doubles = true
|
|
28
|
-
end
|
|
29
|
-
end
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
package generic.remote;
|
|
2
|
-
|
|
3
|
-
import "error.proto";
|
|
4
|
-
|
|
5
|
-
message Author {
|
|
6
|
-
optional string guid = 1;
|
|
7
|
-
optional string name = 2;
|
|
8
|
-
repeated Error errors = 3;
|
|
9
|
-
optional string user_guid = 4;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
message Authors {
|
|
13
|
-
repeated Author records = 1;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
message AuthorRequest {
|
|
17
|
-
repeated string guid = 1;
|
|
18
|
-
repeated string name = 2;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
service AuthorService {
|
|
22
|
-
rpc Search (AuthorRequest) returns (Authors);
|
|
23
|
-
rpc Create (Author) returns (Author);
|
|
24
|
-
rpc Update (Author) returns (Author);
|
|
25
|
-
rpc Delete (Author) returns (Author);
|
|
26
|
-
rpc CreateAll (Authors) returns (Authors);
|
|
27
|
-
rpc UpdateAll (Authors) returns (Authors);
|
|
28
|
-
rpc DeleteAll (Authors) returns (Authors);
|
|
29
|
-
rpc DestroyAll (Authors) returns (Authors);
|
|
30
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
package generic.remote;
|
|
2
|
-
|
|
3
|
-
import "error.proto";
|
|
4
|
-
|
|
5
|
-
message Category {
|
|
6
|
-
optional string guid = 1;
|
|
7
|
-
optional string name = 2;
|
|
8
|
-
repeated Error errors = 3;
|
|
9
|
-
optional string user_guid = 4;
|
|
10
|
-
optional string author_guid = 5;
|
|
11
|
-
optional string chief_editor_guid = 6;
|
|
12
|
-
optional string editor_guid = 7;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
message Categories {
|
|
16
|
-
repeated Category records = 1;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
message CategoryRequest {
|
|
20
|
-
repeated string guid = 1;
|
|
21
|
-
repeated string name = 2;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
service CategoryService {
|
|
25
|
-
rpc Search (CategoryRequest) returns (Categories);
|
|
26
|
-
rpc Create (Category) returns (Category);
|
|
27
|
-
rpc Update (Category) returns (Category);
|
|
28
|
-
rpc Delete (Category) returns (Category);
|
|
29
|
-
rpc CreateAll (Categories) returns (Categories);
|
|
30
|
-
rpc UpdateAll (Categories) returns (Categories);
|
|
31
|
-
rpc DeleteAll (Categories) returns (Categories);
|
|
32
|
-
rpc DestroyAll (Categories) returns (Categories);
|
|
33
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
package generic.remote;
|
|
2
|
-
|
|
3
|
-
import "error.proto";
|
|
4
|
-
import "category.proto";
|
|
5
|
-
|
|
6
|
-
message Post {
|
|
7
|
-
optional string guid = 1;
|
|
8
|
-
optional string name = 2;
|
|
9
|
-
optional string author_guid = 3;
|
|
10
|
-
optional Category category = 4;
|
|
11
|
-
repeated Error errors = 5;
|
|
12
|
-
optional string user_guid = 6;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
message Posts {
|
|
16
|
-
repeated Post records = 1;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
message PostRequest {
|
|
20
|
-
repeated string guid = 1;
|
|
21
|
-
repeated string name = 2;
|
|
22
|
-
repeated string author_guid = 3;
|
|
23
|
-
repeated string user_guid = 4;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
service PostService {
|
|
27
|
-
rpc Search (PostRequest) returns (Posts);
|
|
28
|
-
rpc Create (Post) returns (Post);
|
|
29
|
-
rpc Update (Post) returns (Post);
|
|
30
|
-
rpc Delete (Post) returns (Post);
|
|
31
|
-
rpc CreateAll (Posts) returns (Posts);
|
|
32
|
-
rpc UpdateAll (Posts) returns (Posts);
|
|
33
|
-
rpc DeleteAll (Posts) returns (Posts);
|
|
34
|
-
rpc DestroyAll (Posts) returns (Posts);
|
|
35
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
message Serializer {
|
|
2
|
-
enum Type {
|
|
3
|
-
DEFAULT = 0;
|
|
4
|
-
USER = 1;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
optional bool bool_field = 1;
|
|
8
|
-
optional bytes bytes_field = 2;
|
|
9
|
-
optional double double_field = 3;
|
|
10
|
-
optional fixed32 fixed32_field = 4;
|
|
11
|
-
optional fixed64 fixed64_field = 5;
|
|
12
|
-
optional float float_field = 6;
|
|
13
|
-
optional int32 int32_field = 7;
|
|
14
|
-
optional int64 int64_field = 8;
|
|
15
|
-
optional sfixed32 sfixed32_field = 9;
|
|
16
|
-
optional sfixed64 sfixed64_field = 10;
|
|
17
|
-
optional sint32 sint32_field = 11;
|
|
18
|
-
optional sint64 sint64_field = 12;
|
|
19
|
-
optional string string_field = 13;
|
|
20
|
-
optional uint32 uint32_field = 14;
|
|
21
|
-
optional uint64 uint64_field = 15;
|
|
22
|
-
optional Type enum_field = 16;
|
|
23
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
package generic.remote;
|
|
2
|
-
|
|
3
|
-
import "error.proto";
|
|
4
|
-
|
|
5
|
-
message Tag {
|
|
6
|
-
optional string guid = 1;
|
|
7
|
-
optional string name = 2;
|
|
8
|
-
repeated Error errors = 3;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
message Tags {
|
|
12
|
-
repeated Tag records = 1;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
message TagRequest {
|
|
16
|
-
repeated string guid = 1;
|
|
17
|
-
repeated string name = 2;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
service TagService {
|
|
21
|
-
rpc Search (TagRequest) returns (Tags);
|
|
22
|
-
rpc Create (Tag) returns (Tag);
|
|
23
|
-
rpc Update (Tag) returns (Tag);
|
|
24
|
-
rpc Delete (Tag) returns (Tag);
|
|
25
|
-
rpc Register (Tag) returns (Tag);
|
|
26
|
-
rpc CreateAll (Tags) returns (Tags);
|
|
27
|
-
rpc UpdateAll (Tags) returns (Tags);
|
|
28
|
-
rpc DeleteAll (Tags) returns (Tags);
|
|
29
|
-
rpc DestroyAll (Tags) returns (Tags);
|
|
30
|
-
}
|
data/spec/support/helpers.rb
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
##
|
|
2
|
-
# Reset all DSL variables so specs don't interfere with each other.
|
|
3
|
-
#
|
|
4
|
-
def reset_dsl_variables(klass)
|
|
5
|
-
reset_app_name(klass)
|
|
6
|
-
reset_auto_paging_size(klass)
|
|
7
|
-
reset_namespace(klass)
|
|
8
|
-
reset_publishable_attributes(klass)
|
|
9
|
-
reset_service_class(klass)
|
|
10
|
-
reset_service_name(klass)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def reset_app_name(klass)
|
|
14
|
-
klass.send(:instance_variable_set, :@app_name, nil)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def reset_auto_paging_size(klass)
|
|
18
|
-
klass.send(:instance_variable_set, :@auto_paging_size, nil)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def reset_namespace(klass)
|
|
22
|
-
klass.send(:instance_variable_set, :@namespace, nil)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def reset_publishable_attributes(klass)
|
|
26
|
-
klass.send(:instance_variable_set, :@publishable_attributes, nil)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def reset_service_class(klass)
|
|
30
|
-
klass.send(:instance_variable_set, :@service_class, nil)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def reset_service_name(klass)
|
|
34
|
-
klass.send(:instance_variable_set, :@service_name, nil)
|
|
35
|
-
end
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
require "support/protobuf/author.pb"
|
|
2
|
-
|
|
3
|
-
##
|
|
4
|
-
# Define a generic class that inherits from active remote base
|
|
5
|
-
#
|
|
6
|
-
class Author < ::ActiveRemote::Base
|
|
7
|
-
service_class ::Generic::Remote::AuthorService
|
|
8
|
-
|
|
9
|
-
attribute :guid, :string
|
|
10
|
-
attribute :name, :string
|
|
11
|
-
attribute :user_guid, :string
|
|
12
|
-
attribute :chief_editor_guid, :string
|
|
13
|
-
attribute :editor_guid, :string
|
|
14
|
-
attribute :category_guid, :string
|
|
15
|
-
attribute :age, :integer
|
|
16
|
-
attribute :birthday, :datetime
|
|
17
|
-
attribute :writes_fiction, :boolean
|
|
18
|
-
attribute :net_sales, :float
|
|
19
|
-
|
|
20
|
-
has_many :posts
|
|
21
|
-
has_many :user_posts, class_name: "::Post", scope: :user_guid
|
|
22
|
-
has_many :flagged_posts, class_name: "::Post"
|
|
23
|
-
has_many :bestseller_posts, class_name: "::Post", foreign_key: :bestseller_guid
|
|
24
|
-
|
|
25
|
-
belongs_to :category
|
|
26
|
-
end
|