<commit_before>require 'rails_helper'
require_relative '../dummy_provider'

RSpec.describe DiscourseChat::Channel do
  include_context "dummy provider"
  include_context "validated dummy provider"


  it 'should save and load successfully' do
    expect(DiscourseChat::Channel.all.length).to eq(0)

    chan = DiscourseChat::Channel.create({
          provider:"dummy",
        })

    expect(DiscourseChat::Channel.all.length).to eq(1)

    loadedChan = DiscourseChat::Channel.find(chan.id)

    expect(loadedChan.provider).to eq('dummy')
    
  end

  it 'can be filtered by provider' do
    channel1 = DiscourseChat::Channel.create!(provider:'dummy')
    channel2 = DiscourseChat::Channel.create!(provider:'dummy2', data:{val:"blah"})
    channel3 = DiscourseChat::Channel.create!(provider:'dummy2', data:{val:"blah2"})

    expect(DiscourseChat::Channel.all.length).to eq(3)

    expect(DiscourseChat::Channel.with_provider('dummy2').length).to eq(2)
    expect(DiscourseChat::Channel.with_provider('dummy').length).to eq(1)
  end

  it 'can be filtered by data value' do
    channel2 = DiscourseChat::Channel.create!(provider:'dummy2', data:{val:"foo"})
    channel3 = DiscourseChat::Channel.create!(provider:'dummy2', data:{val:"blah"})

    expect(DiscourseChat::Channel.all.length).to eq(2)

    for_provider = DiscourseChat::Channel.with_provider('dummy2')
    expect(for_provider.length).to eq(2)

    expect(DiscourseChat::Channel.with_provider('dummy2').with_data_value('val','blah').length).to eq(1)
  end

  it 'can find its own rules' do<commit_msg>Add spec for editing channels<commit_after>require 'rails_helper'
require_relative '../dummy_provider'

RSpec.describe DiscourseChat::Channel do
  include_context "dummy provider"
  include_context "validated dummy provider"


  it 'should save and load successfully' do
    expect(DiscourseChat::Channel.all.length).to eq(0)

    chan = DiscourseChat::Channel.create({
          provider:"dummy",
        })

    expect(DiscourseChat::Channel.all.length).to eq(1)

    loadedChan = DiscourseChat::Channel.find(chan.id)

    expect(loadedChan.provider).to eq('dummy')
    
  end

  it 'should edit successfully' do
    channel = DiscourseChat::Channel.create!(provider:"dummy2", data:{val:"hello"})
    expect(channel.valid?).to eq(true)
    channel.save!
  end

  it 'can be filtered by provider' do
    channel1 = DiscourseChat::Channel.create!(provider:'dummy')
    channel2 = DiscourseChat::Channel.create!(provider:'dummy2', data:{val:"blah"})
    channel3 = DiscourseChat::Channel.create!(provider:'dummy2', data:{val:"blah2"})

    expect(DiscourseChat::Channel.all.length).to eq(3)

    expect(DiscourseChat::Channel.with_provider('dummy2').length).to eq(2)
    expect(DiscourseChat::Channel.with_provider('dummy').length).to eq(1)
  end

  it 'can be filtered by data value' do
    channel2 = DiscourseChat::Channel.create!(provider:'dummy2', data:{val:"foo"})
    channel3 = DiscourseChat::Channel.create!(provider:'dummy2', data:{val:"blah"})

    expect(DiscourseChat::Channel.all.length).to eq(2)

    for_provider = DiscourseChat::Channel.with_provider('dummy2')
    expect(for_provider.length).to eq(2)

    expect(DiscourseChat::Channel.with_provider('dummy2').with_data_value('val','blah').length).to eq(1)
  end

  it 'can find its own rules' do
{'fraction_non_alphanumeric': 0.14487526299969944, 'fraction_numerical': 0.012924556657649534, 'mean_word_length': 5.039927404718694, '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': '2238697', 'n_tokens_mistral': 1052, 'n_tokens_neox': 1002, 'n_words': 185}