mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 01:01:39 -05:00
Fix tags request specs
This commit is contained in:
parent
e02b397b87
commit
01df22d080
3 changed files with 31 additions and 9 deletions
|
|
@ -6,6 +6,8 @@ class Tag < ApplicationRecord
|
||||||
has_many :places, through: :taggings, source: :taggable, source_type: 'Place'
|
has_many :places, through: :taggings, source: :taggable, source_type: 'Place'
|
||||||
|
|
||||||
validates :name, presence: true, uniqueness: { scope: :user_id }
|
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 :color, format: { with: /\A#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\z/, allow_blank: true }
|
||||||
validates :privacy_radius_meters, numericality: {
|
validates :privacy_radius_meters, numericality: {
|
||||||
greater_than: 0,
|
greater_than: 0,
|
||||||
|
|
@ -20,4 +22,13 @@ class Tag < ApplicationRecord
|
||||||
def privacy_zone?
|
def privacy_zone?
|
||||||
privacy_radius_meters.present?
|
privacy_radius_meters.present?
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -50,9 +50,8 @@ RSpec.describe "Tags", type: :request do
|
||||||
it "prevents editing other users' tags" do
|
it "prevents editing other users' tags" do
|
||||||
other_tag = create(:tag, user: create(:user))
|
other_tag = create(:tag, user: create(:user))
|
||||||
|
|
||||||
expect {
|
get edit_tag_path(other_tag)
|
||||||
get edit_tag_path(other_tag)
|
expect(response).to have_http_status(:not_found)
|
||||||
}.to raise_error(ActiveRecord::RecordNotFound)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -116,9 +115,8 @@ RSpec.describe "Tags", type: :request do
|
||||||
it "prevents updating other users' tags" do
|
it "prevents updating other users' tags" do
|
||||||
other_tag = create(:tag, user: create(:user))
|
other_tag = create(:tag, user: create(:user))
|
||||||
|
|
||||||
expect {
|
patch tag_path(other_tag), params: { tag: { name: 'Hacked' } }
|
||||||
patch tag_path(other_tag), params: { tag: { name: 'Hacked' } }
|
expect(response).to have_http_status(:not_found)
|
||||||
}.to raise_error(ActiveRecord::RecordNotFound)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -139,9 +137,8 @@ RSpec.describe "Tags", type: :request do
|
||||||
it "prevents deleting other users' tags" do
|
it "prevents deleting other users' tags" do
|
||||||
other_tag = create(:tag, user: create(:user))
|
other_tag = create(:tag, user: create(:user))
|
||||||
|
|
||||||
expect {
|
delete tag_path(other_tag)
|
||||||
delete tag_path(other_tag)
|
expect(response).to have_http_status(:not_found)
|
||||||
}.to raise_error(ActiveRecord::RecordNotFound)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
14
spec/support/github_api_stubs.rb
Normal file
14
spec/support/github_api_stubs.rb
Normal file
|
|
@ -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
|
||||||
Loading…
Reference in a new issue