trabajo-afectivo/spec/models/knowledge_base/answer/translation_spec.rb

48 lines
2.3 KiB
Ruby
Raw Normal View History

2019-06-04 03:40:48 +00:00
require 'rails_helper'
require 'models/contexts/factory_context'
RSpec.describe KnowledgeBase::Answer::Translation, type: :model, current_user_id: 1 do
2019-06-04 03:40:48 +00:00
subject { create(:knowledge_base_answer_translation) }
include_context 'factory'
it { is_expected.to validate_presence_of(:title) }
it { is_expected.to validate_uniqueness_of(:kb_locale_id).scoped_to(:answer_id).with_message(//) }
it { is_expected.to belong_to(:answer) }
it { is_expected.to belong_to(:kb_locale) }
describe '.search' do
include_context 'basic Knowledge Base'
shared_examples 'verify given search backend' do |trait:, user_id:, is_visible:, elasticsearch:|
prefix = is_visible ? 'lists' : 'does not list'
it "#{prefix} #{trait} answer to #{user_id} when ES=#{elasticsearch}", searchindex: elasticsearch do
user = create(user_id)
object = create(:knowledge_base_answer, trait, knowledge_base: knowledge_base)
configure_elasticsearch(required: true, rebuild: true) if elasticsearch
expect(described_class.search({ query: object.translations.first.title, current_user: user }))
.to is_visible ? be_present : be_blank
end
end
shared_examples 'verify given user' do |trait:, user_id:, is_visible:|
include_examples 'verify given search backend', trait: trait, user_id: user_id, is_visible: is_visible, elasticsearch: true
include_examples 'verify given search backend', trait: trait, user_id: user_id, is_visible: is_visible, elasticsearch: false
end
shared_examples 'verify given permissions' do |trait:, admin:, agent:, customer:|
include_examples 'verify given user', trait: trait, user_id: :admin, is_visible: admin
include_examples 'verify given user', trait: trait, user_id: :agent, is_visible: agent
include_examples 'verify given user', trait: trait, user_id: :customer, is_visible: customer
end
include_examples 'verify given permissions', trait: :published, admin: true, agent: true, customer: false
include_examples 'verify given permissions', trait: :internal, admin: true, agent: true, customer: false
include_examples 'verify given permissions', trait: :draft, admin: true, agent: false, customer: false
include_examples 'verify given permissions', trait: :archived, admin: true, agent: false, customer: false
end
2019-06-04 03:40:48 +00:00
end