spec/twitter_cldr_spec.rb [106:192]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      end

      it "should fall back if the user sets an unsupported locale" do
        FastGettext.locale = :ko
        TwitterCldr.locale = "blarg"
        expect(TwitterCldr.locale).to eq(:ko)

        FastGettext.locale = nil
        I18n.locale = :hu
        expect(TwitterCldr.locale).to eq(:hu)
      end
    end

    context "with implicit locale (fallbacks)" do
      before(:each) do
        TwitterCldr.locale = nil
      end

      it "should return FastGettext locale before I18n locale and fall back gracefully" do
        FastGettext.locale = :pt
        I18n.locale = :ar
        expect(TwitterCldr.locale).to eq(:pt)

        FastGettext.locale = nil
        expect(TwitterCldr.locale).to eq(:ar)

        I18n.locale = nil
        expect(TwitterCldr.locale).to eq(:en)
      end

      context "with only FastGettext locale" do
        before(:each) do
          I18n.locale = nil  # disable I18n fallback
        end

        it "should return the FastGettext locale if it's supported" do
          FastGettext.locale = "vi"
          expect(TwitterCldr.locale).to eq(:vi)
        end

        it "should return the default locale if the FastGettext locale is unsupported" do
          FastGettext.locale = "bogus"
          expect(TwitterCldr.locale).to eq(TwitterCldr::DEFAULT_LOCALE)
        end
      end

      context "with only I18n locale" do
        before(:each) do
          FastGettext.locale = nil  # disable FastGettext fallback
        end

        it "should return the I18n locale if it's supported" do
          I18n.locale = "ru"
          expect(TwitterCldr.locale).to eq(:ru)
        end

        it "should return the default locale if the I18n locale is unsupported" do
          I18n.locale = "bogus"
          expect(TwitterCldr.locale).to eq(TwitterCldr::DEFAULT_LOCALE)
        end
      end

      context "with a custom fallback" do
        before(:each) do
          @allow = false
          TwitterCldr.register_locale_fallback(lambda { @allow ? :uk : nil })
        end

        it "should fall back to the custom locale" do
          expect(TwitterCldr.locale).to eq(:en)
          @allow = true
          expect(TwitterCldr.locale).to eq(:uk)
        end

        it "should fall back to the next fallback option if the custom one returns nil" do
          FastGettext.locale = :lv
          expect(TwitterCldr.locale).to eq(:lv)
          @allow = true
          expect(TwitterCldr.locale).to eq(:uk)
        end

        it "should not return the fallback locale if it's unsupported" do
          TwitterCldr.reset_locale_fallbacks
          TwitterCldr.register_locale_fallback(lambda { :zzz })
          expect(TwitterCldr.locale).to eq(:en)
        end
      end
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



spec/twitter_cldr_spec.rb [192:278]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      end

      it "should fall back if the user sets an unsupported locale" do
        FastGettext.locale = :ko
        TwitterCldr.locale = "blarg"
        expect(TwitterCldr.locale).to eq(:ko)

        FastGettext.locale = nil
        I18n.locale = :hu
        expect(TwitterCldr.locale).to eq(:hu)
      end
    end

    context "with implicit locale (fallbacks)" do
      before(:each) do
        TwitterCldr.locale = nil
      end

      it "should return FastGettext locale before I18n locale and fall back gracefully" do
        FastGettext.locale = :pt
        I18n.locale = :ar
        expect(TwitterCldr.locale).to eq(:pt)

        FastGettext.locale = nil
        expect(TwitterCldr.locale).to eq(:ar)

        I18n.locale = nil
        expect(TwitterCldr.locale).to eq(:en)
      end

      context "with only FastGettext locale" do
        before(:each) do
          I18n.locale = nil  # disable I18n fallback
        end

        it "should return the FastGettext locale if it's supported" do
          FastGettext.locale = "vi"
          expect(TwitterCldr.locale).to eq(:vi)
        end

        it "should return the default locale if the FastGettext locale is unsupported" do
          FastGettext.locale = "bogus"
          expect(TwitterCldr.locale).to eq(TwitterCldr::DEFAULT_LOCALE)
        end
      end

      context "with only I18n locale" do
        before(:each) do
          FastGettext.locale = nil  # disable FastGettext fallback
        end

        it "should return the I18n locale if it's supported" do
          I18n.locale = "ru"
          expect(TwitterCldr.locale).to eq(:ru)
        end

        it "should return the default locale if the I18n locale is unsupported" do
          I18n.locale = "bogus"
          expect(TwitterCldr.locale).to eq(TwitterCldr::DEFAULT_LOCALE)
        end
      end

      context "with a custom fallback" do
        before(:each) do
          @allow = false
          TwitterCldr.register_locale_fallback(lambda { @allow ? :uk : nil })
        end

        it "should fall back to the custom locale" do
          expect(TwitterCldr.locale).to eq(:en)
          @allow = true
          expect(TwitterCldr.locale).to eq(:uk)
        end

        it "should fall back to the next fallback option if the custom one returns nil" do
          FastGettext.locale = :lv
          expect(TwitterCldr.locale).to eq(:lv)
          @allow = true
          expect(TwitterCldr.locale).to eq(:uk)
        end

        it "should not return the fallback locale if it's unsupported" do
          TwitterCldr.reset_locale_fallbacks
          TwitterCldr.register_locale_fallback(lambda { :zzz })
          expect(TwitterCldr.locale).to eq(:en)
        end
      end
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



