Skip to content

Instantly share code, notes, and snippets.

@rbarazi
Created April 11, 2010 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbarazi/362827 to your computer and use it in GitHub Desktop.
Save rbarazi/362827 to your computer and use it in GitHub Desktop.
[Beginning Rails 3] Listing 12-9. Create properties table and define its model in vendor/plugins/simple_search/test/simple_search_test.rb
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
@alessioalex
Copy link

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

Rails 3.0.9

Any ideas? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment