forked from pat/thinking-sphinx
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added gem building rake task. Completed specs for ThinkingSphinx::Act…
…iveRecord::Delta. Added delta field to spec's Person model. Tweaked charset and morphology settings to allow index-specific values.
- Loading branch information
Showing
6 changed files
with
231 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
gem_deploy.rake | ||
pkg | ||
coverage | ||
coverage | ||
*.tmproj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
require 'spec/spec_helper' | ||
|
||
describe "ThinkingSphinx::ActiveRecord::Delta" do | ||
describe "after_commit callback" do | ||
before :each do | ||
Person.stub_method(:write_inheritable_array => true) | ||
end | ||
|
||
after :each do | ||
Person.unstub_method(:write_inheritable_array) | ||
end | ||
|
||
it "should add callbacks" do | ||
Person.after_commit :toggle_delta | ||
|
||
Person.should have_received(:write_inheritable_array).with( | ||
:after_commit, [:toggle_delta] | ||
) | ||
end | ||
end | ||
|
||
describe "save_with_after_commit_callback method" do | ||
before :each do | ||
@person = Person.new | ||
@person.stub_methods( | ||
:save_without_after_commit_callback => true, | ||
:callback => true | ||
) | ||
end | ||
|
||
it "should call the normal save method" do | ||
@person.save | ||
|
||
@person.should have_received(:save_without_after_commit_callback) | ||
end | ||
|
||
it "should call the callbacks if the save was successful" do | ||
@person.save | ||
|
||
@person.should have_received(:callback).with(:after_commit) | ||
end | ||
|
||
it "shouldn't call the callbacks if the save failed" do | ||
@person.stub_method(:save_without_after_commit_callback => false) | ||
|
||
@person.save | ||
|
||
@person.should_not have_received(:callback) | ||
end | ||
|
||
it "should return the normal save's result" do | ||
@person.save.should be_true | ||
|
||
@person.stub_method(:save_without_after_commit_callback => false) | ||
|
||
@person.save.should be_false | ||
end | ||
end | ||
|
||
describe "save_with_after_commit_callback! method" do | ||
before :each do | ||
@person = Person.new | ||
@person.stub_methods( | ||
:save_without_after_commit_callback! => true, | ||
:callback => true | ||
) | ||
end | ||
|
||
it "should call the normal save! method" do | ||
@person.save! | ||
|
||
@person.should have_received(:save_without_after_commit_callback!) | ||
end | ||
|
||
it "should call the callbacks if the save! was successful" do | ||
@person.save! | ||
|
||
@person.should have_received(:callback).with(:after_commit) | ||
end | ||
|
||
it "shouldn't call the callbacks if the save! failed" do | ||
@person.stub_method(:save_without_after_commit_callback! => false) | ||
|
||
@person.save! | ||
|
||
@person.should_not have_received(:callback) | ||
end | ||
|
||
it "should return the normal save's result" do | ||
@person.save!.should be_true | ||
|
||
@person.stub_method(:save_without_after_commit_callback! => false) | ||
|
||
@person.save!.should be_false | ||
end | ||
end | ||
|
||
describe "destroy_with_after_commit_callback method" do | ||
before :each do | ||
@person = Person.new | ||
@person.stub_methods( | ||
:destroy_without_after_commit_callback => true, | ||
:callback => true | ||
) | ||
end | ||
|
||
it "should call the normal destroy method" do | ||
@person.destroy | ||
|
||
@person.should have_received(:destroy_without_after_commit_callback) | ||
end | ||
|
||
it "should call the callbacks if the destroy was successful" do | ||
@person.destroy | ||
|
||
@person.should have_received(:callback).with(:after_commit) | ||
end | ||
|
||
it "shouldn't call the callbacks if the destroy failed" do | ||
@person.stub_method(:destroy_without_after_commit_callback => false) | ||
|
||
@person.destroy | ||
|
||
@person.should_not have_received(:callback) | ||
end | ||
|
||
it "should return the normal save's result" do | ||
@person.destroy.should be_true | ||
|
||
@person.stub_method(:destroy_without_after_commit_callback => false) | ||
|
||
@person.destroy.should be_false | ||
end | ||
end | ||
|
||
describe "toggle_delta method" do | ||
it "should set the delta value to true" do | ||
@person = Person.new | ||
|
||
@person.delta.should be_false | ||
@person.send(:toggle_delta) | ||
@person.delta.should be_true | ||
end | ||
end | ||
|
||
describe "index_delta method" do | ||
before :each do | ||
ThinkingSphinx::Configuration.stub_method(:environment => "spec") | ||
ThinkingSphinx.stub_method(:deltas_enabled? => true) | ||
|
||
@person = Person.new | ||
@person.stub_method(:system => true) | ||
end | ||
|
||
after :each do | ||
ThinkingSphinx::Configuration.unstub_method(:environment) | ||
ThinkingSphinx.unstub_method(:deltas_enabled?) | ||
end | ||
|
||
it "shouldn't index if delta indexing is disabled" do | ||
ThinkingSphinx.stub_method(:deltas_enabled? => false) | ||
|
||
@person.send(:index_delta) | ||
|
||
@person.should_not have_received(:system) | ||
end | ||
|
||
it "shouldn't index if the environment is 'test'" do | ||
ThinkingSphinx::Configuration.stub_method(:environment => "test") | ||
|
||
@person.send(:index_delta) | ||
|
||
@person.should_not have_received(:system) | ||
end | ||
|
||
it "should call indexer for the delta index" do | ||
@person.send(:index_delta) | ||
|
||
@person.should have_received(:system).with( | ||
"indexer --config #{ThinkingSphinx::Configuration.new.config_file} --rotate person_delta" | ||
) | ||
end | ||
end | ||
end |