spec/unit/thinking_sphinx/attribute_spec.rb in freelancing-god-thinking-sphinx-0.9.12 vs spec/unit/thinking_sphinx/attribute_spec.rb in freelancing-god-thinking-sphinx-0.9.13
- old
+ new
@@ -13,157 +13,9 @@
ThinkingSphinx::Attribute.new([1234])
}.should raise_error(RuntimeError)
end
end
- describe "to_select_sql method with MySQL" do
- before :each do
- @index = Person.sphinx_indexes.first
- @index.link!
- end
-
- it "should concat with spaces if there's more than one non-integer column" do
- @index.attributes[0].to_select_sql.should match(/CONCAT_WS\(' ', /)
- end
-
- it "should concat with spaces if there's more than one association for a non-integer column" do
- @index.attributes[1].to_select_sql.should match(/CONCAT_WS\(' ', /)
- end
-
- it "should concat with commas if there's multiple integer columns" do
- @index.attributes[2].to_select_sql.should match(/CONCAT_WS\(',', /)
- end
-
- it "should concat with commas if there's more than one association for an integer column" do
- @index.attributes[3].to_select_sql.should match(/CONCAT_WS\(',', /)
- end
-
- it "should group with spaces if there's string columns from a has_many or has_and_belongs_to_many association" do
- @index.attributes[4].to_select_sql.should match(/GROUP_CONCAT\(.+ SEPARATOR ' '\)/)
- end
-
- it "should group with commas if there's integer columns from a has_many or has_and_belongs_to_many association" do
- @index.attributes[5].to_select_sql.should match(/GROUP_CONCAT\(.+ SEPARATOR ','\)/)
- end
-
- it "should convert datetime values to timestamps" do
- @index.attributes[6].to_select_sql.should match(/UNIX_TIMESTAMP/)
- end
- end
-
- describe "to_select_sql method with PostgreSQL" do
- before :each do
- @index = Person.sphinx_indexes.first
- Person.connection.class.stub_method(
- :name => "ActiveRecord::ConnectionAdapters::PostgreSQLAdapter"
- )
- @index.link!
- end
-
- it "should concat with spaces if there's more than one non-integer column" do
- @index.attributes[0].to_select_sql.should match(/|| ' ' ||/)
- end
-
- it "should concat with spaces if there's more than one association for a non-integer column" do
- @index.attributes[1].to_select_sql.should match(/|| ' ' ||/)
- end
-
- it "should concat with commas if there's multiple integer columns" do
- @index.attributes[2].to_select_sql.should match(/|| ',' ||/)
- end
-
- it "should concat with commas if there's more than one association for an integer column" do
- @index.attributes[3].to_select_sql.should match(/|| ',' ||/)
- end
-
- it "should group with spaces if there's string columns from a has_many or has_and_belongs_to_many association" do
- @index.attributes[4].to_select_sql.should match(/array_to_string\(array_accum\(.+, ' '\)/)
- end
-
- it "should group with commas if there's integer columns from a has_many or has_and_belongs_to_many association" do
- @index.attributes[5].to_select_sql.should match(/array_to_string\(array_accum\(.+, ','\)/)
- end
- end
-
- describe "to_group_sql method" do
- before :each do
- @attribute = ThinkingSphinx::Attribute.new([Object.stub_instance(:__stack => [])])
- @attribute.stub_method(:is_many? => false, :is_string? => false)
-
- ThinkingSphinx.stub_method(:use_group_by_shortcut? => false)
- end
-
- it "should return nil if is_many?" do
- @attribute.stub_method(:is_many? => true)
-
- @attribute.to_group_sql.should be_nil
- end
-
- it "should return nil if is_string?" do
- @attribute.stub_method(:is_string? => true)
-
- @attribute.to_group_sql.should be_nil
- end
-
- it "should return nil if group_by shortcut is allowed" do
- ThinkingSphinx.stub_method(:use_group_by_shortcut? => true)
-
- @attribute.to_group_sql.should be_nil
- end
-
- it "should return an array if neither is_many? or shortcut allowed" do
- @attribute.stub_method(:column_with_prefix => 'hello')
- @attribute.to_group_sql.should be_a_kind_of(Array)
- end
-
- after :each do
- ThinkingSphinx.unstub_method(:use_group_by_shortcut?)
- end
- end
-
- describe "to_sphinx_clause method" do
- before :each do
- @attribute = ThinkingSphinx::Attribute.new [Object.stub_instance(:__stack => [])]
- @attribute.stub_method(:unique_name => "unique name")
- end
-
- it "should use sql_attr_multi syntax for MVA attributes" do
- @attribute.stub_method(:type => :multi)
- @attribute.to_sphinx_clause.should match(/^sql_attr_multi\s+= uint unique name from field$/)
- end
-
- it "should use sql_attr_timestamp syntax for datetime values" do
- @attribute.stub_method(:type => :datetime)
- @attribute.to_sphinx_clause.should match(/^sql_attr_timestamp\s+= unique name$/)
- end
-
- it "should use sql_attr_str2ordinal for string values" do
- @attribute.stub_method(:type => :string)
- @attribute.to_sphinx_clause.should match(/^sql_attr_str2ordinal\s+= unique name$/)
- end
-
- it "should use sql_attr_float for float values" do
- @attribute.stub_method(:type => :float)
- @attribute.to_sphinx_clause.should match(/^sql_attr_float\s+= unique name$/)
- end
-
- it "should use sql_attr_bool for boolean values" do
- @attribute.stub_method(:type => :boolean)
- @attribute.to_sphinx_clause.should match(/^sql_attr_bool\s+= unique name$/)
- end
-
- it "should use sql_attr_uint for integer values" do
- @attribute.stub_method(:type => :integer)
- @attribute.to_sphinx_clause.should match(/^sql_attr_uint\s+= unique name$/)
- end
-
- it "should assume integer for any other types" do
- @attribute.stub_method(:type => :unknown)
- @attribute.to_sphinx_clause.should match(/^sql_attr_uint\s+= unique name$/)
- end
-
- end
-
describe "unique_name method" do
before :each do
@attribute = ThinkingSphinx::Attribute.new [
Object.stub_instance(:__stack => [], :__name => "col_name")
]
\ No newline at end of file