mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +02:00
Add setting uniqueness test
This commit is contained in:
parent
330a732382
commit
788ec64ee6
5 changed files with 21 additions and 4 deletions
|
@ -1,3 +0,0 @@
|
|||
class SettingsController < ApplicationController
|
||||
|
||||
end
|
|
@ -1,3 +1,4 @@
|
|||
class Setting < ActiveRecord::Base
|
||||
belongs_to :setting_group
|
||||
validates :code, uniqueness: { scope: :setting_group_id }
|
||||
end
|
||||
|
|
|
@ -64,6 +64,10 @@ en:
|
|||
invalid: 'IPv4 is invalid'
|
||||
ipv6:
|
||||
invalid: 'IPv6 is invalid'
|
||||
setting:
|
||||
attributes:
|
||||
code:
|
||||
taken: 'Code already exists'
|
||||
attributes:
|
||||
domain:
|
||||
name: 'Domain name'
|
||||
|
|
|
@ -6,7 +6,6 @@ Rails.application.routes.draw do
|
|||
end
|
||||
|
||||
resources :setting_groups
|
||||
resources :settings
|
||||
|
||||
# The priority is based upon order of creation: first created -> highest priority.
|
||||
# See how all your routes lay out with "rake routes".
|
||||
|
|
|
@ -2,4 +2,20 @@ require "rails_helper"
|
|||
|
||||
describe Setting do
|
||||
it { should belong_to(:setting_group) }
|
||||
|
||||
it 'validates code uniqueness' do
|
||||
sg = Fabricate(:setting_group)
|
||||
sg.settings.build(code: 'this_is_code')
|
||||
expect(sg.save).to be true
|
||||
|
||||
sg.settings.build(code: 'this_is_code')
|
||||
expect(sg.save).to be false
|
||||
err = sg.settings.last.errors[:code].first
|
||||
expect(err).to eq('Code already exists')
|
||||
|
||||
sg_2 = Fabricate(:setting_group)
|
||||
|
||||
sg_2.settings.build(code: 'this_is_code')
|
||||
expect(sg_2.save).to be true
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue