mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 01:47:18 +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
|
class Setting < ActiveRecord::Base
|
||||||
belongs_to :setting_group
|
belongs_to :setting_group
|
||||||
|
validates :code, uniqueness: { scope: :setting_group_id }
|
||||||
end
|
end
|
||||||
|
|
|
@ -64,6 +64,10 @@ en:
|
||||||
invalid: 'IPv4 is invalid'
|
invalid: 'IPv4 is invalid'
|
||||||
ipv6:
|
ipv6:
|
||||||
invalid: 'IPv6 is invalid'
|
invalid: 'IPv6 is invalid'
|
||||||
|
setting:
|
||||||
|
attributes:
|
||||||
|
code:
|
||||||
|
taken: 'Code already exists'
|
||||||
attributes:
|
attributes:
|
||||||
domain:
|
domain:
|
||||||
name: 'Domain name'
|
name: 'Domain name'
|
||||||
|
|
|
@ -6,7 +6,6 @@ Rails.application.routes.draw do
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :setting_groups
|
resources :setting_groups
|
||||||
resources :settings
|
|
||||||
|
|
||||||
# The priority is based upon order of creation: first created -> highest priority.
|
# The priority is based upon order of creation: first created -> highest priority.
|
||||||
# See how all your routes lay out with "rake routes".
|
# See how all your routes lay out with "rake routes".
|
||||||
|
|
|
@ -2,4 +2,20 @@ require "rails_helper"
|
||||||
|
|
||||||
describe Setting do
|
describe Setting do
|
||||||
it { should belong_to(:setting_group) }
|
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
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue