Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

texticle => textacular

  • Loading branch information...
commit e85b32aa5d2d9ab8cfac81bb694e0aff14f0f5d1 1 parent 4b938ad
@pvh pvh authored benhamill committed
View
16 CHANGELOG.md
@@ -11,7 +11,7 @@
## 2.1.1
* 1 bugfix
- * Include `lib/texticle/version.rb` in the gemspec so the gem will load. Sorry!
+ * Include `lib/textacular/version.rb` in the gemspec so the gem will load. Sorry!
## 2.1.0
@@ -39,7 +39,7 @@
* Allow searching through all model columns irrespective of the column's type; we cast all columns to text
in the search query. Performance may degrade when searching through anything but a string column.
* 2 bugfixes
- * Fix exceptions when adding Texticle to a table-less model.
+ * Fix exceptions when adding Textacular to a table-less model.
* Column names in a search query are now scoped to the current table.
* 1 dev improvement
* Running `rake` from the project root will setup the test environment by creating a test database
@@ -69,19 +69,19 @@
* Searchable is now available to specify which columns you want searched:
```ruby
- require 'texticle/searchable'
+ require 'textacular/searchable'
class Game
extend Searchable(:title)
end
```
- This also allows Texticle use in Rails without having #search available to all models:
+ This also allows Textacular use in Rails without having #search available to all models:
```
- gem 'texticle', '~> 2.0.pre4', :require => 'texticle/searchable'
+ gem 'textacular', '~> 2.0.pre4', :require => 'textacular/searchable'
```
* 1 bugfix
- * ActiveRecord::Base.extend(Texticle) doesn't break #method_missing and #respond_to? anymore
+ * ActiveRecord::Base.extend(Textacular) doesn't break #method_missing and #respond_to? anymore
## 2.0.pre3
@@ -99,9 +99,9 @@
## 2.0.pre
-* Complete refactoring of Texticle
+* Complete refactoring of Textacular
* For users:
- * Texticle should only be used for its simplicity; if you need to deeply configure your text search, please give `gem install pg_search` a try.
+ * Textacular should only be used for its simplicity; if you need to deeply configure your text search, please give `gem install pg_search` a try.
* `#search` method is now included in all ActiveRecord models by default, and searches across a model's :string columns.
* `#search_by_<column>` dynamic methods are now available.
* `#search` can now be chained; `Game.search_by_title("Street Fighter").search_by_system("PS3")` works.
View
10 Manifest.txt
@@ -3,10 +3,10 @@ CHANGELOG.rdoc
Manifest.txt
README.rdoc
Rakefile
-lib/texticle.rb
-lib/texticle/rails.rb
-lib/texticle/searchable.rb
+lib/textacular.rb
+lib/textacular/rails.rb
+lib/textacular/searchable.rb
spec/config.yml
spec/spec_helper.rb
-spec/texticle_spec.rb
-spec/texticle/searchable_spec.rb
+spec/textacular_spec.rb
+spec/textacular/searchable_spec.rb
View
14 README.md
@@ -1,11 +1,11 @@
-# texticle
+# textacular
-Further documentation available at http://texticle.github.com/texticle.
+Further documentation available at http://textacular.github.com/textacular.
## DESCRIPTION:
-Texticle exposes full text search capabilities from PostgreSQL,
+Textacular exposes full text search capabilities from PostgreSQL,
extending ActiveRecord with scopes making search easy and fun!
@@ -22,15 +22,15 @@ extending ActiveRecord with scopes making search easy and fun!
In the project's Gemfile add
- gem 'texticle', '~> 2.0', require: 'texticle/rails'
+ gem 'textacular', '~> 2.0', require: 'textacular/rails'
#### ActiveRecord outside of Rails 3
```ruby
-require 'texticle'
+require 'textacular'
-ActiveRecord::Base.extend(Texticle)
+ActiveRecord::Base.extend(Textacular)
```
@@ -113,7 +113,7 @@ config.active_record.schema_format = :sql
## INSTALL:
```
-$ gem install texticle
+$ gem install textacular
```
View
12 Rakefile
@@ -16,7 +16,7 @@ end
desc "Fire up an interactive terminal to play with"
task :console do
require 'pry'
- require File.expand_path(File.dirname(__FILE__) + '/lib/texticle')
+ require File.expand_path(File.dirname(__FILE__) + '/lib/textacular')
config = YAML.load_file File.expand_path(File.dirname(__FILE__) + '/spec/config.yml')
ActiveRecord::Base.establish_connection config.merge(:adapter => :postgresql)
@@ -42,7 +42,7 @@ task :console do
# start the console! :-)
welcome = <<-EOS
- Welcome to the Texticle devloper console. You have some classes you can play with:
+ Welcome to the Textacular devloper console. You have some classes you can play with:
class Character < ActiveRecord::Base
# string :name
@@ -72,9 +72,9 @@ task :console do
end
task :test do
- require 'texticle_spec'
- require 'texticle/searchable_spec'
- require 'texticle/full_text_indexer_spec'
+ require 'textacular_spec'
+ require 'textacular/searchable_spec'
+ require 'textacular/full_text_indexer_spec'
end
namespace :db do
@@ -96,7 +96,7 @@ namespace :db do
end
STDOUT.puts "Creating database..."
- `createdb texticle`
+ `createdb textacular`
STDOUT.puts "Writing configuration file..."
View
8 lib/texticle.rb → lib/textacular.rb
@@ -1,8 +1,8 @@
require 'active_record'
-require 'texticle/version'
+require 'textacular/version'
-module Texticle
+module Textacular
def self.searchable_language
'english'
end
@@ -164,7 +164,7 @@ def quoted_language
end
def searchable_language
- Texticle.searchable_language
+ Textacular.searchable_language
end
module Helper
@@ -225,4 +225,4 @@ def dynamic_search_method?(method, class_columns)
end
end
-require File.expand_path(File.dirname(__FILE__) + '/texticle/full_text_indexer')
+require File.expand_path(File.dirname(__FILE__) + '/textacular/full_text_indexer')
View
4 lib/texticle/full_text_indexer.rb → lib/textacular/full_text_indexer.rb
@@ -1,4 +1,4 @@
-class Texticle::FullTextIndexer
+class Textacular::FullTextIndexer
def generate_migration(model_name)
stream_output do |io|
io.puts(<<-MIGRATION)
@@ -74,6 +74,6 @@ def index_name_for(model, column)
end
def dictionary
- Texticle.searchable_language
+ Textacular.searchable_language
end
end
View
2  lib/texticle/postgres_module_installer.rb → lib/textacular/postgres_module_installer.rb
@@ -1,4 +1,4 @@
-module Texticle
+module Textacular
class PostgresModuleInstaller
def install_module(module_name)
major, minor, patch = postgres_version.split('.')
View
10 lib/textacular/rails.rb
@@ -0,0 +1,10 @@
+# Module used to conform to Rails 3 plugin API
+require File.expand_path(File.dirname(__FILE__) + '/../textacular')
+
+module Textacular
+ class Railtie < Rails::Railtie
+ initializer "textacular.configure_rails_initialization" do
+ ActiveRecord::Base.extend(Textacular)
+ end
+ end
+end
View
6 lib/texticle/searchable.rb → lib/textacular/searchable.rb
@@ -1,9 +1,9 @@
-require 'texticle'
+require 'textacular'
def Searchable(*searchable_columns)
Module.new do
- include Texticle
+ include Textacular
define_method(:searchable_columns) do
searchable_columns.map(&:to_s)
@@ -17,4 +17,4 @@ def indexable_columns
end
end
-Searchable = Texticle
+Searchable = Textacular
View
8 lib/texticle/tasks.rb → lib/textacular/tasks.rb
@@ -1,16 +1,16 @@
require 'rake'
-require 'texticle'
+require 'textacular'
-namespace :texticle do
+namespace :textacular do
desc 'Create full text search index migration, give the model for which you want to create the indexes'
task :create_index_migration, [:model_name] => :environment do |task, args|
raise 'A model name is required' unless args[:model_name]
- Texticle::FullTextIndexer.new.generate_migration(args[:model_name])
+ Textacular::FullTextIndexer.new.generate_migration(args[:model_name])
end
desc "Install trigram text search module"
task :install_trigram => [:environment] do
- installer = Texticle::PostgresModuleInstaller.new
+ installer = Textacular::PostgresModuleInstaller.new
installer.install_module('pg_trgm')
puts "Trigram text search module successfully installed into '#{installer.db_name}' database."
View
0  lib/texticle/version.rb → lib/textacular/version.rb
File renamed without changes
View
10 lib/texticle/rails.rb
@@ -1,10 +0,0 @@
-# Module used to conform to Rails 3 plugin API
-require File.expand_path(File.dirname(__FILE__) + '/../texticle')
-
-module Texticle
- class Railtie < Rails::Railtie
- initializer "texticle.configure_rails_initialization" do
- ActiveRecord::Base.extend(Texticle)
- end
- end
-end
View
2  spec/config.yml.example
@@ -1,4 +1,4 @@
-database: texticle
+database: textacular
username: <username>
pool: 5
timeout: 5000
View
20 spec/spec_helper.rb
@@ -1,24 +1,24 @@
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
require 'yaml'
-require 'texticle'
+require 'textacular'
require 'shoulda'
require 'pry'
require 'active_record'
-require 'texticle'
-require 'texticle/searchable'
+require 'textacular'
+require 'textacular/searchable'
config = YAML.load_file File.expand_path(File.dirname(__FILE__) + '/config.yml')
ActiveRecord::Base.establish_connection config.merge(:adapter => :postgresql)
class ARStandIn < ActiveRecord::Base;
self.abstract_class = true
- extend Texticle
+ extend Textacular
end
class NotThere < ARStandIn; end
-class TexticleWebComic < ARStandIn;
+class TextacularWebComic < ARStandIn;
has_many :characters, :foreign_key => :web_comic_id
self.table_name = :web_comics
end
@@ -60,11 +60,11 @@ class Game < ActiveRecord::Base
# text :description
end
-class GameExtendedWithTexticle < Game
- extend Texticle
+class GameExtendedWithTextacular < Game
+ extend Textacular
end
-class GameExtendedWithTexticleAndCustomLanguage < GameExtendedWithTexticle
+class GameExtendedWithTextacularAndCustomLanguage < GameExtendedWithTextacular
def searchable_language
'spanish'
end
@@ -73,6 +73,6 @@ def searchable_language
class GameFail < Game; end
-class GameFailExtendedWithTexticle < GameFail
- extend Texticle
+class GameFailExtendedWithTextacular < GameFail
+ extend Textacular
end
View
8 spec/texticle/full_text_indexer_spec.rb → spec/textacular/full_text_indexer_spec.rb
@@ -5,7 +5,7 @@ class FullTextIndexerTest < Test::Unit::TestCase
context ".stream_output" do
context "when Rails is not defined" do
setup do
- @indexer = Texticle::FullTextIndexer.new
+ @indexer = Textacular::FullTextIndexer.new
end
should "point to stdout" do
@@ -32,7 +32,7 @@ def self.root
@now = Time.now
- @indexer = Texticle::FullTextIndexer.new
+ @indexer = Textacular::FullTextIndexer.new
end
teardown do
@@ -56,7 +56,7 @@ def self.root
context "when we've listed one specific field in a Searchable call" do
setup do
- @indexer = Texticle::FullTextIndexer.new
+ @indexer = Textacular::FullTextIndexer.new
@output = StringIO.new
@indexer.instance_variable_set(:@output_stream, @output)
end
@@ -89,7 +89,7 @@ def self.down
context "when we've listed two specific fields in a Searchable call" do
setup do
- @indexer = Texticle::FullTextIndexer.new
+ @indexer = Textacular::FullTextIndexer.new
@output = StringIO.new
@indexer.instance_variable_set(:@output_stream, @output)
end
View
2  spec/texticle/searchable_spec.rb → spec/textacular/searchable_spec.rb
@@ -1,5 +1,5 @@
require 'spec_helper'
-require 'texticle/searchable'
+require 'textacular/searchable'
class SearchableTest < Test::Unit::TestCase
context "when extending an ActiveRecord::Base subclass" do
View
216 spec/textacular_spec.rb
@@ -0,0 +1,216 @@
+# coding: utf-8
+require 'spec_helper'
+
+class TextacularTest < Test::Unit::TestCase
+ context "after extending ActiveRecord::Base" do
+ should "not break #respond_to?" do
+ assert_nothing_raised do
+ ARStandIn.respond_to? :abstract_class?
+ end
+ end
+
+ should "not break #respond_to? for table-less classes" do
+ assert !NotThere.table_exists?
+ assert_nothing_raised do
+ NotThere.respond_to? :system
+ end
+ end
+
+ should "not break #method_missing" do
+ assert_raise(NoMethodError) { ARStandIn.random }
+ begin
+ ARStandIn.random
+ rescue NoMethodError => error
+ assert_match error.message, /undefined method `random'/
+ end
+ end
+
+ should "not break #method_missing for table-less classes" do
+ assert !NotThere.table_exists?
+ assert_raise(NoMethodError) { NotThere.random }
+ begin
+ NotThere.random
+ rescue NoMethodError => error
+ assert_match error.message, /undefined method `random'/
+ end
+ end
+
+ context "when finding models based on searching a related model" do
+ setup do
+ @qc = TextacularWebComic.create :name => "Questionable Content", :author => "Jeph Jaques"
+ @jw = TextacularWebComic.create :name => "Johnny Wander", :author => "Ananth & Yuko"
+ @pa = TextacularWebComic.create :name => "Penny Arcade", :author => "Tycho & Gabe"
+
+ @gabe = @pa.characters.create :name => 'Gabe', :description => 'the simple one'
+ @tycho = @pa.characters.create :name => 'Tycho', :description => 'the wordy one'
+ @div = @pa.characters.create :name => 'Div', :description => 'a crude divx player with anger management issues'
+
+ @martin = @qc.characters.create :name => 'Martin', :description => 'the insecure protagonist'
+ @faye = @qc.characters.create :name => 'Faye', :description => 'a sarcastic barrista with anger management issues'
+ @pintsize = @qc.characters.create :name => 'Pintsize', :description => 'a crude AnthroPC'
+
+ @ananth = @jw.characters.create :name => 'Ananth', :description => 'Stubble! What is under that hat?!?'
+ @yuko = @jw.characters.create :name => 'Yuko', :description => 'So... small. Carl Sagan haircut.'
+ @john = @jw.characters.create :name => 'John', :description => 'Tall. Anger issues?'
+ @cricket = @jw.characters.create :name => 'Cricket', :description => 'Chirrup!'
+ end
+
+ teardown do
+ TextacularWebComic.delete_all
+ Character.delete_all
+ end
+
+ should "look in the related model with nested searching syntax" do
+ assert_equal [@jw], TextacularWebComic.joins(:characters).advanced_search(:characters => {:description => 'tall'})
+ assert_equal [@pa, @jw, @qc].sort, TextacularWebComic.joins(:characters).advanced_search(:characters => {:description => 'anger'}).sort
+ assert_equal [@pa, @qc].sort, TextacularWebComic.joins(:characters).advanced_search(:characters => {:description => 'crude'}).sort
+ end
+ end
+ end
+
+ context "after extending an ActiveRecord::Base subclass" do
+ setup do
+ @zelda = GameExtendedWithTextacular.create :system => "NES", :title => "Legend of Zelda", :description => "A Link to the Past."
+ @mario = GameExtendedWithTextacular.create :system => "NES", :title => "Super Mario Bros.", :description => "The original platformer."
+ @sonic = GameExtendedWithTextacular.create :system => "Genesis", :title => "Sonic the Hedgehog", :description => "Spiky."
+ @dkong = GameExtendedWithTextacular.create :system => "SNES", :title => "Diddy's Kong Quest", :description => "Donkey Kong Country 2"
+ @megam = GameExtendedWithTextacular.create :system => nil, :title => "Mega Man", :description => "Beware Dr. Brain"
+ @sfnes = GameExtendedWithTextacular.create :system => "SNES", :title => "Street Fighter 2", :description => "Yoga Flame!"
+ @sfgen = GameExtendedWithTextacular.create :system => "Genesis", :title => "Street Fighter 2", :description => "Yoga Flame!"
+ @takun = GameExtendedWithTextacular.create :system => "Saturn", :title => "Magical Tarurūto-kun", :description => "カッコイイ!"
+ end
+
+ teardown do
+ GameExtendedWithTextacular.delete_all
+ end
+
+ should "not break respond_to? when connection is unavailable" do
+ GameFailExtendedWithTextacular.establish_connection({:adapter => :postgresql, :database =>'unavailable', :username=>'bad', :pool=>5, :timeout=>5000}) rescue nil
+
+ assert_nothing_raised do
+ GameFailExtendedWithTextacular.respond_to?(:advanced_search)
+ end
+ end
+
+ should "define a #search method" do
+ assert GameExtendedWithTextacular.respond_to?(:search)
+ end
+
+ context "when searching with a String argument" do
+ should "search across all :string columns if no indexes have been specified" do
+ assert_equal [@mario], GameExtendedWithTextacular.advanced_search("Mario")
+ assert_equal Set.new([@mario, @zelda]), GameExtendedWithTextacular.advanced_search("NES").to_set
+ end
+
+ should "work if the query contains an apostrophe" do
+ assert_equal [@dkong], GameExtendedWithTextacular.advanced_search("Diddy's")
+ end
+
+ should "work if the query contains whitespace" do
+ assert_equal [@megam], GameExtendedWithTextacular.advanced_search("Mega Man")
+ end
+
+ should "work if the query contains an accent" do
+ assert_equal [@takun], GameExtendedWithTextacular.advanced_search("Tarurūto-kun")
+ end
+
+ should "search across records with NULL values" do
+ assert_equal [@megam], GameExtendedWithTextacular.advanced_search("Mega")
+ end
+
+ should "scope consecutively" do
+ assert_equal [@sfgen], GameExtendedWithTextacular.advanced_search("Genesis").advanced_search("Street Fighter")
+ end
+ end
+
+ context "when searching with a Hash argument" do
+ should "search across the given columns" do
+ assert_empty GameExtendedWithTextacular.advanced_search(:title => "NES")
+ assert_empty GameExtendedWithTextacular.advanced_search(:system => "Mario")
+ assert_empty GameExtendedWithTextacular.advanced_search(:system => "NES", :title => "Sonic")
+
+ assert_equal [@mario], GameExtendedWithTextacular.advanced_search(:title => "Mario")
+
+ assert_equal 2, GameExtendedWithTextacular.advanced_search(:system => "NES").count
+
+ assert_equal [@zelda], GameExtendedWithTextacular.advanced_search(:system => "NES", :title => "Zelda")
+ assert_equal [@megam], GameExtendedWithTextacular.advanced_search(:title => "Mega")
+ end
+
+ should "scope consecutively" do
+ assert_equal [@sfgen], GameExtendedWithTextacular.advanced_search(:system => "Genesis").advanced_search(:title => "Street Fighter")
+ end
+
+ should "cast non-:string columns as text" do
+ assert_equal [@mario], GameExtendedWithTextacular.advanced_search(:id => @mario.id)
+ end
+ end
+
+ context "when using dynamic search methods" do
+ should "generate methods for each :string column" do
+ assert_equal [@mario], GameExtendedWithTextacular.advanced_search_by_title("Mario")
+ assert_equal [@takun], GameExtendedWithTextacular.advanced_search_by_system("Saturn")
+ end
+
+ should "generate methods for each :text column" do
+ assert_equal [@mario], GameExtendedWithTextacular.advanced_search_by_description("platform")
+ end
+
+ should "generate methods for any combination of :string and :text columns" do
+ assert_equal [@mario], GameExtendedWithTextacular.advanced_search_by_title_and_system("Mario", "NES")
+ assert_equal [@sonic], GameExtendedWithTextacular.advanced_search_by_system_and_title("Genesis", "Sonic")
+ assert_equal [@mario], GameExtendedWithTextacular.advanced_search_by_title_and_title("Mario", "Mario")
+ assert_equal [@megam], GameExtendedWithTextacular.advanced_search_by_title_and_description("Man", "Brain")
+ end
+
+ should "generate methods for inclusive searches" do
+ assert_equal Set.new([@megam, @takun]), GameExtendedWithTextacular.advanced_search_by_system_or_title("Saturn", "Mega Man").to_set
+ end
+
+ should "scope consecutively" do
+ assert_equal [@sfgen], GameExtendedWithTextacular.advanced_search_by_system("Genesis").advanced_search_by_title("Street Fighter")
+ end
+
+ should "generate methods for non-:string columns" do
+ assert_equal [@mario], GameExtendedWithTextacular.advanced_search_by_id(@mario.id)
+ end
+
+ should "work with #respond_to?" do
+ assert GameExtendedWithTextacular.respond_to?(:advanced_search_by_system)
+ assert GameExtendedWithTextacular.respond_to?(:advanced_search_by_title)
+ assert GameExtendedWithTextacular.respond_to?(:advanced_search_by_system_and_title)
+ assert GameExtendedWithTextacular.respond_to?(:advanced_search_by_system_or_title)
+ assert GameExtendedWithTextacular.respond_to?(:advanced_search_by_title_and_title_and_title)
+ assert GameExtendedWithTextacular.respond_to?(:advanced_search_by_id)
+
+ assert !GameExtendedWithTextacular.respond_to?(:advanced_search_by_title_and_title_or_title)
+ end
+
+ should "allow for 2 arguments to #respond_to?" do
+ assert GameExtendedWithTextacular.respond_to?(:normalize, true)
+ end
+ end
+
+ context "when searching after selecting columns to return" do
+ should "not fetch extra columns" do
+ assert_raise(ActiveModel::MissingAttributeError) do
+ GameExtendedWithTextacular.select(:title).advanced_search("Mario").first.system
+ end
+ end
+ end
+
+ context "when setting a custom search language" do
+ setup do
+ GameExtendedWithTextacularAndCustomLanguage.create :system => "PS3", :title => "Harry Potter & the Deathly Hallows"
+ end
+
+ teardown do
+ GameExtendedWithTextacularAndCustomLanguage.delete_all
+ end
+
+ should "still find results" do
+ assert_not_empty GameExtendedWithTextacularAndCustomLanguage.advanced_search_by_title("harry")
+ end
+ end
+ end
+end
View
216 spec/texticle_spec.rb
@@ -1,216 +0,0 @@
-# coding: utf-8
-require 'spec_helper'
-
-class TexticleTest < Test::Unit::TestCase
- context "after extending ActiveRecord::Base" do
- should "not break #respond_to?" do
- assert_nothing_raised do
- ARStandIn.respond_to? :abstract_class?
- end
- end
-
- should "not break #respond_to? for table-less classes" do
- assert !NotThere.table_exists?
- assert_nothing_raised do
- NotThere.respond_to? :system
- end
- end
-
- should "not break #method_missing" do
- assert_raise(NoMethodError) { ARStandIn.random }
- begin
- ARStandIn.random
- rescue NoMethodError => error
- assert_match error.message, /undefined method `random'/
- end
- end
-
- should "not break #method_missing for table-less classes" do
- assert !NotThere.table_exists?
- assert_raise(NoMethodError) { NotThere.random }
- begin
- NotThere.random
- rescue NoMethodError => error
- assert_match error.message, /undefined method `random'/
- end
- end
-
- context "when finding models based on searching a related model" do
- setup do
- @qc = TexticleWebComic.create :name => "Questionable Content", :author => "Jeph Jaques"
- @jw = TexticleWebComic.create :name => "Johnny Wander", :author => "Ananth & Yuko"
- @pa = TexticleWebComic.create :name => "Penny Arcade", :author => "Tycho & Gabe"
-
- @gabe = @pa.characters.create :name => 'Gabe', :description => 'the simple one'
- @tycho = @pa.characters.create :name => 'Tycho', :description => 'the wordy one'
- @div = @pa.characters.create :name => 'Div', :description => 'a crude divx player with anger management issues'
-
- @martin = @qc.characters.create :name => 'Martin', :description => 'the insecure protagonist'
- @faye = @qc.characters.create :name => 'Faye', :description => 'a sarcastic barrista with anger management issues'
- @pintsize = @qc.characters.create :name => 'Pintsize', :description => 'a crude AnthroPC'
-
- @ananth = @jw.characters.create :name => 'Ananth', :description => 'Stubble! What is under that hat?!?'
- @yuko = @jw.characters.create :name => 'Yuko', :description => 'So... small. Carl Sagan haircut.'
- @john = @jw.characters.create :name => 'John', :description => 'Tall. Anger issues?'
- @cricket = @jw.characters.create :name => 'Cricket', :description => 'Chirrup!'
- end
-
- teardown do
- TexticleWebComic.delete_all
- Character.delete_all
- end
-
- should "look in the related model with nested searching syntax" do
- assert_equal [@jw], TexticleWebComic.joins(:characters).advanced_search(:characters => {:description => 'tall'})
- assert_equal [@pa, @jw, @qc].sort, TexticleWebComic.joins(:characters).advanced_search(:characters => {:description => 'anger'}).sort
- assert_equal [@pa, @qc].sort, TexticleWebComic.joins(:characters).advanced_search(:characters => {:description => 'crude'}).sort
- end
- end
- end
-
- context "after extending an ActiveRecord::Base subclass" do
- setup do
- @zelda = GameExtendedWithTexticle.create :system => "NES", :title => "Legend of Zelda", :description => "A Link to the Past."
- @mario = GameExtendedWithTexticle.create :system => "NES", :title => "Super Mario Bros.", :description => "The original platformer."
- @sonic = GameExtendedWithTexticle.create :system => "Genesis", :title => "Sonic the Hedgehog", :description => "Spiky."
- @dkong = GameExtendedWithTexticle.create :system => "SNES", :title => "Diddy's Kong Quest", :description => "Donkey Kong Country 2"
- @megam = GameExtendedWithTexticle.create :system => nil, :title => "Mega Man", :description => "Beware Dr. Brain"
- @sfnes = GameExtendedWithTexticle.create :system => "SNES", :title => "Street Fighter 2", :description => "Yoga Flame!"
- @sfgen = GameExtendedWithTexticle.create :system => "Genesis", :title => "Street Fighter 2", :description => "Yoga Flame!"
- @takun = GameExtendedWithTexticle.create :system => "Saturn", :title => "Magical Tarurūto-kun", :description => "カッコイイ!"
- end
-
- teardown do
- GameExtendedWithTexticle.delete_all
- end
-
- should "not break respond_to? when connection is unavailable" do
- GameFailExtendedWithTexticle.establish_connection({:adapter => :postgresql, :database =>'unavailable', :username=>'bad', :pool=>5, :timeout=>5000}) rescue nil
-
- assert_nothing_raised do
- GameFailExtendedWithTexticle.respond_to?(:advanced_search)
- end
- end
-
- should "define a #search method" do
- assert GameExtendedWithTexticle.respond_to?(:search)
- end
-
- context "when searching with a String argument" do
- should "search across all :string columns if no indexes have been specified" do
- assert_equal [@mario], GameExtendedWithTexticle.advanced_search("Mario")
- assert_equal Set.new([@mario, @zelda]), GameExtendedWithTexticle.advanced_search("NES").to_set
- end
-
- should "work if the query contains an apostrophe" do
- assert_equal [@dkong], GameExtendedWithTexticle.advanced_search("Diddy's")
- end
-
- should "work if the query contains whitespace" do
- assert_equal [@megam], GameExtendedWithTexticle.advanced_search("Mega Man")
- end
-
- should "work if the query contains an accent" do
- assert_equal [@takun], GameExtendedWithTexticle.advanced_search("Tarurūto-kun")
- end
-
- should "search across records with NULL values" do
- assert_equal [@megam], GameExtendedWithTexticle.advanced_search("Mega")
- end
-
- should "scope consecutively" do
- assert_equal [@sfgen], GameExtendedWithTexticle.advanced_search("Genesis").advanced_search("Street Fighter")
- end
- end
-
- context "when searching with a Hash argument" do
- should "search across the given columns" do
- assert_empty GameExtendedWithTexticle.advanced_search(:title => "NES")
- assert_empty GameExtendedWithTexticle.advanced_search(:system => "Mario")
- assert_empty GameExtendedWithTexticle.advanced_search(:system => "NES", :title => "Sonic")
-
- assert_equal [@mario], GameExtendedWithTexticle.advanced_search(:title => "Mario")
-
- assert_equal 2, GameExtendedWithTexticle.advanced_search(:system => "NES").count
-
- assert_equal [@zelda], GameExtendedWithTexticle.advanced_search(:system => "NES", :title => "Zelda")
- assert_equal [@megam], GameExtendedWithTexticle.advanced_search(:title => "Mega")
- end
-
- should "scope consecutively" do
- assert_equal [@sfgen], GameExtendedWithTexticle.advanced_search(:system => "Genesis").advanced_search(:title => "Street Fighter")
- end
-
- should "cast non-:string columns as text" do
- assert_equal [@mario], GameExtendedWithTexticle.advanced_search(:id => @mario.id)
- end
- end
-
- context "when using dynamic search methods" do
- should "generate methods for each :string column" do
- assert_equal [@mario], GameExtendedWithTexticle.advanced_search_by_title("Mario")
- assert_equal [@takun], GameExtendedWithTexticle.advanced_search_by_system("Saturn")
- end
-
- should "generate methods for each :text column" do
- assert_equal [@mario], GameExtendedWithTexticle.advanced_search_by_description("platform")
- end
-
- should "generate methods for any combination of :string and :text columns" do
- assert_equal [@mario], GameExtendedWithTexticle.advanced_search_by_title_and_system("Mario", "NES")
- assert_equal [@sonic], GameExtendedWithTexticle.advanced_search_by_system_and_title("Genesis", "Sonic")
- assert_equal [@mario], GameExtendedWithTexticle.advanced_search_by_title_and_title("Mario", "Mario")
- assert_equal [@megam], GameExtendedWithTexticle.advanced_search_by_title_and_description("Man", "Brain")
- end
-
- should "generate methods for inclusive searches" do
- assert_equal Set.new([@megam, @takun]), GameExtendedWithTexticle.advanced_search_by_system_or_title("Saturn", "Mega Man").to_set
- end
-
- should "scope consecutively" do
- assert_equal [@sfgen], GameExtendedWithTexticle.advanced_search_by_system("Genesis").advanced_search_by_title("Street Fighter")
- end
-
- should "generate methods for non-:string columns" do
- assert_equal [@mario], GameExtendedWithTexticle.advanced_search_by_id(@mario.id)
- end
-
- should "work with #respond_to?" do
- assert GameExtendedWithTexticle.respond_to?(:advanced_search_by_system)
- assert GameExtendedWithTexticle.respond_to?(:advanced_search_by_title)
- assert GameExtendedWithTexticle.respond_to?(:advanced_search_by_system_and_title)
- assert GameExtendedWithTexticle.respond_to?(:advanced_search_by_system_or_title)
- assert GameExtendedWithTexticle.respond_to?(:advanced_search_by_title_and_title_and_title)
- assert GameExtendedWithTexticle.respond_to?(:advanced_search_by_id)
-
- assert !GameExtendedWithTexticle.respond_to?(:advanced_search_by_title_and_title_or_title)
- end
-
- should "allow for 2 arguments to #respond_to?" do
- assert GameExtendedWithTexticle.respond_to?(:normalize, true)
- end
- end
-
- context "when searching after selecting columns to return" do
- should "not fetch extra columns" do
- assert_raise(ActiveModel::MissingAttributeError) do
- GameExtendedWithTexticle.select(:title).advanced_search("Mario").first.system
- end
- end
- end
-
- context "when setting a custom search language" do
- setup do
- GameExtendedWithTexticleAndCustomLanguage.create :system => "PS3", :title => "Harry Potter & the Deathly Hallows"
- end
-
- teardown do
- GameExtendedWithTexticleAndCustomLanguage.delete_all
- end
-
- should "still find results" do
- assert_not_empty GameExtendedWithTexticleAndCustomLanguage.advanced_search_by_title("harry")
- end
- end
- end
-end
View
30 texticle.gemspec → textacular.gemspec
@@ -1,19 +1,19 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../lib/texticle/version', __FILE__)
+require File.expand_path('../lib/textacular/version', __FILE__)
Gem::Specification.new do |s|
- s.name = 'texticle'
- s.version = Texticle::VERSION
+ s.name = 'textacular'
+ s.version = Textacular::VERSION
- s.summary = 'Texticle exposes full text search capabilities from PostgreSQL'
- s.description = 'Texticle exposes full text search capabilities from PostgreSQL, extending
+ s.summary = 'Textacular exposes full text search capabilities from PostgreSQL'
+ s.description = 'Textacular exposes full text search capabilities from PostgreSQL, extending
ActiveRecord with scopes making search easy and fun!'
s.license = 'MIT'
s.authors = ['Ben Hamill', 'ecin', 'Aaron Patterson']
s.email = ['git-commits@benhamill.com', 'ecin@copypastel.com']
- s.homepage = 'http://texticle.github.com/texticle'
+ s.homepage = 'http://textacular.github.com/textacular'
s.files = [
'CHANGELOG.md',
@@ -21,13 +21,13 @@ Gem::Specification.new do |s|
'Manifest.txt',
'README.md',
'Rakefile',
- 'lib/texticle.rb',
- 'lib/texticle/full_text_indexer.rb',
- 'lib/texticle/postgres_module_installer.rb',
- 'lib/texticle/rails.rb',
- 'lib/texticle/searchable.rb',
- 'lib/texticle/tasks.rb',
- 'lib/texticle/version.rb'
+ 'lib/textacular.rb',
+ 'lib/textacular/full_text_indexer.rb',
+ 'lib/textacular/postgres_module_installer.rb',
+ 'lib/textacular/rails.rb',
+ 'lib/textacular/searchable.rb',
+ 'lib/textacular/tasks.rb',
+ 'lib/textacular/version.rb'
]
s.executables = []
s.test_files = [
@@ -36,8 +36,8 @@ Gem::Specification.new do |s|
'spec/fixtures/game.rb',
'spec/fixtures/webcomic.rb',
'spec/spec_helper.rb',
- 'spec/texticle/searchable_spec.rb',
- 'spec/texticle_spec.rb'
+ 'spec/textacular/searchable_spec.rb',
+ 'spec/textacular_spec.rb'
]
s.require_paths = ['lib']
Please sign in to comment.
Something went wrong with that request. Please try again.