require 'spec_helper'
describe SimpleSolr::ActiveRecord do
describe SimpleDocument do
it "provides simple_solr class method" do
SimpleDocument.should respond_to(:simple_solr)
end
it "stores simple_solr fields" do
SimpleDocument.simple_solr_fields.should eq({:id => nil, :title => nil})
end
context "save" do
let(:document) { SimpleDocument.create! :title => 'Omg Ponies' }
it "posts to solr" do
SimpleDocument.should_receive(:post).with("test.local:8983/solr/update?commit=true", :body => "#{document.id}Omg Ponies")
end
end
context "destroy" do
let(:document) { SimpleDocument.create! :title => 'Omg Ponies' }
it "posts to solr" do
SimpleDocument.should_receive(:post).with("test.local:8983/solr/update?commit=true", :body => "#{document.id}Omg Ponies")
SimpleDocument.should_receive(:post).with("test.local:8983/solr/update?commit=true", :body => "#{document.id}")
document.destroy
end
end
context "when unconfigured" do
before do
SimpleSolr.stub_chain(:configuration, :present?).and_return(false)
end
it "does nothing" do
SimpleDocument.should_not_receive(:post)
document = SimpleDocument.new :title => 'Omg Ponies'
document.save
end
end
end
describe FullDocument do
let(:document) { FullDocument.create :title => "Rainbows" }
it "posts to solr after save" do
FullDocument.should_receive(:post).with("test.local:8983/solr?commit=true", :body => "full-document-#{document.id}Rainbows#{document.created_at}false")
end
end
end