Sha256: d68c87fc0dbfed7752c7f859483d19c54836286911f9615297f3877f51ffdbdd

Contents?: true

Size: 1.58 KB

Versions: 31

Compression:

Stored size: 1.58 KB

Contents

require "rails_helper"

describe Releaf::Builders::FormBuilder::I18nFields, type: :class do
  class FormBuilderTestHelper < ActionView::Base
    include Releaf::ApplicationHelper
    include Releaf::ButtonHelper
    include FontAwesome::Rails::IconHelper
  end

  let(:template){ FormBuilderTestHelper.new }
  let(:object){ Book.new }
  let(:subject){ Releaf::Builders::FormBuilder.new(:book, object, template, {}) }

  describe "#locales" do
    it "returns object globalize locales" do
      allow(subject.object.class).to receive(:globalize_locales).and_return([:de, :ru])
      expect(subject.locales).to eq([:de, :ru])
    end
  end

  describe "#default_locale" do
    before do
      allow(subject).to receive(:layout_settings).with("releaf.i18n.locale").and_return("de")
      allow(I18n).to receive(:locale).and_return(:ru)
      allow(subject).to receive(:locales).and_return([:de, :ru])
    end

    context "when layout settings has stored locale" do
      it "returns stored locale normalized to symbol" do
        expect(subject.default_locale).to eq(:de)
      end
    end

    context "when layout settings hasn't stored locale" do
      it "returns current I18n locale" do
        allow(subject).to receive(:layout_settings).with("releaf.i18n.locale").and_return(nil)
        expect(subject.default_locale).to eq(:ru)
      end
    end

    context "when stored locale or I18n locale is not within form locales" do
      it "returns first form locale" do
        allow(subject).to receive(:locales).and_return([:lv, :en])
        expect(subject.default_locale).to eq(:lv)
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
releaf-core-1.1.22 spec/builders/releaf/builders/form_builder/i18n_fields_spec.rb
releaf-core-1.1.21 spec/builders/releaf/builders/form_builder/i18n_fields_spec.rb
releaf-core-1.1.20 spec/builders/releaf/builders/form_builder/i18n_fields_spec.rb
releaf-core-1.1.19 spec/builders/releaf/builders/form_builder/i18n_fields_spec.rb
releaf-core-1.1.18 spec/builders/releaf/builders/form_builder/i18n_fields_spec.rb
releaf-core-1.1.17 spec/builders/releaf/builders/form_builder/i18n_fields_spec.rb
releaf-core-1.1.16 spec/builders/releaf/builders/form_builder/i18n_fields_spec.rb
releaf-core-1.1.15 spec/builders/releaf/builders/form_builder/i18n_fields_spec.rb
releaf-core-1.1.14 spec/builders/releaf/builders/form_builder/i18n_fields_spec.rb
releaf-core-1.1.13 spec/builders/releaf/builders/form_builder/i18n_fields_spec.rb
releaf-core-1.1.12 spec/builders/releaf/builders/form_builder/i18n_fields_spec.rb
releaf-core-1.1.11 spec/builders/releaf/builders/form_builder/i18n_fields_spec.rb
releaf-core-1.1.10 spec/builders/releaf/builders/form_builder/i18n_fields_spec.rb
releaf-core-1.1.9 spec/builders/releaf/builders/form_builder/i18n_fields_spec.rb
releaf-core-1.1.8 spec/builders/releaf/builders/form_builder/i18n_fields_spec.rb
releaf-core-1.1.7 spec/builders/releaf/builders/form_builder/i18n_fields_spec.rb
releaf-core-1.1.6 spec/builders/releaf/builders/form_builder/i18n_fields_spec.rb
releaf-core-1.1.5 spec/builders/releaf/builders/form_builder/i18n_fields_spec.rb
releaf-core-1.1.4 spec/builders/releaf/builders/form_builder/i18n_fields_spec.rb
releaf-core-1.1.3 spec/builders/releaf/builders/form_builder/i18n_fields_spec.rb