<commit_before>require 'spec_helper'

describe Coursewareable::ImagesController do
  include ActionDispatch::TestProcess

  let(:classroom) { Fabricate('coursewareable/classroom') }

  describe 'GET index' do

    context 'not being logged in' do
      it 'should redirect to login' do
        @request.host = "#{classroom.slug}.#{@request.host}"
        get :index, :use_route => :coursewareable
        response.should redirect_to(login_path)
      end

      it 'should redirect to login if classroom does not exist' do
        @request.host = "wrong.#{@request.host}"
        get :index, :use_route => :coursewareable
        response.should redirect_to(login_path)
      end
    end

    context 'being logged in' do
      it 'should respond with a json' do
        @controller.send(:auto_login, classroom.owner)
        @request.host = "#{classroom.slug}.#{@request.host}"
        get :index, :use_route => :coursewareable
        response.body.strip.should be_empty
      end

      it 'should redirect to not found if classroom does not exist' do
        @controller.send(:auto_login, classroom.owner)<commit_msg>Update some specs to properly query json format.<commit_after>require 'spec_helper'

describe Coursewareable::ImagesController do
  include ActionDispatch::TestProcess

  let(:classroom) { Fabricate('coursewareable/classroom') }

  describe 'GET index' do

    context 'not being logged in' do
      it 'should redirect to login' do
        @request.host = "#{classroom.slug}.#{@request.host}"
        get :index, :use_route => :coursewareable
        response.should redirect_to(login_path)
      end

      it 'should redirect to login if classroom does not exist' do
        @request.host = "wrong.#{@request.host}"
        get :index, :use_route => :coursewareable
        response.should redirect_to(login_path)
      end
    end

    context 'being logged in' do
      context 'with some images' do

        before do
          @image = Fabricate('coursewareable/image',
            :classroom => classroom, :user => classroom.owner)
        end

        it 'should respond with a json' do
          @controller.send(:auto_login, classroom.owner)
          @request.host = "#{classroom.slug}.#{@request.host}"
          get :index, :use_route => :coursewareable, :format => :json
          json = JSON.parse(response.body)

          json.size.should eq(1)
          json[0]['image'].should eq(@image.url(:large))
        end
      end

      it 'should respond with an empty json' do
        @controller.send(:auto_login, classroom.owner)
        @request.host = "#{classroom.slug}.#{@request.host}"
        get :index, :use_route => :coursewareable, :format => :json
        json = JSON.parse(response.body)

        json.size.should eq(0)
      end

      it 'should redirect to not found if classroom does not exist' do
        @controller.send(:auto_login, classroom.owner)
{'fraction_non_alphanumeric': 0.10946643717728055, 'fraction_numerical': 0.0010327022375215145, 'mean_word_length': 2.793733681462141, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '3105794', 'n_tokens_mistral': 831, 'n_tokens_neox': 819, 'n_words': 234}