<commit_before>require 'spec_helper'
require 'base_objects'
require 'authorized_controller'

describe ProgramsController do
  include BaseObjects

  before :each do
    create_base_objects

    # For use by authorized_controller tests
    @model = Program
    @object = @reg
  end

  context "authorization" do
    it_behaves_like "an authorized create"
    it_behaves_like "an authorized new"
    it_behaves_like "an authorized read", ['show',
                                           'tooltip',
                                           'controls',
                                           'sections',
                                           'section_controls',
                                           'control_sections',
                                           'category_controls']
    it_behaves_like "an authorized update", ['edit', 'update']
    it_behaves_like "an authorized action", ['import'], 'update_program'
  end

  context "show" do
    before :each do
      login({}, { :role => 'superuser' })
      @ctl2 = FactoryGirl.create(:control, :title => 'Control 2', :slug => 'CTL2', :description => 'x', :program => @creg)
      @ctl3 = FactoryGirl.create(:control, :title => 'Control 3', :slug => 'CTL2-1', :description => 'x', :parent => @ctl2, :program => @creg)<commit_msg>Tests for the programs controller<commit_after>require 'spec_helper'
require 'base_objects'
require 'authorized_controller'

describe ProgramsController do
  include BaseObjects

  before :each do
    create_base_objects

    # For use by authorized_controller tests
    @model = Program
    @object = @reg
  end

  context "authorization" do
    it_behaves_like "an authorized create"
    it_behaves_like "an authorized new"
    it_behaves_like "an authorized read", ['show',
                                           'tooltip',
                                           'controls',
                                           'sections',
                                           'section_controls',
                                           'control_sections',
                                           'category_controls']
    it_behaves_like "an authorized update", ['edit', 'update']
    it_behaves_like "an authorized action", ['import'], 'update_program'
  end

  context "index" do
    before :each do
      login({}, {:role => 'superuser'})
    end

    it 'should return all programs' do
      get 'index', :format => :json
      assigns(:programs).count.should eq(2)
    end
    it 'should filter by relevant_to when provided' do
      program1 = FactoryGirl.create(:program)
      program2 = FactoryGirl.create(:program)
      product = FactoryGirl.create(:product)
      product.add_within_scope_of(program2)
      get 'index', :format => :json, :relevant_to => product.id
      assigns(:programs).count.should eq(1)
      assigns(:programs).should eq([program2])
    end
  end

  context "show" do
    before :each do
      login({}, { :role => 'superuser' })
      @ctl2 = FactoryGirl.create(:control, :title => 'Control 2', :slug => 'CTL2', :description => 'x', :program => @creg)
      @ctl3 = FactoryGirl.create(:control, :title => 'Control 3', :slug => 'CTL2-1', :description => 'x', :parent => @ctl2, :program => @creg)
{'fraction_non_alphanumeric': 0.1140215716486903, 'fraction_numerical': 0.006779661016949152, 'mean_word_length': 2.085551330798479, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1450211', 'n_tokens_mistral': 864, 'n_tokens_neox': 828, 'n_words': 239}