Merge pull request #1437 from tchak/fix-public-private
Fix public and private champs scopes
This commit is contained in:
commit
2223d3437d
4 changed files with 20 additions and 2 deletions
|
@ -12,7 +12,7 @@ class Champ < ActiveRecord::Base
|
|||
before_save :multiple_select_to_string, if: Proc.new { type_champ == 'multiple_drop_down_list' }
|
||||
|
||||
scope :updated_since?, -> (date) { where('champs.updated_at > ?', date) }
|
||||
scope :public_only, -> { where.not(type: 'ChampPrivate').or(where(private: [false, nil])) }
|
||||
scope :public_only, -> { where(type: 'ChampPublic').or(where(private: false)) }
|
||||
scope :private_only, -> { where(type: 'ChampPrivate').or(where(private: true)) }
|
||||
|
||||
def public?
|
||||
|
|
|
@ -26,7 +26,7 @@ class TypeDeChamp < ActiveRecord::Base
|
|||
|
||||
belongs_to :procedure
|
||||
|
||||
scope :public_only, -> { where.not(type: 'TypeDeChampPrivate').or(where(private: [false, nil])) }
|
||||
scope :public_only, -> { where(type: 'TypeDeChampPublic').or(where(private: false)) }
|
||||
scope :private_only, -> { where(type: 'TypeDeChampPrivate').or(where(private: true)) }
|
||||
|
||||
has_many :champ, inverse_of: :type_de_champ, dependent: :destroy do
|
||||
|
|
|
@ -13,6 +13,15 @@ describe Champ do
|
|||
it { expect(champ.private?).to be_falsey }
|
||||
end
|
||||
|
||||
describe '#public_only' do
|
||||
let(:dossier) { create(:dossier) }
|
||||
|
||||
it 'partition public and private' do
|
||||
expect(dossier.champs.count).to eq(1)
|
||||
expect(dossier.champs_private.count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#format_datetime' do
|
||||
let(:type_de_champ) { build(:type_de_champ, type_champ: 'datetime') }
|
||||
let(:champ) { type_de_champ.champ.build(value: value) }
|
||||
|
|
|
@ -4,4 +4,13 @@ describe TypeDeChamp do
|
|||
require 'models/type_de_champ_shared_example'
|
||||
|
||||
it_should_behave_like "type_de_champ_spec"
|
||||
|
||||
describe '#public_only' do
|
||||
let(:procedure) { create(:procedure, :with_type_de_champ, :with_type_de_champ_private) }
|
||||
|
||||
it 'partition public and private' do
|
||||
expect(procedure.types_de_champ.count).to eq(1)
|
||||
expect(procedure.types_de_champ_private.count).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue