Skip to content

Commit 6ff2d71

Browse files
committed
Use the tag methods provided by acts-as-taggable-on
1 parent 7d32827 commit 6ff2d71

File tree

16 files changed

+24
-49
lines changed

16 files changed

+24
-49
lines changed

app/jobs/synchronize_cognates_on_topics_job.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class SynchronizeCognatesOnTopicsJob < ApplicationJob
22
def perform(tag)
33
Topic.where(id: tag.taggings.select(:taggable_id)).each do |topic|
4-
tags = topic.current_tags_list << tag.cognates_tags.uniq.pluck(:name)
4+
tags = topic.tag_list << tag.cognates_tags.uniq.pluck(:name)
55
topic.tag_list.add(tags)
66
topic.save
77
end

app/models/concerns/taggable.rb

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,6 @@ class LanguageContextError < StandardError; end
1313
end
1414
end
1515

16-
# Retrieves associated tags
17-
#
18-
# @return [Array<Tag>] list of tags
19-
def current_tags
20-
tags
21-
end
22-
23-
# Retrieves associated tags
24-
#
25-
# @return [Array<String>] list of tag names
26-
def current_tags_list
27-
tag_list
28-
end
29-
3016
# Updates the list of tags for a specific record
3117
# @param attrs [Array<String>] the list of tags
3218
# @return [Boolean] true if tags are processed successfully, false otherwise
@@ -49,7 +35,7 @@ def process_tags(tag_names)
4935
return unless tag_names.present?
5036

5137
Rails.logger.info "Processing tags: #{tag_names} for record: #{id}"
52-
removed_tags = current_tags_list - tag_names
38+
removed_tags = tag_list - tag_names
5339
@full_list_of_tags = tag_names + removed_tags
5440
removed_tags_with_cognates = tags_with_cognates(removed_tags)
5541
tag_names_without_redundant_cognates = tag_names - removed_tags_with_cognates

app/services/text_generator/tags.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def initialize(language, **args)
1010

1111
def text_content
1212
scope
13-
.flat_map { |topic| topic.current_tags_list }
13+
.flat_map { |topic| topic.tag_list }
1414
.uniq
1515
.sort
1616
.join("\n")

app/services/text_generator/title_and_tags.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def initialize(language, **args)
1111
def text_content
1212
scope
1313
.flat_map do |topic|
14-
[ topic.title ] + topic.current_tags_list
14+
[ topic.title ] + topic.tag_list
1515
end
1616
.join("\n")
1717
end

app/views/topics/_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
ActsAsTaggableOn::Tag.all&.order(name: :asc),
4848
:name,
4949
:name,
50-
topic.current_tags_list
50+
topic.tag_list
5151
),
5252
{ prompt: "Select tags", include_blank: true },
5353
multiple: true,

app/views/topics/_topic.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
</div>
3232
<div class="card-footer">
3333
<strong>Tags:</strong>
34-
<% topic.current_tags.each do |tag| %>
34+
<% topic.tags.each do |tag| %>
3535
<%= link_to tag.name, tag_path(tag), class: "badge bg-success text-decoration-none me-1", target: "_blank" %>
3636
<% end %>
3737
</div>

lib/autorequire/data_import.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def self.import_topic_tags
204204
topic.tag_list.add(tag_names_str)
205205
topic.save!
206206

207-
puts "#{topic.title} - #{topic.id} / Tags: #{topic.current_tags_list}"
207+
puts "#{topic.title} - #{topic.id} / Tags: #{topic.tag_list}"
208208
end
209209
puts "Topic tags import completed"
210210
end

spec/factories/tags.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
trait :english do
2222
after(:build) do |tag|
2323
topic = create(:topic)
24-
topic.current_tags << tag
24+
topic.tags << tag
2525
topic.save
2626
end
2727
end

spec/jobs/synchronize_cognates_on_topics_job_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
it "adds new cognates to topics tagged with the original tag" do
3636
SynchronizeCognatesOnTopicsJob.perform_now(tag)
37-
expect(Topic.find_by(id: english_topic_1.id).current_tags_list)
37+
expect(Topic.find_by(id: english_topic_1.id).tag_list)
3838
.to match_array([ "tag", "english cognate", "english reverse cognate", "spanish cognate", "spanish reverse cognate" ])
3939
end
4040
end

spec/requests/topics/update_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
put topic_url(topic), params: { topic: topic_params }
3838

3939
expect(response).to redirect_to(topics_url)
40-
expect(topic.reload.current_tags).to be_empty
40+
expect(topic.reload.tags).to be_empty
4141
expect(Tag.find_by(name: tag.name)).to be_nil
4242
end
4343
end
@@ -54,7 +54,7 @@
5454
it "removes the tag from the topic but does not destroy the tag" do
5555
put topic_url(topic), params: { topic: topic_params }
5656
expect(response).to redirect_to(topics_url)
57-
expect(topic.reload.current_tags).to be_empty
57+
expect(topic.reload.tags).to be_empty
5858
expect(Tag.find_by(name: tag.name)).to be_present
5959
end
6060
end
@@ -75,7 +75,7 @@
7575
put topic_url(topic), params: { topic: topic_params }
7676

7777
expect(response).to redirect_to(topics_url)
78-
expect(topic.reload.current_tags).to eq([])
78+
expect(topic.reload.tags).to eq([])
7979
expect(Tag.find_by(name: "tag")).to be_nil
8080
expect(Tag.find_by(name: "cognate")).to be_nil
8181
end

0 commit comments

Comments
 (0)