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,149 @@
1
+ require "spec_helper"
2
+
3
+ describe "Tagger" do
4
+ before(:each) do
5
+ @user = User.create
6
+ @taggable = TaggableModel.create(name: "Bob Jones")
7
+ end
8
+
9
+ it "should have taggings" do
10
+ @user.tag(@taggable, with: "ruby,scheme", on: :tags)
11
+ expect(@user.owned_taggings.size).to eq(2)
12
+ end
13
+
14
+ it "should have tags" do
15
+ @user.tag(@taggable, with: "ruby,scheme", on: :tags)
16
+ expect(@user.owned_tags.size).to eq(2)
17
+ end
18
+
19
+ it "should scope objects returned by tagged_with by owners" do
20
+ @taggable2 = TaggableModel.create(name: "Jim Jones")
21
+ @taggable3 = TaggableModel.create(name: "Jane Doe")
22
+
23
+ @user2 = User.new
24
+ @user.tag(@taggable, with: "ruby, scheme", on: :tags)
25
+ @user2.tag(@taggable2, with: "ruby, scheme", on: :tags)
26
+ @user2.tag(@taggable3, with: "ruby, scheme", on: :tags)
27
+
28
+ expect(TaggableModel.tagged_with(%w[ruby scheme], owned_by: @user).count).to eq(1)
29
+ expect(TaggableModel.tagged_with(%w[ruby scheme], owned_by: @user2).count).to eq(2)
30
+ end
31
+
32
+ it "only returns objects tagged by owned_by when any is true" do
33
+ @user2 = User.new
34
+ @taggable2 = TaggableModel.create(name: "Jim Jones")
35
+ @taggable3 = TaggableModel.create(name: "Jane Doe")
36
+
37
+ @user.tag(@taggable, with: "ruby", on: :tags)
38
+ @user.tag(@taggable2, with: "java", on: :tags)
39
+ @user2.tag(@taggable3, with: "ruby", on: :tags)
40
+
41
+ tags = TaggableModel.tagged_with(%w[ruby java], owned_by: @user, any: true)
42
+ expect(tags).to include(@taggable, @taggable2)
43
+ expect(tags.size).to eq(2)
44
+ end
45
+
46
+ it "only returns objects tagged by owned_by when exclude is true" do
47
+ @user2 = User.new
48
+ @taggable2 = TaggableModel.create(name: "Jim Jones")
49
+ @taggable3 = TaggableModel.create(name: "Jane Doe")
50
+
51
+ @user.tag(@taggable, with: "ruby", on: :tags)
52
+ @user.tag(@taggable2, with: "java", on: :tags)
53
+ @user2.tag(@taggable3, with: "java", on: :tags)
54
+
55
+ tags = TaggableModel.tagged_with(%w[ruby], owned_by: @user, exclude: true)
56
+ expect(tags).to eq([@taggable2])
57
+ end
58
+
59
+ it "should not overlap tags from different taggers" do
60
+ @user2 = User.new
61
+ expect(-> {
62
+ @user.tag(@taggable, with: "ruby, scheme", on: :tags)
63
+ @user2.tag(@taggable, with: "java, python, lisp, ruby", on: :tags)
64
+ }).to change(MakeTaggable::Tagging, :count).by(6)
65
+
66
+ [@user, @user2, @taggable].each(&:reload)
67
+
68
+ expect(@user.owned_tags.map(&:name).sort).to eq(%w[ruby scheme].sort)
69
+ expect(@user2.owned_tags.map(&:name).sort).to eq(%w[java python lisp ruby].sort)
70
+
71
+ expect(@taggable.tags_from(@user).sort).to eq(%w[ruby scheme].sort)
72
+ expect(@taggable.tags_from(@user2).sort).to eq(%w[java lisp python ruby].sort)
73
+
74
+ expect(@taggable.all_tags_list.sort).to eq(%w[ruby scheme java python lisp].sort)
75
+ expect(@taggable.all_tags_on(:tags).size).to eq(5)
76
+ end
77
+
78
+ it "should not lose tags from different taggers" do
79
+ @user2 = User.create
80
+ @user2.tag(@taggable, with: "java, python, lisp, ruby", on: :tags)
81
+ @user.tag(@taggable, with: "ruby, scheme", on: :tags)
82
+
83
+ expect(-> {
84
+ @user2.tag(@taggable, with: "java, python, lisp", on: :tags)
85
+ }).to change(MakeTaggable::Tagging, :count).by(-1)
86
+
87
+ [@user, @user2, @taggable].each(&:reload)
88
+
89
+ expect(@taggable.tags_from(@user).sort).to eq(%w[ruby scheme].sort)
90
+ expect(@taggable.tags_from(@user2).sort).to eq(%w[java python lisp].sort)
91
+
92
+ expect(@taggable.all_tags_list.sort).to eq(%w[ruby scheme java python lisp].sort)
93
+ expect(@taggable.all_tags_on(:tags).length).to eq(5)
94
+ end
95
+
96
+ it "should not lose tags" do
97
+ @user2 = User.create
98
+
99
+ @user.tag(@taggable, with: "awesome", on: :tags)
100
+ @user2.tag(@taggable, with: "awesome, epic", on: :tags)
101
+
102
+ expect(-> {
103
+ @user2.tag(@taggable, with: "epic", on: :tags)
104
+ }).to change(MakeTaggable::Tagging, :count).by(-1)
105
+
106
+ @taggable.reload
107
+ expect(@taggable.all_tags_list).to include("awesome")
108
+ expect(@taggable.all_tags_list).to include("epic")
109
+ end
110
+
111
+ it "should not lose tags" do
112
+ @taggable.update(tag_list: "ruby")
113
+ @user.tag(@taggable, with: "ruby, scheme", on: :tags)
114
+
115
+ [@taggable, @user].each(&:reload)
116
+ expect(@taggable.tag_list).to eq(%w[ruby])
117
+ expect(@taggable.all_tags_list.sort).to eq(%w[ruby scheme].sort)
118
+
119
+ expect(-> {
120
+ @taggable.update(tag_list: "")
121
+ }).to change(MakeTaggable::Tagging, :count).by(-1)
122
+
123
+ expect(@taggable.tag_list).to be_empty
124
+ expect(@taggable.all_tags_list.sort).to eq(%w[ruby scheme].sort)
125
+ end
126
+
127
+ it "is tagger" do
128
+ expect(@user.is_tagger?).to be_truthy
129
+ end
130
+
131
+ it "should skip save if skip_save is passed as option" do
132
+ expect(-> {
133
+ @user.tag(@taggable, with: "epic", on: :tags, skip_save: true)
134
+ }).to_not change(MakeTaggable::Tagging, :count)
135
+ end
136
+
137
+ it "should change tags order in ordered taggable" do
138
+ @ordered_taggable = OrderedTaggableModel.create name: "hey!"
139
+
140
+ @user.tag @ordered_taggable, with: "tag, tag1", on: :tags
141
+ expect(@ordered_taggable.reload.tags_from(@user)).to eq(["tag", "tag1"])
142
+
143
+ @user.tag @ordered_taggable, with: "tag2, tag1", on: :tags
144
+ expect(@ordered_taggable.reload.tags_from(@user)).to eq(["tag2", "tag1"])
145
+
146
+ @user.tag @ordered_taggable, with: "tag1, tag2", on: :tags
147
+ expect(@ordered_taggable.reload.tags_from(@user)).to eq(["tag1", "tag2"])
148
+ end
149
+ end
@@ -0,0 +1,115 @@
1
+ require "spec_helper"
2
+
3
+ describe MakeTaggable::Tagging do
4
+ before(:each) do
5
+ @tagging = MakeTaggable::Tagging.new
6
+ end
7
+
8
+ it "should not be valid with a invalid tag" do
9
+ @tagging.taggable = TaggableModel.create(name: "Bob Jones")
10
+ @tagging.tag = MakeTaggable::Tag.new(name: "")
11
+ @tagging.context = "tags"
12
+
13
+ expect(@tagging).to_not be_valid
14
+
15
+ expect(@tagging.errors[:tag_id]).to eq(["can't be blank"])
16
+ end
17
+
18
+ it "should not create duplicate taggings" do
19
+ @taggable = TaggableModel.create(name: "Bob Jones")
20
+ @tag = MakeTaggable::Tag.create(name: "awesome")
21
+
22
+ expect(-> {
23
+ 2.times { MakeTaggable::Tagging.create(taggable: @taggable, tag: @tag, context: "tags") }
24
+ }).to change(MakeTaggable::Tagging, :count).by(1)
25
+ end
26
+
27
+ it "should not delete tags of other records" do
28
+ 6.times { TaggableModel.create(name: "Bob Jones", tag_list: "very, serious, bug") }
29
+ expect(MakeTaggable::Tag.count).to eq(3)
30
+ taggable = TaggableModel.first
31
+ taggable.tag_list = "bug"
32
+ taggable.save
33
+
34
+ expect(taggable.tag_list).to eq(["bug"])
35
+
36
+ another_taggable = TaggableModel.where("id != ?", taggable.id).sample
37
+ expect(another_taggable.tag_list.sort).to eq(%w[very serious bug].sort)
38
+ end
39
+
40
+ it "should destroy unused tags after tagging destroyed" do
41
+ previous_setting = MakeTaggable.remove_unused_tags
42
+ MakeTaggable.remove_unused_tags = true
43
+ MakeTaggable::Tag.destroy_all
44
+ @taggable = TaggableModel.create(name: "Bob Jones")
45
+ @taggable.update_attribute :tag_list, "aaa,bbb,ccc"
46
+ @taggable.update_attribute :tag_list, ""
47
+ expect(MakeTaggable::Tag.count).to eql(0)
48
+ MakeTaggable.remove_unused_tags = previous_setting
49
+ end
50
+
51
+ describe "context scopes" do
52
+ before do
53
+ @tagging_2 = MakeTaggable::Tagging.new
54
+ @tagging_3 = MakeTaggable::Tagging.new
55
+
56
+ @tagger = User.new
57
+ @tagger_2 = User.new
58
+
59
+ @tagging.taggable = TaggableModel.create(name: "Black holes")
60
+ @tagging.tag = MakeTaggable::Tag.create(name: "Physics")
61
+ @tagging.tagger = @tagger
62
+ @tagging.context = "Science"
63
+ @tagging.save
64
+
65
+ @tagging_2.taggable = TaggableModel.create(name: "Satellites")
66
+ @tagging_2.tag = MakeTaggable::Tag.create(name: "Technology")
67
+ @tagging_2.tagger = @tagger_2
68
+ @tagging_2.context = "Science"
69
+ @tagging_2.save
70
+
71
+ @tagging_3.taggable = TaggableModel.create(name: "Satellites")
72
+ @tagging_3.tag = MakeTaggable::Tag.create(name: "Engineering")
73
+ @tagging_3.tagger = @tagger_2
74
+ @tagging_3.context = "Astronomy"
75
+ @tagging_3.save
76
+ end
77
+
78
+ describe ".owned_by" do
79
+ it "should belong to a specific user" do
80
+ expect(MakeTaggable::Tagging.owned_by(@tagger).first).to eq(@tagging)
81
+ end
82
+ end
83
+
84
+ describe ".by_context" do
85
+ it "should be found by context" do
86
+ expect(MakeTaggable::Tagging.by_context("Science").length).to eq(2)
87
+ end
88
+ end
89
+
90
+ describe ".by_contexts" do
91
+ it "should find taggings by contexts" do
92
+ expect(MakeTaggable::Tagging.by_contexts(["Science", "Astronomy"]).first).to eq(@tagging)
93
+ expect(MakeTaggable::Tagging.by_contexts(["Science", "Astronomy"]).second).to eq(@tagging_2)
94
+ expect(MakeTaggable::Tagging.by_contexts(["Science", "Astronomy"]).third).to eq(@tagging_3)
95
+ expect(MakeTaggable::Tagging.by_contexts(["Science", "Astronomy"]).length).to eq(3)
96
+ end
97
+ end
98
+
99
+ describe ".not_owned" do
100
+ before do
101
+ @tagging_4 = MakeTaggable::Tagging.new
102
+ @tagging_4.taggable = TaggableModel.create(name: "Gravity")
103
+ @tagging_4.tag = MakeTaggable::Tag.create(name: "Space")
104
+ @tagging_4.context = "Science"
105
+ @tagging_4.save
106
+ end
107
+
108
+ it "should found the taggings that do not have owner" do
109
+ expect(MakeTaggable::Tagging.all.length).to eq(4)
110
+ expect(MakeTaggable::Tagging.not_owned.length).to eq(1)
111
+ expect(MakeTaggable::Tagging.not_owned.first).to eq(@tagging_4)
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,43 @@
1
+ require "spec_helper"
2
+
3
+ describe MakeTaggable::TagsHelper do
4
+ before(:each) do
5
+ @bob = TaggableModel.create(name: "Bob Jones", language_list: "ruby, php")
6
+ @tom = TaggableModel.create(name: "Tom Marley", language_list: "ruby, java")
7
+ @eve = TaggableModel.create(name: "Eve Nodd", language_list: "ruby, c++")
8
+
9
+ @helper =
10
+ class Helper
11
+ include MakeTaggable::TagsHelper
12
+ end.new
13
+ end
14
+
15
+ it "should yield the proper css classes" do
16
+ tags = {}
17
+
18
+ @helper.tag_cloud(TaggableModel.tag_counts_on(:languages), %w[sucky awesome]) do |tag, css_class|
19
+ tags[tag.name] = css_class
20
+ end
21
+
22
+ expect(tags["ruby"]).to eq("awesome")
23
+ expect(tags["java"]).to eq("sucky")
24
+ expect(tags["c++"]).to eq("sucky")
25
+ expect(tags["php"]).to eq("sucky")
26
+ end
27
+
28
+ it "should handle tags with zero counts (build for empty)" do
29
+ MakeTaggable::Tag.create(name: "php")
30
+ MakeTaggable::Tag.create(name: "java")
31
+ MakeTaggable::Tag.create(name: "c++")
32
+
33
+ tags = {}
34
+
35
+ @helper.tag_cloud(MakeTaggable::Tag.all, %w[sucky awesome]) do |tag, css_class|
36
+ tags[tag.name] = css_class
37
+ end
38
+
39
+ expect(tags["java"]).to eq("sucky")
40
+ expect(tags["c++"]).to eq("sucky")
41
+ expect(tags["php"]).to eq("sucky")
42
+ end
43
+ end
@@ -0,0 +1,22 @@
1
+ require "spec_helper"
2
+
3
+ describe MakeTaggable::Utils do
4
+ describe "#like_operator" do
5
+ it "should return 'ILIKE' when the adapter is PostgreSQL" do
6
+ allow(MakeTaggable::Utils.connection).to receive(:adapter_name) { "PostgreSQL" }
7
+ expect(MakeTaggable::Utils.like_operator).to eq("ILIKE")
8
+ end
9
+
10
+ it "should return 'LIKE' when the adapter is not PostgreSQL" do
11
+ allow(MakeTaggable::Utils.connection).to receive(:adapter_name) { "MySQL" }
12
+ expect(MakeTaggable::Utils.like_operator).to eq("LIKE")
13
+ end
14
+ end
15
+
16
+ describe "#sha_prefix" do
17
+ it "should return a consistent prefix for a given word" do
18
+ expect(MakeTaggable::Utils.sha_prefix("kittens")).to eq(MakeTaggable::Utils.sha_prefix("kittens"))
19
+ expect(MakeTaggable::Utils.sha_prefix("puppies")).not_to eq(MakeTaggable::Utils.sha_prefix("kittens"))
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ RSpec.describe MakeTaggable do
2
+ it "has a version number" do
3
+ expect(MakeTaggable::VERSION).not_to be nil
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require_relative "../spec/dummy/config/environment"
5
+ ActiveRecord::Migrator.migrations_paths = [File.expand_path("../spec/dummy/db/migrate", __dir__)]
6
+ ActiveRecord::Migration.maintain_test_schema!
7
+
8
+ require "rspec/rails"
9
+ require "rails"
10
+
11
+ Dir["./spec/support/**/*.rb"].sort.each { |f| require f }
12
+
13
+ RSpec.configure do |config|
14
+ config.fixture_path = "spec/fixtures"
15
+ config.global_fixtures = :all
16
+ config.use_transactional_fixtures = true
17
+ config.infer_base_class_for_anonymous_controllers = true
18
+ end
@@ -0,0 +1,9 @@
1
+ unless [].respond_to?(:freq)
2
+ class Array
3
+ def freq
4
+ k = Hash.new(0)
5
+ each { |e| k[e] += 1 }
6
+ k
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,31 @@
1
+ def using_sqlite?
2
+ MakeTaggable::Utils.connection && MakeTaggable::Utils.connection.adapter_name == "SQLite"
3
+ end
4
+
5
+ def supports_concurrency?
6
+ !using_sqlite?
7
+ end
8
+
9
+ def using_postgresql?
10
+ MakeTaggable::Utils.using_postgresql?
11
+ end
12
+
13
+ def postgresql_version
14
+ if using_postgresql?
15
+ MakeTaggable::Utils.connection.execute("SHOW SERVER_VERSION").first["server_version"].to_f
16
+ else
17
+ 0.0
18
+ end
19
+ end
20
+
21
+ def postgresql_support_json?
22
+ postgresql_version >= 9.2
23
+ end
24
+
25
+ def using_mysql?
26
+ MakeTaggable::Utils.using_mysql?
27
+ end
28
+
29
+ def using_case_insensitive_collation?
30
+ using_mysql? && MakeTaggable::Utils.connection.collation =~ /_ci\Z/
31
+ end
metadata ADDED
@@ -0,0 +1,391 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: make_taggable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.3
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Kennedy
8
+ - Michael Bleigh
9
+ - Joost Baaij
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2020-11-20 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '5.2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '5.2'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rspec
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '3.0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '3.0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rspec-rails
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: sqlite3
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: standard
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ - !ruby/object:Gem::Dependency
86
+ name: appraisal
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ description: MakeTaggable is a fork of acts-as-taggable-on v6.5 with code updates
100
+ and a new set of migrations.
101
+ email:
102
+ - m.kennedy@me.com
103
+ - michael@intridea.com
104
+ - joost@spacebabies.nl
105
+ executables: []
106
+ extensions: []
107
+ extra_rdoc_files: []
108
+ files:
109
+ - ".github/workflows/ci.yml"
110
+ - ".gitignore"
111
+ - ".rspec"
112
+ - ".standard.yml"
113
+ - ".standard_todo.yml"
114
+ - ".travis.yml"
115
+ - Appraisals
116
+ - CHANGELOG.md
117
+ - CODE_OF_CONDUCT.md
118
+ - CONTRIBUTING.md
119
+ - Gemfile
120
+ - LICENSE.md
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - bin/console
125
+ - bin/setup
126
+ - db/migrate/1_create_make_taggable_tags.rb
127
+ - db/migrate/2_create_make_taggable_taggings.rb
128
+ - db/migrate/3_add_index_to_tags.rb
129
+ - db/migrate/4_add_index_to_taggings.rb
130
+ - gemfiles/rails_5.gemfile
131
+ - gemfiles/rails_6.gemfile
132
+ - gemfiles/rails_master.gemfile
133
+ - lib/make_taggable.rb
134
+ - lib/make_taggable/default_parser.rb
135
+ - lib/make_taggable/engine.rb
136
+ - lib/make_taggable/generic_parser.rb
137
+ - lib/make_taggable/tag.rb
138
+ - lib/make_taggable/tag_list.rb
139
+ - lib/make_taggable/taggable.rb
140
+ - lib/make_taggable/taggable/cache.rb
141
+ - lib/make_taggable/taggable/collection.rb
142
+ - lib/make_taggable/taggable/core.rb
143
+ - lib/make_taggable/taggable/ownership.rb
144
+ - lib/make_taggable/taggable/related.rb
145
+ - lib/make_taggable/taggable/tag_list_type.rb
146
+ - lib/make_taggable/taggable/tagged_with_query.rb
147
+ - lib/make_taggable/taggable/tagged_with_query/all_tags_query.rb
148
+ - lib/make_taggable/taggable/tagged_with_query/any_tags_query.rb
149
+ - lib/make_taggable/taggable/tagged_with_query/exclude_tags_query.rb
150
+ - lib/make_taggable/taggable/tagged_with_query/query_base.rb
151
+ - lib/make_taggable/tagger.rb
152
+ - lib/make_taggable/tagging.rb
153
+ - lib/make_taggable/tags_helper.rb
154
+ - lib/make_taggable/utils.rb
155
+ - lib/make_taggable/version.rb
156
+ - lib/tasks/tags_collate_utf8.rake
157
+ - make_taggable.gemspec
158
+ - spec/dummy/README.md
159
+ - spec/dummy/Rakefile
160
+ - spec/dummy/app/assets/config/manifest.js
161
+ - spec/dummy/app/channels/application_cable/channel.rb
162
+ - spec/dummy/app/channels/application_cable/connection.rb
163
+ - spec/dummy/app/controllers/application_controller.rb
164
+ - spec/dummy/app/controllers/concerns/.keep
165
+ - spec/dummy/app/jobs/application_job.rb
166
+ - spec/dummy/app/mailers/application_mailer.rb
167
+ - spec/dummy/app/models/altered_inheriting_taggable_model.rb
168
+ - spec/dummy/app/models/application_record.rb
169
+ - spec/dummy/app/models/cached_model.rb
170
+ - spec/dummy/app/models/cached_model_with_array.rb
171
+ - spec/dummy/app/models/columns_override_model.rb
172
+ - spec/dummy/app/models/company.rb
173
+ - spec/dummy/app/models/concerns/.keep
174
+ - spec/dummy/app/models/inheriting_taggable_model.rb
175
+ - spec/dummy/app/models/market.rb
176
+ - spec/dummy/app/models/non_standard_id_taggable_model.rb
177
+ - spec/dummy/app/models/ordered_taggable_model.rb
178
+ - spec/dummy/app/models/other_cached_model.rb
179
+ - spec/dummy/app/models/other_taggable_model.rb
180
+ - spec/dummy/app/models/student.rb
181
+ - spec/dummy/app/models/taggable_model.rb
182
+ - spec/dummy/app/models/untaggable_model.rb
183
+ - spec/dummy/app/models/user.rb
184
+ - spec/dummy/app/views/layouts/mailer.html.erb
185
+ - spec/dummy/app/views/layouts/mailer.text.erb
186
+ - spec/dummy/bin/rails
187
+ - spec/dummy/bin/rake
188
+ - spec/dummy/bin/setup
189
+ - spec/dummy/config.ru
190
+ - spec/dummy/config/application.rb
191
+ - spec/dummy/config/boot.rb
192
+ - spec/dummy/config/cable.yml
193
+ - spec/dummy/config/credentials.yml.enc
194
+ - spec/dummy/config/database.yml
195
+ - spec/dummy/config/environment.rb
196
+ - spec/dummy/config/environments/development.rb
197
+ - spec/dummy/config/environments/production.rb
198
+ - spec/dummy/config/environments/test.rb
199
+ - spec/dummy/config/initializers/application_controller_renderer.rb
200
+ - spec/dummy/config/initializers/backtrace_silencers.rb
201
+ - spec/dummy/config/initializers/cors.rb
202
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
203
+ - spec/dummy/config/initializers/inflections.rb
204
+ - spec/dummy/config/initializers/mime_types.rb
205
+ - spec/dummy/config/initializers/wrap_parameters.rb
206
+ - spec/dummy/config/locales/en.yml
207
+ - spec/dummy/config/master.key
208
+ - spec/dummy/config/puma.rb
209
+ - spec/dummy/config/routes.rb
210
+ - spec/dummy/config/spring.rb
211
+ - spec/dummy/config/storage.yml
212
+ - spec/dummy/db/migrate/20201119220853_create_taggable_models.rb
213
+ - spec/dummy/db/migrate/20201119221037_create_columns_override_models.rb
214
+ - spec/dummy/db/migrate/20201119221121_create_non_standard_id_taggable_models.rb
215
+ - spec/dummy/db/migrate/20201119221228_create_untaggable_models.rb
216
+ - spec/dummy/db/migrate/20201119221247_create_cached_models.rb
217
+ - spec/dummy/db/migrate/20201119221314_create_other_cached_models.rb
218
+ - spec/dummy/db/migrate/20201119221343_create_companies.rb
219
+ - spec/dummy/db/migrate/20201119221416_create_users.rb
220
+ - spec/dummy/db/migrate/20201119221434_create_other_taggable_models.rb
221
+ - spec/dummy/db/migrate/20201119221507_create_ordered_taggable_models.rb
222
+ - spec/dummy/db/migrate/20201119221530_create_cache_methods_injected_models.rb
223
+ - spec/dummy/db/migrate/20201119221629_create_other_cached_with_array_models.rb
224
+ - spec/dummy/db/migrate/20201119221746_create_taggable_model_with_jsons.rb
225
+ - spec/dummy/db/migrate/20201119222429_create_make_taggable_tags.make_taggable_engine.rb
226
+ - spec/dummy/db/migrate/20201119222430_create_make_taggable_taggings.make_taggable_engine.rb
227
+ - spec/dummy/db/migrate/20201119222431_add_index_to_tags.make_taggable_engine.rb
228
+ - spec/dummy/db/migrate/20201119222432_add_index_to_taggings.make_taggable_engine.rb
229
+ - spec/dummy/db/schema.rb
230
+ - spec/dummy/db/seeds.rb
231
+ - spec/dummy/lib/tasks/.keep
232
+ - spec/dummy/log/.keep
233
+ - spec/dummy/public/robots.txt
234
+ - spec/dummy/storage/.keep
235
+ - spec/dummy/test/channels/application_cable/connection_test.rb
236
+ - spec/dummy/test/controllers/.keep
237
+ - spec/dummy/test/fixtures/.keep
238
+ - spec/dummy/test/fixtures/files/.keep
239
+ - spec/dummy/test/integration/.keep
240
+ - spec/dummy/test/mailers/.keep
241
+ - spec/dummy/test/models/.keep
242
+ - spec/dummy/test/test_helper.rb
243
+ - spec/dummy/vendor/.keep
244
+ - spec/make_taggable/acts_as_tagger_spec.rb
245
+ - spec/make_taggable/caching_spec.rb
246
+ - spec/make_taggable/default_parser_spec.rb
247
+ - spec/make_taggable/dirty_spec.rb
248
+ - spec/make_taggable/generic_parser_spec.rb
249
+ - spec/make_taggable/make_taggable_spec.rb
250
+ - spec/make_taggable/related_spec.rb
251
+ - spec/make_taggable/single_table_inheritance_spec.rb
252
+ - spec/make_taggable/tag_list_spec.rb
253
+ - spec/make_taggable/tag_spec.rb
254
+ - spec/make_taggable/taggable_spec.rb
255
+ - spec/make_taggable/tagger_spec.rb
256
+ - spec/make_taggable/tagging_spec.rb
257
+ - spec/make_taggable/tags_helper_spec.rb
258
+ - spec/make_taggable/utils_spec.rb
259
+ - spec/make_taggable_spec.rb
260
+ - spec/spec_helper.rb
261
+ - spec/support/array.rb
262
+ - spec/support/helpers.rb
263
+ homepage: https://github.com/MatthewKennedy/make_taggable
264
+ licenses:
265
+ - MIT
266
+ metadata: {}
267
+ post_install_message:
268
+ rdoc_options: []
269
+ require_paths:
270
+ - lib
271
+ required_ruby_version: !ruby/object:Gem::Requirement
272
+ requirements:
273
+ - - ">="
274
+ - !ruby/object:Gem::Version
275
+ version: '0'
276
+ required_rubygems_version: !ruby/object:Gem::Requirement
277
+ requirements:
278
+ - - ">="
279
+ - !ruby/object:Gem::Version
280
+ version: '0'
281
+ requirements: []
282
+ rubygems_version: 3.1.4
283
+ signing_key:
284
+ specification_version: 4
285
+ summary: Advanced Tagging For Rails
286
+ test_files:
287
+ - spec/dummy/README.md
288
+ - spec/dummy/Rakefile
289
+ - spec/dummy/app/assets/config/manifest.js
290
+ - spec/dummy/app/channels/application_cable/channel.rb
291
+ - spec/dummy/app/channels/application_cable/connection.rb
292
+ - spec/dummy/app/controllers/application_controller.rb
293
+ - spec/dummy/app/controllers/concerns/.keep
294
+ - spec/dummy/app/jobs/application_job.rb
295
+ - spec/dummy/app/mailers/application_mailer.rb
296
+ - spec/dummy/app/models/altered_inheriting_taggable_model.rb
297
+ - spec/dummy/app/models/application_record.rb
298
+ - spec/dummy/app/models/cached_model.rb
299
+ - spec/dummy/app/models/cached_model_with_array.rb
300
+ - spec/dummy/app/models/columns_override_model.rb
301
+ - spec/dummy/app/models/company.rb
302
+ - spec/dummy/app/models/concerns/.keep
303
+ - spec/dummy/app/models/inheriting_taggable_model.rb
304
+ - spec/dummy/app/models/market.rb
305
+ - spec/dummy/app/models/non_standard_id_taggable_model.rb
306
+ - spec/dummy/app/models/ordered_taggable_model.rb
307
+ - spec/dummy/app/models/other_cached_model.rb
308
+ - spec/dummy/app/models/other_taggable_model.rb
309
+ - spec/dummy/app/models/student.rb
310
+ - spec/dummy/app/models/taggable_model.rb
311
+ - spec/dummy/app/models/untaggable_model.rb
312
+ - spec/dummy/app/models/user.rb
313
+ - spec/dummy/app/views/layouts/mailer.html.erb
314
+ - spec/dummy/app/views/layouts/mailer.text.erb
315
+ - spec/dummy/bin/rails
316
+ - spec/dummy/bin/rake
317
+ - spec/dummy/bin/setup
318
+ - spec/dummy/config.ru
319
+ - spec/dummy/config/application.rb
320
+ - spec/dummy/config/boot.rb
321
+ - spec/dummy/config/cable.yml
322
+ - spec/dummy/config/credentials.yml.enc
323
+ - spec/dummy/config/database.yml
324
+ - spec/dummy/config/environment.rb
325
+ - spec/dummy/config/environments/development.rb
326
+ - spec/dummy/config/environments/production.rb
327
+ - spec/dummy/config/environments/test.rb
328
+ - spec/dummy/config/initializers/application_controller_renderer.rb
329
+ - spec/dummy/config/initializers/backtrace_silencers.rb
330
+ - spec/dummy/config/initializers/cors.rb
331
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
332
+ - spec/dummy/config/initializers/inflections.rb
333
+ - spec/dummy/config/initializers/mime_types.rb
334
+ - spec/dummy/config/initializers/wrap_parameters.rb
335
+ - spec/dummy/config/locales/en.yml
336
+ - spec/dummy/config/master.key
337
+ - spec/dummy/config/puma.rb
338
+ - spec/dummy/config/routes.rb
339
+ - spec/dummy/config/spring.rb
340
+ - spec/dummy/config/storage.yml
341
+ - spec/dummy/db/migrate/20201119220853_create_taggable_models.rb
342
+ - spec/dummy/db/migrate/20201119221037_create_columns_override_models.rb
343
+ - spec/dummy/db/migrate/20201119221121_create_non_standard_id_taggable_models.rb
344
+ - spec/dummy/db/migrate/20201119221228_create_untaggable_models.rb
345
+ - spec/dummy/db/migrate/20201119221247_create_cached_models.rb
346
+ - spec/dummy/db/migrate/20201119221314_create_other_cached_models.rb
347
+ - spec/dummy/db/migrate/20201119221343_create_companies.rb
348
+ - spec/dummy/db/migrate/20201119221416_create_users.rb
349
+ - spec/dummy/db/migrate/20201119221434_create_other_taggable_models.rb
350
+ - spec/dummy/db/migrate/20201119221507_create_ordered_taggable_models.rb
351
+ - spec/dummy/db/migrate/20201119221530_create_cache_methods_injected_models.rb
352
+ - spec/dummy/db/migrate/20201119221629_create_other_cached_with_array_models.rb
353
+ - spec/dummy/db/migrate/20201119221746_create_taggable_model_with_jsons.rb
354
+ - spec/dummy/db/migrate/20201119222429_create_make_taggable_tags.make_taggable_engine.rb
355
+ - spec/dummy/db/migrate/20201119222430_create_make_taggable_taggings.make_taggable_engine.rb
356
+ - spec/dummy/db/migrate/20201119222431_add_index_to_tags.make_taggable_engine.rb
357
+ - spec/dummy/db/migrate/20201119222432_add_index_to_taggings.make_taggable_engine.rb
358
+ - spec/dummy/db/schema.rb
359
+ - spec/dummy/db/seeds.rb
360
+ - spec/dummy/lib/tasks/.keep
361
+ - spec/dummy/log/.keep
362
+ - spec/dummy/public/robots.txt
363
+ - spec/dummy/storage/.keep
364
+ - spec/dummy/test/channels/application_cable/connection_test.rb
365
+ - spec/dummy/test/controllers/.keep
366
+ - spec/dummy/test/fixtures/.keep
367
+ - spec/dummy/test/fixtures/files/.keep
368
+ - spec/dummy/test/integration/.keep
369
+ - spec/dummy/test/mailers/.keep
370
+ - spec/dummy/test/models/.keep
371
+ - spec/dummy/test/test_helper.rb
372
+ - spec/dummy/vendor/.keep
373
+ - spec/make_taggable/acts_as_tagger_spec.rb
374
+ - spec/make_taggable/caching_spec.rb
375
+ - spec/make_taggable/default_parser_spec.rb
376
+ - spec/make_taggable/dirty_spec.rb
377
+ - spec/make_taggable/generic_parser_spec.rb
378
+ - spec/make_taggable/make_taggable_spec.rb
379
+ - spec/make_taggable/related_spec.rb
380
+ - spec/make_taggable/single_table_inheritance_spec.rb
381
+ - spec/make_taggable/tag_list_spec.rb
382
+ - spec/make_taggable/tag_spec.rb
383
+ - spec/make_taggable/taggable_spec.rb
384
+ - spec/make_taggable/tagger_spec.rb
385
+ - spec/make_taggable/tagging_spec.rb
386
+ - spec/make_taggable/tags_helper_spec.rb
387
+ - spec/make_taggable/utils_spec.rb
388
+ - spec/make_taggable_spec.rb
389
+ - spec/spec_helper.rb
390
+ - spec/support/array.rb
391
+ - spec/support/helpers.rb