spec/unit/thinking_sphinx/field_spec.rb in DrMark-thinking-sphinx-1.1.6 vs spec/unit/thinking_sphinx/field_spec.rb in DrMark-thinking-sphinx-1.1.14

- old
+ new

@@ -1,25 +1,30 @@ require 'spec/spec_helper' describe ThinkingSphinx::Field do + before :each do + @index = ThinkingSphinx::Index.new(Alpha) + @source = ThinkingSphinx::Source.new(@index) + end + describe '#initialize' do it 'raises if no columns are provided so that configuration errors are easier to track down' do lambda { - ThinkingSphinx::Field.new([]) + ThinkingSphinx::Field.new(@source, []) }.should raise_error(RuntimeError) end it 'raises if an element of the columns param is an integer - as happens when you use id instead of :id - so that configuration errors are easier to track down' do lambda { - ThinkingSphinx::Field.new([1234]) + ThinkingSphinx::Field.new(@source, [1234]) }.should raise_error(RuntimeError) end end describe "unique_name method" do before :each do - @field = ThinkingSphinx::Field.new [ + @field = ThinkingSphinx::Field.new @source, [ Object.stub_instance(:__stack => [], :__name => "col_name") ] end it "should use the alias if there is one" do @@ -40,39 +45,43 @@ end end describe "prefixes method" do it "should default to false" do - @field = ThinkingSphinx::Field.new([Object.stub_instance(:__stack => [])]) + @field = ThinkingSphinx::Field.new( + @source, [Object.stub_instance(:__stack => [])] + ) @field.prefixes.should be_false end it "should be true if the corresponding option is set" do @field = ThinkingSphinx::Field.new( - [Object.stub_instance(:__stack => [])], :prefixes => true + @source, [Object.stub_instance(:__stack => [])], :prefixes => true ) @field.prefixes.should be_true end end describe "infixes method" do it "should default to false" do - @field = ThinkingSphinx::Field.new([Object.stub_instance(:__stack => [])]) + @field = ThinkingSphinx::Field.new( + @source, [Object.stub_instance(:__stack => [])] + ) @field.infixes.should be_false end it "should be true if the corresponding option is set" do @field = ThinkingSphinx::Field.new( - [Object.stub_instance(:__stack => [])], :infixes => true + @source, [Object.stub_instance(:__stack => [])], :infixes => true ) @field.infixes.should be_true end end describe "column_with_prefix method" do before :each do - @field = ThinkingSphinx::Field.new [ + @field = ThinkingSphinx::Field.new @source, [ ThinkingSphinx::Index::FauxColumn.new(:col_name) ] @field.columns.each { |col| @field.associations[col] = [] } @field.model = Person @@ -114,10 +123,10 @@ @assoc_a = Object.stub_instance(:is_many? => true) @assoc_b = Object.stub_instance(:is_many? => true) @assoc_c = Object.stub_instance(:is_many? => true) @field = ThinkingSphinx::Field.new( - [ThinkingSphinx::Index::FauxColumn.new(:col_name)] + @source, [ThinkingSphinx::Index::FauxColumn.new(:col_name)] ) @field.associations = { :a => @assoc_a, :b => @assoc_b, :c => @assoc_c } end