From 01df22d080494c1a7ee6ebcde656a23567fea8ed Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 19 Nov 2025 20:35:43 +0100 Subject: [PATCH] Fix tags request specs --- app/models/tag.rb | 11 +++++++++++ spec/requests/tags_spec.rb | 15 ++++++--------- spec/support/github_api_stubs.rb | 14 ++++++++++++++ 3 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 spec/support/github_api_stubs.rb diff --git a/app/models/tag.rb b/app/models/tag.rb index 13cd4c3c..a47a8726 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -6,6 +6,8 @@ class Tag < ApplicationRecord has_many :places, through: :taggings, source: :taggable, source_type: 'Place' validates :name, presence: true, uniqueness: { scope: :user_id } + validates :icon, length: { maximum: 10, allow_blank: true } + validate :icon_is_not_ascii_letter validates :color, format: { with: /\A#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\z/, allow_blank: true } validates :privacy_radius_meters, numericality: { greater_than: 0, @@ -20,4 +22,13 @@ class Tag < ApplicationRecord def privacy_zone? privacy_radius_meters.present? end + + private + + def icon_is_not_ascii_letter + return if icon.blank? + return unless icon.match?(/\A[a-zA-Z]+\z/) + + errors.add(:icon, 'must be an emoji or symbol, not a letter') + end end diff --git a/spec/requests/tags_spec.rb b/spec/requests/tags_spec.rb index e267af16..3609b356 100644 --- a/spec/requests/tags_spec.rb +++ b/spec/requests/tags_spec.rb @@ -50,9 +50,8 @@ RSpec.describe "Tags", type: :request do it "prevents editing other users' tags" do other_tag = create(:tag, user: create(:user)) - expect { - get edit_tag_path(other_tag) - }.to raise_error(ActiveRecord::RecordNotFound) + get edit_tag_path(other_tag) + expect(response).to have_http_status(:not_found) end end @@ -116,9 +115,8 @@ RSpec.describe "Tags", type: :request do it "prevents updating other users' tags" do other_tag = create(:tag, user: create(:user)) - expect { - patch tag_path(other_tag), params: { tag: { name: 'Hacked' } } - }.to raise_error(ActiveRecord::RecordNotFound) + patch tag_path(other_tag), params: { tag: { name: 'Hacked' } } + expect(response).to have_http_status(:not_found) end end @@ -139,9 +137,8 @@ RSpec.describe "Tags", type: :request do it "prevents deleting other users' tags" do other_tag = create(:tag, user: create(:user)) - expect { - delete tag_path(other_tag) - }.to raise_error(ActiveRecord::RecordNotFound) + delete tag_path(other_tag) + expect(response).to have_http_status(:not_found) end end diff --git a/spec/support/github_api_stubs.rb b/spec/support/github_api_stubs.rb new file mode 100644 index 00000000..017cd9f3 --- /dev/null +++ b/spec/support/github_api_stubs.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +# Stub GitHub API requests in tests +RSpec.configure do |config| + config.before(:each) do + # Stub GitHub API version checking + stub_request(:get, "https://api.github.com/repos/Freika/dawarich/tags") + .to_return( + status: 200, + body: [{ name: "v0.1.0" }].to_json, + headers: { 'Content-Type' => 'application/json' } + ) + end +end