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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3370755c291011043272f5b45c44d4c9d9ad8445
4
- data.tar.gz: b0c0b7c22dd7c79b7a343af679ba5ab9cee2e817
3
+ metadata.gz: 4265ce68e4f181daae87f7bd5ddeafd3b6319b74
4
+ data.tar.gz: 01747846949f1a3ceef279a62f1e4587cea23a7a
5
5
  SHA512:
6
- metadata.gz: 9d426b395d05e45de9ac1341f7b19ae3cf35533801e2c62dba488c221c15e0a78602e4ee349f720186701dc39586899671508068f837bfdf0852a7012c9475dc
7
- data.tar.gz: 031698a4ae0185a3e73fd4a191f04e1a497258958378056469228e826f28b138d0aaa5b182b209841322c47fa803f31824d2751a2b13feebb86f1e361c1f76c5
6
+ metadata.gz: 9cd720c7b946da4ec997dff477eae5ccc4133a086784bdd1a9521ba53c5b0683698c5daa6d445acf48b9eb600bfe2d805a60a5410ddcdaac7fd22259ad0040d2
7
+ data.tar.gz: 5978ac5a4a59eeaf656b09dcadb36f0034e8e9190d5d8c800e5525471b738c9fde8187676a130d0c2e9ebd160cbe9b448b808b16e3a1a3b5d10201df54ea0164
@@ -1,5 +1,10 @@
1
1
  # Change Log
2
2
 
3
+ ## Unreleased
4
+
5
+ * Fix trigram installation migration reversed filename and content.
6
+ * Rewrite all tests using RSpec.
7
+
3
8
  ## 3.2.0
4
9
 
5
10
  * Add generator for trigram installation migration.
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
- Rake::TestTask.new do |t|
8
- t.libs << 'spec'
9
- t.test_files = FileList[ 'spec/**/*_spec.rb' ]
10
- end
11
- task :default => :test
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(content, filename)
15
+ generator = Textacular::MigrationGenerator.new(filename, content)
16
16
  generator.generate_migration
17
17
  end
18
18
  end
@@ -1,5 +1,5 @@
1
1
  module Textacular
2
- VERSION = '3.2.0'
2
+ VERSION = '3.2.1'
3
3
 
4
4
  def self.version
5
5
  VERSION
@@ -0,0 +1,8 @@
1
+ pool: 5
2
+ timeout: 5000
3
+ host: localhost
4
+ adapter: postgresql
5
+ username: postgres
6
+ password:
7
+ database: textacular_test
8
+ min_messages: ERROR
@@ -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 'textacular/searchable'
9
- require 'flexmock/test_unit'
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
- class ARStandIn < ActiveRecord::Base;
15
- self.abstract_class = true
16
- extend Textacular
17
- end
18
-
19
- class NotThere < ARStandIn; end
20
-
21
- class TextacularWebComic < ARStandIn;
22
- has_many :characters, :foreign_key => :web_comic_id
23
- self.table_name = :web_comics
24
- end
25
-
26
-
27
- class WebComic < ActiveRecord::Base
28
- # string :name
29
- # string :author
30
- # integer :id
31
-
32
- has_many :characters
33
- end
34
-
35
- class WebComicWithSearchable < WebComic
36
- extend Searchable
37
- end
38
-
39
- class WebComicWithSearchableName < WebComic
40
- extend Searchable(:name)
41
- end
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
- class GameFail < Game; end
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
- class GameFailExtendedWithTextacular < GameFail
77
- extend Textacular
99
+ config.around(:each) do |example|
100
+ DatabaseCleaner.cleaning do
101
+ example.run
102
+ end
103
+ end
78
104
  end
@@ -0,0 +1,4 @@
1
+ class ARStandIn < ActiveRecord::Base;
2
+ self.abstract_class = true
3
+ extend Textacular
4
+ end
@@ -2,5 +2,6 @@ class Character < ActiveRecord::Base
2
2
  # string :name
3
3
  # string :description
4
4
  # integer :web_comic_id
5
+
5
6
  belongs_to :web_comic
6
7
  end
@@ -3,5 +3,3 @@ class Game < ActiveRecord::Base
3
3
  # string :title
4
4
  # text :description
5
5
  end
6
-
7
- class GameFail < Game; end
@@ -0,0 +1,5 @@
1
+ require 'support/game'
2
+
3
+ class GameExtendedWithTextacular < Game
4
+ extend Textacular
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'support/game_extended_with_textacular'
2
+
3
+ class GameExtendedWithTextacularAndCustomLanguage < GameExtendedWithTextacular
4
+ def searchable_language
5
+ 'spanish'
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ require 'support/game'
2
+
3
+ class GameFail < Game; end
@@ -0,0 +1,5 @@
1
+ require 'support/game_fail'
2
+
3
+ class GameFailExtendedWithTextacular < GameFail
4
+ extend Textacular
5
+ end
@@ -0,0 +1,3 @@
1
+ require 'support/ar_stand_in'
2
+
3
+ class NotThere < ARStandIn; end
@@ -0,0 +1,7 @@
1
+ require 'support/ar_stand_in'
2
+ require 'support/character'
3
+
4
+ class TextacularWebComic < ARStandIn;
5
+ has_many :characters, :foreign_key => :web_comic_id
6
+ self.table_name = :web_comics
7
+ end
@@ -0,0 +1,6 @@
1
+ require 'textacular/searchable'
2
+ require 'support/web_comic'
3
+
4
+ class WebComicWithSearchable < WebComic
5
+ extend Searchable
6
+ end
@@ -0,0 +1,6 @@
1
+ require 'textacular/searchable'
2
+ require 'support/web_comic'
3
+
4
+ class WebComicWithSearchableName < WebComic
5
+ extend Searchable(:name)
6
+ end
@@ -0,0 +1,6 @@
1
+ require 'textacular/searchable'
2
+ require 'support/web_comic'
3
+
4
+ class WebComicWithSearchableNameAndAuthor < WebComic
5
+ extend Searchable(:name, :author)
6
+ end
@@ -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