Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

cleaned up directory structure of test constant source files

  • Loading branch information...
commit fae50ef581e0792b00baf45853ea43d275a5526f 1 parent 3246c7c
@Roman2K authored
Showing with 79 additions and 32 deletions.
  1. +1 −0  .gitignore
  2. +1 −1  lib/rails_development_boost/dependencies_patch.rb
  3. BIN  test/constants/.DS_Store
  4. +0 −2  test/constants/a/c.rb
  5. 0  test/constants/{db_models → active_record}/comment.rb
  6. 0  test/constants/{db_models → active_record}/message.rb
  7. 0  test/constants/{db_models → active_record}/other.rb
  8. 0  test/constants/{db_models → active_record}/post.rb
  9. +0 −2  test/constants/d.rb
  10. +2 −0  test/constants/deep_nesting/a.rb
  11. +2 −0  test/constants/deep_nesting/a/b.rb
  12. +2 −0  test/constants/deep_nesting/a/b/c.rb
  13. +2 −0  test/constants/deep_nesting/a/b/c/d.rb
  14. +1 −1  test/constants/{mut.rb → double_removal/ns.rb}
  15. +3 −0  test/constants/double_removal/ns/c.rb
  16. +2 −0  test/constants/double_removal/ns/m.rb
  17. 0  test/constants/{ → mixins}/client.rb
  18. 0  test/constants/{ → mixins}/mixin.rb
  19. 0  test/constants/{ → mixins}/update/mixin.rb
  20. +0 −3  test/constants/mut/c.rb
  21. +0 −2  test/constants/mut/m.rb
  22. +2 −0  test/constants/nested_mixins/b.rb
  23. +2 −0  test/constants/nested_mixins/b/c.rb
  24. 0  test/constants/{ → nested_mixins}/ma.rb
  25. 0  test/constants/{ → nested_mixins}/ma/mb.rb
  26. 0  test/constants/{ → nested_mixins}/ma/mb/mc.rb
  27. +4 −0 test/constants/nested_mixins/oa.rb
  28. +3 −0  test/constants/nested_mixins/oa/ob.rb
  29. +2 −0  test/constants/nested_mixins/oa/ob/oc.rb
  30. 0  test/constants/{ → single_removal}/a.rb
  31. +2 −0  test/constants/single_removal/b.rb
  32. +2 −0  test/constants/subclass/a.rb
  33. 0  test/constants/{ → subclass}/b.rb
  34. +2 −0  test/constants/subclass/c.rb
  35. +44 −21 test/rails_development_boost_test.rb
View
1  .gitignore
@@ -0,0 +1 @@
+.DS_Store
View
2  lib/rails_development_boost/dependencies_patch.rb
@@ -90,7 +90,7 @@ def remove_dependent_modules(mod)
modules.dup.each do |other|
next unless other < mod
next unless other.superclass == mod if Class === mod
- next unless other.name.constantize == other
+ next unless qualified_const_defined?(other.name) && other.name.constantize == other
remove_constant(other.name)
end
end
View
BIN  test/constants/.DS_Store
Binary file not shown
View
2  test/constants/a/c.rb
@@ -1,2 +0,0 @@
-class A::C
-end
View
0  test/constants/db_models/comment.rb → test/constants/active_record/comment.rb
File renamed without changes
View
0  test/constants/db_models/message.rb → test/constants/active_record/message.rb
File renamed without changes
View
0  test/constants/db_models/other.rb → test/constants/active_record/other.rb
File renamed without changes
View
0  test/constants/db_models/post.rb → test/constants/active_record/post.rb
File renamed without changes
View
2  test/constants/d.rb
@@ -1,2 +0,0 @@
-class D
-end
View
2  test/constants/deep_nesting/a.rb
@@ -0,0 +1,2 @@
+module A
+end
View
2  test/constants/deep_nesting/a/b.rb
@@ -0,0 +1,2 @@
+module A::B
+end
View
2  test/constants/deep_nesting/a/b/c.rb
@@ -0,0 +1,2 @@
+module A::B::C
+end
View
2  test/constants/deep_nesting/a/b/c/d.rb
@@ -0,0 +1,2 @@
+module A::B::C::D
+end
View
2  test/constants/mut.rb → test/constants/double_removal/ns.rb
@@ -1,3 +1,3 @@
-class Mut
+class Ns
include M
end
View
3  test/constants/double_removal/ns/c.rb
@@ -0,0 +1,3 @@
+class Ns::C
+ include Ns::M
+end
View
2  test/constants/double_removal/ns/m.rb
@@ -0,0 +1,2 @@
+module Ns::M
+end
View
0  test/constants/client.rb → test/constants/mixins/client.rb
File renamed without changes
View
0  test/constants/mixin.rb → test/constants/mixins/mixin.rb
File renamed without changes
View
0  test/constants/update/mixin.rb → test/constants/mixins/update/mixin.rb
File renamed without changes
View
3  test/constants/mut/c.rb
@@ -1,3 +0,0 @@
-class Mut::C
- include Mut::M
-end
View
2  test/constants/mut/m.rb
@@ -1,2 +0,0 @@
-module Mut::M
-end
View
2  test/constants/nested_mixins/b.rb
@@ -0,0 +1,2 @@
+module B
+end
View
2  test/constants/nested_mixins/b/c.rb
@@ -0,0 +1,2 @@
+class B::C
+end
View
0  test/constants/ma.rb → test/constants/nested_mixins/ma.rb
File renamed without changes
View
0  test/constants/ma/mb.rb → test/constants/nested_mixins/ma/mb.rb
File renamed without changes
View
0  test/constants/ma/mb/mc.rb → test/constants/nested_mixins/ma/mb/mc.rb
File renamed without changes
View
4 test/constants/nested_mixins/oa.rb
@@ -0,0 +1,4 @@
+module Oa
+ include Ma::Mb
+ Ob
+end
View
3  test/constants/nested_mixins/oa/ob.rb
@@ -0,0 +1,3 @@
+module Oa::Ob
+ Oc
+end
View
2  test/constants/nested_mixins/oa/ob/oc.rb
@@ -0,0 +1,2 @@
+class Oa::Ob::Oc < B::C
+end
View
0  test/constants/a.rb → test/constants/single_removal/a.rb
File renamed without changes
View
2  test/constants/single_removal/b.rb
@@ -0,0 +1,2 @@
+class B
+end
View
2  test/constants/subclass/a.rb
@@ -0,0 +1,2 @@
+class A
+end
View
0  test/constants/b.rb → test/constants/subclass/b.rb
File renamed without changes
View
2  test/constants/subclass/c.rb
@@ -0,0 +1,2 @@
+class C
+end
View
65 test/rails_development_boost_test.rb
@@ -6,13 +6,15 @@
RailsDevelopmentBoost.apply!
class RailsDevelopmentBoostTest < Test::Unit::TestCase
- def test_constant_update
+ def test_single_removal
+ load_from "single_removal"
+
assert_same_object_id('A') { reload! }
assert_different_object_id('A') { reload! { update("a.rb") } }
assert_different_object_id('A') { reload! { update("a.rb") } }
assert_same_object_id('A') { reload! }
- assert_same_object_id('D') do
+ assert_same_object_id('B') do
assert_different_object_id('A') do
reload! do
update("a.rb")
@@ -22,15 +24,21 @@ def test_constant_update
end
def test_subclass_update_cascade
+ load_from "subclass"
+
assert_different_object_id 'A', 'B' do
- reload! do
- update("a.rb")
+ assert_same_object_id 'C' do
+ reload! do
+ update("a.rb")
+ end
end
end
end
- def test_nested_constants_update_cascade
- assert_different_object_id 'A', 'A::C' do
+ def test_nested_constant_update_cascade
+ load_from "deep_nesting"
+
+ assert_different_object_id 'A::B::C::D', 'A::B::C', 'A::B', 'A' do
reload! do
update("a.rb")
end
@@ -38,6 +46,8 @@ def test_nested_constants_update_cascade
end
def test_mixin_update_cascade
+ load_from "mixins"
+
assert_different_object_id 'Mixin', 'Client' do
reload! do
update("mixin.rb")
@@ -50,48 +60,56 @@ def test_mixin_update_cascade
reload! do
update("mixin.rb")
end
- Deps.load_paths.unshift("#{CONSTANT_DIR}/update")
+ Deps.load_paths.unshift("#{@constant_dir}/update")
assert !Client.public_method_defined?('from_mixin')
assert Client.public_method_defined?('from_mixin_update')
end
def test_prevention_of_removal_cycle
+ load_from "double_removal"
+
# Failure of this test = SystemStackError: stack level too deep
- assert_different_object_id 'Mut::M', 'Mut::C', 'Mut' do
+ assert_different_object_id 'Ns::M', 'Ns::C', 'Ns' do
reload! do
- update("mut/m.rb")
+ update("ns/m.rb")
end
end
end
def test_nested_mixins
+ load_from "nested_mixins"
+
assert_different_object_id 'Ma::Mb::Mc', 'Ma::Mb', 'Ma' do
- reload! do
- update("ma/mb/mc.rb")
+ assert_different_object_id 'Oa::Ob::Oc', 'Oa::Ob', 'Oa' do
+ assert_same_object_id 'B::C' do
+ reload! do
+ update("ma/mb/mc.rb")
+ end
+ end
end
end
end
def test_consistency_of_activerecord_registry
- Deps.load_paths = ["#{CONSTANT_DIR}/db_models"]
+ load_from "active_record"
- fetch_detected_ar_subclasses = lambda do
+ fetch_registered_ar_subclasses = lambda do
ActiveRecord::Base.instance_eval { subclasses }.sort_by(&:name)
end
# Load initial version of the models
- assert_equal [Comment, Message, Other, Post], fetch_detected_ar_subclasses.call
+ assert_equal [Comment, Message, Other, Post], fetch_registered_ar_subclasses[]
# AR::Base subclass tree is updated
assert_different_object_id 'Message', 'Post', 'Comment' do
assert_same_object_id 'Other' do
reload! do
- update("db_models/message.rb")
+ update("message.rb")
end
end
end
- assert_equal [Comment, Message, Other, Post], fetch_detected_ar_subclasses.call
+ assert_equal [Comment, Message, Other, Post], fetch_registered_ar_subclasses[]
# Create initial references to reflection classes
assert_equal Comment, Post.new.comments.new.class
@@ -100,14 +118,14 @@ def test_consistency_of_activerecord_registry
assert_same_object_id 'Post' do
assert_different_object_id 'Comment' do
reload! do
- update("db_models/comment.rb")
+ update("comment.rb")
end
end
end
assert_equal Comment, Post.new.comments.new.class
end
-private
+protected
CONSTANT_DIR = "#{File.dirname(__FILE__)}/constants".freeze
CONSTANT_FILES = Dir.chdir(CONSTANT_DIR) { Dir.glob("**/*.rb") }.freeze
@@ -117,6 +135,7 @@ def test_consistency_of_activerecord_registry
def setup
# Cleanup
clean_up! "setup"
+ @constant_dir = CONSTANT_DIR
# Configuration
Deps.load_paths = [CONSTANT_DIR]
@@ -133,13 +152,17 @@ def teardown
private
+ def load_from(root)
+ @constant_dir = "#{CONSTANT_DIR}/#{root}"
+ Deps.load_paths = [@constant_dir]
+ end
+
def update(path)
- stub_mtime(path, File.mtime("#{CONSTANT_DIR}/#{path}") + 1)
+ stub_mtime(path, File.mtime("#{@constant_dir}/#{path}") + 1)
end
def stub_mtime(path, time=1)
- path = "#{CONSTANT_DIR}/#{path}"
- File.stubs(:mtime).with(path).returns time
+ File.stubs(:mtime).with("#{@constant_dir}/#{path}").returns time
end
def reload!
Please sign in to comment.
Something went wrong with that request. Please try again.