textacular 3.2.0 → 3.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +7 -1
- data/Rakefile +5 -6
- data/lib/textacular/trigram_installer.rb +1 -1
- data/lib/textacular/version.rb +1 -1
- data/spec/config.travis.yml +8 -0
- data/spec/spec_helper.rb +93 -67
- data/spec/support/ar_stand_in.rb +4 -0
- data/spec/{fixtures → support}/character.rb +1 -0
- data/spec/{fixtures → support}/game.rb +0 -2
- data/spec/support/game_extended_with_textacular.rb +5 -0
- data/spec/support/game_extended_with_textacular_and_custom_language.rb +7 -0
- data/spec/support/game_fail.rb +3 -0
- data/spec/support/game_fail_extended_with_textacular.rb +5 -0
- data/spec/support/not_there.rb +3 -0
- data/spec/support/textacular_web_comic.rb +7 -0
- data/spec/{fixtures/webcomic.rb → support/web_comic.rb} +0 -0
- data/spec/support/web_comic_with_searchable.rb +6 -0
- data/spec/support/web_comic_with_searchable_name.rb +6 -0
- data/spec/support/web_comic_with_searchable_name_and_author.rb +6 -0
- data/spec/textacular/full_text_indexer_spec.rb +69 -0
- data/spec/textacular/migration_generator_spec.rb +67 -0
- data/spec/textacular/searchable_spec.rb +136 -55
- data/spec/textacular/trigram_installer_spec.rb +24 -0
- data/spec/textacular_spec.rb +292 -150
- metadata +54 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4265ce68e4f181daae87f7bd5ddeafd3b6319b74
|
4
|
+
data.tar.gz: 01747846949f1a3ceef279a62f1e4587cea23a7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cd720c7b946da4ec997dff477eae5ccc4133a086784bdd1a9521ba53c5b0683698c5daa6d445acf48b9eb600bfe2d805a60a5410ddcdaac7fd22259ad0040d2
|
7
|
+
data.tar.gz: 5978ac5a4a59eeaf656b09dcadb36f0034e8e9190d5d8c800e5525471b738c9fde8187676a130d0c2e9ebd160cbe9b448b808b16e3a1a3b5d10201df54ea0164
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
|
-
[![Build Status](https://travis-ci.org/textacular/textacular.png)](https://travis-ci.org/textacular/textacular) [![Code Climate](https://codeclimate.com/github/textacular/textacular.png)](https://codeclimate.com/github/textacular/textacular)
|
2
1
|
# textacular
|
2
|
+
[![Gem Version](http://img.shields.io/gem/v/textacular.svg)][rubygems]
|
3
|
+
[![Build Status](https://img.shields.io/travis/textacular/textacular/master.svg)][travis]
|
4
|
+
[![Code Climate](https://img.shields.io/codeclimate/github/textacular/textacular.svg)][codeclimate]
|
5
|
+
|
6
|
+
[rubygems]: http://rubygems.org/gems/textacular
|
7
|
+
[travis]: https://travis-ci.org/textacular/textacular
|
8
|
+
[codeclimate]: https://codeclimate.com/github/textacular/textacular
|
3
9
|
|
4
10
|
Further documentation available at http://textacular.github.com/textacular.
|
5
11
|
|
data/Rakefile
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
|
3
3
|
require 'active_record'
|
4
|
-
require 'rake/testtask'
|
5
4
|
require 'pry'
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
task :default => :
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
|
8
|
+
RSpec::Core::RakeTask.new(:spec)
|
9
|
+
|
10
|
+
task :default => :spec
|
12
11
|
|
13
12
|
file 'spec/config.yml' do |t|
|
14
13
|
sh 'erb spec/config.yml.example > spec/config.yml'
|
@@ -12,7 +12,7 @@ class InstallTrigram < ActiveRecord::Migration
|
|
12
12
|
end
|
13
13
|
MIGRATION
|
14
14
|
filename = "install_trigram"
|
15
|
-
generator = Textacular::MigrationGenerator.new(
|
15
|
+
generator = Textacular::MigrationGenerator.new(filename, content)
|
16
16
|
generator.generate_migration
|
17
17
|
end
|
18
18
|
end
|
data/lib/textacular/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,78 +1,104 @@
|
|
1
|
-
require 'bundler/setup'
|
2
|
-
require 'yaml'
|
3
|
-
require 'textacular'
|
4
|
-
require 'shoulda'
|
5
1
|
require 'pry'
|
6
|
-
require 'active_record'
|
7
2
|
require 'textacular'
|
8
|
-
require '
|
9
|
-
require '
|
3
|
+
require 'database_cleaner'
|
4
|
+
require 'yaml'
|
10
5
|
|
11
6
|
config = YAML.load_file File.expand_path(File.dirname(__FILE__) + '/config.yml')
|
12
7
|
ActiveRecord::Base.establish_connection config.merge(:adapter => :postgresql)
|
13
8
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
class WebComicWithSearchableNameAndAuthor < WebComic
|
44
|
-
extend Searchable(:name, :author)
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
class Character < ActiveRecord::Base
|
49
|
-
# string :name
|
50
|
-
# string :description
|
51
|
-
# integer :web_comic_id
|
52
|
-
|
53
|
-
belongs_to :web_comic
|
54
|
-
end
|
55
|
-
|
56
|
-
|
57
|
-
class Game < ActiveRecord::Base
|
58
|
-
# string :system
|
59
|
-
# string :title
|
60
|
-
# text :description
|
61
|
-
end
|
62
|
-
|
63
|
-
class GameExtendedWithTextacular < Game
|
64
|
-
extend Textacular
|
65
|
-
end
|
66
|
-
|
67
|
-
class GameExtendedWithTextacularAndCustomLanguage < GameExtendedWithTextacular
|
68
|
-
def searchable_language
|
69
|
-
'spanish'
|
9
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
10
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
11
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
12
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
13
|
+
#
|
14
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
15
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
16
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
17
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
18
|
+
# a separate helper file that requires the additional dependencies and performs
|
19
|
+
# the additional setup, and require it from the spec files that actually need it.
|
20
|
+
#
|
21
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
22
|
+
# users commonly want.
|
23
|
+
#
|
24
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
25
|
+
RSpec.configure do |config|
|
26
|
+
# rspec-expectations config goes here. You can use an alternate
|
27
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
28
|
+
# assertions if you prefer.
|
29
|
+
config.expect_with :rspec do |expectations|
|
30
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
31
|
+
# and `failure_message` of custom matchers include text for helper methods
|
32
|
+
# defined using `chain`, e.g.:
|
33
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
34
|
+
# # => "be bigger than 2 and smaller than 4"
|
35
|
+
# ...rather than:
|
36
|
+
# # => "be bigger than 2"
|
37
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
70
38
|
end
|
71
|
-
end
|
72
39
|
|
40
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
41
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
42
|
+
config.mock_with :rspec do |mocks|
|
43
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
44
|
+
# a real object. This is generally recommended, and will default to
|
45
|
+
# `true` in RSpec 4.
|
46
|
+
mocks.verify_partial_doubles = true
|
47
|
+
end
|
73
48
|
|
74
|
-
|
49
|
+
# These two settings work together to allow you to limit a spec run
|
50
|
+
# to individual examples or groups you care about by tagging them with
|
51
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
52
|
+
# get run.
|
53
|
+
config.filter_run :focus
|
54
|
+
config.run_all_when_everything_filtered = true
|
55
|
+
|
56
|
+
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
57
|
+
# For more details, see:
|
58
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
59
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
60
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
61
|
+
config.disable_monkey_patching!
|
62
|
+
|
63
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
64
|
+
# be too noisy due to issues in dependencies.
|
65
|
+
config.warnings = true
|
66
|
+
|
67
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
68
|
+
# file, and it's useful to allow more verbose output when running an
|
69
|
+
# individual spec file.
|
70
|
+
# if config.files_to_run.one?
|
71
|
+
# Use the documentation formatter for detailed output,
|
72
|
+
# unless a formatter has already been configured
|
73
|
+
# (e.g. via a command-line flag).
|
74
|
+
# config.default_formatter = 'doc'
|
75
|
+
# end
|
76
|
+
|
77
|
+
# Print the 10 slowest examples and example groups at the
|
78
|
+
# end of the spec run, to help surface which specs are running
|
79
|
+
# particularly slow.
|
80
|
+
# config.profile_examples = 10
|
81
|
+
|
82
|
+
# Run specs in random order to surface order dependencies. If you find an
|
83
|
+
# order dependency and want to debug it, you can fix the order by providing
|
84
|
+
# the seed, which is printed after each run.
|
85
|
+
# --seed 1234
|
86
|
+
config.order = :random
|
87
|
+
|
88
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
89
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
90
|
+
# test failures related to randomization by passing the same `--seed` value
|
91
|
+
# as the one that triggered the failure.
|
92
|
+
Kernel.srand config.seed
|
93
|
+
|
94
|
+
config.before(:suite) do
|
95
|
+
DatabaseCleaner.strategy = :transaction
|
96
|
+
DatabaseCleaner.clean_with(:truncation)
|
97
|
+
end
|
75
98
|
|
76
|
-
|
77
|
-
|
99
|
+
config.around(:each) do |example|
|
100
|
+
DatabaseCleaner.cleaning do
|
101
|
+
example.run
|
102
|
+
end
|
103
|
+
end
|
78
104
|
end
|
File without changes
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'support/web_comic_with_searchable_name'
|
2
|
+
require 'support/web_comic_with_searchable_name_and_author'
|
3
|
+
|
4
|
+
RSpec.describe Textacular::FullTextIndexer do
|
5
|
+
context "with one specific field in a Searchable call" do
|
6
|
+
it "generates the right SQL" do
|
7
|
+
file_name = "web_comic_with_searchable_name_full_text_search"
|
8
|
+
content = <<-MIGRATION
|
9
|
+
class WebComicWithSearchableNameFullTextSearch < ActiveRecord::Migration
|
10
|
+
def self.up
|
11
|
+
execute(<<-SQL.strip)
|
12
|
+
DROP index IF EXISTS web_comics_name_fts_idx;
|
13
|
+
CREATE index web_comics_name_fts_idx
|
14
|
+
ON web_comics
|
15
|
+
USING gin(to_tsvector("english", "web_comics"."name"::text));
|
16
|
+
SQL
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.down
|
20
|
+
execute(<<-SQL.strip)
|
21
|
+
DROP index IF EXISTS web_comics_name_fts_idx;
|
22
|
+
SQL
|
23
|
+
end
|
24
|
+
end
|
25
|
+
MIGRATION
|
26
|
+
|
27
|
+
generator = double(:migration_generator)
|
28
|
+
expect(Textacular::MigrationGenerator).to receive(:new).with(content, file_name).and_return(generator)
|
29
|
+
expect(generator).to receive(:generate_migration)
|
30
|
+
|
31
|
+
Textacular::FullTextIndexer.new.generate_migration('WebComicWithSearchableName')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "with two specific fields in a Searchable call" do
|
36
|
+
it "generates the right SQL" do
|
37
|
+
file_name = "web_comic_with_searchable_name_and_author_full_text_search"
|
38
|
+
content = <<-MIGRATION
|
39
|
+
class WebComicWithSearchableNameAndAuthorFullTextSearch < ActiveRecord::Migration
|
40
|
+
def self.up
|
41
|
+
execute(<<-SQL.strip)
|
42
|
+
DROP index IF EXISTS web_comics_name_fts_idx;
|
43
|
+
CREATE index web_comics_name_fts_idx
|
44
|
+
ON web_comics
|
45
|
+
USING gin(to_tsvector("english", "web_comics"."name"::text));
|
46
|
+
DROP index IF EXISTS web_comics_author_fts_idx;
|
47
|
+
CREATE index web_comics_author_fts_idx
|
48
|
+
ON web_comics
|
49
|
+
USING gin(to_tsvector("english", "web_comics"."author"::text));
|
50
|
+
SQL
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.down
|
54
|
+
execute(<<-SQL.strip)
|
55
|
+
DROP index IF EXISTS web_comics_name_fts_idx;
|
56
|
+
DROP index IF EXISTS web_comics_author_fts_idx;
|
57
|
+
SQL
|
58
|
+
end
|
59
|
+
end
|
60
|
+
MIGRATION
|
61
|
+
|
62
|
+
generator = double(:migration_generator)
|
63
|
+
expect(Textacular::MigrationGenerator).to receive(:new).with(content, file_name).and_return(generator)
|
64
|
+
expect(generator).to receive(:generate_migration)
|
65
|
+
|
66
|
+
Textacular::FullTextIndexer.new.generate_migration('WebComicWithSearchableNameAndAuthor')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
RSpec.describe Textacular::MigrationGenerator do
|
2
|
+
describe ".stream_output" do
|
3
|
+
context "when Rails is not defined" do
|
4
|
+
subject do
|
5
|
+
Textacular::MigrationGenerator.new('filename', 'content')
|
6
|
+
end
|
7
|
+
|
8
|
+
it "points to STDOUT" do
|
9
|
+
output_stream = nil
|
10
|
+
|
11
|
+
subject.stream_output do |io|
|
12
|
+
output_stream = io
|
13
|
+
end
|
14
|
+
|
15
|
+
expect(output_stream).to eq(STDOUT)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when Rails is defined" do
|
20
|
+
before do
|
21
|
+
module ::Rails
|
22
|
+
# Stub this out, sort of.
|
23
|
+
def self.root
|
24
|
+
File.join('.', 'fake_rails')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
after do
|
30
|
+
Object.send(:remove_const, :Rails)
|
31
|
+
FileUtils.rm_rf(File.join('.', 'fake_rails'))
|
32
|
+
end
|
33
|
+
|
34
|
+
let(:now) do
|
35
|
+
Time.now
|
36
|
+
end
|
37
|
+
|
38
|
+
subject do
|
39
|
+
Textacular::MigrationGenerator.new('file_name', 'content')
|
40
|
+
end
|
41
|
+
|
42
|
+
it "points to a properly names migration file" do
|
43
|
+
expected_file_name = "./fake_rails/db/migrate/#{now.strftime('%Y%m%d%H%M%S')}_file_name.rb"
|
44
|
+
|
45
|
+
output_stream = nil
|
46
|
+
|
47
|
+
subject.stream_output(now) do |io|
|
48
|
+
output_stream = io
|
49
|
+
end
|
50
|
+
|
51
|
+
expect(output_stream.path).to eq(expected_file_name)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
it "generates the right SQL" do
|
56
|
+
content = "content\n" #newline automatically added
|
57
|
+
output = StringIO.new
|
58
|
+
|
59
|
+
generator = Textacular::MigrationGenerator.new('file_name', content)
|
60
|
+
generator.instance_variable_set(:@output_stream, output)
|
61
|
+
|
62
|
+
generator.generate_migration
|
63
|
+
|
64
|
+
expect(output.string).to eq(content)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|