<commit_before>require 'test_helper'

describe AudioFileTemplatePolicy do
  let(:account) { create(:account) }
  let(:series) { create(:series, account: account) }
  let(:audio_version_template) { create(:audio_version_template, series: series) }
  let(:audio_file_template) { build_stubbed(:audio_file_template, audio_version_template: audio_version_template) }
  let(:token) { StubToken.new(series.account_id, ['member']) }
  let(:non_member_token) { StubToken.new(series.account_id + 1, ['no']) }
  let(:user) { build_stubbed(:user, id: token.user_id) }

  describe '#update? and #create?' do
    it 'returns true if user member of account that owns the template series' do
      AudioFileTemplatePolicy.new(token, audio_file_template).must_allow :update?
      AudioFileTemplatePolicy.new(token, audio_file_template).must_allow :create?
    end

    it 'returns false otherwise' do
      AudioFileTemplatePolicy.new(non_member_token, audio_file_template).wont_allow :update?
      AudioFileTemplatePolicy.new(non_member_token, audio_file_template).wont_allow :create?
    end
  end
end<commit_msg>Update AudioFileTemplate test to reflect series scope<commit_after>require 'test_helper'

describe AudioFileTemplatePolicy do
  let(:account) { create(:account) }
  let(:series) { create(:series, account: account) }
  let(:audio_version_template) { create(:audio_version_template, series: series) }
  let(:audio_file_template) { build_stubbed(:audio_file_template, audio_version_template: audio_version_template) }
  let(:token) { StubToken.new(series.account_id, ['cms:series']) }
  let(:non_member_token) { StubToken.new(series.account_id + 1, ['cms:series']) }
  let(:non_series_token) { StubToken.new(series.account_id, ['cms:account']) }
  let(:user) { build_stubbed(:user, id: token.user_id) }

  describe '#update? and #create?' do
    it 'returns true if user member of account that owns the template series' do
      AudioFileTemplatePolicy.new(token, audio_file_template).must_allow :update?
      AudioFileTemplatePolicy.new(token, audio_file_template).must_allow :create?
    end

    it 'returns false if the token lacks the series scope' do
      AudioFileTemplatePolicy.new(non_series_token, audio_file_template).wont_allow :update?
      AudioFileTemplatePolicy.new(non_series_token, audio_file_template).wont_allow :create?
    end

    it 'returns false otherwise' do
      AudioFileTemplatePolicy.new(non_member_token, audio_file_template).wont_allow :update?
      AudioFileTemplatePolicy.new(non_member_token, audio_file_template).wont_allow :create?
    end

  end
end
{'fraction_non_alphanumeric': 0.10613662678502508, 'fraction_numerical': 0.0007719027402547279, 'mean_word_length': 5.8936170212765955, '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': '2395563', 'n_tokens_mistral': 800, 'n_tokens_neox': 789, 'n_words': 166}