Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix tests with string primary keys.

  • Loading branch information...
commit 632d13cda2607e5faf703d06c4556f35a50fc10a 1 parent 82d2ae7
@neglectedvalue authored
Showing with 13 additions and 6 deletions.
  1. +13 −6 test/environment.rb
View
19 test/environment.rb
@@ -28,14 +28,21 @@ def self.with_model options = {}
begin
model = Class.new(ActiveRecord::Base)
- (class << model; self; end).send :define_method, :model_name do; Struct.new(:human, :underscore).new 'TestNode', 'test_node'; end
const_set 'TestNode', model
- if primary_key_type == :string
- model.before_create { self.id = ActiveSupport::SecureRandom.hex(10) }
+ model.class_eval do
+ before_create :set_id if primary_key_type == :string
+ has_ancestry options unless options.delete(:skip_ancestry)
+
+ def self.model_name
+ Struct.new(:human, :underscore).new 'TestNode', 'test_node'
+ end
+
+ private
+ def set_id
+ self.id = ActiveSupport::SecureRandom.hex(10)
+ end
end
- model.send :set_table_name, 'test_nodes'
- model.has_ancestry options unless options.delete(:skip_ancestry)
if depth > 0
yield model, create_test_nodes(model, depth, width)
@@ -44,7 +51,7 @@ def self.with_model options = {}
end
ensure
ActiveRecord::Base.connection.drop_table 'test_nodes'
- remove_const "TestNode"
+ remove_const 'TestNode'
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.