make_taggable 0.6.3 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/mysql_tests.yml +56 -0
  3. data/.github/workflows/pg_tests.yml +56 -0
  4. data/.github/workflows/{ci.yml → sqlite_tests.yml} +10 -10
  5. data/.github/workflows/standardrb-check.yml +37 -0
  6. data/.gitignore +3 -0
  7. data/Appraisals +4 -0
  8. data/README.md +77 -33
  9. data/Rakefile +4 -0
  10. data/UPGRADING.md +5 -0
  11. data/db/migrate/3_change_tag_name_collation_mysql.rb +7 -0
  12. data/db/migrate/{3_add_index_to_tags.rb → 4_add_index_to_tags.rb} +0 -0
  13. data/db/migrate/{4_add_index_to_taggings.rb → 5_add_index_to_taggings.rb} +0 -0
  14. data/lib/make_taggable.rb +3 -3
  15. data/lib/make_taggable/taggable/tagged_with_query/query_base.rb +4 -4
  16. data/lib/make_taggable/tagger.rb +1 -1
  17. data/lib/make_taggable/tagging.rb +1 -1
  18. data/lib/make_taggable/version.rb +1 -2
  19. data/lib/tasks/setup_test_db.rake +6 -0
  20. data/make_taggable.gemspec +22 -8
  21. data/spec/dummy/README.md +0 -24
  22. data/spec/dummy/app/models/cached_model_with_array.rb +0 -6
  23. data/spec/dummy/app/models/taggable_model_with_json.rb +6 -0
  24. data/spec/dummy/config/application.rb +2 -8
  25. data/spec/dummy/config/database.yml +1 -19
  26. data/spec/dummy/config/mysql_database.yml.ci +8 -0
  27. data/spec/dummy/config/pg_database.yml.ci +8 -0
  28. data/spec/dummy/db/migrate/{20201119220853_create_taggable_models.rb → 020201119220853_create_taggable_models.rb} +0 -0
  29. data/spec/dummy/db/migrate/{20201119221037_create_columns_override_models.rb → 020201119221037_create_columns_override_models.rb} +0 -0
  30. data/spec/dummy/db/migrate/{20201119221121_create_non_standard_id_taggable_models.rb → 020201119221121_create_non_standard_id_taggable_models.rb} +0 -0
  31. data/spec/dummy/db/migrate/{20201119221228_create_untaggable_models.rb → 020201119221228_create_untaggable_models.rb} +0 -0
  32. data/spec/dummy/db/migrate/{20201119221247_create_cached_models.rb → 020201119221247_create_cached_models.rb} +0 -0
  33. data/spec/dummy/db/migrate/{20201119221314_create_other_cached_models.rb → 020201119221314_create_other_cached_models.rb} +0 -0
  34. data/spec/dummy/db/migrate/{20201119221343_create_companies.rb → 020201119221343_create_companies.rb} +0 -0
  35. data/spec/dummy/db/migrate/{20201119221416_create_users.rb → 020201119221416_create_users.rb} +0 -0
  36. data/spec/dummy/db/migrate/{20201119221434_create_other_taggable_models.rb → 020201119221434_create_other_taggable_models.rb} +0 -0
  37. data/spec/dummy/db/migrate/{20201119221507_create_ordered_taggable_models.rb → 020201119221507_create_ordered_taggable_models.rb} +0 -0
  38. data/spec/dummy/db/migrate/{20201119221530_create_cache_methods_injected_models.rb → 020201119221530_create_cache_methods_injected_models.rb} +0 -0
  39. data/spec/dummy/db/migrate/{20201119221629_create_other_cached_with_array_models.rb → 020201119221629_create_other_cached_with_array_models.rb} +0 -0
  40. data/spec/dummy/db/migrate/{20201119221746_create_taggable_model_with_jsons.rb → 020201119221746_create_taggable_model_with_jsons.rb} +0 -0
  41. data/spec/make_taggable/tag_spec.rb +88 -250
  42. data/spec/make_taggable/taggable_spec.rb +1 -1
  43. data/spec/spec_helper.rb +0 -2
  44. metadata +116 -80
  45. data/.travis.yml +0 -36
  46. data/gemfiles/rails_5.gemfile +0 -9
  47. data/gemfiles/rails_6.gemfile +0 -9
  48. data/gemfiles/rails_master.gemfile +0 -9
  49. data/spec/dummy/db/migrate/20201119222429_create_make_taggable_tags.make_taggable_engine.rb +0 -11
  50. data/spec/dummy/db/migrate/20201119222430_create_make_taggable_taggings.make_taggable_engine.rb +0 -13
  51. data/spec/dummy/db/migrate/20201119222431_add_index_to_tags.make_taggable_engine.rb +0 -6
  52. data/spec/dummy/db/migrate/20201119222432_add_index_to_taggings.make_taggable_engine.rb +0 -13
  53. data/spec/dummy/db/schema.rb +0 -117
  54. data/spec/dummy/db/seeds.rb +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75e4c687d801738a1e36a15accd18686dd13ed883941e609bbfae23f98eaaae9
4
- data.tar.gz: 103971ae8293cbfaaf351c3193022332eb024581c02ca89ea1d95d8bb8a4f154
3
+ metadata.gz: 656b91c8e3413eb256819e637338927cd744e9502e9208ab2ee983344eeb0dc0
4
+ data.tar.gz: fc1d7f0e41f254536af79d94a0d42d40afb1f8db2e6a7fc1ff92f7536efe8b39
5
5
  SHA512:
6
- metadata.gz: eaf416b1f1490f92bf44c1992bbf68519a44ef55068f4183c73fbb19f729d4864e89124a4454e65afe9e164e16c9339f3659ae4d6ed95821ddfd15371649de3d
7
- data.tar.gz: 46b07f4697367374b69458d011b6770883ae36b29c519c66dedd1aa070ca22cb08defecc8d80da29d79860a82368592898ba3be5a77d7b33e308f5a4c2d630f3
6
+ metadata.gz: ebac450ac5fdc36410898fa78e1a8d93453967ffdc4a9326c3438348d462ccff566bb65282ee50b1bf7c3af32a48764f18139bc566635253401f936497670319
7
+ data.tar.gz: 0662c53dc1f42ef1fd87b3d9ee1d26ab8af286e2f85105ffe9cf6af4fa41eb0b189ecc34fa1e752615107acc3bcaa27186deb19ad7b5cf5978436d4e66965e03
@@ -0,0 +1,56 @@
1
+ ---
2
+ name: MySQL Tests
3
+
4
+ on:
5
+ pull_request:
6
+ branches:
7
+ - '*'
8
+ push:
9
+ branches:
10
+ - master
11
+ jobs:
12
+ mysql:
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ matrix:
16
+ ruby: ['2.5', '2.6', '2.7']
17
+
18
+ services:
19
+ mysql:
20
+ image: mysql:8
21
+ env:
22
+ MYSQL_ROOT_PASSWORD: password
23
+ MSQL_DATABASE: my_sql_test_db
24
+ ports: ['3306:3306']
25
+ options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
26
+
27
+ steps:
28
+ - uses: actions/checkout@master
29
+
30
+ - name: Set up Ruby ${{ matrix.ruby }}
31
+ uses: ruby/setup-ruby@v1
32
+ with:
33
+ ruby-version: ${{ matrix.ruby }}
34
+
35
+ - name: Cache gems
36
+ uses: actions/cache@v2
37
+ with:
38
+ path: vendor/bundle
39
+ key: ${{ runner.os }}-${{ matrix.ruby }}-gem-${{ hashFiles('**/Gemfile.lock') }}
40
+ restore-keys: |
41
+ ${{ runner.os }}-${{ matrix.ruby }}-gem-
42
+
43
+ - name: Install dependencies
44
+ run: |
45
+ gem install bundler
46
+ bundle install --jobs 4 --retry 3
47
+ bundle exec appraisal install
48
+
49
+ - name: Run tests
50
+ env:
51
+ DATABASE_URL: mysql2://root:password@127.0.0.1:3306/my_sql_test_db
52
+ RAILS_ENV: test
53
+ run: |
54
+ cp spec/dummy/config/mysql_database.yml.ci spec/dummy/config/database.yml
55
+ bundle exec rake test_app
56
+ bundle exec appraisal rake
@@ -0,0 +1,56 @@
1
+ ---
2
+ name: Postgres Tests
3
+
4
+ on:
5
+ pull_request:
6
+ branches:
7
+ - '*'
8
+ push:
9
+ branches:
10
+ - master
11
+ jobs:
12
+ postgres:
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ matrix:
16
+ ruby: ['2.5', '2.6', '2.7']
17
+
18
+ services:
19
+ postgres:
20
+ image: postgres:12
21
+ env:
22
+ POSTGRES_USER: postgres
23
+ POSTGRES_PASSWORD: password
24
+ POSTGRES_DB: pg_test
25
+ ports: ['5432:5432']
26
+
27
+ steps:
28
+ - uses: actions/checkout@master
29
+
30
+ - name: Set up Ruby ${{ matrix.ruby }}
31
+ uses: ruby/setup-ruby@v1
32
+ with:
33
+ ruby-version: ${{ matrix.ruby }}
34
+
35
+ - name: Cache gems
36
+ uses: actions/cache@v2
37
+ with:
38
+ path: vendor/bundle
39
+ key: ${{ runner.os }}-${{ matrix.ruby }}-gem-${{ hashFiles('**/Gemfile.lock') }}
40
+ restore-keys: |
41
+ ${{ runner.os }}-${{ matrix.ruby }}-gem-
42
+
43
+ - name: Install dependencies
44
+ run: |
45
+ gem install bundler
46
+ bundle install --jobs 4 --retry 3
47
+ bundle exec appraisal install
48
+
49
+ - name: Run tests
50
+ env:
51
+ DATABASE_URL: postgres://postgres:password@localhost:5432/pg_test
52
+ RAILS_ENV: test
53
+ run: |
54
+ cp spec/dummy/config/pg_database.yml.ci spec/dummy/config/database.yml
55
+ bundle exec rake test_app
56
+ bundle exec appraisal rake
@@ -1,4 +1,5 @@
1
- name: Tests
1
+ ---
2
+ name: SQLite Tests
2
3
 
3
4
  on:
4
5
  pull_request:
@@ -8,26 +9,27 @@ on:
8
9
  branches:
9
10
  - master
10
11
  jobs:
11
- test:
12
+ sqlite:
12
13
  runs-on: ubuntu-latest
13
14
  strategy:
14
15
  matrix:
15
- ruby: [ '2.7', '2.6', '2.5' ]
16
+ ruby: ['2.5', '2.6', '2.7']
16
17
  steps:
17
18
  - uses: actions/checkout@master
18
19
 
19
- - name: Set up Ruby
20
+ - name: Set up Ruby ${{ matrix.ruby }}
20
21
  uses: ruby/setup-ruby@v1
21
22
  with:
22
23
  ruby-version: ${{ matrix.ruby }}
23
24
 
24
25
  - name: Cache gems
25
- uses: actions/cache@v1
26
+ uses: actions/cache@v2
26
27
  with:
27
28
  path: vendor/bundle
28
- key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
29
+ key: ${{ runner.os }}-${{ matrix.ruby }}-gem-${{ hashFiles('**/Gemfile.lock') }}
29
30
  restore-keys: |
30
- ${{ runner.os }}-gem-
31
+ ${{ runner.os }}-${{ matrix.ruby }}-gem-
32
+
31
33
  - name: Install dependencies
32
34
  run: |
33
35
  sudo apt-get update
@@ -37,11 +39,9 @@ jobs:
37
39
  bundle install --jobs 4 --retry 3
38
40
  bundle exec appraisal install
39
41
 
40
- - name: StandardRb check
41
- run: bundle exec standardrb
42
-
43
42
  - name: Run tests
44
43
  env:
45
44
  RAILS_ENV: test
46
45
  run: |
46
+ bundle exec rake test_app
47
47
  bundle exec appraisal rake
@@ -0,0 +1,37 @@
1
+ name: Standard Rb
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - '*'
7
+ push:
8
+ branches:
9
+ - master
10
+
11
+ jobs:
12
+ standard:
13
+ name: StandardRB Check Action
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@master
17
+
18
+ - name: Set up Ruby 2.7
19
+ uses: actions/setup-ruby@v1
20
+ with:
21
+ ruby-version: 2.7.x
22
+
23
+ - uses: actions/cache@v1
24
+ with:
25
+ path: vendor/bundle
26
+ key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
27
+ restore-keys: |
28
+ ${{ runner.os }}-gems-
29
+
30
+ - name: Bundle install
31
+ run: |
32
+ gem install bundler
33
+ bundle config path vendor/bundle
34
+ bundle install --jobs 4 --retry 3
35
+
36
+ - name: Run StandardRB
37
+ run: bundle exec standardrb --format progress
data/.gitignore CHANGED
@@ -11,3 +11,6 @@ tmp
11
11
  *.lock
12
12
  *.iml
13
13
  /.idea
14
+ spec/dummy/db/schema.rb
15
+ spec/dummy/db/migrate/[!0]*
16
+ /gemfiles/*
data/Appraisals CHANGED
@@ -6,6 +6,10 @@ appraise "rails-6" do
6
6
  gem "rails", "~> 6.0.0"
7
7
  end
8
8
 
9
+ appraise "rails-6-1" do
10
+ gem "rails", "~> 6.1.0"
11
+ end
12
+
9
13
  appraise "rails-master" do
10
14
  gem "rails", github: "rails/rails"
11
15
  end
data/README.md CHANGED
@@ -1,26 +1,20 @@
1
1
  # MakeTaggable
2
2
  [![Gem Version](https://badge.fury.io/rb/make_taggable.svg)](https://badge.fury.io/rb/make_taggable)
3
- [![Build Status](https://travis-ci.com/MatthewKennedy/make_taggable.svg?branch=master)](https://travis-ci.com/MatthewKennedy/make_taggable)
4
- [![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
3
+ ![Postgres Tests](https://github.com/MatthewKennedy/make_taggable/workflows/Postgres%20Tests/badge.svg)
4
+ ![MySQL Tests](https://github.com/MatthewKennedy/make_taggable/workflows/MySQL%20Tests/badge.svg)
5
+ ![SQLite Tests](https://github.com/MatthewKennedy/make_taggable/workflows/SQLite%20Tests/badge.svg)
6
+ ![Standard Rb](https://github.com/MatthewKennedy/make_taggable/workflows/Standard%20Rb/badge.svg)
5
7
 
6
- MakeTaggable is a fork of acts-as-taggable-on v6.5 with code updates and a new set of migrations. All credit goes to those who contributed before acts-as-taggable-on became MakeTaggable: Michael Bleigh & Joost Baaij.
8
+ MakeTaggable is a fork of Acts-As-Taggable-On with code updates, fresh migrations that work on MySQL, and tested against a dummy Rails app.
7
9
 
8
- Why fork acts-as-taggable-on? Act As Taggable On appears stuck with a set of legacy migrations from rails pre [4.2] that added and removed indexes so much that the migrations do not run on a fresh install using MySQL.
9
-
10
- For the PostgreSQL users, this is not an issue, but if you have an app or gem that used acts-as-taggable-on, you can no longer test against MySQL, so it seems a fresh start would be useful to clear out any legacy issues and move forward.
10
+ All credit goes to those who contributed to Acts-As-Taggable-On: Michael Bleigh & Joost Baaij.
11
11
 
12
12
  ## Installation
13
13
 
14
- To use it, add it to your Gemfile:
15
-
16
- ```ruby
17
- gem "make_taggable", "~> 0.6.0"
18
- ```
19
-
20
- and bundle:
14
+ To use make_taggable, run the followng from the root of your application:
21
15
 
22
16
  ```shell
23
- bundle
17
+ bundle add make_taggable
24
18
  ```
25
19
 
26
20
  #### Post Installation
@@ -28,15 +22,30 @@ bundle
28
22
  Install migrations
29
23
 
30
24
  ```shell
31
- # For the latest versions :
32
25
  rails make_taggable_engine:install:migrations
33
26
  ```
34
27
 
35
- Review the generated migrations then migrate :
28
+ Review the generated migrations then migrate:
36
29
  ```shell
37
30
  rails db:migrate
38
31
  ```
39
32
 
33
+ #### For MySql users
34
+ To make MySQL play nice with spÉcial characters you can setting the following line in an initializer file:
35
+
36
+ ```ruby
37
+ MakeTaggable.force_binary_collation = true
38
+ ```
39
+
40
+ Or by run this rake task:
41
+
42
+ ```shell
43
+ rails make_taggable_engine:tag_names:collate_bin
44
+ ```
45
+
46
+ See the Configuration section for more details.
47
+
48
+
40
49
  ## Usage
41
50
 
42
51
  Setup
@@ -167,7 +176,7 @@ MakeTaggable::Tag.least_used(10)
167
176
 
168
177
  ### Finding Tagged Objects
169
178
 
170
- Make Taggable uses scopes to create an association for tags.
179
+ MakeTaggable uses scopes to create an association for tags.
171
180
  This way you can mix and match to filter down your results.
172
181
 
173
182
  ```ruby
@@ -396,6 +405,7 @@ CSS:
396
405
  .css4 { font-size: 1.6em; }
397
406
  ```
398
407
 
408
+
399
409
  ## Configuration
400
410
 
401
411
  If you would like to remove unused tag objects after removing taggings, add:
@@ -444,35 +454,69 @@ MakeTaggable.delimiter = ','
444
454
  *NOTE 1: SQLite by default can't upcase or downcase multibyte characters, resulting in unwanted behavior. Load the SQLite ICU extension for proper handle of such characters. [See docs](http://www.sqlite.org/src/artifact?ci=trunk&filename=ext/icu/README.txt)*
445
455
 
446
456
 
447
- #### Upgrading
448
-
449
- see [UPGRADING](UPGRADING.md)
457
+ ## Upgrading
450
458
 
451
- ## Contributors
459
+ Install new migrations by running:
452
460
 
453
- We have a long list of valued contributors. [Check them all](https://github.com/mbleigh/acts-as-taggable-on/contributors)
461
+ ```shell
462
+ rails make_taggable_engine:install:migrations
463
+ ```
454
464
 
455
465
  ## Compatibility
456
466
 
457
- Versions 0.6.x is compatible with Ruby 2.5 + and Rails 6.
467
+ Version 0.7.x is compatible with Ruby 2.5 > and Rails 5.2 >
458
468
 
459
469
 
460
- ## TODO
461
- - Review migrations indexes they seem excessive looking at the schema.
462
- - See if the newer version of ActiveRecord or arel can be used instead of the MySQL workarounds.
463
-
464
470
  ## Testing
465
471
 
466
- Make Taggable uses RSpec for its test coverage. Inside the gem
467
- directory, you can run the specs with:
472
+ MakeTaggable uses RSpec for its test coverage. Inside the gem directory, you can run the specs by following the steps below:
473
+
474
+ Install the rquired gems:
475
+
476
+ ```shell
477
+ bundle install
478
+ ```
479
+
480
+ Setup the dummy test app:
481
+
482
+ ```shell
483
+ bundle exec rake test_app
484
+ ```
485
+
486
+ Run the spec tests against SQLite use the followiong command.
487
+
488
+ ```shell
489
+ bundle exec rake
490
+ ```
491
+
492
+ You can also run all the tests across all the Rails versions by running:
493
+
494
+ ```shell
495
+ bundle exec appraisal install
496
+
497
+ bundle exec appraisal rake
498
+ ```
499
+
500
+ ## Contributing
501
+
502
+ Please use the following Standard Rb commands to format your code before creating a pull request:
503
+
504
+ Check for code errors:
505
+
506
+ ```shell
507
+ bundle exec standardrb
508
+ ```
509
+
510
+ Fix code errors:
468
511
 
469
512
  ```shell
470
- bundle
471
- rake spec
513
+ bundle exec standardrb --fix
472
514
  ```
515
+ For more information please review the [Contributing](https://github.com/MatthewKennedy/make_taggable/blob/master/CONTRIBUTING.md) section.
473
516
 
474
- You can run all the tests across all the Rails versions by running `rake appraise`. If you'd also like to [run the tests across all rubies and databases as configured for Travis CI, install and run `wwtd`](https://github.com/grosser/wwtd).
517
+ #### Contributors
518
+ List of valued contributors From Acts-As-Taggable-On: [Check them all](https://github.com/mbleigh/acts-as-taggable-on/contributors)
475
519
 
476
520
 
477
521
  ## License
478
- MIT
522
+ This gem is available as open source under the terms of the [MIT License](https://github.com/MatthewKennedy/make_taggable/blob/master/LICENSE.txt).
data/Rakefile CHANGED
@@ -1,7 +1,11 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
+ import "./lib/tasks/tags_collate_utf8.rake"
4
+
3
5
  APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
4
6
 
5
7
  require "rspec/core/rake_task"
6
8
  RSpec::Core::RakeTask.new(:spec)
7
9
  task default: :spec
10
+
11
+ load "lib/tasks/setup_test_db.rake"
@@ -0,0 +1,5 @@
1
+ When upgrading run the migrations generator
2
+
3
+ rails make_taggable_engine:install:migrations
4
+
5
+ This will create any new migrations and skip existing ones
@@ -0,0 +1,7 @@
1
+ class ChangeTagNameCollationMysql < ActiveRecord::Migration[5.2]
2
+ def change
3
+ if MakeTaggable::Utils.using_mysql?
4
+ execute("ALTER TABLE #{MakeTaggable.tags_table} MODIFY name varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;")
5
+ end
6
+ end
7
+ end
@@ -111,10 +111,10 @@ module MakeTaggable
111
111
 
112
112
  def self.apply_binary_collation(bincoll)
113
113
  if Utils.using_mysql?
114
- coll = "utf8_general_ci"
115
- coll = "utf8_bin" if bincoll
114
+ coll = "utf8mb4_general_ci"
115
+ coll = "utf8mb4_bin" if bincoll
116
116
  begin
117
- ActiveRecord::Migration.execute("ALTER TABLE #{Tag.table_name} MODIFY name varchar(255) CHARACTER SET utf8 COLLATE #{coll};")
117
+ ActiveRecord::Migration.execute("ALTER TABLE #{Tag.table_name} MODIFY name varchar(255) CHARACTER SET utf8mb4 COLLATE #{coll};")
118
118
  rescue => e
119
119
  puts "Trapping #{e.class}: collation parameter ignored while migrating for the first time."
120
120
  end