<commit_before>require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "Mongoid::AppSettings" do
  let(:settings) do
    settings = Class.new 
    settings.instance_eval { include Mongoid::AppSettings }
    settings
  end

  let(:other_settings) do
    other_settings = Class.new
    other_settings.instance_eval { include Mongoid::AppSettings }
    other_settings
  end

  it "should be possible to save a setting" do 
    settings.instance_eval { setting :something }
    settings.something = "some nice value"
    settings.something.should == "some nice value"
  end

  it "should define fields on the record" do
    settings.instance_eval { setting :something }
    expect { 
      settings.send(:record).something 
    }.not_to raise_error(NoMethodError)
  end

  it "should save settings outside of itself" do
    settings.instance_eval { setting :something }
    other_settings.instance_eval { setting :something }

    settings.something = "some nice value"
    other_settings.something.should == "some nice value"
  end

  it "should be possible to specify default values" do
    settings.instance_eval { setting :foo, :default => "bar" }
    settings.foo.should == "bar"
  end

  it "should be possible to use defaults of other settings in defaults" do
    settings.instance_eval { setting :foo, :default => "bar"
                             setting :baz, :default => "#{foo} quux" }
    settings.baz.should == "bar quux"
  end

  it "should be possible to use values of other settings in defaults" do
    settings.instance_eval { setting :foo, :default => "bar" }
    settings.foo = "baz"
    settings.instance_eval { setting :qux, :default => "#{foo} quux" }
    settings.qux.should === "baz quux"
  end

  it "should be possible to overwrite a default value" do
    settings.instance_eval { setting :foo, :default => "bar" }
    settings.foo = "baz"
    settings.foo.should == "baz"
  end

  it "should be possible to overwrite a value with something else" do
    settings.instance_eval { setting :foo, :default => "bar" }
    settings.foo = "baz"
    settings.foo = "quux"
    settings.foo.should == "quux"
  end

  it "should be possible to overwrite a value with something falsey" do
    settings.instance_eval { setting :foo, :default => "bar" }
    settings.foo = "baz"
    settings.foo = false
    settings.foo.should == false
  end

  it "should not constantly reload" do
    settings.instance_eval { setting :foo }
    other_settings.instance_eval { setting :foo }
    other_settings.foo # force other_settings to load the record

    settings.foo = "bar"
    other_settings.foo.should be_nil
  end

  it "should be possible to reload" do
    settings.instance_eval { setting :foo }
    other_settings.instance_eval { setting :foo }
    other_settings.foo # force other_settings to load the record

    settings.foo = "bar"
    other_settings.reload
    other_settings.foo.should == "bar"
  end
end<commit_msg>Reorg specs into groups<commit_after>require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "Mongoid::AppSettings" do
  let(:settings) do
    settings = Class.new 
    settings.instance_eval { include Mongoid::AppSettings }
    settings
  end

  let(:other_settings) do
    other_settings = Class.new
    other_settings.instance_eval { include Mongoid::AppSettings }
    other_settings
  end

  describe "defining settings" do
    it "should be possible to define a setting" do
      settings.instance_eval { setting :something }
      settings.something.should be_nil
    end

    it "should be possible to specify default values" do
      settings.instance_eval { setting :foo, :default => "bar" }
      settings.foo.should == "bar"
    end

    it "should be possible to use defaults of other settings in defaults" do
      settings.instance_eval { setting :foo, :default => "bar"
                              setting :baz, :default => "#{foo} quux" }
      settings.baz.should == "bar quux"
    end

    it "should be possible to use values of other settings in defaults" do
      settings.instance_eval { setting :foo, :default => "bar" }
      settings.foo = "baz"
      settings.instance_eval { setting :qux, :default => "#{foo} quux" }
      settings.qux.should === "baz quux"
    end

    it "should define fields on the record" do
      settings.instance_eval { setting :something }
      expect { 
        settings.send(:record).something 
      }.not_to raise_error(NoMethodError)
    end
  end

  describe "setting values" do
    it "should be possible to save a setting" do 
      settings.instance_eval { setting :something }
      settings.something = "some nice value"
      settings.something.should == "some nice value"
    end

    it "should save settings to mongodb" do
      settings.instance_eval { setting :something }
      other_settings.instance_eval { setting :something }

      settings.something = "some nice value"
      other_settings.something.should == "some nice value"
    end

    it "should be possible to overwrite a default value" do
      settings.instance_eval { setting :foo, :default => "bar" }
      settings.foo = "baz"
      settings.foo.should == "baz"
    end

    it "should be possible to overwrite a value with something else" do
      settings.instance_eval { setting :foo, :default => "bar" }
      settings.foo = "baz"
      settings.foo = "quux"
      settings.foo.should == "quux"
    end

    it "should be possible to unset a value, reverting to default" do
      settings.instance_eval { setting :foo, :default => "bar" }
      settings.foo = "baz"
      settings.delete(:foo)
      settings.foo.should == "bar"
    end

    it "should be possible to overwrite a value with false" do
      # At one point, Mongoid didn't support Record#set with nil/false
      # This spec is here to prevent regression
  it "should be possible to overwrite a value with something else" do
    settings.instance_eval { setting :foo, :default => "bar" }

    it "should be possible to overwrite a value with false" do
      # At one point, Mongoid didn't support Record#set with nil/false
      # This spec is here to prevent regression
      settings.instance_eval { setting :foo, :default => "bar" }
      settings.foo = "baz"
      settings.foo = nil
      settings.foo.should == nil
    end
  end

  describe "reload behaviour" do
    it "should not reload for every call" do
      settings.instance_eval { setting :foo }
      other_settings.instance_eval { setting :foo }
      other_settings.foo # force other_settings to load the record

      settings.foo = "bar"
      other_settings.foo.should be_nil
    end

    it "should be possible to reload" do
      settings.instance_eval { setting :foo }
      other_settings.instance_eval { setting :foo }
      other_settings.foo # force other_settings to load the record

      settings.foo = "bar"
      other_settings.reload
      other_settings.foo.should == "bar"
    end
  end
end
{'fraction_non_alphanumeric': 0.09067394740623652, 'fraction_numerical': 0.0, 'mean_word_length': 2.968072976054732, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '5196059', 'n_tokens_mistral': 2019, 'n_tokens_neox': 1939, 'n_words': 669}