Create a gist now

Instantly share code, notes, and snippets.

@bogdan /service_spec.rb Secret
Created Apr 23, 2011

What would you like to do?
require 'spec_helper'
describe Service do
subject { Factory.build(described_class.to_s.underscore, :title => "heart diagnostic") }
it { should_not accept_values_for(:category, nil) }
it "should truncate spaces around url"
it { should_not accept_values_for(:title, nil, "", "a") }
it { should accept_values_for(:title, "aa") }
it "should have described association with article" do
pending
end
context "after #save!" do
before(:each) do
subject.title = 'hello'
subject.save!
Sunspot.commit
end
it "should be indexed by sunspot" do
Sunspot.search(Service) do |s|
s.keywords 'hello'
end.total.should > 0
end
context "with keyword" do
before(:each) do
Factory.create(:keyword, :service => subject.reload, :title => "world")
Sunspot.commit
end
it "should be searchable by this keyword" do
Sunspot.search(Service) do |s|
s.keywords 'World'
end.total.should > 0
end
end
end
context "after #save!" do
before(:each) do
subject.save!
Sunspot.commit
end
describe "#solr_score" do
let(:search) { Sunspot.search(Service){|s| s.keywords "heart" } }
it "should be the solr score of the service for the given search" do
subject.solr_score(search).should == search.hits.first.score
end
end
end
describe "#company_services_count" do
context "with company_service exists that is " do
before(:each) do
Factory.create(
:company_service,
:company => Factory.create(:company, :disabled => disabled),
:service => subject
)
end
context "disabled" do
let(:disabled) { true }
it "should be zero" do
subject.company_services_count.should == 0
end
end
context "enabled" do
let(:disabled) { false }
it "should be one" do
subject.company_services_count.should == 1
end
end
end
end
end
# == Schema Information
#
# Table name: services
#
# id :integer not null, primary key
# title :string(255)
# category_id :integer
# created_at :datetime
# updated_at :datetime
# price_units_type :integer(2) not null
# company_services_count :integer default(0), not null
# important :boolean
# description :string(255) default(""), not null
# characteristic :string(255) default(""), not null
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment