forceps 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- base_class = remote_object.type.constantize rescue base_class
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
@@ -47,19 +47,26 @@ module Forceps
47
47
  end
48
48
 
49
49
  def build_new_remote_class(local_class, class_name)
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
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
- unless needs_type_condition
58
- def self.finder_needs_type_condition?
59
- false
60
- end
61
- end
62
- end
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)
@@ -1,3 +1,3 @@
1
1
  module Forceps
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -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
Binary file