forceps 0.5.0 → 0.6.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.
- data/lib/forceps/acts_as_copyable_model.rb +3 -3
- data/lib/forceps/client.rb +16 -9
- data/lib/forceps/version.rb +1 -1
- data/test/clone_structures_test.rb +0 -8
- data/test/dummy/db/remote.sqlite3 +0 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +24820 -0
- data/test/sti_test.rb +25 -0
- data/test/test_helper.rb +2 -0
- metadata +7 -5
@@ -100,7 +100,6 @@ module Forceps
|
|
100
100
|
|
101
101
|
def create_local_copy_with_simple_attributes(remote_object)
|
102
102
|
# 'self.dup.becomes(Invoice)' won't work because of different AR connections.
|
103
|
-
# todo: prepare for rails 3 and attribute protection
|
104
103
|
debug "#{as_trace(remote_object)} copying..."
|
105
104
|
|
106
105
|
# todo: pending test for STI scenario
|
@@ -117,8 +116,9 @@ module Forceps
|
|
117
116
|
|
118
117
|
def base_local_class_for(remote_object)
|
119
118
|
base_class = remote_object.class.base_class
|
120
|
-
if remote_object.respond_to?(:type)
|
121
|
-
|
119
|
+
if remote_object.respond_to?(:type) && remote_object.type.present?
|
120
|
+
local_type = remote_object.type.gsub('Forceps::Remote', '')
|
121
|
+
base_class = local_type.constantize rescue base_class
|
122
122
|
end
|
123
123
|
base_class
|
124
124
|
end
|
data/lib/forceps/client.rb
CHANGED
@@ -47,19 +47,26 @@ module Forceps
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def build_new_remote_class(local_class, class_name)
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
needs_type_condition = (local_class.base_class != ActiveRecord::Base) && local_class.finder_needs_type_condition?
|
51
|
+
Class.new(local_class) do
|
52
|
+
self.table_name = local_class.table_name
|
53
53
|
|
54
54
|
include Forceps::ActsAsCopyableModel
|
55
55
|
|
56
|
+
def self.instantiate(record, column_types = {})
|
57
|
+
if record[inheritance_column].present?
|
58
|
+
record[inheritance_column] = "Forceps::Remote::#{record[inheritance_column]}"
|
59
|
+
end
|
60
|
+
super
|
61
|
+
end
|
62
|
+
|
56
63
|
# We don't want to include STI condition automatically (the base class extends the original one)
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
64
|
+
unless needs_type_condition
|
65
|
+
def self.finder_needs_type_condition?
|
66
|
+
false
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
63
70
|
end
|
64
71
|
|
65
72
|
def remote_class_name_for(local_class_name)
|
data/lib/forceps/version.rb
CHANGED
@@ -62,12 +62,4 @@ class CloneStructuresTest < ActiveSupport::TestCase
|
|
62
62
|
assert_identical remote_address, copied_user.address
|
63
63
|
end
|
64
64
|
|
65
|
-
test "should download child objects when using single table inheritance" do
|
66
|
-
remote_car = RemoteProduct.create!(name: 'audi')
|
67
|
-
remote_car.update_column :type, 'Car'
|
68
|
-
|
69
|
-
Forceps::Remote::Product.find_by_name('audi').becomes(Forceps::Remote::Product).copy_to_local
|
70
|
-
assert_not_nil Product.find_by_name('CAR: audi')
|
71
|
-
end
|
72
|
-
|
73
65
|
end
|
Binary file
|
data/test/dummy/db/test.sqlite3
CHANGED
Binary file
|