Skip to content

Commit

Permalink
AO3-6328 Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
weeklies committed Sep 28, 2023
1 parent 7c55cd8 commit ffd0716
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion features/step_definitions/tag_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@

# Create tags with specified number of uses
hash.each do |freeform, uses|
tag = Freeform.create(name: freeform)
tag = Freeform.find_or_create_by_name(freeform)
tag.taggings_count = uses
end

Expand Down
21 changes: 9 additions & 12 deletions spec/models/tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
end
end

context "write_redis_to_database" do
describe "write_redis_to_database" do
let(:tag) { create(:fandom) }
let!(:work) { create(:work, fandom_string: tag.name) }

Expand All @@ -87,22 +87,23 @@
tag.reload
end

def expect_tag_update_flag_in_redis_to_be(flag)
expect(REDIS_GENERAL.sismember("tag_update", tag.id)).to eq flag
end

it "does not write to the database when reading the count" do
tag.taggings_count
# Check if redis has flagged this tag for an update to the database.
expect(REDIS_GENERAL.sismember("tag_update", tag.id)).to eq false
expect_tag_update_flag_in_redis_to_be(false)
end

it "does not write to the database when assigning the same count" do
tag.taggings_count = 1
# Check if redis has flagged this tag for an update to the database.
expect(REDIS_GENERAL.sismember("tag_update", tag.id)).to eq false
expect_tag_update_flag_in_redis_to_be(false)
end

it "writes to the database when assigning a new count" do
tag.taggings_count = 2
# Check if redis has flagged this tag for an update to the database.
expect(REDIS_GENERAL.sismember("tag_update", tag.id)).to eq true
expect_tag_update_flag_in_redis_to_be(true)

RedisJobSpawner.perform_now("TagCountUpdateJob")
tag.reload
Expand All @@ -113,12 +114,8 @@
end

it "writes to the database when adding a new work with the same tag" do
expect(tag.taggings_count_cache).to eq 1
expect(tag.taggings_count).to eq 1

create(:work, fandom_string: tag.name)
# Check if redis has flagged this tag for an update to the database.
expect(REDIS_GENERAL.sismember("tag_update", tag.id)).to eq true
expect_tag_update_flag_in_redis_to_be(true)

RedisJobSpawner.perform_now("TagCountUpdateJob")
tag.reload
Expand Down

0 comments on commit ffd0716

Please sign in to comment.