Skip to content

Commit

Permalink
+ various spec improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
floere committed Mar 3, 2011
1 parent 5de9136 commit b734123
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 3 deletions.
6 changes: 3 additions & 3 deletions server/lib/picky/internals/index/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ def initialize bundle_name, config
# Delegate to the right collection.
#
def ids sym
@index.collection sym
index.collection sym
end

# Delegate to the right member value.
#
# Note: Converts to float.
#
def weight sym
@weights.member(sym).to_f
weights.member(sym).to_f
end

# Delegate to a member value.
#
def setting sym
@configuration.member sym
configuration.member sym
end

end
Expand Down
3 changes: 3 additions & 0 deletions server/spec/lib/internals/generators/partial/none_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

describe Internals::Generators::Partial::None do

it 'is not saved' do
described_class.new.saved?.should == false
end
it "has the right superclass" do
described_class.should < Internals::Generators::Partial::Strategy
end
Expand Down
74 changes: 74 additions & 0 deletions server/spec/lib/internals/index/redis_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
require 'spec_helper'

describe Internals::Index::Redis do

let(:config) do
index = stub :index, :name => :some_index
category = stub :category, :name => :some_category
Configuration::Index.new index, category
end
let(:redis) { described_class.new :some_name, config }

describe 'setting' do
it 'delegates to the configuration' do
configuration = stub :configuration
redis.stub! :configuration => configuration

configuration.should_receive(:member).once.with :some_sym

redis.setting :some_sym
end
it 'returns the value' do
configuration = stub :configuration
redis.stub! :configuration => configuration

configuration.should_receive(:member).any_number_of_times.and_return "some config"

redis.setting(:any).should == "some config"
end
end
describe 'weight' do
it 'delegates to the weights' do
weights = stub :weights
redis.stub! :weights => weights

weights.should_receive(:member).once.with :some_sym

redis.weight :some_sym
end
it 'returns a floated value' do
weights = stub :weights
redis.stub! :weights => weights

weights.should_receive(:member).any_number_of_times.and_return "1.0"

redis.weight(:any).should == 1.0
end
it 'returns a floated value' do
weights = stub :weights
redis.stub! :weights => weights

weights.should_receive(:member).any_number_of_times.and_return 1

redis.weight(:any).should == 1.0
end
end
describe 'ids' do
it 'delegates to the index' do
index = stub :index
redis.stub! :index => index

index.should_receive(:collection).once.with :some_sym

redis.ids :some_sym
end
it 'returns the value' do
index = stub :index
redis.stub! :index => index

index.should_receive(:collection).any_number_of_times.and_return [1,2,3]

redis.ids(:any).should == [1,2,3]
end
end
end

0 comments on commit b734123

Please sign in to comment.