make_taggable 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ci.yml +47 -0
  3. data/.gitignore +13 -0
  4. data/.rspec +3 -0
  5. data/.standard.yml +18 -0
  6. data/.standard_todo.yml +5 -0
  7. data/.travis.yml +36 -0
  8. data/Appraisals +11 -0
  9. data/CHANGELOG.md +0 -0
  10. data/CODE_OF_CONDUCT.md +74 -0
  11. data/CONTRIBUTING.md +57 -0
  12. data/Gemfile +16 -0
  13. data/LICENSE.md +20 -0
  14. data/LICENSE.txt +21 -0
  15. data/README.md +478 -0
  16. data/Rakefile +7 -0
  17. data/bin/console +14 -0
  18. data/bin/setup +8 -0
  19. data/db/migrate/1_create_make_taggable_tags.rb +10 -0
  20. data/db/migrate/2_create_make_taggable_taggings.rb +12 -0
  21. data/db/migrate/3_add_index_to_tags.rb +5 -0
  22. data/db/migrate/4_add_index_to_taggings.rb +12 -0
  23. data/gemfiles/rails_5.gemfile +9 -0
  24. data/gemfiles/rails_6.gemfile +9 -0
  25. data/gemfiles/rails_master.gemfile +9 -0
  26. data/lib/make_taggable.rb +134 -0
  27. data/lib/make_taggable/default_parser.rb +75 -0
  28. data/lib/make_taggable/engine.rb +4 -0
  29. data/lib/make_taggable/generic_parser.rb +19 -0
  30. data/lib/make_taggable/tag.rb +131 -0
  31. data/lib/make_taggable/tag_list.rb +102 -0
  32. data/lib/make_taggable/taggable.rb +100 -0
  33. data/lib/make_taggable/taggable/cache.rb +90 -0
  34. data/lib/make_taggable/taggable/collection.rb +183 -0
  35. data/lib/make_taggable/taggable/core.rb +323 -0
  36. data/lib/make_taggable/taggable/ownership.rb +137 -0
  37. data/lib/make_taggable/taggable/related.rb +71 -0
  38. data/lib/make_taggable/taggable/tag_list_type.rb +4 -0
  39. data/lib/make_taggable/taggable/tagged_with_query.rb +16 -0
  40. data/lib/make_taggable/taggable/tagged_with_query/all_tags_query.rb +111 -0
  41. data/lib/make_taggable/taggable/tagged_with_query/any_tags_query.rb +68 -0
  42. data/lib/make_taggable/taggable/tagged_with_query/exclude_tags_query.rb +81 -0
  43. data/lib/make_taggable/taggable/tagged_with_query/query_base.rb +61 -0
  44. data/lib/make_taggable/tagger.rb +89 -0
  45. data/lib/make_taggable/tagging.rb +32 -0
  46. data/lib/make_taggable/tags_helper.rb +15 -0
  47. data/lib/make_taggable/utils.rb +34 -0
  48. data/lib/make_taggable/version.rb +4 -0
  49. data/lib/tasks/tags_collate_utf8.rake +17 -0
  50. data/make_taggable.gemspec +26 -0
  51. data/spec/dummy/README.md +24 -0
  52. data/spec/dummy/Rakefile +6 -0
  53. data/spec/dummy/app/assets/config/manifest.js +2 -0
  54. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  55. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  56. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  57. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  58. data/spec/dummy/app/jobs/application_job.rb +7 -0
  59. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  60. data/spec/dummy/app/models/altered_inheriting_taggable_model.rb +5 -0
  61. data/spec/dummy/app/models/application_record.rb +3 -0
  62. data/spec/dummy/app/models/cached_model.rb +3 -0
  63. data/spec/dummy/app/models/cached_model_with_array.rb +11 -0
  64. data/spec/dummy/app/models/columns_override_model.rb +5 -0
  65. data/spec/dummy/app/models/company.rb +15 -0
  66. data/spec/dummy/app/models/concerns/.keep +0 -0
  67. data/spec/dummy/app/models/inheriting_taggable_model.rb +4 -0
  68. data/spec/dummy/app/models/market.rb +2 -0
  69. data/spec/dummy/app/models/non_standard_id_taggable_model.rb +8 -0
  70. data/spec/dummy/app/models/ordered_taggable_model.rb +4 -0
  71. data/spec/dummy/app/models/other_cached_model.rb +3 -0
  72. data/spec/dummy/app/models/other_taggable_model.rb +4 -0
  73. data/spec/dummy/app/models/student.rb +4 -0
  74. data/spec/dummy/app/models/taggable_model.rb +14 -0
  75. data/spec/dummy/app/models/untaggable_model.rb +3 -0
  76. data/spec/dummy/app/models/user.rb +3 -0
  77. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  78. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  79. data/spec/dummy/bin/rails +4 -0
  80. data/spec/dummy/bin/rake +4 -0
  81. data/spec/dummy/bin/setup +33 -0
  82. data/spec/dummy/config.ru +5 -0
  83. data/spec/dummy/config/application.rb +19 -0
  84. data/spec/dummy/config/boot.rb +5 -0
  85. data/spec/dummy/config/cable.yml +10 -0
  86. data/spec/dummy/config/credentials.yml.enc +1 -0
  87. data/spec/dummy/config/database.yml +25 -0
  88. data/spec/dummy/config/environment.rb +5 -0
  89. data/spec/dummy/config/environments/development.rb +52 -0
  90. data/spec/dummy/config/environments/production.rb +105 -0
  91. data/spec/dummy/config/environments/test.rb +49 -0
  92. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  93. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  94. data/spec/dummy/config/initializers/cors.rb +16 -0
  95. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  96. data/spec/dummy/config/initializers/inflections.rb +16 -0
  97. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  98. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  99. data/spec/dummy/config/locales/en.yml +33 -0
  100. data/spec/dummy/config/master.key +1 -0
  101. data/spec/dummy/config/puma.rb +38 -0
  102. data/spec/dummy/config/routes.rb +3 -0
  103. data/spec/dummy/config/spring.rb +6 -0
  104. data/spec/dummy/config/storage.yml +34 -0
  105. data/spec/dummy/db/migrate/20201119220853_create_taggable_models.rb +8 -0
  106. data/spec/dummy/db/migrate/20201119221037_create_columns_override_models.rb +9 -0
  107. data/spec/dummy/db/migrate/20201119221121_create_non_standard_id_taggable_models.rb +8 -0
  108. data/spec/dummy/db/migrate/20201119221228_create_untaggable_models.rb +8 -0
  109. data/spec/dummy/db/migrate/20201119221247_create_cached_models.rb +9 -0
  110. data/spec/dummy/db/migrate/20201119221314_create_other_cached_models.rb +11 -0
  111. data/spec/dummy/db/migrate/20201119221343_create_companies.rb +7 -0
  112. data/spec/dummy/db/migrate/20201119221416_create_users.rb +7 -0
  113. data/spec/dummy/db/migrate/20201119221434_create_other_taggable_models.rb +8 -0
  114. data/spec/dummy/db/migrate/20201119221507_create_ordered_taggable_models.rb +8 -0
  115. data/spec/dummy/db/migrate/20201119221530_create_cache_methods_injected_models.rb +7 -0
  116. data/spec/dummy/db/migrate/20201119221629_create_other_cached_with_array_models.rb +11 -0
  117. data/spec/dummy/db/migrate/20201119221746_create_taggable_model_with_jsons.rb +9 -0
  118. data/spec/dummy/db/migrate/20201119222429_create_make_taggable_tags.make_taggable_engine.rb +11 -0
  119. data/spec/dummy/db/migrate/20201119222430_create_make_taggable_taggings.make_taggable_engine.rb +13 -0
  120. data/spec/dummy/db/migrate/20201119222431_add_index_to_tags.make_taggable_engine.rb +6 -0
  121. data/spec/dummy/db/migrate/20201119222432_add_index_to_taggings.make_taggable_engine.rb +13 -0
  122. data/spec/dummy/db/schema.rb +117 -0
  123. data/spec/dummy/db/seeds.rb +7 -0
  124. data/spec/dummy/lib/tasks/.keep +0 -0
  125. data/spec/dummy/log/.keep +0 -0
  126. data/spec/dummy/public/robots.txt +1 -0
  127. data/spec/dummy/storage/.keep +0 -0
  128. data/spec/dummy/test/channels/application_cable/connection_test.rb +11 -0
  129. data/spec/dummy/test/controllers/.keep +0 -0
  130. data/spec/dummy/test/fixtures/.keep +0 -0
  131. data/spec/dummy/test/fixtures/files/.keep +0 -0
  132. data/spec/dummy/test/integration/.keep +0 -0
  133. data/spec/dummy/test/mailers/.keep +0 -0
  134. data/spec/dummy/test/models/.keep +0 -0
  135. data/spec/dummy/test/test_helper.rb +13 -0
  136. data/spec/dummy/vendor/.keep +0 -0
  137. data/spec/make_taggable/acts_as_tagger_spec.rb +112 -0
  138. data/spec/make_taggable/caching_spec.rb +123 -0
  139. data/spec/make_taggable/default_parser_spec.rb +45 -0
  140. data/spec/make_taggable/dirty_spec.rb +140 -0
  141. data/spec/make_taggable/generic_parser_spec.rb +13 -0
  142. data/spec/make_taggable/make_taggable_spec.rb +260 -0
  143. data/spec/make_taggable/related_spec.rb +93 -0
  144. data/spec/make_taggable/single_table_inheritance_spec.rb +220 -0
  145. data/spec/make_taggable/tag_list_spec.rb +169 -0
  146. data/spec/make_taggable/tag_spec.rb +297 -0
  147. data/spec/make_taggable/taggable_spec.rb +804 -0
  148. data/spec/make_taggable/tagger_spec.rb +149 -0
  149. data/spec/make_taggable/tagging_spec.rb +115 -0
  150. data/spec/make_taggable/tags_helper_spec.rb +43 -0
  151. data/spec/make_taggable/utils_spec.rb +22 -0
  152. data/spec/make_taggable_spec.rb +5 -0
  153. data/spec/spec_helper.rb +18 -0
  154. data/spec/support/array.rb +9 -0
  155. data/spec/support/helpers.rb +31 -0
  156. metadata +391 -0
@@ -0,0 +1,8 @@
1
+ class CreateTaggableModels < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :taggable_models do |t|
4
+ t.column :name, :string
5
+ t.column :type, :string
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ class CreateColumnsOverrideModels < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :columns_override_models do |t|
4
+ t.column :name, :string
5
+ t.column :type, :string
6
+ t.column :ignored_column, :string
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ class CreateNonStandardIdTaggableModels < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :non_standard_id_taggable_models, primary_key: "an_id" do |t|
4
+ t.column :name, :string
5
+ t.column :type, :string
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ class CreateUntaggableModels < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :untaggable_models do |t|
4
+ t.column :taggable_model_id, :integer
5
+ t.column :name, :string
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ class CreateCachedModels < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :cached_models do |t|
4
+ t.column :name, :string
5
+ t.column :type, :string
6
+ t.column :cached_tag_list, :string
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ class CreateOtherCachedModels < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :other_cached_models do |t|
4
+ t.column :name, :string
5
+ t.column :type, :string
6
+ t.column :cached_language_list, :string
7
+ t.column :cached_status_list, :string
8
+ t.column :cached_glass_list, :string
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ class CreateCompanies < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :companies do |t|
4
+ t.column :name, :string
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ class CreateUsers < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :users do |t|
4
+ t.column :name, :string
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ class CreateOtherTaggableModels < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :other_taggable_models do |t|
4
+ t.column :name, :string
5
+ t.column :type, :string
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ class CreateOrderedTaggableModels < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :ordered_taggable_models do |t|
4
+ t.column :name, :string
5
+ t.column :type, :string
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ class CreateCacheMethodsInjectedModels < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :cache_methods_injected_models do |t|
4
+ t.column :cached_tag_list, :string
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ class CreateOtherCachedWithArrayModels < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :other_cached_with_array_models do |t|
4
+ t.column :name, :string
5
+ t.column :type, :string
6
+ t.column :cached_language_list, :string, array: true
7
+ t.column :cached_status_list, :string, array: true
8
+ t.column :cached_glass_list, :string, array: true
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ class CreateTaggableModelWithJsons < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :taggable_model_with_jsons do |t|
4
+ t.column :name, :string
5
+ t.column :type, :string
6
+ t.column :opts, :json
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ # This migration comes from make_taggable_engine (originally 1)
2
+ class CreateMakeTaggableTags < ActiveRecord::Migration[5.2]
3
+ def change
4
+ create_table MakeTaggable.tags_table do |t|
5
+ t.string :name
6
+ t.integer :taggings_count, default: 0
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ # This migration comes from make_taggable_engine (originally 2)
2
+ class CreateMakeTaggableTaggings < ActiveRecord::Migration[5.2]
3
+ def change
4
+ create_table MakeTaggable.taggings_table do |t|
5
+ t.references :tag, foreign_key: {to_table: MakeTaggable.tags_table}
6
+ t.references :taggable, polymorphic: true
7
+ t.references :tagger, polymorphic: true
8
+ t.string :context, limit: 128
9
+
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ # This migration comes from make_taggable_engine (originally 3)
2
+ class AddIndexToTags < ActiveRecord::Migration[5.2]
3
+ def change
4
+ add_index MakeTaggable.tags_table, :name, unique: true
5
+ end
6
+ end
@@ -0,0 +1,13 @@
1
+ # This migration comes from make_taggable_engine (originally 4)
2
+ class AddIndexToTaggings < ActiveRecord::Migration[5.2]
3
+ def change
4
+ add_index MakeTaggable.taggings_table, :taggable_id
5
+ add_index MakeTaggable.taggings_table, :tagger_id
6
+ add_index MakeTaggable.taggings_table, :taggable_type
7
+ add_index MakeTaggable.taggings_table, :context
8
+ add_index MakeTaggable.taggings_table, [:tagger_id, :tagger_type]
9
+ add_index MakeTaggable.taggings_table, [:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type], unique: true, name: "taggings_idx"
10
+ add_index MakeTaggable.taggings_table, [:taggable_id, :taggable_type, :context], name: "taggings_taggable_context_idx"
11
+ add_index MakeTaggable.taggings_table, [:taggable_id, :taggable_type, :tagger_id, :context], name: "taggings_idy"
12
+ end
13
+ end
@@ -0,0 +1,117 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # This file is the source Rails uses to define your schema when running `rails
6
+ # db:schema:load`. When creating a new database, `rails db:schema:load` tends to
7
+ # be faster and is potentially less error prone than running all of your
8
+ # migrations from scratch. Old migrations may fail to apply correctly if those
9
+ # migrations use external dependencies or application code.
10
+ #
11
+ # It's strongly recommended that you check this file into your version control system.
12
+
13
+ ActiveRecord::Schema.define(version: 2020_11_19_222432) do
14
+
15
+ create_table "cache_methods_injected_models", force: :cascade do |t|
16
+ t.string "cached_tag_list"
17
+ end
18
+
19
+ create_table "cached_models", force: :cascade do |t|
20
+ t.string "name"
21
+ t.string "type"
22
+ t.string "cached_tag_list"
23
+ end
24
+
25
+ create_table "columns_override_models", force: :cascade do |t|
26
+ t.string "name"
27
+ t.string "type"
28
+ t.string "ignored_column"
29
+ end
30
+
31
+ create_table "companies", force: :cascade do |t|
32
+ t.string "name"
33
+ end
34
+
35
+ create_table "non_standard_id_taggable_models", primary_key: "an_id", force: :cascade do |t|
36
+ t.string "name"
37
+ t.string "type"
38
+ end
39
+
40
+ create_table "ordered_taggable_models", force: :cascade do |t|
41
+ t.string "name"
42
+ t.string "type"
43
+ end
44
+
45
+ create_table "other_cached_models", force: :cascade do |t|
46
+ t.string "name"
47
+ t.string "type"
48
+ t.string "cached_language_list"
49
+ t.string "cached_status_list"
50
+ t.string "cached_glass_list"
51
+ end
52
+
53
+ create_table "other_cached_with_array_models", force: :cascade do |t|
54
+ t.string "name"
55
+ t.string "type"
56
+ t.string "cached_language_list"
57
+ t.string "cached_status_list"
58
+ t.string "cached_glass_list"
59
+ end
60
+
61
+ create_table "other_taggable_models", force: :cascade do |t|
62
+ t.string "name"
63
+ t.string "type"
64
+ end
65
+
66
+ create_table "taggable_model_with_jsons", force: :cascade do |t|
67
+ t.string "name"
68
+ t.string "type"
69
+ t.json "opts"
70
+ end
71
+
72
+ create_table "taggable_models", force: :cascade do |t|
73
+ t.string "name"
74
+ t.string "type"
75
+ end
76
+
77
+ create_table "taggings", force: :cascade do |t|
78
+ t.integer "tag_id"
79
+ t.string "taggable_type"
80
+ t.integer "taggable_id"
81
+ t.string "tagger_type"
82
+ t.integer "tagger_id"
83
+ t.string "context", limit: 128
84
+ t.datetime "created_at", null: false
85
+ t.datetime "updated_at", null: false
86
+ t.index ["context"], name: "index_taggings_on_context"
87
+ t.index ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true
88
+ t.index ["tag_id"], name: "index_taggings_on_tag_id"
89
+ t.index ["taggable_id", "taggable_type", "context"], name: "taggings_taggable_context_idx"
90
+ t.index ["taggable_id", "taggable_type", "tagger_id", "context"], name: "taggings_idy"
91
+ t.index ["taggable_id"], name: "index_taggings_on_taggable_id"
92
+ t.index ["taggable_type", "taggable_id"], name: "index_taggings_on_taggable_type_and_taggable_id"
93
+ t.index ["taggable_type"], name: "index_taggings_on_taggable_type"
94
+ t.index ["tagger_id", "tagger_type"], name: "index_taggings_on_tagger_id_and_tagger_type"
95
+ t.index ["tagger_id"], name: "index_taggings_on_tagger_id"
96
+ t.index ["tagger_type", "tagger_id"], name: "index_taggings_on_tagger_type_and_tagger_id"
97
+ end
98
+
99
+ create_table "tags", force: :cascade do |t|
100
+ t.string "name"
101
+ t.integer "taggings_count", default: 0
102
+ t.datetime "created_at", null: false
103
+ t.datetime "updated_at", null: false
104
+ t.index ["name"], name: "index_tags_on_name", unique: true
105
+ end
106
+
107
+ create_table "untaggable_models", force: :cascade do |t|
108
+ t.integer "taggable_model_id"
109
+ t.string "name"
110
+ end
111
+
112
+ create_table "users", force: :cascade do |t|
113
+ t.string "name"
114
+ end
115
+
116
+ add_foreign_key "taggings", "tags"
117
+ end
@@ -0,0 +1,7 @@
1
+ # This file should contain all the record creation needed to seed the database with its default values.
2
+ # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
3
+ #
4
+ # Examples:
5
+ #
6
+ # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
7
+ # Character.create(name: 'Luke', movie: movies.first)
File without changes
File without changes
@@ -0,0 +1 @@
1
+ # See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
File without changes
@@ -0,0 +1,11 @@
1
+ require "test_helper"
2
+
3
+ class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase
4
+ # test "connects with cookies" do
5
+ # cookies.signed[:user_id] = 42
6
+ #
7
+ # connect
8
+ #
9
+ # assert_equal connection.user_id, "42"
10
+ # end
11
+ end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,13 @@
1
+ ENV['RAILS_ENV'] ||= 'test'
2
+ require_relative '../config/environment'
3
+ require 'rails/test_help'
4
+
5
+ class ActiveSupport::TestCase
6
+ # Run tests in parallel with specified workers
7
+ parallelize(workers: :number_of_processors)
8
+
9
+ # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
10
+ fixtures :all
11
+
12
+ # Add more helper methods to be used by all tests here...
13
+ end
File without changes
@@ -0,0 +1,112 @@
1
+ require "spec_helper"
2
+
3
+ describe "acts_as_tagger" do
4
+ describe "Tagger Method Generation" do
5
+ before(:each) do
6
+ @tagger = User.new
7
+ end
8
+
9
+ it "should add #is_tagger? query method to the class-side" do
10
+ expect(User).to respond_to(:is_tagger?)
11
+ end
12
+
13
+ it "should return true from the class-side #is_tagger?" do
14
+ expect(User.is_tagger?).to be_truthy
15
+ end
16
+
17
+ it "should return false from the base #is_tagger?" do
18
+ expect(ActiveRecord::Base.is_tagger?).to be_falsy
19
+ end
20
+
21
+ it "should add #is_tagger? query method to the singleton" do
22
+ expect(@tagger).to respond_to(:is_tagger?)
23
+ end
24
+
25
+ it "should add #tag method on the instance-side" do
26
+ expect(@tagger).to respond_to(:tag)
27
+ end
28
+
29
+ it "should generate an association for #owned_taggings and #owned_tags" do
30
+ expect(@tagger).to respond_to(:owned_taggings, :owned_tags)
31
+ end
32
+ end
33
+
34
+ describe "#tag" do
35
+ context "when called with a non-existent tag context" do
36
+ before(:each) do
37
+ @tagger = User.new
38
+ @taggable = TaggableModel.new(name: "Richard Prior")
39
+ end
40
+
41
+ it "should by default not throw an exception " do
42
+ expect(@taggable.tag_list_on(:foo)).to be_empty
43
+ expect(-> {
44
+ @tagger.tag(@taggable, with: "this, and, that", on: :foo)
45
+ }).to_not raise_error
46
+ end
47
+
48
+ it "should by default create the tag context on-the-fly" do
49
+ expect(@taggable.tag_list_on(:here_ond_now)).to be_empty
50
+ @tagger.tag(@taggable, with: "that", on: :here_ond_now)
51
+ expect(@taggable.tag_list_on(:here_ond_now)).to_not include("that")
52
+ expect(@taggable.all_tags_list_on(:here_ond_now)).to include("that")
53
+ end
54
+
55
+ it "should show all the tag list when both public and owned tags exist" do
56
+ @taggable.tag_list = "ruby, python"
57
+ @tagger.tag(@taggable, with: "java, lisp", on: :tags)
58
+ expect(@taggable.all_tags_on(:tags).map(&:name).sort).to eq(%w[ruby python java lisp].sort)
59
+ end
60
+
61
+ it "should not add owned tags to the common list" do
62
+ @taggable.tag_list = "ruby, python"
63
+ @tagger.tag(@taggable, with: "java, lisp", on: :tags)
64
+ expect(@taggable.tag_list).to eq(%w[ruby python])
65
+ @tagger.tag(@taggable, with: "", on: :tags)
66
+ expect(@taggable.tag_list).to eq(%w[ruby python])
67
+ end
68
+
69
+ it "should throw an exception when the default is over-ridden" do
70
+ expect(@taggable.tag_list_on(:foo_boo)).to be_empty
71
+ expect(-> {
72
+ @tagger.tag(@taggable, with: "this, and, that", on: :foo_boo, force: false)
73
+ }).to raise_error(RuntimeError)
74
+ end
75
+
76
+ it "should not create the tag context on-the-fly when the default is over-ridden" do
77
+ expect(@taggable.tag_list_on(:foo_boo)).to be_empty
78
+ begin
79
+ @tagger.tag(@taggable, with: "this, and, that", on: :foo_boo, force: false)
80
+ rescue
81
+ expect(@taggable.tag_list_on(:foo_boo)).to be_empty
82
+ end
83
+ end
84
+ end
85
+
86
+ describe "when called by multiple tagger's" do
87
+ before(:each) do
88
+ @user_x = User.create(name: "User X")
89
+ @user_y = User.create(name: "User Y")
90
+ @taggable = TaggableModel.create(name: "make_taggable", tag_list: "plugin")
91
+
92
+ @user_x.tag(@taggable, with: "ruby, rails", on: :tags)
93
+ @user_y.tag(@taggable, with: "ruby, plugin", on: :tags)
94
+
95
+ @user_y.tag(@taggable, with: "", on: :tags)
96
+ @user_y.tag(@taggable, with: "", on: :tags)
97
+ end
98
+
99
+ it "should delete owned tags" do
100
+ expect(@user_y.owned_tags).to be_empty
101
+ end
102
+
103
+ it "should not delete other taggers tags" do
104
+ expect(@user_x.owned_tags.count).to eq(2)
105
+ end
106
+
107
+ it "should not delete original tags" do
108
+ expect(@taggable.all_tags_list_on(:tags)).to include("plugin")
109
+ end
110
+ end
111
+ end
112
+ end