active_remote 3.3.3 → 5.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +28 -0
- data/CHANGES.md +13 -0
- data/Gemfile +1 -1
- data/Rakefile +7 -3
- data/active_remote.gemspec +8 -6
- data/lib/active_remote.rb +9 -8
- data/lib/active_remote/association.rb +12 -14
- data/lib/active_remote/attribute_definition.rb +14 -12
- data/lib/active_remote/attributes.rb +6 -6
- data/lib/active_remote/base.rb +20 -27
- data/lib/active_remote/config.rb +1 -1
- data/lib/active_remote/dirty.rb +3 -3
- data/lib/active_remote/dsl.rb +3 -4
- data/lib/active_remote/errors.rb +1 -11
- data/lib/active_remote/persistence.rb +11 -12
- data/lib/active_remote/primary_key.rb +0 -1
- data/lib/active_remote/query_attributes.rb +13 -13
- data/lib/active_remote/rpc.rb +8 -14
- data/lib/active_remote/rpc_adapters/protobuf_adapter.rb +18 -17
- data/lib/active_remote/scope_keys.rb +1 -2
- data/lib/active_remote/search.rb +8 -6
- data/lib/active_remote/serializers/protobuf.rb +15 -25
- data/lib/active_remote/validations.rb +1 -1
- data/lib/active_remote/version.rb +1 -1
- data/spec/lib/active_remote/association_spec.rb +23 -23
- data/spec/lib/active_remote/attributes_spec.rb +49 -3
- data/spec/lib/active_remote/base_spec.rb +1 -1
- data/spec/lib/active_remote/dirty_spec.rb +12 -12
- data/spec/lib/active_remote/dsl_spec.rb +4 -4
- data/spec/lib/active_remote/integration_spec.rb +2 -2
- data/spec/lib/active_remote/persistence_spec.rb +26 -33
- data/spec/lib/active_remote/primary_key_spec.rb +3 -3
- data/spec/lib/active_remote/query_attribute_spec.rb +0 -120
- data/spec/lib/active_remote/rpc_adapters/protobuf_adapter_spec.rb +1 -1
- data/spec/lib/active_remote/rpc_spec.rb +1 -1
- data/spec/lib/active_remote/scope_keys_spec.rb +7 -7
- data/spec/lib/active_remote/search_spec.rb +8 -8
- data/spec/lib/active_remote/serialization_spec.rb +4 -4
- data/spec/lib/active_remote/serializers/protobuf_spec.rb +23 -23
- data/spec/lib/active_remote/validations_spec.rb +17 -17
- data/spec/spec_helper.rb +9 -9
- data/spec/support/helpers.rb +6 -6
- data/spec/support/models.rb +8 -8
- data/spec/support/models/author.rb +1 -1
- data/spec/support/models/category.rb +1 -2
- data/spec/support/models/default_author.rb +1 -1
- data/spec/support/models/post.rb +4 -4
- data/spec/support/models/tag.rb +1 -1
- data/spec/support/models/typecasted_author.rb +4 -5
- data/spec/support/protobuf.rb +5 -5
- metadata +24 -26
- data/lib/active_remote/attribute_assignment.rb +0 -53
- data/lib/active_remote/type.rb +0 -36
- data/lib/active_remote/type/registry.rb +0 -45
- data/lib/active_remote/typecasting.rb +0 -51
- data/lib/active_remote/typecasting/big_decimal_typecaster.rb +0 -21
- data/lib/active_remote/typecasting/boolean.rb +0 -7
- data/lib/active_remote/typecasting/boolean_typecaster.rb +0 -18
- data/lib/active_remote/typecasting/date_time_typecaster.rb +0 -10
- data/lib/active_remote/typecasting/date_typecaster.rb +0 -10
- data/lib/active_remote/typecasting/float_typecaster.rb +0 -9
- data/lib/active_remote/typecasting/integer_typecaster.rb +0 -10
- data/lib/active_remote/typecasting/object_typecaster.rb +0 -9
- data/lib/active_remote/typecasting/string_typecaster.rb +0 -9
- data/spec/lib/active_remote/errors_spec.rb +0 -31
- data/spec/lib/active_remote/typecasting_spec.rb +0 -53
@@ -1,16 +1,16 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe ActiveRemote::ScopeKeys do
|
4
4
|
let(:key) { :user_guid }
|
5
|
-
let(:_scope_keys) { [
|
6
|
-
let(:scope_keys) { [
|
5
|
+
let(:_scope_keys) { ["user_guid"] }
|
6
|
+
let(:scope_keys) { ["guid"] + _scope_keys }
|
7
7
|
let(:tag) { Tag.new(tag_hash) }
|
8
|
-
let(:tag_hash) { { :guid =>
|
8
|
+
let(:tag_hash) { { :guid => "TAG-123", :user_guid => "USR-123", :name => "teh tag" } }
|
9
9
|
|
10
10
|
describe ".scope_key" do
|
11
11
|
after { Tag._scope_keys = [] }
|
12
12
|
|
13
|
-
it
|
13
|
+
it "adds scope_key to _scope_keys" do
|
14
14
|
Tag.scope_key(key)
|
15
15
|
expect(Tag._scope_keys).to eq(_scope_keys)
|
16
16
|
end
|
@@ -20,7 +20,7 @@ describe ActiveRemote::ScopeKeys do
|
|
20
20
|
before { allow(Tag).to receive(:_scope_keys).and_return(_scope_keys) }
|
21
21
|
|
22
22
|
it "combines primary key with _scope_keys" do
|
23
|
-
expect(Tag.scope_keys).to eq([
|
23
|
+
expect(Tag.scope_keys).to eq(["guid"] + _scope_keys)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -31,7 +31,7 @@ describe ActiveRemote::ScopeKeys do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
describe "#scope_key_hash" do
|
34
|
-
let(:scope_key_hash) { {
|
34
|
+
let(:scope_key_hash) { { "guid" => "TAG-123", "user_guid" => "USR-123" } }
|
35
35
|
|
36
36
|
before { allow(tag).to receive(:scope_keys).and_return(scope_keys) }
|
37
37
|
|
@@ -1,14 +1,14 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe ActiveRemote::Search do
|
4
|
-
let(:records) { [
|
4
|
+
let(:records) { [Generic::Remote::Tag.new] }
|
5
5
|
let(:response) { Generic::Remote::Tags.new(:records => records) }
|
6
6
|
let(:rpc) { double(:rpc) }
|
7
7
|
|
8
8
|
describe ".find" do
|
9
|
-
let(:args) {
|
9
|
+
let(:args) { {} }
|
10
10
|
let(:record) { double(:record) }
|
11
|
-
let(:records) { [
|
11
|
+
let(:records) { [record] }
|
12
12
|
|
13
13
|
before { allow(Tag).to receive(:search).and_return(records) }
|
14
14
|
|
@@ -37,10 +37,10 @@ describe ActiveRemote::Search do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
describe ".search" do
|
40
|
-
let(:serialized_records) { [
|
40
|
+
let(:serialized_records) { [Tag.new] }
|
41
41
|
|
42
42
|
context "given args that respond to :to_hash" do
|
43
|
-
let(:args) {
|
43
|
+
let(:args) { {} }
|
44
44
|
let(:rpc) { ::ActiveRemote::RPCAdapters::ProtobufAdapter.new(::Tag.service_class, ::Tag.endpoints) }
|
45
45
|
|
46
46
|
before { allow(rpc).to receive(:execute).and_return(response) }
|
@@ -66,8 +66,8 @@ describe ActiveRemote::Search do
|
|
66
66
|
end
|
67
67
|
|
68
68
|
describe "#reload" do
|
69
|
-
let(:args) { attributes.slice(
|
70
|
-
let(:attributes) { HashWithIndifferentAccess.new(:guid =>
|
69
|
+
let(:args) { attributes.slice("guid", "user_guid") }
|
70
|
+
let(:attributes) { HashWithIndifferentAccess.new(:guid => "foo", :name => "bar", :updated_at => nil, :user_guid => "baz") }
|
71
71
|
|
72
72
|
subject { Tag.new(args) }
|
73
73
|
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe ActiveRemote::Serialization do
|
4
4
|
describe ".serialize_records" do
|
5
|
-
let(:records) { [
|
5
|
+
let(:records) { [{ :foo => "bar" }] }
|
6
6
|
|
7
7
|
subject { Tag.new }
|
8
8
|
|
@@ -14,7 +14,7 @@ describe ActiveRemote::Serialization do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
describe "#add_errors" do
|
17
|
-
let(:error) { Generic::Error.new(:field =>
|
17
|
+
let(:error) { Generic::Error.new(:field => "name", :message => "Boom!") }
|
18
18
|
let(:response) {
|
19
19
|
tag = Generic::Remote::Tag.new
|
20
20
|
tag.errors << error
|
@@ -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
|
-
expect(subject.errors[:name]).to match_array([
|
29
|
+
expect(subject.errors[:name]).to match_array(["Boom!"])
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe ActiveRemote::Serializers::Protobuf::Fields do
|
4
4
|
describe ".from_attributes" do
|
5
|
-
let(:ready_value) { { :records => [
|
6
|
-
let(:value) { { :records => { :name =>
|
5
|
+
let(:ready_value) { { :records => [{ :name => "Cool Post", :errors => [{ :message => "Boom!" }] }] } }
|
6
|
+
let(:value) { { :records => { :name => "Cool Post", :errors => { :message => "Boom!" } } } }
|
7
7
|
|
8
8
|
it "gets protobuf-ready fields from attributes" do
|
9
9
|
expect(described_class.from_attributes(Generic::Remote::Posts, value)).to eq ready_value
|
@@ -17,8 +17,8 @@ describe ActiveRemote::Serializers::Protobuf::Field do
|
|
17
17
|
let(:field) { Generic::Remote::Posts.get_field(:records) }
|
18
18
|
|
19
19
|
context "and the value is not an array" do
|
20
|
-
let(:ready_value) { [
|
21
|
-
let(:value) { { :name =>
|
20
|
+
let(:ready_value) { [{ :name => "Cool Post", :errors => [{ :message => "Boom!" }] }] }
|
21
|
+
let(:value) { { :name => "Cool Post", :errors => { :message => "Boom!" } } }
|
22
22
|
|
23
23
|
it "gets protobuf-ready fields from the value" do
|
24
24
|
expect(described_class.from_attribute(field, value)).to eq ready_value
|
@@ -30,8 +30,8 @@ describe ActiveRemote::Serializers::Protobuf::Field do
|
|
30
30
|
let(:field) { Generic::Remote::Post.get_field(:category) }
|
31
31
|
|
32
32
|
context "and value is a hash" do
|
33
|
-
let(:ready_value) { { :name =>
|
34
|
-
let(:value) { { :name =>
|
33
|
+
let(:ready_value) { { :name => "Film", :errors => [{ :message => "Boom!" }] } }
|
34
|
+
let(:value) { { :name => "Film", :errors => { :message => "Boom!" } } }
|
35
35
|
|
36
36
|
it "gets protobuf-ready fields from the value" do
|
37
37
|
expect(described_class.from_attribute(field, value)).to eq ready_value
|
@@ -43,8 +43,8 @@ describe ActiveRemote::Serializers::Protobuf::Field do
|
|
43
43
|
let(:field) { Generic::Remote::PostRequest.get_field(:name) }
|
44
44
|
|
45
45
|
context "and the value is not an array" do
|
46
|
-
let(:ready_value) { [
|
47
|
-
let(:value) {
|
46
|
+
let(:ready_value) { ["Cool Post"] }
|
47
|
+
let(:value) { "Cool Post" }
|
48
48
|
|
49
49
|
it "gets protobuf-ready fields from the value" do
|
50
50
|
expect(described_class.from_attribute(field, value)).to eq ready_value
|
@@ -61,28 +61,28 @@ describe ActiveRemote::Serializers::Protobuf::Field do
|
|
61
61
|
# typecasting.
|
62
62
|
#
|
63
63
|
context "when typecasting fields" do
|
64
|
-
let(:string_value) { double(:string, :to_s =>
|
64
|
+
let(:string_value) { double(:string, :to_s => "") }
|
65
65
|
|
66
66
|
def typecasts(field, conversion)
|
67
67
|
field = Serializer.get_field(field, true)
|
68
68
|
expect(described_class.from_attribute(field, conversion.first[0])).to eq conversion.first[1]
|
69
69
|
end
|
70
70
|
|
71
|
-
it { typecasts(:bool_field,
|
72
|
-
it { typecasts(:bytes_field, string_value =>
|
71
|
+
it { typecasts(:bool_field, "0" => false) }
|
72
|
+
it { typecasts(:bytes_field, string_value => "") }
|
73
73
|
it { typecasts(:double_field, 0 => 0.0) }
|
74
|
-
it { typecasts(:fixed32_field,
|
75
|
-
it { typecasts(:fixed64_field,
|
74
|
+
it { typecasts(:fixed32_field, "0" => 0) }
|
75
|
+
it { typecasts(:fixed64_field, "0" => 0) }
|
76
76
|
it { typecasts(:float_field, 0 => 0.0) }
|
77
|
-
it { typecasts(:int32_field,
|
78
|
-
it { typecasts(:int64_field,
|
79
|
-
it { typecasts(:sfixed32_field,
|
80
|
-
it { typecasts(:sfixed64_field,
|
81
|
-
it { typecasts(:sint32_field,
|
82
|
-
it { typecasts(:sint64_field,
|
83
|
-
it { typecasts(:string_field, string_value =>
|
84
|
-
it { typecasts(:uint32_field,
|
85
|
-
it { typecasts(:uint64_field,
|
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
86
|
it { typecasts(:enum_field, 0 => 0) }
|
87
87
|
end
|
88
88
|
end
|
@@ -1,53 +1,53 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe ActiveRemote::Validations do
|
4
4
|
let(:invalid_record) { ::Post.new }
|
5
|
-
let(:valid_record) { ::Post.new(:name =>
|
5
|
+
let(:valid_record) { ::Post.new(:name => "test") }
|
6
6
|
|
7
7
|
before { allow(valid_record).to receive(:create_or_update).and_return(true) }
|
8
8
|
before { allow(invalid_record).to receive(:create_or_update).and_return(true) }
|
9
9
|
|
10
|
-
describe
|
11
|
-
context
|
12
|
-
it
|
10
|
+
describe "save" do
|
11
|
+
context "valid record" do
|
12
|
+
it "returns true" do
|
13
13
|
result = valid_record.save
|
14
14
|
expect(result).to be true
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
context
|
19
|
-
it
|
18
|
+
context "invalid record" do
|
19
|
+
it "returns false" do
|
20
20
|
result = invalid_record.save
|
21
21
|
expect(result).to be false
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
describe
|
27
|
-
context
|
28
|
-
it
|
26
|
+
describe "save!" do
|
27
|
+
context "valid record" do
|
28
|
+
it "returns true" do
|
29
29
|
result = valid_record.save!
|
30
30
|
expect(result).to be true
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
context
|
35
|
-
it
|
34
|
+
context "invalid record" do
|
35
|
+
it "raises invalid record error" do
|
36
36
|
expect { invalid_record.save! }.to raise_error(ActiveRemote::RemoteRecordInvalid)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
describe
|
42
|
-
context
|
43
|
-
it
|
41
|
+
describe "valid?" do
|
42
|
+
context "valid record" do
|
43
|
+
it "returns true" do
|
44
44
|
result = valid_record.valid?
|
45
45
|
expect(result).to be true
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
context
|
50
|
-
it
|
49
|
+
context "invalid record" do
|
50
|
+
it "returns false" do
|
51
51
|
result = invalid_record.valid?
|
52
52
|
expect(result).to be false
|
53
53
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler"
|
3
3
|
|
4
|
-
require
|
4
|
+
require "simplecov"
|
5
5
|
SimpleCov.start do
|
6
|
-
add_filter
|
6
|
+
add_filter "/spec/"
|
7
7
|
end
|
8
8
|
|
9
9
|
Bundler.require(:default, :development, :test)
|
10
10
|
|
11
|
-
require
|
12
|
-
require
|
11
|
+
require "protobuf/rspec"
|
12
|
+
require "support/helpers"
|
13
13
|
|
14
|
-
$LOAD_PATH << ::File.expand_path(
|
15
|
-
require
|
16
|
-
require
|
14
|
+
$LOAD_PATH << ::File.expand_path("../support/protobuf", __FILE__)
|
15
|
+
require "support/protobuf"
|
16
|
+
require "support/models"
|
17
17
|
|
18
18
|
RSpec.configure do |config|
|
19
19
|
config.include Protobuf::RSpec::Helpers
|
data/spec/support/helpers.rb
CHANGED
@@ -11,25 +11,25 @@ def reset_dsl_variables(klass)
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def reset_app_name(klass)
|
14
|
-
|
14
|
+
klass.send(:instance_variable_set, :@app_name, nil)
|
15
15
|
end
|
16
16
|
|
17
17
|
def reset_auto_paging_size(klass)
|
18
|
-
|
18
|
+
klass.send(:instance_variable_set, :@auto_paging_size, nil)
|
19
19
|
end
|
20
20
|
|
21
21
|
def reset_namespace(klass)
|
22
|
-
|
22
|
+
klass.send(:instance_variable_set, :@namespace, nil)
|
23
23
|
end
|
24
24
|
|
25
25
|
def reset_publishable_attributes(klass)
|
26
|
-
|
26
|
+
klass.send(:instance_variable_set, :@publishable_attributes, nil)
|
27
27
|
end
|
28
28
|
|
29
29
|
def reset_service_class(klass)
|
30
|
-
|
30
|
+
klass.send(:instance_variable_set, :@service_class, nil)
|
31
31
|
end
|
32
32
|
|
33
33
|
def reset_service_name(klass)
|
34
|
-
|
34
|
+
klass.send(:instance_variable_set, :@service_name, nil)
|
35
35
|
end
|
data/spec/support/models.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
1
|
+
require "support/models/message_with_options"
|
2
|
+
require "support/models/author"
|
3
|
+
require "support/models/default_author"
|
4
|
+
require "support/models/category"
|
5
|
+
require "support/models/no_attributes"
|
6
|
+
require "support/models/post"
|
7
|
+
require "support/models/tag"
|
8
|
+
require "support/models/typecasted_author"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "support/protobuf/category.pb"
|
2
2
|
|
3
3
|
##
|
4
4
|
# Define a generic class that inherits from active remote base
|
@@ -16,5 +16,4 @@ class Category < ::ActiveRemote::Base
|
|
16
16
|
has_one :senior_author, :class_name => "::Author"
|
17
17
|
has_one :primary_editor, :class_name => "::Author", :foreign_key => :editor_guid
|
18
18
|
has_one :chief_editor, :class_name => "::Author", :scope => :user_guid, :foreign_key => :chief_editor_guid
|
19
|
-
|
20
19
|
end
|
data/spec/support/models/post.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "support/protobuf/post.pb"
|
2
2
|
|
3
3
|
##
|
4
4
|
# Define a generic class that inherits from active remote base
|
@@ -13,9 +13,9 @@ class Post < ::ActiveRemote::Base
|
|
13
13
|
attribute :bestseller_guid
|
14
14
|
|
15
15
|
belongs_to :author
|
16
|
-
belongs_to :coauthor, :class_name =>
|
17
|
-
belongs_to :bestseller, :class_name =>
|
18
|
-
belongs_to :user, :class_name =>
|
16
|
+
belongs_to :coauthor, :class_name => "::Author"
|
17
|
+
belongs_to :bestseller, :class_name => "::Author", :foreign_key => :bestseller_guid
|
18
|
+
belongs_to :user, :class_name => "::Author", :scope => :user_guid
|
19
19
|
|
20
20
|
validates :name, :presence => true
|
21
21
|
end
|
data/spec/support/models/tag.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
class TypecastedAuthor < ::ActiveRemote::Base
|
2
|
-
attribute :guid, :
|
3
|
-
attribute :name, :
|
2
|
+
attribute :guid, :string
|
3
|
+
attribute :name, :string
|
4
4
|
attribute :age, :integer
|
5
|
-
attribute :birthday, :
|
5
|
+
attribute :birthday, :datetime
|
6
6
|
attribute :writes_fiction, :boolean
|
7
|
-
attribute :net_sales, :
|
8
|
-
attribute :big_integer_field, :big_integer
|
7
|
+
attribute :net_sales, :float
|
9
8
|
end
|
data/spec/support/protobuf.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require "support/protobuf/author.pb"
|
2
|
+
require "support/protobuf/category.pb"
|
3
|
+
require "support/protobuf/post.pb"
|
4
|
+
require "support/protobuf/serializer.pb"
|
5
|
+
require "support/protobuf/tag.pb"
|