Sha256: 752367cc4bbaa53abbfe3df9876f8f7aaa3a3d1fe454f5975622e0d4ed2c6022

Contents?: true

Size: 1.73 KB

Versions: 5

Compression:

Stored size: 1.73 KB

Contents

require 'rails_helper'

module Pwb
  RSpec.describe Api::V1::TranslationsController, type: :controller do
    routes { Pwb::Engine.routes }
    context 'with admin user' do
      login_admin_user

      describe 'PUT' do
        it 'creates correct translation' do
          # below will throw an error if no translations exist
          # original_pt_count = I18n.t("propertyTypes").count
          new_translation_params = {
            locale: "en",
            i18n_value: "Flat",
            i18n_key: "flat",
            batch_key: "property-types"
          }
          put :create_translation_value, params: new_translation_params
          expect(response.status).to eq(200)
          expect(response.content_type).to eq('application/json')

          expect(I18n::Backend::ActiveRecord::Translation.last.key).to eq(new_translation_params[:batch_key].underscore.camelcase(:lower) + "." + new_translation_params[:i18n_key])
          # result = JSON.parse(response.body)
          # expect(I18n.t("propertyTypes").count).to eq(original_pt_count + 1)
          expect(I18n.t(I18n::Backend::ActiveRecord::Translation.last.key)).to eq(new_translation_params[:i18n_value])
        end
      end
      describe 'GET #get_by_batch' do
        it 'renders correct json' do
          get :get_by_batch, params: {
            batch_key: "property-types"
          }
          # , format: :json

          expect(response.status).to eq(200)
          expect(response.content_type).to eq('application/json')

          result = JSON.parse(response.body)
          expect(result).to have_key('batch_key')
          expect(result).to have_key('translations')
          # expect(result['agency']['company_name']).to eq(agency.company_name)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pwb-1.4.0 spec/controllers/pwb/api/v1/translations_controller_spec.rb
pwb-1.3.0 spec/controllers/pwb/api/v1/translations_controller_spec.rb
pwb-1.2.0 spec/controllers/pwb/api/v1/translations_controller_spec.rb
pwb-1.1.1 spec/controllers/pwb/api/v1/translations_controller_spec.rb
pwb-1.0.0 spec/controllers/pwb/api/v1/translations_controller_spec.rb