public
Last active

[Beginning Rails 3] Listing 12-9. Create properties table and define its model in vendor/plugins/simple_search/test/simple_search_test.rb

  • Download Gist
simple_search_test.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
require 'test_helper'
 
$stdout = StringIO.new
 
def create_properties_table
ActiveRecord::Schema.define(:version => 1) do
create_table :properties do |t|
t.column :name, :string
t.column :description, :text
end
end
end
 
class Property < ActiveRecord::Base
simple_search :name, :description
end
 
class SimpleSearchTest < ActiveSupport::TestCase
setup do
create_properties_table
Property.create(:name => 'Some name', :description => 'Some description')
Property.create(:name => 'another name', :description => 'another description')
end
test "search method is available" do
assert Property.respond_to?(:search)
end
 
test "should search" do
assert_equal 2, Property.search("name").size
assert_equal 1, Property.search("another").size
assert_equal 0, Property.search("swimming").size
end
end

I get an error telling me that the table Properties is already created.

Rails 3.0.9

Any ideas? Thanks

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.