<commit_before>require 'rails_helper'

describe Concerns::Storable::Collection do
  let(:model) { described_class }
  let(:klass) { model.to_s.underscore.to_sym }
  let(:config) { Concerns::Storable::Config.new }
  let(:page) { create(:page) }

  # TODO: Split up tests; 1 expect / test.
  it '#save' do
    config.add :locales, Array
    config.add :active, Axiom::Types::Boolean
    config.add :starts_on, Date
    config.add :starts_at, DateTime
    config.add :discount, Float
    config.add :age, Integer
    config.add :email, String

    collection = model.new(page, :custom, config)
    collection.locales = [:nl, :fr]
    collection.active = true
    collection.starts_on = Date.today
    collection.starts_at = DateTime.parse('2016-01-07 14:45')
    collection.discount = 13.37
    collection.age = 37
    collection.email = '<EMAIL>'
    collection.save

    collection = model.new(page, :custom, config)
    expect(collection.locales).to eq [:nl, :fr]
    expect(collection.active).to eq true
    expect(collection.starts_on).to eq Date.today
    expect(collection.starts_at).to eq DateTime.parse('2016-01-07 14:45')
    expect(collection.discount).to eq 13.37
    expect(collection.age).to eq 37
    expect(collection.email).to eq '<EMAIL>'
  end

  it '#define_reader_method_for_uploader_field' do
    store = create(:store, storable: page, name: 'foo', value: 'bar', collection: :custom)
    config.add :foo, String
    instance = described_class.new(page, :custom, config)
    instance.define_reader_method_for_uploader_field(:foo, { type: String })
    expect(instance).to respond_to(:foo)
  end

  it '#define_writer_method_for_uploader_field' do
    store = create(:store, storable: page, name: 'foo', value: 'bar', collection: :custom)
    config.add :foo, String
    instance = described_class.new(page, :custom, config)
    instance.define_writer_method_for_uploader_field(:foo, { type: String })
    expect(instance).to respond_to('foo=')
  end

  describe '#store' do
    let(:instance) { described_class.new(page, :custom, config) }
    before(:each) { config.add :foo, String }

    it 'no result' do
      expect(instance.store(:foo).id).to eq nil
    end

    it 'with result' do
      store = create(:store, storable: page, name: 'foo', value: 'bar', collection: :custom)
      expect(instance.store(:foo).id).to eq store.id
    end

    it 'file: true' do
      store = create(:store, storable: page, name: 'foo', value: 'bar', collection: :custom)
      expect(instance.store(:foo, file: true).id).to eq store.id<commit_msg>Remove unused var.<commit_after>require 'rails_helper'

describe Concerns::Storable::Collection do
  let(:model) { described_class }
  let(:klass) { model.to_s.underscore.to_sym }
  let(:config) { Concerns::Storable::Config.new }
  let(:page) { create(:page) }

  # TODO: Split up tests; 1 expect / test.
  it '#save' do
    config.add :locales, Array
    config.add :active, Axiom::Types::Boolean
    config.add :starts_on, Date
    config.add :starts_at, DateTime
    config.add :discount, Float
    config.add :age, Integer
    config.add :email, String

    collection = model.new(page, :custom, config)
    collection.locales = [:nl, :fr]
    collection.active = true
    collection.starts_on = Date.today
    collection.starts_at = DateTime.parse('2016-01-07 14:45')
    collection.discount = 13.37
    collection.age = 37
    collection.email = '<EMAIL>'
    collection.save

    collection = model.new(page, :custom, config)
    expect(collection.locales).to eq [:nl, :fr]
    expect(collection.active).to eq true
    expect(collection.starts_on).to eq Date.today
    expect(collection.starts_at).to eq DateTime.parse('2016-01-07 14:45')
    expect(collection.discount).to eq 13.37
    expect(collection.age).to eq 37
    expect(collection.email).to eq '<EMAIL>'
  end

  it '#define_reader_method_for_uploader_field' do
    create(:store, storable: page, name: 'foo', value: 'bar', collection: :custom)
    config.add :foo, String
    instance = described_class.new(page, :custom, config)
    instance.define_reader_method_for_uploader_field(:foo, { type: String })
    expect(instance).to respond_to(:foo)
  end

  it '#define_writer_method_for_uploader_field' do
    create(:store, storable: page, name: 'foo', value: 'bar', collection: :custom)
    config.add :foo, String
    instance = described_class.new(page, :custom, config)
    instance.define_writer_method_for_uploader_field(:foo, { type: String })
    expect(instance).to respond_to('foo=')
  end

  describe '#store' do
    let(:instance) { described_class.new(page, :custom, config) }
    before(:each) { config.add :foo, String }

    it 'no result' do
      expect(instance.store(:foo).id).to eq nil
    end

    it 'with result' do
      store = create(:store, storable: page, name: 'foo', value: 'bar', collection: :custom)
      expect(instance.store(:foo).id).to eq store.id
    end

    it 'file: true' do
      store = create(:store, storable: page, name: 'foo', value: 'bar', collection: :custom)
      expect(instance.store(:foo, file: true).id).to eq store.id
{'fraction_non_alphanumeric': 0.1366934693077074, 'fraction_numerical': 0.014512649539125318, 'mean_word_length': 3.820415879017013, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2133880', 'n_tokens_mistral': 1733, 'n_tokens_neox': 1646, 'n_words': 401}