warp-thinking-sphinx 1.2.12 → 1.3.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. data/README.textile +21 -4
  2. data/VERSION +1 -0
  3. data/features/abstract_inheritance.feature +10 -0
  4. data/features/alternate_primary_key.feature +1 -1
  5. data/features/attribute_updates.feature +22 -5
  6. data/features/deleting_instances.feature +3 -0
  7. data/features/facets.feature +6 -0
  8. data/features/facets_across_model.feature +2 -2
  9. data/features/searching_across_models.feature +1 -1
  10. data/features/searching_by_index.feature +40 -0
  11. data/features/sphinx_scopes.feature +7 -0
  12. data/features/step_definitions/alpha_steps.rb +14 -1
  13. data/features/step_definitions/beta_steps.rb +1 -1
  14. data/features/step_definitions/common_steps.rb +12 -2
  15. data/features/step_definitions/facet_steps.rb +5 -1
  16. data/features/step_definitions/scope_steps.rb +4 -0
  17. data/features/step_definitions/sphinx_steps.rb +8 -4
  18. data/features/sti_searching.feature +5 -0
  19. data/features/support/{db/database.example.yml → database.example.yml} +0 -0
  20. data/features/support/db/fixtures/foxes.rb +3 -0
  21. data/features/support/db/fixtures/music.rb +4 -0
  22. data/features/support/db/fixtures/robots.rb +1 -1
  23. data/features/support/db/fixtures/tags.rb +1 -1
  24. data/features/support/db/migrations/create_alphas.rb +1 -0
  25. data/features/support/db/migrations/create_genres.rb +3 -0
  26. data/features/support/db/migrations/create_music.rb +6 -0
  27. data/features/support/db/migrations/create_robots.rb +1 -2
  28. data/features/support/env.rb +16 -1
  29. data/features/support/models/alpha.rb +12 -0
  30. data/features/support/models/comment.rb +3 -3
  31. data/features/support/models/fox.rb +5 -0
  32. data/features/support/models/genre.rb +3 -0
  33. data/features/support/models/medium.rb +5 -0
  34. data/features/support/models/music.rb +8 -0
  35. data/features/support/models/post.rb +2 -1
  36. data/features/support/models/robot.rb +4 -0
  37. data/lib/cucumber/thinking_sphinx/external_world.rb +8 -0
  38. data/lib/cucumber/thinking_sphinx/internal_world.rb +126 -0
  39. data/lib/cucumber/thinking_sphinx/sql_logger.rb +20 -0
  40. data/lib/thinking_sphinx.rb +56 -37
  41. data/lib/thinking_sphinx/active_record.rb +257 -192
  42. data/lib/thinking_sphinx/active_record/attribute_updates.rb +10 -12
  43. data/lib/thinking_sphinx/active_record/delta.rb +0 -26
  44. data/lib/thinking_sphinx/active_record/scopes.rb +37 -1
  45. data/lib/thinking_sphinx/adapters/mysql_adapter.rb +1 -1
  46. data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +18 -11
  47. data/lib/thinking_sphinx/attribute.rb +19 -4
  48. data/lib/thinking_sphinx/auto_version.rb +22 -0
  49. data/lib/thinking_sphinx/configuration.rb +57 -59
  50. data/lib/thinking_sphinx/context.rb +74 -0
  51. data/lib/thinking_sphinx/deltas.rb +0 -2
  52. data/lib/thinking_sphinx/deltas/default_delta.rb +14 -20
  53. data/lib/thinking_sphinx/deploy/capistrano.rb +1 -1
  54. data/lib/thinking_sphinx/facet_search.rb +3 -1
  55. data/lib/thinking_sphinx/index.rb +77 -19
  56. data/lib/thinking_sphinx/index/builder.rb +2 -2
  57. data/lib/thinking_sphinx/search.rb +47 -9
  58. data/lib/thinking_sphinx/search_methods.rb +22 -4
  59. data/lib/thinking_sphinx/source.rb +9 -8
  60. data/lib/thinking_sphinx/source/sql.rb +5 -3
  61. data/lib/thinking_sphinx/tasks.rb +13 -57
  62. data/lib/thinking_sphinx/test.rb +52 -0
  63. data/rails/init.rb +4 -2
  64. data/spec/{lib/thinking_sphinx → thinking_sphinx}/active_record/delta_spec.rb +4 -6
  65. data/spec/{lib/thinking_sphinx → thinking_sphinx}/active_record/has_many_association_spec.rb +0 -0
  66. data/spec/thinking_sphinx/active_record/scopes_spec.rb +177 -0
  67. data/spec/thinking_sphinx/active_record_spec.rb +622 -0
  68. data/spec/{lib/thinking_sphinx → thinking_sphinx}/association_spec.rb +0 -0
  69. data/spec/{lib/thinking_sphinx → thinking_sphinx}/attribute_spec.rb +39 -0
  70. data/spec/thinking_sphinx/auto_version_spec.rb +39 -0
  71. data/spec/{lib/thinking_sphinx → thinking_sphinx}/configuration_spec.rb +27 -61
  72. data/spec/thinking_sphinx/context_spec.rb +119 -0
  73. data/spec/{lib/thinking_sphinx → thinking_sphinx}/core/array_spec.rb +0 -0
  74. data/spec/{lib/thinking_sphinx → thinking_sphinx}/core/string_spec.rb +0 -0
  75. data/spec/{lib/thinking_sphinx → thinking_sphinx}/excerpter_spec.rb +0 -0
  76. data/spec/{lib/thinking_sphinx → thinking_sphinx}/facet_search_spec.rb +0 -0
  77. data/spec/{lib/thinking_sphinx → thinking_sphinx}/facet_spec.rb +0 -0
  78. data/spec/{lib/thinking_sphinx → thinking_sphinx}/field_spec.rb +0 -0
  79. data/spec/{lib/thinking_sphinx → thinking_sphinx}/index/builder_spec.rb +24 -0
  80. data/spec/{lib/thinking_sphinx → thinking_sphinx}/index/faux_column_spec.rb +0 -0
  81. data/spec/thinking_sphinx/index_spec.rb +183 -0
  82. data/spec/{lib/thinking_sphinx → thinking_sphinx}/rails_additions_spec.rb +0 -0
  83. data/spec/{lib/thinking_sphinx → thinking_sphinx}/search_methods_spec.rb +0 -0
  84. data/spec/{lib/thinking_sphinx → thinking_sphinx}/search_spec.rb +41 -0
  85. data/spec/{lib/thinking_sphinx → thinking_sphinx}/source_spec.rb +1 -1
  86. data/spec/thinking_sphinx_spec.rb +204 -0
  87. data/tasks/distribution.rb +6 -20
  88. data/tasks/testing.rb +8 -19
  89. metadata +117 -142
  90. data/VERSION.yml +0 -4
  91. data/features/a.rb +0 -17
  92. data/features/datetime_deltas.feature +0 -66
  93. data/features/delayed_delta_indexing.feature +0 -37
  94. data/features/step_definitions/datetime_delta_steps.rb +0 -15
  95. data/features/step_definitions/delayed_delta_indexing_steps.rb +0 -7
  96. data/features/support/db/active_record.rb +0 -40
  97. data/features/support/db/fixtures/delayed_betas.rb +0 -10
  98. data/features/support/db/fixtures/thetas.rb +0 -10
  99. data/features/support/db/migrations/create_delayed_betas.rb +0 -17
  100. data/features/support/db/migrations/create_thetas.rb +0 -5
  101. data/features/support/db/mysql.rb +0 -3
  102. data/features/support/db/postgresql.rb +0 -3
  103. data/features/support/models/delayed_beta.rb +0 -7
  104. data/features/support/models/theta.rb +0 -7
  105. data/features/support/post_database.rb +0 -43
  106. data/features/support/z.rb +0 -19
  107. data/lib/thinking_sphinx/deltas/datetime_delta.rb +0 -50
  108. data/lib/thinking_sphinx/deltas/delayed_delta.rb +0 -30
  109. data/lib/thinking_sphinx/deltas/delayed_delta/delta_job.rb +0 -24
  110. data/lib/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job.rb +0 -27
  111. data/lib/thinking_sphinx/deltas/delayed_delta/job.rb +0 -26
  112. data/spec/lib/thinking_sphinx/active_record/scopes_spec.rb +0 -96
  113. data/spec/lib/thinking_sphinx/active_record_spec.rb +0 -353
  114. data/spec/lib/thinking_sphinx/deltas/job_spec.rb +0 -32
  115. data/spec/lib/thinking_sphinx/index_spec.rb +0 -45
  116. data/spec/lib/thinking_sphinx_spec.rb +0 -162
  117. data/vendor/after_commit/LICENSE +0 -20
  118. data/vendor/after_commit/README +0 -16
  119. data/vendor/after_commit/Rakefile +0 -22
  120. data/vendor/after_commit/init.rb +0 -8
  121. data/vendor/after_commit/lib/after_commit.rb +0 -45
  122. data/vendor/after_commit/lib/after_commit/active_record.rb +0 -114
  123. data/vendor/after_commit/lib/after_commit/connection_adapters.rb +0 -103
  124. data/vendor/after_commit/test/after_commit_test.rb +0 -53
  125. data/vendor/delayed_job/lib/delayed/job.rb +0 -251
  126. data/vendor/delayed_job/lib/delayed/message_sending.rb +0 -7
  127. data/vendor/delayed_job/lib/delayed/performable_method.rb +0 -55
  128. data/vendor/delayed_job/lib/delayed/worker.rb +0 -54
  129. data/vendor/riddle/lib/riddle.rb +0 -30
  130. data/vendor/riddle/lib/riddle/client.rb +0 -635
  131. data/vendor/riddle/lib/riddle/client/filter.rb +0 -53
  132. data/vendor/riddle/lib/riddle/client/message.rb +0 -66
  133. data/vendor/riddle/lib/riddle/client/response.rb +0 -84
  134. data/vendor/riddle/lib/riddle/configuration.rb +0 -33
  135. data/vendor/riddle/lib/riddle/configuration/distributed_index.rb +0 -48
  136. data/vendor/riddle/lib/riddle/configuration/index.rb +0 -142
  137. data/vendor/riddle/lib/riddle/configuration/indexer.rb +0 -19
  138. data/vendor/riddle/lib/riddle/configuration/remote_index.rb +0 -17
  139. data/vendor/riddle/lib/riddle/configuration/searchd.rb +0 -25
  140. data/vendor/riddle/lib/riddle/configuration/section.rb +0 -43
  141. data/vendor/riddle/lib/riddle/configuration/source.rb +0 -23
  142. data/vendor/riddle/lib/riddle/configuration/sql_source.rb +0 -34
  143. data/vendor/riddle/lib/riddle/configuration/xml_source.rb +0 -28
  144. data/vendor/riddle/lib/riddle/controller.rb +0 -53
@@ -1,32 +0,0 @@
1
- require 'spec/spec_helper'
2
-
3
- describe ThinkingSphinx::Deltas::Job do
4
- describe '.cancel_thinking_sphinx_jobs' do
5
- before :each do
6
- ThinkingSphinx::Deltas::Job.stub!(:delete_all => true)
7
- end
8
-
9
- it "should not delete any rows if the delayed_jobs table does not exist" do
10
- ThinkingSphinx::Deltas::Job.connection.stub!(:tables => [])
11
- ThinkingSphinx::Deltas::Job.should_not_receive(:delete_all)
12
-
13
- ThinkingSphinx::Deltas::Job.cancel_thinking_sphinx_jobs
14
- end
15
-
16
- it "should delete rows if the delayed_jobs table does exist" do
17
- ThinkingSphinx::Deltas::Job.connection.stub!(:tables => ['delayed_jobs'])
18
- ThinkingSphinx::Deltas::Job.should_receive(:delete_all)
19
-
20
- ThinkingSphinx::Deltas::Job.cancel_thinking_sphinx_jobs
21
- end
22
-
23
- it "should delete only Thinking Sphinx jobs" do
24
- ThinkingSphinx::Deltas::Job.connection.stub!(:tables => ['delayed_jobs'])
25
- ThinkingSphinx::Deltas::Job.should_receive(:delete_all) do |sql|
26
- sql.should match(/handler LIKE '--- !ruby\/object:ThinkingSphinx::Deltas::\%'/)
27
- end
28
-
29
- ThinkingSphinx::Deltas::Job.cancel_thinking_sphinx_jobs
30
- end
31
- end
32
- end
@@ -1,45 +0,0 @@
1
- require 'spec/spec_helper'
2
-
3
- describe ThinkingSphinx::Index do
4
- describe "prefix_fields method" do
5
- before :each do
6
- @index = ThinkingSphinx::Index.new(Person)
7
-
8
- @field_a = stub('field', :prefixes => true)
9
- @field_b = stub('field', :prefixes => false)
10
- @field_c = stub('field', :prefixes => true)
11
-
12
- @index.stub!(:fields => [@field_a, @field_b, @field_c])
13
- end
14
-
15
- it "should return fields that are flagged as prefixed" do
16
- @index.prefix_fields.should include(@field_a)
17
- @index.prefix_fields.should include(@field_c)
18
- end
19
-
20
- it "should not return fields that aren't flagged as prefixed" do
21
- @index.prefix_fields.should_not include(@field_b)
22
- end
23
- end
24
-
25
- describe "infix_fields method" do
26
- before :each do
27
- @index = ThinkingSphinx::Index.new(Person)
28
-
29
- @field_a = stub('field', :infixes => true)
30
- @field_b = stub('field', :infixes => false)
31
- @field_c = stub('field', :infixes => true)
32
-
33
- @index.stub!(:fields => [@field_a, @field_b, @field_c])
34
- end
35
-
36
- it "should return fields that are flagged as infixed" do
37
- @index.infix_fields.should include(@field_a)
38
- @index.infix_fields.should include(@field_c)
39
- end
40
-
41
- it "should not return fields that aren't flagged as infixed" do
42
- @index.infix_fields.should_not include(@field_b)
43
- end
44
- end
45
- end
@@ -1,162 +0,0 @@
1
- require 'spec/spec_helper'
2
-
3
- describe ThinkingSphinx do
4
- it "should define indexes by default" do
5
- ThinkingSphinx.define_indexes?.should be_true
6
- end
7
-
8
- it "should disable index definition" do
9
- ThinkingSphinx.define_indexes = false
10
- ThinkingSphinx.define_indexes?.should be_false
11
- end
12
-
13
- it "should enable index definition" do
14
- ThinkingSphinx.define_indexes = false
15
- ThinkingSphinx.define_indexes?.should be_false
16
- ThinkingSphinx.define_indexes = true
17
- ThinkingSphinx.define_indexes?.should be_true
18
- end
19
-
20
- it "should index deltas by default" do
21
- ThinkingSphinx.deltas_enabled = nil
22
- ThinkingSphinx.deltas_enabled?.should be_true
23
- end
24
-
25
- it "should disable delta indexing" do
26
- ThinkingSphinx.deltas_enabled = false
27
- ThinkingSphinx.deltas_enabled?.should be_false
28
- end
29
-
30
- it "should enable delta indexing" do
31
- ThinkingSphinx.deltas_enabled = false
32
- ThinkingSphinx.deltas_enabled?.should be_false
33
- ThinkingSphinx.deltas_enabled = true
34
- ThinkingSphinx.deltas_enabled?.should be_true
35
- end
36
-
37
- it "should update indexes by default" do
38
- ThinkingSphinx.updates_enabled = nil
39
- ThinkingSphinx.updates_enabled?.should be_true
40
- end
41
-
42
- it "should disable index updating" do
43
- ThinkingSphinx.updates_enabled = false
44
- ThinkingSphinx.updates_enabled?.should be_false
45
- end
46
-
47
- it "should enable index updating" do
48
- ThinkingSphinx.updates_enabled = false
49
- ThinkingSphinx.updates_enabled?.should be_false
50
- ThinkingSphinx.updates_enabled = true
51
- ThinkingSphinx.updates_enabled?.should be_true
52
- end
53
-
54
- it "should always say Sphinx is running if flagged as being on a remote machine" do
55
- ThinkingSphinx.remote_sphinx = true
56
- ThinkingSphinx.stub!(:sphinx_running_by_pid? => false)
57
-
58
- ThinkingSphinx.sphinx_running?.should be_true
59
- end
60
-
61
- it "should actually pay attention to Sphinx if not on a remote machine" do
62
- ThinkingSphinx.remote_sphinx = false
63
- ThinkingSphinx.stub!(:sphinx_running_by_pid? => false)
64
- ThinkingSphinx.sphinx_running?.should be_false
65
-
66
- ThinkingSphinx.stub!(:sphinx_running_by_pid? => true)
67
- ThinkingSphinx.sphinx_running?.should be_true
68
- end
69
-
70
- describe '.version' do
71
- it "should return the version from the stored YAML file" do
72
- version = Jeweler::VersionHelper.new(
73
- File.join(File.dirname(__FILE__), '../..')
74
- ).to_s
75
-
76
- ThinkingSphinx.version.should == version
77
- end
78
- end
79
-
80
- describe "use_group_by_shortcut? method" do
81
- before :each do
82
- adapter = defined?(JRUBY_VERSION) ? :JdbcAdapter : :MysqlAdapter
83
- unless ::ActiveRecord::ConnectionAdapters.const_defined?(adapter)
84
- pending "No MySQL"
85
- return
86
- end
87
-
88
- @connection = stub('adapter',
89
- :select_all => true,
90
- :class => ActiveRecord::ConnectionAdapters::MysqlAdapter,
91
- :config => {:adapter => defined?(JRUBY_VERSION) ? 'jdbcmysql' : 'mysql'}
92
- )
93
- ::ActiveRecord::Base.stub!(
94
- :connection => @connection
95
- )
96
- end
97
-
98
- it "should return true if no ONLY_FULL_GROUP_BY" do
99
- @connection.stub!(
100
- :select_all => {:a => "OTHER SETTINGS"}
101
- )
102
-
103
- ThinkingSphinx.use_group_by_shortcut?.should be_true
104
- end
105
-
106
- it "should return true if NULL value" do
107
- @connection.stub!(
108
- :select_all => {:a => nil}
109
- )
110
-
111
- ThinkingSphinx.use_group_by_shortcut?.should be_true
112
- end
113
-
114
- it "should return false if ONLY_FULL_GROUP_BY is set" do
115
- @connection.stub!(
116
- :select_all => {:a => "OTHER SETTINGS,ONLY_FULL_GROUP_BY,blah"}
117
- )
118
-
119
- ThinkingSphinx.use_group_by_shortcut?.should be_false
120
- end
121
-
122
- it "should return false if ONLY_FULL_GROUP_BY is set in any of the values" do
123
- @connection.stub!(
124
- :select_all => {
125
- :a => "OTHER SETTINGS",
126
- :b => "ONLY_FULL_GROUP_BY"
127
- }
128
- )
129
-
130
- ThinkingSphinx.use_group_by_shortcut?.should be_false
131
- end
132
-
133
- describe "if not using MySQL" do
134
- before :each do
135
- adapter = defined?(JRUBY_VERSION) ? 'JdbcAdapter' : 'PostgreSQLAdapter'
136
- unless ::ActiveRecord::ConnectionAdapters.const_defined?(adapter)
137
- pending "No PostgreSQL"
138
- return
139
- end
140
-
141
- @connection = stub(adapter).as_null_object
142
- @connection.stub!(
143
- :select_all => true,
144
- :config => {:adapter => defined?(JRUBY_VERSION) ? 'jdbcpostgresql' : 'postgresql'}
145
- )
146
- ::ActiveRecord::Base.stub!(
147
- :connection => @connection
148
- )
149
- end
150
-
151
- it "should return false" do
152
- ThinkingSphinx.use_group_by_shortcut?.should be_false
153
- end
154
-
155
- it "should not call select_all" do
156
- @connection.should_not_receive(:select_all)
157
-
158
- ThinkingSphinx.use_group_by_shortcut?
159
- end
160
- end
161
- end
162
- end
@@ -1,20 +0,0 @@
1
- Copyright (c) 2008 Nick Muerdter
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,16 +0,0 @@
1
- after_commit
2
- ===========
3
-
4
- A Ruby on Rails plugin to add after_commit callbacks. The callbacks that are provided can be used
5
- to trigger events that run only after the entire transaction is complete. This is beneficial
6
- in situations where you are doing asynchronous processing and need committed objects.
7
-
8
- The following callbacks are provided:
9
-
10
- * (1) after_commit
11
- * (2) after_commit_on_create
12
- * (3) after_commit_on_update
13
- * (4) after_commit_on_destroy
14
-
15
- The after_commit callback is run for any object that has just been committed. You can obtain finer
16
- callback control by using the additional <tt>after_commit_on_*</tt> callbacks.
@@ -1,22 +0,0 @@
1
- require 'rake'
2
- require 'rake/testtask'
3
- require 'rake/rdoctask'
4
-
5
- desc 'Default: run unit tests.'
6
- task :default => :test
7
-
8
- desc 'Test the after_commit plugin.'
9
- Rake::TestTask.new(:test) do |t|
10
- t.libs << 'lib'
11
- t.pattern = 'test/**/*_test.rb'
12
- t.verbose = true
13
- end
14
-
15
- desc 'Generate documentation for the after_commit plugin.'
16
- Rake::RDocTask.new(:rdoc) do |rdoc|
17
- rdoc.rdoc_dir = 'rdoc'
18
- rdoc.title = 'AfterCommit'
19
- rdoc.options << '--line-numbers' << '--inline-source'
20
- rdoc.rdoc_files.include('README')
21
- rdoc.rdoc_files.include('lib/**/*.rb')
22
- end
@@ -1,8 +0,0 @@
1
- ActiveRecord::Base.send(:include, AfterCommit::ActiveRecord)
2
-
3
- Object.subclasses_of(ActiveRecord::ConnectionAdapters::AbstractAdapter).each do |klass|
4
- klass.send(:include, AfterCommit::ConnectionAdapters)
5
- end
6
- if defined?(JRUBY_VERSION) and defined?(JdbcSpec::MySQL)
7
- JdbcSpec::MySQL.send :include, AfterCommit::ConnectionAdapters
8
- end
@@ -1,45 +0,0 @@
1
- require 'after_commit/active_record'
2
- require 'after_commit/connection_adapters'
3
-
4
- module AfterCommit
5
- def self.committed_records
6
- @@committed_records ||= []
7
- end
8
-
9
- def self.committed_records=(committed_records)
10
- @@committed_records = committed_records
11
- end
12
-
13
- def self.committed_records_on_create
14
- @@committed_records_on_create ||= []
15
- end
16
-
17
- def self.committed_records_on_create=(committed_records)
18
- @@committed_records_on_create = committed_records
19
- end
20
-
21
- def self.committed_records_on_update
22
- @@committed_records_on_update ||= []
23
- end
24
-
25
- def self.committed_records_on_update=(committed_records)
26
- @@committed_records_on_update = committed_records
27
- end
28
-
29
- def self.committed_records_on_destroy
30
- @@committed_records_on_destroy ||= []
31
- end
32
-
33
- def self.committed_records_on_destroy=(committed_records)
34
- @@committed_records_on_destroy = committed_records
35
- end
36
- end
37
-
38
- ActiveRecord::Base.send(:include, AfterCommit::ActiveRecord)
39
-
40
- Object.subclasses_of(ActiveRecord::ConnectionAdapters::AbstractAdapter).each do |klass|
41
- klass.send(:include, AfterCommit::ConnectionAdapters)
42
- end
43
- if defined?(JRUBY_VERSION) and defined?(JdbcSpec::MySQL)
44
- JdbcSpec::MySQL.send :include, AfterCommit::ConnectionAdapters
45
- end
@@ -1,114 +0,0 @@
1
- module AfterCommit
2
- module ActiveRecord
3
- # Based on the code found in Thinking Sphinx:
4
- # http://ts.freelancing-gods.com/ which was based on code written by Eli
5
- # Miller:
6
- # http://elimiller.blogspot.com/2007/06/proper-cache-expiry-with-aftercommit.html
7
- # with slight modification from Joost Hietbrink. And now me! Whew.
8
- def self.included(base)
9
- base.class_eval do
10
- # The define_callbacks method was added post Rails 2.0.2 - if it
11
- # doesn't exist, we define the callback manually
12
- if respond_to?(:define_callbacks)
13
- define_callbacks :after_commit,
14
- :after_commit_on_create,
15
- :after_commit_on_update,
16
- :after_commit_on_destroy
17
- else
18
- class << self
19
- # Handle after_commit callbacks - call all the registered callbacks.
20
- def after_commit(*callbacks, &block)
21
- callbacks << block if block_given?
22
- write_inheritable_array(:after_commit, callbacks)
23
- end
24
-
25
- def after_commit_on_create(*callbacks, &block)
26
- callbacks << block if block_given?
27
- write_inheritable_array(:after_commit_on_create, callbacks)
28
- end
29
-
30
- def after_commit_on_update(*callbacks, &block)
31
- callbacks << block if block_given?
32
- write_inheritable_array(:after_commit_on_update, callbacks)
33
- end
34
-
35
- def after_commit_on_destroy(*callbacks, &block)
36
- callbacks << block if block_given?
37
- write_inheritable_array(:after_commit_on_destroy, callbacks)
38
- end
39
- end
40
- end
41
-
42
- after_save :add_committed_record
43
- after_create :add_committed_record_on_create
44
- after_update :add_committed_record_on_update
45
- after_destroy :add_committed_record_on_destroy
46
-
47
- # We need to keep track of records that have been saved or destroyed
48
- # within this transaction.
49
- def add_committed_record
50
- AfterCommit.committed_records << self
51
- end
52
-
53
- def add_committed_record_on_create
54
- AfterCommit.committed_records_on_create << self
55
- end
56
-
57
- def add_committed_record_on_update
58
- AfterCommit.committed_records_on_update << self
59
- end
60
-
61
- def add_committed_record_on_destroy
62
- AfterCommit.committed_records << self
63
- AfterCommit.committed_records_on_destroy << self
64
- end
65
-
66
- def after_commit
67
- # Deliberately blank.
68
- end
69
-
70
- # Wraps a call to the private callback method so that the the
71
- # after_commit callback can be made from the ConnectionAdapters when
72
- # the commit for the transaction has finally succeeded.
73
- def after_commit_callback
74
- call_after_commit_callback :after_commit
75
- end
76
-
77
- def after_commit_on_create_callback
78
- call_after_commit_callback :after_commit_on_create
79
- end
80
-
81
- def after_commit_on_update_callback
82
- call_after_commit_callback :after_commit_on_update
83
- end
84
-
85
- def after_commit_on_destroy_callback
86
- call_after_commit_callback :after_commit_on_destroy
87
- end
88
-
89
- private
90
-
91
- def call_after_commit_callback(call)
92
- if can_call_after_commit call
93
- callback call
94
- clear_after_commit_call call
95
- end
96
- end
97
-
98
- def can_call_after_commit(call)
99
- @calls ||= {}
100
- @calls[call] ||= false
101
- if @calls[call]
102
- return false
103
- else
104
- @calls[call] = true
105
- end
106
- end
107
-
108
- def clear_after_commit_call(call)
109
- @calls[call] = false
110
- end
111
- end
112
- end
113
- end
114
- end