switchman 1.2.10 → 1.2.11

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.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/app/models/switchman/shard.rb +2 -2
  3. data/lib/switchman/active_record/connection_handler.rb +18 -9
  4. data/lib/switchman/active_record/connection_pool.rb +3 -0
  5. data/lib/switchman/active_record/query_cache.rb +6 -1
  6. data/lib/switchman/active_record/query_methods.rb +1 -1
  7. data/lib/switchman/connection_pool_proxy.rb +1 -1
  8. data/lib/switchman/r_spec_helper.rb +73 -61
  9. data/lib/switchman/test_helper.rb +8 -2
  10. data/lib/switchman/version.rb +1 -1
  11. data/lib/tasks/switchman.rake +5 -0
  12. data/spec/dummy/config/database.yml +2 -4
  13. data/spec/dummy/config/environments/development.rb +0 -4
  14. data/spec/dummy/config/environments/test.rb +1 -1
  15. data/spec/dummy/db/schema.rb +12 -12
  16. data/spec/dummy/db/shard_120.sqlite3 +0 -0
  17. data/spec/dummy/db/shard_156.sqlite3 +0 -0
  18. data/spec/dummy/db/shard_193.sqlite3 +0 -0
  19. data/spec/dummy/db/shard_23.sqlite3 +0 -0
  20. data/spec/dummy/db/shard_234.sqlite3 +0 -0
  21. data/spec/dummy/db/shard_257.sqlite3 +0 -0
  22. data/spec/dummy/db/shard_277.sqlite3 +0 -0
  23. data/spec/dummy/db/shard_311.sqlite3 +0 -0
  24. data/spec/dummy/db/shard_324.sqlite3 +0 -0
  25. data/spec/dummy/db/shard_342.sqlite3 +0 -0
  26. data/spec/dummy/db/shard_375.sqlite3 +0 -0
  27. data/spec/dummy/db/shard_389.sqlite3 +0 -0
  28. data/spec/dummy/db/shard_428.sqlite3 +0 -0
  29. data/spec/dummy/db/shard_452.sqlite3 +0 -0
  30. data/spec/dummy/db/shard_462.sqlite3 +0 -0
  31. data/spec/dummy/db/shard_483.sqlite3 +0 -0
  32. data/spec/dummy/db/shard_508.sqlite3 +0 -0
  33. data/spec/dummy/db/shard_531.sqlite3 +0 -0
  34. data/spec/dummy/db/shard_554.sqlite3 +0 -0
  35. data/spec/dummy/db/shard_577.sqlite3 +0 -0
  36. data/spec/dummy/db/shard_58.sqlite3 +0 -0
  37. data/spec/dummy/db/shard_600.sqlite3 +0 -0
  38. data/spec/dummy/db/shard_623.sqlite3 +0 -0
  39. data/spec/dummy/db/shard_646.sqlite3 +0 -0
  40. data/spec/dummy/db/shard_668.sqlite3 +0 -0
  41. data/spec/dummy/db/shard_680.sqlite3 +0 -0
  42. data/spec/dummy/db/shard_708.sqlite3 +0 -0
  43. data/spec/dummy/db/shard_735.sqlite3 +0 -0
  44. data/spec/dummy/db/shard_753.sqlite3 +0 -0
  45. data/spec/dummy/db/shard_76.sqlite3 +0 -0
  46. data/spec/dummy/db/shard_802.sqlite3 +0 -0
  47. data/spec/dummy/db/test.sqlite3 +0 -0
  48. data/spec/dummy/log/development.log +7 -0
  49. data/spec/dummy/log/test.log +106293 -0
  50. data/spec/dummy/tmp/cache/313/970/shard%2F30 +1 -0
  51. data/spec/dummy/tmp/cache/316/980/shard%2F15 +1 -0
  52. data/spec/dummy/tmp/cache/317/9D0/shard%2F52 +1 -0
  53. data/spec/dummy/tmp/cache/31C/A40/shard%2F75 +1 -0
  54. data/spec/dummy/tmp/cache/345/E00/shard%2F500 +1 -0
  55. data/spec/dummy/tmp/cache/346/DF0/shard%2F321 +1 -0
  56. data/spec/dummy/tmp/cache/349/DE0/shard%2F126 +1 -0
  57. data/spec/dummy/tmp/cache/349/E10/shard%2F153 +0 -0
  58. data/spec/dummy/tmp/cache/349/E20/shard%2F243 +1 -0
  59. data/spec/dummy/tmp/cache/34A/E20/shard%2F154 +0 -0
  60. data/spec/dummy/tmp/cache/34A/E40/shard%2F172 +1 -0
  61. data/spec/dummy/tmp/cache/34A/E70/shard%2F523 +1 -0
  62. data/spec/dummy/tmp/cache/34A/EB0/shard%2F721 +1 -0
  63. data/spec/dummy/tmp/cache/34A/EC0/shard%2F730 +1 -0
  64. data/spec/dummy/tmp/cache/34B/E40/shard%2F245 +0 -0
  65. data/spec/dummy/tmp/cache/34B/E60/shard%2F425 +1 -0
  66. data/spec/dummy/tmp/cache/34B/EC0/shard%2F722 +1 -0
  67. data/spec/dummy/tmp/cache/34C/E50/shard%2F246 +0 -0
  68. data/spec/dummy/tmp/cache/34C/E80/shard%2F273 +1 -0
  69. data/spec/dummy/tmp/cache/34C/E90/shard%2F363 +0 -0
  70. data/spec/dummy/tmp/cache/34C/E90/shard%2F444 +1 -0
  71. data/spec/dummy/tmp/cache/34C/EA0/shard%2F615 +1 -0
  72. data/spec/dummy/tmp/cache/34C/F00/shard%2F750 +1 -0
  73. data/spec/dummy/tmp/cache/34D/E80/shard%2F265 +1 -0
  74. data/spec/dummy/tmp/cache/34D/ED0/shard%2F391 +1 -0
  75. data/spec/dummy/tmp/cache/34D/EE0/shard%2F724 +1 -0
  76. data/spec/dummy/tmp/cache/34E/ED0/shard%2F383 +1 -0
  77. data/spec/dummy/tmp/cache/34E/EF0/shard%2F725 +1 -0
  78. data/spec/dummy/tmp/cache/34E/F00/shard%2F653 +1 -0
  79. data/spec/dummy/tmp/cache/34F/EE0/shard%2F546 +1 -0
  80. data/spec/dummy/tmp/cache/34F/F00/shard%2F807 +1 -0
  81. data/spec/dummy/tmp/cache/34F/F30/shard%2F672 +1 -0
  82. data/spec/dummy/tmp/cache/350/EA0/shard%2F178 +1 -0
  83. data/spec/dummy/tmp/cache/350/EB0/shard%2F349 +1 -0
  84. data/spec/dummy/tmp/cache/350/F00/shard%2F718 +0 -0
  85. data/spec/dummy/tmp/cache/350/F40/shard%2F592 +1 -0
  86. data/spec/dummy/tmp/cache/351/F00/shard%2F386 +0 -0
  87. data/spec/dummy/tmp/cache/351/F10/shard%2F638 +1 -0
  88. data/spec/dummy/tmp/cache/351/F10/shard%2F719 +0 -0
  89. data/spec/dummy/tmp/cache/352/F10/shard%2F387 +0 -0
  90. data/spec/dummy/tmp/cache/352/F10/shard%2F468 +1 -0
  91. data/spec/dummy/tmp/cache/352/F30/shard%2F729 +1 -0
  92. data/spec/dummy/tmp/cache/353/F10/shard%2F298 +1 -0
  93. data/spec/dummy/tmp/cache/353/F50/shard%2F739 +1 -0
  94. data/spec/dummy/tmp/cache/354/F50/shard%2F569 +1 -0
  95. data/spec/dummy/tmp/cache/354/F80/shard%2F677 +1 -0
  96. data/spec/dummy/tmp/cache/354/F90/shard%2F767 +1 -0
  97. data/spec/dummy/tmp/cache/358/FE0/shard%2F699 +1 -0
  98. data/spec/dummy/tmp/cache/3A5/EA0/shard%2F10004 +1 -0
  99. data/spec/dummy/tmp/cache/3A6/F40/shard%2F10410 +1 -0
  100. data/spec/dummy/tmp/cache/3A7/F30/shard%2F10231 +1 -0
  101. data/spec/dummy/tmp/cache/3A8/F90/shard%2F10520 +1 -0
  102. data/spec/dummy/tmp/cache/3A9/F40/shard%2F10062 +1 -0
  103. data/spec/dummy/tmp/cache/3A9/F80/shard%2F10341 +1 -0
  104. data/spec/dummy/tmp/cache/3AA/F10/shard%2F10027 +1 -0
  105. data/spec/dummy/tmp/cache/3AA/F10/shard%2F10108 +1 -0
  106. data/spec/dummy/tmp/cache/3AA/FB0/shard%2F10441 +1 -0
  107. data/spec/dummy/tmp/cache/3AA/FC0/shard%2F10612 +1 -0
  108. data/spec/dummy/tmp/cache/3AB/010/shard%2F10730 +1 -0
  109. data/spec/dummy/tmp/cache/3AB/F70/shard%2F10154 +1 -0
  110. data/spec/dummy/tmp/cache/3AC/020/shard%2F10650 +1 -0
  111. data/spec/dummy/tmp/cache/3AC/FC0/shard%2F10272 +1 -0
  112. data/spec/dummy/tmp/cache/3AD/000/shard%2F10543 +1 -0
  113. data/spec/dummy/tmp/cache/3AD/F50/shard%2F10039 +1 -0
  114. data/spec/dummy/tmp/cache/3AD/F90/shard%2F10318 +1 -0
  115. data/spec/dummy/tmp/cache/3AD/FA0/shard%2F10246 +1 -0
  116. data/spec/dummy/tmp/cache/3AE/060/shard%2F10751 +1 -0
  117. data/spec/dummy/tmp/cache/3AE/FF0/shard%2F10364 +1 -0
  118. data/spec/dummy/tmp/cache/3AF/030/shard%2F10635 +1 -0
  119. data/spec/dummy/tmp/cache/3B0/FE0/shard%2F10177 +1 -0
  120. data/spec/dummy/tmp/cache/3B1/030/shard%2F10295 +1 -0
  121. data/spec/dummy/tmp/cache/3B1/040/shard%2F10466 +1 -0
  122. data/spec/dummy/tmp/cache/3B1/090/shard%2F10673 +1 -0
  123. data/spec/dummy/tmp/cache/3B2/070/shard%2F10566 +1 -0
  124. data/spec/dummy/tmp/cache/3B3/060/shard%2F10387 +1 -0
  125. data/spec/dummy/tmp/cache/3B5/0B0/shard%2F10497 +1 -0
  126. data/spec/dummy/tmp/cache/3B6/100/shard%2F10696 +1 -0
  127. data/spec/dummy/tmp/cache/3B7/0E0/shard%2F10589 +1 -0
  128. data/spec/dummy/tmp/cache/3BA/160/shard%2F10799 +1 -0
  129. data/spec/lib/action_controller/caching_spec.rb +4 -4
  130. data/spec/lib/active_record/abstract_adapter_spec.rb +1 -1
  131. data/spec/lib/active_record/association_spec.rb +83 -67
  132. data/spec/lib/active_record/attribute_methods_spec.rb +29 -29
  133. data/spec/lib/active_record/base_spec.rb +20 -20
  134. data/spec/lib/active_record/calculations_spec.rb +79 -59
  135. data/spec/lib/active_record/connection_handler_spec.rb +14 -14
  136. data/spec/lib/active_record/connection_pool_spec.rb +7 -7
  137. data/spec/lib/active_record/finder_methods_spec.rb +8 -8
  138. data/spec/lib/active_record/query_cache_spec.rb +38 -38
  139. data/spec/lib/active_record/query_methods_spec.rb +45 -45
  140. data/spec/lib/active_record/relation_spec.rb +8 -8
  141. data/spec/lib/active_record/spawn_methods_spec.rb +11 -11
  142. data/spec/lib/connection_pool_proxy_spec.rb +2 -2
  143. data/spec/lib/database_server_spec.rb +37 -37
  144. data/spec/lib/default_shard_spec.rb +3 -3
  145. data/spec/lib/r_spec_helper_spec.rb +33 -7
  146. data/spec/lib/rails_spec.rb +5 -5
  147. data/spec/lib/shackles_spec.rb +35 -35
  148. data/spec/models/shard_spec.rb +104 -104
  149. data/spec/spec_helper.rb +1 -1
  150. metadata +254 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc2dfd339cd0bc006a3a5201bee157d982f3294a
4
- data.tar.gz: 122345b29537d27f0b0dd5808b4f2881af26fa9d
3
+ metadata.gz: 24a9d501ff39800e2fbc3c7bcdd58b1ed78a59fc
4
+ data.tar.gz: bd0d9bb1b19dc0ea14b5f79f44a16925283e761a
5
5
  SHA512:
6
- metadata.gz: c59075ed736d45ecf0aabfc3f7e69eab51d7920d07a423b5acd5241cdb0bbbe42b78709a6e94032d17b7aa557535f0f717a56293a7a49d927e0db9a6bf970e04
7
- data.tar.gz: 334d1fa1b0e4d1fc65aef700842597403627bfd1e6196e4987c4516ae9608637a74afbb5ded7a6e4db7c8cccd41abf9b82af91076d1de9932783263b70309f43
6
+ metadata.gz: bd6f9f98050e479013de4f449d9c1f77fe2a851c3bcec9b40701d52c6b2457e4bc3a36df12a97c1e7f9fd2f5597df11ef360233cf7403fe1aa3e6a70b7c77477
7
+ data.tar.gz: e4df60dc747f88ea8908395d01685d4a9b7a43417e4d8c915d2ae38f94b5a88a465d4ab741d242c67f0fd33778aec11cf8d698eab6dfd2c67513e95d5296f9b0
@@ -41,7 +41,7 @@ module Switchman
41
41
  active_shards.clear
42
42
 
43
43
  # Now find the actual record, if it exists; rescue the fake default if the table doesn't exist
44
- @default = Shard.find_by_default(true) || default rescue default
44
+ @default = Shard.where(default:true).first || default rescue default
45
45
  end
46
46
  @default
47
47
  end
@@ -122,7 +122,7 @@ module Switchman
122
122
  # :exception - :ignore, :raise, :defer (wait until the end and raise the first
123
123
  # error), or a proc
124
124
  def with_each_shard(*args)
125
- raise ArgumentError("wrong number of arguments (#{args.length} for 0...3)") if args.length > 3
125
+ raise ArgumentError, "wrong number of arguments (#{args.length} for 0...3)" if args.length > 3
126
126
 
127
127
  unless default.is_a?(Shard)
128
128
  return Array(yield)
@@ -4,14 +4,18 @@ require_dependency 'switchman/shard'
4
4
  module Switchman
5
5
  module ActiveRecord
6
6
  module ConnectionHandler
7
- def self.make_sharing_automagic(config, shard)
7
+ def self.make_sharing_automagic(config)
8
8
  key = config[:adapter] == 'postgresql' ? :schema_search_path : :database
9
9
 
10
- # we may not be able to connect to this shard yet, cause it might be an empty database server
11
- shard_name = shard.name rescue nil
12
- return unless shard_name
10
+ # only load the shard name from the db if we have to
11
+ if config[key] || !config[:shard_name]
12
+ # we may not be able to connect to this shard yet, cause it might be an empty database server
13
+ shard_name = Shard.current.name rescue nil
14
+ return unless shard_name
15
+
16
+ config[:shard_name] ||= shard_name
17
+ end
13
18
 
14
- config[:shard_name] ||= shard_name
15
19
  if !config[key] || config[key] == shard_name
16
20
  # this may truncate the schema_search_path if it was not specified in database.yml
17
21
  # but that's what our old behavior was anyway, so I guess it's okay
@@ -53,10 +57,12 @@ module Switchman
53
57
  Shard.default
54
58
 
55
59
  # automatically change config to allow for sharing connections with simple config
56
- ConnectionHandler.make_sharing_automagic(spec.config, Shard.default)
57
- ConnectionHandler.make_sharing_automagic(Shard.default.database_server.config, Shard.default)
60
+ ConnectionHandler.make_sharing_automagic(spec.config)
61
+ ConnectionHandler.make_sharing_automagic(Shard.default.database_server.config)
62
+
63
+ ::ActiveRecord::Base.configurations[::Rails.env] = spec.config.stringify_keys
58
64
  end
59
- @shard_connection_pools ||= { Shard.default.database_server.id => pool }
65
+ @shard_connection_pools ||= { [:master, Shard.default.database_server.shareable? ? ::Rails.env : Shard.default] => pool}
60
66
 
61
67
  proxy = ConnectionPoolProxy.new(model.shard_category,
62
68
  pool,
@@ -101,7 +107,10 @@ module Switchman
101
107
  next if server == Shard.default.database_server
102
108
  shard = server.shards.where(:name => nil).first
103
109
  shard ||= Shard.new(:database_server => server)
104
- ConnectionHandler.make_sharing_automagic(server.config, shard)
110
+ shard.activate do
111
+ ConnectionHandler.make_sharing_automagic(server.config)
112
+ ConnectionHandler.make_sharing_automagic(proxy.current_pool.spec.config)
113
+ end
105
114
  end
106
115
  end
107
116
  # we may have established some connections above trying to infer the shard's name.
@@ -24,6 +24,9 @@ module Switchman
24
24
  def checkout_new_connection_with_sharding
25
25
  # TODO: this might be a threading issue
26
26
  spec.config[:shard_name] = self.shard.name
27
+ if self.shard.database_server.id == ::Rails.env
28
+ ::ActiveRecord::Base.configurations[::Rails.env] = spec.config.stringify_keys
29
+ end
27
30
 
28
31
  conn = checkout_new_connection_without_sharding
29
32
  conn.shard = self.shard
@@ -51,6 +51,7 @@ module Switchman
51
51
 
52
52
  def select_all(arel, name = nil, binds = [])
53
53
  if self.query_cache_enabled && !locked?(arel)
54
+ arel, binds = binds_from_relation(arel, binds) unless ::Rails.version < '4'
54
55
  sql = to_sql(arel, binds)
55
56
  cache_sql(sql, binds) { super(sql, name, binds) }
56
57
  else
@@ -83,7 +84,11 @@ module Switchman
83
84
  query_cache[sql][binds] = yield
84
85
  end
85
86
 
86
- result.collect { |row| row.dup }
87
+ if ::ActiveRecord::Result === result
88
+ result.dup
89
+ else
90
+ result.collect { |row| row.dup }
91
+ end
87
92
  end
88
93
 
89
94
  def self.included(base)
@@ -93,7 +93,7 @@ module Switchman
93
93
  when ::ActiveRecord::Relation
94
94
  Shard.default
95
95
  else
96
- raise ArgumentError("invalid shard value #{shard_value}")
96
+ raise ArgumentError, "invalid shard value #{shard_value}"
97
97
  end
98
98
  end
99
99
 
@@ -32,7 +32,7 @@ module Switchman
32
32
  end
33
33
 
34
34
  def current_pool
35
- pool = self.default_pool if active_shard.database_server == Shard.default.database_server && active_shackles_environment == :master && active_shard.database_server.shareable?
35
+ pool = self.default_pool if active_shard.database_server == Shard.default.database_server && active_shackles_environment == :master && (active_shard == Shard.default || active_shard.database_server.shareable?)
36
36
  pool = @connection_pools[pool_key] ||= create_pool unless pool
37
37
  pool.shard = active_shard
38
38
  pool
@@ -13,73 +13,88 @@ module Switchman
13
13
  @@keep_the_shards = false
14
14
  @@shard1 = nil
15
15
 
16
+ def self.included_in?(klass)
17
+ klass.parent_groups.any? { |group| group.included_modules.include?(self) }
18
+ end
19
+
16
20
  def self.included(klass)
17
21
  # our before handlers have already been configured from a parent group; don't add them again
18
- return if klass.parent_groups[1..-1].any? { |group| group.included_modules.include?(self) }
22
+ parent_group = klass.parent_groups[1]
23
+ return if parent_group && included_in?(parent_group)
19
24
 
20
- klass.before(:all) do
21
- unless @@shard1
22
- puts "Setting up sharding for all specs..."
23
- Shard.delete_all
25
+ # set up sharding schemas/dbs before the root group runs, so that
26
+ # they persist across transactional groups (e.g. once-ler)
27
+ root_group = klass.parent_groups.last
28
+ root_group.prepend_before(:all) do |group|
29
+ next if @@shard1
30
+ # if we aren't actually going to run a sharding group/example,
31
+ # don't set it up after all
32
+ groups = group.class.descendant_filtered_examples.map(&:example_group).uniq
33
+ next unless groups.any?{ |group| RSpecHelper.included_in?(group) }
24
34
 
25
- @@shard1, @@shard2 = TestHelper.recreate_persistent_test_shards
26
- @@default_shard = Shard.default
27
- if @@shard1.is_a?(Shard)
28
- @@keep_the_shards = true
29
- @@shard3 = nil
30
- else # @@shard1.is_a?(DatabaseServer)
31
- begin
32
- @@shard1 = @@shard1.create_new_shard
33
- @@shard2 = @@shard2.create_new_shard
34
- if @@shard1.database_server == Shard.default.database_server
35
- @@shard3 = nil
36
- else
37
- @@shard3 = @@shard1.database_server.create_new_shard
38
- end
39
- rescue
40
- @@shard1 = @@shard2 = @@shard3 = nil
41
- raise
35
+ puts "Setting up sharding for all specs..."
36
+ Shard.delete_all
37
+
38
+ @@shard1, @@shard2 = TestHelper.recreate_persistent_test_shards
39
+ @@default_shard = Shard.default
40
+ if @@shard1.is_a?(Shard)
41
+ @@keep_the_shards = true
42
+ @@shard3 = nil
43
+ else # @@shard1.is_a?(DatabaseServer)
44
+ begin
45
+ @@shard1 = @@shard1.create_new_shard
46
+ @@shard2 = @@shard2.create_new_shard
47
+ if @@shard1.database_server == Shard.default.database_server
48
+ @@shard3 = nil
49
+ else
50
+ @@shard3 = @@shard1.database_server.create_new_shard
42
51
  end
52
+ rescue
53
+ @@shard1 = @@shard2 = @@shard3 = nil
54
+ raise
43
55
  end
44
- puts "Done!"
56
+ end
57
+ # we'll re-persist in the group's `before :all`; we don't want them to exist
58
+ # in the db before then
59
+ Shard.delete_all
60
+ Shard.default(true)
61
+ puts "Done!"
45
62
 
46
- at_exit do
47
- # preserve rspec's exit status
48
- status= $!.is_a?(::SystemExit) ? $!.status : nil
49
- puts "Tearing down sharding for all specs"
50
- @@shard1.database_server.destroy unless @@shard1.database_server == Shard.default.database_server
51
- unless @@keep_the_shards
52
- @@shard1.drop_database
53
- @@shard1.destroy
54
- @@shard2.drop_database
55
- @@shard2.destroy
56
- if @@shard3
57
- @@shard3.drop_database
58
- @@shard3.destroy
59
- end
63
+ at_exit do
64
+ # preserve rspec's exit status
65
+ status= $!.is_a?(::SystemExit) ? $!.status : nil
66
+ puts "Tearing down sharding for all specs"
67
+ @@shard1.database_server.destroy unless @@shard1.database_server == Shard.default.database_server
68
+ unless @@keep_the_shards
69
+ @@shard1.drop_database
70
+ @@shard1.destroy
71
+ @@shard2.drop_database
72
+ @@shard2.destroy
73
+ if @@shard3
74
+ @@shard3.drop_database
75
+ @@shard3.destroy
60
76
  end
61
- @@shard2.database_server.destroy
62
- exit status if status
63
77
  end
64
- else
65
- dup = @@default_shard.dup
66
- dup.id = @@default_shard.id
67
- dup.save!
68
- Shard.default(true)
69
- dup = @@shard1.dup
70
- dup.id = @@shard1.id
71
- dup.save!
72
- @@shard1.instance_variable_set(:@destroyed, false)
73
- dup = @@shard2.dup
74
- dup.id = @@shard2.id
78
+ @@shard2.database_server.destroy
79
+ exit status if status
80
+ end
81
+ end
82
+
83
+ klass.before(:all) do
84
+ dup = @@default_shard.dup
85
+ dup.id = @@default_shard.id
86
+ dup.save!
87
+ Shard.default(true)
88
+ dup = @@shard1.dup
89
+ dup.id = @@shard1.id
90
+ dup.save!
91
+ dup = @@shard2.dup
92
+ dup.id = @@shard2.id
93
+ dup.save!
94
+ if @@shard3
95
+ dup = @@shard3.dup
96
+ dup.id = @@shard3.id
75
97
  dup.save!
76
- @@shard2.instance_variable_set(:@destroyed, false)
77
- if @@shard3
78
- dup = @@shard3.dup
79
- dup.id = @@shard3.id
80
- dup.save!
81
- @@shard3.instance_variable_set(:@destroyed, false)
82
- end
83
98
  end
84
99
  @shard1, @shard2 = @@shard1, @@shard2
85
100
  @shard3 = @@shard3 ? @@shard3 : Shard.default
@@ -137,10 +152,7 @@ module Switchman
137
152
  end
138
153
 
139
154
  klass.after(:all) do
140
- Shard.default.destroy
141
- @@shard1.destroy
142
- @@shard2.destroy
143
- @@shard3.destroy if @@shard3
155
+ Shard.delete_all
144
156
  Shard.default(true)
145
157
  end
146
158
  end
@@ -1,14 +1,14 @@
1
1
  module Switchman
2
2
  module TestHelper
3
3
  class << self
4
- def recreate_persistent_test_shards
4
+ def recreate_persistent_test_shards(options = {})
5
5
  # recreate the default shard (it got buhleted)
6
6
  if Shard.default(true).is_a?(DefaultShard)
7
7
  begin
8
8
  Shard.create!(default: true)
9
9
  rescue
10
10
  # database doesn't exist yet, presumably cause we're creating it right now
11
- [nil, nil]
11
+ return [nil, nil]
12
12
  end
13
13
  Shard.default(true)
14
14
  end
@@ -37,6 +37,12 @@ module Switchman
37
37
 
38
38
  recreate_shards = shard1.activate { ::ActiveRecord::Base.connection.tables == [] }
39
39
  if recreate_shards
40
+ if options[:dont_create]
41
+ shard1.destroy
42
+ shard2.destroy
43
+ return [nil, nil]
44
+ end
45
+
40
46
  shard1.drop_database rescue nil
41
47
  shard1.destroy
42
48
  shard2.drop_database rescue nil
@@ -1,3 +1,3 @@
1
1
  module Switchman
2
- VERSION = "1.2.10"
2
+ VERSION = "1.2.11"
3
3
  end
@@ -5,6 +5,11 @@ module Switchman
5
5
  old_task.actions.clear
6
6
 
7
7
  old_task.enhance do
8
+ if ::Rails.env.test?
9
+ require 'switchman/test_helper'
10
+ TestHelper.recreate_persistent_test_shards(dont_create: true)
11
+ end
12
+
8
13
  ::Shackles.activate(:deploy) do
9
14
 
10
15
  scope = Shard.order("database_server_id IS NOT NULL, database_server_id, id")
@@ -11,10 +11,8 @@ development:
11
11
  # re-generated from your development database when you run "rake".
12
12
  # Do not set this db to the same as development or production.
13
13
  test:
14
- adapter: sqlite3
15
- database: db/test.sqlite3
16
- pool: 5
17
- timeout: 5000
14
+ adapter: postgresql
15
+ database: switchman_test
18
16
 
19
17
  production:
20
18
  adapter: sqlite3
@@ -16,10 +16,6 @@ Dummy::Application.configure do
16
16
  # Only use best-standards-support built into browsers
17
17
  config.action_dispatch.best_standards_support = :builtin
18
18
 
19
- # Log the query plan for queries taking more than this (works
20
- # with SQLite, MySQL, and PostgreSQL)
21
- config.active_record.auto_explain_threshold_in_seconds = 0.5
22
-
23
19
  # Do not compress assets
24
20
  config.assets.compress = false
25
21
 
@@ -24,5 +24,5 @@ Dummy::Application.configure do
24
24
  # Print deprecation notices to the stderr
25
25
  config.active_support.deprecation = :stderr
26
26
 
27
- config.eager_load = false
27
+ config.eager_load = true
28
28
  end
@@ -19,35 +19,35 @@ ActiveRecord::Schema.define(version: 20140219183820) do
19
19
  create_table "appendages", force: true do |t|
20
20
  t.integer "user_id", limit: 8
21
21
  t.integer "value"
22
- t.datetime "created_at"
23
- t.datetime "updated_at"
22
+ t.datetime "created_at", null: false
23
+ t.datetime "updated_at", null: false
24
24
  end
25
25
 
26
26
  create_table "digits", force: true do |t|
27
27
  t.integer "appendage_id", limit: 8
28
28
  t.integer "value"
29
- t.datetime "created_at"
30
- t.datetime "updated_at"
29
+ t.datetime "created_at", null: false
30
+ t.datetime "updated_at", null: false
31
31
  end
32
32
 
33
33
  create_table "features", force: true do |t|
34
34
  t.integer "owner_id", limit: 8
35
35
  t.string "owner_type"
36
36
  t.integer "value"
37
- t.datetime "created_at"
38
- t.datetime "updated_at"
37
+ t.datetime "created_at", null: false
38
+ t.datetime "updated_at", null: false
39
39
  end
40
40
 
41
41
  create_table "mirror_users", force: true do |t|
42
42
  t.integer "user_id", limit: 8
43
- t.datetime "created_at"
44
- t.datetime "updated_at"
43
+ t.datetime "created_at", null: false
44
+ t.datetime "updated_at", null: false
45
45
  end
46
46
 
47
47
  create_table "roots", force: true do |t|
48
48
  t.integer "user_id", limit: 8
49
- t.datetime "created_at"
50
- t.datetime "updated_at"
49
+ t.datetime "created_at", null: false
50
+ t.datetime "updated_at", null: false
51
51
  end
52
52
 
53
53
  create_table "switchman_shards", force: true do |t|
@@ -59,8 +59,8 @@ ActiveRecord::Schema.define(version: 20140219183820) do
59
59
  create_table "users", force: true do |t|
60
60
  t.string "name"
61
61
  t.integer "mirror_user_id", limit: 8
62
- t.datetime "created_at"
63
- t.datetime "updated_at"
62
+ t.datetime "created_at", null: false
63
+ t.datetime "updated_at", null: false
64
64
  t.integer "parent_id", limit: 8
65
65
  end
66
66