<commit_before>require "spec_helper"

describe "Mobility::Backends::ActiveRecord::KeyValue", orm: :active_record do
  require "mobility/backends/active_record/key_value"
  extend Helpers::ActiveRecord

  context "with no plugins applied" do
    before do
      stub_const 'Article', Class.new(ActiveRecord::Base)
      Article.include Mobility
    end

    include_backend_examples described_class, 'Article'
  end

  context "with standard plugins applied" do
    let(:title_backend)   { article.mobility_backend_for("title") }
    let(:content_backend) { article.mobility_backend_for("content") }
    let(:cache) { false }

    before do
      stub_const 'Article', Class.new(ActiveRecord::Base)
      cache_ = cache
      Article.class_eval do
        include Mobility
        translates :title, :content, backend: :key_value, cache: cache_
        translates :subtitle, backend: :key_value
      end
    end

    context "without cache" do
      let(:article) { Article.new }
      include_accessor_examples "Article"

      it "finds translation on every read/write" do
        expect(title_backend.translations).to receive(:find).thrice.and_call_original
        title_backend.write(:en, "foo")
        title_backend.write(:en, "bar")
        expect(title_backend.read(:en)).to eq("bar")
      end
    end

    context "with cache" do
      let(:article) { Article.new }
      let(:cache) { true }
      include_accessor_examples "Article"

      it "only fetches translation once per locale" do
        expect(title_backend.translations).to receive(:find).twice.and_call_original
        title_backend.write(:en, "foo")
        title_backend.write(:en, "bar")
        expect(title_backend.read(:en)).to eq("bar")
        title_backend.write(:fr, "baz")
        expect(title_backend.read(:fr)).to eq("baz")<commit_msg>Call private method in specs<commit_after>require "spec_helper"

describe "Mobility::Backends::ActiveRecord::KeyValue", orm: :active_record do
  require "mobility/backends/active_record/key_value"
  extend Helpers::ActiveRecord

  context "with no plugins applied" do
    before do
      stub_const 'Article', Class.new(ActiveRecord::Base)
      Article.include Mobility
    end

    include_backend_examples described_class, 'Article'
  end

  context "with standard plugins applied" do
    let(:title_backend)   { article.mobility_backend_for("title") }
    let(:content_backend) { article.mobility_backend_for("content") }
    let(:cache) { false }

    before do
      stub_const 'Article', Class.new(ActiveRecord::Base)
      cache_ = cache
      Article.class_eval do
        include Mobility
        translates :title, :content, backend: :key_value, cache: cache_
        translates :subtitle, backend: :key_value
      end
    end

    context "without cache" do
      let(:article) { Article.new }
      include_accessor_examples "Article"

      it "finds translation on every read/write" do
        expect(title_backend.send(:translations)).to receive(:find).thrice.and_call_original
        title_backend.write(:en, "foo")
        title_backend.write(:en, "bar")
        expect(title_backend.read(:en)).to eq("bar")
      end
    end

    context "with cache" do
      let(:article) { Article.new }
      let(:cache) { true }
      include_accessor_examples "Article"

      it "only fetches translation once per locale" do
        expect(title_backend.send(:translations)).to receive(:find).twice.and_call_original
        title_backend.write(:en, "foo")
        title_backend.write(:en, "bar")
        expect(title_backend.read(:en)).to eq("bar")
        title_backend.write(:fr, "baz")
        expect(title_backend.read(:fr)).to eq("baz")
{'fraction_non_alphanumeric': 0.11150394343214577, 'fraction_numerical': 0.0, 'mean_word_length': 3.3942652329749103, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4665757', 'n_tokens_mistral': 1116, 'n_tokens_neox': 1076, 'n_words': 243}